TeX 何时处于“无模式”?

TeX 何时处于“无模式”?

TeX 有 7 种不同的模式:

  1. 垂直模式:这是 TeX 启动和构建页面的模式。
  2. 内部垂直模式:TeX 在 内处于此模式\vbox{...}
  3. 水平模式:构建段落时。
  4. 受限水平模式:在 内\hbox{...}
  5. 显示数学模式:($$...$$以及 LaTeX 的其他显示数学环境)。
  6. 数学模式:$...$用于内联数学。
  7. 无模式:仅在\write命令内?

no mode可以通过运行以下命令来确定模式的存在

\tracingall
\immediate\write16{\iftrue\fi}
\end

(使用纯 TeX 格式)。日志包含

 \write->\iftrue \fi 
 {no mode: \iftrue: (level 1)}
 {true}
 {\fi: \iftrue (level 1)}

 {vertical mode: blank space  }
 {\end}

如您所见,TeX 会记下在该模式下运行的第一个命令的模式。在此代码片段中,我们可以看到no modevertical mode

到目前为止,我注意到,无论是\message还是都\special将模式更改为no mode。只有\write似乎这样做。

答案1

no modemode在 tex.web 中对应于具有值的变量0。这可以在程序print_mode(§211)中看到,即

else if m=0 then print("no")

现在,TeX 中将此变量设置为零的唯一地方是§1371,这是扩展语句的代码\write

所以对你的问题的答案是:是的,那是唯一的地方。

答案2

这个问题已经得到解答了,但是这很相关并且很有趣。

TUGboat,第 11 卷(1990 年),第 2 期,Knuth给出了一组“练习TeX:程序,其中23号是

  1. 找到一个简短的程序,它将导致 打印模式子程序打印' no mode'。(不要假设已预加载纯 TeX 的类别代码或宏。)在所有提交的正确解决方案中,程序最短(即标记最少)的人将获得额外积分。

然后后续文章提供练习答案的网站称

  1. TeX 仅在处理语句时处于“无模式” ,并且仅\write在以下情况下打印模式: \write跟踪命令> 1 在展开时。我们可能认为\catcode操作是必要的,因此存在左右括号\write;但可以让 TeX 的错误恢复机制提供它们!因此,满足要求的最短程序可能是以下程序,它基于 Ronaldo Amá 的想法,他建议将
    \batchmode\tracingcommands2
    \immediate\write!\nomode

放入文件中。(总共 7 个 token。)

那么让我们尝试一下。我使用 iniTeX 只是为了表明它不依赖于纯 TeX(尽管如果加载了纯 TeX 它会起作用)。请原谅 TeX Live 版本太过时了;这是目前我获取 iniTeX 最简单的方法。

$ ed
a
\batchmode\tracingcommands2
\immediate\write!\nomode
.
wq nomode.tex
53
$ initex
This is TeX, Version 3.14159265 (TeX Live 2015/Debian) (INITEX)
**\input nomode.tex
(./nomode.tex
$

哦,对了。因为\batchmode,所有重要的输出都在转录文件中,我将完整地重现它。

This is TeX, Version 3.14159265 (TeX Live 2015/Debian) (INITEX)  5 JAN 2020 10:11
**\input nomode.tex
(./nomode.tex
{vertical mode: \immediate}
! Missing number, treated as zero.
<to be read again> 
                   !
l.2 \immediate\write!
                     \nomode
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

! Missing { inserted.
<to be read again> 
                   !
l.2 \immediate\write!
                     \nomode
A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.
(If you're confused by all this, try typing `I}' now.)

)
Runaway text?
!\nomode 
! File ended while scanning text of \write.
<inserted text> 
                }
<*> \input nomode.tex

I suspect you have forgotten a `}', causing me
to read past where you wanted me to stop.
I'll try to recover; but if the error is serious,
you'd better type `E' or `X' now and fix your file.

{no mode: undefined}
! Undefined control sequence.
<write> !\nomode 

...
<*> \input nomode.tex

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

!
! Emergency stop.
<*> \input nomode.tex

*** (job aborted, no legal \end found)

No pages of output.

相关内容