Why the following sample fails to compile in pdflatex when \ifeven is used?
It fails with many errors in line 34 (where the last closing brackets are). The errors are like: Undefined control sequence. }, Extra }, or forgoten \endgroup.}, Extra \else.}, Extra \fi }.
\documentclass[tikz]{standalone}
\newcommand{\stencilptreg}[4][]{\node[circle,fill,draw,inner sep=1.5pt,label={below:#4},#1] at (#2) (#3) {}}
\newcommand{\stencilptstg}[4][]{\node[circle,fill,white,draw=black,inner sep=1.5pt,label={below:#4},#1] at (#2) (#3) {}}
\begin{document}
\begin{tikzpicture}[x=2cm,y=2cm]
\pgfmathsetmacro\N{5};
\pgfmathsetmacro\M{3};
\pgfmathsetmacro\NN{(\N*2)}; % Number of points in staggered grid
\pgfmathsetmacro\MM{(\M*2)}; % Number of points in staggered grid
\foreach \j [evaluate=\j as \q using {{int(\j/2)}}] in {0,1,...,\MM} {
\ifodd\j
\draw [black!50,thin] (0,\j) node[red,left] {$n=\frac{\j}{2}$} -- (\N,\j);
\else
\draw [black!50,thin] (0,\j) node[red,left] {$n=\q$} -- (\N,\j);
\fi
\foreach \i [evaluate=\i as \p using {(\i/2)}] in {0,1,...,\NN}
{
\ifodd\i
\ifodd\j
\stencilptstg{\p,\j}{x-\i-\j}{$\p$};
\fi
\else
%\ifeven\j
\pgfmathsetmacro{\p}{{int(\p)}};
\stencilptreg{\p,\j}{x-\i-\j}{$\p$};
%\fi
\fi
}
}
\end{tikzpicture}
\end{document}

ifevenas a if-primitive (probably, I didn't trace very carefully) – user202729 Oct 10 '22 at 17:53