I often go back and forward between presentations software, trying to find the best one, never being happy. I recently used cleaver , which is nice for simple stuff, but this time I’m back to LibreOffice Impress because I don’t want to spend a long time fighting with layout.
One task that’s never super obvious is figuring out how to do syntax highlighting of code in my presentations. I wanted to share my solution. I’m fairly sure this will also work for MS Office and maybe even Keynote.
First, download Pygments . Pygments is a syntax highlighting tool for the command line.
On ubuntu it can be installed with:
apt-get install python-pygmentsIf you’re on a Mac, I don’t believe there’s a homebrew package. This should work though:
sudo easy_install PygmentsAfter that, we’re using the tool to convert your source file into a syntax highlighted RTF file ! Yes, the old school format you’d never thought you’d need again.
Run it like this:
pygmentize -O style=xcode -o output.rtf input.jsI picked the xcode style, because it worked fairly well with the light backgrounds in my presentation, but other styles are supported. To see a list run:
pygmentize -LInstead of pygmentize I also tried highlight , but it was impossible for me to build and seems a bit over engineered.
Using the fileIn LibreOffice Impress, just click “Insert” and then “File” to find your rtf file.
Batch syntax highlightingI don’t want to have to type this every time, so I made this Makefile to automatically do this. The file assumes that you have:
A src/ directory containing .js files (you can change the extension). An empty rtf/ directory.STYLE=xcode SRC = $(wildcard src/*.js) RTF = $(patsubst src/%.js, rtf/%.js.rtf, $(SRC)) all: $(RTF) rtf/%.js.rtf: src/%.js pygmentize -O style=$(STYLE) -o $@ $< clean: rm rtf/*.rtf