Tikz library external produces error if package optional is loaded?

I'm working on a large document which exceeded the memory capacity of TexLive 2011 so I tried to externalize the tikz images by using it's external library, as described in pgfmanual. I compiled using

pdflatex -shell-escape foo.tex


which resulted in an error like this:

! Package tikz Error: Sorry, the system call 'pdflatex -shell-escape -halt-on-e rror -interaction=batchmode -jobname "foo-figure0" "\def\tikzexternal realjob{foo}\input{foo}"' did NOT result in a usable output file 'foo-figure0' (expected one of .pdf:.jpg:.jpeg:.png:). Please v erify that you have enabled system calls. For pdflatex, this is 'pdflatex -shel l-escape'. Sometimes it is also named 'write 18' or something like that. Or may be the command simply failed? Error messages can be found in 'ktikztemplate-fig ure0.log'. If you continue now, I'll try to typeset the picture.

I managed to narrow down the problem and came up with the following MWE which produces the same error:

\documentclass{article}
\usepackage{optional}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
\begin{document}
\begin{tikzpicture}
\draw(0,0)--(1,1);
\end{tikzpicture}
\end{document}


Comment out the \usepackage{optional} line and the error is gone. I could somewhat easily manage without that package, but it would be nice if there is some solution for this.

I use TexLive 2011 on Ubuntu 11.10 (both freshly installed few day ago).

It seems that if you provide some option the the \usepackage{optional} command this compiles.

\usepackage[opta]{optional}


This is just a guess, but I think what is happening is that since you did not provide a package option, it reverts to going to the command line to ask the user to input the option. But since you are running in batch mode this is a problem.

The following code works for me using pdflatex with TeXLive2011:

\ifdefined\Options%
\else%
\def\Options{opta}
\fi%

\documentclass{article}
\usepackage[\Options]{optional}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
\begin{document}
\opt{opta}{Option A was selected}
\opt{optb}{Option B was selected}
\begin{tikzpicture}
\draw(0,0)--(1,1);
\end{tikzpicture}
\end{document}


and yields:

• I just tried your proposal (adding [opta] as an option, but it does not compile and I end up with the same error. I also run again the compilation command from the terminal (after i reverted back to \usepackage{optional} and it indeed asked for an option. I entered random string as an option at the error occurred again. Am I doing something wrong? – Vladimir Nov 4 '11 at 22:56
• I have included the full code example, so try that. Also, you mention you did a fresh install, but did you also do an update to get the latest packages? I updated everything a few weeks ago (using TeXLive2011 on Mac OS) – Peter Grill Nov 4 '11 at 23:02
• Yes, I have also updated TexLive2011 (sudo tlmgr update --self --all). I tried your code and it compile just fine (using pdflatex -shell-escape foo.tex`). Thanks for your time and effort. – Vladimir Nov 5 '11 at 12:47
• So it compiles now with or without this extra if else ? – HCAI Mar 27 '13 at 14:52