# Print pages with refs [duplicate]

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.)

• Maybe I'm missing something, but simply issuing \ref directives after each and every \label directive won't tell you whether the item being cross-reference in this manner are also cross-referenced elsewhere in the document. Please clarify what you're trying to achieve,. – Mico Aug 15 '20 at 19:07
• @Mico right --- it was not clear --- it is fixed now, sorry. – Anton Petrunin Aug 16 '20 at 2:12
• – Henri Menke Aug 16 '20 at 6:12
• @HenriMenke --- it is a different question. – Anton Petrunin Aug 17 '20 at 1:43
• @AntonPetrunin From what I understand it's the same, which indicates that your question is unclear. Maybe you should try to do a better job at stating your problem in the future. – Henri Menke Aug 17 '20 at 3:24

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

\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{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:

\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}

• I updated my question (it was not formulated sufficiently clear, sorry). – Anton Petrunin Aug 16 '20 at 2:14
• @AntonPetrunin Still it is not clear for me what you want exactly, bur see if the added to the answer gets closer. – Fran Aug 16 '20 at 3:08
• I simply want a list of page-numbers prineted next to each label --- those pages that contain refs. – Anton Petrunin Aug 16 '20 at 3:26