Expand description
The core of latexml-oxide: the TeX engine that reads a document and builds its XML, the port of Perl
LaTeXML’s LaTeXML::Core, LaTeXML::Common and the definers of LaTeXML::Package.
A conversion runs through the stages Perl’s does: the mouth turns characters into tokens, the gullet
expands macros and reads arguments, the stomach digests tokens into boxes, and the document builds the XML
from them. The global state holds every definition (definition) and value, thread-local per conversion.
The binding module holds the definers and loaders (DefMacro, DefConstructor, RequirePackage, …) that
the bindings in latexml_engine and latexml_package are written with.
Most users want the latexml crate, which drives a whole conversion. For the Perl-to-Rust map, read
ORGANIZATION.md.
Re-exports§
pub use crate::common::error::*;
Modules§
- alignment
- Support for TeX-like Alignments
- aux_
macros - Auxiliary macros Helper macros for quicker and more idiomatic construction and access to data structures.
- binding
- The programmable API foundation for creating bindings of LaTeX sty/cls libraries
- comment
- TeX comments as standalone objects
- common
- Common abstractions that are useful at various stages of Core processing
- cycle_
guard - Windowed cycle-detection infinite-loop guard.
- definition
- All possible definitions for TeX-native commands (expandable, primitive, constructor,…)
- digested
- a shared interface for digested objects Interface layer for the full range of digested objects
- document
- An abstraction layer over the converted XML document
- dump_
codegen - Code generator: dump file → compiled Rust module Generate Rust source code from a kernel dump file.
- dump_
reader - Reader for Rust-native kernel dump files Reader for Rust-native kernel dump files (produced by dump_writer.rs).
- dump_
writer - Writer for Rust-native kernel dump files Writer for Rust-native kernel dump files.
- gullet
- The Gullet is responsible for reading Tokens and other data from the Mouth
- keyval
- A LaTeX-like Key-Value object Key-Value Definitions
- keyvals
- A collection of Key-Value objects, typically from a single LaTeX argument
- ligature
- Rules for combining together characters and other text rules
- list
- A list of
Digestedobjects - mouth
- The mouth is a thin interface over a file, responsible for reading characters and associating them with catcodes
- parameter
- The abstraction layer used by the Gullet to read arguments for the various kinds of TeX object definitions
- rewrite
- Rules for rewriting the constructed XML document, after core processing has completed
- stack_
guard - Configurable native-stack growth guard for deeply-recursive digestion.
- state
- A global, singleton, mutable state - hosts almost all TeX-facing runtime information for the conversion
- stomach
- The stomach is an abstraction responsible for digesting
TokensandRegisters prepared by the Gullet into Boxes - sxml
- Streaming XML substrate — the shared representation layer for fragmented (bounded-memory) conversion.
- tbox
- A TeX-like digested Box
- telemetry
- Per-job structured telemetry: phase wall times, counts, resource peaks.
See
docs/performance/TELEMETRY.mdfor the design contract. Per-job telemetry: phase wall times, counts, and resource peaks. - token
- The Token and its Catcode
- tokens
- Grouping Tokens together Token List constructors.
- util
- Auxilary utilities that do not participate in the main conversion abstraction
- watchdog
- Wall-clock watchdog that forcibly aborts the process after a deadline.
- whatsit
- A TeX-like digested Whatsit
Macros§
- Assign
Register - Perl
AssignRegister($cs, $value, $scope, @parameters)(Package.pm:1397-1406):$csa name or a Token; a cs that is not a register Warns and assigns nothing. - Char
Token - Special case: a character needs swift string conversion, so let’s use a dedicated macro
- Debug
- Debug-status diagnostics. Lazy: the argument expressions — which at
several sites build whole
node_to_stringsubtree serializations — are evaluated only whendebug_record_enabledsays the record would actually be logged (2026-08-23 audit, PERFORMANCE.md Open levers P0). The Debug status tally (note_status) is preserved unconditionally, so status counts are identical to the eager form at every verbosity. - Debug
Feature - Feature-gated debug logging — Perl’s
Debug(...) if $LaTeXML::DEBUG{feature}. Usage:DebugFeature!("frontmatter", "FRONT Add {}", entry). Logs with the feature name as thelogtarget (so output matches the previouslog::debug!(target: "frontmatter", ...)form) and counts a Debug in the status report, likeDebug!. NB deliberately does NOT forward toDebug!— its 3-expr(category, object, message)arm would mis-capture a format string with two arguments. - Error
- Explode
- Explode a string into a list of tokens, all w/catcode OTHER (except space). Note: newlines are converted to OTHER, NOT SPACE (Perl #2700 reverted #2646). ^^J in TeX decodes to CC_OTHER by default; let the tokenizer handle catcode reassignment if needed.
- Explode
Chars - Explode
Text - Similar to Explode, but convert letters to catcode LETTER and others to OTHER
Hopefully, this is essentially correct WITHOUT resorting to catcode lookup?
Perl sync: newlines are OTHER, not SPACE (matches Perl #2700 revert of #2646).
Letters are ASCII
[a-zA-Z]only, as Perl Token.pm:111-116 and latex.ltx\char@if@alph;éis OTHER. - Fatal
- Font
- build a Font from key=>val pairs
- Font
Directive - build a FontDirective from key=>val pairs (currently only FontDirective::Asset is supported in this macro)
- Info
- NewDefault
- given a struct
$name, create a new instance of it using the given key=>val pairs and complete the remaining entries via the Default instance - NewDefaultV
- Just like NewDefault, but adds a mandatory
.into_option()to all values - Note
- Progress note to BOTH the log and stderr — Perl
Note(_printline): the LOG always (if a buffer is bound, ANSI-stripped), STDERR only when the verbosity admits it ($USE_STDERR && $VERBOSITY>=0). The STDERR gate is the decoupled console verbosity (crate::util::logger::stderr_shows_info), NOTmax_level— under--quietthe log-file floor keepsmax_levelatInfo, but the console note must still be silenced (issue #763). - NoteLog
- Progress note to the LOG only — Perl
NoteLog(print $LOG … if $LOG). Always written to the bound log buffer (the log is the verbose record), never stderr. - NoteSTDERR
- Progress note to STDERR only — Perl
NoteSTDERR(if $USE_STDERR && $VERBOSITY>=0). Never touches the log. Gated on the decoupled console verbosity (crate::util::logger::stderr_shows_info), notmax_level(issue #763). - Number
- Roman
- Convert the number to upper case roman numerals, returning a list of LaTeXML::Core::Token
- SetCounter
- SymExplode
Text - T_
ACTIVE - macro for an ACTIVE char token
- T_ALIGN
- macro for an ALIGN “&” token
- T_ARG
- macro for a numbered ARG token
- T_BEGIN
- macro for a BEGIN “{” token
- T_
COMMENT - macro for a COMMENT content token
- T_CR
- macro for a CR “\n” token
- T_CS
- macro for a command sequence token
- T_END
- macro for a new END “{” token
- T_
LETTER - macro for a LETTER token
- T_
MARKER - macro for a tracing MARKER token
- T_MATH
- macro for a MATH “$” token
- T_OTHER
- macro for an OTHER code token
- T_
OTHER_ CHAR - T_OTHER from a single character
- T_PARAM
- macro for a PARAM “#” token
- T_RELAX
- macro for T_CS(“\relax”)
- T_SPACE
- macro for a SPACE token (default “ “)
- T_SUB
- macro for a SUB “_” token
- T_SUPER
- macro for a SUPER “^” token
- Token
- Token constructor macro (defaults to OTHER code).
Token!(sym <SymStr>, <catcode>)takes an already-interned symbol (a token’stext, aStored::String), without interning it again. - Tokens
- convenience macro for assembling a Tokens object from different pieces (
Token,Vec<Token>,Tokens) - Warn
- after_
digest - after_
digest_ simple - after_
digest_ single - before_
digest - before_
digest_ simple - before_
digest_ single - construct
- count_
unpack_ ref - fatal
- fontmap
- Instantiates a
Font, using theFontfields as keys, and calling.into()for each value. The specification can be partial - missing fields are taken via theDefaulttrait. - forbid
Math - generate_
message - getter
- A closure for obtaining a
RegisterValue, usually owned by aRegistergetter. - map
- A flexary macro for constructing
HashMap<String, T>maps, whereTis generic. - mixrc
- A variant on
mixvec!where each argument receives an additional.into()call best used with an outer context that explicitly provides the expected type, such as - mixvec
- A variant on
vec!where each argument receives an additional.into()call best used with an outer context that explicitly provides the expected type, such as - noreplacement
- pin
- Call-site-cached interning for string literals — the first call on
a thread (after an arena
reset) pins the literal viapin_static, later calls return the cachedSymStrdirectly (a thread-local load, no arena access). Use this from hot state-key lookup sites so you can keep writing string literals at the call site and still skip the per-callpin()hash probe: - predigest
- print_
stderr - prints a to STDERR without a line break, through
eprint!likeprintln_stderr!. - println_
stderr - prints a single line to STDERR. Through
eprintln!, asstderr_echo, so a test harness’s output capture receives it. - prop_
bool - prop_
digested - prop_
str - prop_
string - prop_
whatsit - properties
- raw_
char_ map - A flexary macro for constructing
HashMap<char, T>maps, whereTis generic - raw_map
- A flexary macro for constructing
HashMap<K, V>maps, whereKandVare both generic (inferred at time of use) - reader
- replacement
- report
- report_
mut - require
Math - reversion
- reversion_
digested - rewrite_
replace_ sub - roman
- Convert the number to lower case roman numerals, returning a list of LaTeXML::Core::Token
- s
- The
s!macro is a briefer alias forformat! - set
- Simple generic helper for
HashSet<K,V>creation Source: https://riptutorial.com/rust/example/4149/create-a-hashset-macro - setter
- sizersub
- some
- The
some!macro transforms data in typeStoOption<Into<T>>(always wrapping withSome) - static_
map - A flexary macro for constructing
HashMap<&'static str, &'static str>maps - stored_
map - A flexary macro for constructing
SymHashMap<Stored>maps - string_
keys_ map - A flexary macro for constructing
HashMap<String, T>maps - string_
map - A flexary macro for constructing
HashMap<String, String>maps - sym_map
- A flexary macro for constructing
SymHashMap<T>maps - tagsub
- transfer_
opt_ default - Transfers a mutable pointer to a hashmap entry, or fills in with a default if missing.
- unpack_
opt - Try to efficiently unwrap a
Vec<T>into a[T;n]for$arg1…$argn - unpack_
opt_ ref - Try to efficiently unwrap a
&Vec<T>into a&[T;n]for$arg1…$argn - unported
- unref
- Convenience macro to flexibly unpack a collection of
Vec<ArgWrap>arguments into individualTokensvariables.
Structs§
- Core
- The Core conversion runtime
- Core
Options - Configuration for the Core processing
- Post
State Values - The STATE values the render phases still read once the engine’s state is
released (
release_core_state_for_post) or, in a page-render worker process, never built:
Enums§
- TexMode
- The current TeX processing mode
Constants§
- NO_
PROPERTIES - The empty property map of an object that has none. A
constreference, not astatic: a static needsSync, whichStored(it holdsRcs and libxml nodes) is not; the empty map holds noStored, so every thread may read it.
Traits§
- BoxOps
- Common operations for Box-like (digested) data
Functions§
- ensure_
libxml_ init - Initialize libxml2 for thread safety. Must be called before any libxml2
operations that don’t go through
libxml::parser::Parser. Delegates to the safe wrapper in rust-libxml, which uses its ownstd::sync::Onceto guarantee exactly-once initialisation even across threads. - init_
thread_ engine - Build this thread’s engine roots in dependency order (arena, token constants, model, gullet, catcode templates),
as every conversion’s
Core::newdoes first. A thread that runs this before its first conversion may run more afterreset_thread_engine(which returnstruethere): the constants get back the symbols they hold. - release_
core_ state_ for_ post - Release the TeX engine’s thread-local state (
STATE,STOMACH,GULLET,StringInternerarena, and per-conversion caches) afterMakeBibliographycompletes and before the render phases (parallel_render,CrossRef,Graphics,MathML,XSLT), while keepingREPORT(includingundefined/missingmacro/file tallies),LOGGER,telemetry, and watchdog/deadline limits intact. - reset_
conversion_ state - Forgets what one conversion leaves on its thread for the next, as Perl builds a fresh State per document
(LaTeXML.pm:232): a persistent
cortex_workerconverts its papers on one thread. Called at each conversion’s start (initialize_report) and byreset_thread_engine. Not every per-conversion reset: the gullet’s, the math parser’s, the telemetry’s and the rescued boxes’ are inCore::initialize_singletons, the engine crate’s (the fm reading, the title-page check, the pdfTeX random generators) inConverter::initialize_session; a stack a guard pops on unwinding needs none. - reset_
thread_ engine - Free this thread’s accumulated engine state — the three
Statesingletons (STATE,STD_STATE,STY_STATE), the string-interner arena, the model, gullet, stomach and local assignments, and the per-conversion caches — and rebuild them empty, as a fresh thread’sinit_thread_engineleaves them. - shrink_
thread_ engine - Empty this thread’s engine roots to their smallest values, for a thread about to exit: the roots are leaked
statics (no destructor at thread exit), so a thread that exits after
reset_thread_engineleaves its rebuilt engine behind (~36 MB: the 2^17-slot interner, the three dump-sized States); after this, little more than the roots’ boxes. The thread must not convert again. The library API’s workers run it before they exit (retired, evicted, or after a panic); allocation-light, it needs no destructor and nounsafe(STABLE1 APIPOOL). - stored_
dimension - A size property as a Dimension: a Dimension itself, a Glue’s natural size, and a MuGlue/MuDimension in scaled
points at the current font size (TeX’s
math_kern, tex.web §717);Nonefor anything else.