# macro for empty nodes in tikz-qtree

I'm trying to define a macro for writing empty nodes in a binary tree using tikz-qtree. Referring to the code below, I want the string \missing in my code to be replaced by \edge[draw=none]; {} as-is (just like if I simply did a find and replace in my code).

Is this possible and how can it be done? I don't want to paste \edge[draw=none]; {} every time there is an empty node in my binary tree.

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}

\newcommand{\missing}{ \edge[draw=none]; {} }
%intended usage inside tikzpicture enviornment:
%\Tree  [.3  1
%               \missing ]
%To producce the same result as code below but
%it gave me an error:
%! Undefined control sequence.
%\missing -> \edge
%                  [draw=none]; {}

\begin{document}

\begin{tikzpicture}
\Tree  [.3  1
\edge[draw=none]; {} ]
\end{tikzpicture}

\end{document}

-
Welcome to TeX.sx! A tip: You can use backticks  to mark your inline code as I did in my edit. :) –  Paulo Cereda Jun 7 '12 at 21:35
Unfortunately \edge is not a real command, but a sentinel; if there is, then tikz-qtree is able to do its business. But you can't hide it in a macro. –  egreg Jun 7 '12 at 22:54

You need to encourage \missing to expand at the right time:

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\makeatletter

\let\old@@children\@@children
\def\@@children{\futurelet\my@next\my@@children}
\def\my@@children{%
\ifx\my@next\missing\else
\expandafter\@gobble
\fi
\expandafter\old@@children}

\makeatother

\newcommand{\missing}{ \edge[draw=none]; {} }
%intended usage inside tikzpicture enviornment:
%\Tree  [.3  1
%               \missing ]
%To producce the same result as code below but
%it gave me an error:
%! Undefined control sequence.
%\missing -> \edge
%                  [draw=none]; {}

\begin{document}

\begin{tikzpicture}

\Tree  [.3  1 \missing ]
\end{tikzpicture}

\end{document}
`
-
You are my hero. –  Richard Dec 19 '12 at 10:27