Saturday, April 26, 2008

LaTeX: hyperref/algorithm interaction

According to the hyperref documentation, the algorithm package should be loaded after hyperref:
algorithm:
\usepackage{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).

6 comments:

  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.

    http://www.gatsby.ucl.ac.uk/~iam23/compnotes/latex.html#hyperref

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

    \newcommand{\theHalgorithm}{\arabic{algorithm}}


    http://www.mail-archive.com/lyx-users@lists.lyx.org/msg10118.html

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

    http://users.encs.concordia.ca/~w_jiewen/LaTeX/qa.htm

    http://users.encs.concordia.ca/~w_jiewen/LaTeX/algorithmic-fix.sty

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

    http://www.cs.uwaterloo.ca/~j55wu/LaTeX/qa.htm

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

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

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

    ReplyDelete

Disqus for The Geomblog