Cross-Referencing – How to Get LaTeX to Warn About Unreferenced Figures and Unused Labels

cross-referencingwarnings

When writing documents, I consider it to be necessary that all figures and tables are referenced (\ref) in the text, whether or not I've remembered to \label them. LaTeX does not currently warn if a figure or table is not referenced. Is there a way to ensure that this is flagged up as a warning?

Note that I am specifically concerned about figures and tables, not chapter or section headings; it will be no good looking just at \labels that don't have an associated \ref.

In other words, it should report boo and not report bla in the following MWE:

\documentclass{article}
\begin{document}
\section{BLA}\label{bla}
\section{BOO}\label{boo}
In Section~\ref{bla} we do something.
\end{document}

Best Answer

Use the package refcheck. It is

Intended to check references in a document, looking for numbered but unlabelled equations, for labels which are not used in the text, for unused bibliography references.

Note that it checks for labels that are not used in the text but not for tables and figures that are not labelled. Thus if you got a table or figure without a label you'll not get warned. If you compile the following you'll get a demonstration of its core features (the idea for this is from the package's excellent demo):

\documentclass{article}

\usepackage{refcheck}

\begin{document}

\begin{equation}\label{eq:1}% Labelled and referred to
1+1=2
\end{equation}

\ref{eq:1}

\begin{equation}\label{eq:2}% Labelled but not referred to
1-1=0
\end{equation}

\begin{equation}% Not labelled nor referred to
1+1=0
\end{equation}

\begin{table}[h]
\center
\begin{tabular}{cc}
1 & 2 \\
3 & 4 \\
\end{tabular}
\caption{Numbers}\label{tab:1}% Labelled but not referred to
\end{table}

\begin{figure}[h]\label{fig:1}% Labelled but not referred to
\caption{Foo}
\end{figure}

\end{document}

The last two equations will be marked by "?" in the output because they're not labelled and referred to. The table and figure will be marked by "?" because they're labelled but not referred to. Also the .log file will contain:

 Unused label `eq:2' on page 1
 Unlabelled equation (3) on page 1
 Unused label `tab:1' on page 1
 Unused label `fig:1' on page 1

Note that refcheck should be loaded after the ams packages and the hyperref package.

Relatedly you may also want to check for duplicate labels.

Related Question