Let's look at how \enddocument
is defined (see latex.ltx
, the LaTeX "kernel"):
\def\enddocument{%
\let\AtEndDocument\@firstofone
\@enddocumenthook
\@checkend{document}%
\clearpage
\begingroup
\if@filesw
\immediate\closeout\@mainaux
\let\@setckpt\@gobbletwo
\let\@newl@bel\@testdef
\@tempswafalse
\makeatletter \@@input\jobname.aux
\fi
\@dofilelist
\ifdim \font@submax >\fontsubfuzz\relax
\@font@warning{Size substitutions with differences\MessageBreak
up to \font@submax\space have occurred.\@gobbletwo}%
\fi
\@defaultsubs
\@refundefined
\if@filesw
\ifx \@multiplelabels \relax
\if@tempswa
\@latex@warning@no@line{Label(s) may have changed.
Rerun to get cross-references right}%
\fi
\else
\@multiplelabels
\fi
\fi
\endgroup
\deadcycles\z@\@@end}
A full discussion of what all is being executed would be very tedious. Among the more interesting activities, in my view..., are (a) the \clearpage
instruction, which flushes all pending floats, (b) the closing of the aux
file, and (c) a check if some cross-references are still unresolved; if there are still-unresolved references, the following famous warning message about needing to rerun LaTeX is generated:
\@latex@warning@no@line{Label(s) may have changed.
Rerun to get cross-references right}%
The definition of \bye
(see p. 357 of the Texbook) follows a completely different model:
\outer\def\bye{\par\vfill\supereject\end}
Finally, here's the definition of \stop
, a macro mentioned in a comment by David Carlisle:
\def\stop{\clearpage\deadcycles\z@\let\par\@@par\@@end}
(\@@end
is a LaTeX-internal version of the "primitive" command \end
.) Can you tell why David added that "it should never be used in normal [LaTeX] documents"?
\bye
and\end{document}
do completely different things, and environments are the main syntactic construct introduced by latex, so why do you find this strange?\begin{document}
? Something close to\bye
is available in latex namely\stop
but it should never be used in normal documents, it's useful in some test cases and error trapping code.\def\bye{\end{document}}
:-)\outer
.:-P