General ⇒ [Fix] LaTeX Error: Unknown message 'caption-code-by-class-deactivated' (tocbasic / KOMA-Script)
[Fix] LaTeX Error: Unknown message 'caption-code-by-class-deactivated' (tocbasic / KOMA-Script)
I recently updated MiKTeX (December 2025) and encountered a breaking error when compiling my thesis. I managed to fix it and wanted to share the solution here to help others.
**The Error:**
! LaTeX Error: Unknown message 'caption-code-by-class-deactivated' for module (LaTeX) 'tocbasic'.
**The Cause:**
It seems to be a bug in the latest version of `tocbasic.sty` (v3.49). The package tries to use an error message before it is actually defined in the file.
**The Solution (Workaround):**
You need to manually edit the file `tocbasic.sty` in your LaTeX distribution folder (e.g., `.../tex/latex/koma-script/tocbasic.sty`).
1. Open `tocbasic.sty`.
2. Search for the block starting with:
\msg_new:nnnn { tocbasic } { caption-code-by-class-deactivated }
ex :
\msg_new:nnnn { tocbasic } { caption-code-by-class-deactivated }
{
Loading~of~class-dependent~code~for~package~caption3~prevented\MessageBreak
line~context.
}
{
The~caption3~package~attempts~to~detect~classes~known~to~it\MessageBreak
using~a~number~of~heuristics~and,~if~necessary,\MessageBreak
reload~class-dependent~code.\MessageBreak
Unfortunately,~the~code~from~caption-koma.sto,~for~example,\MessageBreak
is~no~longer~compatible~with~the~KOMA-Script~package~tocbasic\MessageBreak
since~KOMA-Script~3.46.\MessageBreak
Therefore,~the~tocbasic~package~attempts~to~prevent~these~files\MessageBreak
from~being~loaded~by~pretending~to~caption3~that~a~standard~class\MessageBreak
is~being~used.\MessageBreak
Since~the~caption3~package,~as~part~of~the~caption~collection,\MessageBreak
is~no~longer~maintained,~and~since~the~KOMA-Script~author~himself\MessageBreak
is~trying~to~maintain~the~compatibility~of~the~caption~package\MessageBreak
with~KOMA-Script,~this~is~currently~the~best~known~method\MessageBreak
to~prevent~unnecessary~warnings~from~caption~or~caption3.
}
(It is located near the end of the file).
3. Cut (Ctrl+X) this entire definition block.
4. Paste (Ctrl+V) it at the beginning of the file, just after the `\ExplSyntaxOn` command.
ex :
\if@tocbasic@old@latex@found\else
\ExplSyntaxOn
% --- PASTE HERE---
\msg_new:nnnn { tocbasic } { caption-code-by-class-deactivated }
{ ... }
{ ... }
% -------------------------------------------
\bool_new:N \g__tocbasic_patch_all_bool
This ensures the message is defined before `tocbasic` tries to trigger it.
Hope this helps!
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- Stefan Kottwitz
- Site Admin
- Posts: 10397
- Joined: Mon Mar 10, 2008 9:44 pm
Re: [Fix] LaTeX Error: Unknown message 'caption-code-by-class-deactivated' (tocbasic / KOMA-Script)
welcome to the forum!
Thanks for letting us know! It's indeed helpful to post your fix here in the forum, as people may find it later when googling for such a fix, so thanks for that.
Stefan