FatalDocument Structure
Missing \begin{document}
! LaTeX Error: Missing \begin{document}.
What this error means
LaTeX found content (text, commands, or environments) before the \begin{document} marker. Everything before \begin{document} is the preamble — it should only contain class declarations, package loading, and global settings.
Common causes
- Accidentally placed text or content in the preamble
- The \begin{document} line was deleted or commented out
- Typo in \begin{document}
How to fix it
Move all content that should appear in the PDF to after \begin{document}. The preamble should only contain \documentclass, \usepackage calls, and command definitions.
Code examples
Causes the error
\documentclass{article}
\usepackage{amsmath}
This text is in the preamble! % Error
\begin{document}
More content here.
\end{document}Fixed
\documentclass{article}
\usepackage{amsmath}
\begin{document}
This text is correct.
More content here.
\end{document}Related errors
Test the fix live
Paste your LaTeX into the playground and compile instantly.

