I am using the \lstnewenvironment
to format a set of code listings in my document.
\lstnewenvironment{code}
{\lstset{language=haskell,
basicstyle=\small\ttfamily,
numbers=left,
numberstyle=\tiny\color{gray},
backgroundcolor=\color{lightgray},
firstnumber=auto
}}
{}
I would like to be able to give all these listings the same name, so that they will be continuously numbered, even if other listings (not using the code
environment) are scattered in between them.
However I cannot add the name
property using \lstset
. The top of page 11 of the listings manual indicates that there are certain properties that can only be set as options directly on the listing (and not in \lstset
). I suspect this is one of those properties. So I would have to do
\begin{code}[name=main]
...
\end{code}
on every listing. Is there some other way I can indicate that the code
environment should always carry that name
option?
Best Answer
Thanks to egreg, you can use a custom counter to keep track of the last line number and resume from there:
Code: