我使用此公式命令来减少创建对齐公式块时的输入。我想在此命令中使用空行来帮助构建我的 LaTeX 源。目前,这些会导致错误,因为显示公式环境不支持它们。在将内容转发到 amsmath 环境之前,我如何从中删除所有空行#1
,但保留?\\
最小示例:
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newcommand{\eq}[1]{\begin{equation}\begin{aligned}#1\end{aligned}\end{equation}}
\makeatother
\begin{document}
\eq{
z &= f(y) \\
y &= f(x) \\
x &= 5
}
\end{document}
错误信息:
Runaway argument?
\begin {aligned} z &= f(y) \\ y &= f(x) \\
! Paragraph ended before \gather was complete.
<to be read again>
\par
l.14 }
I suspect you've forgotten a `}', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.
答案1
我建议不是这样做,但您可以在行尾放置一个普通空格,而不是,^M
这样它就永远不会生成\par
。
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newcommand{\eq}{\begingroup\endlinechar=32 \eqx}
\newcommand{\eqx}[1]{\endlinechar=32 \begin{gather}\begin{aligned}#1\end{aligned}\end{gather}\endgroup}
\makeatother
\begin{document}
\eq{
z &= f(y) \\
y &= f(x) \\
x &= 5
}
\end{document}