Authoring Numbered Equations with Cross-References in LaTeX Using amsmath
A practical guide to writing numbered, multi-line equations with amsmath, placing labels correctly, and resolving cross-references through multiple LaTeX compile passes. Covers pdfLaTeX, XeLaTeX, and LuaLaTeX differences.
17 Aug 2026, 13:39 UTC

Desired Outcome
Produce a LaTeX document where multi-line derivations are numbered automatically, and references to those equations in the surrounding text resolve to the correct numbers after compilation. The workflow should work with pdfLaTeX, XeLaTeX, or LuaLaTeX and require only standard packages.
Prerequisites
- A working TeX distribution (TeX Live 2023+, MikTeX current, or equivalent).
- An editor or command-line access to run
latexmkor the engine directly (pdflatex,xelatex,lualatex). - Basic familiarity with LaTeX document structure (preamble,
\begin{document}/\end{document}).
Minimal Preamble
Load amsmath early, before any package that patches math behavior. If you need the extensions from mathtools (e.g., \coloneqq, \mathclap), load it instead; it pulls in amsmath automatically.
\documentclass{article}
\usepackage{amsmath} % or \usepackage{mathtools}
\usepackage{hyperref} % optional: makes \eqref links clickable
\begin{document}
Engine note: With XeLaTeX or LuaLaTeX, add \usepackage{unicode-math} after amsmath if you want OpenType math fonts. Do not load legacy math font packages (e.g., mathptmx) together with unicode-math.
Writing a Numbered Multi-Line Derivation
Use the align environment for equations that share alignment points (typically at &= or &\approx). Each line receives a single equation number unless you suppress it with \nonumber.
\begin{align}
E &= mc^2 \label{eq:einstein} \\
p &= \gamma m v \label{eq:momentum}
\end{align}
&marks the alignment column.\\ends a line (not a paragraph break).\label{...}must appear inside the environment, on the line you want to reference.
For a derivation that should share one number across several lines, wrap the inner lines in split inside an equation environment:
\begin{equation}
\begin{split}
a &= b + c \\
&= d + e + f
\end{split}
\label{eq:split-demo}
\end{equation}
Referencing in Text
Use \eqref{...} (from amsmath) for parenthesized references, or \ref{...} for the raw number. \eqref automatically adds parentheses and, with hyperref, creates a link.
Equation \eqref{eq:einstein} relates energy and mass,
while \eqref{eq:momentum} gives relativistic momentum.
Compilation Procedure
- Save the file as
equations.tex. - Run the engine twice (or use
latexmkwhich handles passes automatically):# pdfLaTeX latexmk -pdf equations.tex # XeLaTeX latexmk -xelatex equations.tex # LuaLaTeX latexmk -lualatex equations.tex - Open the resulting PDF. Equation numbers should appear at the right margin (or left if
leqnoclass option is used), and references should show numbers, not??.
Expected Checks
- PDF output: Each
alignline has a sequential number (1), (2), …;splitblock shares one number. - References:
\eqref{eq:einstein}renders as “(1)”, not “(??)”. - Log file: No “LaTeX Warning: Reference `eq:einstein' on page 1 undefined” after the final pass. No “multiply defined” warnings.
Common Failures and Recovery
| Symptom | Cause | Fix |
|---|---|---|
Reference shows ?? |
Only one compile pass; label not yet written to .aux. |
Rerun the engine (or latexmk) until references stabilize. |
| “Label `eq:foo' multiply defined” | Same \label used twice. |
Give each label a unique key; adopt a prefix convention like eq:, fig:, sec:. |
| Equation number missing on a line | \nonumber or \notag present, or line inside align*. |
Remove \nonumber or switch from align* to align. |
Misaligned columns in align |
Missing or extra & markers. |
Each line must have the same number of &; use &={} for empty left side if needed. |
| Unicode glyphs missing with XeLaTeX/LuaLaTeX | unicode-math loaded but no math font set. |
Add \setmathfont{Latin Modern Math} (or another OpenType math font) after loading unicode-math. |
Verification Checklist
- Compile the minimal example above with your target engine.
- Confirm equation numbers appear and increment correctly.
- Add a new
\labeland\eqrefpair, recompile twice, verify the reference updates. - Inspect
equations.logfor “undefined references” or “multiply defined” warnings. - If using XeLaTeX/LuaLaTeX with
unicode-math, check that symbols (∑, ∫, Greek letters) render with the chosen math font and spacing looks consistent.
Limitations
amsmathdoes not support automatic line-breaking of long equations; usemultlineor manual breaks with\\and alignment tweaks.- Cross-references across
\includefiles work, but labels must be unique project-wide. - Manual spacing commands (
\!,\:,\;,\quad) are sometimes necessary but reduce portability; preferamsmath’s built-in spacing where possible.
Next Steps
For larger documents, consider cleveref (load after hyperref) to get “Eq. (1)” automatically via \cref{eq:einstein}. For numbered groups of related equations, use the subequations environment to produce (1a), (1b), … while keeping a single parent number.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.