Take the 2-minute tour ×
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.

This question is related to the question How to get a list of all the labels in a LaTeX document. According to the author of lablst.sty, you can use lablst as a global option to documentstyle as \documentstyle[11pt,lablst]{article} to produce (a list of) label definitions at the end of the document.

Can this be updated so that it can be used with documentclass?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

You can try with this newlablst.sty to be called by \usepackage{newlablst}:

\RequirePackage{atveryend,ltxcmds}
\AtVeryEndDocument{\@lablst}
\def\@lablst{
  \parindent 0pt \parskip 0pt
  \normalsize
  \newwrite \labfile \relax
  \immediate\openout \labfile =\jobname.lab\relax
  {\def\toc{toc}
   \def\@writefile##1##2{\def\temp{##1}%
     \ifx\temp\toc
       \immediate\write\labfile{\unexpanded{##2}}%
     \fi}
   \def\newlabel##1##2{\immediate\write\labfile{\string\newlabel{##1}{##2}}}
   \def\bibcite##1##2{\immediate\write\labfile{\string\bibcite{##1}{##2}}}
   \makeatletter
   \input \jobname.aux }
   \immediate\closeout\labfile
   \def\newlabel##1##2{\par \hbox to \textwidth
     {\hfill\makebox[10em][l]{\ttfamily ##1}\makebox[3.5em][l]{\first 
      ##2}\hspace{1em}Page:\makebox[3em][r]{\second ##2}\hspace{4em}}}
   \ltx@ifpackageloaded{hyperref}
     {\def\first##1##2##3##4{##1}\def\second##1##2##3##4{##2}}
     {\def\first##1##2{##1}\def\second##1##2{##2}}
   \def\bibcite##1##2{\par\makebox[2in][l]{\ttfamily ##1}[##2]\par}
   \input \jobname.lab
   \clearpage
}

EDIT

This is perhaps a more robust version; it's just the more modern lablst.tex:

\RequirePackage{atveryend,ltxcmds}
\def\@lablst{%
  \ltx@ifpackageloaded{hyperref}
    {\long\def\x@firstoftwo##1##2##3##4{##1}%
     \long\def\x@secondoftwo##1##2##3##4{##2}}
    {\long\def\x@firstoftwo##1##2{##1}%
     \long\def\x@secondoftwo##1##2{##2}}
  \let \@mlabel \@gobbletwo
  % No protection needed:
  % 
  \let \protect \relax
  % Better formatting?:
  % 
  \let \raggedright  \relax
  % Only write out toc entries:
  % 
  \def \@writefile ##1##2{%
    \def\lablst@tempa{##1}%
    \def\lablst@tempb{toc}%
    \ifx \lablst@tempa\lablst@tempb
      \par{##2}\par\nobreak
      \vspace{3pt}%
    \fi
  }
  % Allow characters like ^ _ to be printed `verbatim'.
  %
  \def\@lablstverb##1{%
    \def\lablst@tempa{##1}%
    {\ttfamily\expandafter\strip@prefix\meaning\lablst@tempa}}%
  % For first run:
  % 
  \def \newlabel ##1##2{%
    \par
    \hbox to \textwidth{%
      \hfill\makebox[10em][r]{\@lablstverb{##1}}%
      \hspace{1em}\makebox[4.5em][l]{\x@firstoftwo ##2}%
      Page:
      \makebox[2.5em][r]{\x@secondoftwo ##2}%
      \hspace{4em}}\par
  }
  \let \bibcite \@gobbletwo
  {\Large \sl Logical labels within sections}
  \input{\jobname.aux}
  % For second run:
  % 
  \def \bibcite ##1##2{\par
    \hbox to \textwidth{%
    \hfill\makebox[2in][r]{\@lablstverb{##1}}\hspace{1em}[##2]\hspace{4em}}}
  \let \newlabel \@gobbletwo
  \let \@writefile \@gobbletwo
  \par
  \vspace{2\baselineskip}
  {\Large \sl Bibliography logical labels} 
  \input{\jobname.aux}\clearpage
}

This seems to works also with hyperref.

share|improve this answer
    
This is great! This should be another (better) answer to (tex.stackexchange.com/q/15101/7764). –  Sony Dec 27 '11 at 17:10
    
I don't know how robust it is; things have changed from 1985 and something appearing in the .aux file might break this hack. –  egreg Dec 27 '11 at 17:14
    
I added a bibliography with one \bibitem to my test.tex in my answer to (tex.stackexchange.com/q/15101/7764) to further test newlablst.sty. It produced the following LaTeX error. ! LaTeX Error: Something's wrong--perhaps a missing \item. l.2 ...ction}{\numberline {1}Table of Contents}{1} You can see the test.tex at (text-upload.com/read.php?id=234036&c=8132979). –  Sony Dec 27 '11 at 20:24
    
Add \par at the end of the \bibcite line (I did in my edit). –  egreg Dec 27 '11 at 20:51
    
test.tex file no longer available at text-upload.com. It is now available at github for you to test egreg's wonderful newlablst.sty. –  Sony Dec 29 '11 at 0:14

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.