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 answers

3
Carl Norum 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
Greg On
0
bugtussle On
0
el.pescado - нет войне 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
Simon 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.