[e-lang] Curlies in LaTeX

David Hopwood david.nospam.hopwood at blueyonder.co.uk
Sun Jun 19 08:35:36 EDT 2005

Mark Miller wrote:
> When you define a macro such as
> \newcommand{\pr}[1]{{#1}}                      % principals
> What significance do the double-curlies have? Is this different than 
> single-curlies?

Yes. Normally in [La]TeX curlies are used to delimit a scope. For example,
"{\tt foo} bar" puts "foo" but not "bar" in typewriter font.

In the macro definition, the outer curlies are part of the syntax of
\newcommand. The inner curlies are like the extra parentheses that are
usually added around arguments to C preprocessor macros. Using only
one set of curlies in this example would be like writing this in C:

   #define pr(x) x

which is a bad idea because the macro user may be expecting the
parentheses on the pr() to affect precedence (consider "pr(2+3)*4").
Similarly, a TeX macro user may be expecting the curlies on \pr{}
to delimit a scope (consider "\pr{\tt foo} bar").

Here's a slightly more complicated case:

   \newcommand{\var}[1]{\tt {#1}}                 % variables
   \newcommand{\var}[1]{\emph{\tt {#1}}}          % variables

The former is wrong because the \tt would affect all of the text after
the macro expansion. The latter is correct; it doesn't need an extra pair
of curlies around \emph, for the same reason that

   #define foo(x) bar(x)

doesn't need to be "(bar(x))".

David Hopwood <david.nospam.hopwood at blueyonder.co.uk>

More information about the e-lang mailing list