1

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?

Johannes_B
  • 24,235
  • 10
  • 93
  • 248
charkh
  • 41

1 Answers1

3

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:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}

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

\end{document}

See following output:

Output

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

charkh
  • 41