LaTeX Warning: Reference `<label>' on page <n> undefined
A \ref, \eqref or \pageref names a label LaTeX has not seen: a typo, a missing \label, or a part excluded by \includeonly. Prints ?? in the PDF.
Help centre › LaTeX errors › References and bibliography · Warning: the document still compiles
What the log says
LaTeX Warning: Reference `fig:results' on page 2 undefined on input line 31.
...
LaTeX Warning: There were undefined references.What it means
The label in \ref{…} was not defined anywhere in the previous run's .aux file. The PDF shows ?? where the number should be. On a first compile this is normal: labels are written to the .aux file in one pass and read in the next. If it survives a second pass, the label really does not exist.
Causes and fixes
Most common first. Each example is a complete document; the first fails with this message, the second is the same document fixed.
1. The label in \ref is spelled differently from the \label
Labels are case-sensitive and match character by character, so fig:Results, fig:result and fig:results are three labels. Search the source for \label{ and copy the exact text.
\documentclass{article}
\begin{document}
\section{Results}\label{sec:results}
The results are discussed in Section~\ref{sec:result}.
\end{document}\documentclass{article}
\begin{document}
\section{Results}\label{sec:results}
The results are discussed in Section~\ref{sec:results}.
\end{document}2. The label is in a chapter excluded by \includeonly
With \includeonly{…}, chapters left out are not typeset, and their labels are known only if their .aux files survive from an earlier full compile. Remove \includeonly (or add the chapter to it) and compile the whole document once.
\begin{filecontents*}[overwrite]{intro.tex}
\chapter{Introduction}\label{ch:intro}
Some background.
\end{filecontents*}
\begin{filecontents*}[overwrite]{methods.tex}
\chapter{Methods}
As set out in Chapter~\ref{ch:intro}, we measure twice.
\end{filecontents*}
\documentclass{report}
\includeonly{methods}
\begin{document}
\include{intro}
\include{methods}
\end{document}\begin{filecontents*}[overwrite]{intro.tex}
\chapter{Introduction}\label{ch:intro}
Some background.
\end{filecontents*}
\begin{filecontents*}[overwrite]{methods.tex}
\chapter{Methods}
As set out in Chapter~\ref{ch:intro}, we measure twice.
\end{filecontents*}
\documentclass{report}
\begin{document}
\include{intro}
\include{methods}
\end{document}3. The \label was never written, or is commented out
A figure or table needs \label{…} inside its environment, after \caption{…}; an equation needs it inside equation or align. Check that the line carrying the label is not behind a %.
4. Only one pass has run
Labels reach the .aux file in one LaTeX run and are read in the next. Compile again; latexmk repeats the passes automatically.
Finding the line when the line number does not help
- The warning names the label and the input line of the \ref. Search the whole project for the label's text without its prefix (for example
results) to find near misses.
In Manulyx
The editor shows the warning beside the line with the \ref. Manulyx repeats the LaTeX passes itself, so a reference that only needed a second pass resolves without you doing anything.
Write in Manulyx for free · Journal templates
More in references and bibliography
- LaTeX Warning: Citation `<key>' on page <n> undefinedA \cite key has no entry in the built bibliography: a key typo, a missing \bibliography line, a broken .bib entry, or BibTeX has not run yet.
- I couldn't open database file <name>.bibBibTeX cannot find the .bib file named in \bibliography. Check the spelling and folder, and write the name without the .bib extension.
- I found no \bibdata commandBibTeX read the .aux file and found no \bibliography, no \cite or no \bibliographystyle. Add the missing command, or run biber for biblatex.
- Repeated entry---line <n> of file <name>.bibTwo .bib entries share one citation key. BibTeX keeps the first and skips the other. Delete the duplicate or give it its own key.
- I was expecting a `,' or a `}'---line <n> of file <name>.bibA .bib entry is malformed, most often a missing comma between fields or a space in the key. BibTeX skips the rest of the entry.
- Package natbib Error: Bibliography not compatible with author-year citations.natbib wants author-year data, but the bibliography style gives only numbers. Use an author-year style such as plainnat, or load natbib with [numbers].
Every example on this page was compiled with pdfLaTeX to check that it fails and is fixed as described. All LaTeX errors