# Problem parsing product 2\x with TiKZ 3.0

I was used to write 2\x to obtain the product 2*x but today I've found this is not correct anymore in TiKZ.

Next code

\documentclass[tikz,border=2mm]{standalone}

\begin{document}
\begin{tikzpicture}[x=2cm,y=0.5cm]
\foreach \i in {0,...,3}
\foreach \j in {0,...,3} {
}
\end{tikzpicture}
\end{document}


gives me

As you can see all blue circles with coordinates computed through (2\i, 2\j) are wrongly placed while red ones computed with (2*\i,2*\j) are correct.

I don't remember to have read anything about * addition for products in TiKZ but, of course, I could be wrong. So, is it a known behaviour? Where is it documented?

-
I have always used * as otherwise it is just expanding to 2\i==20, so I think it is obvious to always put the *. Think what would happen if you accidentally put it in an expanded context. Then 2\i would always be wrong. –  zeroth Sep 1 '14 at 11:34
I think you were using 2\i if \i was a dimen. Then it is recognized but otherwise it should be as zeroth noted direct replacement of the number. –  percusse Sep 1 '14 at 11:41
@percusse: thank you for the comment. Could you consider converting it into an answer? –  Ignasi Sep 1 '14 at 12:56
Was it the problem? –  percusse Sep 1 '14 at 12:57
@zeroth: After more than twenty years using LaTeX I'm still trying to understand expansion, so, thank you for the example. Please consider converting it into an answer? –  Ignasi Sep 1 '14 at 12:59

A simple reason for not using this is that TikZ expands its arguments whenever it can (in certain context it might not expand the macros):

\foreach \i in {0,1} {
\draw (2\i,0) circle (2pt);
}


will produce these commands

\draw (20,0) circle (2pt);
\draw (21,0) circle (2pt);


it would then correspond to coordinates multiplied by the current x and y unit vectors (1cm is the default value for both) which was clearly not the intent.

Providing an asterisk (*) will enable the TikZ to switch to pgfmath parsing which then calculates the result

\foreach \i in {0,1} {
(2*\i,0)
}


and will produce:

\draw (0,0) circle (2pt);
\draw (2,0) circle (2pt);


Alternatively, if the variable is a dimension, then left implied multiplication is a valid TeX operation such as .5\textwidth,2\pageheight etc. Then Tikz reads the dimension calculation as a single argument and expands correctly.

-
I took the liberty to clarify some minor differences. Hope you don't mind. –  percusse Sep 1 '14 at 14:59
@percusse, sure no problem :) –  zeroth Sep 1 '14 at 15:42