After looking around at some other answers on this site, I'm trying to typeset a tree using the tikz-qtree package. It works great, but by design it does not let you use macros in the tree nodes, unless you use the two specific macros \node and \edge to define TikZ nodes and edges directly.
What I'd like to have is something along the lines of
\tikzset{every tree node/.style={
execute at begin node=\code\bgroup,
execute at end node=\egroup}}
where at the moment, \code locally sets up some symbols and then sets the text in TT font:
\newcommand{\code}[1]{{\def\_{\wild}%
\def\"{\quot}% dummy " for hightlighting...
\def\~{\symbol{126}}%
\def\^{\symbol{94}}%
\texttt{#1}}}
This compiles, but doesn't typeset the node text in TT font. Bizarrely, if I just change \impl to \texttt directly, it does typeset in TT font. I know that TikZ plays around with null fonts and such, to ensure things get typeset only when they're supposed to, so I'm not terribly surprised that this font-changing of a node is tricky.
I saw in another question that it's suggested to use \begingroup/\endgroup instead of \bgroup/\egroup. I tried that, but LaTeX complains about "Missing } inserted; Extra } or forgotten \endgroup"
A minimum (non-)working example is below:
\usepackage{tikz-qtree}
\usepackage{tikz}
\usetikzlibrary[trees]
\newcommand{\code}[1]{{\def\_{\wild}%
\def\"{\quot}% dummy " for hightlighting...
\def\~{\symbol{126}}%
\def\^{\symbol{94}}%
\texttt{#1}}}
\begin{tikzpicture}[grow=down]
\tikzset{every tree node/.style={
execute at begin node=\strut\code\bgroup,
execute at end node=\egroup}};
\Tree [.html head body ]
\end{tikzpicture}
I'm not sure whether my use of \bgroup/\egroup is wrong, or whether my definition of \code is faulty...