以下来自 pgf 手册的代码可以很好地编译lualatex --shell-escape
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
\begin{document}
A simple image is \tikz \fill (0,0) circle(5pt);.
\end{document}
但是,如果我编写一些 luacode (例如$\pi = \directlua{tex.sprint(math.pi)}$
),我会出现以下错误消息:
===== '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);
问题是:哪里出了问题?此外,为什么要调用 pdflatex?
注意:仅当我之前删除了 aux 文件时,使用 lua 代码的编译才会失败。
答案1
您可以更改程序 PGF/TikZ 调用以使用键生成外部图形/tikz/external/system call
(请参阅手动的,第 345 页)。默认值为
\tikzset{external/system call={pdflatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}}
替换pdflatex
为lualatex
应该可以解决问题:
\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}
答案2
看来,问题恰恰出在pdflatex
所调用的那个。它无法理解\directlua
,因此无法生成您的外部图形。
之所以pdflatex
会调用 ,似乎是因为它在/tex/generic/pgf/frontendlayer/tikz/libraries/tikzexternalshared.code.tex
文件中被硬编码了。尝试编辑该文件,并将每个调用替换为pdflatex
。lualatex
希望这会有所帮助。