6

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.

  • 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 ? – David Carlisle Nov 30 '13 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 – David Carlisle Nov 30 '13 at 11:33
11

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.