Skip to content

Instantly share code, notes, and snippets.

Last active Sep 2, 2020
What would you like to do?
Syntax highlighting code for PowerPoint (Mac OS)

How to add syntax-highlighted code to PowerPoint slides (Mac OS)

  1. pygmentize -f rtf FILE | pbcopy
  2. Paste into TextEdit (in rich text mode: Format → Make Rich Text before pasting), and copy to clipboard again.
  3. In PowerPoint, Edit → Paste Special… → Styled Text.

(Pasting RTF directly into PowerPoint doesn't work correctly, at least with PowerPoint 2008 — it extends colour spans longer than it should, and sometimes removes line breaks. Going via TextEdit seems to solve the problem.)

Copy link

matatk commented Jun 16, 2014

With PowerPoint 2011 for Mac, I found that it is not necessary to go via TextEdit to preserve the formatting -- however it was necessary to use the "Paste Options" popup to "Keep Source Formatting" (explained there for Windows).

I found a page with previews of all the pygmentize styles which can be helpful finding a style for you (especially in my case, as I needed one with white text, whereas the default one has black text).

Thanks for this great tip, BTW. Also I didn't know about pbcopy!

Copy link

benders commented May 22, 2015

Great tip! Seemingly obvious in hindsight, yet something I had not considered at all before.

For future readers, note that you can also read from the clipboard if you don't want to extract your snippets out to files: pbpaste | pygmentize -l ruby -f rtf | pbcopy. In this scenario the lexer (-l) should be specified, since there will be no filename to guess from.

Copy link

gernotstarke commented Feb 29, 2020

WHOW... this definitely makes my day. Need to prepare dozens of slides with (cucumber) code - your tipp saved hours! Thanx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment