One quick thing
We track anonymous usage — page views, feature usage, compilation events — to understand what works and what doesn't. No ads, no personal data, no third-party sharing.
\errors{latex}
50 common errors explained — what causes them, how to fix them, and working code examples. Bookmark this for when LaTeX inevitably surprises you.
! LaTeX Error: Missing \begin{document}.
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.
Move all content that should appear in the PDF to after \begin{document}. The preamble should only contain \documentclass, \usepackage calls, and command definitions.
\documentclass{article}
\usepackage{amsmath}
This text is in the preamble! % Error
\begin{document}
More content here.
\end{document}\documentclass{article}
\usepackage{amsmath}
\begin{document}
This text is correct.
More content here.
\end{document}! LaTeX Error: \begin{XXX} on input line N ended by \end{YYY}.
A \begin{envname} was closed with a different \end{envname}. LaTeX environments must be nested properly — the most recently opened environment must be closed first.
Check that every \begin{foo} has a matching \end{foo}. Environments must close in the reverse order they were opened — if you open itemize inside enumerate, close itemize before enumerate.
\documentclass{article}
\begin{document}
\begin{itemize}
\item First
\begin{enumerate}
\item Nested
\end{itemize} % Wrong! Should be \end{enumerate}
\end{enumerate} % Wrong! Should be \end{itemize}
\end{document}\documentclass{article}
\begin{document}
\begin{itemize}
\item First
\begin{enumerate}
\item Nested
\end{enumerate} % Close the inner environment first
\end{itemize} % Then close the outer
\end{document}! LaTeX Error: Can only be used in preamble.
A command that can only appear in the preamble (before \begin{document}) was used inside the document body. Common offenders are \documentclass, \usepackage, and \pagestyle.
Move the offending command to the preamble, before \begin{document}. If you need to change page style mid-document, use \thispagestyle{} instead of \pagestyle{}.
\documentclass{article}
\begin{document}
\usepackage{graphicx} % Too late! Must be in preamble
\includegraphics{image.png}
\end{document}\documentclass{article}
\usepackage{graphicx} % Correct: in preamble
\begin{document}
\includegraphics{image.png}
\end{document}! Extra }, or forgotten $.
LaTeX found a closing brace } or $ with no matching opening counterpart. This breaks the internal grouping mechanism that LaTeX uses to scope commands and environments.
Check brace pairing carefully. Every { must have a matching }. Use an editor with brace matching, or add braces systematically and count them. In math mode, every $ must have a closing $.
\documentclass{article}
\begin{document}
\textbf{Hello}} % Extra closing brace
\end{document}\documentclass{article}
\begin{document}
\textbf{Hello} % Balanced braces
\end{document}! Paragraph ended before \XXX was complete.
A blank line (paragraph break) appeared inside a command argument that doesn't allow paragraph breaks. Most standard LaTeX commands that take short arguments cannot span paragraph boundaries.
Remove the blank line from inside the command argument, or close the command before the blank line. For multi-paragraph content, use environments like minipage or a custom command that accepts long arguments (\long\def).
\documentclass{article}
\begin{document}
\textbf{This is bold text.
But this paragraph is inside the argument!}
\end{document}\documentclass{article}
\begin{document}
\textbf{This is bold text.}
But this paragraph is outside the command.
\end{document}! Too many }'s.
LaTeX encountered a } that has no matching {. This happens when the brace nesting is off, usually because a brace was closed twice or an extra brace was inserted.
Carefully trace brace nesting from the start of the file. Each { must pair with exactly one }. Editors with brace highlighting (VS Code, Emacs, TeXStudio) make this much easier to spot.
\documentclass{article}
\begin{document}
{\bfseries Bold text}} % Extra }
\end{document}\documentclass{article}
\begin{document}
{\bfseries Bold text} % Balanced
\end{document}! LaTeX Error: Two \documentclass or \documentstyle commands.
A LaTeX document can only have one \documentclass declaration. If LaTeX encounters a second one, it reports this error. This usually happens when two files are accidentally merged or a template is incorrectly concatenated.
Remove the duplicate \documentclass. Each LaTeX document must have exactly one class declaration, and all other content should be after \begin{document}. Input files should not contain \documentclass.
\documentclass{article}
\documentclass{report} % Second class — error!
\begin{document}
Hello
\end{document}\documentclass{article}
\begin{document}
Hello
\end{document}LaTeX Warning: Label 'XXX' multiply defined.
Two \label{} commands in your document use the same identifier. LaTeX will use the value from the second definition, which may cause wrong cross-references. This is a warning, not an error, but the output will likely be incorrect.
Give each \label{} a unique name. Use a naming scheme like fig:plot1, tab:results, sec:intro to avoid collisions. Run LaTeX twice after renaming to clear the stale .aux file reference.
\documentclass{article}
\begin{document}
\section{Introduction}\label{sec:intro}
% ...
\section{Background}\label{sec:intro} % Duplicate!
\end{document}\documentclass{article}
\begin{document}
\section{Introduction}\label{sec:intro}
% ...
\section{Background}\label{sec:background} % Unique label
\end{document}! LaTeX Error: \caption outside float.
The \caption{} command was used outside of a floating environment (figure or table). Captions are part of float management and can only appear inside figure, table, or similar float environments.
Wrap the content and \caption in a figure or table environment. Always use \begin{figure}...\end{figure} around images you want to caption, and \begin{table}...\end{table} for tables.
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics{plot.png}
\caption{My plot} % Error: no surrounding figure
\end{document}\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[h]
\centering
\includegraphics{plot.png}
\caption{My plot}
\label{fig:plot}
\end{figure}
\end{document}