9

I am writing a large document using LaTeX and WinEdt. I have labeled each chapter, section and so on. I would like to print out a list of just the labels (so that I don't duplicate one later on, and so that I have it handy in order to write \refs).

Is there a way to do this?

8 Answers 8

5

This can be done in a very simple manner directly within WinEdt:

  1. Show the Gather interface (from the View menu in WinEdt>=6)
  2. Press the Collect Items button in its toolbar
  3. Jump to the Label tab and there you can see all your labels

Also, you can now press the button Copy in the interface toolbar and paste it in a blank document to perform a search on your labels

7

I don't know about a list of labels, but you can try using the showkeys package from CTAN to print the labels in the margins wherever you define them. I use this in my final proof reading to make sure I have everything labeled and in order.

1
  • Thanks! That's useful, although it isn't exactly what I wanted.
    – Peter Flom
    Apr 6, 2011 at 19:57
7

I wanted a list of all the labels in my project and wasn't entirely satisfied with the answers listed here so I wrote a bit of Python to search through my LaTeX project files, find all the labels, and print them out by category. Here is an iPython notebook that demonstrates the code. This code presumes that all your labels are of the form chp:chapter_name or fig:fig_name. i.e. word characters with a colon in the middle. The regular expressions patterns can be modified to fit whatever convention you're using.

Here is the important part of the code:

# reg exp to find full label specifications
patt = re.compile("\\label{(\w*:\w*)}") 
# reg exp to find `addtotoc` labels
app_patt = re.compile("(\w+:\w+)")

lbls = []
for root, dirs, files in os.walk(chdir):
    for fn in files: 
        if fn == 'main.tex':
            # my project has some appendices that are pulled into
            # the project using includepdf and the labels for these
            # are specified using `addtotoc`. This if statement
            # finds those labels in main.tex.
            with open(os.path.join(root, fn)) as f:
                lbls.extend(re.findall(app_patt, f.read()))
        elif fn.endswith(".tex") and fn<>"zTemplateChapter1.tex":
            # there's a template file in my project that I don't
            # want to search for labels.
            with open(os.path.join(root,fn)) as f:
                txt = f.read()
                labels = re.findall(patt, txt)
                lbls.extend(labels)
typs = []
names = []
for lbl in lbls:
    t, n = lbl.split(':')
    typs.append(t)
    names.append(n)

The output for my project looks like:

app:
    depth_param_est
    param_est
    preprocessing
    water_column

chp:
    BPS
    Depth
    Intro
    OpticalRS
    ParamEst
    Water

sec:
    curve_fit_est
    lin_reg_est

fig:
    bps_fig1
    pd_K_ests
    pe_curve_fit
    pe_dwm_bars
    pe_linear_K_est
    pe_linear_K_est_dr
    pe_location_map
    pe_surf_corr_K
    wcc_depths
    wcc_imgcomp
    wcc_location_map
    wcc_method_comp
    wcc_parallel

tab:
    est_parameters

eq:
    albedo_plus
    geometric_factor
    k_from_slope
    linregress
    lyz_model_sag
    lyz_model_transformed
    lyz_shallow_water
    lyz_transform
    mar_sag_comp
    mar_wcc
    maritorena9a
    maritorena_albedo_subsurf
    maritorena_model
    maritorena_toa
    refraction
    sag_index_radiance
    sag_ref_index
    surf_correction
    surf_ref
    toa_refletance
    toar_deep
6

I had the same problem. I solved it with just a few code lines using the tocloft package. In my opinion the advantage over other solutions is the easy use (put it in an separate file or package and comment it in or out), it is easy to understand and it is easy to adapt to your own needs or to dublicate for other lists (i.e. citations, collect section names, counting your footnotes, ...).

\documentclass{article}
\usepackage{tocloft}

% create a new list incl. counter
\newlistof{labelTagCounter}{labelTags}{List of \textbackslash labeltags}

% redefine the  label command
\let\myLabel\label
\renewcommand{\label}[1]{
\refstepcounter{labelTagCounter}% step the counter
\addcontentsline{labelTags}{labelTagCounter}{\thelabelTagCounter:\quad#1}% add item to list
\myLabel{#1}% now execute the original label command
 }

\AtEndDocument{
\cleardoublepage
\listoflabelTagCounter% print the list
}

\begin{document}
Lorem ipsum dolor\label{labelA} sit amet, consetetur sadipscing elitr\label{labelB},  sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam\label{labelC} erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr,  sed diam nonumy eirmod tempor invidun\label{labelA}t ut labore et dolore magna aliquyam erat, sed diam voluptua\label{labelD}. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr,  sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat\label{labelC}, sed diam voluptua. At vero eos et accusam et justo duo\label{labelC} dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
\newpage
Duis autem vel eum iriure dolor in\label{labelE} hendrerit in vulputate velit esse molestie consequat, vel illum\label{labelA} dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue\label{labelC} duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
\end{document}
2

I do not have WinEdt. So I cannot test the following in WinEdt.

You could use the lablst.tex file. Compile lablst.tex file.
(That is, do Something like latex lablst.tex)

(1) It will ask you to type the name of your latex file. Enter the name of your latex file. (For example, if the name of your latex file is myfile.tex then type myfile.)

(2) It will ask you to type the document class. Enter the document class. (For example, if your document class is article then enter article)

(3) It will ask you to type the list of packages you used. (you can just hit enter fro this or, if you prefer, type the list.)

Then it will produce a file with a list of all the labels you have used. The following is an example. My file name is test.tex, which is given below. (I used TeXShop to do this.)

\documentclass[12pt]{article}
\begin{document}

\section{Table of Contents}\label{toc}
The \verb-\tableofcontents- command produces table of contents.

\subsection{List of figures\label{list} and Tables}\label{lof}
The commands \verb-\listoffigures- and \verb-\listoftables- produce
list of figures and list of tables, respectively. 

\section{Cross Referencing}
You can assign a \textit{key} of your choice to a \verb-figure-, a \verb-table-, 
an \verb-equation-, \verb-equation array-, \verb-enumerate-, \verb-theorems- 
or a \verb-section-.  The key is assigned a number by the \verb-\label- command  
and the number is printed by the \verb-\ref- command.  For example, 
``see section~\ref{toc} for table of contents" can be produced by 
\verb-see section~\ref{toc} for table of contents-.  \verb-toc- is the key assigned 
to section 1 by \verb-\label{toc}-. 

\subsection*{labeling words}
You can label a word with a key and refer to it back using \verb-\pageref- command.  
For example, the list of figures sub-section appears on page~\pageref{list}.

\end{document} 

The following is the lablst.tex output.

enter image description here

2
  • I don't have it too but I remember this was a feature on v5. There is a Build Tree option which would collect all references, bibliography entry keys etc. Then, you can see the existing ones either while typing or, if I remember correctly, using <kbd>Ctrl</kbd>+<kbd>Enter</kbd>.
    – percusse
    Dec 26, 2011 at 20:18
  • 1
    A better answer is to use egreg's newlablst.sty. Copy newlablst.sty into your ~/texmf/tex/latex/ folder. Then include \usepackage{newlablst} to your preamble. See an example at github. Label list will be printed at the end of your output document.
    – Sony
    Dec 29, 2011 at 0:20
1

This answer does not explicitly use WinEdt, but will display a list of labels in the document itself, with hyperlinking, if needed:

The crossreftools package provides a \crtlistoflabels macro, that is available unless the final option is used.

enter image description here

Please compile at least twice in order to get the cross - referencing information correctly.

In any case, load crossreftools quite at the end of the preamble.

The labels are stored separately again in a .lla file.

\documentclass{book}

\usepackage{hyperref}
\usepackage{crossreftools}

\begin{document}
\crtlistoflabels

\chapter{Foo}\label{foochapter}

\section{A foo section}\label{foosection}

\begin{figure}

  \caption{Foo} \label{foofigure}
\end{figure}


\end{document}
1

The way I do it in WinEdt 10:

  1. Make sure that auto-complete is not disabled (Options-> Preferences -> Editor un-check "Disable Auto-complete")
  2. Anywhere in the document type "\ref" and, in the popup menu, double click "\ref{***}"
  3. You get a list of all labels with repetitions. Double click one of them and remember the line number
  4. Close the list of the labels and go to that line: ctrl_g
0

In the .log file, you can see the warning where duplicate labels are listed. Then, get to the Search/Find menu -> Select "Find in Files" and type in the duplicate label to navigate where they are in the file(s).

1
  • 2
    The question does not ask about duplicate labels, but all labels in a document.
    – mafp
    Apr 1, 2014 at 22:22

You must log in to answer this question.

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