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 want to duplicate some content without re-defining its labels. For example,


will emit a warning, because sec:foo is defined more than once. Is there any way to prevent the second \usebox from writing to the aux file?

share|improve this question
You basically can't, with this approach. When the \vbox is built, the \label command is translated into a whatsit that contains a \write instruction and it can't be disabled any more, because the vertical list is already packaged. – egreg Feb 6 '14 at 18:55
That's quite unfortunate. Is there any way to duplicate content without affecting what is to be typeset? My original intent was to typeset a bunch of labelled theorems multiple times. With a plain macro instead of a box, the theorem numbering counters (of course) were also incremented the second time, which I do not want. – Kristóf Marussy Feb 6 '14 at 19:57
There are two problems. (1) Avoid \label doing a \write in the later usages: this might be solved by absorbing the text as a macro replacement text; (2) “freezing” all counters to their current value. Could you be more specific about the problem and what counters you need to be frozen? – egreg Feb 6 '14 at 20:39
up vote 5 down vote accepted

I assume, you want to have the first \label intact and to disable the others. Then the following uses a trick:

  1. The box is created with two commands \BeginIgnoreAux{<id>} and \EndIgnoreAux before and after the original contents. These macros write markers into the .aux file with the result, the label stuff gets in between.
  2. If the .aux file is read, then the label stuff is executed as usual the first time. If \BeginIgnoreAux{<id>} is called more then once with the same <id>, then the label stuff is ignored. This avoids duplicate labels.
  3. LaTeX reads the .aux file twice. At the end of the document the .toc files are written, for example. Therefore Macro \AuxResetIgnoreStuff clears the <id>s.


% Macros inside the `.aux' file
    \global\expandafter\let\csname ignore@#1\endcsname\@empty
      \expandafter\global\expandafter\let\csname ignore@#1\endcsname\relax

% User commands


Reference to the first label: \ref{sec:foo}.


The .aux file contains:

\@writefile{toc}{\contentsline {section}{\numberline {1}Foo}{1}}
\@writefile{toc}{\contentsline {section}{\numberline {1}Foo}{1}}

And the .toc file:

\contentsline {section}{\numberline {1}Foo}{1}
share|improve this answer
Thanks! This works like a charm. :) – Kristóf Marussy Feb 7 '14 at 10:33

Your Answer


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.