Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Perhaps the most common mistake I make is to forget to place a closing bracket, i.e. }, or closing command, e.g. \end{description}. When compiling, such mistakes usually do not say, "\begin{description} is missing a closing command.", rather, they say something like, "\end{document} appeared unexpectedly."

  • In a large, complicated document, it can be difficult to find the source of such errors.
  • When the errors appear inside an \input file, these are often more difficult to find.
  • These are further made difficult when some macros require additional brackets, e.g. \begin{tabular}{lll}.

Are there any techniques or strategies one can apply to quickly locate the items which are missing closing items, in a document?

share|improve this question
1  
emacs has M-x check-parens, which looks for unbalanced braces, parentheses, and brackets. That's what I use. Back in the day, I also made use of bibclean, I think, for .bib files. But I don't have it installed any more. –  jon Apr 29 '12 at 23:23
4  
Compile frequently as you write. Then you'll know the missing item is something you typed recently. –  Ethan Bolker Apr 29 '12 at 23:37
5  
I know it's a bit ideal, and can be difficult to keep up, but try always to insert balanced structures. Thus when you insert a \begin{}, insert the corresponding \end{} at the same time, and always enter "{}" then back up and fill in. Of course, autocomplete will help a lot, too. –  Brent.Longborough Apr 29 '12 at 23:48
1  
@Brent.Longborough I have an emacs macro that inserts the \begin{foo}...\end{foo} pair and leaves the cursor between them. –  Ethan Bolker Apr 30 '12 at 0:02
1  
My comments on this are documented at Help me to write Long LaTeX equations fast with colours and possibly with other aids, and I apply similar techniques for environments in that I add the end{environment} at the time I add \begin{environment}. –  Peter Grill Apr 30 '12 at 1:21
show 2 more comments

3 Answers

up vote 9 down vote accepted

If you are using e-TeX (which you probably are), you can make TeX record grouping levels and strangenesses in the log file by

\tracinggroups=1
\tracingnesting=2

This can probably help to find the cause of an error if it is due to a grouping problem.

In your own code, it's probably best to give a short log message at the start of a group level so you can immediately identify in the log what groups are started and closed where.

Furthermore, you can show the current group nesting at any time in your code with

\showgroups
share|improve this answer
add comment

While I use TexMaker, I keep TeXnicCenter installed (but not the windows default) for this purpose. http://www.texniccenter.org/resources/downloads/29

Open TeXnicCenter, load the offending file. Put the curser in the middle of the suspected problem area. Press Ctrl-m and it will highlight the contents of the inclosed brackets. Press again and it increased scope. This usually provides me a fast identification of the problem. Especially when debugging student problems.

share|improve this answer
add comment

May I suggest you to use the syntonly package. It must be declared in the document header,

\usepackage{syntonly}

then, right after it you write

\syntaxonly

what it does, it checks only the syntax without compiling the document. It does not provide further help in spotting the errors, but at least you can avoid to compile the document unsuccessfully. Once the syntax is correct, just comment it.

%\syntaxonly
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.