I would like to have LaTeX compilation (I use pdflatex) give an error if there exists one label in my document that I do not reference. Is this possible? This is to ensure that I mention every table and figure for which I set a label. I would prefer to use the same label and ref commands as always, if possible.
Asked
Active
Viewed 663 times
4
1 Answers
4
You could use the package refcheck. There already a question you might want to check out: here. It worked for me in LuaLaTeX.
I'll give a brief example:
\documentclass{article}
\usepackage{amsmath}
\usepackage{refcheck}
\begin{document}
\begin{figure}
% ...
\caption{A nice picture of my dog}\label{fig:dog}
\end{figure}
% As seen in figure~\ref{fig:dog}
\end{document}
With the second last line commented out a call of your LaTeX compiler (in my case LuaLaTex) will produce output like this
...
Package refcheck Warning: Unused label `fig:dog' on input line 8.
...
The output contains a warning that tells you that a label was never referenced. If you remove the % infront of the second line, the label will be referenced and therefore the warning disappears.
refcheckxrdoc(doc) to manually invoke the check (I have never used it). If the check fails you could probably throw an error by yourself (I have not done this as well) but here is a question regarding this topic. I would write a bash script to extract such warnings from the log file. – Fabian Köhler Jul 04 '15 at 23:13@. I was not notified of your message. I had to check manually. – Xu Wang Jul 05 '15 at 11:59