How to easily print code

For the first-year project in computer science at the University of Fribourg (where I am working as an underassistant) I had to correct exercises handed in by the students. 5 groups handed in their solutions, for each group I had to print out 7 files containing programming code (written in the Lisp-dialect Scheme). Opening all them in DrScheme takes a lot of time – too much as I decided.
I therefore searched the web for an easy solution and found it in the unix (terminal) tool enscript. For me it is the perfect solution for printing code. It includes syntax highlighting for numberless programming languages, including Scheme. For example the command

enscript -2 --highlight=scheme -r -d diufpr06 switch.scm

prints the file switch.scm on the printer diufpr06 (option -d), printing two sides per page (option -2) in landscape-format (option -r). The –highlight-option allows to indicate the programming language for which the syntax should be highlighted. The list of available languages can be displayed by typing enscript --help-highlight, it might be usefull to add | less to the command, otherwise the list is not really readable.
With the option -G (not used here) quite fancy headers are printed. All options can be displayed using man enscript. The installation of enscript is very easy under Ubuntu: just type sudo apt-get install enscript and within a few seconds everything is done. Under MacOS enscript is even installed by default.

2 Responses to “How to easily print code”

  1. clem sagt:

    ok, finally something in english.. well done Dominik. Now you must increase the update frequency and then you’ll be a real blogger! :-))

Leave a Reply