Skip to main content

Module gullet

Module gullet 

Source
Expand description

The Gullet is responsible for reading Tokens and other data from the Mouth

Structs§

FileHooksEnd
A content file read with latex.ltx’s file hooks (content::input_content_with_file_hooks): its request, and whether its load pushed ltfilehook’s file-name stack, which its end pops (content::input_file_ended).
Gullet
InputMark
A place in the input (input_mark): how many mouths enclose it, the current mouth’s read position, its pushback’s length then, the mark’s serial on the mouth’s watch (PushbackWatch), and the pushback’s last MARK_HELD tokens, the next to read last. Copy: a mark holds nothing on the heap, so the marks a ledger keeps (an author block’s each) cost what their number does, whatever the pushback holds (revRC1: a copy of the pushback per mark made 3,000 macro-held authors take 3.7 GB).
MouthRuntime
NumberScan
RAII marker for a number/dimension/glue scan (see NUMBER_SCAN_DEPTH). Every ?-return and every unwind past a reader runs the drop, so the depth is back to what it was the moment the scan ends. The eTeX expression evaluator (etex.rs) takes one too, for its own inter-operand reads (etex.ch scan_expr treats a tab/row end the same).
NumberScanSuspended
The guard NumberScan::suspend returns: restores the suspended depth.
OperandRead
RAII marker for the read of a quantity’s operand head (READING_OPERAND): scan_optional_signs’s, and the eTeX expression’s factor (etex.ch scan_expr).
ReadBudget
What read_budget began; the budget is off once this is ended or dropped.
ReadBudgetEnd
What ReadBudget::end tells.
ScannerStatusGuard
Restores the enclosing ScannerStatus (and warning_index) when it drops, on every exit path of the scan that set it, ? included. The runaway argument (argument_runaway) is scoped the same way: a scan starts without one, and the enclosing scan’s comes back when it ends.
SpeculativeDigestion
A speculative digestion runs while this lives (speculative_digestion).

Enums§

BalancedBoundary
What a balanced read (read_balanced) does when it exhausts a mouth before the braces balance.
ExpansionLevel
A directive describing to what degree a gullet reader should perform TeX’s expansion
FileEndRecovery
What recover_at_file_end did.
Runaway
Why a macro call’s arguments are abandoned (argument_runaway).
ScannerStatus
What the scanner is reading, for the recovery TeX makes when a file ends in the middle of it: tex.web §305 scanner_status (with warning_index, the command it names). A scan that owns a status sets it for its duration with set_scanner_status and restores the enclosing one after, as tex.web saves and restores it (§389 macro_call, §473 scan_toks); every nested read that sets none inherits it. recover_at_file_end consults it.

Constants§

CYCLE_GUARD_ACTIVATE_GRAPHICS
Cycle-guard activation floor for graphics-heavy bindings (pgf/tikz/xy). These packages legitimately expand 100M+ tokens; this floor sits above the heaviest measured healthy graphics doc (1805.03265 tikz-cd ~155M) so they stay out of the per-token fingerprint regime, while remaining far below the 1G token_limit backstop. Raised — never lowered — per raise_cycle_guard_activate.
DEFAULT_TOKEN_LIMIT
The runaway-token BACKSTOP’s baseline: real runaways are cut far earlier by the cycle guards / pushback limit / byte budget, so erring high costs no detection latency. The heaviest measured legit arXiv paper is math0402448 (amsart + xy-pic, 80.2M end-of-run progress under the 2026-06-10 all-three-reader-loop accounting; the old “80M” figure predated that multi-counting) and the former 400M ceiling was 5× that — but the TeX Live doc corpus goes higher with NO loop: tikzlings-doc (scrartcl, ~250 raw-pgf animal pictures through tcolorbox listings, each box typeset twice) completes at a measured 444.5M (Debug:gullet:progress, 2026-09-01, 30 KB main source so the per-byte scaling never engaged), and finite O(n²) macro work goes further still: circularglyphs-sample (xstring \StrSubstitute ×34 over 600-char phrases, ~2.5G) and source2e (l3doc crossrefs over 46k codelines, ~2G) both COMPLETE under LATEXML_TOKEN_LIMIT=0 within the 300 s budget where Perl times out, yet died at the former 1G with a false “infinite loop?”. 4G; raised, never lowered (a genuine loop is still bounded — by this ceiling, by the --timeout wall clock, by the cycle guards, and by the RSS cap). LATEXML_TOKEN_LIMIT overrides (0 disables). Book-scale sources raise it proportionally per conversion — see scale_token_limit_to_source. 20e9 = the 300 s sweep wall at the measured 65 M tok/s ceiling: at 4e9 the backstop fired at 61 s on lie-hasse’s legitimate E8 poset figure (completes at ~8e9 in 124 s with a 304 KB picture; pdflatex 83 s) and mislabelled it “infinite loop” with a 39-byte XML. True loops are still bounded by the wall clock, the cycle guards and the RSS cap.
MAX_IN_OPEN
TeX’s limit on simultaneously open input files (\input files and \scantokens pseudo-files): max_in_open, texmf.cnf:868 (TL 2025; tex.web §328 begin_file_reading checks in_open = max_in_open before opening another).

Statics§

CSNAME_TRACE
Cached LATEXML_CSNAME_TRACE flag + the shared lookahead dump used by both csname-assembly error sites: reads up to 40 tokens, prints them, and puts them back (a counted-read/retracting-unread round trip — align ledger symmetric).
TRACE_GROUP_END
Cached snapshot of LXML_TRACE_GROUP_END env var, sampled exactly once per process. Inlining std::env::var(...) on the hot read_x_token path was triggering SIGSEGVs in __GI_getenv under concurrent test-thread execution: glibc’s getenv walks the process-global environ array unprotected, and the volume of concurrent calls (millions/sec across N threads) made the unsafe concurrent walks visible. The fix is to read the env var ONCE at static-init time; subsequent checks are a free atomic load.

Functions§

abandon_argument_at_par
Abandon the call at the \par just read into its argument (is_par_ending_argument): the readers stop, and abandon_runaway_call reports it and puts the \par back (tex.web §396).
abandon_runaway_call
Abandon the call of cs whose argument ran off the end of a file, given the runaway tokens it had read (ScannerStatusGuard::end_taking_runaway_argument).
argument_ran_off_a_file
recover_at_file_end for a reader of macro arguments only (a single token, a delimited argument; tex.web §392): whether the call is abandoned. At any other status such a reader keeps its own end-of-input behaviour.
argument_runaway
Whether a macro argument has run off the end of a file and the call is to be abandoned (see FileEndRecovery::Abandoned); readers stop at once.
at_end_of_all_input
Return a (balanced) sequence tokens until a match against one of the Tokens in @delims.
braced_length_evaluator
The braced-length evaluator, when the current document loaded calc.
calc_expressions_active
Whether the current document loaded calc, whose seams (set_internal_dimension_fn, set_braced_length_fn) are then in force.
close_mouth
consume_pushback_to
Consume the pushback down to its first len tokens, as a native reader’s answer does (with_pushback); braces among them must balance, since the brace ledger counts none of them, read or not.
count_reads
Count reads tokens as read, where a run’s reading is known without making it (the frontmatter’s rehearsal of a text it rehearsed before): progress stands where the run would leave it, its limits read again.
do_expand
Fully expand tokens and return the result, without digesting them.
do_expand_partially
As do_expand, but stopping at the first unexpandable token of each branch (ExpansionLevel::Partial) instead of expanding to the bitter end.
expand_as_csname_text
Fully expand tokens as the name inside a \csname…\endcsname (\ifincsname true), the way LaTeX reads a file name: \set@curr@file (latex.ltx) expands \input’s argument within \csname, so an active character guarded by \ifincsname keeps its literal form there (underscore-ltx.sty’s _, utf8.def’s octets).
expand_as_file_name
A file name as latex.ltx reads one (\set@curr@file, \@kernel@make@file@csname, latex.ltx:9654, :19745-19747): \@firstofone#1 strips the braces of a leading group (\include{{./x}} reads ./x.tex; 2406.05605), then the name is expanded within \csname (expand_as_csname_text).
expand_depth_left
How many more levels of expansion recursion the guard of read_x_token allows, usize::MAX if it is off.
expand_once_partial
Expand token, just read, ONE level if read_x_token(Some(false), ..) would expand it, pushing the expansion back onto the input, and report whether it did. A reader that must look at every token an expansion yields before expanding it further (the case changer’s l3text checks) steps with this; a token it leaves alone is still the caller’s to handle (unread it for read_x_token to return, stub or resolve).
field_cover_of
What the invocation of a token with field provenance prov (Token::prov) consumed of its field’s stored value, now that it read what it reads: its own position up to the next token of that value still to be read, if the pushback holds one (a primitive’s or a macro’s arguments: \hspace{1em}, \\[2pt], $x$), else its own position alone. The pushback only: a field’s stored tokens are read from it (an expansion, a digested argument), never from a mouth, so nothing is read or tokenized. OXIDIZED_DESIGN #715.
fix_token_limit
The front end’s explicit token limit (--token-limit): kept as given, as LATEXML_TOKEN_LIMIT is, where scale_token_limit_to_source would raise a limit below the source’s scaled one.
flush
Obscure, but the only way I can think of to End!! (see \bye or \end{document}) Flush all sources (close all pending mouth’s)
flush_mouth
This flushes a mouth so that it will be automatically closed, next time it’s read Corresponds to TeX’s \endinput
get_input_locator
\inputlineno‘s locator: the innermost TeX input level, past the token mouths an Expand opens (Perl’s are sourceless, Gullet.pm:150-156). \scantokens’ pseudo-file is a level that counts its own lines (eTeX’s pseudo_start sets line:=0, pdftex.web:38551), so it stops the walk though it reads no named source.
get_location
Comment-oriented location string, based on get_locator
get_location_opt
A message’s location (Error/Warn, error::location_line): the innermost mouth reading a named source, past the token lists a binding digests (digest()’s “Anonymous String”), as Perl’s getLocator walks past a sourceless mouth (Gullet.pm:150-162; \lx@empheq@box); else get_locator_opt’s; None where it finds no mouth (a --preloaded binding, the dump load), where Perl’s message has no at line (Error.pm:623) instead of Locator::default’s Rust file. A box’s locator stays get_locator_opt’s, which --source-map reads.
get_locator
Get the current location of input getting read
get_locator_from_start
get_locator’s accurate-start sibling (§1, docs/performance/SOURCE_PROVENANCE.md): same mouthstack walk, but reads the mouth’s get_locator_from_start (from = the last token’s captured start) instead of the heuristic from. Used for the construct-START snapshot at constructor digest under --source-map.
get_locator_opt
After Perl’s getLocator (Gullet.pm:150-162): the innermost mouth with a source, else the first mouth of the stack; None when there is neither (before the first mouth opens, or a sourceless one alone). Perl keeps the last mouth its walk examined, so a sourceless mouth alone reports its own String; line … and an all-sourceless stack ends on the outermost mouth; here the first case has no at line (the binding machinery’s mouth, not the document’s, is the only one open) and the second takes the innermost (front()), as before. Porting Perl’s walk exactly is a logged follow-up (row R RHAILOCWALK); only the message text differs.
get_pending_comment
get_source_location
The location of the innermost mouth that reads a source (not a token string, Anonymous String): where in the document a construct digested from a token list stands — \footnote{…}’s or \section{…}’s line, rather than nowhere.
gullet_root
has_more_input
Check if there is more input to be read from the current mouth
if_next
in_csname
True while a \csname…\endcsname name is being scanned.
in_speculative_digestion
Is a speculative digestion running (speculative_digestion)?
initialize_gullet
Initialize (or reset, if reentrant) a Gullet to its default empty state.
input_mark
Mark the input as it stands: everything still to be read now (input_unread_since). What is pushed back after the mark (a macro’s expansion, unread on top of the pushback) is read before anything the mark holds.
input_unread_since
Whether none of the input mark held has been read since it was taken (input_mark): its mouth is still open, has read no further, and its pushback still holds every token it held then (only what was pushed after the mark was read, or what a mouth opened since holds). Read-only, for an observer telling apart what a call’s expansion did from what the input after the call did (the frontmatter observer’s ledger, the title-page check’s document calls). The mouth’s watch tells how short its pushback has been since the mark (PushbackWatch): no shorter than the mark’s length, nothing it held was read; shorter by at most MARK_HELD tokens, those read were put back if the slots hold the very tokens they held (same_token: a peek leaves the input unread); shorter still, it was read. Tokens read below the mark and others pushed in their place read as read, though the token now at the mark’s last slot equals the one it held — IEEEtran’s \IEEEauthorblockN{…}⏎\IEEEauthorblockA{…}, whose line-end space was read with \IEEEauthorblockA and its argument and whose expansion, longer, put another space there: its affiliation calls read as the author block’s own and were lost by the frontmatter emitter (2401.11731, 1801.03314). No token is copied but the held ones: a mark costs at most one run of the watch, a test a binary search of its runs.
insert_par_at_extra_brace
A macro’s argument scan met a } (is_extra_brace_in_argument): “Argument of \x has an extra }”, the } put back, and the \par TeX inserts returned as the reader’s next token, the rest of the call read as a non-\long macro’s (tex.web §395 long_state:=call): a \par delimiter takes it, any other reader ends the call (§396).
is_column_end
Is token an alignment column end — a tab or a row end — and which one: the COLUMN_ENDS entry (the token to act on, its keyword, whether it is hidden), or (token, "align", false) for a tab.
is_extra_brace_in_argument
Whether token, read into a macro argument, is a } that ends the call (tex.web §392 cur_tok<right_brace_limit, §395): a right brace met while a macro’s arguments are read, delimited or not.
is_left_brace
tex.web’s cur_cmd=left_brace: a character of catcode 1, or a control sequence or active character \let to one (\bgroup).
is_par_ending_argument
Whether token, read into a macro argument, ends the call: tex.web §392/§399 cur_tok=par_token — the control sequence named par, whatever it means (a \noexpanded one too) — while a non-\long macro’s arguments are read.
is_right_brace
tex.web’s cur_cmd=right_brace (§1068 handle_right_brace): a character of catcode 2, or a control sequence or active character \let to one (\egroup). The closer that matches is_left_brace’s opener: under \catcode<=1 \catcode\>=2, \hbox<…> is a box (2606.11726’s plain-TeX macros), where Perl’s defined_as(T_END) knew only }.
is_space_or_implicit_space
Check if a token is a space token (catcode SPACE) or an “implicit space” (a CS or ACTIVE token \let to a space token). See TeXbook p269: <one optional space> absorbs both explicit and implicit spaces. (tex.web’s cur_cmd=spacer.)
isolated_input_ends_here
Whether the token just read ends an isolated reading context (reading_from_mouth: a token list digested on its own, such as a constructor’s argument {$x}, which may come wrapped in a further brace pair): only }s left in its pushback and its mouth exhausted. A } read here is the argument’s own closing brace, which TeX strips with the argument — one end of a construct digested as a unit (stomach.rs formula_ends_with_its_unit, OXIDIZED_DESIGN #553). false whenever a mouth of its own is still open in the context.
mark_everyeof_mouth
Mark the CURRENT mouth as an eTeX file level whose end inserts the \everyeof token list (see MouthRuntime::insert_everyeof). Every \input file mouth is marked (content.rs::load_tex_content), and so is the \scantokens pseudo-file (etex.rs).
mark_file_hooks_mouth
Mark the CURRENT mouth, a content file just opened, as one whose end runs \InputIfFileExists’ code after \@@input (latex.ltx:19670-19673), decided when the file ends as TeX reads it then (content::input_file_ended).
mouth_depth
The mouths open: the one in reading (Gullet::runtime) and those under it. open_mouth pushes nothing on the stack when none is in reading, so the stack alone doesn’t count them. A pushback_len compares only at one depth: a constructor digests its argument in a mouth of its own (a rehearsal’s notes, token::FieldNotesHook).
mouth_is_open
note_missing_argument
A required argument of spec whose reader ran out: at the true end of all input Perl’s “Missing argument” Error (Parameter.pm:93-97), the call then running on the reader’s empty value; an isolated mouth’s end stays quiet.
note_runaway_tokens
A reader stopping at a runaway argument puts in front of the runaway tokens the ones it had read itself, so that abandon_runaway_call sees the argument as it was read: a delimited reader’s text before a brace group that ran off, then the group’s own.
open_mouth
open_mouth_with
open_mouth, choosing how a balanced read treats the new mouth’s end.
operand_lookahead
The guards of a read ahead of a quantity’s operand that expands as the operand’s does: an assignment’s optional = (tex.web §405 scan_optional_equals), the by of \advance, \multiply and \divide (§1236 scan_keyword), whose first non-matching token is the operand’s. Only while OPERAND_VALUES holds values (the deposit).
peek_nonspace_remove
ltcmd’s \__cmd_peek_nonspace_remove:NTF (latex.ltx:4475-4482): whether the next token past spaces means target, peeked unexpanded; if so it goes with the spaces, else one explicit space per space taken goes back.
peek_token
Perl: peekToken — peek at the next token without triggering alignment Sets ALIGN_STATE to 1000000 to suppress alignment template handling (Perl line 331-337)
peek_upcoming_tokens
The tokens the current input holds next, without reading them: the pushback, next-read first, then the current mouth’s next max_lines source lines (at most max_chars characters of them, Mouth::peek_text) tokenized by a scratch mouth under the current catcodes as the iterator is drawn on, max_tokens in all. Nothing is read, expanded or moved, so a catcode change the look-ahead runs past still applies to the text when it is really read. Only the current mouth: the input levels outside it are not reached. The cost is bounded by the limits, not by the length of the line or of the pending expansion. A look-ahead for a decision about what follows (stomach.rs formula_continues_past_par, OXIDIZED_DESIGN #553).
pushback_holds_nonspace
Read the next raw line (string); primarily to read from the Mouth, but keep any unread input! Whether the gullet’s unread (pushed-back) tokens include a non-space token.
pushback_is_empty
Whether the input’s pushback is empty: no token of a field’s stored value is left to read (field_cover_of).
pushback_len
How many tokens the input’s pushback holds (with_pushback): a macro’s expansion is being read while it holds more than it did before the expansion (a rehearsal’s notes, token::FieldNotesHook).
pushback_text
The pending pushback as text, next-to-read first, left in place: what a raw line reader would take before the mouth’s line (see read_raw_line).
queue_sizes
Queue sizes (mouthstack, pending_comments) — pass-1 streaming telemetry.
raise_cycle_guard_activate
Raise the cycle-guard activation floor for the current (thread-local) gullet, only ever upward. Called from graphics package bindings (pgf/tikz/xy) whose healthy expansion runs to 100M+ tokens — see CYCLE_GUARD_ACTIVATE_GRAPHICS. Idempotent and order-independent: loading several graphics packages just re-asserts the same floor. The per-conversion reset (initialize_gullet) restores the default so the raise does not leak across documents.
read_arg
Read and return a “normal” TeX argument
read_arg_or_none
read_arg, or None when the input ran out before the argument (Perl readArg’s undef, Gullet.pm:735).
read_balanced
Approximates TeX’s scan_toks (but doesn’t parse \def parameter lists) and only optionally requires the openning “{”.
read_balanced_text
A balanced text: tex.web §473 scan_toks(false, xpand) (eTeX scan_general_text), read at absorbing status for the command being executed (\write, \uppercase, \detokenize, \toks=, the pdfTeX texts …). A file that ends inside it ends the text there (§339).
read_balanced_with_close
read_balanced that also hands back the CLOSE token that ended the group (None when the read ran out or found no opening brace). A delimited reader stores a matched group verbatim (tex.web §392-398 macro_call’s store_new_token(cur_tok) — the argument keeps the braces it was scanned with; the single-group outer-brace strip is §399-400, by catcode). Diverges from Perl’s canonical T_END (Gullet.pm:661/674), OXIDIZED_DESIGN_DIVERGENCES #224. chemfig scans (…) submols with (/) given catcodes 1/2 (chemfig.tex:1315-1324) and a canonical } in their place re-tokenized as a real end-brace in the next \scantokens, unbalancing it (chemexec/chemnum, sweep 74).
read_budget
A run of digestion’s limit on the tokens it reads, until ReadBudget::end: the read past it fails, and so does each one after, with an ErrorCategory::ReadBudget error that is logged nowhere and latches nothing, so whoever made the run ends it and the document goes on. The title-page check’s runs (latexml_engine sect05.rs speculative_run_read): a run’s cost is bounded whatever the document’s text does. The count is the one progress keeps; the token limit, the deadline and the cycle guard read theirs as before.
read_cs_name
read_cs_name_quiet
Quiet version of read_cs_name — used by \ifcsname. In TeX, \ifcsname silently skips non-expandable CS tokens and returns the constructed name without emitting errors (unlike \csname which DOES emit errors).
read_definition_body
A definition body: tex.web §473 scan_toks(true, xpand), read at defining status with its # parameters packed (\def, \edef, via the DefPlain/DefExpanded parameter types). A file that ends inside it ends the definition there (§339). TeX names the macro being defined; the body reader does not know it, so the report says “definition” alone.
read_delimited_balanced
The rest of an xparse o/O{}/r[]/D<> argument whose open was just read: up to the matching close, nested pairs and braced groups kept whole, as ltcmd’s delimited grab nests them (LaTeX’s \@ifnextchar[ stops at the first).
read_dimension
read_factor
Return a number (Rust f64 number)
read_float
====================================================================== Float, a floating point number. Similar to factor, but does NOT accept comma! This is NOT part of TeX, but is convenient.
read_glue
read_keyword
Match the input against a set of keywords; Similar to readMatch, but the keywords are strings, and Case and catcodes are ignored; additionally, leading spaces are skipped. AND, macros are expanded.
read_ltcmd_optional
ltcmd’s o argument (\__cmd_grab_D_aux:NNnNN, latex.ltx:3594-3651) of the command cs: […] past spaces, to the matching explicit ] (read_delimited_balanced), one brace pair around the whole of it stripped; Some(None) when absent. Read as the non-\long delimited macro ltcmd grabs it with (\cs_set_protected_nopar:Npn): a \par, a } or a file’s end in it ends the call, None, with TeX’s Error naming cs (tex.web §395-396, §338).
read_ltcmd_star
ltcmd’s s argument (\__cmd_grab_t:w, latex.ltx:3816): a * past spaces.
read_match
Match the input against one of the Token or Tokens in @choices; return the matching one or undef.
read_mu_dimension
read_mu_glue
read_mu_unit
read_next_conditional
reads and discards tokens, until it encounters a conditional, if any. Perl: skipConditionalBody inner loop (Conditional.pm L127-133) reads tokens directly from pushback/mouth (NOT through readToken) and manually tracks $LaTeXML::ALIGN_STATE for { and }. This loop does not call read_token either: its expansion and comment handling belong to digestion, and calling it from here once let pmatrix’s & get treated as the OUTER alignment’s column-end during \ifx.#1.\else…\fi skip when #1 contains \begin{pmatrix}…&…\end{pmatrix}. (REG-2 / math-ph0501074: the 9-line \nonumber+\lefteqn+\pmatrix repro.) It does take a column end at a zero count for the cell’s end, as tex.web’s pass_text does through get_next (§342) and Perl does not (KNOWN_PERL_ERRORS #1183).
read_non_blank_non_call
tex.web §406 “Get the next non-blank non-call token”: get_x_token, so a \protected macro expands too, past spaces and implicit spaces (cur_cmd=spacer); an undefined control sequence is reported by expand and discarded (§370), as in read_non_blank_non_relax. §577 scan_font_ident reads a font identifier with it.
read_non_blank_non_relax
tex.web §404 “Get the next non-blank non-relax non-call token”: expanded (a \protected macro too, as get_x_token expands it), past spaces and implicit spaces, \relax and \noexpanded tokens (relax, §358); an undefined control sequence is reported by expand and discarded (§370), as the csname reader does — the scan goes on, so \hbox\undefined{…} is still the box of {…}.
read_non_space
Read a single non-space token
read_normal_integer
read_number
read_optional
Read and return a LaTeX optional argument
read_optional_angled
The angle-bracket twin of read_optional.
read_optional_signs
read_primitive_token
Read a token as a primitive reads one: tex.web §365 get_token under the current ScannerStatus (\let, \futurelet, \afterassignment, \aftergroup, \expandafter, a Token parameter). An input level that ends here closes (§362 end_file_reading) and §336 check_outer_validity looks at the status:
read_raw_current_line_from_start
The current mouth line as raw text from column 0, DROPPING the pushback: for a reader that knows the pushback holds tokens probed off this very line (pushback_holds_nonspace), so the line comes back whole — with its indentation and any catcode-9 characters the probe’s tokenization lost.
read_raw_line
read_raw_line_decoded
read_raw_line from the current mouth with its input bytes decoded through the declared input encoding (Mouth::read_raw_line_decoded); the .bib reader’s and {verbatim}’s line source. Pending pushback is taken as read_raw_line takes it, and decoded with the rest of the line: a pushed-back active byte prints as its Latin-1 character (a {verbatim} wrapper whose optional-argument check peeked the body’s first character left a cp1251 first line as mojibake).
read_redefinable_token
The control sequence a definition names: tex.web §1215 get_r_token, repeat get_token until cur_tok<>space_token (\def, \let, \futurelet, \chardef, \countdef …). Each read is read_primitive_token, so a bare \let or \def as a file’s last token takes its name from the input after the file, skipping the spaces there.
read_register_value
read_register_value_coerce
Read a register value, optionally coercing from a compatible larger type. Perl: readRegisterValue($self, $type, $sign, $coerce) Coercion rules (from Perl %RegisterCoercionTypes): Number <- Dimension, Glue (extract raw i64) Dimension <- Glue (extract skip as Dimension) MuDimension <- MuGlue (extract skip as MuDimension)
read_required_arg
read_arg for a required parameter of type spec: input that ran out is note_missing_argument’s, and the call runs on the empty argument (Perl’s put-back, Parameter.pm:93-97; OD #304).
read_rubber
read_token
Gullet.pm readToken (L300-324); its loop is in read_token_after.
read_token_across_input_ends
Read a token as tex.web §367 \noexpand does: get_token under scanner_status := normal, so an input level that ends here closes without a runaway (§362 end_file_reading, §336 passes) and the read goes on in the enclosing level. Crosses exactly what read_x_token drains: autoclose mouths with a parent (\input files, \scantokens pseudo-files, line remainders), never a reading_from_mouth context. A definition, text, preamble or macro argument that runs off a file’s end is still a §338 runaway: read_token stops there, and the scan recovers by its ScannerStatus (recover_at_file_end). This is what \everyeof{\noexpand} relies on (catchfile.sty:251-261, morewrites.sty:465, l3build regression-test.tex:101). Guards: noexpand_input_ends::*.
read_token_required
Read a token that the calling macro/primitive REQUIRES, holding the “argument expected but input ended” diagnostic in one place.
read_tokens_value
The right-hand side of a token-list assignment, \toks<n>=…, \everypar=… (tex.web §1226-1227), after its optional =: the next non-blank non-\relax token, expanding (§404, get_x_token, which at a file’s end goes on in the enclosing input). A left brace, explicit or implicit (\toks0=\bgroup abc}), opens the balanced text, read at absorbing status (scan_toks(false, false), read_balanced_text); a token-list register or parameter gives its value. Any other token is the value itself, as in Perl (Gullet.pm:824-842 readTokensValue), after TeX’s error, “Missing { inserted” (§403 scan_left_brace; TeX then absorbs up to the next }). Perl reads the token unexpanded and recurses on an expandable one, so a \relax, an implicit brace or a file end before the text lost it: Paul Taylor’s diagrams.sty:15 \toks0=\bgroup} stored \bgroup, and its } closed a group (arXiv 2605.02221, 2605.25087). Guards: token_kernel_gaps::*.
read_unit
Read a unit, returning the exact TeX (num, den) conversion fraction (see convert_unit_ratio / numeric_ops::fixpoint_unit). Internal/coerced units (\wd0, \dimen, glue) yield (value_sp, 65536) — the floor(fix·v/65536) path of tex.web §8983, exact in integer arithmetic.
read_until
read_until_brace
reads until it encounters a Catcode::BEGIN token Note: Perl uses $$token[1] == CC_BEGIN (catcode check, not defined_as)
read_until_token
read_value
read_x_non_space
Read a single expanded, non-space, token
read_x_token
Read the next non-expandable token, expanding until one appears. Hot path — read_token is folded in. toplevel (default true): on mouth exhaustion, step to the containing mouth. fully_expand (default = toplevel): expand even protected defns (“for execution”). Unlike read_balanced, does NOT defer \the & friends; \noexpand’d tokens act like \relax. For \if/ \ifx arguments pass for_conditional=true (handles \noexpand and CS \let to tokens specially).
read_x_token_cell_head
The alignment’s cell-head peek, tex.web §785 align_peek and §791 (e-TeX get_x_or_protected): expand until the first token that is not expandable — or protected, as read_x_token(Some(true), false, Some(false)) stops — and stop as well at a macro whose optional argument is a \newcommand one (Parameter::testopt): LaTeX’s \newcommand\dg[3][] is \@protected@testopt\dg\\dg{}, whose expansion reaches the unexpandable \let of \kernel@ifnextchar before it reads an argument (latex.ltx:1249-1261), so TeX starts the cell there and the arguments are read inside it. Our macro reads its arguments as it expands; expanded in the peek it read the cell’s & before the cell existed (diagbox.sty:212 \newcommand\diagbox[3][], 2406.11917). The token is returned unexpanded: the cell’s own reader expands it. The binding closures that peek by \futurelet (Definition::peeks_by_futurelet, the kernel’s \@ifnextchar family) still expand here: several stand for a TeX macro whose head is not the peek (booktabs’ \cmidrule is \noalign{…\@ifnextchar[…}, booktabs.sty:166).
read_x_token_cell_head_stopping_at
read_x_token_cell_head, also stopping, unexpanded, at a token stop accepts (empheq’s left, which looks for a \multicolumn before it expands).
read_x_until
Convenience method wrapping around read_until — EOF degrades to empty (callers that need to distinguish use read_until directly). Expanding delimited scan: read tokens with full expansion up to (and consuming) until, copying brace groups unexpanded once opened. The XUntil: parameter type’s reader (Perl Parameters.pm XUntil, after PR #2767 “should only expand, not digest”: a bare token push is all that remains). A \noexpand’d token collected here reverts to its plain shadowed identity, as in read_balanced: TeX’s no_expand_flag is transient (tex.web §1149-1153), so a \protect\cs pair produced under \@unexpandable@protect is stored as the plain pair, not relax markers.
read_x_until_any
read_x_until up to the first of untils, returned with the text (None when the input ran out).
reading_context
The reading context tokens are read in now, as (serial, depth): the serial reading_from_mouth gives each isolated context (a constructor’s argument digested on its own; 0 for the document’s own input, \input files included), and how many such contexts are open. A \left records it (stomach.rs record_left_group_input), so that only the end of the input it was read in closes its group (OXIDIZED_DESIGN #530).
reading_document_text
Is the next token read straight from the document’s own text — nothing pushed back, the mouth a content file’s (Mouth::is_document_text)? A macro called now reads its arguments from what the document wrote (state::note_document_call).
reading_from_mouth
Do something, while reading tokens from a specific Mouth.
recover_at_file_end
A file has just ended under the current read: tex.web §362 closes it and calls §336 check_outer_validity, which, when the ScannerStatus is not normal, reports the runaway (§338 “File ended while scanning definition / use / preamble / text of \cs”) and inserts the tokens that should lead to recovery (§339).
reset_mouth_closed_errors
Forgets the mouth-closed errors counted: a predecessor that spent the budget (0906.1883) silenced the next paper’s first ten and made its first a Fatal.
restore_raw_line_rest
Give back the rest of the line a raw reader just read, as the current line of the input it came from, so the next token or raw line is read from it and then from the lines after — one TeX input line (\end{lstlisting} x \begin{lstlisting}: the second listing’s raw reader reads its body from the following lines, 2408.11865). False when tokens wait in front of it, which the line would then follow.
restore_token_limit
Restore the token limit and progress from a previous set_token_limit call.
retract_scanned_brace
back_input-style ledger retraction WITHOUT pushing anything: apply to tokens that were READ through a counting reader and are about to be RE-EMITTED as part of an expansion result (so they will be counted again when rescanned). tex.web §368: \expandafter saves its first token and back_inputs it (§325 retracts a scanned brace) around the one-step expansion, which enters as an unadjusted token list. A closure-style expandable that returns previously-read tokens inside its expansion must call this on that re-emitted portion, or every {/} passed through it is double-counted (l3’s \exp_after:wN { idiom drove the alignment ledger positive and & went stray — see unread_expansion).
retract_scanned_braces
scale_token_limit_to_source
Scale the runaway-token backstop to the SOURCE size — cumulatively, over every file the conversion opens. The DEFAULT_TOKEN_LIMIT baseline is sized for arXiv-scale inputs; a book-scale source legitimately expands past it (witness: a 131 MB flat-index compilation died at the then-400M ceiling mid-digestion with no loop in sight, at a measured ~3+ tokens/byte and paper-class documents measured up to ~160 tokens/byte; l3doc’s crossref pass over source2e’s .dtxs ~1000/byte). ×1000/byte keeps the ceiling finite — a true infinite loop still trips, and opens no new files while it spins — while never LOWERING the baseline for small documents. The bytes are summed over the main source AND everything it \inputs/\DocIncludes (every Mouth::open_file): source2e.tex is a 15 KB driver over ~40 .dtx files (~2 MB), so the driver-only sizing never engaged. An explicit LATEXML_TOKEN_LIMIT or --token-limit (fix_token_limit) wins unchanged (including 0 = disabled).
scan_left_brace
tex.web §403 scan_left_brace: the next non-blank non-relax token (read_non_blank_non_relax) is a { (is_left_brace); any other is put back with “Missing { inserted”, and the group is taken as begun.
scan_stops_at_futurelet_peek
TeX’s number scan stops at the unexpandable head of a peeking macro. latex.ltx’s \@ifnextchar (1756-1760), and with it \@ifstar, \@testopt and every \newcommand optional argument, opens with \let and peeks by \futurelet; the digits of a number scan end at the first unexpandable token (tex.web §445), so the peek happens only where the macro is executed. Our peeking macros are closures that peek as they expand: in a scan they stay unexpanded, the scan ends at them, and the next reader outside the scan (the main loop, an alignment’s cell-head peek) expands them. Expanding them in the scan read the chosen branch into the number (\count@=1\@ifstar{7}{5}* assigned 17), or its conditionals into a false branch’s skip: egpeirce.sty:184-189 \ifodd \the\value{cutdepth}% + \psset → \XKV@ifstar exposed \let\ifXKV@st\iffalse and the skip ran off the end of the document (egpeirce-doc, 51 errors; Perl shares the bug). Guards: cluster_package_guards::ifnextchar_scans.
scanner_status
The current ScannerStatus.
set_braced_length_fn
Install the braced-length evaluator and switch the calc seams on for the current document (calc.sty at load time).
set_internal_dimension_fn
Install the internal-dimension resolver (calc.sty at load time).
set_operand_values
Give the control sequences OPERAND_VALUES holds, returning the ones given before.
set_pushback_limit
Set the pushback limit (maximum pushback stack size before fatal error).
set_scanner_status
Enter a scan at status, naming warning_index (the command TeX’s runaway message names: the macro whose arguments are read, the primitive whose text is absorbed). tex.web saves and restores the status around such a scan; the returned guard does the restoring.
set_scanner_status_checking_par
set_scanner_status for a macro call’s arguments, with checks_par its macro’s crate::definition::expandable::Expandable::checks_par (tex.web §389 long_state).
set_token_limit
Set the token limit and reset progress. Returns previous (limit, progress) for restoration.
show_unexpected
Perl: showUnexpected — returns a debug message about the next available token
skip_filler
<filler> = <optional spaces> | <filler>\relax<optional spaces>
skip_one_space
Skip one optional space. If expanded is true, acts like <one optional space> and expands tokens (readXToken). Perl: skip1Space($self, $expanded)
skip_spaces
Discard any run of spaces at the head of the input — Perl Package.pm:SkipSpaces.
speculative_digestion
A run of digestion whose output and assignments are all discarded starts (latexml_engine sect05.rs speculative_run_read, the observer’s rehearsal, queue_digest::speculative_label_ink), until the guard drops: the document does not end in it. A \end{document}, \enddocument, \@@end or \bye it reads does nothing (flush, the kernel’s document end), whatever text brought it there: a stored argument, \closing{\end{document}}, ended the real document with the run otherwise, and took the whole body with it.
take_rest_of_mouth
Take everything still unread in the CURRENT mouth — its pushback, then the rest of its source — as raw tokens, leaving it exhausted. The enclosing input is untouched. This is how a braced argument hands back what followed the quantity scanned from it (crate::parameter::Parameters::reparse_argument): TeX leaves that tail in the input (\setlength#1#2{#1 #2\relax}, latex.ltx:10253). The tokens count as READ for the alignment brace ledger (as read_token counts them), so a caller that puts them back uses unread_vec, which retracts them again.
token_or_relax
A token argument, or \relax when the input ran out (after note_missing_argument): the no-op stand-in a primitive’s coercion accepts.
token_progress
How many tokens the gullet has read so far: at the end of a run, the telemetry basis for token_limit / CYCLE_GUARD_ACTIVATE; during one, the input a stretch of digestion consumed, for the stomach’s box-cycle guard (stomach.rs cycle_guard_record).
unread
Push the tokens back into the input stream to be re-read.
unread_after_current_file
Push tokens to be read where the innermost \input file (mark_everyeof_mouth) ends, in its enclosing level, after the file’s own end code (content::input_file_ended); false when no such file is open.
unread_expansion
Push EXPANSION OUTPUT (macro bodies, conditional-branch replays, \the results) to the start of the token stream WITHOUT touching the alignment brace ledger.
unread_one
Unreads a single Token to the start of the token stream. Perl: unread() always adjusts $ALIGN_STATE when unreading { or } tokens.
unread_substituted
unread_expansion of a macro body with its parameters substituted (Tokens::substitute_parameters), without building the list first: tex.web macro_call (§390) puts the body on the input as stored and the arguments where its out_params are. The pieces go onto the pushback stack last first, each reversed; args[n - 1] is parameter #n’s argument. The brace ledger is not touched, as for any expansion output.
unread_substituted_args
unread_substituted of arguments all read as tokens, each found where it is.
unread_vec
Unreads a Vec<Token> to the start of the token stream Perl: also adjusts ALIGN_STATE by retracting scanned braces (Gullet.pm lines 343-358). Correct ONLY for tokens that were previously READ (and hence counted) — for expansion output use unread_expansion (tex.web begin_token_list flavor, which adjusts nothing).
with_mouth_mut
Execute a function with a mutable reference to the current mouth
with_pushback
A look at the input’s pushback as it stands, the next token to read last; nothing is read, so nothing is tokenized or counted. For a native reader of what a macro’s own expansion put there (crate::definition::expandable::NativeCall).

Type Aliases§

BracedLengthFn
A package-installed evaluator for a braced LENGTH argument — calc.sty’s expression scanner. latex.ltx hands every user length to \setlength (\@hspace, \@imakebox, \@rule, \@iiiparbox, \@iiiminipage, array’s \@startpbox: latex.ltx:9425, 16099-16102, 16360-16366, 16249, 16305), and calc redefines \setlength to evaluate its whole argument as an expression (calc.sty:86, \calc@assign@skip → \calc@open(#4!, :51-53). A binding’s {Dimension}/{Glue} argument is that \setlength operand, so with calc loaded crate::parameter::Parameters::reparse_argument evaluates it here: \makebox[\widthof{ab}+\widthof{cd}] gets the sum, not the first term. The evaluator reads from the argument’s own mouth, leaving unread whatever calc could not parse (after reporting it, as calc.sty:281-284 does).
InternalDimensionFn
A package-installed resolver for control sequences that yield an internal dimension by reading their own argument — e.g. calc.sty’s \widthof{box}. Given the already-read CS token, it either consumes that CS’s argument(s) from the gullet and returns the measured value (Ok(Some(_))), or leaves the stream untouched and declines (Ok(None)), in which case the caller un-reads the token. Keeps core calc-agnostic: the base dimension reader consults this seam before giving up with “Missing number”, so \makebox[\widthof{X}] / \rule{\widthof{X}}{…} resolve like real LaTeX without \widthof having to be a register (which would change its bare digestion). See calc_sty.rs / OXIDIZED_DESIGN #115.