How to Write Equations in LaTeX
Updated June 2026
To write equations in LaTeX, use $...$ for inline math (e.g. $E=mc^2$) and the equation environment for numbered display math: \begin{equation} ... \end{equation}. Load amsmath with \usepackage{amsmath} for fractions (\frac), alignment (align), and advanced symbols. LetX renders math live as you type.
Step by step
- 1
Load amsmath
Add \usepackage{amsmath} for the best math support.
- 2
Inline math
Wrap math in $...$ to keep it in the text line, e.g. $a^2 + b^2 = c^2$.
- 3
Display math
Use \begin{equation} ... \end{equation} for a centered, numbered equation.
- 4
Align multiple lines
Use the align environment with & alignment points and \\ between lines.
- 5
Compile
Compile to PDF; LetX shows rendered math in the live preview in seconds.
Example
\usepackage{amsmath}
% Inline: the identity $e^{i\pi} + 1 = 0$.
\begin{equation}
\frac{\partial f}{\partial x} = 2x
\end{equation}
\begin{align}
a &= b + c \\
&= d
\end{align}Use \frac{a}{b} for fractions, x^{2} for superscripts, x_{i} for subscripts, and \sum, \int, \sqrt{} for common operators.
Symbol cheat sheet
| You want | Command | You want | Command |
|---|---|---|---|
| α β γ | \alpha \beta \gamma | ± × ÷ | \pm \times \div |
| ≤ ≥ ≠ | \leq \geq \neq | ≈ ≡ ∝ | \approx \equiv \propto |
| ∞ ∂ ∇ | \infty \partial \nabla | → ⇒ ↦ | \to \Rightarrow \mapsto |
| ∈ ⊂ ∪ ∩ | \in \subset \cup \cap | ∀ ∃ ¬ | \forall \exists \neg |
| ∑ ∏ ∫ | \sum \prod \int | x̄ x̂ ẋ | \bar x \hat x \dot x |
Matrices
\begin{equation}
A = \begin{pmatrix} % p=() b=[] v=|| B={}
1 & 2 \\
3 & 4
\end{pmatrix}
\end{equation}Piecewise functions (cases)
\begin{equation}
f(x) = \begin{cases}
x^2 & \text{if } x \geq 0 \\
-x & \text{otherwise}
\end{cases}
\end{equation}Note \text{...} from amsmath — it keeps words upright inside math mode instead of italicizing them as variables.
Long derivations with align
\begin{align}
(a+b)^2 &= (a+b)(a+b) \\
&= a^2 + ab + ba + b^2 \nonumber % suppress one number
\\
&= a^2 + 2ab + b^2
\end{align}The & marks the alignment column (usually before =); \nonumber or the starred align* suppresses equation numbers.
Frequently asked questions
What is the difference between equation and align?
equation is for a single numbered equation; align is for multiple equations aligned at a chosen point (the &), each numbered unless you use align*.
How do I write an unnumbered equation?
Use the starred version: \begin{equation*} ... \end{equation*}, or use \[ ... \] for quick display math.
How do I write a fraction in LaTeX?
Use \frac{numerator}{denominator}, e.g. \frac{1}{2}. For inline fractions in text, \tfrac gives a smaller, text-sized fraction.
How do I write a matrix in LaTeX?
Use the pmatrix environment from amsmath: \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}. Variants: bmatrix for [brackets], vmatrix for |determinants|, Bmatrix for {braces}.
How do I put normal text inside an equation?
Use \text{...} from amsmath: f(x) = x^2 \text{ for } x > 0. Without it, LaTeX italicizes the words as if each letter were a variable.
How do I number equations by section?
Add \numberwithin{equation}{section} (amsmath) to the preamble — equations then number as (2.1), (2.2) per section.
Why does my equation overflow the page margin?
Long equations need manual breaking: use the multline environment, or split inside align across several lines at sensible operators.
Try this in LetX now
Open the editor, paste the example, and compile in seconds — free, in your browser.
Start Writing Free