Expand description
Autoload the LaTeX format when an undefined control sequence turns out to be one the LaTeX kernel defines.
§Why this exists
In real LaTeX there is no such thing as “before the kernel”: latex.ltx
is the format, so every kernel command is live from token one. LaTeXML
(Perl and Rust alike) instead loads LaTeX.pool lazily, on first sight of a
trigger control sequence — the list ported from Perl TeX.pool.ltxml
L33-56 (\documentclass, \newcommand, \begin, …), installed in
latexml_engine::tex.
A curated trigger list is incomplete by construction. Any kernel command
that is not on it — and a document may legitimately use one before
\documentclass — is simply undefined, gets an <ltx:ERROR/> stub, and the
document derails. The canonical case is the “use this class if installed”
idiom
\IfFileExists{proc-l.cls}{\documentclass{proc-l}}{\documentclass{amsproc}}where the collapsed conditional means no class is ever selected and the
run cascades into Fatal:TooManyErrors. Same-host Perl LaTeXML fails
identically (see docs/parity/KNOWN_PERL_ERRORS.md — shared defect, upstream
candidate), so this is a “at parity, still a bug” fix rather than a
divergence repair.
§What this module is
The single funnel through which the undefined-CS paths ask “should the LaTeX
kernel be loaded for this token instead of erroring?”. It holds no policy of
its own: the answer comes from a hook the engine registers at TeX.pool
load time (set_hook), because deciding it needs the kernel dump and the
pool loader, neither of which latexml_core owns.
The eager Perl trigger list is kept — it fires on a legitimate use before any error is raised, which this hook cannot do. This is the safety net beneath it, not a replacement.
§Call sites: two, deliberately not three
read_x_token’s Outcome::Undefined arm and invoke_token_undefined are
the paths a CS reaches when it is actually being used. read_balanced’s
“cs SHOULD have defn by now; report early!” branch — the third
generate_error_stub caller, inside token-list scanning — is left alone on
purpose: it fires while collecting an \edef-style body rather than
executing it, and loading a format mid-scan buys a rare case
(\edef\x{\IfFileExists…} before \documentclass) at the price of running
the whole pool from inside a partially-read token list. Wire it up only with
a reproducer that needs it.
Functions§
- set_
hook - Register the engine’s kernel-autoload decision procedure. Called from
TeX.pool’s definition load, which precedes every conversion. Repeat calls are ignored (the first registration wins). - try_
autoload - Ask the registered hook whether
tokenshould pull the LaTeX kernel in.
Type Aliases§
- Kernel
Autoload Hook - Engine-supplied decision procedure for “is
tokena LaTeX kernel control sequence, and if so load the kernel and report whether it is now defined”.