Equations in LaTeX

LaTeX excels at mathematical typesetting. Use equation for single equations and align for multi-line systems.

Quick Answer

latex
% Inline math:
The formula $E = mc^2$ is famous.

% Display equation (numbered):
\begin{equation}
  E = mc^2
\end{equation}

% Display equation (unnumbered):
\[ E = mc^2 \]

Math Modes

latex
% Inline — flows with text:
Einstein's equation $E = mc^2$ changed physics.

% Display — centered on its own line (unnumbered):
\[ \int_0^\infty e^{-x^2}\,dx = \frac{\sqrt{\pi}}{2} \]

% Display — numbered (use \label for referencing):
\begin{equation}
  \nabla \cdot \mathbf{E} = \frac{\rho}{\varepsilon_0}
  \label{eq:gauss}
\end{equation}

% Reference it:
As shown in Equation~\eqref{eq:gauss}, ...

Multi-Line Equations with align

The align environment (from amsmath) aligns equations at the & symbol. Each line gets a number; use \notag or align* to suppress.

latex
\usepackage{amsmath}

\begin{align}
  f(x) &= x^2 + 2x + 1 \\
       &= (x + 1)^2
\end{align}

% Unnumbered:
\begin{align*}
  a &= b + c \\
  d &= e - f
\end{align*}

Writing your thesis in LaTeX?

MonsterWriter's LaTeX Workspace gives you real-time PDF preview with no compile limits — at a fraction of Overleaf's price. Works just like Overleaf, costs 11× less.

Try MonsterWriter free

Cases (Piecewise Functions)

latex
\begin{equation}
  f(x) = \begin{cases}
    x^2 & \text{if } x \geq 0 \\
    -x  & \text{if } x < 0
  \end{cases}
\end{equation}

Common Math Symbols

latex
% Superscript and subscript:
x^2    x_i    x^{2n}    x_{ij}

% Fractions:
\frac{a}{b}    \dfrac{a}{b}  % \dfrac forces display size

% Square root:
\sqrt{x}    \sqrt[3]{x}  % cube root

% Summation and integral:
\sum_{i=1}^{n} i^2
\int_0^1 f(x)\,dx

% Operators:
\sin(x)  \cos(x)  \log(x)  \lim_{x \to 0}

% Relations:
\leq  \geq  \neq  \approx  \equiv  \in  \subset

Equation Numbering

latex
% Suppress number on one line in align:
\begin{align}
  a &= b \notag \\
  c &= d
\end{align}

% Tag a specific line:
\begin{align*}
  x &= y + z \tag{*}
\end{align*}

% Reset counter per section:
\numberwithin{equation}{section}
% Produces: (1.1), (1.2), (2.1), ...

Related Topics