# What are the effects of an empty group, {}?

In order to have a syntactic space after a no-argument command, one is taught to delimit the command token with an empty group ({}), like this: \somecommand{} more LaTeX material.

However an empty group isn't without meaning: in math mode, $${} + a$$ is typeset differently from $$+ a$$.

Also, $$\somecommand{} + a$$ and $$\somecommand + a$$ are interestingly different. (Insert for example \empty or \allowbreak for \somecommand here.) (An explanatory note: Spaces don't matter in math mode, so since in $$\somecommand + a$$ the \somecommand eats up the following space, I would have expected the two to yield identical results. An explanation for why these two are different is given here.)

This makes me wonder about what else one might need to pay attention to when using empty groups. What are the effects of an empty group and where might one use one?

-
May be this is somehow related: What is the difference between \relax and {} –  Manuel Feb 5 '13 at 13:27

My understanding is that {} has no effect in printing (so long as it doesn't follow a macro with arguments). As { isn't a letter, the collecting of command name stops (a quirk of TeX is that if the collecting stops at whitespace, said whitespace is gobbled up). In math mode, if you write $+ a$, it is a plus sign, while in $a + b$ it is a binary addition symbol (written the same, different meaning, different spacing). Writing ${} + a$ means nothing (an empty group) added to $a$, i.e., an addition.

Summary:

• In text, use \somecommand{} to stop (La)TeX from eating the following space, or \somecommand{}moretext to stop the command name timely (but perhaps {\somecommand} (if this is safe, meaning \somecommand does not perform an assignment) in both cases is clearer)
• In math, use it as a "nothing here, but pretend there was" term/factor in expressions to force interpretation/spacing as a binary operator.
-
"Expansion" in TeX has a technical meaning that doesn't apply here. More precisely, {} in text mode does (almost) nothing (if it's not the argument to a command). It might prevent automatic kerning if placed in the middle of a word, though. –  egreg Feb 5 '13 at 17:13
@egreg, please edit my ramblings to fix any misunderstandings of wrong wording. –  vonbrand Feb 5 '13 at 18:12
I think egreg's comment about kerning is important. In such a case, one should use \somecommand moretext with nothing in between. –  Bruno Le Floch Feb 5 '13 at 18:49
@egreg Can one really use {\somecommand} instead of \somecommand in all cases where \somecommand does not take arguments? Doesn't the grouping localize (i.e., locally limit) the scope of certain changes? –  Lover of Structure Feb 8 '13 at 14:03
@LoverofStructure If \somecommand performs some assignment, it of course shouldn't be in braces. In most cases parameterless macros don't. –  egreg Feb 8 '13 at 14:12

This is in reply to the OP's question in the @vonbrand answer thread.

In fact, an empty group in the middle of a word (but not just a command by itself) prevents kerning (special spacing between pairs of letters) and ligatures. The effect on ligatures is the most visible.

\def\f{f}
ffi    % => ligature of ffi
f\f i  % => ligature of ffi
f\f{}i % => ligature of ff, then i.
\bye

Here, it is typographically better to simply leave a single space after the parameterless macro \f. Admittedly, this is not a practical example, since no one in their right mind would define such a macro.

A more practical example, perhaps is for someone who defines macros for shorthands of words (don't do this), for instance \c for constrain, and then adds s, or t, or whatever missing letters for plural, verb, etc. The computer modern font (default of TeX) has a little bit of kerning (space) between n and t. In the first two cases, TeX's stomach sees constraints and \c ts as a word, and applies kerning as appropriate. In the last case, the empty group in \c{}ts makes TeX's stomach see two words: constrain and ts, thus no kerning is applied between n and t.

\def\c{constrain}
\def\test#1#2{\setbox0\hbox{#2}\immediate\write16{#1: \the\wd0}}
\test{No shorthand}{This constrains $a$ to obey some constraints.}
\test{No braces}{This \c s $a$ to obey some \c ts.}
\test{Braces}{This \c{}s $a$ to obey some \c{}ts.}
\bye

This might not apply to LuaTeX.

-
I don't think it applies to XeLaTex either. I read somewhere that an empty group is not enough to stop OpenType ligatures in XeLaTeX. –  Johan_E Feb 10 '13 at 0:34

To add to the existing information: In math mode, {} is also used to affect horizontal subscript/superscript positioning and to subtly affect vertical subscript/superscript positioning.

-