Macos – How to print source code on OS X with line numbers, line-wrapping, margins, formatting

macmacosprintingtext-editors

I'm looking through some of WordPress' core code and would like to print it out to review.

I'm looking for a tool that

  • defaults to a monospace font
  • can wrap long lines
  • possibly print line numbers in the left column
  • maximize space usage on a page (i.e. would be nice if it didn't start with 2" margins)

What I've tried already:

  • Textmate: Unable to change screen and print font size independently. I don't want to have to switch back and forth
  • TextEdit: Options don't seem very helpful
  • MS Word: Have to paste the input, change line spacing and font. Painful.
  • Coda: Has the most options. Closest to what I want so far. Does not seem to save my print preferences as defaults though.

Best Answer

I would use enscript --line-numbers -f fontname --word-wrap --margins=… filename

On my Linux systems enscript filename, by default, prints the file to my default printer (which understands Postscript - I don't buy any other sort).

In OS X, you can print to a PDF file using pstopdf:

enscript --line-numbers -p - --word-wrap Session.java | pstopdf -i -o ~/out.pdf

You can tweak global or personal settings for enscript to make those options standard so you just enter a command enscript filename. You may be able to set up an option in your favourite text editor that invokes external command enscript for you.

Related Question