2

I would like to provide an alternative version of only some part of already existing algorithm, using the algorithm2e package. My source looks like:

\begin{algorithm}[t]
\dots \;
\nlset{\ref{alg:previous:ref}} alternative line content \;
\dots \;
\end{algorithm}

This source however result in the following compilation error: ! Argument of \reserved@a has an extra }.

Any help?

EDIT

Minimal document that simulates the error:

\documentclass{article}
\usepackage{algorithm2e}
\usepackage{hyperref}
\begin{document}

\begin{algorithm}
line content \; \label{alg:previous:ref} 
\end{algorithm}

\begin{algorithm}
\nlset{\ref{alg:previous:ref}} alternative line content \;
\end{algorithm}

\end{document}

The problem seems to occur when hyperref package is loaded, without it works well.

1
  • Please provide complete, minimal documents, not just code snippets. Where does \nlset comes from? Commented Oct 7, 2012 at 14:57

1 Answer 1

2

You can extract the reference number and store it in a counter using refcount. Here's your MWE, now working with hyperref:

enter image description here

\documentclass{article}
\usepackage{algorithm2e}% http://ctan.org/pkg/algorithm2e
\usepackage{refcount}% http://ctan.org/pkg/refcount
\usepackage{hyperref}% http://ctan.org/pkg/hyperref
\newcounter{mycount}% To store extracted references
  % Default printing using \themycount will be \arabic
\begin{document}

\begin{algorithm}
line content \; \label{alg:previous:ref} 
\end{algorithm}

\begin{algorithm}
\setcounterref{mycount}{alg:previous:ref}%
\nlset{\themycount} alternative line content \;
\end{algorithm}

\end{document}

Of course, the reference itself is lost. However, I'm not sure whether you were interested in keeping the hyper reference since it's difficult to understand the context it's used in.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .