TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
    
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
up vote 8 down vote accepted

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}
share|improve this answer
    
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 Jul 26 '14 at 22:16
    
In the meantime the package has become part of TeXlive and MiKTeX. – NobbZ Aug 4 '14 at 15:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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