Troubleshooting
The Most Common LaTeX Errors and How to Fix Them
LaTeX error messages look cryptic, but a handful of them cover most failed compiles. Each one names a line, and the cause is usually on that line or just before it. Here they are, roughly in the order you'll meet them, with the fix for each.
How to read an error
- Fix the first error first. Later errors are often side effects of it.
- Look at the line number, then at the line above. A missing
}or$often only breaks the next thing. - Read the message's second line: LaTeX prints the text it had read when it stopped, which points at the exact spot.
Lemma lists errors with their line numbers after each compile. Tap one to jump to that line in the editor.
Undefined control sequence
LaTeX met a command it doesn't know. Either it is misspelled (\textbf written \textbt), or it comes from a package you haven't loaded. \includegraphics needs graphicx, \url needs url or hyperref, and \SI needs siunitx.
! Undefined control sequence.
l.14 \includegraphics
[width=\linewidth]{plot.png}
% Fix: add to the preamble
\usepackage{graphicx}Missing $ inserted
You used something that only works in math mode, such as _, ^, \alpha or \frac, in normal text. Wrap it in $...$, or escape it if you meant the literal character: write \_ for an underscore in a file name.
The value x_1 is positive. % error
The value $x_1$ is positive. % fixed
See data\_2024.csv. % a literal underscoreRunaway argument and "File ended while scanning"
A brace was opened and never closed, so LaTeX kept reading until a paragraph break or the end of the file. Count the braces around the reported line. Editors that match brackets make this quick: put the cursor on a { and look for its partner.
File not found
LaTeX Error: File 'something.sty' not found means a package isn't installed. File 'chapter1.tex' not found or a missing image means a path is wrong. Paths are relative to the main file, and they are case-sensitive on Android, Linux and macOS, so Figures/Plot.PNG and figures/plot.png are different files.
In Lemma, missing packages aren't an error to fix by hand: TeX packages download the first time a document needs them, with progress shown, and then work offline.
Misplaced alignment tab character &
An & appeared outside a table or an align environment. In text, write \&. Inside a tabular, check that every row has the same number of & separators as the column spec allows.
Warnings that matter: overfull boxes and undefined references
Overfull \hboxmeans a line sticks out into the margin, often because of a long URL or word. Loadmicrotype, allow breaks in URLs with\usepackage{xurl}, or rephrase.Reference 'fig:plot' undefinedor??in the PDF means a\refhas no matching\label, or the document needs one more compile to resolve it.Citation 'knuth' undefinedmeans the bibliography hasn't been processed, or the key is misspelled. See BibTeX vs biblatex.
When the error makes no sense
- Comment out half the document body and compile. Repeat on the half that still fails.
- Check the last thing you changed. Version control makes this easy: Lemma can commit, push and pull with any Git host.
- Copy the document into a minimal file with only the preamble lines it needs. That's also what people ask for when you post a question.
Start fresh with How to Write and Compile LaTeX on Android, or look up a symbol in the LaTeX math symbols cheat sheet.