% \subsubsection{TikZ export}
% We generate SVGs and PNGs for any TikZ images, via the
% ``externalize'' feature of TikZ.
%
% Currently TikZ doesn't compile natively into the website because of
% how the xake bake compilation works.  In order to make Tikz work,
% you need to get the tool \verb|mutool| on the machine that is
% performing \verb|xake bake|.
%    \begin{macrocode}
%<*classXimera>
\ifdefined\HCode
  \tikzexporttrue
\fi

\iftikzexport
  \usetikzlibrary{external}

  \ifdefined\HCode
    % in htlatex, just include the svg files
    \def\pgfsys@imagesuffixlist{.svg}
    
    \tikzexternalize[prefix=./,mode=graphics if exists]
  \else
    % in pdflatex, actually generate the svg files
    \tikzset{
      /tikz/external/system call={
        pdflatex \tikzexternalcheckshellescape
        -halt-on-error -interaction=batchmode
        -jobname "\image" "\\PassOptionsToClass{tikzexport}{ximera}\texsource";
        mutool draw -F svg \image.pdf > \image.svg ;     % mutool adds "1" to filename ????
        mutool draw -o \image.svg \image.pdf ;
        mutool draw -r 150 -c rgbalpha -o \image.png \image.pdf ;
        ebb -x \image.png
      }
    }
    \tikzexternalize[optimize=false,prefix=./]
  \fi

  \fi

%</classXimera>
%    \end{macrocode}