I would like to use the \x and \y variables of the two nested \foreach loops in my tikz script to reference the elements of a list. The code looks like this :
\documentclass{minimal}
\usepackage{tikz}
\usepackage{calc}
\RequirePackage{etoolbox} % defines lists and their operations
\pgfsetxvec{\pgfpoint{.866cm}{.5cm}}
\pgfsetyvec{\pgfpoint{.866cm}{-.5cm}}
\pgfsetzvec{\pgfpoint{0cm}{-1cm}}
\begin{document}
\begin{tikzpicture}
\newcount\tmpnum
\def\storedata#1#2{\tmpnum=0 \edef\tmp{\string#1}\storedataA#2\end}
\def\storedataA#1{\advance\tmpnum by1
\ifx\end#1\else
\expandafter\def\csname data:\tmp:\the\tmpnum\endcsname{#1}%
\expandafter\storedataA\fi
}
\def\getdata[#1]#2{\csname data:\string#2:#1\endcsname}
\storedata\List{{$0$}{$1$}{$\ast$}{$\times$}
{$0$}{$1$}{$\ast$}{$\times$}
{$0$}{$1$}{$\ast$}{$\times$}
{$0$}{$1$}{$\ast$}{$\times$}}
\foreach \x in {1,...,4}
\foreach \y in {1,...,4}
\draw (\x,\y,0) -- (\x+1,\y,0) --(\x+1,\y+1,0)--(\x,\y+1,0) -- (\x,\y,0) node [midway,sloped,above,xslant=0.5]{\getdata[\x+\y]\List};
\end{tikzpicture}
\end{document}
I have some troubles understanding why it actually does not perform the addition of the two variables. Furthermore I tried printing just the \x+y value and it looked like it was doing a string concatenation e.g. :
\x+\y = "x + y" as
I am sorry for this dumb question, I hope some tikz-ninjas and TeX-samurais can help.
etoolbox
when you don't use it? Do you need help with creating the list and storing and getting values to/from it? Or what exactly is your question here?\numexpr
or\pgfmathparse
or the like. TeX only performs calculations when the defintion of a command tells it to do so. So,1 + 1
will print "1 + 1", but\the\numexpr1 + 1\relax
, for example, or\pgfmathparse{int(1 + 1)}\pgfmathresult
would print "2".