Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
for anyone wondering about cleveref, see Making refcheck work with cleveref –  cmhughes Dec 6 '13 at 20:58

1 Answer 1

up vote 38 down vote accepted

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.

share|improve this answer
    
Fantastic, thanks for the quick and great answer. –  Bill Cheatham Aug 15 '11 at 10:58
    
@BillCheatham I've updated my answer with a better example and a note on it not warning for figures and tables that are not labelled (it only warns for tables and figures that are labelled but not referred to). –  N.N. Aug 15 '11 at 11:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.