Alpha Hydrae

Coding on the edge of the web...

Highlight Code in LibreOffice Impress on OS X

It’s a pain to put code with proper syntax highlighting in slides, but it turns out there’s a solution for LibreOffice that does not involve taking screenshots, copying-and-pasting rendered HTML, or manually coloring text.

This article describes how to install libreoffice-code-highlighter, a syntax highlighting Python macro for LibreOffice, on OS X (the original instructions are for Linux). It uses Pygments to perform the syntax highlighting.

First, download the macro script and save it to your LibreOffice’s python scripts directory. The following commands will accomplish this:

mkdir -p ~/Library/Application\ Support/LibreOffice/4/user/scripts/python
curl > ~/Library/Application\ Support/LibreOffice/4/user/scripts/python/

(The /4 part probably depends on your version of LibreOffice.)

Download the Pygments source code wherever you want, for example to ~/Downloads/pygments-main.

Go to that directory in a terminal, and install Pygments with LibreOffice’s bundled Python version:

cd ~/Downloads/pygments-main
/Applications/ -E install

Now you can configure a keyboard shortcut to trigger the macro in LibreOffice:

  • Go to Tools > Customize > Keyboard
  • Select the LibreOffice option button (available in the top left corner)
  • Select any desired shortcut
  • Select LibreOffice Macros/user/Highlight/highlight_source_code in the Category and Function boxes
  • Click the Modify button to set the shortcut

You’re all set! Follow the usage instructions of libreoffice-code-highlighter to highlight some code.


  • LibreOffice:
  • Python: 3.3.5 (bundled with LibreOffice)
  • OS X: 10.10.5 Yosemite
  • libreoffice-code-highlighter: f21631