[Tex/LaTex] If-Then-Else clause in TIkZ Latex

tikz-pgf

I'm continuing my work on the "changeable" graphics. I have an array of values, and I have already succeeded in making variables from it. The next step is that I want to ignore the zero values. Here it is, what I have a problem with:

\pgfmathifthenelse{\myq==0}{}{\fill (B) circle (4pt)};

I thought this code should draw a circle in the node B in case the variable \myq has non-zero value. But I cannot even compile the code, compilation freezes. Can you figure out the possible problem or give an advice?

The whole code is:

\begin{tikzpicture}
\def\zamkl{{3,4,4.5,5}}
\def\zamkh{{4,3.5,5,4.5}}
\def\zamkq{{20,0,30,0}}

\pgfmathparse{\zamkl[0]}
\edef\myl{\pgfmathresult}

\pgfmathparse{\zamkh[0]}
\edef\myh{\pgfmathresult}

\pgfmathparse{\zamkq[0]}
\edef\myq{\pgfmathresult}

\draw[help lines] (0,0) grid (2*\myl,2*\myh);

\coordinate (A) at (0,0);
\coordinate (B) at (\myl,0); \node at (B) [below] {$T$};
\coordinate (C) at (2*\myl,0);
\coordinate (D) at (2*\myl,\myh); \node at (D) [left] {$S$};
\coordinate (E) at (2*\myl,2*\myh);
\coordinate (F) at (\myl,2*\myh); \node at (F) [below] {$R$};
\coordinate (G) at (0,2*\myh);
\coordinate (H) at (0,\myh); \node at (H) [right] {$W$};

\draw [very thick] (A) -- (C) -- (E) --(G) -- (A);

\pgfmathifthenelse{\myq==0}{}{\fill (B) circle (4pt)};

\end{tikzpicture}

Best Answer

With pgfmath the correct syntax is

\pgfmathifthenelse{\myq==0}{}{"\noexpand\fill (B) circle (4pt);"}\pgfmathresult

or

\pgfmathparse{\myq==0?:"\noexpand\fill (B) circle (4pt);"}\pgfmathresult

Every expression is expanded with \edef before it is parsed. Using \noexpand protects \fill from this expansion. And as always \pgfmathifthenelse returns the result in the macro \pgfmathresult.