简体   繁体   English

Latex \\ newcommand问题

[英]Latex \newcommand problem

can someone please tell what I'm doing wrong here? 谁能告诉我这里做错了什么?

\newcommand{\bc}{\small\begin{verbatim}}
\newcommand{\ec}{\normalsize\end{verbatim}}

and then 然后

\bc
1  3       6 7 89 10
 22 7  7  45
\ec

but I get 但我明白了

Runaway argument?
^^M1  3       6 7 89 10^^M 22 7  7  45^^M\ec^^M^^M\section{Reading on\ETC.
! File ended while scanning use of \@xverbatim.
<inserted text> 
                \par 
<*> i4c.tex

? 
! Emergency stop.
<inserted text> 
                \par 
<*> i4c.tex

I thought it was pretty safe to do that, since most commands are just text substitutions... any hints? 我认为这样做非常安全,因为大多数命令只是文本替换...任何提示?

How \\begin{verbatim} works. 如何\\begin{verbatim}有效。 briefly and roughly. 简要而粗略地说。

  1. \\begin{verbatim} is expanded to \\verbatim . \\begin{verbatim}扩展为\\verbatim
  2. Then \\verbatim sets category code of each special characters to 12. Now all chars is like digits or puncts. 然后\\verbatim将每个特殊字符的类别代码设置为12.现在所有字符都像数字或符号。
  3. Then \\verbatim sets font, parindent and calls \\@xverbatim . 然后\\verbatim设置font,parindent并调用\\@xverbatim
  4. \\@xverbatim catches the end of verbatim using the following trick: \\@xverbatim使用以下技巧捕获逐字结尾:

     \\def\\@xverbatim#1\\end{#1\\end} 
  5. Then \\end{verbatim} finishes work. 然后\\ end {verbatim}完成工作。

How newcommand{\\bc}{\\small\\begin{verbatim}} works. newcommand{\\bc}{\\small\\begin{verbatim}}工作原理。

  1. \\bс expands to \\small\\begin{verbatim} . \\bс扩展为\\small\\begin{verbatim}
  2. Then \\begin{verbatim} expands to \\varbatim . 然后\\begin{verbatim}扩展为\\varbatim \\varbatim changes all categories and font. \\varbatim更改所有类别和字体。
  3. Then \\verbatim calls \\@xverbatim . 然后\\verbatim调用\\@xverbatim
  4. \\@xverbatim tries to catch your argument using the following trick: \\@xverbatim尝试使用以下技巧捕捉你的论点:

     \\def\\@xverbatim#1\\end{#1\\end} 

    but it is impossible because of \\@xverbatim tries to catch \\end where all letters ( \\ , e , n , d ) have the category 12 and 11. But in fact there are only \\ec exsits. 但这是不可能的,因为\\@xverbatim试图捕捉\\end所有字母( \\end )都有类别12和11.但实际上只有\\ec exsits。

  5. \\@xverbatim is trying and trying to find \\end where backslash ( \\ ) has category 12 but.... File ended while scanning use of \\@xverbatim \\@xverbatim正在尝试并尝试查找\\end ,其中反斜杠( \\ )有类别12但.... File ended while scanning use of \\@xverbatim

verbatim是特殊的,它扫描文字 \\end{verbatim} ,因为在\\begin{verbatim}之后没有执行任何宏替换。

Some environment, such as verbatim , need to scan in the text ahead to find their end manually. 某些环境(例如verbatim )需要在前面的文本中扫描以手动查找它们的结尾。 So unlike “normal” environments, verbatim needs to find the text \\end{verbatim} in the input text, verbatim. 因此,与“普通”环境不同, verbatim需要在输入文本中找到text \\end{verbatim}

In your example, it doesn't (since the input text contains \\ec instead. 在您的示例中,它没有(因为输入文本包含\\ec而不是。

As a workaround, you can instead use the fancyvrb package that defines a Verbatim package and allows definition custom verbatim environments. 作为一种变通方法,您可以改为使用定义Verbatim包的fancyvrb包,并允许定义自定义逐字环境。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM