LaTeX Error: Missing \begin document
This error appears when you have forgotten to include \begin{document}
in your document. It can also appear if you have not written \documentclass[...]{...}
at the beginning of your main document.
Common Causes
Forgetting to include \begin{document}:
The most basic cause of this error occurs when you have forgotten to write \begin{document}
after the preamble in your main document. If you make this mistake, you will generate the error message shown below:
main.tex, line 5
See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ... You're in trouble here. Try typing <return> to proceed. If that doesn't work, type X <return> to quit.
To resolve this error, simply make sure that you have included \begin{document}
after the preamble in your main document. See here to learn more about how to structure documents in LaTeX.
\documentclass[...]{...} in wrong place:
Another common cause of this error is if \documentclass[...]{...}
is written in the wrong place. This must be written at the start of the main document. If you have a separate file for your preamble, you cannot include \documentclass[...]{...}
in that file. It still must appear at the top of the main project file, or else only the preamble file will be compiled.
Main document set incorrectly:
This error may also appear if you have set the main document incorrectly in the left hand menu. This can happen if \documentclass[...]{...}
is written in the wrong place, so you should correct this first if needed. To change the choice of main document, open the left hand menu:
and go to the Main document drop down menu:
Overleaf guides
- Creating a document in Overleaf
- Uploading a project
- Copying a project
- Creating a project from a template
- Including images in Overleaf
- Exporting your work from Overleaf
- Working offline in Overleaf
- Using Track Changes in Overleaf
- Using bibliographies in Overleaf
- Sharing your work with others
- Debugging Compilation timeout errors
- How-to guides
LaTeX Basics
- Creating your first LaTeX document
- Choosing a LaTeX Compiler
- Paragraphs and new lines
- Bold, italics and underlining
- Lists
- Errors
Mathematics
- Mathematical expressions
- Subscripts and superscripts
- Brackets and Parentheses
- Fractions and Binomials
- Aligning Equations
- Operators
- Spacing in math mode
- Integrals, sums and limits
- Display style in math mode
- List of Greek letters and math symbols
- Mathematical fonts
Figures and tables
- Inserting Images
- Tables
- Positioning Images and Tables
- Lists of Tables and Figures
- Drawing Diagrams Directly in LaTeX
- TikZ package
References and Citations
- Bibliography management in LaTeX
- Bibliography management with biblatex
- Biblatex bibliography styles
- Biblatex citation styles
- Bibliography management with natbib
- Natbib bibliography styles
- Natbib citation styles
- Bibliography management with bibtex
- Bibtex bibliography styles
Languages
- Multilingual typesetting on Overleaf using polyglossia and fontspec
- International language support
- Quotations and quotation marks
- Arabic
- Chinese
- French
- German
- Greek
- Italian
- Japanese
- Korean
- Portuguese
- Russian
- Spanish
Document structure
- Sections and chapters
- Table of contents
- Cross referencing sections and equations
- Indices
- Glossaries
- Nomenclatures
- Management in a large project
- Multi-file LaTeX projects
- Hyperlinks
Formatting
- Lengths in LaTeX
- Headers and footers
- Page numbering
- Paragraph formatting
- Line breaks and blank spaces
- Text alignment
- Page size and margins
- Single sided and double sided documents
- Multiple columns
- Counters
- Code listing
- Code Highlighting with minted
- Using colours in LaTeX
- Footnotes
- Margin notes
Fonts
Presentations
Commands
Field specific
- Theorems and proofs
- Chemistry formulae
- Feynman diagrams
- Molecular orbital diagrams
- Chess notation
- Knitting patterns
- CircuiTikz package
- Pgfplots package
- Typing exams in LaTeX
- Knitr
- Attribute Value Matrices
Class files
- Understanding packages and class files
- List of packages and class files
- Writing your own package
- Writing your own class
- Tips