# Tikz Externalize with LualateX - Fontspec?

There are several questions already posted about issues externalizing tikz with the Lualatex engine. However, most of these are dead ends with no correct answer. The reasons for externalizing are simple - I'm working on a thesis that has many graphics and I would like to decrease the compile time. The problem is that a pdf of the tikz figure is never created using lualatex and fontspec.

A MWE follows:

\documentclass[12pt,letterpaper,twoside,openany]{scrbook}
\usepackage{fontspec} % For font handling
\usepackage{pgfplots} % For tikz

\pgfplotsset{
compat=1.11, % Version of pgfplots
}

\usetikzlibrary{external}
\tikzset{external/system call={lualatex
\tikzexternalcheckshellescape -halt-on-error -interaction=batchmode
-jobname "\image" "\texsource"}}
\tikzexternalize[shell escape=-enable-write18]

\begin{document}
\mainmatter
A simple image is \tikz \fill (0,0) circle(5pt);.
\end{document}


Ultimately, I will be using tikz files produced by matlab2tikz, but the same error happens with the simple \tikz command here.

I have -enable-write18 because I use Miktex on Windows.

When I build this file, a dpth and md5 file are created, but no pdf. If I change the external/system call to use xelatex instead of lualatex, the pdf file is created properly.

One odd occurrence is that if the fontspec package is not loaded (and the pdf previously created by xelatex is deleted) then the pdf is created successfully by lualatex. I find it hard to believe that fontspec is actually causing the problem even in this simple case, yet removing it seems to do the trick. What is going on? How can I including the fontspec package and still externalize tikz when using lualatex?

• I'm assuming your example is minimal? So the problem also disappears if you remove pgfplots or scrhack etc.? (That is, you can't reproduce with plain tikz?) – cfr Jan 10 '15 at 23:42
• No problem on Mac OS X with TeX Live 2014 (MacTeX) – egreg Jan 10 '15 at 23:43
• @cfr Sorry, the extra scr packages weren't necessary. If I remove pgfplots, then I can't compile with the tikz commands. – EP_Guy Jan 10 '15 at 23:46
• But do you get the problem with the straight tikz package (which I assume pgfplots loads?)? – cfr Jan 10 '15 at 23:47
• If I replace the pgfplots package with tikz, the same error occurs. – EP_Guy Jan 10 '15 at 23:49