Maybe not a TeX question, but are there a some common way to refer specific line in listing, like:
"In listing 1.2.3:10 we see this and that..." (i.e., line 10).
And also line range, like "listing 1.2.3:10-14".
I just hate idea to write "... at line x ...", or "... at lines from x to y ...", etc.
General ⇒ Referring line in listing
NEW: TikZ book now 40% off at Amazon.com for a short time.

-
- Posts: 707
- Joined: Tue Mar 25, 2008 5:02 pm
Referring line in listing
I refer you to Section 7 of the listings manual, which has a heading that says, "How to reference line numbers."
Their example has something like this (for Pascal, which uses (* and *) as "digraph" comments):
Depending on the language, it should be possible to introduce something that (a) notifies the listings package not to typeset that particular comment but instead treat it as an actual comment, and (b) preserves the programming languages comment rules. For example, in C, you could use something like
or something like
for shell scripts.
Their example has something like this (for Pascal, which uses (* and *) as "digraph" comments):
Code: Select all
\lstset{escapeinside={(*@}{@*)}}
\begin{lstlisting}
for i:=maxint to 0 do
begin
{ my comment }(*@\label{comment}@*)
end;
\end{lstlisting}
Line \ref{comment} shows a comment.
\lstset{escapeinside={/*@}{*/}}
or something like
\lstset{escapeinside={#%}{\^^M}}
for shell scripts.