How to Fix Common LaTeX Errors: A Diagnostic Guide
Português: Leia este tutorial em português.
LaTeX compilation errors may look cryptic at first, but most of them can be solved with a simple method: locate the first relevant message, identify the command or file involved, and test the correction in a minimal example. This guide covers frequent problems in Overleaf, Windows, and Linux.
Start with the first error in the log
One initial failure can produce dozens of secondary messages. Do not start with the final warning. Open the full log, find the first actual error, and note the reported line. Read one or two lines before it as well: the cause is often an unclosed brace, environment, or command started earlier.
Correct that first error and compile again. Repeat until the document is generated normally.
Undefined control sequence
This message means the compiler does not recognize a command. Common causes include a typo, a missing package, or a command that is incompatible with the selected engine.
! Undefined control sequence.
l.18 \inclduegraphics{chart.pdf}
Here, \inclduegraphics is misspelled. The correct command is \includegraphics, provided by the graphicx package:
\usepackage{graphicx}
...
\includegraphics[width=.8\textwidth]{chart.pdf}
Missing $ inserted
Mathematical characters and commands must be used in math mode. An underscore typed directly in ordinary text is a common cause.
final_value % incorrect in normal text
final\_value % literal underscore
$value_{final}$ % mathematical expression
Also check that every $...$, \(...\), and \[...\] delimiter has been closed.
File not found
LaTeX could not find an image, included file, class, or bibliography database. Check the complete name, extension, capitalization, and path relative to the main file.
\includegraphics{figures/result.pdf}
\input{chapters/method}
\addbibresource{references.bib}
On Linux servers and Overleaf, Chart.pdf and chart.pdf are different names. Avoid spaces and accented characters in filenames to make projects easier to move between systems.
References and citations appear as ??
Cross-references require more than one compilation. Citations with BibLaTeX normally require Biber between LaTeX runs.
pdflatex main
biber main
pdflatex main
pdflatex main
Verify that the key used in \ref{...} or \cite{...} exists, that the .bib file is declared, and that the project uses the correct bibliography tool. In Overleaf, try Recompile from scratch when auxiliary files are stale.
Runaway argument and unbalanced braces
Messages such as Runaway argument?, File ended while scanning use of..., or Extra } usually indicate an unclosed brace or environment.
\textbf{Text without a closing brace
\begin{figure}
...
% missing \end{figure}
Use the editor’s delimiter matching and temporarily remove sections of the document. If the error disappears, restore the blocks gradually until the problematic region is found.
Unicode characters and fonts
If the document uses many system fonts or multiple writing systems, prefer XeLaTeX or LuaLaTeX with fontspec. For modern pdfLaTeX projects, keep files in UTF-8 and use an up-to-date distribution.
% XeLaTeX or LuaLaTeX
\usepackage{fontspec}
\setmainfont{TeX Gyre Pagella}
Do not load fontspec with pdfLaTeX. Check the project compiler before changing font packages.
Overfull and Underfull hbox
These are typesetting warnings, not necessarily fatal errors. Overfull \hbox means that content extends beyond a margin; long URLs, wide tables, and words without valid break points are frequent causes.
- Use
\url{...}with thehyperrefpackage. - Adjust column widths and use
tabularxfor wide tables. - Rewrite the sentence before forcing manual spacing.
- Do not apply
\sloppyglobally without reviewing the visual result.
Create a minimal reproducible example
Copy the problem into a small file containing only the document class, required packages, and failing excerpt:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
% code that produces the error
\end{document}
If the minimal example compiles, the cause is elsewhere in the project or in a package interaction. Restore elements gradually. A minimal example also makes requests for help much clearer.
Recommended diagnostic workflow
- Create a copy or save a stable version of the project.
- Read the first actual error in the log.
- Go to the reported line and inspect the preceding block.
- Check braces, environments, filenames, and packages.
- Clear auxiliary files and compile again.
- Reduce the problem to a minimal example.
- Consult the package documentation using the exact error message.
Final checklist
- Is the selected compiler compatible with every package?
- Are all files present and named consistently?
- Are braces, brackets, environments, and math delimiters closed?
- Were references compiled the required number of times?
- Did you fix the first log error before addressing the others?
With this process, most LaTeX errors stop being a mysterious list of messages and become a localized, testable problem. To practice, start with one of the TexDrop LaTeX templates and make changes in small steps.