Monday, July 6, 2009

pretty printing perl with enscript

I've been using enscript for years to format source code for printing. In particular the -2Gr flags for two-up, landscape prints with "Fancy header".

I recently found there are some colorization flags, -E for syntax highlighting and --color for colored syntax highlighting. -E can take an optional lang flag, perl in our case.

So now my pretty printer uses 'enscript -2Gr --color -Eperl' to create the postscript file and then ps2pdf to dump to pdf.

My perl wrapper and self-referential pdf output. Script requires enscript to be installed.

This is the shell code that the wrapper ends up evaluating:

enscript -MLetter -Gr2 --color -Eperl '' -p - | ps2pdf - "$HOME/public_html/pdf/code_to_pdf.pdf"

% enscript --help-highlight |egrep '^Hi|^Name|^Desc|^$'
Highlighting is supported for the following languages and file formats:

Name: ada
Description: Ada95 programming language.

Name: asm
Description: Assembler listings.
Name: awk
Description: AWK programming language.

Name: bash
Description: Bourne-Again shell programming language.

Name: c
Description: C programming language.

Name: changelog
Description: ChangeLog files.

Name: cpp
Description: C++ programming language.

Name: csh
Description: C-Shell script language

Name: delphi
Description: Delphi programming language.

Name: diff
Description: normal diffs

Name: diffs
Description: side diff

Name: diffu
Description: unified diffs

Name: dylan
Description: Dylan Programming Language template for Enscript.

Name: eiffel
Description: Eiffel programming language.

Name: elisp
Description: Emacs LISP.

Name: forth
Description: Forth Programming Language.

Name: fortran
Description: Fortran77 programming language.

Name: fortran_pp
Description: Fortran77 programming language with cpp-statements

Name: haskell
Description: Haskell programming language.

Name: html
Description: Hypertext markup language HTML.

Name: icon
Description: Icon Programming Language.

Name: idl
Description: IDL (CORBA Interface Definition Language)

Name: inf
Description: GUI INF Script language

Name: java
Description: Java programming language.

Name: javascript
Description: JavaScript language.

Name: ksh
Description: Korn shell programming language.

Name: lua
Description: Lua Programming Language template for Enscript.

Name: m4
Description: macro processor

Name: mail
Description: Mail and news articles.

Name: makefile
Description: Make program's definition files.

Name: matlab
Description: Matlab programming language.

Name: nroff
Description: Manual pages formatted with the nroff program.

Name: oberon2
Description: Oberon 2 Programming Language.

Name: objc
Description: Objective-C programming language.

Name: outline
Description: Outline text.

Name: oz
Description: Mozart/Oz Programming Language.

Name: pascal
Description: Pascal programming language

Name: perl
Description: Perl programming language.

Name: postscript
Description: PostScript programming language.

Name: pyrex
Description: Pyrex - a Language for Writing Python Extension Modules

Name: python
Description: Python programming language.

Name: rfc
Description: RFC and Internet Draft reformatter.

Name: ruby
Description: Ruby programming language.

Name: scheme
Description: Scheme programming language.

Name: sh
Description: Bourne shell programming language.

Name: skill
Description: Cadence Design Systems lispy language.

Name: Smalltalk
Description: Smalltalk Programming Language.

Name: sml
Description: Standard ML Programming Language.

Name: sql
Description: Sybase 11 SQL.

Name: states
Description: States program's definition files.

Name: synopsys
Description: Synopsys dc shell scripting language

Name: tcl
Description: Tcl programming language.

Name: tcsh
Description: TC-Shell script language

Name: tex
Description: TeX/LaTeX command, comment and math highlighting.

Name: vba
Description: Visual Basic (for Applications)

Name: verilog
Description: Verilog hardware description language

Name: vhdl
Description: VHSIC Hardware Description Language (VHDL)

Name: vrml
Description: Virtual Reality Modeling Language (VRML97)

Name: wmlscript
Description: WMLScript language.

Name: zsh
Description: Z-shell programming language.


oylenshpeegul said...

Hey, neat! I too have been using "enscript -2rG" for years when I want to print out source code. I didn't realize it had color syntax highlighting!

Unknown said...

If you're doing code reviews, -C is handy as well.

Andrew Grangaard said...

cp, thanks for the tip.

-C / --linenumbers[=START] turn on line numbering in the print outs.

That is hot! I've added it to my wrapper.