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

Accessibility in your inbox

I send an accessibility-centric 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. WWDC 2024 roundup

    I got al the features I wanted from this year’s WWDC, Apple’s World Wide Developer Conference; as ever, there were also a few surprises!

  2. How to browse the web with the keyboard alone

    Some people use the keyboard to get around their computer. Knowing how to do this is important for accessibility testing and to inform design.