Possible Duplicate:
How can I get LaTeX to warn about unreferenced figures?

In my document I have several figures, most of which I created references for (using \ref{}) immediately after I placed them into the document. However, I had a few figures that I forgot to reference in the document, leaving some figures "hanging" without any citation, which is a mistake on my part and must be corrected.

So, my questions is:

Is there a way to force latex to issue a warning if a figure is never referenced?

marked as duplicate by diabonas, lockstep, Martin Scharrer Dec 4 '11 at 12:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Are all figures labeled? – Marco Daniel Dec 3 '11 at 20:14
  • Yes, in my case all of the figures are labeled. – nickb Dec 3 '11 at 20:14

The refcheck package might be useful here.

The following MWE has a figure that is not referenced, so the refcheck puts a warning in your pdf with ? surrounding it.

enter image description here




As soon as you reference the figure, the ? will be removed. Note that this method does rely on each figure having a label.

Note that I have demonstrated refcheck with a figure, but it works in the same way for anything that has a label (table, chapter, equation, etc).

  • That's a neat package I'd never heard of. Thanks! – Alan Munn Dec 3 '11 at 20:34
  • That's quite useful. However, is there a way to have refcheck loaded, and not have the <fig:myfig> in the margin, once the figure is referenced. – Peter Grill Dec 3 '11 at 20:34
  • @PeterGrill Good question, not sure! I usually just comment out %\usepackage{refcheck} when I'm done checking – cmhughes Dec 3 '11 at 20:42

Here's a hand-made solution:

Add the following to your preamble:




  \expandafter\global\expandafter\def\csname warning@#1\endcsname{%
    \typeout{warning: label #1 was not referenced.}}%
    \csname warning@#1\endcsname}

  \expandafter\global\expandafter\def\csname warning@#1\endcsname{}


and the following directly before \end{document}:


Now on every LaTeX run, for each unreferenced label you get a line

warning: label (your label here) was not referenced.

on your standard output and in your refwarn.log.

If you prefer the warning directly in your document instead, remove the \typeout (and possibly add a \texttt around the #1 and a \\ at the end) in the warning macro.

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