Alex Rivera | Logout

Printing code with syntax highlighting?

Asked 2009-11-01T11:19:15.613
33

I have occasion to need to print code (Horrors!!! ;) ), and i was wondering what editor or tool would i use to print that code out with proper formatting and syntax highlighting? If it's important, it will be c# code but ideally the tool will work for as many languages as possible. Can Notepad++ or something handle this?

Edit
Report

4 Answers

42

You can use Vim! It's probably installed already if you're on modern Linux/MacOS and an easy install if not.

:syntax will turn syntax highlighting on and :hardcopy will print it. There's syntax highlighting definitions for many languages out there. The default look is usually optimised for screen display, but you can fix that.

Simply open the file on command line with vim <filename>, type :syntax on<ENTER>, then :hardcopy<ENTER> to print it. Quit Vim with :q!<ENTER>.

There's also the :TOhtml command which will open the current selection as HTML in a new Vim window. Capture the entire document with :%y<ENTER> followed by :TOhtml<ENTER> to open it.

answered 2009-11-01T11:30:42.203
15

Yes, Notepad++ can certainly print code with syntax highlighting.

Colour printing would obviously be preferable, but on the occasions when I've printed in black and white, the subtle differences in colour [rendered as shades of grey, of course] can be difficult to distinguish.

However, I think a little customisation of the colour schemes should make this less of a problem.

answered 2009-11-01T11:32:58.987
3

Visual Studio will, and allows you have a completely separate configuration for printing.

answered 2009-11-01T12:03:56.900
1

I while ago I created a household python script that wraps pygments into a small console utility. It works with any language supported by pygments.

Also if you happen to use eclipse, you could simply copy the selected text in the editor and then paste it in a RTF-aware editor like MS Word - it will preserve all the colors, fonts and formatting.

answered 2011-02-01T14:20:10.903

Your Answer