I am trying to save some plots as individual PDFs, but I want to decide which ones to save with a condition.
mwe.tex
:
\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{external}
\usepackage{pgfplots}
\tikzexternalize
\begin{document}
\ifdefined\myRandomVariable
\begin{figure}[h]
\centering
\begin{tikzpicture}
\begin{axis} []
\end{axis}
\end{tikzpicture}
\end{figure}
\fi
\end{document}
If I compile it as:
pdflatex -shell-escape "\def\myRandomVariable{}\input{mwe}"
It fails.
I can \def\myRandomVariable{}
at the beginning of my file and it works without any problems:
\def\myRandomVariable{}
\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{external}
\usepackage{pgfplots}
\tikzexternalize
\begin{document}
\ifdefined\myRandomVariable
\begin{figure}[h]
\centering
\begin{tikzpicture}
\begin{axis} []
\end{axis}
\end{tikzpicture}
\end{figure}
\fi
\end{document}
And compiling as:
pdflatex -shell-escape mwe
How can I achieve what I want? I need to give the condition i.e. \def
with the compilation command because I need to do this in a bash script with multiple different conditions every time.
Best Answer
The following log lines indicate the problem is, when
external
calls extra latex commands,\myRandomVariable
is always undefined.Configuring the key
external/system call
seems to work: