4

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.

cfr
  • 198,882

1 Answers1

5

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 09 '15 at 07:19
  • Thank you! I could have sworn that I tried that in my original tree, but I obviously missed something somewhere. However, I didn't know why and so this is really helpful apart from making me try this again! – cfr Apr 09 '15 at 16:23
  • http://tex.stackexchange.com/a/237562/. – cfr Apr 09 '15 at 16:31