The “undefined control sequence” error means LaTeX found a command it does not recognize. This is the most common LaTeX error, and it is almost always one of three things: a typo in the command name, a missing package, or invisible characters from copy-paste. The error log tells you the exact line number and the exact command that failed.
What you see:
! Undefined control sequence.
l.42 \includegraphics
{figure1.pdf}
The command after l.42 is the one LaTeX does not recognize. In this case, \includegraphics is a valid command, but it only exists after you load the graphicx package.
Quick answer
Check three things in this order:
- Spelling: is the command name typed correctly? LaTeX is case-sensitive
- Package: does the command need a
\usepackage{}you have not loaded? - Copy-paste: did the line come from Word, a PDF, or a website?
If the command is spelled correctly and the package is loaded, delete the entire line and retype it manually. Invisible Unicode characters from copy-paste are the cause.
Undefined Control Sequence LaTex Error Cause 1 : Typo in the Command Name
LaTeX commands are case-sensitive. \textBf{} fails because the correct command is \textbf{}. \Usepackage{} fails because it is \usepackage{}. \begin{itemze} fails because it is \begin{itemize}.
Check the exact spelling of the command on the line the error points to. If it looks correct, check the line above. A missing closing brace on the previous line can cause LaTeX to misread the next line and report the wrong command as undefined.
Cause 2: Missing Package
Many commands only exist after you load the package that defines them. If you use a command without its package, LaTeX does not know what it is.
These are the 10 commands that trigger this error most often:
\includegraphics{} needs \usepackage{graphicx}. This is the single most frequent trigger.
\citep{} or \citet{} needs \usepackage{natbib}. If you are using biblatex instead, the equivalents are \parencite{} and \textcite{}.
\href{} or \url{} needs \usepackage{hyperref} or \usepackage{url}.
\textcolor{} or \definecolor{} needs \usepackage{xcolor}.
\begin{align} needs \usepackage{amsmath}. The align environment is not part of base LaTeX.
\boldsymbol{} needs \usepackage{amssymb} or \usepackage{amsmath}.
\toprule, \midrule, \bottomrule need \usepackage{booktabs}.
\lstinputlisting{} or \begin{lstlisting} needs \usepackage{listings}.
\SI{} or \si{} needs \usepackage{siunitx}. Common in physics and engineering papers.
\subfloat{} or \subfigure{} needs \usepackage{subfig} or \usepackage{subcaption}. Note that the subfigure package is deprecated. Use subcaption instead.
We fix LaTeX compilation errors as part of every formatting job.
Upload your .tex file and the error log. We identify every issue, fix it, and deliver a clean-compiling document.
Cause 3: Invisible Characters From Copy-Paste
If the command is spelled correctly and the package is loaded, but the error persists, the problem is almost certainly an invisible character. Text pasted from Word, Google Docs, PDFs, or websites contains characters that look identical to their ASCII equivalents but are different bytes.
Common culprits: smart quotes that look like regular quotes but are Unicode, non-breaking spaces that look like regular spaces, and backslashes from Windows file paths (C:\Users\Files) where LaTeX interprets \Users as a command.
The fix: delete the entire line and retype it manually. Do not copy-paste it again from the same source. If you need to find the specific character, open the file in a text editor that shows hex values (Notepad++ with Hex Editor, or VS Code with a hex viewer) and look for bytes above 0x7F.
How to Read the Error Log
The line number in the error message points to where LaTeX stopped, but the actual problem is sometimes on the line above. If the command on the reported line looks correct, check the previous line for a missing closing brace } or an incomplete command that caused LaTeX to misread the next line.
In Overleaf, click the error message in the log panel and Overleaf will jump to the line. In TeXstudio and VS Code with LaTeX Workshop, errors are highlighted inline in the editor.
For other common LaTeX errors, see our complete guide to LaTeX compilation errors.
Frequently Asked Questions
It means LaTeX encountered a command (starting with a backslash) that it does not recognize. The three most common causes are a typo in the command name, a missing \usepackage{} declaration for the package that defines the command, or invisible Unicode characters from copy-pasting text from Word, PDFs, or websites.
LaTeX reports the line where it realized something was wrong, not necessarily where the actual error is. A missing closing brace on line 30 can cause LaTeX to misread line 31 and report the undefined control sequence there. Always check the line above the reported line if the reported line looks correct.
Search the command name on CTAN (ctan.org) or on the TeX Stack Exchange. Overleaf’s documentation also lists common commands and their required packages. If you are using a command from a template or a colleague’s document, check the preamble of their original .tex file for the \usepackage{} lines you may be missing.