summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-matchbrak.html
blob: 8f9d04cf2cdd3da717e278a93a1f5d9b56ab0cc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<head>
<title>UK TeX FAQ -- question label matchbrak</title>
</head><body>
<h3>My brackets don&rsquo;t match</h3>
<p/>(La)TeX has a low-level mechanism for matching braces in document
text.  This means you can type something like:
<blockquote>
<pre>
\section{All \emph{OK} now.}
</pre>
</blockquote><p>
and know that the first brace (for the argument of <code>\</code><code>section</code>) will
be matched with the last brace, and the internal pair of braces (for
the argument of <code>\</code><code>emph</code>) will be matched with each other.  It&rsquo;s all
very simple.
<p/>However, LaTeX has a convention of enclosing optional arguments in
brackets, as in:
<blockquote>
<pre>
\section[OK]{All \emph{OK} now.}
</pre>
</blockquote><p>
These brackets are not matched by TeX mechanisms, despite the
superficial similarity of their use.  As a result,
straightforward-looking usages like:
<blockquote>
<pre>
\section[All [OK] now]{All \emph{OK} now.}
</pre>
</blockquote><p>
aren&rsquo;t OK at all &mdash; the optional argument comes to consist of
&ldquo;All [OK&rdquo;, and <code>\</code><code>section</code> takes the single character &ldquo;n&rdquo; (of
the first &ldquo;now&rdquo;) as its argument.
<p/>Fortunately, TeX&rsquo;s scanning mechanisms helps us by accepting the
syntax &ldquo;<code>{]}</code>&rdquo; to &lsquo;hide&rsquo; the closing bracket from the
scanning mechanism that LaTeX uses.  In practice, the commonest way
to use this facility is:
<blockquote>
<pre>
\section[All {[OK]} now]{All \emph{OK} now.}
</pre>
</blockquote><p>
since bracing the bracket on its own &ldquo;looks odd&rdquo;.
<p/>LaTeX has another argument syntax, even less regular, where the
argument is enclosed in parentheses, as in:
<blockquote>
<pre>
\put(1,2){foo}
</pre>
</blockquote><p>
(a picture environment command).
<p/>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.
<p/><p>This question on the Web: <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=matchbrak">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=matchbrak</a>
</body>