Is there a package which allows me to render (n)curses based output (VT100, ANSI ...) directly in LaTeX (including colors if possible)? I'm currently making screenshots and include the PNGs via graphicx. I'm just wondering whether it's possible to achieve a higher quality.
Jan's solution is the most direct, but, speaking from experience, writing parsers for teletype codes is a real pain. I wonder if it makes sense to reinvent such a tricky wheel, rather than use some external program to do the parsing instead.
Instead, I suggest using an external curses to HTML converter, and use one of the existing HTML to Latex interpreters/translaters to generate the code for the document.
I can't say which tools are right for the job, but maybe some of my thoughts are worth typing out:
- David Mertz has written a series on curses programming in Python, of which #6: Curses programming in Python: Tips for Beginners introduces curses_txt2html.py — note that code has dependencies on other code from the series;
- Finding the right converter from HTML to Latex is made more difficult by the fact that (i) there are so many, and (ii) most care about logical structure, rather than exactly representing coloured, preformatted monospaced text.
- The Texinfo people know about curses, since, e.g., the
pinfoTexinfo reader is ncurses based, and Texinfo is a Tex format that closely resembles, and is easily converted to Latex. I don't know if they have done anything like this, but if they have, they are likely to have done a good job.
I don't know about a package. You would have to make TeX interpret the ANSI sequences. That should be possible by assigning catcode 13 to the ESC character. It may be tricky to figure out how long is the argument, though, since in the escape sequences it is the last character that determines what type of sequence it is, and therefore how long the argument is.
This would be very useful to have, I scoured the internet unsuccessfully last week for something which would do just this. I think I decided the best approach would be (eventually) to modify http://pypi.python.org/pypi/ansi2html/ so that it could support LaTeX output too, along the lines of the Pygments syntax highlighting system which creates a generic internal representation then supports multiple output formats like HTML, LaTeX, RTF etc.