Code with syntax highlighting in a word processor

2.5k Views Asked by At

How can I get code with syntax highlighting into a word processor?

It's for a manual that will have code examples which should be able to go from page to page so putting images is not an option.

I'd rather do it with OpenOffice but I could also use iWorks or Office. The code is Ruby, Java, Python and maybe others. I could use TextMate to export it if necessary.

5

There are 5 best solutions below

3
On BEST ANSWER

XCode does that already, I think. If you copy out of its window and paste into another app that accepts rich text, the formatting comes along with it. I just made a screenshot:

screenshot http://img710.imageshack.us/img710/8756/xcodetextedit.png

0
On
0
On
0
On

VIM has a syntax hilighing for almost every programming language, and has option to export hilighted source as HTML file that should be easily imported by word processor. Use

:TOhtml
0
On

I was able to copy/paste correctly highlighted Java code from Eclipse into Word 2007 and Word 2010 by selecting not the regular Paste, but Paste Special->Rich Text Format.

"Paste Special" is found by clicking the little down arrow under the Paste icon on the Word Ribbon Bar.