When is TeX in "no mode"?

no mode in tex.web corresponds to the variable modehaving the value 0. This can be seen in the procedure print_mode (§211), i.e.,

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

Now the only place in TeX where this variable is set to zero is in §1371 which is the code that expands a \write statement.

So the answer to your question is: yes that is the only place.


This question has been answered already, but this is relevant and interesting.

In TUGboat, Volume 11 (1990), No. 2, Knuth gives a set of "Exercises for TeX: The Program", of which number 23 is

  1. Find a short program that will cause the print_mode subroutine to print 'no mode'. (Do not assume that the category codes or macros of plain TeX have been preloaded.) Extra credit will be given to the person who has the shortest program, i.e., the fewest tokens, among all correct solutions submitted.

Then the followup article, which provides answers to the exercises, says

  1. TeX is in 'no mode' only while processing \write statements, and the mode is printed during \write only when tracing_commands > 1 during expand. We might think that \catcode operations are necessary, so that the left and right braces for \write exist; but it's possible to let TeX's error-recovery mechanism supply them! Therefore the shortest program that meets the requirements is probably the following one based on an idea due to Ronaldo Amá, who suggests putting
    \batchmode\tracingcommands2
    \immediate\write!\nomode

into a file. (Seven tokens total.)

So let's try it. I'm using iniTeX just to show that there's no dependency on plain TeX (though it will work if plain TeX is loaded). Please pardon the horribly outdated TeX Live version; it's the simplest way for me to get iniTeX at this moment.

$ 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
$

Oh, right. Because of \batchmode, all of the important output is in the transcript file, which I will reproduce in its entirety.

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.

Tags:

Tex Core