[Tex/LaTex] Override TikZ externalize “up-to-date” flag

latexmktikz-externaltikz-pgf

I am currently using the TikZ external package in order to avoid recompiling all figures in my thesis. There are more than 50 figures, relying on large data, and a full build without externalizing takes a few minutes to run. Just for some background, I use Latexmk which calls xelatex for the build.

Now my question is, per the documentation, a file is considered "up-to-date" if:

The up-to-date check is simple: if the file does not exist, it is not up-to-date. Furthermore, if one of the force remake or remake next keys is true, the figure is not up-to-date. In all other case, the file is considered to be up-to-date.

I'd like to change the requirements for a file to be up-to-date. More specifically, given the following MWE

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
\tikzsetexternalprefix{figures/cache/}
\begin{document}
\tikzsetnextfilename{circle}
\begin{tikzpicture}
  \draw (0,0) circle [radius=1];
\end{tikzpicture}
\end{document}

The current behavior is to not remake the figure if the file figures/cache/circle.pdf exists. If I make a change to the tikz source, say for example \draw (0,0) circle [radius=2];, the figure will not be rebuilt.

Right now, I add \tikzset{external/remake next} before the figure, run latexmk, wait for the externalizing to start and then rapidly comment out the force remake (if I don't, the figure is rebuilt at each run, which gives huge build times).

Is there anyway to tell tikz to rebuild only if there was an edit to the source of the figure ?

[As a bonus, this should also work when using a custom external/system call, such as converting from pdf to png]

Best Answer

As of May 17, 2012, the external lib comes with support for both checksum checks and diff-based checks (CVS version at the time of this writing).

With this version, the picture's content is compared against the state of the most recent successfull image externalization. Changes in the picture's content will automatically cause a remake for both mode=list and make and mode=convert with system call (the latter one is the system default).

The initial setup will use MD5 checksums. If MD5 checksums are unavailable, it will automatically fall back to diff-based checks.

Note that changes in the document's preamble still need to be resolved manually (by remaking all affected pictures).

Thanks for the (numerous) feature requests in this area.

Related Question