# Conflict between beamer and forest

There appears to be a conflict when I'm using the forest package to build trees in a beamer presentation. Whenever I use the delay option (possibly only in combination with content, have not used it otherwise), the following error appears:

! Illegal parameter number in definition of \beamer@doifinframe.

Despite the error, a pdf is generated on Overleaf, providing the tree I wanted, but TeXworks is not that kind to me.

What is causing the error and how to solve it?

MWE (from the forest documentation)

\documentclass{beamer}

\usepackage{forest}

\begin{document}

\begin{frame}

\begin{forest}
[roman, delay={for children={content=\romannumeral##1}}
[1][2][3][4]
]\end{forest}

\end{frame}

\end{document}


Which renders:

• Add fragile and drop a #: \begin{frame}[fragile] \begin{forest} [roman, delay={for children={content=\romannumeral#1}} [1][2][3][4] ]\end{forest} \end{frame}
– user194703
Mar 23, 2020 at 22:31
• Or, if you do not like fragile, use four (!) #: \begin{frame} \begin{forest} [roman, delay={for children={content=\romannumeral####1}} [1][2][3][4] ]\end{forest} \end{frame}. Why four? Because three is too little and five too much. ;-)
– user194703
Mar 23, 2020 at 22:39

In a way, this is a duplicate to this question and many others. As Martin Scharrer explains,

The frame environment is a pseudo-environment, i.e. actually \frame{ .. } in disguise.

What that means is that one has to be careful with the #. forest is no exception to this, so the options are:

• use the fragile option, or
• double the # twice, i.e. quadruple them.

\documentclass{beamer}

\usepackage{forest}

\begin{document}

\begin{frame}[fragile]

\begin{forest}
[roman, delay={for children={content=\romannumeral#1}}
[1][2][3][4]
]\end{forest}

\end{frame}

\begin{frame}

\begin{forest}
[roman, delay={for children={content=\romannumeral####1}}
[1][2][3][4]
]\end{forest}

\end{frame}
\end{document}


This yields two identical frames:

In particular, there is no genuine conflict between forest and beamer, just the usual subtleties of defining and using macros with arguments in frames.