Computer code in document?

berntl's picture

I'm writing a document containing computer code snippets. I have traditionally used Typewriter font style for in-line code, and Verbatim for blocks of code. I'm wondering if there are better ways to do this:

* Some books use a greyish background for computer code blocks (an extension of verbatim??)
* Sometimes, I'd like to make references to a another block, e.g. if the code of the current block is a continuation of past blocks so that the readers should know that the past code must be run first (I'm talking about dynamic languages such as Matlab, Python, etc.). Thus, ideally it should be possible to number the code and give it a caption just like for tables and figures.
* Sometimes, I need to insert a block of code in another environment such as a list. I haven't found a nice way to do this...

I'm grateful for suggestions!

After some searching on

After some searching on comp.text.tex, the listings package seems like something to investigate.  See and you can view the package documentation by using the .pdf link.  This package is not included with SW, so it would need to be installed and then referenced in your document via the Go Native method.