1

So I was wondering if pdflatex was writing all the labels used from a main.tex document.

When you're working on a hundred pages-long document like a phd dissertation, it is humanly impossible to remember all the references and point to them :0 !

I ran into Tex editor able to recover all labels of a document
and How to get a list of all the labels in a LaTeX document in WinEdt

But I figured one may also wish to get one's labels without scrolling tex code, switching editor nor move to windows. That got me blowing some dust off the manual, and produce the small script below, but still...

The open question:
Does tex not provide a way to do that??

  • 3
    All labels are written out to the .aux file in lines beginning \newlabel. The mechanism is described in this answer. So looking for all instances of \newlabel in the .aux file will give you the information you are looking for. There is also a package showlabels that will print out the information in the margin of your output. – barbara beeton Jan 23 at 19:05
  • Thanks... it's a shame that there's no human readable for main.aux, and running through the .tex source has the advantage providing some context. Package showlabel looks good :) I'd also like avoiding scrolling over and over again through the whole pdf when working on a specific part though... – shevket Jan 23 at 19:39
  • If you use Window, it just to run the .aux through find with the /V switch: At a command prompt find /V "\\newlabel" myfile.aux > myfile.lab. Load myfile.lab in separate window in you preferred est editor. If you have several aux-files, use a for %i in (*.aux) do find /V "\\newlabel" >>myfile.lab-loop – Sveinung Jan 23 at 20:44
  • @barbarabeeton oi showlablels is the opposition:-) don't forget to mention te showkeys package (which does the same thing:-) – David Carlisle Jan 23 at 21:32
  • @babarabeeton yes linux, as per the bash script below! But then if you'd grep through the .aux then you'd might as well grep through all the *.tex using find! and I definitely prefer the ouput :) prints me directories, filenames, line numbers, context... – shevket Jan 24 at 11:56
3

All labels are written out to the .aux file in lines beginning \newlabel. The mechanism is described in this answer. So looking for all instances of \newlabel in the .aux file will give you the information you are looking for.

If using the .aux file for reference, copy it under a new name and use the copy, since the "original" will disappear as soon as the source file is recompiled.

If you are using a *nix system, you can launch (or script) the command grep \\newlabel *aux | main-labels.txt. This will produce a new file containing only the \label lines from the ,aux file. This can then be used as a reference.

A comment on the question by @Sveinung provides a similar method for Windows.

Finally, there are two packages that print out the label values on the pages where they are defined in your document:

  • showlabels

  • showkeys

Both packages report the values of labels that are accessed by \ref or \cite (and friends). Both provide options to include or exclude particular types of labels, and for specifying where to position the reported labels on the output. (See the package documentation for details.)

|improve this answer|||||
1

A good old shell solution :)

#! /usr/bin/sh
match="grep -THn -A 2 --colour" 
pattern='\\label{.*}'

find $1 -name "*.tex" | xargs -n 1 $match $pattern 

Edit: pass an optional directory argument: $ ./labels.sh chapX, as this may produce some output! Prints all matches with filename, line number and two lines of context (label highlighted).

|improve this answer|||||

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.