10

The following code from the pgf manual compiles fine with lualatex --shell-escape

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
\begin{document}
A simple image is \tikz \fill (0,0) circle(5pt);.
\end{document}

But, if I write some luacode (for example $\pi = \directlua{tex.sprint(math.pi)}$) I have the following error message :

===== 'mode=convert with system call': Invoking 'pdflatex -halt-on-error -inter
action=batchmode -jobname "test-figure0" "\def\tikzexternalrealjob{test}\input{
test}"' ========
runsystem(pdflatex -halt-on-error -interaction=batchmode -jobname "test-figure0
" "\def\tikzexternalrealjob{test}\input{test}")...executed.
./test.tex:7: Package tikz Error: Sorry, the system call 'pdflatex -halt-on-err
or -interaction=batchmode -jobname "test-figure0" "\def\tikzexternalrealjob{tes
t}\input{test}"' did NOT result in a usable output file 'test-figure0' (expecte
d one of .pdf:.jpg:.jpeg:.png:). Please verify that you have enabled system cal
ls. For pdflatex, this is 'pdflatex -shell-escape'. Sometimes it is also named 
'write 18' or something like that. Or maybe the command simply failed? Error me
ssages can be found in 'test-figure0.log'. If you continue now, I'll try to typ
eset the picture.

See the tikz package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.7 ...ple image is \tikz \fill (0,0) circle(5pt);

The question is: what's wrong? And subsidiarily, why is pdflatex invoked?

N.B. The compilation with lua code fails only if I deleted the aux files before.

Hendrik Vogt
  • 37,935
PHL
  • 7,555

2 Answers2

17

You can change the program PGF/TikZ calls to generate the external graphics with the key /tikz/external/system call (see the manual, page 345). The default value is

\tikzset{external/system call={pdflatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}}

Replacing pdflatex with lualatex should solve the problem:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzset{external/system call={lualatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}}
\tikzexternalize
\begin{document}
A simple image is \tikz \fill (0,0) circle(5pt);.
$\pi = \directlua{tex.sprint(math.pi)}$
\end{document}
diabonas
  • 25,784
  • This just saved my day. The problem still persists in pgfplots 1.7. Thanks. – Ingo Feb 13 '13 at 09:55
  • This isn't working for me, and lualatex --help shows that it uses double-hyphen for options, but even fixing that doesn't help. Any extra troubleshooting steps needed? I have TexWorks and MiKTeX 2.9. – Ben Voigt Jan 01 '14 at 22:46
  • Ahh, spaces in the filename of the master document are particularly problematic for lualatex (moreso than pdflatex, anyway) – Ben Voigt Jan 01 '14 at 23:03
0

It seems that what is wrong is exactly that pdflatex is called. It does not understand \directlua, and therefore cannot produce your external graphics.

The reason that pdflatex is calls seems to be that it is hardcoded in the /tex/generic/pgf/frontendlayer/tikz/libraries/tikzexternalshared.code.tex file. Try to edit that file, and replace each call to pdflatex by lualatex. Hopefully that will help.

Jan Hlavacek
  • 19,242