views:

392

answers:

3

I often want to printout programs so that I can read them when away from the computer, and I'm wondering what tools people use to make the code readable when printed.

Today I'm using a2ps which works reasonably well, but it shouldn't be impossible to improve it. For example: index over functions etc. cross references from usage to definitions. c2ps have some of these features, but at the moment I'm not doing much c-coding so its of limited use.

Human factors and typography for more readable programs have described a lot of the ideas I'm thinking of but I haven't been able to find any code that have come out of that.

+1  A: 

I haven't tried it but Highlight is supposed to create working TeX et al. from source code. I have no idea if it has the sophistication you're looking for though.

Corporal Touchy
+1  A: 

I really like LaTeX for type setting, but I haven't been really impressed with using it to typeset code snippets. It seems like you should usually be able to just drop in some code and have a tool do the formatting or coloring.

I'm currently writing a paper which involves a fair bit of Haskell code and for that purpose I'm using the listings package, but really it just gives me a nice verbatim environment. No coloring, no cross linking. The most I can seem to get out of the listings package for my purpose is that you can replace some tokens in the source text with latex symbols.

The best I've seen is something like GeShi highlight, but this assumes that php fits your type setting workflow.

Jason Dagit
http://selinap.com/2009/05/insert-source-code-with-syntax-highlighting-in-latex/ might be of some help.
Mica
Not really. That's just someone commenting on their blog that they use the listings package.
Jason Dagit
+4  A: 

This is unlikely to be popular: Lout, which is similar in concept to TeX, and has special commands to typeset C and other source code. Adding a new programming language may be easier than doing so for LaTeX, but i've not had occasion to do so.

DarenW
Lout comes with prg2lout, a program to typeset source code. It's main advantage over TeX is its size: the latest source distribution (that includes full documentation on Postscript) is just 2.1Mb.
Remo.D