Saturday, March 21, 2009

algorithmic-fix

If you try to use line numbers with the LaTeX algorithmic package and also hyperref, you are in trouble.  You get lots of annoying warnings about symbols being defined twice.  The solution is found here.
You need to include a little latex package called algorithmic-fix.sty, provided by the author of hyperref.  The content is:

\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\ProvidesPackage{algorithmic-fix}%
  [2008/02/27 v0.1 Fixes algorithmic for hyperref (capt...@sommerfee.de)]
% 1. Replace the two wrong \refstepcounter's with \stepcounter's
\begingroup
  \long\def\x#1\refstepcounter#2\@nil{%
    \endgroup
    \def\ALC@item[##1]{#1\stepcounter#2}}%
\expandafter\x\ALC@item[{#1}]\@nil
\newcommand\ALC@list{%
  \begingroup
    \long\def\x\refstepcounter##1\@nil{%
      \endgroup
      \def\ALC@it{\stepcounter##1}}%
  \expandafter\x\ALC@it\@nil
  \let\list\ORI@list\list}%
\renewcommand\ALC@setref{}%
% 2. Define a unique \theHALC@line
\newcounter{algorithmic}
\let\ORI@algorithmic\algorithmic
\def\algorithmic{%
  \stepcounter{algorithmic}%
  \let\ORI@list\list\let\list\ALC@list\ORI@algorithmic}
\def\theHALC@line{\thealgorithmic-\theALC@line}
% That's all
\endinput

No comments:

Post a Comment