Sunday, November 12, 2006

Printing beautiful code

While writing beautiful code is an art, printing it beautifully is a frustation. I've long been bugged by this problem, and interestingly Dr. Google has been silent about my query. So, here's my search results for the world:
Use enscript, which is installed by default on linux systems.
$ enscript --help
will show you a whole list of options to choose from. If you're as lazy as me, just rely upon the configuration which I found most useful:
$ enscript -2rGC --color -Ec code.c
The options passed along with what they do is as follows:
  • -2 : 2 columns. To have single column, you can use -1. Use --columns=NUM, if you want to specify more than 2 columns.
  • -r : landscape view.
  • -G : cool fancy looking header, which includes file name, page number and creation time.
  • -C : print line number in front of each line.
  • --color : colored output
  • -Ec : formatted using C syntax. Though enscript supports various coding syntaxes, which range from Java to Python to Tcl etc., it is not intelligent enough to understand which language is the code written in, so you need to pass this flag. For e.g. To get the code formatted using python syntax, use -Epython.
By default, the output will be sent directly to a printer. However, you can retrieve a postscript output by specifying '-p filename.ps' flag.
$ enscript -2rGC --color -p testing.ps -Ec code.c
That's it! Enjoy code reading!

No comments: