# Compiling CircuiTikZ with -shell-escape (pdflatex)

I'm trying to use both CircuiTikZ and pgfplots. In order not to overflow LaTeX memory, I use the TikZ externalize library with -shell-escape command in pdfLaTeX. It compiles the pgfplots nicely, but crashes when encountering an CircuiTikZ picture.

Any ideas how to solve this?

-
Could you add a minimal example of code that fails? –  egreg Nov 9 '12 at 10:53

I was able to reproduce the error and to fix it.

Let's start to examine a simple document with a plot and a resistor:

\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}]
({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}


The compilation with pdflatex -shell-escape test.tex raise an error:

! 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.


The problem, I suspect, is due to the fact that when the compiler encounters \begin{circuitikz} it is not able to process it.

Thus I tried to modify the previous example into:

\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}]
({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}


Compiling again with pdflatex -shell-escape test.tex, the result is:

Notice, indeed, that the environment circuitikz is defined simply as:

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


thus you can also draw circuits with the standard environment tikzpicture without problems.

-
Thank you very much. –  user10918 Nov 9 '12 at 11:58
You're welcome. :) –  Claudio Fiandrino Nov 9 '12 at 19:00