15

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?

  • Why is it a big deal to print the contents of the clipboard? Just save as a temporary file. In any case some formatters need the file extension to infer the language – smci Dec 11 '17 at 2:38
  • Do you want recognition of keywords, strings, constants, comments? Bold, italic? Colors? Configurable colors? PS output? PDF output? Configurable font size? Headers/footers? Duplex and n-up printing? – smci Dec 11 '17 at 2:39
9

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.

6

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.

2

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.

1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .