# Unexpected tikz/counter behaviour

What I've been trying to do, futilely, is to use the foreach[counter=\xi] x in {1,2,3} statement in tikz/pgf with LaTeX. This fails, every time. Whatever. So I moved on to trying to use a counter, surely that would work. Here's a MWE that fails unexpectedly.

\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\newcommand{\test}[1]{
\newcounter{i}
\setcounter{i}{0}
\foreach \x in #1
{
\draw (0,\i) -- (1,0);
\setcounter{i}{\i+1}
}
}

\begin{tikzpicture}
\test{{1,2,3}}
\end{tikzpicture}
\end{document}


This code, at least for me, produces

Can anyone explain why? How I would fix this, or how I could actually get foreach[counter=\xi] to work without returning an \inaccessible exception upon compilation in pdfLaTeX

-
Using \xi as counter variable is not a good idea, at least if you also want to use the Greek letter ξ in your document (which becomes inaccessible after running the loop). –  Caramdir Nov 26 '10 at 23:44

Check the use of the counter macro. You may access its value by \value{i} instead of \i, you can increase it by \stepcounter{i} or \addtocounter{i}{1}. On the other hand you could use \x directly.

So try for example:

\setcounter{i}{0}
\foreach \x in #1
{
\draw (0,\value{i}) -- (1,0);
\stepcounter{i}
}


And without the additional counter it's just:

\foreach \x in #1
{
\draw (0,\x) -- (1,0);
}

-

Which version of TikZ are you using? The count (not counter) option was introduced in version 2.10 (sorry for not adding this info to my answer to your other question). If you are using TeX Live 2010, then a simple tlmgr update --all will (amongst others) update TikZ to the current version.

-