I'm trying to use tikzmath to draw lines between a set of points, however I've an error ERROR: Missing \endcsname inserted.
on the line \ni=\i+1;
. Any idea why?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{math,calc}
\begin{document}
\begin{tikzpicture}
\tikzmath{
\n=5;
}
\foreach \i in {-\n,...,\n} {
\foreach \j in {-\n,...,\n} {
\node[circle,fill,inner sep=1pt] at ($(\i+.3*\j,.5*\j)$) (n-\i-\j) {};
}
}
\foreach \i in {-\n,...,\n-1} {
\foreach \j in {-\n,...,\n-1} {
\tikzmath{%
\ni=\i+1;
\nj=\j+1;
};
\draw[] (n-\i-\j) -- (n-\i-\nj);
}
}
\end{tikzpicture}
\end{document}
\ni
is defined to be a number in TeX’s eyes (it’s defined with\mathchardef
). If I change\ni
to\nx
, I don't get the error, but other ones due to wrong code.\n-1
parts in the foreach list. TikZ doesn't evaluate the expressions there. You might add\numexpr
before it.