\colorbox → 的三重包装\新环境→ \newenvironment 失败
我试图将使用 \NewEnviron
(包“environ”)创建的环境包装到旧的良好 \newenvironment
中:
\NewEnviron{test}{\colorbox[gray]{0.7}{\BODY}}
\newenvironment{wrapper}{\begin{test}}{\end{test}}
\begin{wrapper}
debug me
\end{wrapper}
但是,这给了我一个奇怪的错误:
LaTeX 错误:输入第 15 行上的 \begin{test} 以 \end{wrapper} 结尾。 LaTeX 错误:输入第 15 行上的 \begin{wrapper} 以 \end{document} 结尾。
如果我将 \NewEnviron{test}{aaa(\BODY)bbb}
替换为 \newenvironment{test}{aaa(}{)bbb}
— 一切都会按预期进行!似乎 \NewEnviron
由于某种原因未能找到其终点。
我正在尝试将“floatfig”包装到 \colorbox
中,所以我需要一种方法将 \colorbox
转换为环境并将其包装到另一个环境中。我可以定义一个新命令,但这不是一个好主意。
I am trying to wrap an environment created with \NewEnviron
(package 'environ') into an old good \newenvironment
:
\NewEnviron{test}{\colorbox[gray]{0.7}{\BODY}}
\newenvironment{wrapper}{\begin{test}}{\end{test}}
\begin{wrapper}
debug me
\end{wrapper}
However, this gives me a strange error:
LaTeX Error: \begin{test} on input line 15 ended by \end{wrapper}.
LaTeX Error: \begin{wrapper} on input line 15 ended by \end{document}.
If I replace \NewEnviron{test}{aaa(\BODY)bbb}
with \newenvironment{test}{aaa(}{)bbb}
— everything works as expected! It seems like \NewEnviron
fails to find its end for some reason.
I'm trying to do some magic with 'floatfig' wrapped into a \colorbox
so I need a way to convert \colorbox
to an environment and wrap it into another one. I can define a new command but it's not a very good idea.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是
\NewEviron
和\newenvironment
的工作方式不同。1)
\newenvironment{test}{aaa(}{)bbb}
定义了两个命令:\test
是aaa(
和\ endtest
是)bbb
。\begin{test}
扩展为\test
。\end{test}
扩展为\endtest
并检查您的范围是否以begin{test}
开头,而不是\begin{something else}
,例如\begin{wrapper}
。2)
\NewEviron{test}{aaa(\BODY)bbb}
以不同的方式定义\test
。首先\test
使用以下技巧捕获\BODY
(名称
\testcontinue
可能不同)并插入aaa(\正文)bbb
。然后\testcontinue
检查某些输入行上的\end
是否以\end{test}
结尾,而不是\end{something else}
。宏\endtest
不需要,因为它从未被执行。
查看您的代码:
\begin{wrapper}
扩展为\begin{test}
。然后\begin{test}
扩展为\test
。\test
捕获\BODY
。注意力!
\BODY
等于调试我
。现在\testcontionue
检查\BODY
之后的\end
以\end{test}
结束。这不是真的。\end{test}
不存在。有
\end{wrapper}
。您想说
\end{wrapper}
必须扩展为\end{test}
。但是wrapper之前的\end
被吃掉了,无法执行。
我希望我能成功解释。
The thing is that
\NewEviron
and\newenvironment
works in different ways.1)
\newenvironment{test}{aaa(}{)bbb}
defines two commands:\test
isaaa(
and\endtest
is)bbb
.\begin{test}
is expanded to\test
.\end{test}
is expanded to\endtest
and checks that your scope begins withbegin{test}
rather\begin{something else}
, for example\begin{wrapper}
.2)
\NewEviron{test}{aaa(\BODY)bbb}
defines\test
in different way. First of all\test
catches the\BODY
using the following trick(name
\testcontinue
may be different) and insertsaaa(\BODY)bbb
. Then\testcontinue
checks that\end
on some input line ended by\end{test}
rather than\end{something else}
. Macro\endtest
is not needed because it is never executed.
Look on your code:
\begin{wrapper}
is expanded to\begin{test}
. Then\begin{test}
is expanded to\test
.\test
catch\BODY
.Attention!
\BODY
is equal todebug me
. And now\testcontionue
checksthat
\end
after\BODY
ended by\end{test}
. It is not true.\end{test}
is absent.There is
\end{wrapper}
.You want to say that
\end{wrapper}
must be expanded to\end{test}
. But\end
before wrapper was eaten byand can not be executed.
I hope I success to explain.
我发现了一个技巧来创建一个可以包含在另一个环境中的环境。人们应该像这样使用 saveBox:
I've found a hacky trick to create an environment that can be wrapped in another one. One should use saveBoxes like this: