I am working in a LaTeX template on overleaf to write my thesis in. Usually, generating a table of contents is simply a matter of \tableofcontents somewhere in the document. However, when I try to do this LaTeX gives the following compilation error:

l.24 \tableofcontents
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

Does anyone know what is going on here? How do I fix this? I also checked \listoffigures and \listoftables and they throw similar errors.

I know errors in here always have to be fully reproducible. But since the template contains a .cls file of +- 2000 lines, I decided not to paste everything here. The easiest and fastest way to reproduce the problem is opening This template on overleaf and adding \tableofcontents on line 24 in main.tex. Any help would be greatly appreciated.

  • 3
    Hi there! It seems that the class is simply not defining these commands. That's a bad coding style for the class itself and it should be corrected probably. The problem is that the class defined everything by itself, i.e., it does not build on conventional document classes. You can in theory solve this yourself, but given that this makes the class unusable, it's probably better to simply contact the class authors and ask them for improvements.
    – yo'
    Jun 21 at 14:02
  • That was indeed the problem! Thank you - I will post a fix as answer and contact the owners. Jun 21 at 14:09
  • 1
    But to follow up, if someone is making you use this template, then they need to build from a conventional document class. If someone is not making you use this template, then I would suggest switching to a different class. Otherwise, you're going to run into more problems like this.
    – Teepeemm
    Jun 21 at 14:43
  • Unfortunately - my thesis is almost finished and I was sorta forced to use this template. So I guess I'll have some more debugging to do. Jun 21 at 14:45

The problem was that the \tableofcontents functionality was undefined in the .cls file. On line 530 of the .cls file, under \newcommand{\contentsname}{Contents} add the following snippet:


That solves the issue.

  • Yes, this is an option, given you're close to a deadline. Fingers crossed you won't run into more issues!
    – yo'
    Jun 21 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.