Master LaTeX debugging and error resolution. Learn to identify, understand, and fix common compilation errors with practical solutions and prevention strategies.
Learn to diagnose and fix LaTeX compilation errors efficiently. This comprehensive guide covers error types, debugging strategies, common problems with solutions, and preventive measures to keep your documents compiling smoothly.
Prerequisites: Basic LaTeX knowledge Time to complete: 30-35 minutes Difficulty: Intermediate to Advanced What you’ll learn: Error types, debugging tools, common fixes, and prevention strategies
! LaTeX Error: File `missing-package.sty' not found.^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Type of error and descriptionSee the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help. ... l.5 \usepackage{missing-package}^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Line number and problematic code? ^ Prompt for user action (press Enter to continue)
% Error: \begin{itemize} ended by \end{enumerate}% Wrong:\begin{itemize}\item First item\item Second item\end{enumerate} % Mismatched% Correct:\begin{itemize}\item First item\item Second item\end{itemize}% Common mismatches:% - equation/align% - table/tabular% - figure/center% - document/article% Prevention: Use editor matching% Most editors highlight matching begin/end
% Error: Missing $ inserted% Problem: Math symbols in text modeThe variable α represents... % ErrorThe variable $\alpha$ represents... % Correct% Problem: Text in math mode$the value of x = 5$ % Wrong$\text{the value of } x = 5$ % BetterThe value of $x = 5$ % Best% Problem: Display math syntax$$E = mc^2$$ % Deprecated\[E = mc^2\] % Correct% Problem: Nested math modes$the formula $x^2$ is$ % Error$\text{the formula } x^2 \text{ is}$ % Correct
% Step 1: Start with problematic document% Step 2: Remove content until error disappears% Step 3: Add back until error returns% MWE template\documentclass{article}\usepackage{minimal-packages-only}\begin{document}% Minimal content that reproduces errorOnly include what's necessary to show the problem\end{document}% Good MWE example for table error:\documentclass{article}\usepackage{booktabs}\begin{document}\begin{tabular}{cc}\topruleA & B \\\bottomrule\end{tabular}\end{document}
% Error: TeX capacity exceeded% Problem: Too many labels/refs% Solution: Increase memory% Edit texmf.cnf or set environment:% export extra_mem_top=10000000% Problem: Dimension too large\vspace{100000pt} % Error\vspace{100cm} % OK if fits on page% Problem: Too deeply nested% Solution: Restructure document% Avoid >6 levels of nesting% Problem: Hash size exceeded% Too many commands/labels% Solution: Clean auxiliary files% rm *.aux *.toc *.lof *.lot
% Common package conflicts and solutions% hyperref - load last (with exceptions)\usepackage{graphics}\usepackage{color}\usepackage{hyperref} % Almost always last\usepackage{cleveref} % After hyperref% inputenc vs fontenc order\usepackage[utf8]{inputenc} % First\usepackage[T1]{fontenc} % Second% babel conflicts\usepackage[english]{babel}\usepackage{csquotes} % After babel% Math font conflicts% Don't use multiple math font packages% \usepackage{mathptmx}% \usepackage{fourier} % Conflict!% Caption and subcaption\usepackage{caption}\usepackage{subcaption} % Must be after caption% Don't use with subfigure/subfig
% Document with multiple errors\documentclass{article}\usepackage{amsmath}% Missing graphicx package\begin{document}\title{Debugging Example}\autor{John Doe} % Typo: should be \author\maketitle\section{Introduction}This document has several errors. The equation α = β needs math mode. % Missing $\begin{figure}[h]\includegraphics{nonexistent} % Missing package and file\caption{Test}\label{fig:test\end{figure} % Missing }See Figure \ref{fig:tset}. % Typo in label\begin{equaton} % Typo: should be equationx^2 + y^2 = z^2\end{equation} % Mismatch\end{document}
Remember: Most LaTeX errors have simple solutions. Read error messages carefully, fix the first error first, and when in doubt, create a minimal example that reproduces the problem. The LaTeX community is helpful - don’t hesitate to ask for help with a good MWE.