TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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 using winedt 6.0 and a SIAM template in my document. When I compile, I get an error message stating:

! SIAM Label Error: There were multipy-defined labels

Correct multiply-defined labels.
Type H <return> for immediate help.
...
l.14 \newlabel{L2norm}{{2.2}{3}}

Based upon the last line, I presume the duplicate label is L2norm. Am I correct to assume this? I followed the advice on this post to find this multiply defined label. As it turns out, I used to have a label 'L2norm', but have since changed it to 'L2normerr'. No other labels are have this string and I haven't found any other duplicate labels (just using a <ctrl-f> search). I'm sure I'm misunderstanding something, but I'm not sure what... Please help! :)

share|improve this question
1  
the job is probably using an old .aux file, created before you changed the label. delete the offending .aux file, or rerun the job (twice) and the error message should go away. if it doesn't, the advice in your cited post is useful to help you find the straggler. – barbara beeton Dec 13 '12 at 18:18
    
@barbarabeeton: That worked! Magically, everything is fine now. I'm curious why the old .aux file didn't just get overwritten? Is there a way to make sure it creates a new .aux file each time? – Paul Dec 13 '12 at 20:14
up vote 5 down vote accepted

the job is probably using an old .aux file, created before you changed the label. delete the offending .aux file, or rerun the job (twice) and the error message should go away. if it doesn't, the advice in the post you cited is useful to help you find the straggler.

why is this happening? when a label is changed between runs, the next latex run begins by reading in the existing .aux file (with the old label). only then does it create a new .aux file (with the new label), to be read in on the next run. so the values of labels (and other "saved" material, like the table of contents) are always one run behind.

perhaps you've noticed that there's no table of contents, and cross-references are shown as ?? after your first run. that's because there's no .aux file available until that run is completed. if you really want to be sure your labels are correct, you can restart the cycle by deleting all .aux (and .toc, .lof and .lot) files when you make changes that will affect their values. when you see ?? in your output, that's a strong reminder that another run is needed.

share|improve this answer

Sometimes it can be hard to find the duplicated labels, if the error message has no useful info. If you have Python 3 on your system, you can use the following solution (it should also work with Python 2 under small modifications). Paste the code below into a text file and save it as find_duplicates.py:

#find_duplicates.py (python code)
#inputs: path to tex file
#prints all labels of the form \label{something} that occur more than once

import sys
import re

filename = sys.argv[1]

f = open(filename,'r')

file = f.read()
f.close()

#find all the \label{something} and get something
g = re.compile('\\label\{\w*\}')
labels = g.findall(file)
sortedLabels = sorted(labels)

#get labels that occur more than once

labelCounts = {}
repeatedLabels = []

for label in labels:
    if(label) in labelCounts:
        labelCounts[label] = labelCounts[label]+1
        repeatedLabels.append(label)
    else:
        labelCounts[label] = 1

print('repeated labels: ',repeatedLabels)

Then, in your command line, type:

python find_duplicates.py name_of_your_tex_file.tex

The output will be a list of duplicate labels. You can then go into your tex file and remove the duplicates.

share|improve this answer

In most cases, the above solution worked for me. However, in some cases I needed to quickly finish my document and wasn't able to fix the problem using the above approach. So a quick and dirty fix may be given by adapting siamart.cls (for me lines 1147 - 1176):

\gdef\@siamlabel@error#1#2{%
   \GenericError{%
      \space\space\space\@spaces\@spaces\@spaces
   }{%
      SIAM Label Error: #1%
   }{%
      Correct multiply-defined labels.%
   }{#2}%
}

%%% NEW -- causes multiply defined labels to generate errors
\def\@newl@bel#1#2#3{%
  \@ifundefined{#1@#2}%
    \relax
    {\gdef \@multiplelabels {%
      \@latex@warning@no@line{Label `#2' multiply defined}}%
      \@siamlabel@error{There were multiply-defined labels}{}}%
  \global\@namedef{#1@#2}{#3}}
\def\newlabel{\@newl@bel r}
\@onlypreamble\@newl@bel
\let \@multiplelabels \relax
\def\label#1{\@bsphack
  \protected@write\@auxout{}%
         {\string\newlabel{#1}{{\@currentlabel}{\thepage}}}%
  \@esphack}
\def\refstepcounter#1{\stepcounter{#1}%
    \protected@edef\@currentlabel
       {\csname p@#1\endcsname\csname the#1\endcsname}%
}
%%%

Simply erase/comment out the latter part, i.e.

%%% NEW -- causes multiply defined labels to generate errors
%\def\@newl@bel#1#2#3{%
%  \@ifundefined{#1@#2}%
%    \relax
%    {\gdef \@multiplelabels {%
%      \@latex@warning@no@line{Label `#2' multiply defined}}%
%      \@siamlabel@error{There were multiply-defined labels}{}}%
%  \global\@namedef{#1@#2}{#3}}
%\def\newlabel{\@newl@bel r}
%\@onlypreamble\@newl@bel
%\let \@multiplelabels \relax
%\def\label#1{\@bsphack
%  \protected@write\@auxout{}%
%         {\string\newlabel{#1}{{\@currentlabel}{\thepage}}}%
%  \@esphack}
%\def\refstepcounter#1{\stepcounter{#1}%
%    \protected@edef\@currentlabel
%       {\csname p@#1\endcsname\csname the#1\endcsname}%
%}
%%%

However, note that this prevents the template from detecting multiply-defined labels (i.e. multiply defined labels are skipped and not rendered).

share|improve this answer

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.