[OS X TeX] finding missing braces

Roussanka Loukanova rloukano at stp.lingfil.uu.se
Mon Mar 5 00:05:24 CET 2007

On Sun, 4 Mar 2007, Herbert Schulz wrote:
> On Mar 4, 2007, at 1:40 PM, Rolf Schmolling wrote:
>> Hello!
>> Please accept my apologies for posting without a subject? this was actually 
>> the third time I tried, because somehow everything I sent went as html by 
>> mistake.
>> Thanks for the search expression. I will try to save it somewhere and try 
>> it out.
>> I tried the texshop-wiki as well and there Herbert Schultz suggested to 
>> doubleklick right after an opening brace or right before a closing brace. 
>> If everything is alright all text within the braces should be selected 
>> together with the two braces. Unfortunately that still is semi-automatic.
>> Someone I met in texusergroup hinted about some editors beeing smart enough 
>> to do this but I really want to hang to TexShop because it seems the only 
>> thing I'm able to work properly (simple but elegant, no programming-skill 
>> neded, excellent sync between source and pdf)?
>> Anyway thanks a lot!
>> Greetings,
>> Rolf
> Howdy,
> I believe the problem is intractable. How can a program know what you 
> intended? E.g., suppose you leave off a closing brace in a sentence,
> \emph{emphasized text ...
> how will a program know whether the closing brace goes after the word 
> `emphasized' or the word `text', or ...?

Right: In cases like the above, \emph{emphasized text ..., the error 
notice in the log (e.g., the console in TeXShop) may say that the 
scope of the unmatched "{" goes to the last line of the entire 
tex file.

> I think TeXShop does a reasonable thing here; if you double click just before 
> (I had said after in the forum, sorry) the opening brace and TeXShop finds a 
> matching closing brace it highlights all the text between and including the 
> braces while only highlights the opening brace if it can't find the match. 
> The algorithm seems to just count { and } until the matching } is found; it 
> doesn't seem to know about comments (e.g., it will match on %}) or literal 
> closing braces (\}), but that will work most of the time.

This is right strategy. But if you do not know where in the tex file 
to apply it (esp. in long tex file), then perhaps, the following would 

- Put an extra \end{document} at a location up to which the tex file 
typesets properly.

- Move \end{document} ahead through the tex file over small chunks of text 
until you locate the area with the unmatched "{" (it might be unmatched 
"}"). In these steps, you should observe the areas with any delimiting 
symbols, like $, '', (, ), as environments \begin{...},  etc. not only { 
and }.

> The error message you get while compiling should give you good clue as to
> where the missing closing brace occurs.

Sometimes the error message will point a line, which is far away from the 
mismatched {. The following may also help:

Hit (run) Typeset and look through the output file (in Emacs), or the 
console window in TeXShop. Try to see the number of the last page that is 
typeset properly (but sometimes there may be no such). The pages that are 
successfully typeset are listed with: [1] [2] [3]...[n][]. Then, if you 
have a previously typeset pdf, see what text corresponds to the last 
properly typeset page n, and search right after the corresponding location 
in the tex file.

After you find the local area of text with mismatched {, you may use what 
Herb describes, by getting the innermost matched pairs  {...} highlighted, 
then the next pair {{...}}, etc. until you reach the unmatched {.
In this process, deleting (temporarily) some text may help. Just copy and 
save it in additional temporal file, to restore it then back.

Alternatively, follow the "outermost unmatched {" strategy, as 
Antoine describes in one of he previous emails.


> Finally, the best way to keep from having mismatched pairs is to use Command 
> Completion and/or Macros to generate the pair and place the insertion point 
> between the braces.
> Good Luck,
> Herb Schulz
> (herbs at wideopenwest.com)

------------------------- Helpful Info -------------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
TeX FAQ: http://www.tex.ac.uk/faq
List Archive: http://tug.org/pipermail/macostex-archives/
List Reminders & Etiquette: http://www.esm.psu.edu/mac-tex/list/

More information about the macostex-archives mailing list