How to Fix “Undefined Control Sequence” in an IEEE Overleaf Template
At a glance
- 1. Find the first error
Open the Overleaf log and identify the first undefined command, not just the line where compilation stops.
- 2. Check its package
Confirm the package defining the command is loaded and that the command spelling matches that package’s syntax.
- 3. Use one syntax
For pseudocode, choose algorithmic, algpseudocode, or algorithm2e syntax; do not mix their commands.
- 4. Test a small example
Compile a minimal IEEEtran document, then add your original content back a section at a time.
An “Undefined control sequence” error means LaTeX found a command beginning with a backslash that has not been defined in the current document. The IEEE Transactions template is not necessarily the problem: the command may be misspelled, its package may be missing, or it may belong to a different pseudocode package than the one you loaded.
The quickest fix is to identify the first command named in the error message, then check which package or class is supposed to provide it. The exact command matters: packages for typesetting algorithms use different spellings and are not interchangeable.
Find the command LaTeX does not recognize
In Overleaf, open the error details and look for a message like:
! Undefined control sequence.
l.24 \State
Here, \State is the command LaTeX does not recognize. The reported line is a useful starting point, though the underlying cause can be earlier—for example, a missing package in the preamble. Fix the first undefined-control-sequence error before investigating later errors, since one missing definition can trigger a cascade.
Check the command character by character. TeX commands are case-sensitive, so \State and \STATE are different. Also check whether the command is intended to be a macro or a literal backslash. If you mean to print a backslash in normal text, use a suitable text command such as \textbackslash rather than typing a bare \.
Match algorithm commands to the package
Pseudocode packages use different command names. A common source of errors is copying an example written for one package while loading another.
| Package | Typical commands |
|---|---|
algorithmic | \STATE, \IF, \ENDIF, \FOR |
algpseudocode (from algorithmicx) | \State, \If, \EndIf, \For |
algorithm2e | \KwIn, \KwOut, \For, \While |
For example, \State is the mixed-case command used by algpseudocode; if your document loads only algorithmic, LaTeX will not know that command. Either switch to the uppercase commands supported by algorithmic, or load and use algpseudocode consistently. Avoid loading multiple pseudocode packages just to make an unknown command work: their environments and command definitions can conflict.
A working IEEEtran example with algorithmic
This complete example uses the uppercase command style provided by algorithmic:
\documentclass[journal]{IEEEtran}
\usepackage{algorithm}
\usepackage{algorithmic}
\begin{document}
\begin{algorithm}
\caption{Sum the first $n$ integers}
\label{alg:sum}
\begin{algorithmic}[1]
\STATE $s \gets 0$
\FOR{$i=1$ to $n$}
\STATE $s \gets s+i$
\ENDFOR
\RETURN $s$
\end{algorithmic}
\end{algorithm}
\end{document}
The algorithm package supplies the floating algorithm environment, which allows a caption and label. The algorithmic package supplies the pseudocode environment and commands such as \STATE, \FOR, and \RETURN. The optional [1] requests line numbering. Follow the author instructions for your target IEEE publication if they require a particular algorithm presentation; a template or journal style may impose additional formatting rules.
If your source uses mixed-case commands such as \State and \For, use the corresponding algpseudocode setup instead. Do not combine those commands with the uppercase algorithmic style in the same pseudocode block.
A reliable debugging sequence
- Read the first error in the log. Write down the command shown after “Undefined control sequence.”
- Check the preamble. Confirm that the package defining the command is loaded before
\begin{document}. - Compare spelling and capitalization. Check the package documentation or a known example written for that exact package.
- Check for a copied command. A command may come from an older template, a custom
.styfile, or a package not included in the project. If it is custom, make sure its definition file is uploaded and loaded. - Compile a minimal example. Temporarily remove unrelated figures, bibliography code, and macros. Add them back gradually after the small document compiles.
If the command appears to be defined in a file that is already loaded, check whether the relevant conditional, class option, or package version is preventing that definition from being made. Overleaf’s compiler setting can matter for commands tied to a particular engine, but changing engines will not fix an ordinary spelling or missing-package error.
Common mistakes
- Changing
\Stateto\STATEwithout checking the package. This helps only if the document usesalgorithmic; the correct spelling depends on the package. - Loading a package after the document begins. Packages belong in the preamble, before
\begin{document}. - Mixing
algorithm2ewithalgorithmicenvironments. These packages define different interfaces. Choose one system and adapt the code to it. - Fixing a later error first. LaTeX may report several errors after one undefined command. Start with the earliest relevant message and compile again after each fix.
- Assuming every command in a template is built into IEEEtran. Many commands come from packages or custom style files rather than the document class itself.
Once the first unknown command is either defined or replaced with a command supported by the loaded package, compile again. If another undefined command appears, repeat the same check for that command rather than making unrelated changes to the template.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.