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. A provider named for first use (provide_on_first_use) is asked there too: it
defines a few commands, not a format, so the scan reads the name again.
Functions§
- name_
first_ use_ provider - Name
provider, an expandable command that defines a family of commands where still undefined, as what an undefinedtokenof that family runs on its first use ("{cs}:first@use@provider", global). Nothing is defined until then, so\ifdefined,\@ifundefinedand a document’s own\newcommandsee what TeX sees. Beyond Perl, which has no such seam: the ar5iv preload names hyperref’s and atbegshi’s user commands (OXIDIZED_DESIGN #588). - name_
undefined_ fallback - Name
stand_inas what a use of the undefinedtokenreads ("{cs}:undefined@fallback", global), forundefined_fallback. - provide_
on_ first_ use - Run the provider named for the undefined
token(name_first_use_provider), until it has provided once;true⇒tokennow has a meaning, retry it. Asked at every undefined-CS site, aftertry_autoloadandtry_refused_environment_definition. - reset_
first_ use_ providers - Forget that a provider was named (
reset_thread_engine). - reset_
undefined_ fallback - Forget that a stand-in was named (
reset_thread_engine). - 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). - set_
refused_ environment_ hook - Register the engine’s
RefusedEnvironmentHook(first registration wins). - try_
autoload - Ask the registered hook whether
tokenshould pull the LaTeX kernel in. - try_
refused_ environment_ definition - Ask the registered
RefusedEnvironmentHookabout an undefinedtoken, at the same two call sites astry_autoload(after it):true⇒tokennow has a meaning, retry it. - undefined_
fallback - The stand-in LaTeXML reads for an undefined
token, if one is named (name_undefined_fallback): the name stays undefined —\ifdefined,\@ifundefinedand\meaningsee what TeX sees — and a use of it reads the stand-in, which is responsible for saying that TeX errs there. The class-less\chapteris the one named (OXIDIZED_DESIGN #734, latexml_enginesupply_chapter_fallback). Asked at the two undefined-CS sites, aftertry_autoloadandtry_refused_environment_definition:Some⇒ read the stand-in in place oftoken.
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”. - Refused
Environment Hook - Engine-supplied procedure for “does an open environment whose class definition the kernel’s lock refused define
tokenfor its body, and if so define it as the class would have and report it defined” — a class’s\figurethat makes\csentencefor its captions (bmcart.cls:716), its\abstractthat makes\parttitle(:1508). The same contract asKernelAutoloadHook:true⇒ retrytoken.