Saturday, April 26, 2008

LaTeX: hyperref/algorithm interaction

According to the hyperref documentation, the algorithm package should be loaded after hyperref:
\usepackage[chapter]{algorithm}% eg.
According to the hyperref documentation, all packages should be loaded before hyperref:
In most cases, therefore, you should load your package before you load hyperref, and hyperref will patch things up so that they work, so you can utilise your (patched) package after loading both:
If you do the first, you get this annoying set of warnings:
! pdfTeX warning (ext4): destination with the same identifier (name{page.1}) has been already used, duplicate ignored
If you do the second, you get an error:
undefined control sequence \theHalgorithm
Clearly, the first is preferable to the second, but even the first is terribly annoying. Does anyone have any ideas on how this can be fixed ?

Update: It works ! A comment from Iain Murray points out that in the hyperref README, one is told to include the float package BEFORE hyperref , and only then include algorithm (after hyperref).


  1. I have got the algorithm package to work by including it after hyperref, but manually include the float package (which algorithm will normally include for you) before hyperref. This is in the README file of recent versions of hyperref.

    I have had many problems with hyperref. These were mainly solved by using the latest version and carefully following all the instructions. Warning: this can lead to dependency hell. Once you put a more recent version of some LaTeX package in your ~/texmf directory you may have to grab more recent versions of many others too.

  2. One fix which I found is to use the second strategy and manually define the \theHalgorithms in your latex preamble as


  3. Your solution did not work for me but I found this:

  4. I agree with the algorithmic-fix package that Anonymous poster suggested. The new URL is here:

    I had to combine that and the float/hyperref/algorithm ordering to remove all warnings.

  5. Thanks Lian for the post! Problems are gone!

  6. I suggest to use the algorithm2e package instead of algorithm. It also defines an algorithm environment, and the hyperref linking works again.


Disqus for The Geomblog