[Tex/LaTex] Does TeX always insert the macro \par

macrosparagraphstex-core

When the input processor encounters two characters with category code 5 in a row (in other words, a blank line), it inserts the \par macro.

When \vbox{Abc.} ends, TeX ends the current paragraph, but not by inserting the \par macro. It seems that TeX is inserting the \par primitive instead. Am I understanding correctly what TeX is doing in this case? What about other places where TeX inserts \par? When is it the macro \par, and when the primitive?

\catcode`@=11
\let\@@par\par
\def\par{\typeout{Macro!}\@@par}

Abc.

\vbox{Abc.\tracingall}

Best Answer

There are exactly 7 places in the TeX program where TeX executes the paragraph builder internally, i.e. turning a horizontal list (if there is one under construction) into a paragraph. This happens not by inserting a \par token into the input stream but by executing the procedure end_graf implemented in module §1096 in the TeX program.

This procedure does nothing if TeX is not in horizontal mode, more or less nothing if in horizontal mode but with an empty list (null paragraphs are ignored by TeX), and executes the procedure line_break otherwise (and that one does all the magic about adding parfillskip penalties, etc.).

The seven places are

  • at the end of the internal vertical structures like the closing brace of a \vbox but also \noalign or \vcenter or an alignment cell
  • when the primitive par_end is sensed (which is available on the macro level initially as the meaning of the token \par)
  • immediately after an output routine (OR) has ended (thus any horizontal list started in the OR will not continue with material from the galley but form a paragraph by its own)

In none of these cases there is a \par token inserted (that might be subject to redefinitions); instead, the end_graf procedure is executed!

\par tokens are only inserted when in horizontal mode and primitives incompatible with horizontal mode (like \vskip, \hrule, ... the full list in is §1094 in the TeX code) are encountered. And of course in the tokenization process when TeX replaces two endline chars by \par (i.e., making empty lines equivalent to \par).