调用 tikzexternalize 时 pgf/tikz auxlock 文件出现奇怪问题

调用 tikzexternalize 时 pgf/tikz auxlock 文件出现奇怪问题

我正在尝试使用 gnuplot 的 lua/tikz 终端生成一些基于 TikZ 的复杂图。上个月一切运行良好,但今天当我需要更新其中一些图时,一切却不起作用。我构建了一个 gnuplot 脚本的最小示例和一个产生错误的 TeX 文件。

问题是,当我运行时lualatex --shell-escape --interaction=nonstopmode test.in,在大量输出中出现以下错误:

===== 'mode=convert with system call': Invoking 'lualatex --halt-on-error --int
eraction=batchmode --jobname "TikZ_figs/fig1" "\def\tikzexternalrealjob{test}\i
nput{test}"' ========
This is LuaTeX, Version beta-0.50.0-2010010505
! I can't write on file `test.auxlockalt-on-error --interaction=batchmode --job
name "TikZ_figs/fig1" "\def\tikzexternalrealjob{test}\input{test}"'.
\tikzexternalauxlock@setlock ...@realjob .auxlock 
                                                  \immediate \write \w@pgf@w...
l.74 \end{tikzpicture}

Please type another output file name
! Emergency stop.

我想保留该-interaction=nonstopmode标志,因为我想继续使用 TeXlipse 来编译文档。删除此标志后,会出现提示

Please type another output file name:

如果我输入名称test.auxlock(这似乎是正确的名称,因为该文件的内容仅包含一行:)\def \tikzexternallocked {0},那么我会收到相同的错误(这次只是一个警告),但没有因而引发的紧急停止-interaction=nonstopmode

然后构建继续,并成功生成主文档和外部化图形。另一方面,如果我将提示留空,则文件test.auxlock将覆盖主 tex 文件test.tex。相当令人沮丧!

似乎 tikzexternalize 的调用行被用作 auxlock 文件的文件名。我不知道为什么会发生这种情况,也不知道如何防止这种情况。

我遇到这种情况是不是因为安装有缺陷?(正如我所说,它以前可以工作,但现在不行了,我可能更新了某些东西或者损坏了某些文件。)

我在 Ubuntu 10.10 上运行 texlive,使用来自 Ubuntu 12.04 的 pgf 2.10(因为来自 Ubuntu 10.10 的 pgf 没有适当的外部化例程)和 texlive-luatex 2009-7。

最小工作示例的文件和目录:

test.plt
test.tex
TikZ_files/

MWE 代码

Gnuplot脚本test.plt:

#!/usr/bin/gnuplot
#test.plt - create some plots to be rendered with TikZ

set term tikz
set output 'fig1.tex'
plot sin(x)/x

set output 'fig2.tex'
plot erf(x)

主tex文件test.tex:

%test.tex - MWE for lualatex auxlock file error
\documentclass[]{report}

\usepackage{tikz}
\usetikzlibrary{external}
\usepackage{gnuplot-lua-tikz}
\tikzset{ external/system call={lualatex \tikzexternalcheckshellescape
          --halt-on-error --interaction=batchmode
          --jobname "\image" "\texsource"} }
\tikzexternalize[
  mode=convert with system call,
  prefix=TikZ_figs/
]

\begin{document}

  \begin{figure}
    \tikzsetnextfilename{fig1}
    \input{fig1.tex}
    \caption{\label{fig:fig1} A plot of sinc($x$).}
  \end{figure}

  \begin{figure}
    \tikzsetnextfilename{fig2}
    \input{fig2.tex}
    \caption{\label{fig:fig2} A plot of erf($x$).}
  \end{figure}

\end{document}

如果您没有将 lua/tikz 支持编译到 gnuplot 中,gnuplot 脚本将无法运行,对此我们深表歉意。gnuplot 生成的 tex 文件(fig1.tex 和 fig2.tex)比较长,但这里就不多说了。

图1.tex:

\begin{tikzpicture}[gnuplot]
%% generated with GNUPLOT 4.6p0 (Lua 5.1; terminal rev. 99, script rev. 100)
%% Tue 22 May 2012 10:34:12 PM EDT
\path (0.000,0.000) rectangle (12.500,8.750);
\gpcolor{color=gp lt color border}
\gpsetlinetype{gp lt border}
\gpsetlinewidth{1.00}
\draw[gp path] (1.196,0.616)--(1.376,0.616);
\draw[gp path] (11.947,0.616)--(11.767,0.616);
\node[gp node right] at (1.012,0.616) {-0.4};
\draw[gp path] (1.196,1.725)--(1.376,1.725);
\draw[gp path] (11.947,1.725)--(11.767,1.725);
\node[gp node right] at (1.012,1.725) {-0.2};
\draw[gp path] (1.196,2.835)--(1.376,2.835);
\draw[gp path] (11.947,2.835)--(11.767,2.835);
\node[gp node right] at (1.012,2.835) { 0};
\draw[gp path] (1.196,3.944)--(1.376,3.944);
\draw[gp path] (11.947,3.944)--(11.767,3.944);
\node[gp node right] at (1.012,3.944) { 0.2};
\draw[gp path] (1.196,5.053)--(1.376,5.053);
\draw[gp path] (11.947,5.053)--(11.767,5.053);
\node[gp node right] at (1.012,5.053) { 0.4};
\draw[gp path] (1.196,6.162)--(1.376,6.162);
\draw[gp path] (11.947,6.162)--(11.767,6.162);
\node[gp node right] at (1.012,6.162) { 0.6};
\draw[gp path] (1.196,7.272)--(1.376,7.272);
\draw[gp path] (11.947,7.272)--(11.767,7.272);
\node[gp node right] at (1.012,7.272) { 0.8};
\draw[gp path] (1.196,8.381)--(1.376,8.381);
\draw[gp path] (11.947,8.381)--(11.767,8.381);
\node[gp node right] at (1.012,8.381) { 1};
\draw[gp path] (1.196,0.616)--(1.196,0.796);
\draw[gp path] (1.196,8.381)--(1.196,8.201);
\node[gp node center] at (1.196,0.308) {-10};
\draw[gp path] (3.884,0.616)--(3.884,0.796);
\draw[gp path] (3.884,8.381)--(3.884,8.201);
\node[gp node center] at (3.884,0.308) {-5};
\draw[gp path] (6.572,0.616)--(6.572,0.796);
\draw[gp path] (6.572,8.381)--(6.572,8.201);
\node[gp node center] at (6.572,0.308) { 0};
\draw[gp path] (9.259,0.616)--(9.259,0.796);
\draw[gp path] (9.259,8.381)--(9.259,8.201);
\node[gp node center] at (9.259,0.308) { 5};
\draw[gp path] (11.947,0.616)--(11.947,0.796);
\draw[gp path] (11.947,8.381)--(11.947,8.201);
\node[gp node center] at (11.947,0.308) { 10};
\draw[gp path] (1.196,8.381)--(1.196,0.616)--(11.947,0.616)--(11.947,8.381)--cycle;
\node[gp node right] at (10.479,8.047) {sin(x)/x};
\gpcolor{color=gp lt color 0}
\gpsetlinetype{gp lt plot 0}
\draw[gp path] (10.663,8.047)--(11.579,8.047);
\draw[gp path] (1.196,2.533)--(1.305,2.628)--(1.413,2.736)--(1.522,2.853)--(1.630,2.974)%
  --(1.739,3.094)--(1.848,3.210)--(1.956,3.315)--(2.065,3.405)--(2.173,3.476)--(2.282,3.524)%
  --(2.391,3.546)--(2.499,3.539)--(2.608,3.502)--(2.716,3.435)--(2.825,3.339)--(2.934,3.216)%
  --(3.042,3.070)--(3.151,2.905)--(3.259,2.725)--(3.368,2.539)--(3.477,2.351)--(3.585,2.171)%
  --(3.694,2.004)--(3.802,1.860)--(3.911,1.745)--(4.019,1.667)--(4.128,1.631)--(4.237,1.644)%
  --(4.345,1.708)--(4.454,1.827)--(4.562,2.002)--(4.671,2.233)--(4.780,2.517)--(4.888,2.853)%
  --(4.997,3.234)--(5.105,3.653)--(5.214,4.104)--(5.323,4.577)--(5.431,5.063)--(5.540,5.551)%
  --(5.648,6.030)--(5.757,6.490)--(5.866,6.919)--(5.974,7.308)--(6.083,7.648)--(6.191,7.930)%
  --(6.300,8.148)--(6.409,8.297)--(6.517,8.372)--(6.626,8.372)--(6.734,8.297)--(6.843,8.148)%
  --(6.952,7.930)--(7.060,7.648)--(7.169,7.308)--(7.277,6.919)--(7.386,6.490)--(7.495,6.030)%
  --(7.603,5.551)--(7.712,5.063)--(7.820,4.577)--(7.929,4.104)--(8.038,3.653)--(8.146,3.234)%
  --(8.255,2.853)--(8.363,2.517)--(8.472,2.233)--(8.581,2.002)--(8.689,1.827)--(8.798,1.708)%
  --(8.906,1.644)--(9.015,1.631)--(9.124,1.667)--(9.232,1.745)--(9.341,1.860)--(9.449,2.004)%
  --(9.558,2.171)--(9.666,2.351)--(9.775,2.539)--(9.884,2.725)--(9.992,2.905)--(10.101,3.070)%
  --(10.209,3.216)--(10.318,3.339)--(10.427,3.435)--(10.535,3.502)--(10.644,3.539)--(10.752,3.546)%
  --(10.861,3.524)--(10.970,3.476)--(11.078,3.405)--(11.187,3.315)--(11.295,3.210)--(11.404,3.094)%
  --(11.513,2.974)--(11.621,2.853)--(11.730,2.736)--(11.838,2.628)--(11.947,2.533);
\gpcolor{color=gp lt color border}
\gpsetlinetype{gp lt border}
\draw[gp path] (1.196,8.381)--(1.196,0.616)--(11.947,0.616)--(11.947,8.381)--cycle;
%% coordinates of the plot area
\gpdefrectangularnode{gp plot 1}{\pgfpoint{1.196cm}{0.616cm}}{\pgfpoint{11.947cm}{8.381cm}}
\end{tikzpicture}
%% gnuplot variables

图2.tex:

\begin{tikzpicture}[gnuplot]
%% generated with GNUPLOT 4.6p0 (Lua 5.1; terminal rev. 99, script rev. 100)
%% Tue 22 May 2012 10:34:12 PM EDT
\path (0.000,0.000) rectangle (12.500,8.750);
\gpcolor{color=gp lt color border}
\gpsetlinetype{gp lt border}
\gpsetlinewidth{1.00}
\draw[gp path] (1.196,0.616)--(1.376,0.616);
\draw[gp path] (11.947,0.616)--(11.767,0.616);
\node[gp node right] at (1.012,0.616) {-1};
\draw[gp path] (1.196,2.557)--(1.376,2.557);
\draw[gp path] (11.947,2.557)--(11.767,2.557);
\node[gp node right] at (1.012,2.557) {-0.5};
\draw[gp path] (1.196,4.499)--(1.376,4.499);
\draw[gp path] (11.947,4.499)--(11.767,4.499);
\node[gp node right] at (1.012,4.499) { 0};
\draw[gp path] (1.196,6.440)--(1.376,6.440);
\draw[gp path] (11.947,6.440)--(11.767,6.440);
\node[gp node right] at (1.012,6.440) { 0.5};
\draw[gp path] (1.196,8.381)--(1.376,8.381);
\draw[gp path] (11.947,8.381)--(11.767,8.381);
\node[gp node right] at (1.012,8.381) { 1};
\draw[gp path] (1.196,0.616)--(1.196,0.796);
\draw[gp path] (1.196,8.381)--(1.196,8.201);
\node[gp node center] at (1.196,0.308) {-10};
\draw[gp path] (3.884,0.616)--(3.884,0.796);
\draw[gp path] (3.884,8.381)--(3.884,8.201);
\node[gp node center] at (3.884,0.308) {-5};
\draw[gp path] (6.572,0.616)--(6.572,0.796);
\draw[gp path] (6.572,8.381)--(6.572,8.201);
\node[gp node center] at (6.572,0.308) { 0};
\draw[gp path] (9.259,0.616)--(9.259,0.796);
\draw[gp path] (9.259,8.381)--(9.259,8.201);
\node[gp node center] at (9.259,0.308) { 5};
\draw[gp path] (11.947,0.616)--(11.947,0.796);
\draw[gp path] (11.947,8.381)--(11.947,8.201);
\node[gp node center] at (11.947,0.308) { 10};
\draw[gp path] (1.196,8.381)--(1.196,0.616)--(11.947,0.616)--(11.947,8.381)--cycle;
\node[gp node right] at (10.479,8.047) {erf(x)};
\gpcolor{color=gp lt color 0}
\gpsetlinetype{gp lt plot 0}
\draw[gp path] (10.663,8.047)--(11.579,8.047);
\draw[gp path] (1.196,0.616)--(1.305,0.616)--(1.413,0.616)--(1.522,0.616)--(1.630,0.616)%
  --(1.739,0.616)--(1.848,0.616)--(1.956,0.616)--(2.065,0.616)--(2.173,0.616)--(2.282,0.616)%
  --(2.391,0.616)--(2.499,0.616)--(2.608,0.616)--(2.716,0.616)--(2.825,0.616)--(2.934,0.616)%
  --(3.042,0.616)--(3.151,0.616)--(3.259,0.616)--(3.368,0.616)--(3.477,0.616)--(3.585,0.616)%
  --(3.694,0.616)--(3.802,0.616)--(3.911,0.616)--(4.019,0.616)--(4.128,0.616)--(4.237,0.616)%
  --(4.345,0.616)--(4.454,0.616)--(4.562,0.616)--(4.671,0.616)--(4.780,0.616)--(4.888,0.616)%
  --(4.997,0.616)--(5.105,0.616)--(5.214,0.617)--(5.323,0.620)--(5.431,0.626)--(5.540,0.642)%
  --(5.648,0.675)--(5.757,0.741)--(5.866,0.862)--(5.974,1.067)--(6.083,1.387)--(6.191,1.848)%
  --(6.300,2.460)--(6.409,3.210)--(6.517,4.057)--(6.626,4.940)--(6.734,5.787)--(6.843,6.537)%
  --(6.952,7.149)--(7.060,7.610)--(7.169,7.930)--(7.277,8.135)--(7.386,8.256)--(7.495,8.322)%
  --(7.603,8.355)--(7.712,8.371)--(7.820,8.377)--(7.929,8.380)--(8.038,8.381)--(8.146,8.381)%
  --(8.255,8.381)--(8.363,8.381)--(8.472,8.381)--(8.581,8.381)--(8.689,8.381)--(8.798,8.381)%
  --(8.906,8.381)--(9.015,8.381)--(9.124,8.381)--(9.232,8.381)--(9.341,8.381)--(9.449,8.381)%
  --(9.558,8.381)--(9.666,8.381)--(9.775,8.381)--(9.884,8.381)--(9.992,8.381)--(10.101,8.381)%
  --(10.209,8.381)--(10.318,8.381)--(10.427,8.381)--(10.535,8.381)--(10.644,8.381)--(10.752,8.381)%
  --(10.861,8.381)--(10.970,8.381)--(11.078,8.381)--(11.187,8.381)--(11.295,8.381)--(11.404,8.381)%
  --(11.513,8.381)--(11.621,8.381)--(11.730,8.381)--(11.838,8.381)--(11.947,8.381);
\gpcolor{color=gp lt color border}
\gpsetlinetype{gp lt border}
\draw[gp path] (1.196,8.381)--(1.196,0.616)--(11.947,0.616)--(11.947,8.381)--cycle;
%% coordinates of the plot area
\gpdefrectangularnode{gp plot 1}{\pgfpoint{1.196cm}{0.616cm}}{\pgfpoint{11.947cm}{8.381cm}}
\end{tikzpicture}
%% gnuplot variables

答案1

这不是一个很好的答案,但这是我迄今为止找到的最好的答案。 tikzexternalize 将字符串推送到变量中似乎存在一些问题。 我修改了在 tikzexternalshared.code.tex 中找到的代码(在 Ubuntu 上的 texlive 中,位于 /usr/share/texmf/tex/generic/pgf/frontendlayer/tikz/libraries)以包含额外的一行。

之前的代码(第 415-419 行):

\def\tikzexternalauxlock@setlock#1{%
        \immediate\openout\w@pgf@writea=\[email protected]
        \immediate\write\w@pgf@writea{\noexpand\def\noexpand\tikzexternallocked{#1}}%
        \immediate\closeout\w@pgf@writea
}

以及之后的代码:

\def\tikzexternalauxlock@setlock#1{%
        \immediate\write16{Value of \noexpand\w@pgf@writea: '\the\w@pgf@writea'}
        \immediate\openout\w@pgf@writea=\[email protected]
        \immediate\write\w@pgf@writea{\noexpand\def\noexpand\tikzexternallocked{#1}}%
        \immediate\closeout\w@pgf@writea

}

只需一个打印出文件句柄值(在我的情况下为“3”)的小调试语句,lualatex 编译器就可以顺利运行,至少对于 auxlock 文件名而言是如此。似乎没有调用\the,变量\w@pgf@writea就无法正确清除自身(它之前曾用于保存转换系统调用),最终会在变量的开头写入 auxlock 文件的名称,而不会先将其“清零”,从而给出导致文件打开失败的尾随字符。

我仍然不知道我的系统发生了什么变化导致出现此行为。有人可以确认此行为吗,或者解释修补 tikzexternalize 例程的正确方法吗?

相关内容