21

When I compile the following document, I get no error

\documentclass{article}

\newcommand{\foo}{foo}

\begin{document}
Why is \foo{ indifferent about its closing brace?
\end{document}

yet there is no } for \foo. Using \newcommand* makes no difference. The document compiles identically to if the closing brace had been present.

1
  • Good question. My guess is that opening braces that are unmatched at the end of the document are ok. Note that it has nothing to do with your \newcommand. The following code produces the same effect. \documentclass{article} \begin{document} Why is { indifferent about its closing brace? \end{document}
    – JPi
    Commented Sep 3, 2016 at 1:21

1 Answer 1

31

\foo is defined without arguments, so TeX does not look for any. Often, {}<space> is used to "terminate" the control sequence for macros without arguments (like this: \foo{}<space>), producing the expansion of the macro plus a trailing space, but this is by no means required, and \foo\<space> accomplishes the same thing.

From that point, since the brace was not used to delimit an argument, { enters a group, which is reported in the log file:

### simple group (level 1) entered at line 6 ({)

Then, the document ends before the group is closed (which is not an error), which is also reported in the log file:

(\end occurred inside a group at level 1)

For some reason, trailing spaces are not shown in inline code fragments here, so I have marked these with <space> because they are important to the discussion at hand. In the actual code, of course, <space> is a single space character.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .