[Tex/LaTex] When should one use \begingroup instead of \bgroup

best practicesgroupingimplicit-bracestex-core

Is there ever a case when the use of \begingroup is preferred to \bgroup? Obviously, \bgroup is necessary in cases where you need to have balanced braces and thus cannot use {, but when is it necessary to use \begingroup?

A related question would be: What's the difference between a simple group and a semi-simple group?

Best Answer

\bgroup is a synonym for {, which is defined in Plain TeX using \let\bgroup={.

It interacts with TeX's "digestive system" in hairy ways: {s and \bgroups start the same sort of groups, called simple groups, and each can be terminated with either }s or \egroups, since they are the same. But when the TeX digestive system encounters them, they are of different catcodes, so commands that look ahead, e.g., in LaTeX with \section\bgroup Title}, can break this matching.

\begingroup is different. It is a TeX primitive, and it matches a different sort of group that TeX accounts for separately, called "semi-simple groups" (a Knuth joke, I assume). Thus a \begingroup must be terminated by an \endgroup, not a }, and vice versa for \endgroup.

I generally avoid \bgroup, and use \begingroup, but \bgroup could be useful if you are messing about with a nested token list.

Related Question