Guide
Common LaTeX errors and how to fix them
What eight common LaTeX errors and warnings mean, what usually causes them, and the smallest fix for each, with code you can copy.
- Nebula Writer Team
- October 14, 2026
- 7 min read
Most LaTeX errors come from a short list of causes: a misspelled command, a math symbol outside math mode, a missing package, or a brace or environment left open. Fix the first error in the log, compile again, and many of the errors after it disappear, because one mistake often confuses everything that follows.
This page explains the errors people search for most, what each one means and the plain fix. None of it needs a particular editor.
How to read a LaTeX error
A typical error in the log looks like this:
! Undefined control sequence.
l.42 The result is \textbd
{significant}.
The line starting with ! is the error. The line starting with l.42 is the line number in the file being read, and the break in that line shows where TeX stopped. The real mistake is usually at that spot or a little before it. If the project has several files, look for the file name just above the error, or compile with -file-line-error so each error starts with file.tex:42:.
Always start with the first error. Later errors are often side effects.
Undefined control sequence
What it means: TeX found a command it does not know.
Usual cause: a typo (\textbd instead of \textbf), or a command from a package you have not loaded (\includegraphics without graphicx, \SI without siunitx).
Fix: correct the spelling, or load the package that defines the command in the preamble.
% Wrong
The result is \textbd{significant}.
% Right
The result is \textbf{significant}.
% Or load the package that provides the command
\usepackage{graphicx} % for \includegraphics
If the command is your own macro, check that \newcommand comes before the first use.
Missing $ inserted
What it means: TeX met something that only works in math mode, such as ^, _ or \alpha, while it was typesetting normal text. Or it met a blank line inside an equation.
Usual cause: an underscore in a file name or variable name, a forgotten $ around a formula, or an empty line inside equation or align.
Fix: put math in math mode, escape underscores in text, and remove blank lines inside display math.
% Wrong
The file data_2024.csv has x^2 values.
% Right
The file data\_2024.csv has $x^2$ values.
% Wrong: blank line inside an equation
\begin{equation}
E = mc^2
\end{equation}
% Right
\begin{equation}
E = mc^2
\end{equation}
File `x.sty' not found
What it means: the document asks for a package (or class, .cls) that your TeX installation does not have.
Usual cause: the package is not installed, or its name is misspelled in \usepackage.
Fix: check the spelling first. Then install the package. With TeX Live, run tlmgr install <package> (the package name is usually the file name without .sty). With MiKTeX, the package manager can install it, or install packages on the fly. A .sty file that came with a journal template can also go in the same folder as your main .tex file.
\usepackage{siunitx} % File `siunitx.sty' not found? Install siunitx
\usepackage{booktab} % Typo: the package is booktabs
Missing \begin{document}
What it means: TeX started typesetting text before \begin{document}.
Usual cause: a stray character in the preamble, text pasted above \begin{document}, a broken command definition, or an invisible character at the very start of the file. It also appears when you compile a chapter file on its own instead of the main file.
Fix: look between \documentclass and \begin{document} for anything that is not a command, and make sure you compile the main file.
\documentclass{article}
\usepackage{amsmath}
x % <- stray text in the preamble causes the error
\begin{document}
Hello.
\end{document}
Runaway argument and Paragraph ended before ... was complete
What it means: a command's argument never closed. TeX kept reading until it hit a blank line (a new paragraph) or the end of the file.
Usual cause: a missing }, often in \section{...}, \caption{...} or \footnote{...}, or a blank line inside an argument that does not allow one.
Fix: find the command named in the message (for example Paragraph ended before \textbf was complete) and close its brace.
% Wrong
\textbf{Important result.
The next paragraph.
% Right
\textbf{Important result.}
The next paragraph.
A related message, \begin{itemize} ended by \end{document}, means an environment was opened and never closed. Add the matching \end{...}.
Extra alignment tab has been changed to \cr
What it means: a table row has more cells than the column specification allows.
Usual cause: an extra & in a row, or a column was added to the rows but not to the tabular specification.
Fix: count the & signs in the row named by the line number. A row needs one fewer & than there are columns.
% Wrong: three columns declared, four cells in the row
\begin{tabular}{lcc}
Method & Precision & Recall & F1 \\
\end{tabular}
% Right
\begin{tabular}{lccc}
Method & Precision & Recall & F1 \\
\end{tabular}
Citations show [?] and references show ??
What it means: the document compiled, but LaTeX does not yet know the labels or citation keys. This is a warning, Citation 'smith2024deep' undefined or There were undefined references, not an error.
Usual cause: the bibliography tool has not run, or LaTeX has not run enough times after it. Cross-references need two runs. Citations need LaTeX, then BibTeX or Biber, then LaTeX twice more. A misspelled key, or a key missing from the .bib file, gives the same result.
Fix: run the full sequence, or let latexmk do it, which reruns tools until references settle.
# natbib or plain \bibliography: use BibTeX
pdflatex main && bibtex main && pdflatex main && pdflatex main
# biblatex: use Biber
pdflatex main && biber main && pdflatex main && pdflatex main
# or
latexmk -pdf main
If one citation still shows [?], check that its key exists in the .bib file exactly as written, including case. Running BibTeX on a biblatex document that expects Biber (its default) also leaves every citation undefined, so the tool must match the setup.
Overfull \hbox (a warning)
What it means: a line is wider than the text block, so something sticks into the margin. It is a warning. The PDF is still produced.
Usual cause: a long word, URL or inline formula that TeX cannot break, or a table or image wider than \textwidth.
Fix: only worry about it if you can see the overflow in the PDF. Then help TeX break the line, or shrink the object.
\usepackage{url} % lets \url break long addresses
\usepackage{microtype} % often removes small overflows
Thermo\-dynamic % suggest a hyphenation point
\includegraphics[width=\linewidth]{figures/plot.pdf}
Small overflows of a point or two are invisible, and many authors leave them.
When an error makes no sense
Compile from a clean state by deleting the .aux, .bbl and .toc files; a broken run can leave bad data in them. Then comment out half of the document, compile, and repeat on the half that fails until you find the line. A minimal example of a few lines often shows the cause in minutes.
If you hit a compile timeout on Overleaf rather than an error, see Overleaf compile timed out?.
How Nebula Writer helps
Nebula Writer is a desktop editor that compiles LaTeX on your computer, with the source and the PDF side by side. When a compile fails, cards above the log explain the first problems. For an undefined command the card can offer Open the source line and Fix with AI. For a missing package it offers Install missing TeX package and retry. Once TeX Live is installed, Nebula Writer installs missing packages it finds during a compile and tries again. With TeX Live, it compiles through latexmk, which runs BibTeX or Biber for you. The LaTeX guide covers engines and settings.
You can also ask the agent to read the log first and change nothing:
Prompt
Compile @main.tex. Explain the first error in the log in plain words and
propose the smallest fix. Keep labels, citation keys and commands as they
are. Do not edit anything yet.
You should see the explanation and the proposed change in the agent pane, and no review bar, because no file has changed.
Prompt
Apply only that fix, then compile again and tell me whether the error is
gone. If a new first error appears, explain it but do not fix it.
You should see a Review agent edit bar on the .tex file. LaTeX is a text format, so you can step through the changed lines and choose Accept or Reject for each one, or Keep all and Discard all for the rest. How to check every AI edit explains the review bar.
Your request and the parts of your documents the agent needs are sent to our servers and our AI provider. Your files stay in your folder.
Related
- Overleaf compile timed out? How to fix it
- Write a thesis in LaTeX on your computer
- Nebula Writer vs. Overleaf
The editor is free forever with a monthly AI allowance. Pro is $25 a month for more AI. Download Nebula Writer.