Quantcast
Channel: My experiments with life
Viewing all articles
Browse latest Browse all 78

MAC – Syntax Highlighting Code Samples In Keynote Presentations

$
0
0

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.

01. HelloDolly.f - syntax highlighted in Terminal application 02. HelloDolly.c - syntax highlighted in Terminal application 03. SimpleArithmeic.m - syntax highlighted in Terminal application 04. man page for 'qlmanage' 05. Contents of 'TestBed' 06. code2keynote.sh - the automagical shell script 07. Contents of 'TestBed', after running 'code2keynote.sh' 08. Contents of 'HelloDolly.f.qlpreview' 09. Contents of 'Preview.rtf' - copy and paste into Keynote presentation

Share


Viewing all articles
Browse latest Browse all 78

Trending Articles