I'm writing master thesis where I need to include some parts of program code. This code needs to be commented and properly described in text below/above. I would like to add some specific labels in the verbatim environment and use this labels as references in text. How can I do that?


Thanks for your help guys. Based on question Is there a possibility to make reference to the line in the lstlisting environment? I've finaly used following:


\begin{lstlisting}[frame=single, caption={Useless code}, label=useless_code, numbers=left]
 for i:=maxint to 0 do begin
   { comment }(*@\label{comment}@*) 
Line \ref{comment} of Listing~\ref{useless_code} shows a comment.


See following output:


I know that it is not optimal solution, but for the purpose of my thesis seems to be sufficient solution.

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.