# Give an error if I don't reference a label

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.

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.

• Welcome to TeX.SX! Can you elaborate on your answer" At the moment it's more like a comment – user31729 Jul 4 '15 at 14:15
• How can I turn the warning into an error though? – Xu Wang Jul 4 '15 at 15:27
• Refcheck has a command 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 4 '15 at 23:13
• @FabianKöhler Thanks, I posted a follow-up question here: tex.stackexchange.com/questions/253773/… – Xu Wang Jul 5 '15 at 11:59
• @FabianKöhler also, please use the @`. I was not notified of your message. I had to check manually. – Xu Wang Jul 5 '15 at 11:59