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.

Tip: LaTeX error line numbers can be off by several lines. Always read the error message first, then look at the context around the line number — the actual mistake is often a few lines above.
! Undefined control sequence
Cause

You used a command that LaTeX doesn't know — either a typo, a missing package, or a command from a package you forgot to load.

Fix

Check the spelling of the command. If the command is correct, search which package provides it and add \usepackage{packagename} in the preamble.

Example
% 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 $ inserted
Cause

You used a math-only character or command (like ^, _, \frac, \alpha) outside a math environment.

Fix

Wrap the expression in dollar signs for inline math ($...$) or \[...\] for display math.

Example
% 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}
Cause

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.

Fix

Ensure your document follows the standard structure: \documentclass{...} then preamble (\usepackage, etc.) then \begin{document}.

Example
% Correct structure
\documentclass{article}
\usepackage{amsmath}    % preamble goes here

\begin{document}
  Hello, world!         % content goes here
\end{document}
! File 'packagename.sty' not found
Cause

The package you are trying to load is not installed in your LaTeX distribution.

Fix

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 complete
Cause

A 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.

Fix

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.

Example
% Problem: missing closing brace
\textbf{important text  % => Runaway argument

% Fix:
\textbf{important text}
! LaTeX Error: There's no line here to end
Cause

You 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{}.

Fix

Remove the \\ or replace it with a blank line (paragraph break) or \medskip/\bigskip for vertical spacing.

Example
% 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 \cr
Cause

A tabular or array environment has more & column separators in a row than there are columns defined.

Fix

Count your & separators per row. A table with 3 columns needs exactly 2 & separators per row (not 3).

Example
% 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}
Cause

Environment begin and end tags are mismatched. You opened one environment but closed a different one.

Fix

Check that every \begin{X} is paired with the correct \end{X}. Nested environments must close in reverse order of opening.

Example
% 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)
Cause

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.

Fix

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.

Example
% 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 up
Cause

Your 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.

Fix

Add \usepackage[utf8]{inputenc} to your preamble, or (for newer documents) use \usepackage{fontspec} with XeLaTeX or LuaLaTeX which handle UTF-8 natively.

Example
% Fix for pdfLaTeX:
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

General Debugging Strategy

When you encounter an unfamiliar error, follow this systematic approach:

  1. 1
    Read 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.

  2. 2
    Find the first error

    Fix errors top to bottom. One mistake can cascade into dozens of fake errors downstream. Fix the first one and recompile.

  3. 3
    Comment out sections

    Use % to comment out blocks of your document and narrow down which section triggers the error.

  4. 4
    Check braces and environments

    Most errors come from unmatched { } braces or \begin{}/\end{} mismatches. Count them carefully.

  5. 5
    Minimal 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

Continue Learning