Code examples in your Keynote or Powerpoint-Presentations

March 10, 2018 by Michael

Code examples, when nicely executed, are a good and valid alternative to live coding. In the end, when you’re not Venkat or Josh, what is live coding anyway? Most of the time one does rehearse the code anyway 😉

Before you add code to your slides, have a look at this presentation by Uri Native called codeware.

One option to get nice code into your presentation regardless wether you’re using a tool like Powerpoint, Google Slides or Reveal.JS are images. Carbon is one way to create nice images from code.

I personally like (or, TBH dislike the least) Keynote, so images are not the first format I’d chose, especially if I want to generate PDFs from presentations who’s code can be copy and pasted. Therefor I run with highlight by André Simon.

Install it with Homebrew brew install highlight and then you can use it’s RTF output option to create RTF data that can be pasted into Keynote (or Powerpoint) as you like. Combine it with pbpaste and pbcopy for an easy workflow without intermediate files. pbcopy is a terminal tool that copies content piped to it into your macOS clipboard.

Here are some examples:

# Highlight a Java source file and copy it's content to your clipboard
highlight --style zellner -O rtf | pbcopy
# Paste unformatted JSON code, format it and then highlight and copy it
pbpaste | python -m json.tool | highlight --style zellner -O rtf --syntax json | pbcopy

I think you get the point. Just insert the formatted RTF data into your deck. Most of the time I try to increase the font size as much as possible.

I’m using this in my slides and I am pretty happy with it.

One comment

  1. Ralf wrote:

    I copy and paste my code from Intelligence to ppt. Worx also great!

    Posted on March 10, 2018 at 8:33 PM | Permalink
Post a Comment

Your email is never published nor shared. Required fields are marked *