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.
\def
and theinput
in my scripts and that seems to work for me, but not sure if that will resolve your issue. So, trypdflatex -shell-escape "\def\myRandomVariable{}" "\input{mwe}"