# Show plots conditionally / progressively

I would like to show my plot through multiple stages. For example, I'd like to show first the blue plot, then blue and red, and finally all three, without copying the file multiple times and commenting out code.

main.tex

\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\begin{document}
Describing plot v1.
\input{plot}. % v1
Describing plot v2.
\input{plot}. % v2
Describing plot v3.
\input{plot}. % v3
\end{document}


plot.tex

\begin{tikzpicture}
\begin{axis}
\addplot+ [domain=0:360, samples=101, mark=none] {sin(1*x)/1};  % show in v1,2,3
\addplot+ [domain=0:360, samples=101, mark=none] {sin(2*x)/2};  % show in   v2,3
\addplot+ [domain=0:360, samples=101, mark=none] {sin(3*x)/3};  % show in     v3
\end{axis}
\end{tikzpicture}


My guess is there should be a way to send parameters through \input{}, and then use a conditional syntax within the tikzpicture. I'm just not sure how to do this in LaTeX.

## 2 Answers

Is this sort of where you are headed? It produces three pages, each with a different plot. You can use the [page=...] option of \includegraphics.

BTW, you might prefer the ifthen package protocol. I generally don't bother.

\documentclass[border=2mm,multi={tikzpicture}]{standalone}
\usepackage{pgfplots}

\begin{document}
\foreach \x in {1,2,3} {\begin{tikzpicture}
\begin{axis}
\addplot+ [domain=0:360, samples=101, mark=none] {sin(1*x)/1};  % show in 1,2,3
\ifnum\x>1 \addplot+ [domain=0:360, samples=101, mark=none] {sin(2*x)/2};\fi  % show in   2,3
\ifnum\x>2 \addplot+ [domain=0:360, samples=101, mark=none] {sin(3*x)/3};\fi  % show in     3
\end{axis}
\end{tikzpicture}}
\end{document}

• Thanks for your reply. I realise there's missing info on my request. The body is <text> <plot1> <text> <plot2> <text> <plot3>, where I'm describing the figure, one element at the time. So plot.tex should be the “full picture” but I should be able to decide what elements to show per each case. Let me improve the main question above. Mar 12 at 18:22
• I solved my issue by using \newif\ifplot{A,B,C}\plot{A,B,C}false and \plot{A,B,C}true in main.tex and then using \ifplot{A,B,C} \fi in plot.tex, where {} are to be interpreted in the Bash way. I'm not sure now if I should edit your answer, answer my own question, or accept yours for giving me the inspiration. Mar 14 at 22:01
• Generally answering your own question is best. After a day or so you can accept it. BTW, you might also look at \ifcase. Mar 15 at 15:11
• Yes, I've just learnt about it through en.wikibooks.org/wiki/LaTeX/Plain_TeX. Thank you for helping out! Mar 15 at 20:00

Turns out what I was actually looking for is TeX's flag mechanism (I didn't even know this was a thing when I first posted my question). Documentation of its behaviour can be found on LaTeX Wikibook.

So, the main.tex goes as follow.

\documentclass{minimal}
\usepackage{pgfplots}
\begin{document}
% Deactivate indentation
\setlength{\parindent}{0pt}

% Defining flags
\newif\ifA\newif\ifB\newif\ifC

% Activate A only
Describing plot A.

\Atrue\input{plot}  % A

% Activate also B
Describing plot A \& B.

\Btrue\input{plot}  % A & B

% Activate also C
Describing plot A \& B \& C.

\Ctrue\input{plot}  % A & B & C
\end{document}


And here's plot.tex.

\vspace{1ex}
\begin{tikzpicture}
\begin{axis}[width=5cm]
\pgfplotsset{
every axis plot post/.style={domain=0:360, samples=101, mark=none}
}
\ifA\addplot {sin(1*x)/1};\fi
\ifB\addplot {sin(2*x)/2};\fi
\ifC\addplot {sin(3*x)/3};\fi
\end{axis}
\end{tikzpicture}


And this is the final result, where I can selectively turn on specific curves in a given plot.