Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

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

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
Great, that works, thanks a lot... –  Daniel Langr Oct 7 '12 at 16:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.