13

I get the warning

pdfTeX warning (ext4): destination with the same identifier 
(name{ALG@line.2}) has been already used, duplicate ignored

with the MWE down below.

\documentclass{article}

\usepackage{algpseudocode}
\usepackage{hyperref}
\usepackage{cleveref}

\begin{document}
\begin{algorithmic}
\Procedure{Euclid}{$a,b$}
\EndProcedure
\end{algorithmic}

\begin{algorithmic}
\Procedure{Euclid}{$a,b$}
\EndProcedure
\end{algorithmic}
\end{document}

Is there a chance to fix that?

1 Answer 1

13

You should change the load order (pushing algpseudocode after hyperref) and redefine the way hyperref looks at destinations for lines within algorithmic:

\documentclass{article}

\usepackage{hyperref}
\usepackage{algpseudocode}
\usepackage{cleveref}

\makeatletter
\newcounter{algorithmicH}% New algorithmic-like hyperref counter
\let\oldalgorithmic\algorithmic
\renewcommand{\algorithmic}{%
  \stepcounter{algorithmicH}% Step counter
  \oldalgorithmic}% Do what was always done with algorithmic environment
\renewcommand{\theHALG@line}{ALG@line.\thealgorithmicH.\arabic{ALG@line}}
\makeatother

\begin{document}
\begin{algorithmic}
\Procedure{Euclid}{$a,b$}
\EndProcedure
\end{algorithmic}

\begin{algorithmic}
\Procedure{Euclid}{$a,b$}
\EndProcedure
\end{algorithmic}
\end{document}

Above I've made each line be referenced using ALG@line.<algnum>.<linenum> where I've inserted <algnum>. as a newly made counter (incremented at every use of algorithmic). This makes line number X in one algorithm distinguishable from the same line number X in another.

Not sure whether this affects algorithms that are saved and restored.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.