(La)TeX has a low-level mechanism for matching braces in document text. This means you can type something like:
and know that the first brace (for the argument of\section{All \emph{OK} now.}
\section
) will
be matched with the last brace, and the internal pair of braces (for
the argument of \emph
) will be matched with each other. It’s all
very simple.
However, LaTeX has a convention of enclosing optional arguments in brackets, as in:
These brackets are not matched by TeX mechanisms, despite the superficial similarity of their use. As a result, straightforward-looking usages like:\section[OK]{All \emph{OK} now.}
aren’t OK at all — the optional argument comes to consist of “All [OK”, and\section[All [OK] now]{All \emph{OK} now.}
\section
takes the single character “n” (of
the first “now”) as its argument.
Fortunately, TeX’s scanning mechanisms helps us by accepting the syntax “{]}” to ‘hide’ the closing bracket from the scanning mechanism that LaTeX uses. In practice, the commonest way to use this facility is:
since bracing the bracket on its own “looks odd”.\section[All {[OK]} now]{All \emph{OK} now.}
LaTeX has another argument syntax, even less regular, where the argument is enclosed in parentheses, as in:
(a picture environment command).\put(1,2){foo}
This mechanism is also prone to problems with matching closing parentheses, but the issue seldom arises since such arguments rarely contain text. If it were to arise, the same solution (enclosing the confused characters in braces) would solve the problem.
This question on the Web: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=matchbrak