14

I was wondering if it is possible to refer to the lines of the code enclosed in lstlisting environment rather than just manually write a number of the line I want to describe. I have never met with this feature, is this available?

Werner
  • 603,163
MichalB
  • 263

1 Answers1

29

At page 53 in the manual you will find the section How to reference line numbers with the following example:

\lstset{escapeinside={(*@}{@*)}}
\begin{lstlisting}
 for i:=maxint to 0 do begin
   { comment }(*@\label{comment}@*) 
 end;
\end{lstlisting}
Line \ref{comment} shows a comment.
Marco Daniel
  • 95,681