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?
Asked
Active
Viewed 2,131 times
1
1 Answers
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:

I know that it is not optimal solution, but for the purpose of my thesis seems to be sufficient solution.
numberedblockpackage, http://tex.stackexchange.com/questions/202966/how-can-i-show-codeboxes/202969#202969 – Steven B. Segletes Dec 27 '14 at 12:52