使用 -shell-escape 编译 CircuiTikZ (pdflatex)

使用 -shell-escape 编译 CircuiTikZ (pdflatex)

我尝试同时使用CircuiTikZpgfplots。为了不溢出 LaTeX 内存,我在 pdfLaTeX 中使用带有 -shell-escape 命令的 TikZ externalize 库。它可以pgfplots很好地编译,但遇到CircuiTikZ图片时会崩溃。

有什么想法可以解决这个问题吗?

答案1

我能够重现该错误并修复它。

让我们开始检查一个带有图表和电阻的简单文档:

\documentclass[a4paper,11pt]{article}

\usepackage{circuitikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\usetikzlibrary{external}
\tikzexternalize
\tikzset{external/force remake}

\begin{document}

\begin{tikzpicture}
\begin{axis}[view={60}{30}]
\addplot3+[domain=0:5*pi,samples=60,samples y=0]
({sin(deg(x))},
{cos(deg(x))},
{2*x/(5*pi)});
\end{axis}
\end{tikzpicture}

\begin{circuitikz}
\draw (0,0) to[R, i^<=$i_1$] (2,0);
\end{circuitikz}

\end{document}

编译时会pdflatex -shell-escape test.tex引发错误:

! Package tikz Error: Sorry, the system call 'pdflatex -shell-escape -halt-on-e
rror -interaction=batchmode -jobname "test-figure0" "\def\tikzexter
nalrealjob{test}\input{test}"' did NOT result in a usab
le output file 'test0' (expected one of .pdf:.jpg:.jpeg:.png
:). Please verify that you have enabled system calls. For pdflatex, this is 'pd
flatex -shell-escape'. Sometimes it is also named 'write 18' or something like 
that. Or maybe the command simply failed? Error messages can be found in 'test-figure0.log'. If you continue now, I'll try to typeset the picture.

我怀疑该问题是由于编译器遇到时\begin{circuitikz}无法处理它。

因此我尝试将前面的例子修改成:

\documentclass[a4paper,11pt]{article}

\usepackage{circuitikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\usetikzlibrary{external}
\tikzexternalize
\tikzset{external/force remake}

\begin{document}

\begin{tikzpicture}
\begin{axis}[view={60}{30}]
\addplot3+[domain=0:5*pi,samples=60,samples y=0]
({sin(deg(x))},
{cos(deg(x))},
{2*x/(5*pi)});
\end{axis}
\end{tikzpicture}

\begin{tikzpicture} % NOTICE the environment
\draw (0,0) to[R, i^<=$i_1$] (2,0);
\end{tikzpicture} % NOTICE the environment

\end{document}

再次用 编译pdflatex -shell-escape test.tex,结果是:

在此处输入图片描述

请注意,环境的circuitikz定义确实很简单:

\newenvironment{circuitikz}{
\begin{tikzpicture}}{\end{tikzpicture}}

因此您也可以在标准环境下tikzpicture毫无问题地绘制电路。

相关内容