# [Tex/LaTex] node names and nested loops in TikZ

tikz-pgf

I'm trying to draw a (part of a) lattice. To achieve that I use two nested foreach loops, like this:

\foreach \x in {-1, 0, 1} {
\foreach \y in {0, 1, 2} {
\path node (\x.\y) at (\x+\y-1, \y-\x) {};
}
}


Anyway I'm not able to refer to the nodes I create in the code above. Specifically, if I try something like this:

\path[->] (0.0) edge [bend right = 30] (0.1);


I get an error:

ERROR: Package pgf Error: No shape named 0 is known.


So the question is: which name will TikZ accept? The names should correspond to the lattice points. So, in some way, they should contain \x and \y.

Trying to variate on the nodes name doesn't help either. For example, if I try this

\path node (X\x Y\y) at (\x+\y-1, \y-\x) {};


I still get the same error:

ERROR: Package pgf Error: No shape named X0 Y0 is known.


Try this:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[>=latex,scale=2]
\foreach \x in {-1, 0, 1} {
\foreach \y in {0, 1, 2} {
\path node (\x-\y) at (\x+\y-1, \y-\x) {};
}
}
\path[->] (0-0) edge [bend right = 30] (0-1);
\end{tikzpicture}

\end{document}


From the pgf documentation (Section 3.7 Naming Nodes ):

Names for nodes can be pretty arbitrary, but they should not contain commas, periods, parentheses, colons, and some other special characters. However, they can contain underscores and hyphens.