It's the number-one error for LaTeX beginners — and the good news is that it almost always has two simple causes. "Undefined control sequence" literally means you used a command LaTeX does not know.
The message looks like this, with the offending line number (here l.7):
! Undefined control sequence.
l.7 \mathbb
{R}
?
Cause #1 — a typo
One letter too many or too few and the command no longer exists: \textt instead of \texttt, \fintegral instead of \int, \usepackage{graphixs} instead of graphicx. LaTeX is strict about spelling.
l.7 in the message points to the exact line. Re-read the reported command there, character by character. Cause #2 — the command comes from a package you didn't load
Many commands only exist if you load the package that provides them. Very common examples:
\mathbb,\mathcal,\leqslant→amssymb\includegraphics→graphicx\textcolor,\colorbox→xcolor\href,\url→hyperref
Without that package, the following code fails:
\documentclass{article}
\begin{document}
The set of real numbers: $\mathbb{R}$. % \mathbb unknown here -> error
\end{document}
Just add the complete line \usepackage{amssymb} in the preamble (between \documentclass and \begin{document}) to fix it:
\documentclass{article}
\usepackage{amssymb} % provides \mathbb
\begin{document}
The set of real numbers: $\mathbb{R}$.
\end{document}
Try it yourself
This example compiles directly in your browser — no installation. Compile it once (it works). Then, to see the error "for real", delete the \usepackage{amssymb} line, recompile, and watch: the "Undefined control sequence" message then appears in the log.
The method, every time
- Read the line number (
l.7): the error is there, or just before. - Check the spelling of the reported command.
- Ask where it comes from: if it's a "special" command (math, colors, images…), it needs its
\usepackage. - Don't know the package? Search "command-name latex package" — the exact name is there.
An AI can fix the error — directly in your code
AI assistants (Claude, Gemini, ChatGPT…) know LaTeX very well: describe the error message and they explain the cause with a fix. The usual drawback is the back-and-forth — copying your code to the AI, then pasting its answer back into the editor.
sarmate.net removes this round-trip with its MCP server: you connect the AI directly to your online editor. It reads your files, compiles them, analyzes the error log and fixes the code in place, with no copy-paste. You stay in control: nothing is changed without your approval.
Write and compile LaTeX online
Full editor, instant compilation (pdfLaTeX/XeLaTeX/LuaLaTeX), nothing to install.
Open the online editor