[Tex/LaTex] Tikz library `external` produces error if package `optional` is loaded

texlivetikz-pgfUbuntu

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

Best Answer

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:

enter image description here

Related Question