我定义了一个新的环境eq
来简化equation
,
\newenvironment{eq}{\begin{equation}}{\end{equation}
它可以工作,但似乎环境末尾有一个多余的空格,可以使用以下命令进行测试:
\documentclass{amsart}
\begin{document}
\begin{eq}
a+b=c
\end{eq}
There is a extra space at the end of ``eq'' environment.
\begin{eq}
a+b=c
\end{eq}%
NO extra space exists at the end of ``eq'' environment.
\end{document}
我的问题是如何自动删除多余的空间?
答案1
关于为其他环境定义包装环境,最好对环境开始和结束宏使用“真实”命令,即本例中的\equation
和,并在正确的位置 \endequation
添加尾随字符。%
问题在于,做这样的短包装是否有用;-)
\documentclass{amsart}
\newenvironment{eq}{%
\equation%
}{%
\endequation%
}
\begin{document}
\begin{eq}
a+b=c
\end{eq}
\textbf{Now} there is \textbf{no} extra space at the end of ``eq'' environment.
\begin{eq}
a+b=c
\end{eq}%
NO extra space exists at the end of ``eq'' environment.
\end{document}
答案2
我不知道你为什么要这样做,但\ignorespacesafterend
添加
{\end{equation}\ignorespacesafterend}
代码:
\documentclass{amsart}
\newenvironment{eq}{\begin{equation}}{\end{equation}\ignorespacesafterend}
\begin{document}
\begin{eq}
a+b=c
\end{eq}
There is a extra space at the end of ``eq'' environment.
% <---------- and don't leave a blank line here as a good practice
\begin{eq}
a+b=c
\end{eq}%
NO extra space exists at the end of ``eq'' environment.
\end{document}
以下是使用包的版本environ
:
\documentclass{amsart}
\usepackage{environ}
\NewEnviron{eq}{%
\begin{equation}
\BODY
\end{equation}
}
\begin{document}
\begin{eq}
a+b=c
\end{eq}
There is a extra space at the end of ``eq'' environment.
% and don't leave a blank line here as a good practice
\begin{eq}
a+b=c
\end{eq}%
NO extra space exists at the end of ``eq'' environment.
\end{document}