Relatively simple problem: I want to use macros to define substructures of a tree. In the following example for illustration, I want to define some children (left and right) to be used several times in a tree.
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\newcommand{\leftchildren}{%
child{node[circle,draw] {l}} child{node[circle,draw] {l}} %
}%
\newcommand{\rightchildren}{%
child{node[circle,draw] {r}} child{node[circle,draw] {r}} %
}%
\node[circle,draw] (root) {} \leftchildren \rightchildren;
\end{tikzpicture}
\end{document}
The problem is
Without the label
(root)it does not even compile (Why?)The macros are not expanded on the same level: the right children become children of the left children
Using more macros, or nesting them, makes it worse.
This is a very simplified version of what I want to do. Often I want to be able to add other children by hand (without using macro). I also would like to be able to define entire subtrees as macros, for example a long chain, as a macro.
I think there is a problem with the expansion of the macros, but I was not able to figure it out myself. Help please.
Cheers, Oliver



\expandafter\leftchildren\rightchildrendoes what I would expect your code to produce. – Andrew Stacey Jun 13 '12 at 11:45\edef\children{\leftchildren\rightchildren}but that wouldn't work if there was fancy stuff going on. – Andrew Stacey Jun 13 '12 at 11:47(root)is not necessary without using macros! – Oliver Jun 13 '12 at 12:52