0

I'm trying to have two copies of the same algorithm, with the same number twice in a paper. The restatable environment is able to reproduce the algorithm but introduces a new algorithm number each time it is restated.

For example:

\begin{restatable}{algorithm}{myAlgo}
   \vdots
\end{restatable}
% ...
\myAlgo*  % will introduce a new number, even when using *

Question: Is there a (simple) way to restate an algorithm while using the same number as before.

Note: this question is extremely similar to this one. However, no answer was provided there and the question was (inexplicably, to me) closed.

Zuza
  • 103

1 Answers1

1

The counters that don't increment with restatable are stored in the comma-separated list \thmt@innercounters. By default it only contains equation. You can redefine this to use the algorithm counter, which at least for algorithm2e is algocf.

\documentclass{article}
\usepackage{algorithm2e,thmtools}

\makeatletter \def\thmt@innercounters{equation,algocf} \makeatother

\begin{document}

\begin{restatable}{algorithm}{myAlgo} \SetAlgoLined \KwData{this text} \KwResult{how to write algorithm with \LaTeX2e } initialization; \While{not at end of this document}{ read current; \eIf{understand}{ go to next section; current section becomes this one; }{ go back to the beginning of current section; } } \caption{How to write algorithms} \end{restatable}

\myAlgo*

\end{document}

algos

mbert
  • 4,171