# How to go deep and debug the real error?

(/usr/share/texlive/texmf-dist/tex/latex/thmtools/unique.sty
Package: unique 2012/05/04 v63
\uniq@channel=\write6
\openout6 = main.unq'.

)

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.334 ]{definition}


How can I go deep to find what the real error is? \begin{document} is there in main.tex, and the code compiled just fine this morning.

• LaTeX is telling you that you have something wrong in line 334, but this probably is not enough to find the error. If you type H at the prompt, LaTeX tells you a bit more (not enough as well, anyway). Aug 25 '13 at 14:11
• Something had to have changed. Can you post an MWE? Aug 25 '13 at 14:15
• Can you show a minimal example of code producing the error? Aug 25 '13 at 14:20
• I'm not sure such an example would be very useful. LaTeX does the best job it can to detect errors. But even after hitting "H", you may not get any better idea where the error is. Somewhere on this site, however, is a list of common things to look for when you have a particular kind of error such as "Missing \begin{document}" when, in fact, it's there. I'll see if I can find that resource and post it here. Aug 25 '13 at 14:44
• @juliohm you say you solved the problem by (tedious) by brute force: can you reveal what the problem actually was? it might help a future user scanning the site, saving the time of turn-around for a question. Aug 25 '13 at 16:10

The error is on line 334 of some file, it is not possible to say which file it is from the fragment shown, you need to look in the log and match ( and ) the line number relates to the filepath shown by the currently open (.

The missing document error is shown if TeX tries to typeset a paragraph before \begin{document}, so you have a command

\foo[]{definition}


but \foo was not expecting an optional argument so took [ as the main argument leaving ]{definition}` which was then taken as plain text, started a paragraph and generated the error message.