1

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?

wwjoze
  • 367
  • 1
  • 7
  • Have you considered using the external TikZ library? It handles this automatically. – Andrew Stacey Sep 29 '11 at 19:16
  • I found a previous thread where you answered, which solved my problem as well! Thanks. Here it is: http://tex.stackexchange.com/questions/15595/problem-with-environment-expansion-and-the-tikz-external-library – wwjoze Sep 29 '11 at 19:54
  • As that solved your problem, we'll close this as a duplicate. If you have any more questions, don't hesitate to ask a new question. – Andrew Stacey Sep 29 '11 at 20:23

0 Answers0