Extract Inkscape Layers to PDF files for LaTeX Beamer Presentations

I like doing fancy presentations with little text (but in the titles, I heard that’s called “power titles” occasionally) but with a lot of graphics and animations. As a computer scientist who uses a lot of math stuff in his work, I of course use LaTeX even for creating presentations for its math features, although, in my opinion, LaTeX is not the perfect technology for making slides. My animations and graphics were done in TikZ so far, with all advantages and downsides: While on the one hand, you can use all the macros of your main document and profit from the wide range of powerfull TikZ/PGF libraries, TikZ animations can be quite brittle and hard to create and maintain.

After discovering the great textext plugin for Inkscape which lets you render LaTeX code from within Inkscape which can be updated (and re-rendered) after creation and allows for the inclusion of a LaTeX preamble, I decided to create graphics for my presentations in Inkscape. In practice, I create a document with the same size as my PDF slides and include a subset of my macros, maybe with a small set of additional definitions for fonts etc., in the preambles of my LaTeX objects. Animations are realized via Inkscape layers. Then, I toggled the layers according to my animation plan and exported several PDFs which I then included via a for-loop in my LaTeX beamer presentation. While that already constitutes a big step forward to WYSIWYG graphics / animations creation for LaTeX, this last step of manually exporting multiple PDFs is quite cumbersome, especially if you change something in your graphics. That’s where my small python script steps in.

The python script I wrote lets you annotate your Inkscape layers with LaTeX Beamer overlay specifications like <1,3-6,7-> — just append that to the name of a layer, and my script will automatically extract several PDF files where at each step, those annotated layers whose overlay range does not include the step are set to be invisible. Now, when you update something in your graphics and animations, just run the script to re-generate your animations. That’s the workflow I wanted to have.

In contrast to other Inkscape-based scripts / workflows like Inksclides etc., the goal of my script is not creating whole presentations from Inkscape vector graphics documents. You could probably do that (e.g., merge the generated PDFs after creation), but inserting a frame in the middle is already quite difficult since you have to update all your layer overlay annotations afterward. It’s really just for making animations within a single frame, but for that purpose, I could not find anything more suitable so far.

So here’s the script — along with a sample SVG that you can use as an example. Enjoy!