I've been looking into speeding up my pdflatex
compilation time and it's lighting fast now.
Only one thing's still very slow: compiling source code using the minted
package.
I was wondering if there is no way of speeding this up (perhaps like the tikz
externalization \tikzexternalize
that only needs to run once and from then on includes the result).
I was thinking of making a new environment that puts the minted
environment inside a tikz
environment, so that the rules of the \tikzexternalize
may apply, but I haven't really figured out how to do this exactly (simply putting it inside a tike node doesn't work).
Best Answer
I am the author of the ConTeXt module
t-vim
which is similar tominted
but usesvim
rather thanpygmentize
to generate syntax highlighting. Thet-vim
module actually delegates the task of running external programs tot-filter
module, which is provides the necessary pluming to call external programs on the content of an environment.By default, the
t-filter
module behaves in the same manner asminted
package: it writes the contents of the environment to an external file, calls the external program, and inputs the result back to TeX. However, to deal with slow external program, the filter module provides acontinue=yes
option. When this option is enabled, the content of each file is written to a separate file and the md5 sum of each file is calculated. The external filter is run only if the md5 sum is changed.In MkII, this feature is enabled by calling the external program using
This calls
mtxrun
, the wrapper script for ConTeXt, which calculates the md5 sum of the file (and stores it asfilename.md5
) and the the program only if the md5 sum is stored. This is faster than runningvim
, but still slow as a new process (mtxrun
) must be executed. To speed things up, I wrap the entire command in a\doifmode{*first}
so thatmtxrun
is called only during the first run of a multi-run compilation.To speed up things further, in MkIV, I use the ConTeXt lua function
job.files.run
, which stores the md5 in thetuc
file (similar toaux
file in LaTeX). So the call to the external program is roughly equal toThe same method can, in principle, be implemented in
minted
. In fact, themtxrun --ifchanged
method can be incorporated easily, provided that minted writes each environment in a separate file (currently it does not do that).