Here is an example that does not require quotes: \begin{tikzpicture} \def\mylist{Laura,Katie,Frank,Joe} \foreach[count=\xi] \x in \mylist \node[minimum width=1cm] (n\xi) at (\xi,\xi) {\x}; \end{tikzpicture}. The quotes are needed when you plugin your list into a macro and to protect the text from a math parser!
–
percusseFeb 19 '12 at 17:19

No, i use it not in a foreach loop. Without foreach loop somehow it doesn't work for me, it gives back the whole string. Thanks!
–
deeenesFeb 19 '12 at 21:04

4 Answers
4

This answer may be more generic than specifically relating to TikZ/PGF.

(La)TeX is a macro-based language, so it does not work as expected compared to other languages when dealing with "arrays". For example, while \names[2] should yield Laura where

\def\names{Katie, Frank, Laura, Joe}

(indexing from 0), (La)TeX considers [2] to have no connection to \names. As such, you're more likely to obtain the output Katie, Frank, Laura, Joe[2] - a concatenation of \names (as it is defined) and [2].

In order to allow for indexing like one typically would using arrays, you would need some other functionality. Here's an example of a list parser that works like you would expect arrays do:

The idea here is to store the names in an array \namesarray and then define a macro (or "function") that takes an optional argument. If no argument is supplied (i.e., you just use \names), then you print the entire \namesarray. If an argument is supplied (of the form \names[<index>]), parse the list sequentially to find that item that matches <index> and print it.

Wow, you implemented it very professionally! It works fine. I'm just adding one comment: i can get the values of the array with a counter, like this: \newcounter{i} \setcounter{i}{0} \names[\value{i}] \stepcounter{i} ...So it's perfect!
–
deeenesFeb 19 '12 at 21:08

Thank you for the nice code and explanation!
–
deeenesFeb 19 '12 at 21:16