I'm a "noobish" TeX/LaTeX user and I was getting the Missing \begin{document} error. I've tried pdflatex, xelatex, xetex, luatex... nothing worked.

Actually I SOLVED this (turned around at least) by deleting every auxiliary file and leaving only the .tex one, after that it compiled smoothly, so I'm leaving this information to other noobs.

I think the issue was with the .aux file more precisely, but I'm not sure, because I can't quite replicate the problem and try file by file.

Before deleting the files, I've tried making a new .tex file with the same code and it compiled, but the original file with the auxiliary files didn't.

My question is: Why it compiled smoothly by just by deleting the auxiliary files?

The code was more or less like this:

\usepackage{geometry} % for landscape and some other stuff
% some other innocent packages like amsmath
% i'm pretty sure it wasn't their fault anyway
\usepackage{lipsum} % illustration purposes

\part{bla, bla, bla}
\chapter{pi, pi, pi}
\section{nhe, nhe, nhe}


I was editing in Ubuntu's terminal and vim, no special options like saving folds in vim, or anything.

I also noticed that sometimes with the other "test" file, I had to compile twice to get the contents straight when I put each block on it, otherwise it'd miss chapters, screw the table of contents and things like that.

The answer might be very handy to other lazy tex users, who didn't read the full documentation.

EDIT: I din't change anything in the preamble, it just "suddenly" decided to miss the \begin{document}

  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Martin Schröder Nov 11 '14 at 14:27
  • What exactly is your question? It's hard to help without the actual code. – Martin Schröder Nov 11 '14 at 14:28

You get that error if latex starts trying to typeset paragraphs before \begin{document} has set things up. During that processing the aux file is read (to resolve cross reference information saved on the previous run). It can happen that the aux file is corrupt and so a command in the file is misinterpreted and characters start being interpreted as text to be typeset, thus triggering the error. If this happens removing the aux file is the the thing to do.

It is not possible to say, looking at a fixed file, how the aux file came to be corrupt. Aborting a previous job, accidental edit, stray cosmic ray, ....

| improve this answer | |
  • Addition to the list (the root cause, of course): butterflies – Paul Gessler Nov 11 '14 at 14:41
  • oh, must have been the butterflies then... monarch butterflies start going to Mexico by the end of october – Ivan Assolant Nov 11 '14 at 16:05
  • 1
    if one exits latex with "x", the log file should be written out, and it should say what file it is reading at the time. then the offending file can be examined (before it's deleted) to see how it's corrupt. fixing the problem does involve deleting the problem file, but it's sometimes useful to figure out exactly what happened before doing that. – barbara beeton Nov 11 '14 at 16:07
  • 1
    Happens a lot if switching between languages in babel (I mean, adding/deleting the babel line and rerun) --- for me it's the most common cause of a corrupt .aux file. Or compiling with latex and after with xelatex and back... – Rmano Nov 11 '14 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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