Math and Equations

How do you label an equation?

Label an equation in LaTeX with label inside the equation environment, refer to it with eqref, use tag for custom numbers, and compile twice.

On this page
  1. A numbered equation with a label
  2. \eqref or \ref
  3. Compile twice
  4. Custom tags and unnumbered equations
  5. Number equations by section
  6. Labels in align
  7. Cross-references with hyperref
  8. Common errors

Put \label{...} inside an equation environment, then cite the equation in the text with \eqref{...}. LaTeX numbers numbered equations automatically, and the label records that number so you can refer to it. \label is part of base LaTeX. \eqref comes from amsmath.

A numbered equation with a label

\begin{equation}
  E = mc^2 \label{eq:energy}
\end{equation}

In the text, refer to it with As Equation~\eqref{eq:energy} shows. The ~ makes a non-breaking space between the word “Equation” and the number, so they stay on the same line.

The label name is up to you. A prefix such as eq: is a common convention that makes equation labels easy to find.

\eqref or \ref

  • \eqref{eq:energy} prints the number in parentheses, such as (1). It needs amsmath.
  • \ref{eq:energy} prints the bare number, such as 1.

Use \eqref for equations, since the parentheses match the equation tag.

Compile twice

LaTeX saves label numbers in the .aux file during one run and reads them on the next. After you add or move a label, compile again. Until you do, the reference shows ??, and LaTeX warns that labels may have changed.

Custom tags and unnumbered equations

  • \tag{A} replaces the automatic number with a custom label, such as (A).
  • \tag*{A} prints the label without parentheses.
  • equation* and \[ ... \] display an equation with no number.
  • \nonumber removes the number from one line in an align environment. Aligning equations with align covers that case.
\begin{equation}
  a + b = c \tag{A}
\end{equation}

Number equations by section

The \numberwithin command from amsmath restarts the equation counter in each numbered section:

\numberwithin{equation}{section}

Equations in Section 2 then print as (2.1), (2.2) and so on.

Labels in align

In an align environment, put a \label on any line that needs a reference, before its \\. Each line can have its own label.

Cross-references with hyperref

The hyperref package turns \eqref into a clickable link in the PDF. It is usually loaded near the end of the preamble.

Common errors

  • Label outside the environment: a \label placed after \end{equation} picks up the number of the previous numbered item. Move it inside the environment.
  • Duplicate labels: two labels with the same name cause a “multiply-defined labels” warning. Give each label a unique name.
  • Question marks in the output: the label is missing, has a typo, or has not been picked up yet. Check the spelling, then compile twice.
  • Undefined control sequence for \eqref: load amsmath in the preamble.

For a matrix equation, the same pattern applies. See matrices and determinants for the matrix environments, and the advanced mathematics guide for other math topics in this cluster.

The complete guide to math and equations

Advanced Mathematics in LaTeX: Operators, Theorems and Proofs
Read the guide

Keep exploring

Guides from other topics

All topics →