LaTeX Debugging – Strategies for Brace Mismatching

debugging

What is the recommended way to track down brace mismatches in LaTeX? I have a large beamer presentation, but this equally applies to any other LaTeX work I've done.

In other computer languages I've used pretty printers to highlight where things mismatch, but I can't seem to find a pretty printer for the LaTeX code itself rather than some other language inside in LaTeX.

My next thought is to start commenting out large sections of the source until the problem is pinned down.

What other strategies might be used?

Best Answer

The log file usually gives some help. For example if you start an environment without ending it then you get

! LaTeX Error: \begin{quote} on input line 16 ended by \end{document}.

which tells you where group started, if it doesn't tell you where it should have finished.

If you have mis-matched { } pairs it depends whether they are being used for grouping or argument delimiting.

In the former case you get

(\end occurred inside a group at level 1)

which tells you something is bad and if at the start of the document you put

\tracinggroups=1

you get in addition

### simple group (level 1) entered at line 16 ({)
### bottom level

which tells you where the { was.

If it is argument matching ie you have \textbf{ with no } then you get:

Runaway argument?
{ \par aa bb xx cc \par \par \par \par 4 $\hat {\hat {\mathcal {A}}} \ETC.
! File ended while scanning use of \textbf .

which gives you some context, but not a line number, although if you have the tracinggroups set as above it is easy to guess as you are told the last group that was entered or left before the error, in this case the log shows

{leaving math shift group (level 1) entered at line 14}
)
Runaway argument?

so it isn't too hard to spot the error on line 16 as line 14 was OK and line 15 (in this case) was empty.

Related Question