trashus wrote:I got everything working when \numberwithin{lstlisting}{section} is called after \begin{document}, but I didn't like having anything other than the document itself after \begin{document}
Instead of patching listings.sty for this purpose you could use
Code: Select all
\AtBeginDocument{\numberwithin{lstlisting}{section}}
right after loading the listings package, this works, too.
I went into listings.sty and commented out these 2 lines (from the section of code in Stefan_K's previous post)
Changing packages is usually a very bad idea, because this makes your document giving a different result when run on a different machine.
This also works for subsections instead of sections, but this method DOES NOT work if you use \numberwithin{lstlisting}{chapter}. Perhaps someone else knows how to fix this?
Just place
into your document (after loading the (original) listings package).
I have attached my modified version of listings.sty.

And this is even a more bad idea, since it's against the license (LPPL) of the listings package! So please remove this attachment immediately, or give this modified version a different file and packaged name, and place your name + e-mail-address as maintainer. Thanks.
For further info on the license of the listings package, see listings.dtx and
http://www.latex-project.org/lppl/.