我正在尝试编译以下代码。如果我不将任何代码放入&
我的环境中,它确实可以工作,但如果我放入,我会收到错误:
ERROR: Argument of \environment pral has an extra }
--- TeX said ---
<inserted text>
\par
l.20 \end{align}
遗憾的是我需要放进&
去。有什么解决办法吗?
谢谢!
\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}
答案1
您不需要这个b
参数,它只应在真正必要时使用。
\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}