I want to create an environment for drawing same-styled derivation trees in my document. I sometimes want this environment placed in a certain float, but sometimes I want a different one (like using a landscape-rotated page or whatever), so I split my favorite float to be an outer environment and my inner float to be the tikz tree. unfortunately, this created a recursion in tex that exploded my stack. Here's a code example:
\documentclass[12pt]{article}
\usepackage{environ}
\usepackage{tikz}
\NewEnviron{AST}{
\begin{tikzpicture}
[
sibling distance = 6em,
level distance = 6em,
align = center,
grow' = right,
every node/.style = {shape=rectangle, rounded corners,
draw, align=center,
top color=white, bottom color=blue!20},
leaf/.style = {font=\ttfamily}
]
\BODY\
\end{tikzpicture}
}
% #1 is short name for figure
% #2 is long name for figure
\NewEnviron{ASTfig}[2]{
\begin{figure}[hbp]
\begin{center}
\begin{AST}
\BODY\
\end{AST}
\end{center}
\caption[AST - #1]{Abstract Syntax Tree - #2}
\end{figure}
}
\begin{document}
\begin{ASTfig}{shambalulu}{bambashushu}
\node {root}
child { node {node}
child { node [leaf] {leafy} }
child { node [leaf] {mcleaf} }
}
};
\end{ASTfig}
\end{document}
I guess it's because tex is trying to replace \BODY\ with \BODY\ ad infinitum. I flipped through the documentation and tried using the \environbodyname command, but it changed \BODY on both cases and did not solve the problem.
what am I missing?


