Question

I am looking for an OS X application to nicely format and print source code from a variety of programming languages.

  • Line numbers would be nice
  • Constant width font
  • Printing the contents of the clipboard would be a real plus

Does something like this exist (besides the obvious programmers' editors), free or reasonably priced?

Was it helpful?

Solution

You will find a nice answer over at sister site superuser. It involves a terminal program called enscript which comes with lot's of options and I know at least of one support file for extending its capabilities to print Ruby code.

EDIT:

I just noticed the "clipboard" part of the question. The clipboard content can be accessed from the command line and fed to enscript using pbpaste as mentioned in Matteo answer.

OTHER TIPS

If you don't want to use the terminal for this task and want a mac 'application' you should look at 'Text Wrangler' by Bare Bones Software. It is freeware, which fits your 'low price' request ;)

I use it to print out smaller runs of text, and use it specifically for the line number feature.

If you are familiar with the command line you could use a2ps (free and open source) which can be installed via MacPorts (install MacPorts and then sudo port install a2ps) or Homebrew (install Homebrew and then brew install a2ps).

For example:

a2ps -1 --line-numbers=5 -g source.c

will print source.c with syntax highlighting (-g) and line numbers each 5 pages. See the manual page for additional options. It supports a wide variety of source formats.

To print the content of the clipboard:

pbpaste | a2ps -1 --line-numbers=5

pbpaste prints the content of the clipboard to standard output which is read by a2ps.

See also GNU Source-highlight, which supports many input languages and several output formats.

Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top