TeX Core – Understanding \outer Primitive

tex-core

It seems that this primitive was designed for the purpose that in case programmers forgot to put } in the end of the definition of a macro (in this case, TeX thought all characters until the end of the current file is a part of the definition of this macro). I cannot grasp the idea behind this macro, especially that sentence

When a macro definition is preceded by \outer, the corresponding control
sequence will not be allowed to appear in any place where tokens are being absorbed
at high speed.

How to use \outer and what's the meaning of high speed by DEK?

Best Answer

Don't use \outer it never does anything useful (despite the fact that I use it in the bm package:-)

"High speed" here means when TeX is tokenizing input without evaluating it. So for example in plain TeX

\def\foo{...\newcount\abc  \abc=42 ...}

You get an error as the replacement text of \foo is being collected, as \newcount is outer in plain.

lots of macros reasonably want to embed \newcount. eg a \newthorem construct probably needs to allocate a theorem counter. The plain TeX version has to use contortions like \csname newcount\endcsname just to avoid the outer \newcount token, which is outer just to discourage use of \newcount in a macro that is used often, in a way that would allocate a counter on each use, and run out of count registers.