# How to put a reference into nlset command of algorithm2e package

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.

-
Please provide complete, minimal documents, not just code snippets. Where does \nlset comes from? – Gonzalo Medina Oct 7 '12 at 14:57

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

\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.

-
Great, that works, thanks a lot... – Daniel Langr Oct 7 '12 at 16:59