8

I would like to ensure that all figures in my document are referenced somewhere in the text. With all the editing I've been doing, some of the figures are no longer being referenced and I would like to find out which (so I can either delete the figures or add appropriate references).

Is there a way (using a package, or custom function) to highlight or list any floats that do not have a corresponding \ref{fig:foobar} in the text body?

Example:

\documentclass{article}
\usepackage{graphicx}
\usepackage{flafter}
\begin{document}

There's a lady who's sure all that glitters is gold (See Figure \ref{fig:gold}).
And she's buying a stairway to heaven.

\begin{figure}[]
\includegraphics{gold.png}
\caption{Picture of gold}
\label{fig:gold}
\end{figure}

\begin{figure}[]
\includegraphics{silver.png}
\caption{Picture of silver}
\label{fig:silver}
\end{figure}

\end{document}

I'd like to run a function that tells me fig:silver was never referenced in the text

Note that I'm already using flafter to ensure floats only appear after they have been referenced. Is there an argument I can pass to flafter or \listoffigures which has the functionality I'm looking for?

Torbjørn T.
  • 206,688

1 Answers1

8

The refcheck package does this. It prints the label next to the caption, and if unreferenced places it between question marks.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{flafter}
\usepackage{refcheck}

\begin{document}

There's a lady who's sure all that glitters is gold (See Figure \ref{fig:gold}).
And she's buying a stairway to heaven.
\begin{figure}[hb]
\caption{Picture of gold}
\label{fig:gold}
\end{figure}
\begin{figure}[hb]
\caption{Picture of silver}
\label{fig:silver}
\end{figure}

\end{document}

enter image description here

Torbjørn T.
  • 206,688