I use pgfplots with externalization. When I try to include a macro that uses \ifthenelse, always the 'else' statement is being executed. When I switch off externalization, it works again. See this example:



% my new command
    % different title depending on argument:
    \addplot {x};

% begin of externalization
\tikzset{external/force remake}
% end of externalization


% use either of those to switch \ifthenelse on and off 
\tikzexternalenable  % now \ifthenelse is off
%\tikzexternaldisable % now \ifthenelse is on

% test my new command
\plotcmd{true} % should be titled 'true'
\plotcmd{false} % should be titled 'false'


Whats going wrong here?

  • Seems to work for me: could we see the \listfiles output in your log? – Joseph Wright Dec 7 '11 at 19:21
  • you are correct, my example was wrong, ill renew it. – Hendrik Dec 7 '11 at 19:38
  • 1
    Your example doesn't compile for me, but fails with Argument of \boolean has an extra }.. I would have been surprised if this had worked, since you're trying to run a macro in your axis options. The example works fine if I use \ifthenelse{\boolean{#1}}{\pgfplotsset{title=true}}{\pgfplotsset{title=false}} before \begin{axis} in your command instead. – Jake Dec 8 '11 at 2:35

Jake's comment is the answer: the compilation failed. This can be verified by inspection of the <filename>-figure0.log .

The immediate cause for the failure is that \ifthenelse cannot be used in a place where keys are evaluated (because that command is not "expandable").

There are two ways to solve the problem:

  1. either by moving the \ifthenelse in front of the axis and inserting \pgfplotset into its body (as shown by jake)


  1. by moving the \ifthenelse into the argument for title. This is what I would suggest; it seems more local:

    % different title depending on argument:
    \addplot {x};

This does not explain why your experiment worked without externalization. From my point of view, it should never have worked ... in fact, on my computer, it does not work if I switch to \tikzexternaldisable.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.