I'm editing a book that includes about 25 papers written in LaTeX by different authors. Since many of them use the same \label, to avoid collisions I redefined the \label command (and \ref and \pageref and \cite and \bibitem) so that if the third paper has \label{main_theorem} the aux file actually uses the tag "iii:main_theorem", and \ref{main_theorem} actually refers to the same tag. I did a similar thing for \cite and \bibitem.

%*************** bib/cite hacks
\advance\count@ 1
%************** label/ref/pageref hacks  %%%%%%%%%%%%% must be before ams pkgs

This all worked fine until I used hyperref, which seems to ignore the redefinition of \label, whether I load it before or after the above code.

Any suggestions? It would be nice if the redefinition would work whether or not hyperref was loaded, so I don't want to just grab the defintion of \label out of the package and tweak it.

I'm also open to alternative methods. Redefining \label and \ref just seemed the most straightforward (to me) solution.

Note that I also want to be able to refer to the inner labels from outside, as well. For example, I might want to say "the main theorem of the third paper is \ChapRef{iii}{main_theorem} from within the introduction (a different chapter).

1 Answer 1


Because some redefining of \label/\ref by hyperref/nameref is done via \AtBeginDocument, you have to use it also at a later time after the packages are loaded:


  % redefining \label, \ref, \pageref (\renewcommand or \DeclareRobustCommand)

Updated with egreg's comment. \LetLtxMacro of package letltxmacro takes care of macros that are defined via \DeclareRobustCommand (or as macros with optional parameters).

  • Using \LetLtxMacro{\TheRealRef}{\ref} and the same for \TheRealPageref, since hyperref redefines the two commands with \DeclareRobustCommand
    – egreg
    Commented Dec 7, 2012 at 15:25
  • @HeikoOberdiek This worked for some things, but not for others. In particular, something like \begin{equation}\label{e1} f(x)=x^2 \end{equation} calls the original \label (well, it puts \newlabel{e1}... into the .aux file), while \begin{theorem}\label{t1} blah blah\end{theorem} adds the modified tag. Commented Dec 7, 2012 at 18:41
  • I think the issue is a collision with \usepackage{amsmath}. I'll look some more. Commented Dec 7, 2012 at 18:58
  • The issue is that amsmath.sty also redefines \label, saving the old value in \ltx@label. This means that either \label needs to also be redefined BEFORE amsmath.sty is loaded, or \ltx@label needs to be set to be the same as the new \label in the \AtBeginDocument Commented Dec 8, 2012 at 15:33
  • So all seems good now. Thanks for the rapid help. Commented Dec 9, 2012 at 20:45

You must log in to answer this question.

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