Notes

Export dependent image extensions

I use emacs org-mode to prepare documents, presentations etc. Orgmode+babel allows for literate programming, e.g. by including R script within the document itself. Other examples of such documents are .Rnw documents that combine latex and R (via knitr) or .Rmd documents that combine markdown and R (again via knitr)1.

Sometimes, I\’ll write an org document that I want to convert into both html and pdf formats. This is fine, until it comes to images. I prefer svg images for including into html, and of course $\LaTeX$ requires (prefers) pdf images for inclusion. Creating the two formats is easy; making extension choice depending on output format was a little more tricky.

Enter macros.

Macros are simply text snippets that contain arguments. When referenced, macros are expanded with their arguments in place. Further, macros can contain lisp, so that you can do all sorts of cool trickery.

Now, to my example, for easy image insertion, dependent on output format. It\’s simply a matter of defining an appropriate macro, that when referenced will expand itself appropriately. You can see the code and usage in the gist below. If exporting to html, the macro will expand to fig-name.svg, if pdf, it will expand to fig-name.pdf.

See the org-mode manual for more details on macros, as well as some pre-defined macros, e.g. for inserting the author and date.

Footnotes


  1. I used markdown (and Rmarkdown) for a little while, however I still don\’t think they\’re flexible enough for cross-referencing figures etc. Plus, org-mode has some extra goodies for note-taking, tagging and scheduling that I like.

    [return]