Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 57 down vote accepted

\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.

share|improve this answer
22  
\begingroup...\endgroup also behaves differently in math mode, in which {...} or \bgroup...\egroup create a subformulae with different spacing. A good rule of thumb would be to avoid using \bgroup...\egroup unless you know you need them. –  Will Robertson Aug 18 '10 at 10:05
2  
I don't know exactly how they behave so my preference goes this way use {} when it works, otherwise \begingroup \endgroup. –  Leo Liu Aug 18 '10 at 14:15
    
Will is right: I'd strongly favour \begingroup ... \endgroup. –  Joseph Wright Aug 18 '10 at 18:35
    
Charles, thanks for the answer. Do you have a reference for the term "semi-simple group"? I can't locate any occurrence of it in the TeXbook... –  Jubobs Nov 21 '13 at 20:32
    
@Jubobs (been away from SO&co for a while) - It's defined in the source and sort of documented in TeX the Program. The Pascal declaration is given define semi_simple_group = 14 {code for '\begingroup...\endgroup'}. In e-Tex, the \tracingmacros command allows you to see the semi-simple groups being called such as you enter and exit them during expansion. –  Charles Stewart Dec 2 '13 at 13:40
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.