[Tex/LaTex] What does the \the\everypar do

tex-core

If you test the following minimal it does not produce an error. What does it actually do?

\the\everypar
\bye

Why doesn't it produce an error as one would expect?

Best Answer

\everypar is a token list register, so its value is assigned by

\everypar={<tokens>}

Its default value in Plain TeX is empty.

What's for? Its contents is delivered into the token list TeX is reading when it switches from vertical to horizontal mode. This happens when TeX, in vertical mode, sees a horizontal command, for instance a character to be typeset or \indent or \noindent.

At that time the horizontal command is set aside; before examining it again, TeX contributes \parskip glue to the vertical list and goes into horizontal mode; now it delivers the contents of \everypar as if \the\everypar was implicit and reexamines the horizontal command that forced the switch to horizontal mode. However the switching to horizontal mode caused by a horizontal command other than \noindent causes TeX to insert an empty box of width \parindent before the contents of \everypar.

One can use \everypar to perform automatically some job at paragraph start, for example to number them.

LaTeX exploits heavily this mechanism, so it's not recommended to play with it when the job involves lists. An example is the declaration

\everypar{\@nodocument}

that is in force until \begin{document} is processed; \@nodocument issues the error message Missing \begin{document} in order to warn the user that text starting a paragraph has been found in the preamble.

As all token registers, its value can be augmented by

\everypar=\expandafter{\the\everypar<tokens>}

since \the\everypar will deliver the current register's contents.

Related Question