Hi All,

I’ve been fairly busy as of late (hence my recent silence on this ML), however I have a patchset that’s been in the works for a while that I’ve finally polished up.

Short version: It adds a new (superior) option for exporting code blocks with syntax highlighting to LaTeX.

The long version follows.

Currently there are four options for exporting code to LaTeX (ordered by complexity/quality).

  1. Verbatim, which simply includes the code unstyled
  2. Custom, which puts the code in an enviroment of your choice
  3. Listings, which uses the LaTeX package by this name. This is quick, but exceedingly basic.
  4. Minted, which uses the LaTeX package by this name. This is slow, but produces better results than Listings

This patchset accomplishes two things:

  1. It refactors the overly large org-latex-src-block function, and makes a few other improvements to pre-existing code
  2. It adds a new option for exporting code, named (you guessed it!) “engraved”

What is this new option, and why do we want it?

About a year ago I started work on a package that generalises the functionality of htmlize.el, termed engrave-faces (https://elpa.gnu.org/packages/engrave-faces.html). It provides the ability to extract font-lock information and export it to a number of formats: html, ansi, and (crucially) LaTeX! Since the LaTeX export is built on the fvextra (LaTeX) package (like pygments), the vast majority of the Minted options you’re used to just carry over.

This allows for a result that is, I think, straight up better than all the pre-existing options. For starters, you can now apply syntax highlighting to any language you have a major mode for.

There are a number of optimisations unattempted, but it already significantly outperforms Minted. Here are some timings from my config.org:

LaTeX code backend Compile time Overhead Overhead ratio
verbatim 12 s 0 0.0
lstlistings 15 s 3 s 0.2
Engrave 34 s 22 s 1.8
Pygments (Minted) 184 s 172 s 14.3

Compared to Minted, we also no longer have to install pygments or pass the --shelll-escape flag to LaTeX to generate passable code blocks.

Having an all-emacs system also allows for some nifty things, like having entire documents/presentations based on your Emacs theme (see https://github.com/tecosaur/ox-chameleon). Demo images: oAl1.png, oAle.png.

Here are some more screenshots to see what the result can look like in practice:

So, please take a look at the patches, give this a whirl, and let me know what you think! 😀

All the best,
Timothy