When LaTeX Speaks in Ancient Curses
It's 11 PM. Your deadline is midnight. You hit compile and see:
! Missing $ inserted.
<inserted text>
$
l.42 The value is α
= 0.05Line 42 looks fine. The error message might as well be written in Sumerian. Your coffee is cold. Your patience is colder.
Here's the good news: there are only about 15 errors you'll ever see regularly. Once you learn to recognize them, debugging takes seconds instead of hours.
This guide decodes every common LaTeX error, explains what actually went wrong, and gives you copy-paste fixes.
Quick Debugging Strategy
Before diving into specific errors, here's the universal debugging approach that works 90% of the time:
- Read the line number - Look at the
l.XXin the error message - Check above that line - The actual error is often a few lines earlier
- Look for unmatched braces - Missing
}or{causes most errors - Delete auxiliary files - Sometimes
.auxfiles cause phantom errors - Comment out sections - Binary search for the problematic code
Now let's tackle each error one by one.
1. Missing $ inserted
The Error:
! Missing $ inserted.
<inserted text>
$
l.42 The value is α = 0.05What Happened:
You used a mathematical symbol (Greek letter, subscript, superscript, operator) outside of math mode. LaTeX expects these symbols only inside $...$ or equation environments.
The Fix: Wrap mathematical content in math delimiters:
% Wrong - Greek letter outside math mode
The value is α = 0.05
% Right - Inline math mode
The value is $\alpha = 0.05$
% Also right - Display math
The value is:
\[\alpha = 0.05\]Common Triggers:
- Greek letters: α, β, γ → Use
$\alpha$,$\beta$,$\gamma$ - Subscripts: H₂O → Use
$H_2O$ - Superscripts: x² → Use
$x^2$ - Special operators: ± → Use
$\pm$ - Underscores in text: file_name → Use
file\_nameor\texttt{file_name}
2. Undefined control sequence
The Error:
! Undefined control sequence.
l.42 \begn{equation}What Happened: LaTeX doesn't recognize the command you used. This is usually a typo or a missing package.
The Fix: Check the spelling of your command:
% Wrong - typo
\begn{equation}
\inclludegraphics{fig.png}
\textbf{bold}
% Right - correct spelling
\begin{equation}
\includegraphics{fig.png}
\textbf{bold}If the spelling is correct, you probably need to load a package:
% Commands and their required packages
\usepackage{graphicx} % for \includegraphics
\usepackage{amsmath} % for \align, \text, \boldsymbol
\usepackage{hyperref} % for \href, \url
\usepackage{xcolor} % for \textcolor
\usepackage{booktabs} % for \toprule, \midrule, \bottomruleDebugging Tip: The error message shows exactly which command failed. Look at what comes after the line number—that's your undefined command.
3. Missing begin document
The Error:
! LaTeX Error: Missing \begin{document}.
l.1 T
his is my textWhat Happened:
You have text before \begin{document}, or you forgot to include it entirely. The preamble (everything before \begin{document}) can only contain commands, not actual content.
The Fix: Ensure your document structure is correct:
\documentclass{article}
\usepackage{amsmath}
% Preamble: only commands here, no text
\begin{document}
% Your content goes here
This is my text
\end{document}Common Causes:
- Stray characters at the start of the file (including invisible BOM characters)
- Forgetting
\begin{document}entirely - Putting text in the preamble by accident
4. Environment undefined / Undefined environment
The Error:
! LaTeX Error: Environment align undefined.What Happened: You tried to use an environment that LaTeX doesn't know about. Either you misspelled it or forgot to load the package that defines it.
The Fix:
% align requires amsmath
\usepackage{amsmath}
\begin{align}
x &= y + z \\
a &= b + c
\end{align}
% lstlisting requires listings
\usepackage{listings}
\begin{lstlisting}
print("Hello")
\end{lstlisting}5. File not found
The Error:
! LaTeX Error: File `myimage.png' not found.What Happened: LaTeX can't locate the file you're trying to include. The file either doesn't exist, is in the wrong folder, or has a different name than specified.
The Fix:
% Check file location - use relative paths
\includegraphics{images/myimage.png}
% Or use absolute path (not recommended)
\includegraphics{/Users/name/project/myimage.png}
% Set graphics path in preamble
\graphicspath{{images/}{figures/}}
\includegraphics{myimage.png} % Will search in images/ and figures/Checklist:
- Is the file name spelled correctly (including extension)?
- Is the file in the same directory as your
.texfile? - Did you use the correct path separator (
/works on all systems)? - Is the file extension correct (
.png,.jpg,.pdf)?
6. Too many }'s / Extra }
The Error:
! Too many }'s.
l.42 }What Happened:
You have more closing braces } than opening braces {. This often happens when you accidentally delete an opening brace or add an extra closing one.
The Fix: Count your braces! Most editors can highlight matching braces. Look for:
% Wrong - extra closing brace
\textbf{some text}}
% Right
\textbf{some text}
% Wrong - missing opening brace
\frac1}{2}
% Right
\frac{1}{2}Prevention Tip: Use an editor that highlights matching braces and shows mismatches. VSCode, TeXShop, and Overleaf all do this.
7. Misplaced alignment tab character &
The Error:
! Misplaced alignment tab character &.
l.42 The R&D departmentWhat Happened:
The & character has special meaning in LaTeX (it's used for alignment in tables and equations). Using it in regular text causes this error.
The Fix: Escape the ampersand with a backslash:
% Wrong
The R&D department
% Right
The R\&D department
% In tables, & is correct for column separation
\begin{tabular}{ll}
Name & Value \\
Alpha & 0.05 \\
\end{tabular}8. Mismatched begin and end environments
The Error:
! LaTeX Error: \begin{itemize} on input line 10 ended by \end{enumerate}.What Happened: You started one environment but ended a different one. This is usually a copy-paste error or a typo.
The Fix: Make sure your begin and end environments match:
% Wrong - mismatched environments
\begin{itemize}
\item First
\item Second
\end{enumerate}
% Right - matching environments
\begin{itemize}
\item First
\item Second
\end{itemize}Debugging Tip:
The error message tells you both environments. Check the line number for \begin and find the corresponding \end.
9. Package clash / Option clash
The Error:
! LaTeX Error: Option clash for package xcolor.What Happened: You loaded the same package twice with different options, or another package loaded it with incompatible options.
The Fix: Load the package once with all needed options, before other packages that might use it:
% Wrong - loading xcolor twice
\usepackage{xcolor}
\usepackage[dvipsnames]{xcolor}
% Right - load once with all options
\usepackage[dvipsnames,svgnames]{xcolor}
% Or load early with options before other packages
\PassOptionsToPackage{dvipsnames}{xcolor}
\usepackage{tcolorbox} % This package loads xcolor internally10. Float(s) lost
The Error:
! LaTeX Error: Float(s) lost.What Happened: You have a float (figure or table) in a place where floats aren't allowed, like inside a minipage, parbox, or another float.
The Fix: Move the float outside the restricted environment:
% Wrong - float inside minipage
\begin{minipage}{0.5\textwidth}
\begin{figure}
\includegraphics{image.png}
\end{figure}
\end{minipage}
% Right - use captionof instead
\usepackage{caption}
\begin{minipage}{0.5\textwidth}
\centering
\includegraphics{image.png}
\captionof{figure}{My caption}
\end{minipage}11. Overfull \hbox
The Warning:
Overfull \hbox (15.0pt too wide) in paragraph at lines 42--45What Happened: This is a warning, not an error. LaTeX couldn't fit text within the margins, so it extends past the edge. This often happens with long words, URLs, or code.
The Fix: Several approaches:
% For URLs - use breakable URLs
\usepackage{url}
\url{https://very-long-url.com/path/to/resource}
% For long words - suggest hyphenation
super\-cali\-fragilistic
% For code - use breakable listings
\usepackage{listings}
\lstset{breaklines=true}
% Global fix - more permissive line breaking
\sloppy % In preamble (use sparingly)12. Runaway argument
The Error:
Runaway argument?
{This is some text that goes on and on...
! File ended while scanning use of \textbf.What Happened:
LaTeX started reading an argument (something in {...}) but never found the closing brace before the file ended or hit another problem.
The Fix: Find the missing closing brace:
% Wrong - missing closing brace
\textbf{This text is bold but I forgot to close it
More text here...
% Right
\textbf{This text is bold}
More text here...Debugging Tip: The error shows what command was waiting for its closing brace. Search for that command and check its braces.
13. ! Emergency stop
The Error:
! Emergency stop.
<*> myfile.texWhat Happened: LaTeX encountered an error so severe it couldn't continue. This usually follows another error, or your file has fundamental structural problems.
The Fix: Look at the errors before this one—the emergency stop is a consequence, not the cause. Common causes:
- Missing
\end{document} - Severely corrupted file
- Wrong file encoding
- Multiple cascading errors
Start by fixing the first error, then recompile.
14. Dimension too large
The Error:
! Dimension too large.
l.42 \hspace{999999cm}What Happened: You specified a dimension larger than LaTeX can handle (about 575cm or 16384pt).
The Fix: Use smaller dimensions or relative units:
% Wrong - too large
\hspace{1000cm}
% Right - reasonable size
\hspace{5cm}
% Better - relative units
\hspace{0.3\textwidth}
\vspace{2\baselineskip}15. ! TeX capacity exceeded
The Error:
! TeX capacity exceeded, sorry [main memory size=5000000].What Happened: Your document is too complex for TeX's memory limits. This can happen with huge documents, recursive macros, or complex TikZ graphics.
The Fix:
- Externalize TikZ graphics:
\usetikzlibrary{external}and\tikzexternalize - Split large documents using
\includeor\input - Simplify complex macros
- Increase memory limits in your TeX distribution's configuration
Prevention: The 5-Minute Pre-Compile Checklist
Before compiling, quickly check:
- Braces match - Every
{has a} - Environments match - Every
\begin{X}has\end{X} - Math mode is closed - Every
$has a closing$ - Special characters escaped -
&,%,_,#,$need backslashes in text - Packages loaded - Required packages are in the preamble
When All Else Fails
If you're completely stuck:
- Delete auxiliary files - Remove
.aux,.log,.toc,.lof,.lot,.bbl,.blg - Binary search - Comment out half your document and compile. If it works, the error is in the other half. Repeat.
- Start fresh - Copy your content into a minimal working document and add packages one by one
- Check encoding - Ensure your file is UTF-8 encoded
Conclusion
LaTeX errors look intimidating, but they follow patterns. Once you've seen each error a few times, you'll fix them automatically.
Key takeaways:
- Always fix the first error first
- The line number is a hint, not the exact location
- Most errors come from mismatched braces or missing packages
- When stuck, delete auxiliary files and recompile
Now you're equipped to handle any LaTeX error. Save this guide for reference, and those 11 PM debugging sessions will be a thing of the past.