# [Tex/LaTex] Numerical conditional within tikz keys

beamerconditionalstikz-pgf

I would like to set up a presentation in which different parts of the same tikz picture appear, depending on the value of one, perhaps more, integer variables. I tried at first using a fixed picture, with changing the visibility of the different path elements of it, depending on the slide number, but this did not scale. There are about 150 slides in a single frame.

Then, I tried an alternative in which the entire picture is defined as a macro, which is invoked once per slide, with different portions showing based on global conditions. However, I failed in including conditionals within the keys.

Here is a not so minimal and certainly not working example demonstrating my failures. Any help would be appreciated:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{chains}

\tikzset{%
invisible/.style={opacity=0},
}

\newcounter{count}

\newcommand\myPicture{
\begin{tikzpicture}
\begin{scope}[start chain = going right]
\node[draw, circle, on chain] {
\ifnum \value{count} > 1
{Count is greater than s}
\fi};
\node[draw, circle, on chain,opacity=0] {B};
\node[draw, circle, on chain,  \ifnum \value{count} > 1\relax invisible\fi] {C};
\node[draw, circle, on chain] {D};
\end{scope}
\end{tikzpicture}
}

\begin{document}

\begin{frame}
\setcounter{count}{2}
\ifnum \value{count} > 1
{Count is greater than 1}
\fi
\ifnum \value{count} > 2
{Count is greater than s}
\fi

\only{
\setcounter{count}{2}
\myPicture
}

\only{
\setcounter{count}{1}
\myPicture
}
\only{
\setcounter{count}{2}
\myPicture
}
\end{frame}
\end{document}


Here is a minimal example giving an idea of the expected result, but of course, without achieving it:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{chains}
\newcounter{count}
\newcommand\myPicture{
\begin{tikzpicture}
\begin{scope}[start chain = going below]
\node[draw, rectangle, on chain] {display only when counter is between 1 and 3};
\node[draw, rectangle, on chain] {display only when counter is negative}; %
\node[draw, rectangle, on chain] {display only if counter is between 100 and 200};
\node[draw, circle, on chain] {only when counter is in the range 3 to 20};
\end{scope}
\end{tikzpicture}
}

\begin{document}
\begin{frame}
\only{\setcounter{count}{-3}\myPicture}
\only{\setcounter{count}{105}\myPicture}
\only{\setcounter{count}{39}\myPicture}
\only{\setcounter{count}{2}\myPicture}
\end{frame}
\end{document}


I am definitely unfamiliar with both beamer and tikz (do not quite get what the \only are supposed to do) but perhaps this could go in the direction you want:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{chains}
\newcounter{count}

% helper macro:
\long\def\GobToSemiColon #1;{}

\newcommand\myPicture{
\begin{tikzpicture}
\begin{scope}[start chain = going below]
\ifnum\value{count}<1 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>3 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only when counter is between
1 and 3};

\ifnum\value{count}>-1 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only when counter is
negative};

\ifnum\value{count}<100 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>200 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only if counter is between
100 and 200};

\ifnum\value{count}<3 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>20 \expandafter\GobToSemiColon\fi
\node[draw, circle, on chain] {only when counter is in the range 3 to 20};
\end{scope}
\end{tikzpicture}
}

\begin{document}
\begin{frame}
\only{\setcounter{count}{-3}\myPicture}
\only{\setcounter{count}{105}\myPicture}
\only{\setcounter{count}{39}\myPicture}
\only{\setcounter{count}{2}\myPicture}
\only{\setcounter{count}{5}\myPicture}
\end{frame}
\end{document}