a2ps and enscript

introduction

There are two nice ways to print source code from a linux command line. The first uses a utility named enscript. To try it, type

enscript -2rG mycode.cpp

at a command line prompt. This gives an attractive landscape-style layout with two pages of source code per printed page, a nice format for handing in written code listings.

Another utility named a2ps, which used to stand for "ascii to postscript" but now stands for "anything to postscript," also does a very nice job of sprucing up plain ol' code files. Type

a2ps mycode.cpp

to print an example (literally -- go fetch your example at the printer). enscript is included in the comprehensive Red Hat distribution, while a2ps is available for free from France.

software names and current versions

documentation

There is extensive help available for a2ps inside the kdehelp system.

downloads

You will need a2ps and psutils

installation instructions (as root)

	rpm -i psutils-1.17.5.i386.rpm
	rpm -i a2ps-4.13-2.i386.rpm
	rpm -i enscript-1.6.1-8.i386.rpm

user level configuration

As befits its European origins, a2ps prefers to print on "A4" paper, which is larger than the American standard "Letter." Here is a way for a user of a2ps to change the default page size from A4 to Letter. Create a user's home configuration file (`$HOME/.a2ps/a2psrc') with the following contents:

# a2psrc
# cparrish, 4 Apr 2000 (or your own name and date if you prefer)
# user level configuration for a2ps

# Default medium
Options: --medium=Letter

The first four lines are comments and the last one does the job.

To change the default for everyone, a system administrator could edit the site configuration file /etc/a2ps-site.cfg and rebuild a2ps.

comments

Here is a simple test:

a2ps mycode.cpp

The following command line takes two files and pretty-prints them onto two panels per page on Letter-sized paper, then prints the result to a postscript file named kilos.ps.

a2ps kilos.h kilos.cpp -Av --media=Letter -o kilos.ps

Then use

gv kilos.ps

to view the result under Ghostview before printing.

A similar experiment using enscript might go as follows:

enscript -2Gr welcome.cpp -o welcome.ps
gv welcome.ps

Type

info rpm

for more information on rpm packages.


cparrish@sewanee.edu