The amsmath package

Adds the display environments align, gather and cases, the matrix environments, and commands such as \text, \dfrac and \DeclareMathOperator.

Loading the package

\usepackage{amsmath}

Plain LaTeX has equation for one numbered formula and eqnarray for several lines, and eqnarray puts too much space around the relation sign. amsmath adds align for lines aligned at a point you choose, gather for centred lines, multline and split for one long formula, and the matrix environments matrix, pmatrix and bmatrix.

Inside align, & marks the alignment point and \\ ends a line. Every numbered environment has a starred form such as align* without equation numbers. The environments start display math themselves, so they do not go inside \[ ... \] or $ ... $.

Main commands

\begin{align} ... \end{align}Several numbered formulas, aligned at &.
\text{if } x > 0Upright text inside a formula, in the size of the surrounding math.
\dfrac{a}{b}Fraction in display size, also in inline math; \tfrac gives the small inline size.
\begin{pmatrix} a & b \\ c & d \end{pmatrix}Matrix in round brackets; bmatrix uses square brackets, vmatrix vertical bars.
\begin{cases} ... \end{cases}Case distinction with one large brace on the left.
\DeclareMathOperator{\sgn}{sgn}Defines an operator name that is set upright with the spacing of \sin. Goes into the preamble.
\eqref{eq:binomial}Reference to an equation, with the number in parentheses.
\notagRemoves the number of one line; \tag{*} sets a label of your own instead.

Complete example

\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\sgn}{sgn}
\begin{document}
\begin{align}
  (a + b)^2 &= a^2 + 2ab + b^2 \label{eq:binomial} \\
  (a - b)^2 &= a^2 - 2ab + b^2 \notag
\end{align}
Equation~\eqref{eq:binomial} holds for all real $a$ and $b$.
\[
  \sgn(x) =
  \begin{cases}
    1  & \text{if } x > 0, \\
    0  & \text{if } x = 0, \\
    -1 & \text{if } x < 0.
  \end{cases}
\]
\end{document}
Result
The compiled example

Open in the editor

Compiled with pdfLaTeX from TeX Live 2023. Tools run in this order: pdflatex → pdflatex.

Pitfalls

Related pages