LaTeX Error: Missing \begin{document}
The "Missing \begin{document}" error usually does not mean the line is missing. It means LaTeX hit something that produces output — stray text, a special character, or a misplaced command — before \begin{document}. Fix it by keeping the preamble to only \documentclass, \usepackage, and setup commands, with all real content after \begin{document}.
Why it happens
Anything that typesets — a loose word, an accented character saved as a Byte Order Mark at the top of the file, or a command like \textbf used in the preamble — makes LaTeX think the body has started, so it complains that \begin{document} is missing. A stray \documentclass inside an included preamble file does the same.
Example
% Wrong — text before the body:
\documentclass{article}
Some notes to self. % <- triggers the error
\begin{document}
% Fix — keep the preamble clean:
\documentclass{article}
\begin{document}
Some notes to self.Frequently asked questions
I did write \begin{document} — why the error?
Then something output-producing sits above it. Common culprits: a Byte Order Mark (save the file as UTF-8 without BOM), a stray character, or a command that typesets text in the preamble.
It appeared after I split out a preamble file.
\documentclass must live in the main file only, and an included preamble file must not contain body text. Move \documentclass back to the top of the main .tex.
Could an old .aux file cause it?
Occasionally — delete the .aux, .toc, and .out files and recompile from scratch. Online editors like LetX rebuild these automatically on every compile.
Try the fix in LetX
Open the editor, paste your code, and compile in 1 second to see the error clear — free, in your browser.
Open LetX Free