7

I'm writing a document with several \label{} environments and I'm looking for an opportunity to generate a list of all of them at the beginning, something like this:

Label 1 ..... 1
Label 2 ..... 2
Label 3 ..... 4

And so on. I had a look at tocloft but couldn't find anything.

2
  • do you actually want to print the internal symbolic label for debugging (like showkeys package) or print the referencable counter saved in the label at that point. so after \section{introduction}\label{xyz} do you want your list to have the section number 1 or the internal lablel xyz ? Commented Nov 30, 2013 at 11:32
  • It always helps to provide a complete small document, it simplifies testing answers and you could be explicit about the list you wanted to generate Commented Nov 30, 2013 at 11:33

1 Answer 1

14

enter image description here

The label information is all in the aux file, so you can extract it something like this:

\documentclass{article}

\usepackage{hyperref}

\long\def\findlabel#1#2\findlabel{%
 \ifx\newlabel#1\lablist\expandafter{\the\lablist\showlabel#2}\fi}

%hyerref has 4 felds in each label culd use them but don't here
\def\showlabel#1#2{%
\par \noindent Label: \texttt{\detokenize{#1}}\dotfill \ref{#1} on page \pageref{#1}}

\newtoks\lablist
\newread\zz
\immediate\openin\zz=\jobname.aux
\loop
\ifeof\zz\else
\read\zz to \tmp
\expandafter\findlabel\tmp\relax\findlabel
\repeat
\begin{document}

\section*{Labels}

\the\lablist

\section{ho ho ho}\label{z}
zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz 
zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz 
zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz 
zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz 
zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz 
\subsection{him hum hum}\label{zz}
zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz 
zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz 
zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz 
zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz 
\begin{equation}
1=2\label{q}
\end{equation}
zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz 
zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz 
zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz 

\begin{figure}

X\\X\\X\\X\\X\\X\\X\\X\\X\\
X\\X\\X\\X\\X\\X\\X\\X\\X\\
X\\X\\X\\X\\X\\X\\X\\X\\X\\
X\\X\\X\\X\\X\\X\\X\\X\\X

\caption{figure figure figure}\label{ff}
\end{figure}

\end{document}
2
  • 2
    Based on your solution, I created a package available from github github.com/NobbZ/listlbls , it is also available from CTAN ctan.org/pkg/listlbls.
    – NobbZ
    Commented Jul 26, 2014 at 22:16
  • In the meantime the package has become part of TeXlive and MiKTeX.
    – NobbZ
    Commented Aug 4, 2014 at 15:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .