Skip to content
Get started

Fix "Undefined control sequence" in LaTeX

This error means LaTeX met a command it does not know. You will learn how to find the command and make it known.

In the Output panel’s full log:

./main.tex:3: Undefined control sequence.
l.3 The deadline is \textcolor
{red}{Friday}.

The l.3 line shows the source up to the point where LaTeX stopped. The last command on that line (here \textcolor) is the undefined one.

  • The command is misspelled, for example \beign or \textbg.
  • The command comes from a package you have not loaded, for example \textcolor (xcolor), \includegraphics (graphicx) or \mathbb (amssymb).
  • The command is defined in a file that is not part of this compile, or in a document class you are not using.
main.tex (broken)
\documentclass{article}
\begin{document}
The deadline is \textcolor{red}{Friday}.
\end{document}

Load the package that provides the command in the preamble, before \begin{document}:

main.tex (fixed)
\documentclass{article}
\usepackage{xcolor}
\begin{document}
The deadline is \textcolor{red}{Friday}.
\end{document}

If the command is a typo, correct its spelling instead.

  • For commands that are often used without their package, the error summary in the Output panel suggests the fix, for example “Add \usepackage{xcolor} to the preamble.”
  • For \includegraphics, \href, \url, \autoref, \nameref, \cref and \Cref, the editor underlines the command before you compile and offers a quick fix, Add \usepackage{…}.
  • To add a package without typing, use Add LaTeX package in the editor toolbar.

Not on Luzbase yet? It compiles LaTeX in your browser and links each error to its line, often with the fix. Start writing free.