使用 pgfplots 时外部化图形不起作用(MiKTeX 2.9)

使用 pgfplots 时外部化图形不起作用(MiKTeX 2.9)

我在使用 externalize 命令将我的 pgfplots 图形导出到单独的文件中时遇到了问题。我收到一个错误,其中心点似乎是“请验证您是否已启用系统调用。”。但是,我已按照 pgfplots 手册中的说明执行此操作。我使用的是 MiKTeX 2.9 和 Windows 7。

(在相关帖子中,发帖人遇到了与我同样的问题:尝试从 TikZ 导出 EPS 图形失败。但是,在这种情况下,发帖人能够使用命令“pdflatex -enable-write18 -output-format=dvi”成功导出图像,我却做不到这一点。我仔细阅读了那个帖子,但仍然不知道如何解决我的问题)。

我的示例如下,取自 pgfplots 手册:

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\tikzexternalize[shell escape=-enable-write18] %needed for the MiKTeX compiler

\begin{document}

\begin{figure}
\begin{tikzpicture}
\begin{axis}
\addplot {x^2};
\end{axis}
\end{tikzpicture}
\caption{Our first external graphics example}
\end{figure}

\end{document}

我使用以下命令进行编译:

pdflatex.exe -shell-escape

这会出现以下错误:

entering extended mode
===== 'mode=convert with system call': Invoking 'pdflatex -enable-write18 -halt
-on-/b/c9/cerror /b/c0/c-interaction=batchmode -jobname "externalizetest-figure0" "\def\tikze
xternalrealjob{externalizetest}\input{externalizetest}"' ========
! Package tikz /b/c9/cError:/b/c0/c Sorry, the system call 'pdflatex -enable-write18 -halt-on
-/b/c9/cerror /b/c0/c-interaction=batchmode -jobname "externalizetest-figure0" "\def\tikzexte
rnalrealjob{externalizetest}\input{externalizetest}"' did NOT result in a usabl
e output file 'externalizetest-figure0' (expected one of .epsi:.eps:.ps:). Plea
se verify that 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 command simply failed? /b/c9/cError /b/c0/cmessages can be found in 'externalizete
st-figure0.log'. If you continue now, I'll try to typeset the picture.
See the tikz package documentation for explanation.

据我了解,

\tikzexternalize[shell escape=-enable-write18]

应该将命令 -shell-escape 替换为 -enable-write18,这是 MiKTeX 所需的。为了确保这不是问题所在,我尝试使用命令

pdflatex.exe -enable-write18

相反,

\tikzexternalize

在 .tex 文件中。但这也不起作用。

如果您能帮助我如何使用 MiKTeX 2.9 启用系统调用,或者,如果问题出在其他地方,请告诉我可能出了什么问题,我将不胜感激。

/安德烈亚斯

答案1

重新安装并更新 MiKTeX 2.9(避免更新 hyph-utf8,自 6 月 23 日发布新版本以来,它似乎出现了一些问题)解决了这个问题。上面的代码(使用上述任一命令行)现在可以正确地将图形导出到单独的 pdf 文件。

答案2

我以前也遇到过同样的问题。在我的环境(Eclipse 和 Texlipse)中,问题在于我指定了一个临时输出目录。通过禁用它,外部化就可以正常工作。此外,我在更新参考书目时遇到了问题。这个问题也解决了。唯一的缺点是目录看起来很乱。谢谢,Roman

答案3

11 年后我才遇到这个错误,现在我发布了我最终找到的解决方案,供遇到此错误的人参考。

  • MiKTeX 4.9
  • Windows 10,22H2
  1. 安装后,打开 TeXworks。转到“编辑”菜单,选择“首选项”列表
  2. 当“TeXworks 首选项”窗口打开时,转到“排版”选项卡
  3. 在“排版”选项卡上,转到“处理工具”部分
  4. 在“处理工具”部分选择您正在使用的文本编译器(例如:“pdfLaTeX + MakeIndex + BibTeX”),然后单击“编辑...”按钮
  5. 在打开的“工具配置”窗口中,转到“参数”部分并​​单击“+”按钮
  6. 在出现的新列表中(通常NewArgument)删除当前文本并粘贴--tex-option=--shell-escape到其位置
  7. 使用“向上”和“向下”箭头将此新列表移至$fullname列表上方
  8. 单击“工具配置”窗口上的“确定”按钮,然后单击“TeXworks 首选项”窗口上的“确定”按钮

使用 pgfplots 的外部图表现在应该可以工作了。

相关内容