For almost an hr I have been starring at this and can't figure where is my syntax error
\documentclass[crop,tikz]{standalone}
\usepackage{amsmath}
\usepackage{forest}
\useforestlibrary{edges}
\begin{document}
\begin{forest}
[
{\begin{align*}
x &= 1
\end{align*}}
]
\end{forest}
\end{document}
Compiling gives
! Missing \endgroup inserted.
<inserted text>
\endgroup
l.16 \end{forest}
I know one needs to add {....}
around all math to protect it and that is what I did. If I use normal math, it works
\documentclass[crop,tikz]{standalone}
\usepackage{amsmath}
\usepackage{forest}
\useforestlibrary{edges}
\begin{document}
\begin{forest}
[
{$x = 1$}
]
\end{forest}
\end{document}
No errors. I also found if I put the align environment in minipage the error goes away:
\documentclass[crop,tikz]{standalone}
\usepackage{amsmath}
\usepackage{forest}
\useforestlibrary{edges}
\begin{document}
\begin{forest}
[
\begin{minipage}{2cm}
{\begin{align*}
x &= 1
\end{align*}}
\end{minipage}
]
\end{forest}
\end{document}
No errors.
So why does the first example above give an error? I know I must be making some syntax error, but I just do not see what it is.
TL 2022
Update
OMG! I find workaround, but have no clue why this makes it work. Simply adding ,text width=3cm
after it, now it works
\documentclass[crop,tikz]{standalone}
\usepackage{amsmath}
\usepackage{forest}
\useforestlibrary{edges}
\begin{document}
\begin{forest}
[
{\begin{align*}
x &= 1
\end{align*}}
,text width=3cm% ADDING THIS MAKES IT WORK
]
\end{forest}
\end{document}
But why??
Update
aligned
does not really do what I want. Here is an example below
\documentclass[crop,tikz]{standalone}
\usepackage{amsmath}
\usepackage{forest}
\useforestlibrary{edges}
\begin{document}
\begin{forest}
[
Write the ode as
{$\begin{aligned}
y'+p(x)y&=q(x)\\
&=f(x,y)
\end{aligned}$}
This is only possible if ode is linear in {$y$}
]
\end{forest}
\end{document}
I wanted it to look like this
\documentclass[crop,tikz]{standalone}
\usepackage{amsmath}
\usepackage{forest}
\useforestlibrary{edges}
\begin{document}
\begin{forest}
[
Write the ode as
{\begin{align*}
y'+p(x)y&=q(x)\\
&=f(x,y)
\end{align*}
}
This is only possible if ode is linear in {$y$}
,text width=3cm
]
\end{forest}
\end{document}
But thanks to the answer, I know now that I needed to add specific value for the width for align*
to work. So I am all OK now. I changed my code to make sure there is a specific text width given and the error now is gone.
\mbox
you can not have vertical displays. a tikz node is an mbox unless you give it a width when it is a minipage{\begin{align*} x &= 1 \end{align*}}
with{$\begin{aligned} x &= 1 \end{aligned}$}
(or, better still, with{$x = 1$}
, as there's nothing to align in this simple example, right?) works too.