# Can't put & inside environment?

I'm trying to make the following code compile. It does work if I don't put any & in my environment, but if I do I get an error:

ERROR: Argument of \environment pral  has an extra }
--- TeX said ---
<inserted text>
\par
l.20   \end{align}


Sadly I do need to put & inside. Any solution?

Thanks!

\documentclass{article}
\usepackage{mathtools}

\usepackage{xparse}
\NewDocumentEnvironment{pral}{sob}{%
\Pr\IfValueT{#2}{_{\IfBooleanTF{#1}{\substack{#2}}{#2}}}\begin{alignedat}[t]{2}[\,#3\,]\end{alignedat}
}{}

\begin{document}
\begin{align}
&
\begin{pral}[a \leftarrow \{0,1\}]
% works without the & on the next two lines:
&\forall x\\
&a \geq \delta
\end{pral}\\
&\geq \eta
\end{align}
\end{document}


You don't need the b argument, which should only be used when really necessary.

\documentclass{article}
\usepackage{mathtools}

\usepackage{xparse}

\NewDocumentEnvironment{pral}{so}
{%
\Pr\IfValueT{#2}{_{\IfBooleanTF{#1}{\substack{#2}}{#2}}}
\begin{alignedat}[t]{2}[\,
}
{\,]\end{alignedat}}

\begin{document}
\begin{align}
&
\begin{pral}[a \leftarrow \{0,1\}]
&\forall x\\
&a \geq \delta
\end{pral}\\
&\geq \eta
\end{align}
\end{document}


• Thanks! But could you ellaborate a bit more on why the b is an issue here? What should I do if I really need this b? Mar 30 '20 at 9:29
• @tobiasBora The problem is that with the b argument type, the & are not hidden from the scanner. I see no real need for it, do you? Mar 30 '20 at 9:33
• I don't think I need any no, I'm just curious to understand. Thanks! Mar 30 '20 at 9:36