Presentations with code that actually works

I don’t do presentations that often these days. And if I do, more often than not, they contain some form of source code. With most things you write, you refine it over and over. This is especially true with stuff that you present. Applied to code snippets, that can mean you test it initially, but once it is in the presentation it is a burden to copy it back and forth to verify every change, and then start over again with the formatting. So you often end up changing your code snippets in the presentation, without verifying if the code is still valid. Sometimes you find these errors during proof reading, but even famous presenters caught compile errors during the presentation. That’s how it works when you use the traditional PowerPoint style of products. As I expressed earlier, the Office suite and their opaque file formats doesn’t belong to my favourite tools.

Thus after I recently learned LaTex, I wondered if presentations could be done with it. Sure enough TexMaker offers a good set of templates for just that.

Next I wanted to see if I could link in code from external files, and sure enough, there is the listings package for LaTex. Now that enables me to have the code in files that I can actually compile.

But wouldn’t it be cool, if I could compile the code snippets for verification and generate a pdf file from the tex source all at one go? Sure enough there is a cmake UseLATEX package.

Now wouldn’t it be even cooler, if I could edit and generate all from within the same console window, without having to exit the editor, start the editor from a specific directory, or type complicated commands? Sure enough I found out how to write project specific .vimrc files. With everything prepared, I just have to type :make in vim to trigger the process, to get a new pdf file with all code snippets verifyed.

A small project to demonstrate the technique is at:

And you can find the resulting pdf file at:

Leave a Reply

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