lualatex 使用 -jobname 和 tikz 外部化图像时出现编译错误

lualatex 使用 -jobname 和 tikz 外部化图像时出现编译错误

使用 TL 2023,此命令有效

lualatex --shell-escape  --file-line-error index.tex

没有给出错误:

...
/usr/local/texlive/2023/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
===== 'mode=convert with system call': Invoking 'lualatex -shell-escape -halt-o
n-error -interaction=batchmode -jobname "images/my_image_file" "\def\tikzextern
alrealjob{index}\input{index}"' ========
This is LuaHBTeX, Version 1.16.0 (TeX Live 2023) 
 system commands enabled.
[1{/usr/local/texlive/2023/texmf-var/fonts/map/pdftex/updmap/pdftex.map}<./imag
es/my_image_file.pdf>] (./index.aux))

但这给出了错误

lualatex --shell-escape  --file-line-error -jobname=LUA index.tex

当 latex 文件尝试使用 tikz 的外部化包将 tikzpicture 保存为 pdf 文件时,会发生此错误。它给出此错误

/usr/local/texlive/2023/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
===== 'mode=convert with system call': Invoking 'lualatex -shell-escape -halt-o
n-error -interaction=batchmode -jobname "images/my_image_file" "\def\tikzextern
alrealjob{LUA}\input{LUA}"' ========
This is LuaHBTeX, Version 1.16.0 (TeX Live 2023) 
 system commands enabled.

./index.tex:15: Package tikz Error: Sorry, the system call 'lualatex -shell-esc
ape -halt-on-error -interaction=batchmode -jobname "images/my_image_file" "\def
\tikzexternalrealjob{LUA}\input{LUA}"' did NOT result in a usable output file '
images/my_image_file' (expected one of .pdf:.jpg:.jpeg:.png:). Please verify th
at you have enabled system calls. For pdflatex, this is 'pdflatex -shell-escape
'. Sometimes it is also named 'write 18' or something like that. Or maybe the c
ommand simply failed? Error messages can be found in 'images/my_image_file.log'
. If you continue now, I'll try to typeset the picture.

See the tikz package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.15 \end{tikzpicture}
                    
? 

它使用jobname了导致问题的。否则外部化可以工作,并且 tikzpicture 的 pdf 可以正确创建。
我需要使用-jobname选项,因为我也在同一个文件夹中构建了 tex4ht,并且此选项有助于将辅助文件名和临时文件名分开,并且当我在同一文件夹中编译为 pdf 和 html 时不会发生冲突。

其中images/my_image_file.log

......
Inserting `luaotfload.rewrite_fontname' in `luaotfload.patch_font'.
Inserting `tracingstacklevels' in `input_level_string'.
! Emergency stop.
<read *> 
   
<*> \def\tikzexternalrealjob{LUA}\input{LUA}

我认为问题在于LUA.tex上面的命令中它正在查找文件,但没有LUA.tex文件。这应该只是作业名称,而不是输入文件名!所以上面的命令应该是

\def\tikzexternalrealjob{LUA}\input{index}

以下是 MWE 对此的复现。这是在运行最新 TL 2023 的 Linux 虚拟盒上进行的

\documentclass[12pt]{article}
\usepackage{shellesc} %need for lualatex!       
\usepackage{tikz} 
\usetikzlibrary{external}
\tikzexternalize[prefix=images/] 

\begin{document}

%this command saves pic to images/my_image_file.pdf
%make sure to create images/ folder first as it will not do it
\tikzsetnextfilename{my_image_file}

\begin{tikzpicture}
    \node[] at (0,0) {some text};
\end{tikzpicture}

\end{document}

运行这些命令时,请确保每次创建并清空 images/ 文件夹以便查看问题。

我发现如果我之前有图像文件,那么使用 jobname 选项时不会出现错误,因为它已经看到了 pdf 图像文件并且不会尝试再次创建它。

问题是:可以使用-jobnamewithlulatex并使用 tikz 外部化吗?

答案1

我建议使用一种比该库更快、更安全、更强大的替代方案external。它不需要完全 shell 转义(仅需要受限,这是默认设置),并且在这种情况下开箱即用。哦,它还会为您创建目录。

\documentclass[12pt]{article}
\usepackage[extract=perl]{memoize}
\mmzset{% perl is default
  path={dir=images},
  mkdir,
}
\usepackage{tikz} 

\begin{document}

\begin{tikzpicture}
    \node[] at (0,0) {some text};
\end{tikzpicture}

\end{document}

编译为

$ TEXMFHOME=/d lualatex -jobname="lua" prawf

两次编译后产生的文件:

$ ls lua.* images/
lua.aux  lua.log  lua.mmz  lua.mmz.log  lua.pdf

images/:
lua.EEA66177700E896EF689C961311611CD-E778DCCCB8AAB0BBD3F6CFEEFD2421F8.memo  lua.EEA66177700E896EF689C961311611CD.memo
lua.EEA66177700E896EF689C961311611CD-E778DCCCB8AAB0BBD3F6CFEEFD2421F8.pdf

目前,您无法指定自定义名称。(我已经开始为此游说;。)对它们的需求并不那么迫切,因为在文档开头插入图像不会导致所有图像更改名称,但为了方便起见,我希望我的图像包含一个人类可读的名称。

perl有三种提取方法。您可能需要为或安装几个库python,假设您已经有可用的解释器。TeX Live 需要perl,所以这是默认的。TeX 方法需要 shell 转义,并且速度最慢。

相关内容