MAC – Syntax Highlighting Code Samples In Keynote Presentations

Ever wondered how cool an Apple Keynote presentation would look if the code samples were automagically syntax highlighted? Ever wondered if there was an automagical way to highlight the syntax? After having spent many a years highlighting the syntax manually, it dawned upon me that Apple is smart enough to have provided an elegant way to get this done and may be I was being naive/dumb in not learning that way. Turns out, both my suspicions were true.

Apple, as part of XCode [it’s free; just need to create an account with Apple Developer Connection], provides a tool called qlmanage that accomplishes this – amongst other things. It probably has a graphical interface but personally, I’m a fan of command line. While I have no reason to expect that this won’t work on your Mac, these instructions come with no guarantee and that you will use them at your very own discretion. More importantly, you will be solely responsible for any/all damage inflicted upon yourself by following this process, intellectual &/or otherwise.

Suppose that all code samples [HelloDolly.f, HelloDolly.c and SimpleArithmetic.m in this case] are in a folder called TestBed [Fig. 05] and the [BASH] script that will produce syntax highlighted version of these code samples is code2keynote.sh [Fig. 06]. Upon running code2keynote.sh in TestBed [using Terminal application], TestBed will have an additional folder for each code sample [Fig. 07]. One can get into any one of them – say HelloDolly.f.qlpreview [Fig. 08] and view the contents of Preview.rtf [Fig. 09] – copy the contents of it to be pasted in a Keynote presentation.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.