Braces are not just for delimiting arguments.
Braces around arguments are generally only necessary if the argument consists of more than one token (according to TeX's rules). So \tilde{\psi}
is the same as \tilde\psi
, but \textbf psi
will only make p
bold.
One of the goals of LaTeX clearly was to tame TeX's free-wheeling syntax: TeX allows macros to be defined with arbitrary delimiters for the arguments, for example. This feature is nowhere to be seen in the LaTeX interface, though LaTeX uses it internally for the optional argument feature (\macro[optional argument]{obligatory argument}
). Some TeX built-ins require braces (like \hbox
, as David Carlisle wrote), while others prohibit them: you must write \vskip 1cm
and not \vskip{1cm}
. LaTeX introduces equivalents (\vspace
) that always accept braces around arguments, and the LaTeX book further "standardizes" the syntax by always writing the braces, even when the language does not require them. Users of plain TeX don't seem to use cosmetic braces nearly as much as LaTeX users.
But in addition to macro arguments, there's another important function of braces: They delimit the scope of non-\global
declarations. For example, the effects of \center
, \raggedright
, and font commands like \bfseries
, \itshape
and the (deprecated) \rm, \it, \bf
persist until the end of the brace group that contains them:
This paragraph begins with regular text, {\bfseries switches to bold text} and
returns to regular text at the end of the group.
While braces around macro arguments are generally harmless, redundant braces can have puzzling effects-- especially in combination with paragraph formatting commands, which must still be in scope when the paragraph ends. The following snippet will not be set ragged right:
\begin{itemize}
\item {\raggedright This is a paragraph of italic text, intended
to be typeset with a ragged right margin. But because the braces introduce
a scope, the closing brace unsets the ragged right parameters before the
paragraph can be formatted.}
\end{itemize}
No braces are needed after \item
, of course; but some people use them in the mistaken belief that \item
takes an argument, and that this style of coding is more "readable". The brace group ends just before the paragraph does, so the paragraph is justified like the rest of the document. (Instead of dropping the braces, the snippet could also be fixed by ending the paragraph inside the brace group: ... can be formatted.\par}
Conclusion: Braces are an integral part of TeX's syntax. LaTeX style encourages using them more than the TeX engine requires, but some redundant braces are not harmless. A basic understanding of their function helps one know when they can be omitted, and when they should be. Some handy principles:
Braces delimiting a macro argument do not create a scope (they are consumed on parsing the argument). However, some commands will themselves introduce a brace group in their expansion. The following will not be typeset ragged right, because the implementation of \emph
expands its argument inside a brace group:
\emph{\raggedright Some text I tried to typeset italic and ragged right.}
The braces around a macro definition also do not create a scope, allowing us to write things like
\newcommand\mybold{this: \bfseries}
Everything after \mybold is now set in boldface.
which produces:
Everything after this: is now set in boldface.
LaTeX's \begin{something}
and \end{something}
macros internally add a brace group, so they are scope delimiters.
$\frac{1}{2}$
vs$\frac12$
.p_1
top_{01}
and notp_01
. Also it helps if someone else is going to read your code. In fact it is a good practice to write your code thinking that someone else will read it. At the end of the day it is a matter of personal choice.\frac12
is not Knuthian - in Plain Tex one writes1 \over 2
, which is more readable (if perhaps more dangerous) than\frac{1}{2}
.