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

\refor\ref*don't work? – Emanuele Nardi Mar 28 '21 at 10:33\refuses the aux file to get the information and therefore contains code which isn't easy to handle, at least not for me who isn't a TeX freak. Furthermore things like\refdo not deliver the needed information on the 1st LaTeX run. Both are reasons - at least for me - to store and restore\thealgocon my own. (Luckily we don't need back references here.) So in short: I have no clue why\refor\ref*does not work here but since I'm not a TeX freak I guess I would not even understand the explanation. But I'm looking forward to a better solution for this problem than mine. – Mar 28 '21 at 12:27