Fix “Undefined control sequence”
Trace an unknown command to a typo, missing package, unavailable definition, or scope error.
On this page
Undefined control sequence means LaTeX does not know the command it just read.
The usual causes are a misspelling, a package that was not loaded, a project
macro used before its definition, or a definition that is out of scope.
Identify the unknown token#
Open Problems and inspect the first error. The compile context normally shows the command at or just after the reported line. Check its spelling and capitalization before changing the preamble.
The domain is \(\mathbb{R}\). % Error unless a package defines \mathbb
The estimate is \(\alhpa\). % Typo: the command is \alpha
The domain is \(\R\). % Error unless the project defines \RSearch the project for the command. Use Go to Definition to inspect a recognized command definition across project files. If the command came from a paper or template, inspect the source that introduced it instead of guessing from its name.
Apply the matching repair#
For a documented package command, load its owning package once in the preamble. For a project abbreviation, define it before use:
\documentclass{article}
\usepackage{amssymb}
\newcommand{\R}{\mathbb{R}}
\begin{document}
The function maps \(\R\) to \(\R\).
\end{document}Use \newcommand when a name must not already exist. A definition placed inside
a group or environment may stop applying at its closing brace or \end; move a
document-wide definition to the main preamble. If definitions live in
macros.tex, confirm that the main document loads that file before the first use.
Avoid speculative package loading#
Do not add unrelated packages until the error disappears. Packages can change other commands, options, spacing, and template behavior. Find the command in the package or venue documentation, verify that package exists in the selected TeX Live snapshot, and load only that owner.
If the defining file, .sty, or .cls cannot be loaded, fix the
file-not-found error first. If the command is
created conditionally for a different engine or class, either select the
required engine/class or use the supported alternative; do not copy an internal
definition out of the template.
Compile again after one repair. Check that the original command resolves and the PDF uses the intended notation; a different first error alone is not enough. For several unrelated failures, return to Solve LaTeX compile problems and keep following the first current error.
