# How can I set a style in \forestset which requires delayed calculations with the results of node walks?

What is the correct way to wrap the specification for the tree below into the my binomial style defined in \forestset and why?

The following code works fine:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{forest}
\def\p{.25}
\begin{document}
\begin{forest}
before typesetting nodes={
for tree={
if level=0{
content={1},
}{
content/.wrap pgfmath arg={#1}{content("!u")*\p},
},
}
},
[A
[B
[D
]
[E
]
]
[C
[F
]
[G
]
]
]
\end{forest}
\end{document}


while the following does not:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{forest}
\forestset{
my binomial/.style={
before typesetting nodes={
for tree={
if level=0{
content={1},
}{
content/.wrap pgfmath arg={#1}{content("!u")*\p},
},
}
},
},
}
\def\p{.25}
\begin{document}
\begin{forest}
my binomial,
[A
[B
[D
]
[E
]
]
[C
[F
]
[G
]
]
]
\end{forest}
\end{document}


Specifically, I get a Missing number, treated as zero \end{forest} error. I'm presuming this has something to do with expansion which I know very little about. If possible, I'd like to understand the problem, independently of whether there's a workaround.

Defining a style creates another macro argument layer, so you need to double the #, like this:
content/.wrap pgfmath arg={##1}{content("!u")*\p},

• \forestset is not to blame. It is the handler .style that introduces another macro argument layer... – Paul Gaborit Apr 9 '15 at 7:19