Syntax Highlighting for Technical Presentations

June 29, 2010

Ever wanted a quick/easy/automated way to get syntax highlighted code from your editor of choice into PowerPoint?

EVERY time I do a technical presentation I need this.  Usually I resort to taking a screenshot, or finding an “export to html” type plugin for the editor I’m using at the time (Visual Studio, Vim, IntelliJ IDEA, etc.) and then try to get that somehow into my slides.

The problem I usually run into, is that while I like coding on a dark background with a 14pt font, that’s not usually that great for presentations.  So I switch to my “presentation settings” that has a light background and bigger font size, and then switch back once I’m done taking screenshots or outputting to html. [ugh, what a pain… terribly manual].

Then what happens when I spot a bug in code that’s in PowerPoint, or I want to add a comment, or I need to change the syntax highlighting theme of the entire presentation because it doesn’t go well with the lighting in the room.  UGH!  What a disaster.

Basically, it’s always an uphill struggle, and it really bothered me… so I decided to fix it once and for all.


I’m going to solely discuss PowerPoint (for Windows or Mac) here.  I don’t have a copy of iWork, and I’m too cheap to buy one.  The reason I have Office for the Mac, is because I got it for free… KeyNote/Mac zealots: feel free to be zealous, but don’t hate on me because I’m frugal… unless you want to buy me a copy of iWork.

First, download:

Windows Solution

The highlight tool can output many formats, but the important one for Windows is RTF.

So something like:

highlight < infile > outfile –-rtf –syntax=rb  –style=vim –font=”Lucida Console” –font-size=18

This will  take the source code file ‘infile’ and syntax color it as Ruby to an RTF file and output it to ‘outfile’.  The text will be 18pt Lucida Console and syntax highlighted with the “vim” color scheme.

There are lots of themes included, you can ask highlight for help (highlight –help), and it’ll tell you all the options available, as well as all the options available for output, and for languages that it supports.

Next, in PowerPoint, do “Insert Object” on your target slide, and choose “Create from file”.  Make sure you check the “Link” checkbox before pressing OK.

Now, whenever your source changes, re-run your command line, then you can choose “Update Link” on your embedded object in PowerPoint, or if you close and then re-open PowerPoint, it’ll give you the option to update all your links.

Mac Solution

My version of PowerPoint for Mac doesn’t like being able to link to RTF files, but it does allow linking to images.

Highlight can output to SVG, but my PowerPoint doesn’t like that either.

Now download inkscape, if you haven’t already.  It will allow you to rasterize the SVG into a PNG, which PowerPoint does like.  You can export your PNG from inkscape from the command line like this:


The path to my inkscape command line runner is at:


It turns out that inkscape doesn’t like external CSS files, which is what highlight gives you with your SVG, so you can merge your CSS file into your SVG file with a little script.  The other cool bit about SVG, is you can tweak it, if you want, since it’s just XML.

Now, in PowerPoint, choose “Insert Picture” and browse to your newly generated PNG.  Make sure the “Link to File” checkbox is checked.

I wrote a script to do this for the latest presentation I did on dependency injection.  You can take a look at the script here [source.rb].   It’s Ruby, and you can see where I merge the CSS and SVG files together, and where I mess with the line spacing as well (I wasn’t happy with the default line spacing, so I tweaked it to my preference).  All the source/images/PowerPoint for that presentation are available here [dependencies presentation] if you want to check them out to see how the whole process works.

Now, when I need to change the font and syntax theme throughout my entire presentation because it doesn’t match the lighting in the room, it’s super-simple: I change the configuration, re-run my script, update PowerPoint, and chill.

Build awesome things for fun.

Check out our current openings for your chance to make awesome things with creative, curious people.

Explore SEP Careers »

You Might Also Like