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.

I got a "LaTeX Warning: There were multiply-defined labels", and I know what it means but my document is pretty big and it has various files. So, how can I find the multiply-defined label?

I am using TeXShop in MacOS.

This is the whole warning (I believe):

------------------------------------------------------------------------------
 Bibliography
------------------------------------------------------------------------------
(./Thesis.bbl [29] [30] [31] [32] [33] [34] [35]) [36] (./Thesis.aux)
LaTeX Warning: There were undefined references.
LaTeX Warning: There were multiply-defined labels.
 )
share|improve this question
add comment

3 Answers

up vote 25 down vote accepted

The log message you quoted is a sort of "summary" of earlier, more detailed warnings, telling you exactly which references are undefined/multiply defined. Scroll up through the log file and you should find more detailed messages that look like the one below:

LaTeX Warning: Label `foo' multiply defined.
share|improve this answer
2  
Using grep "multiply defined" master.log worked like a charm for me. Thanks! –  David L Dec 12 '13 at 19:26
    
this doesn't occur if it is a label in the TOC (or doesn't for me) –  iant Mar 19 at 15:21
add comment

Besides looking into the .log file, the showlabels package could help you if you would like to check the labels in the output.

To check the input, you could open a terminal and grep for labels:

grep label filename.tex

This gives you a compact overview.

share|improve this answer
add comment

There are ways to find duplicate labels in complex documents that have not been mentioned in the other answers. To show how they work I will use a simple (non-complex) test case:

\documentclass{article}

\begin{document}

\section{Section 1}
\label{foo}

\section{Section 2}
\label{foo}

\end{document}

RefTeX

RefTeX can find duplicate labels with the function reftex-find-duplicate-labels which produce a list of all duplicate labels in the document. To use it simply do M-x reftex-find-duplicate-labels. When doing this on the file with the test case it opens a new buffer with the following content:

                MULTIPLE LABELS IN CURRENT DOCUMENT:
 Move point to label and type `r' to run a query-replace on the label
 and its references.  Type `q' to exit this buffer.

 LABEL               FILE
 -------------------------------------------------------------
foo
    ~/test/test.tex
    ~/test/test.tex

Perl

As noted by Walt Mankowski one can use a Perl one-liner to find duplicate labels. The one-liner is as follows:

perl -nE 'say $1 if /(\\label[^}]*})/' *.tex | sort | uniq -c | sort -n

To use it open a terminal and cd to the directory of the document you want to check for duplicate labels in and then execute the one-liner. The output for the test case is as follows:

      2 \label{foo}

Relatedly you may also want to check for unused labels.

share|improve this answer
    
This RefTex advice is worth gold. –  YuppieNetworking Oct 16 '13 at 21:58
    
the perl one-liner just saved my life :-) –  iant Mar 19 at 15:20
add comment

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.