I'm still not too used to \pgfmath... commands and calc tikzlibrary operations.
Today I wanted to use an operation between two macros defined with \pgfmathsetlengthmacro as a upper foreach limit. Something like
\pgfmathsetlengthmacro\X{10mm}
\pgfmathsetlengthmacro\Y{2mm}
\foreach \i in {0,...,\X/\Y}
or
\foreach \i in {0,...,{int(\X/\Y)}}
or
\foreach \i in {0,...,{int(scalar(\X/\Y))}}
Second and third solutions were written because the previous didn't work, but without really understanding where is the problem.
None of this three examples worked and finally I could solve it with an auxiliary macro
\pgfmathsetmacro{\XdivY}{\X/\Y}
\foreach \i in {0,...,\XdivY}
Could you explain me why my first tests didn't work? How can I write a correct operation between \X and \Y as a limit for \foreach?
In case you want some code for testing, here it is:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\pgfmathsetlengthmacro\X{10mm}
\pgfmathsetlengthmacro\Y{2mm}
\pgfmathsetmacro{\XdivY}{\X/\Y}
\foreach \i in {0,...,\XdivY}
\node at (\i,0) {\i};
% This doesn't work
%\foreach \i in {0,...,{int(scalar(\X/\Y))}}
% \node at (\i,0) {\i};
\end{tikzpicture}
\end{document}


\numexpr...\relaxthough – percusse Sep 14 '16 at 18:28