summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-endingroup.html
blob: cbb44ff71dd1d952d7c9224dd4d94a72a780c969 (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
58
59
60
61
62
63
64
65
66
67
68
69
<head>
<title>UK TeX FAQ -- question label endingroup</title>
</head><body>
<h3><code>\</code><code>end</code> occurred inside a group</h3>
<p/>The actual error we observe is:
<p/>
<code>(\end occurred inside a group at level &#60;</code><code><em>n</em></code><code>&#62;)</code>
<p/>
and it tells us that something we started in the document never got
finished before we ended the document itself.  The things involved
(&#8216;groups&#8217;) are what TeX uses for restricting the scope of things:
you see them, for example, in the &#8220;traditional&#8221; font selection
commands: <code>{\it stuff\/}</code> &#8212; if the closing brace is left off such a
construct, the effect of <code>\</code><code>it</code> will last to the end of the document,
and you&#8217;ll get the diagnostic.
<p/>TeX itself doesn&#8217;t tell you where your problem is, but you can
often spot it by looking at the typeset output in a previewer.
Otherwise, you can usually find mismatched braces using an intelligent
editor (at least <i>emacs</i> and <i>winedt</i> offer this facility).
However, groups are not <em>only</em> created by matching
<code>{</code> with <code>}</code>:
other grouping commands are discussed elsewhere in these FAQs,
and are also a potential source of unclosed group.
<p/><code>\</code><code>begin{&lt;<i>environment</i>&gt;}</code> encloses the environment&#8217;s body
in a group, and establishes its own diagnostic mechanism.  If you end
the document before closing some other environment, you get the
&#8216;usual&#8217; LaTeX diagnostic

<pre>
! LaTeX Error: \begin{blah} on input line 6 ended by \end{document}.
</pre>
which (though it doesn&#8217;t tell you which <em>file</em> the
<code>\</code><code>begin{blah}</code> was in) is usually enough to locate the
immediate problem.  If you press on past the LaTeX error, you get
one or more repetitions of the &#8220;occurred inside a group&#8221; message
before LaTeX finally exits.  The <i>checkend</i> package
recognises other unclosed <code>\</code><code>begin{blob}</code> commands, and
generates an &#8220;ended by&#8221; error message for each one, rather than
producing the &#8220;occurred inside a group&#8221; message, which is sometimes
useful (if you remember to load the package).
<p/>In the absence of such information from LaTeX, you need to use
&#8220;traditional&#8221; binary search to find the offending group.  Separate
the preamble from the body of your file, and process each half on its
own with the preamble; this tells you which half of the file is at
fault.  Divide again and repeat.  The process needs to be conducted
with care (it&#8217;s obviously possible to split a correctly-written group
by chopping in the wrong place), but it will usually find the problem
fairly quickly.
<p/>e-TeX (and e-LaTeX &#8212; LaTeX run on e-TeX) gives you
further diagnostics after the traditional infuriating TeX one &#8212; it
actually keeps the information in a similar way to LaTeX:

<pre>
(\end occurred inside a group at level 3)

### semi simple group (level 3) entered at line 6 (\begingroup)
### simple group (level 2) entered at line 5 ({)
### simple group (level 1) entered at line 4 ({)
### bottom level
</pre>
The diagnostic not only tells us where the group started, but also the
<em>way</em> it started: <code>\</code><code>begingroup</code> or <code>{</code> (which is an alias of
<code>\</code><code>bgroup</code>, and the two are not  distinguishable at the TeX-engine
level).
<dl>
<dt><tt><i>checkend.sty</i></tt><dd>Distributed as part of <a href="http://mirror.ctan.org/macros/latex/contrib/bezos.zip">macros/latex/contrib/bezos</a> (or <a href="http://mirror.ctan.org/macros/latex/contrib/bezos/">browse the directory</a>); <a href="http://mirror.ctan.org/help/Catalogue/entries/checkend.html">catalogue entry</a>
</dl>
<p/><p>This question on the Web: <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=endingroup">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=endingroup</a>
</body>