I'm discovering TikZ. I'm using it to draw a fairly complex automaton (something around 20 states). I did it the all manual way (ie by specifying all the states and all the connections). Though it was very long and really boring, so now I try to do it the correct way (ie by doing some looping).
Though I encounter a kinda big problem: I'd like to program a bit but I don't know what are the common tools (ie variables and things like that) available to me. I do know the basis of TeX and even started reading the TeX book, but I'm not advanced in it yet and still lack the basis.
Here for example I'd like to loop through a list of node and link it to the next one. For that I'd like to memorize the last node I went through so that it can be the departure of my next link (I tried to provide a MWE but my actual automaton is way bigger).
My attempt:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{arrows, automata}
\begin{document}
\begin{tikzpicture}
\node[initial,state] (A) {A};
\node[state] (B) [right of=A] {B};
\node[state] (C) [right of=B] {C};
\node[state, accepting] (D) [right of=C] {D};
\newcommand\from{A}
\foreach \to in {B, C, D}
{
\path (\from) edge [-] (\to);
\renewcommand\from{\to};
}
\end{tikzpicture}
\end{document}
I tried \def instead of \newcommand and \renewcommand, but to no avail.
So what I'd like is a pointer towards a good tutorial where I could grab all those basic principles, because the TikZ/pgf manual is large and I didn't find the info I need. The principles I'd like to learn are the basis of TikZ programming.
PS: I guess my question must have been asked before. However I didn't find an answer in the questions I got as a result for my research.

\global\let\from=\to– Andrew Stacey Nov 23 '12 at 00:05