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):
| Command | Load this package |
|---|---|
\includegraphics | graphicx |
\mathbb, \checkmark | amssymb |
\text (in math) | amsmath |
\url | url or hyperref |
\href, \autoref | hyperref |
\cref | cleveref |
\textcolor, \colorbox | xcolor |
\toprule, \midrule, \bottomrule | booktabs |
\multirow | multirow |
\citep, \citet | natbib |
\SI, \qty | siunitx (\qty needs version 3) |
\degree | gensymb |
\sout | ulem |
\lipsum | lipsum |
\fancyhead, \fancyfoot | fancyhdr |
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
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
LaTeX Page Numbering: Roman Numerals, Page X of Y, and Removing Page Numbers
How to change page numbering in LaTeX: switch between roman and arabic numerals, start at any number, move the number, show "Page X of Y", and remove the number from the title page.
7 min readLaTeXLaTeX Footnotes: Add, Reuse and Customize Footnotes (Including in Tables)
How to use footnotes in LaTeX: \footnote, footnotes in tables and minipages, referring to the same footnote twice, symbols instead of numbers, unnumbered notes and endnotes.
7 min readLaTeXLaTeX Hyperlinks with hyperref: \href, \url, Link Colors and Internal Links
How to add hyperlinks in LaTeX with hyperref: \href and \url, email links, links to sections and pages, colored links instead of boxes, breaking long URLs, and PDF metadata.
7 min read