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.


Describing plot v1.
\input{plot}. % v1
Describing plot v2.
\input{plot}. % v2
Describing plot v3.
\input{plot}. % v3


    \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


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 2


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.


\foreach \x in {1,2,3} {\begin{tikzpicture}
    \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
  • 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.
    – Atcold
    Commented Mar 12, 2022 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.
    – Atcold
    Commented Mar 14, 2022 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. Commented Mar 15, 2022 at 15:11
  • Yes, I've just learnt about it through en.wikibooks.org/wiki/LaTeX/Plain_TeX. Thank you for helping out!
    – Atcold
    Commented Mar 15, 2022 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.

  % Deactivate indentation
  % Defining flags
  % 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

And here's plot.tex.

      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

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

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .