12

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?

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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