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: https://github.com/ulrichard/experiments/tree/master/initializerlists

And you can find the resulting pdf file at: https://github.com/ulrichard/experiments/releases/download/initlist_0.1/initializerlists.pdf

vim meets VisualStudio

There are two camps of neckbeards: Those who use emacs, and those who use vi or vim. I can’t tell which is better, and most of the arguments seem to be rhetoric. Until about three years ago, I perceived both as insufferable. I was however curious to learn either of them. The question was which one to pick. During my uncertainty, vim was praised more on hacker news. So I gave it a try. At first, it was awkward to work with, but after a while I managed to get along. People often tell how blazingly fast you are editing with vim. But for a long time, I was not nearly as efficient as with other editors. At the moment I’m reading the book “Practical vim” which has a ton of good tips. It seems the flood of shortcuts is never ending. In a way memorizing more commands and shortcuts is like having more keys. That kind of reminds me of an article, I once read. It compared working with a GUI vs on the console to listening radio vs playing piano. I can’t find the article right now, but it had similar reasoning as this one.

So I’m constantly improving my vim skills. In the meantime I’m about on par with how efficient I am at using the style of editors, that I have been using for two decades. To improve further, I thought I would need to practice more. So the natural progression was to use it on the job. For work we use VisualStudio, and unless I could easily compile and debug out of vim, switching back and forth would be counter effective. So I was thrilled to find out that there is a plugin to bring vim style editing to VisualStudio. I only just started using it, but it certainly looks promising.