Latex \newcommand for \end{verbatim} et.al 不起作用
我试图通过引入一些节省时间的方法来使 Latex 可用,但我在定义完全随机终止环境的新命令时遇到了麻烦。
这有效:
<代码>\newcommand{\bcv}{\ensuremath{\begin{smallmatrix}}} \newcommand{\ecv}{\ensuremath{\end{smallmatrix}}} \newcommand{\be}{\begin{枚举}}
\newcommand{\ee}{\end{enumerate}}
这不起作用:
<代码>\newcommand{\bal}{\begin{align*}}
\newcommand{\eal}{\end{align*}}\newcommand{\verbass}[1]{\begin{verbatim} #1 \end {verbatim}}
具体来说,我认为 \end 值被忽略了?
当我尝试使用 \verbass{Halp}
时,出现错误:!文件在扫描 \@xverbatim 的使用时结束。
显然我可以使用 \begin{foo} 。 .. \end{foo} 在需要的所有位置,但实际上,这应该有效!
I'm trying to make Latex usable, by introducing some timesavers, but I'm having trouble with defining new commands that terminate environments, completely at random.
This works:\newcommand{\bcv}{\ensuremath{\begin{smallmatrix}}}
\newcommand{\ecv}{\ensuremath{\end{smallmatrix}}}\newcommand{\be}{\begin{enumerate}}
\newcommand{\ee}{\end{enumerate}}
This does not work:\newcommand{\bal}{\begin{align*}}
\newcommand{\eal}{\end{align*}}\newcommand{\verbass}[1]{\begin{verbatim} #1 \end {verbatim}}
Specifically, I think the \end value is just ignored?
When I try to use \verbass{Halp}
I get an error: !File ended while scanning use of \@xverbatim.
Obviously I can use \begin{foo} ... \end{foo} at all locations as needed, but really, this should work!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
\begin{verbatim}
的工作原理。简要而粗略地。\begin{verbatim}
扩展为\verbatim
。\verbatim
将每个字符的类别代码设置为11。现在所有字符都是字母。
\verbatim
设置字体、parindent 并调用\@xverbatim
。\@xverbatim
使用以下技巧捕获逐字结尾:<前><代码>\def\@xverbatim#1\end{#1\end}
然后 \end{verbatim} 完成工作。
\newcommand{\verbass}[1]{\begin{verbatim} #1 \end {verbatim}}
的工作原理。\verbass{Halp}
读取它的参数。\verbass
扩展为\begin{verbatim} Halp \end {verbatim}
。重要提示:
\end
的反斜杠属于类别 0 而不是 11。此外,
{
和}
具有类别 1 和 2,而不是 11。\begin{verbatim}
扩展为\varbatim
。\varbatim
更改所有类别和字体。但是(重要)反斜杠的类别(在
\end
中)保持等于 0。\verbatim
调用\@xverbatim
。\@xverbatim
尝试使用以下技巧来捕捉你的论点:<前><代码>\def\@xverbatim#1\end{#1\end}
但这是不可能的,因为
\@xverbatim
试图捕获\end
其中所有字母 (\
,e
,n
,d
) 都有第11类。但实际上还有四个字母带有其他类别代码:
\
为类别 0,e
、n
、d
为类别 11。\@xverbatim 正在尝试并尝试查找
\end
,其中反斜杠 (\
) 的类别为 11,但是......文件在扫描 \@xverbatim< 的使用时结束/代码>
How
\begin{verbatim}
works. briefly and roughly.\begin{verbatim}
is expanded to\verbatim
.\verbatim
sets category code of each characters to 11.Now all chars is letters.
\verbatim
sets font, parindent and calls\@xverbatim
.\@xverbatim
catches the end of verbatim using the following trick:Then \end{verbatim} finishes work.
How
\newcommand{\verbass}[1]{\begin{verbatim} #1 \end {verbatim}}
work.\verbass{Halp}
reads its argument.#1 --> Halp
\verbass
expands to\begin{verbatim} Halp \end {verbatim}
.Important: backslash of
\end
has category 0 rather than 11.Moreover
{
and}
have categories 1 and 2 rather than 11.\begin{verbatim}
expands to\varbatim
.\varbatim
changes all categories and font. But (important)the category of backslash (in
\end
) remains equal to 0.\verbatim
calls\@xverbatim
.\@xverbatim
tries to catch your argument using the following trick:but it is impossible because of
\@xverbatim
tries to catch\end
where all letters (\
,e
,n
,d
) have the category 11.But in fact there are four letters with other category code:
\
with category 0 ande
,n
,d
with category 11.\@xverbatim
is trying and trying to find\end
where backslash (\
) has category 11 but....File ended while scanning use of \@xverbatim
此处有关于动词和逐字的非常简短的解释。基本上,LaTeX 坚持动词和逐字地首先“查看”其内容。
There's a very brief explanation here about verb and verbatim. Basically, LaTeX insists verb and verbatim get the first "look" at their contents.
我距离成为一名专业程序员还很远,但快速而肮脏的解决方案可能是:
输出不是很好,因为换行符被忽略。如果需要的话,可以逐行重复该命令(?)。
I am far away from being a professional programmer, but a quick-and-dirty-solutions could be:
The output is not very nice, because linebreaks are ignored. If this is desired one could repeat the command line-by-line (?).