The reason is in the definition:
\outer\def\bye{\par\vfill\supereject\end}
So \bye
doesn't just issue \end
(that would by itself issue \par
, but not \vfill
): it also performs \supereject
, which is
\def\supereject{\par\penalty-\@MM}
Why a -20000 penalty? The reason is in the output routine:
\def\plainoutput{\shipout\vbox{\makeheadline\pagebody\makefootline}%
\advancepageno
\ifnum\outputpenalty>-\@MM \else\dosupereject\fi}
If the penalty that triggers the output routine is greater than -20000, nothing special is done after advancing the page number. Otherwise \dosupereject
comes into action:
\def\dosupereject{\ifnum\insertpenalties>\z@ % something is being held over
\line{}\kern-\topskip\nobreak\vfill\supereject\fi}
The macro ensures all pending insertions are shipped out, by repeated call of \supereject
until \insertpenalties
is not positive any more.
One can call \supereject
at any time (which is the reason for \par
at the beginning), for instance when a chapter is beginning.
Some more ideas from comments to the question and to the answer
TeX can be run interactively and it goes interactive if the main input file ends without an \end
command (or makes an “Emergency stop” if the running mode is not interactive). Due to this possible interactivity, an implied \end
command would be undesirable.
Only a few operating systems add an implied <EOF>
marker at the end of a file, which could be ^^D
(EOT) or ^^Z
. The ^^Z
character used to be added in MS-DOS files, but not all text editors were compliant.
Depending on the operating system and the shell, hitting Control-D at the interactive prompt can stop the execution, but no \end
command is executed.
Since TeX keeps a stack of the \input
files, it knows when it has reached the end of the main file, so a possible feature could be “insert the token \end
when you reach the end of the main file”. However, there should also be a “disable automatic \end
” feature to allow interaction at the end of the file. There is a similar feature in TeX: when switching from horizontal to vertical mode due to finding a <vertical command>
, TeX adds a \par
token (which could not be the primitive \par
any more). However, the situation for an “automatic \end
” is very different: breaking a paragraph into files is a common TeX activity, while the end of the main file just happen once.
Having the terminating \end
allows for adding structure to it. One could redefine \end
(after keeping a copy of the primitive) to do other bookkeeping business like \bye
does. So
\let\TeXend\end
\outer\def\bye{\par\vfill\supereject\TeXend}
could be thought of, but it was not Knuth's choice (and it wouldn't be mine as well).
Finally, having \end
(or \bye
or \end{document}
) at the end of the main file allows for putting comments and additional material after the end marker, which wouldn't be possible otherwise. Since most programming languages require programs to be explicitly terminated, I don't see why TeX should be an exception.
Best Answer
The "smallest" possible TeX is what Knuth called "virgin" TeX (TeXbook, p.342): it knows just primitive commands, no macros. Plain TeX is the set of macros (developed by Knuth) which makes TeX usable in everyday life of a typist.
And yes, these days we're using many different sets of macros ... one popular set is of course LaTeX. Plain TeX is, well ... the plainest of these ;-)
Regarding formats (as far as I understand). "Teaching" TeX all the macros (of plain TeX, for example) on each run would take too long (well, at least in the old days). Thus, we do it once for good: we input the definitions and take a snapshot, called a format.
The available commands can be classified into primitive commands and macros. Macros are composite commands built from primitive commands and/or other macros.
The "virgin" TeX knows only the primitive commands. Which primitive commands are known to TeX depends on the particular engine. For example, eTeX has more primitives than the original (Knuth's) TeX;
\unexpanded
is an example of a new eTeX primitive. Examples of primitive commands:\relax
,\def
,\halign
. (There's about 300 of them.)Formats (plain TeX, LaTeX, etc.) extend TeX's vocabulary by defining macros. (Actually, packages also do that.) For example, plain TeX defines macros
\item
,\rm
,\newdimen
,\loop
, etc. (Plain TeX defines about 600 macros. The complete vocabulary of plain TeX has thus about 900 words.)To check whether a command is primitive or a macro, one can:
\show
:\show\cs
writes the meaning of\cs
to the terminal. If you\show
a primitive command, it will simply tell you its "name":\relax=\relax
,halign=\halign
, etc. In contrast, if you use\show
on a macro, you will get its definition, e.g.\newdimen=macro:->\alloc@ 1\dimen \dimendef \insc@unt
.To reiterate, there are two types of commands: