Take the 2-minute tour ×

Trying to retroactively get hyperref working for my thesis.


Encountered the following weirdness... I have the following (hard earned) minimal-ish working example:


% \usepackage{mypackage}



\section{Section One}
See Definition~\ref{def:one}.



\section{Section Two}
When using external \texttt{mypackage}, Definition~\ref{def:two} \texttt{hyperref}'s to Definition~\ref{def:one}---otherwise it's fine.



Which works fine after a couple of builds. However, if I put the newtheorem command (LINE 1) into a new custom mypackage.sty as follows:



...stick it in the same directory as the main file, and toggle the comments on LINE 0 & 1 in the main file, after a couple of builds I get a warning:

pdfTex warning (ext4): destination with the same identifier (name{definition.1}) has already been used, duplicate ignored

Also, in the resulting PDF, the label for the second Definition links to the first one.

Now, I have my fix (move the newtheorem declaration into my main .tex file)...

...but I've been held hostage by hyperref for so long this time, I've developed Stockholm syndrome. (Looking back at my history with this package, it was only a matter of time.)

Can someone give me some closure and explain why hyperref cares where I put my newthereom declaration?

Otherwise, can someone point me in the direction of a hyperref victim support group?

share|improve this question
Related: tex.stackexchange.com/questions/7540/… –  badroit Mar 10 '11 at 2:46
See in the readme.pdf of hyperref section 8 "Subordinate counters" for an explanation and solutions. You can use \AtBeginDocument to move the \newtheorem behind hyperref in your package. –  Ulrike Fischer Mar 10 '11 at 8:51
add comment

1 Answer

up vote 8 down vote accepted

hyperref needs to patch many LaTeX commands (and commands offered by other packages) to make proper hyper links happen, and one of them is \newtheorem. So if you include your package before the hyperref package, the \newtheorem inside your package will use the original definition by LaTeX and not the patched one by hyperref.

So the solution to your problem is to include your package after the hyperref package.

As a general rule one can say that packages that offer commands (which will be patched by hyperref, or which uses itself commands which will be patched by hyperref) have to be included before hyperref. Packages that just uses these commands have to be included after hyperref. (And usage of these commands in a document has to be done after including hyperref.)

Another example: The float package offers \newfloat, and this one needs to be patched by hyperref. So wenn using \newfloat, one has to include the float package first (so \newfloat gets defined), the hyperref package afterwards (so \newfloat gets patched), and finally one can use the (patched) \newfloat command.

See also: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=hyperdupdest

share|improve this answer
Usually I add hyperref as a last step for putting a document online... it's always a painful process, mainly because I never took the time to learn what hyperref actually does. This answer will help me avoid such pain in future. Many thanks for that! –  badroit Mar 10 '11 at 20:47
add comment

Your Answer


