When I write documents that contain source code examples and snippets the listings package is a great solution to include such things. Especially with the \lstinputlisting
command and firstline
/lastline
options you don't have to do copy/pasting and you are able to easily test your examples.
But what about the integration of command line sessions? For example a bash
session, a session in the Haskell interpreter hugs
or in the Python shell?
Ideally I would like to be able to write something like this in LaTeX:
\begin{hugs}[nostartbanner]
take 3 [1..]
reverse "hello world"
\end{hugs}
And get following output in my document:
Hugs> take 3 [1..] [1,2,3] Hugs> reverse "hello world" "dlrow olleh"
(perhaps plus some syntax highlighting)
That means such an environment should automagically start an external shell (e.g. hugs) and should paste the session output in the document. And for bonus points it should do some caching of the output.
Such an approach would help to reduce typos in anticipated output and copy-n-pasting orgies (which are of course error prone).
Also while writing documentation for a comment line program or a shell that is still in rapid development you don't have to manually check all your existing examples when the output is automatically integrated in the LaTeX document.
How can I solve this with LaTeX?
I found Listing language for “screen session”, but this question is just about the syntax highlighting part.