Missing \begin{document}

! LaTeX Error: Missing \begin{document} means LaTeX tried to typeset something while still in the preamble — output happened before \begin{document}. Usually it’s stray body text in the preamble, a missing \begin{document}, or an encoding problem.

Causes

  • Stray body text in the preamble — between \documentclass and \begin{document} put only declarations, \usepackage, and settings. Ordinary text there produces output and triggers this error.
  • A missing or misspelled \begin{document}.
  • An encoding mismatch or BOM — a file saved in the wrong encoding, or with a BOM or stray non-ASCII bytes, makes TeX try to typeset characters too early and raises this error.
  • A command in the preamble that emits text.

Example

latex
\documentclass{article}
これは本文。            % ← \begin{document} の前なので NG / before begin{document}
\begin{document}
本文はここから。
\end{document}

The fix

Keep anything typesettable out of the preamble, before \begin{document}. Verify that \begin{document} actually exists and is spelled correctly. If it still appears, check the file is UTF-8 (no BOM) — inspect with nkf -g and re-save as UTF-8 if needed (see “Encoding & newlines”). On older systems, also check for \usepackage[utf8]{inputenc}.