It could happen that errors (or their descriptions) sometimes have no relation to where or what the error points to. Probably in its simplest form, although not really errors, is LaTeX's
\ref system. You document is perfect, yet the references show up as
?? when you compile. "Suddenly", when you compile again, the references appear as expected. Similarly for a Table of Contents; it always seems to be one step behind, or causes errors "out of nowhere."
If this seems to be the case, always start fresh by deleting an auxiliary files (
.toc, ... see File extensions of LaTeX-related files and/or Egad! What are all those files?) and compile again, at least twice (sometimes more) since references and other things may take a couple of runs to settle.
Typical errors related to compilation usually stem from content left in the
.aux from the previous run. Common packages that cause this is
pgf, since they write actual command definitions in there (of course, attempts by the package authors are made to avoid this). That is, upon a removal of these packages, the first re-compile still processes an
.aux containing definitions that are completely unsupported, and might cause problems in your document.
Knuth describes TeX as an "eating machine" (chapter 7 How TeX Read What You Type, p 38):
It is important to understand the idea of token lists, if you want
to gain a thorough understanding of TeX, and it is convenient to learn
the concept by thinking of TeX as if it were a living organism. The
individual lines of input in your files are seen only by TeX's "eyes"
and "mouth"; but after that text has been gobbled up, it is sent to
TeX's "stomach" in the form of a token list, and the digestive processes
that do the actual typesetting are based entirely on tokens. As far as the
stomach is concerned, the input flows in as a stream of tokens, somewhat
as if your TeX manuscript had been typed all on one extremely long line.
To put it bluntly, it may be that TeX has already gobbled some of your content and only developed the stomach problems at a completely different/later stage.
For some TUMS*, see
* A possible remedy for TeX's Unknown stoMach problemS