This message means: LaTeX found before \begin{document} something that produces visible text. Two common causes: text in the preamble or a badly encoded accent.
Cause #1: text in the preamble
Everything you want to write goes after \begin{document}. Text before it triggers the error:
\documentclass{article}
Hello! % text in the preamble -> Missing \begin{document}
\begin{document}
...
\end{document}Move the text after \begin{document}:
\documentclass{article}
\begin{document}
Hello!
\end{document}Cause #2: a badly encoded accent
An accent (é, è, à…) in the preamble, combined with an old inputenc declaration, is read as text and triggers the same error. Fix: modern \usepackage[utf8]{inputenc} + \usepackage[T1]{fontenc} (see Old packages).
\documentclass → \usepackage (preamble) → \begin{document} → your text → \end{document}. Nothing visible before \begin{document}.Try it yourself
This example compiles. Move the word "Hello" above \begin{document} and recompile to see "Missing \begin{document}".
The method
- Check that nothing visible comes before
\begin{document}(only\documentclassand\usepackage). - Move any text after
\begin{document}. - An accent in the preamble? Modernize
inputenc/fontencto UTF-8. - Is a
}missing in a\usepackage[…]{…}? That can also cause this error.
An AI can fix the error — directly in your code
AI assistants (Claude, Gemini, ChatGPT…) know LaTeX very well: show them the preamble and they find the text or accent breaking things before \begin{document}. The usual drawback is the back-and-forth — copy, paste, repeat.
sarmate.net removes this round-trip with its MCP server: you connect the AI directly to your online editor. It reads your files, compiles them, analyzes the error log and fixes the code in place, with no copy-paste. You stay in control: nothing is changed without your approval.
Write and compile LaTeX online
Full editor, instant compilation (pdfLaTeX/XeLaTeX/LuaLaTeX), nothing to install.
Open the online editor