Possible Duplicate:
Problem with environment expansion and the Tikz external library.
I want to externalize some of the TikZ figures of my document. To do so I am using the \beginpgfgraphicnamed command, and I would like to embed it in a new environment. Something like:
\newenvironment{myPic}[1]{%
\beginpgfgraphicnamed{#1}\begin{tikzpicture}
}{%
\end{tikzpicture}\endpgfgraphicnamed
}%
In the end, a basic document test.tex would be :
\documentclass[11pt]{article}
\usepackage{tikz}
\pgfrealjobname{test}
\newenvironment{myPic}[1]{%
\beginpgfgraphicnamed{#1}\begin{tikzpicture}
}{%
\end{tikzpicture}\endpgfgraphicnamed
}%
\begin{document}
\begin{myPic}{imageTest}
\fill[color=red] (0,0) circle (10pt);
\end{myPic}
\end{document}
If I do exactly this, I can compile the external image with
pdflatex --jobname=imageTest test.tex
without any error, but then compiling the actual test.tex document with
pdflatex test.tex
returns:
Runaway argument?
\begin {tikzpicture} \fill [color=red] (0,0) circle (10pt); \end {my\ETC.
! File ended while scanning use of \pgf@next.
<inserted text>
\par
<*> test.tex
If I do the same thing not using my own environment
% test.tex
\documentclass[11pt]{article}
\usepackage{tikz}
\pgfrealjobname{test}
\begin{document}
\beginpgfgraphicnamed{imageTest}
\begin{tikzpicture}
\fill[color=red] (0,0) circle (10pt);
\end{tikzpicture}
\endpgfgraphicnamed
\end{document}
then everything works.
Do you see any problem?
externalTikZ library? It handles this automatically. – Andrew Stacey Sep 29 '11 at 19:16