Common LaTeX Errors and How to Fix Them
LaTeX's error messages are notoriously cryptic. This reference explains the ten most common errors you will encounter, what triggers each one, and exactly how to fix it.
! Undefined control sequenceYou used a command that LaTeX doesn't know — either a typo, a missing package, or a command from a package you forgot to load.
Check the spelling of the command. If the command is correct, search which package provides it and add \usepackage{packagename} in the preamble.
% Problem: \lorem is not a built-in command
\lorem % => Undefined control sequence
% Fix: load the lipsum package which provides \lipsum
\usepackage{lipsum}
\lipsum[1]! Missing $ insertedYou used a math-only character or command (like ^, _, \frac, \alpha) outside a math environment.
Wrap the expression in dollar signs for inline math ($...$) or \[...\] for display math.
% Problem: underscore outside math mode The variable x_i equals 5. % => Missing $ inserted % Fix: wrap in math mode The variable $x_i$ equals 5.
! Missing \begin{document}LaTeX encountered document content before the \begin{document} command. Often caused by preamble commands placed after \begin{document} by mistake, or a document that is missing \begin{document} entirely.
Ensure your document follows the standard structure: \documentclass{...} then preamble (\usepackage, etc.) then \begin{document}.
% Correct structure
\documentclass{article}
\usepackage{amsmath} % preamble goes here
\begin{document}
Hello, world! % content goes here
\end{document}! File 'packagename.sty' not foundThe package you are trying to load is not installed in your LaTeX distribution.
On Skozin's online editor, all common packages are pre-installed. If using a local distribution, install the package via your TeX package manager (tlmgr install packagename on TeX Live, or use MiKTeX's package manager).
Runaway argument? / ! Paragraph ended before \X was completeA command argument was never closed. You opened a curly brace { but forgot to close it with }, or you included a blank line inside an argument that doesn't allow it.
Check for unmatched braces. Every { must have a matching }. Count them carefully — a missing closing brace at the end of a line is a very common mistake.
% Problem: missing closing brace
\textbf{important text % => Runaway argument
% Fix:
\textbf{important text}! LaTeX Error: There's no line here to endYou used \\ (line break) at the start of an environment or where no line has started yet. Common in text just after \begin{document} or after \section{}.
Remove the \\ or replace it with a blank line (paragraph break) or \medskip/\bigskip for vertical spacing.
% Problem:
\section{Introduction}
\\ Some text here. % => There's no line here to end
% Fix:
\section{Introduction}
Some text here.! Extra alignment tab has been changed to \crA tabular or array environment has more & column separators in a row than there are columns defined.
Count your & separators per row. A table with 3 columns needs exactly 2 & separators per row (not 3).
% Problem: 3 columns defined but 4 values given
\begin{tabular}{lll}
A & B & C & D \\ % => Extra alignment tab
\end{tabular}
% Fix:
\begin{tabular}{llll}
A & B & C & D \\
\end{tabular}! LaTeX Error: \begin{X} ended by \end{Y}Environment begin and end tags are mismatched. You opened one environment but closed a different one.
Check that every \begin{X} is paired with the correct \end{X}. Nested environments must close in reverse order of opening.
% Problem:
\begin{itemize}
\item First
\end{enumerate} % => \begin{itemize} ended by \end{enumerate}
% Fix:
\begin{itemize}
\item First
\end{itemize}Overfull \hbox (Xpt too wide)A word, image, or other content is too wide to fit within the text column. LaTeX prints a warning and lets the content protrude into the margin.
This is a warning, not a fatal error. Common fixes: add a hyphenation hint (\- in the word), change a line break, scale a figure smaller, or use \sloppy in extreme cases.
% Fix long unbreakable URL overfull with the url package:
\usepackage{url}
\url{https://very-long-url-that-wraps-nicely.example.com/page}! Package inputenc Error: Unicode character (U+XXXX) not set upYour source file contains a Unicode character (like a smart quote, em dash, or special letter) that the default 7-bit LaTeX encoding doesn't know how to handle.
Add \usepackage[utf8]{inputenc} to your preamble, or (for newer documents) use \usepackage{fontspec} with XeLaTeX or LuaLaTeX which handle UTF-8 natively.
% Fix for pdfLaTeX:
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}General Debugging Strategy
When you encounter an unfamiliar error, follow this systematic approach:
- 1Read the full error message
Don't just look at the line number. The message itself tells you what went wrong. In Skozin, the error panel shows the full compiler output.
- 2Find the first error
Fix errors top to bottom. One mistake can cascade into dozens of fake errors downstream. Fix the first one and recompile.
- 3Comment out sections
Use % to comment out blocks of your document and narrow down which section triggers the error.
- 4Check braces and environments
Most errors come from unmatched { } braces or \begin{}/\end{} mismatches. Count them carefully.
- 5Minimal reproducible example
Strip your document down to the smallest version that still shows the error. This clarifies the cause and makes it easier to search for help.
See errors highlighted in real time
Skozin's editor shows compilation errors with line numbers and descriptions as you type.
Start Writing