I want to print a tree structure and started using the package dirtree (v0.32, see Making a (simple) directory tree). Following calls work smooth:
\dirtree{.1 root. .2 child1. .2 child2. .3 childofchild2. }
\def\mytree{{.1 root. .2 child1. .2 child2. .3 childofchild2. }}
\expandafter\dirtree\mytree{}
\dirtree will draw a tree representation like
root
|-- child1
|-- child2
|-- child of child2
But a problem arises if the generation of the tree data is using some more complex macro.
\documentclass{article}
\usepackage{dirtree}
% edited to remove the use of counters
%\newcounter{qtreedepth}
%\def\nodeC#1{\addtocounter{qtreedepth}{1}#1\addtocounter{qtreedepth}{-1}}
%\renewcommand{\item}[1]{.\arabic{qtreedepth} #1. }
\def\nodeC#1{{#1}}
\newcommand{\myitem}[1]{.1 #1. }
\begin{document}
\nodeC{\myitem{root}\nodeC{\myitem{child}}}
\expandafter\dirtree{\nodeC{\myitem{root}\nodeC{\myitem{child}}}}
\end{document}
The error message:
! Use of \next doesn't match its definition.
<argument> \myitem
{root}\nodeC {\myitem {child}}
l.11 ...nodeC{\myitem{root}\nodeC{\myitem{child}}}
Is there something wrong with the expansion? Is the usage of \expandafter correct? Any idea what is wrong?
(Meanwhile I discovered the page on tree drawing in TikZ, Drawing a directory listing a la the tree command in TikZ. Worth trying, but on the other I'd like to know the reason why above does not work...)

\item, to begin with. Can you give a graphical (approximate) representation of what you want to do? – egreg Jan 15 '13 at 21:26dirtreedocs makes me suspect that\dirtreerequires a fully-expanded argument. So\dirtree{.1 root.}is fine (that's what your\expandafterwill generate), but something with\stepcountercan never work as it's not expandable. – Joseph Wright Jan 15 '13 at 21:38\itemis a leftover because I want to use lists, thus, the redefinition. Reading that environments are not expandable I avoided lists for\dirtree.The graphical output should have a structure like
root |- child1 |- child of child1The input structure should use environments.
\begin{nodeC} \item{root} \begin{nodeC} \item{child1} \begin{nodeC}\item{child of child1}\end{nodeC} \end{nodeC} \end{nodeC}The closest solution would be to change to TikZ package and modify the code of link of Tom Bombadil.
– e-birk Jan 16 '13 at 01:58\dirtreejust wants "plain text" (fully expanded macros).Now I removed all the counter stuff but I get still the same error... Am I doing anything wrong?
– e-birk Jan 16 '13 at 02:18