Getting Started
Text Formatting
Mathematical Expressions
Document Structure
Page Layout
Errors & Troubleshooting
Undefined Control Sequence in LaTeX: What It Means and How to Fix It
Undefined control sequence means TeX hit a backslash command it has no definition for. In real documents the cause is almost always one of two things: a typo in the command name, or a command that is perfectly real but lives in a package you never loaded. Fix the spelling or add the \usepackage line, and the error goes away.
Reading the error message
The log tells you exactly where TeX gave up. Here is what it looks like:
Two things matter. l.42 is the line number where TeX stopped. And the log breaks the line at the exact point of failure: the last thing printed before the break is the command TeX did not recognize. Here that is \mathbb — everything after the break is just the rest of the line, which TeX has not read yet.
One caveat: if the undefined command sits inside a macro you defined yourself, l.42 points at the line where the macro was used, not where it was defined. The broken token before the line break is still the reliable clue.
Cause 1: the package isn't loaded
This is the most common cause by a wide margin. The command is spelled correctly, documented everywhere, works in every example you find online — and still errors, because it is defined by a package your preamble doesn't load. Look up the command here and add the matching line:
| Command | Package to load |
|---|---|
\mathbb | \usepackage{amssymb} |
\citep, \citet | \usepackage{natbib} |
\includegraphics | \usepackage{graphicx} |
\toprule, \midrule, \bottomrule | \usepackage{booktabs} |
\multirow | \usepackage{multirow} |
\SI, \si, \num | \usepackage{siunitx} |
\href, \url | \usepackage{hyperref} |
\cref, \Cref | \usepackage{cleveref} |
\bm | \usepackage{bm} |
\FloatBarrier | \usepackage{placeins} |
The \usepackage line goes in the preamble — between \documentclass{...} and \begin{document}. Putting it after \begin{document} produces a different error (Can be used only in preamble), so if you see that one, you put the line in the wrong place, not the wrong package.
Cause 2: a typo in the command name
\textbf typed as \textbg, \begin as \beign. LaTeX commands are case-sensitive too: \Textbf is undefined even though \textbf exists, and \cref and \Cref are two different (both valid) commands. Read the token in the error character by character against what you meant to type — after a few hours of writing, your eyes will autocorrect the typo unless you force them not to.
Cause 3: the command belongs to a different document class
Some commands are defined by the class, not a package. \chapter exists in book and report but not article. \affiliation and \email come from journal classes like revtex4-2. If you copied a snippet from a colleague's paper and it errors in yours, check the first line of both files: a different \documentclass means a different set of built-in commands.
Cause 4: characters pasted from Word or a PDF
Pasted text carries invisible trouble: smart quotes, a Unicode minus sign (−) instead of a hyphen, non-breaking spaces. Depending on your setup these can expand into partial commands and produce an undefined control sequence pointing at a line that looks completely normal. If the reported line looks fine, retype it by hand — genuinely delete it and type it fresh, don't copy it again. That fixes it more often than staring at it does.
Cause 5: a math-only command in text mode
A handful of commands only exist inside math mode. Writing \frac{1}{2} or \mathbb{R} in plain prose can surface as undefined control sequence rather than the friendlier Missing $ inserted, depending on the command. The fix is the same either way — wrap it:
The fix workflow
- Compile and read the log. Find the
l.<number>line and note the token printed right before the line break. - Jump to that line in your source and check the command's spelling and capitalization character by character.
- Spelled correctly? Check the preamble for the package that defines it (table above). Add the
\usepackageline and recompile. - Still failing? Check the document class, then retype the line by hand in case pasted characters are hiding in it.
Fix the first error only, then recompile. One undefined command can cascade into dozens of follow-on errors, and chasing them in order wastes time — they usually all vanish once the first one is fixed.
Frequently asked questions
What does 'Undefined control sequence' mean in LaTeX?
TeX reached a command (anything starting with a backslash) that it has never seen a definition for. Usually the command is real but comes from a package you haven't loaded — add the matching \usepackage line to your preamble. If the package is loaded, check the spelling: LaTeX commands are case-sensitive.
How do I find which line caused the error?
Look for the line in the log starting with l. followed by a number, e.g. l.42. That is the line TeX stopped on, and the last token printed before the log breaks onto a new line is the exact command it choked on. Note the real mistake can be earlier if the command is defined inside another macro.
Which package do I need for \mathbb, \citep, or \toprule?
\mathbb needs amssymb, \citep and \citet need natbib, \toprule (and \midrule, \bottomrule) needs booktabs. Loading the package with \usepackage in the preamble fixes the error. A missing package is by far the most common cause of undefined control sequence errors.
Why is a command undefined in my document even though it worked in another one?
Either the other document loaded a package this one doesn't, or the command belongs to the document class itself. \affiliation, \keywords, and \frontmatter, for example, only exist in certain classes. Compare the two preambles and copy over the missing \usepackage or \documentclass line.
Undefined Control Sequence in LaTeX: What It Means and How to Fix It
Undefined control sequence means TeX hit a backslash command it has no definition for. In real documents the cause is almost always one of two things: a typo in the command name, or a command that is perfectly real but lives in a package you never loaded. Fix the spelling or add the \usepackage line, and the error goes away.
Reading the error message
The log tells you exactly where TeX gave up. Here is what it looks like:
Two things matter. l.42 is the line number where TeX stopped. And the log breaks the line at the exact point of failure: the last thing printed before the break is the command TeX did not recognize. Here that is \mathbb — everything after the break is just the rest of the line, which TeX has not read yet.
One caveat: if the undefined command sits inside a macro you defined yourself, l.42 points at the line where the macro was used, not where it was defined. The broken token before the line break is still the reliable clue.
Cause 1: the package isn't loaded
This is the most common cause by a wide margin. The command is spelled correctly, documented everywhere, works in every example you find online — and still errors, because it is defined by a package your preamble doesn't load. Look up the command here and add the matching line:
| Command | Package to load |
|---|---|
\mathbb | \usepackage{amssymb} |
\citep, \citet | \usepackage{natbib} |
\includegraphics | \usepackage{graphicx} |
\toprule, \midrule, \bottomrule | \usepackage{booktabs} |
\multirow | \usepackage{multirow} |
\SI, \si, \num | \usepackage{siunitx} |
\href, \url | \usepackage{hyperref} |
\cref, \Cref | \usepackage{cleveref} |
\bm | \usepackage{bm} |
\FloatBarrier | \usepackage{placeins} |
The \usepackage line goes in the preamble — between \documentclass{...} and \begin{document}. Putting it after \begin{document} produces a different error (Can be used only in preamble), so if you see that one, you put the line in the wrong place, not the wrong package.
Cause 2: a typo in the command name
\textbf typed as \textbg, \begin as \beign. LaTeX commands are case-sensitive too: \Textbf is undefined even though \textbf exists, and \cref and \Cref are two different (both valid) commands. Read the token in the error character by character against what you meant to type — after a few hours of writing, your eyes will autocorrect the typo unless you force them not to.
Cause 3: the command belongs to a different document class
Some commands are defined by the class, not a package. \chapter exists in book and report but not article. \affiliation and \email come from journal classes like revtex4-2. If you copied a snippet from a colleague's paper and it errors in yours, check the first line of both files: a different \documentclass means a different set of built-in commands.
Cause 4: characters pasted from Word or a PDF
Pasted text carries invisible trouble: smart quotes, a Unicode minus sign (−) instead of a hyphen, non-breaking spaces. Depending on your setup these can expand into partial commands and produce an undefined control sequence pointing at a line that looks completely normal. If the reported line looks fine, retype it by hand — genuinely delete it and type it fresh, don't copy it again. That fixes it more often than staring at it does.
Cause 5: a math-only command in text mode
A handful of commands only exist inside math mode. Writing \frac{1}{2} or \mathbb{R} in plain prose can surface as undefined control sequence rather than the friendlier Missing $ inserted, depending on the command. The fix is the same either way — wrap it:
The fix workflow
- Compile and read the log. Find the
l.<number>line and note the token printed right before the line break. - Jump to that line in your source and check the command's spelling and capitalization character by character.
- Spelled correctly? Check the preamble for the package that defines it (table above). Add the
\usepackageline and recompile. - Still failing? Check the document class, then retype the line by hand in case pasted characters are hiding in it.
Fix the first error only, then recompile. One undefined command can cascade into dozens of follow-on errors, and chasing them in order wastes time — they usually all vanish once the first one is fixed.
Frequently asked questions
What does 'Undefined control sequence' mean in LaTeX?
TeX reached a command (anything starting with a backslash) that it has never seen a definition for. Usually the command is real but comes from a package you haven't loaded — add the matching \usepackage line to your preamble. If the package is loaded, check the spelling: LaTeX commands are case-sensitive.
How do I find which line caused the error?
Look for the line in the log starting with l. followed by a number, e.g. l.42. That is the line TeX stopped on, and the last token printed before the log breaks onto a new line is the exact command it choked on. Note the real mistake can be earlier if the command is defined inside another macro.
Which package do I need for \mathbb, \citep, or \toprule?
\mathbb needs amssymb, \citep and \citet need natbib, \toprule (and \midrule, \bottomrule) needs booktabs. Loading the package with \usepackage in the preamble fixes the error. A missing package is by far the most common cause of undefined control sequence errors.
Why is a command undefined in my document even though it worked in another one?
Either the other document loaded a package this one doesn't, or the command belongs to the document class itself. \affiliation, \keywords, and \frontmatter, for example, only exist in certain classes. Compare the two preambles and copy over the missing \usepackage or \documentclass line.
Getting Started
Text Formatting
Mathematical Expressions
Document Structure
Page Layout
Errors & Troubleshooting
