# Is there a way to reference the line number in algorithm 2e?

Say I have algorithm appear as followed

Is it possible to reference the line number using ~\ref or any other possiblities?

-
You have accepted 50% of your answered questions. All your questions are excellent answered. We don't put any thanks in our question but you should thank users by upvoting [his/her] answer (with the upward pointing arrow to the left of it). Some users are ignoring questions where the OP has such an accepting rate. I am one of them. –  Marco Daniel Aug 7 '12 at 19:03

Yes, it's possible. :)Use the normal \label command in the line you want to refer (page 4 of the algorithm2e manual), then use \ref to display the line number.

\documentclass{article}

\usepackage[linesnumbered]{algorithm2e}

\begin{document}

Line \ref{alg:goto} is important.

\vspace{2em}

\begin{algorithm}[H]
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
\eIf{understand}{
go to next section\;\label{alg:goto}
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\end{algorithm}

\end{document}


The output:

-