Underleaf Logo
Underleaf
BlogPricing
Log InTry Free

Learn LaTeX

Getting Started

  • What is LaTeX?
  • LaTeX for Beginners

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.

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:

CommandPackage 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

  1. Compile and read the log. Find the l.<number> line and note the token printed right before the line break.
  2. Jump to that line in your source and check the command's spelling and capitalization character by character.
  3. Spelled correctly? Check the preamble for the package that defines it (table above). Add the \usepackage line and recompile.
  4. 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.

Try it free

Skip the syntax — let AI write it.

Snap a photo of an equation, a table, or full handwritten notes and Underleaf turns it into clean, compilable LaTeX in seconds. 10 free credits every month, no credit card required.

Convert your page
Handwritten notes converted into a typeset LaTeX document

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.

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:

CommandPackage 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

  1. Compile and read the log. Find the l.<number> line and note the token printed right before the line break.
  2. Jump to that line in your source and check the command's spelling and capitalization character by character.
  3. Spelled correctly? Check the preamble for the package that defines it (table above). Add the \usepackage line and recompile.
  4. 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.

Underleaf Logo
Underleaf

Empowering students and researchers with AI-powered tools for academic writing.

Go to appContact us

Company

PricingBlogTutorialsConference TemplatesConference Deadlines

Free Tools

Image to LaTeXExcel to LaTeXArXiv to LaTeXTikZ GeneratorLaTeX Table GeneratorCitation GeneratorThesis GeneratorChrome ExtensionAll Tools

Ask AI about Underleaf

Ask ChatGPTAsk ClaudeAsk Perplexity

© 2026 Underleaf. All rights reserved.