I'm trying to do something similar to "Using the same figure twice with no new number", but with the algorithm2e package.
Therefore I wrote the following code.
\newcommand{\repeatAlgoCaption}[2]{%
\renewcommand{\thealgocf}{\ref{#1}}% modify the displayed label
\captionsetup{list=no}% not displayed in the list of algorithms
\caption{#2 (repeated from page~\pageref{#1})}% page reference of the original algorithm
\addtocounter{algocf}{-1}% the next figure after the repeat gets the right number
}
Using this code with hyperref produces the following error
! Argument of \reserved@a has an extra }.
<inserted text>
\par
I have no clue how to get this to work, any suggestion is appreciated.
This is my working MWE (without hyperref)
\documentclass{article}
\usepackage{caption}
\usepackage{algorithm2e}
% from https://tex.stackexchange.com/questions/200211/
\newcommand{\repeatAlgoCaption}[2]{%
\renewcommand{\thealgocf}{\ref{#1}}% modify the displayed label
\captionsetup{list=no}% not displayed in the list of algorithms
\caption{#2 (repeated from page~\pageref{#1})}% page reference of the repeted algorithm
\addtocounter{algocf}{-1}% the next figure after the repeat gets the right number
}
% \usepackage{hyperref}% The one guilty
% arara: pdflatex
% arara: pdflatex
\begin{document}
\begin{algorithm}[H]
\caption{my caption}\label{alg:mylabel}
\end{algorithm}
\begin{algorithm}[H]
\caption{my other caption}
\end{algorithm}
\begin{algorithm}[H]
\repeatAlgoCaption{alg:mylabel}{my caption}
\end{algorithm}
\begin{algorithm}[H]
\caption{my other caption}
\end{algorithm}
\end{document}
The output is
