0

Is there a simple way to print page-numbers that contain \ref{something} next to each \label{something}?

(For a long time I am working on a long text, and want to know maybe some statements are not longer needed.)

1 Answers1

1

One option to check the label-reference correspondence is showlabels:

mwe

\documentclass{article}
\usepackage[inline]{showlabels}
\usepackage{xcolor}
 \showlabels{ref}
 \renewcommand{\showlabelfont}{\color{red}}
\begin{document}
\section{foo}
 Hello  \label{foo}  world.  
\section{bah}
Hello word (see section \ref{foo})
\end{document}

To find references without labels, simply use hyperref to notice easily if there are linked red text (reference with label) or alternatively search for the ?? symbols in the document (reference without label). For the opposite (labels without any reference) you can use refcheck, that also show labels but those unused labels are highlighted with interrogation signs: Example:

\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage{refcheck}
\begin{document}
\section{foo}
 Hello  \label{foo}  world. % label with ref
\section{bah}
Hello word (see section \ref{foo}) % ref with label 
\section{baz}
\label{baz} % label without ref 
Hello word 
\section{whatever}\label{xyz} 
Hello word  \ref{whatever} % ref without label
\section{xyz}\label{xyz} 
Hello word (see section \ref{xyz})
\end{document}

On the other hand, see the .log file!

For instance, if you add \ref{baz} without the corresponding \label{baz}, you will see some like:

LaTeX Warning: Reference `baz' on page 1 undefined on input line 12.
...
LaTeX Warning: There were undefined references.

It warns you also of duplicates labels:

LaTeX Warning: Label `xyz' multiply defined.

Whereas showlabels and refcheck simply show the labels twice, but it could be hard to notice that are duplicates in a large document.

Edit

To list the pages numbers where each label and reference is, you can use the todonotes package, but this say noting about if three are unused label or orphan references:

mwe

\documentclass{article}
\usepackage[colorinlistoftodos]{todonotes}
\let\oldref\ref
\let\oldlabel\label
\renewcommand\ref[1]{\todo[fancyline,color=cyan!30]{R: #1}\oldref{#1}}
\renewcommand\label[1]{\todo[fancyline,color=red!30]{L: #1}\oldlabel{#1}}

\begin{document} \section{foo} Hello \label{foo} world. % label with ref \section{bah} Hello word (see section \ref{foo}) % ref with label \section{baz} \label{baz} % label without ref Hello word \section{whatever}\label{xyz} Hello word \ref{whatever} % ref without label \section{xyz}\label{xyz} Hello word (see section \ref{xyz})

\listoftodos[List of labels and references]

\end{document}

Fran
  • 80,769