LaTeX

Undefined Control Sequence in LaTeX: What It Means and How to Fix It

Find the command LaTeX does not recognise, then load the right package or fix the spelling.

MZ
Dr. Meng Zhao|Physician-Scientist · Founder, LabCat AI
Published: October 2026•6 min read•LaTeX

The error looks like this in the log or in the Overleaf error panel:

! Undefined control sequence.
l.7 \includegraphics
                    [width=\linewidth]{figure1}

It means LaTeX reached a command (a "control sequence") that has not been defined. The line starting l. gives the line number, and the command is the last one at the end of that first line, here \includegraphics on line 7. Everything below the break is the part of the line LaTeX had not read yet.

Short answer

Look at the last command before the line break in the error message. Either it is misspelled, or it comes from a package you have not loaded. \includegraphics needs graphicx, \url needs url or hyperref, and \mathbb needs amssymb.

Cause 1: a package is not loaded

Most "undefined" commands come from packages. These are the ones that catch people most often (each was checked to fail without its package):

CommandLoad this package
\includegraphicsgraphicx
\mathbb, \checkmarkamssymb
\text (in math)amsmath
\urlurl or hyperref
\href, \autorefhyperref
\crefcleveref
\textcolor, \colorboxxcolor
\toprule, \midrule, \bottomrulebooktabs
\multirowmultirow
\citep, \citetnatbib
\SI, \qtysiunitx (\qty needs version 3)
\degreegensymb
\soutulem
\lipsumlipsum
\fancyhead, \fancyfootfancyhdr

Add the package to the preamble, before \begin{document}:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=0.5\linewidth]{example-image}
\end{document}

If you copied a document from a template, check that you also copied its preamble. A missing class file shows a different error ("File ... not found").

Cause 2: a typo or the wrong case

LaTeX commands are case-sensitive. \Begin, \Section and \textBF are all undefined. Some commands people expect simply do not exist: there is no \Alpha in standard LaTeX, because the capital Greek alpha is the Latin letter A.

Cause 3: the command is defined later or elsewhere

A \newcommand must come before the first use. If you keep macros in a separate file, make sure the \input comes first. With several files, the command may be defined in a chapter you are not currently compiling.

Cause 4: Windows paths with backslashes

In \input{C:\Users\meng\chapter1}, LaTeX reads \Users and \meng as commands and reports them as undefined. Use forward slashes, which work on every system, and prefer paths relative to the main file:

\input{chapters/chapter1}

Cause 5: an old package version

Newer commands fail on older installations. \qty arrived in siunitx version 3, and a university server or an old TeX Live may still have version 2. Update your distribution, or on Overleaf choose a recent TeX Live version in the project menu.

Reading the error on Overleaf

Overleaf shows the same message with a link to the line. Fix the first error first: one undefined command often causes a chain of later errors that disappear once it is fixed. If a document compiles despite the error, the output is still wrong, because LaTeX skips the undefined command and carries on.

For specific commands, see our guides to page numbering, hyperlinks and background colors, which list the packages each example needs.

Frequently Asked Questions

What does undefined control sequence mean in LaTeX?

LaTeX found a command (a word starting with a backslash) that has not been defined, usually because of a typo or a package that is not loaded.

How do I find which command is undefined?

In the error message, look at the line starting with l. and the line number. The undefined command is the last command at the end of that line, just before the line break.

Why is \includegraphics undefined?

It comes from the graphicx package. Add \usepackage{graphicx} to the preamble.

More LaTeX Guides

MZ

Written by Dr. Meng Zhao

Physician-Scientist · Founder, LabCat AI

MD · Former Neurosurgeon · Medical AI Researcher

Dr. Meng Zhao is a former neurosurgeon turned medical-AI researcher. After years in the operating room, he moved into applied AI for clinical workflows and now leads LabCat AI, a medical-AI company working on decision support and research tooling for clinicians. He built Journal Metrics as a free resource for researchers who need reliable journal metrics without paid database subscriptions.

Related Articles