Skip to main content

Styling code snippets in Keynote

Posted in Apple

Just after I published my story on why I like Keynote, I was catching up on my RSS feeds and spotted a post from Sara Soueidan about how to highlight code syntax in Keynote.

There’s nothing built into the app, so, unless you want to select various parts of the code text yourself and change the font colour, there are essentially three options:

  1. Take a screen shot of some already-syntax-highlighted code from your text editor, then drop it into Keynote
  2. Copy from VS Code with the copyWithSyntaxHighlighting setting on, then paste into Keynote
  3. Copy from Slides Code Highlighter, then paste into Keynote

Option 1 is what I’ve always used, but it’s a pain because:

  • text sizes are fiddly to match up
  • crop boundaries (essentially the padding/frame around the code) are manual, and therefore almost always slightly inconsistent
  • if you make a change, you’ve got to take another screenshot

Option 2 is out as I’m still using Sublime Text, and there’s no equivalent of VS Code’s copyWithSyntaxHighlighting.

Option 3 works quite nicely; it’s still much easier than styling it all myself and it allows me to make edits easily.

I’ve got my ‘Code’ slide template set up to add a dark background and same-coloured border (padding/frame) to the code text box, but there are there are still a couple of manual steps once I’ve pasted the code in from Slides Code Highlighter:

  • For some reason, the pasted text gets a white (#ffffff) ‘Text background’ value, so that has to be made transparent again
  • I like the Operator Mono typeface for my snippets, so I change that

Those corrections/adjustments are really easy to do, so I’m happy to make them, though as Sara says:

none of these approaches are as convenient as having built-in syntax highlighting in Keynote

The Slides Code Highlighter technique is a tolerable workaround, so I’ll run with that until Apple adds a syntax highlighting to Keynote. But I’m not holding my breath.


Here’s the Slides Code Highlighter custom theme I threw together to match the colours on my website:

{
"bgColor": "#1a1a1c",
"textColor": "#f2f2f2",
"punctuationColor": "#adacaf",
"stringAndValueColor": "#ffe648",
"keywordTagColor": "#ff508c",
"commentColor": "#adacaf",
"typeColor": "#00d7e9",
"numberColor": "#ffe648",
"declarationColor": "#9786e9",
"dimmedColor": "#adacaf",
"highlightColor": "#ff508c",
"lineHeight": 1.5
}

Subscribe

I send a newsletter on the last day of every month, containing:

  • A roundup of the articles I’ve posted
  • A hot pick from my archives
  • Some interesting posts from around the web

I don’t collect any data on when, where or if people open the emails I send them. Your email will only be used to send you newsletters and will never be passed on. You can unsubscribe at any time.

More posts

Here are a couple more posts for you to enjoy. If that’s not enough, have a look at the full list.

  1. XHTML syntax is still worth using

    A few weeks ago I read an article on CSS-Tricks about writing HTML the HTML way, not the XHTML way, and it has been bothering me a bit.

  2. Booleans in ARIA

    HTML booleans are bit quirky but, as if just to complicate things, booleans in ARIA work slightly differently. It’s worth knowing how and why.