Number equations in LaTeX (equation, tag, notag)

The equation environment numbers a formula automatically; \label and \eqref refer to it. equation* or \[...\] sets a formula without a number.

Preamble

The snippets on this page need these lines before \begin{document}:

\usepackage{amsmath}

Number an equation and refer to it

\label{name} inside the environment stores the number. \eqref{name} from amsmath prints it in parentheses, \ref{name} prints the bare number. The number shows up after the second compile run.

\begin{equation}
  E = mc^2 \label{eq:energy}
\end{equation}
Equation~\eqref{eq:energy} relates mass and energy.
Result
The compiled example

Open in the editor

Leave out the number

equation* from amsmath and \[...\] set a formula without a number. In an environment with several lines such as align, \notag removes the number of one line.

\begin{equation*}
  a^2 + b^2 = c^2
\end{equation*}
\begin{align}
  x &= y + z \notag \\
  y &= 2z
\end{align}
Result
The compiled example

Open in the editor

Number equations per section

\numberwithin{equation}{section} in the preamble puts the section number in front and restarts the count in every section: (1.1), (1.2), (2.1). The classes report and book already number equations per chapter.

Complete document:

\documentclass{article}
\usepackage{amsmath}
\numberwithin{equation}{section}
\begin{document}
\section{Results}
\begin{equation}
  a = b
\end{equation}
\end{document}
Result
The compiled example

Open in the editor

Use your own label instead of a number

\tag{text} replaces the number with your own text in parentheses and does not use up an equation number; \tag*{text} leaves out the parentheses. The argument is normal text, so a symbol goes between $...$.

\begin{equation}
  x^2 \ge 0 \tag{$*$}
\end{equation}
\[
  a + b = b + a \tag{commutativity}
\]
Result
The compiled example

Open in the editor

Sub-numbers: 1a, 1b

Inside subequations all equations share one number and get the letters a, b, c. A \label right after \begin{subequations} refers to the shared number.

\begin{subequations}
\begin{align}
  x + y &= 3 \\
  x - y &= 1
\end{align}
\end{subequations}
Result
The compiled example

Open in the editor

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages