tags:

views:

58

answers:

2

I have to write some documents that will include source code examples. Some of the examples will be written from the IDE, and others would be written in place. My examples are primarily in Java.

As someone who is used to LaTeX, doing this in Word is extremely painful. However, I am bound to Word for this. The only options I have seen are:

  1. Write or copy into the document, then use a fixed type font, arrange formatting and hope that Word didn't uppercase stuff for you. Needless to say, this looks like crap.
  2. Copy and paste screenshots of source code from the IDE. At least I keep colors. However, if I change my font size, I'm screwed. I'm also screwed across page boundaries. And let's admit it, Word is not great at managing multiple images on a document.
  3. Write HTML (not really an option here)

Is there some better (and ideally portable) way to do this? Is there at least some sort of verbatim style similar to the LaTeX environment? Is there at least some pretty printer that I could copy-and-paste as RTF?

+2  A: 

It kind of depends on the IDE. Both Visual Studio and Eclipse, for example, will allow you to copy as RTF and paste into Word, keeping all your formatting.

Notepad++ has a plugin called "NppExport" (comes pre-installed) that allows you to copy to RTF, though I don't care much for Notepad++'s syntax highlighting (it'd definitely be passable though). What it does do is support dozens of languages, whereas the aforementioned IDEs are limited to a handful each (without other plug-ins).

Cory Larson
I've had good luck with both VS and Eclipse in doing just this- using the IDE's editor to do the syntax coloring (and any formatting I like), then cutting and pasting directly into word.I typically follow it up with setting the font across the snippet to a fixed width font (it didn't always come across for me)
heckj
+2  A: 

You need to define a style in your Word document and use that for source code. I usually have a style called "Code" which has a monospaced font in a small point size, fixed size tabs, single line spacing, no before/after paragraph spacing, etc. You only need to define this style once and then reuse it. You paste in your source code and apply the "Code" style to it.

Paul R