代码可以更短,MWE也应该更短!!!
正常情况下,#2
不需要显式写入\newenvironment
的定义中<begin-def>
的部分,对于:
\begin{env}
<something>
\end{env}
LaTeX
会自动把<something>
自动插入到<begin-def>
与<end-def>
之间。
区别下面的例子:
\documentclass{article}
\usepackage{tcolorbox}
\newenvironment{tcbA}[2][]{%
\begin{tcolorbox}[#1]
#2
}{\end{tcolorbox}}
\newenvironment{tcbB}[1][]{%
\begin{tcolorbox}[#1]
}{\end{tcolorbox}}
\begin{document}
\begin{tcbA}
Hello, \LaTeX !
\end{tcbA}
\begin{tcbB}
Hello, \LaTeX !
\end{tcbB}
\end{document}
在你的MWE中,因为#2
是必须参数,因此\begin{tcbA}
在处理时,第一个参数optional argument未指定,所以为默认的<empty>
;但是第二个参数mandatory argument缺失,所以TeX
先自动吞下(swallow)了一个token H
.在<begin-def>
命令结束后,之后再把ello, \LaTeX{}
的内容作为<something>
放进tcb
内部。
问 Hello的H后面的空格如何产生的?如何消除?