retex_engine/lib.rs
1//! The retex TeX engine: a clean-room implementation of LuaTeX's
2//! typesetting machine.
3//!
4//! The [`Engine`] holds all state of a TeX run. Its methods are spread
5//! over modules following the parts of *TeX: The Program*:
6//!
7//! * [`print`] and [`error`] — terminal and log output, error recovery;
8//! * [`hash`], [`eqtb`], [`save`] — control sequences, equivalents, grouping;
9//! * [`input`] — the input stack and the tokenizer (`get_next`);
10//! * [`expand`], [`cond`], [`scan`] — expansion, conditionals, scanning;
11//! * [`prefixed`] — assignments;
12//! * [`maincontrol`] — the chief executive.
13
14#![forbid(unsafe_code)]
15#![allow(clippy::too_many_lines)]
16
17pub mod align;
18pub mod backend;
19mod boxnote;
20pub mod build;
21pub mod clock;
22pub mod cmd;
23mod cmd_gen;
24pub mod codes;
25pub mod cond;
26pub mod describe;
27pub mod diag;
28pub mod dirs;
29pub mod display;
30pub mod dvi;
31pub mod eqtb;
32pub mod error;
33pub mod expand;
34pub mod expansion;
35pub mod files;
36pub mod fingerprint;
37pub mod fonts;
38pub mod format;
39pub mod glue;
40pub mod hash;
41pub mod hmode;
42pub mod hyph;
43pub mod image;
44pub mod init;
45pub mod input;
46pub mod linebreak;
47pub mod maincontrol;
48pub mod math;
49pub mod mathdisplay;
50pub mod mathparams;
51pub mod meaning;
52pub mod misc;
53pub mod mlist;
54pub mod native;
55pub mod nodeproc;
56pub mod nodes;
57pub mod pack;
58pub mod page;
59pub mod pagenote;
60pub mod pdfext;
61pub(crate) mod pdfship;
62pub mod prefixed;
63pub mod primitives;
64pub mod primitives_gen;
65pub mod print;
66pub mod profile;
67pub mod protrusion;
68pub mod save;
69pub mod scan;
70pub mod shipout;
71pub mod showbox;
72pub mod snapshot;
73pub mod synctex;
74pub mod the;
75pub mod timing;
76pub mod token;
77pub mod typeset;
78pub mod utf8x;
79
80use cmd::Cmd;
81use cond::CondState;
82use eqtb::Eqtb;
83use error::ErrorState;
84use files::FileState;
85use hash::{CsId, CsTable};
86use input::InputState;
87use print::Printer;
88use save::SaveStack;
89use token::Token;
90
91/// Callbacks from the engine into an embedded Lua interpreter.
92///
93/// The engine does not depend on Lua. `\directlua` and related primitives
94/// call this trait, which `retex-lua` implements. The host is shared
95/// (`Rc`), so nested calls (Lua → TeX → Lua) reach it too.
96pub trait LuaHost {
97 /// Runs a chunk of Lua code for `\directlua` (or `\latelua`, etc.).
98 /// `name` is the chunk name. Text printed with `tex.print` must be
99 /// pushed back into the engine's input by the host.
100 fn run(&self, engine: &mut Engine, name: &str, code: &[u8]) -> Result<(), String>;
101
102 /// Calls the registered Lua function `n` (`\luafunction n`) with its
103 /// number, like [`run`](Self::run) runs a chunk; `None` if there is
104 /// no such function.
105 fn call_function(&self, _engine: &mut Engine, _n: i32) -> Option<Result<(), String>> {
106 None
107 }
108
109 /// Sets entries of expl3's intarrays (l3intarray under LuaTeX keeps
110 /// them in Lua tables), as `\__intarray_gset:w` does: for each
111 /// `(array, first, values)`, entry `first + k` of the array numbered
112 /// `array` (`\__intarray:w <array>`) gets `values[k]`. `gset` is the
113 /// `\luafunction` number of `\__intarray_gset:w`, through which the
114 /// arrays are found. `false`, with nothing changed, when the arrays
115 /// are not reachable natively.
116 fn intarray_set(&self, _gset: i32, _writes: &[(i64, i64, &[i64])]) -> bool {
117 false
118 }
119
120 /// Data to store in the format file (e.g. `lua.bytecode`).
121 fn dump(&self, _engine: &mut Engine) -> Vec<u8> {
122 Vec::new()
123 }
124
125 /// Restores data stored by [`dump`](Self::dump).
126 fn undump(&self, _engine: &mut Engine, _data: &[u8]) -> Result<(), String> {
127 Ok(())
128 }
129
130 /// Calls callback `name` without arguments, ignoring its results
131 /// (`pre_dump`, `stop_run`, …). Does nothing if none is registered.
132 fn call_simple(&self, _engine: &mut Engine, _name: &str) -> Result<(), String> {
133 Ok(())
134 }
135
136 /// Calls callback `name` with one string argument, ignoring its
137 /// results (`buildpage_filter`, `contribute_filter`).
138 fn call_with_string(
139 &self,
140 _engine: &mut Engine,
141 _name: &str,
142 _arg: &str,
143 ) -> Result<(), String> {
144 Ok(())
145 }
146
147 /// Whether a Lua function is registered for callback `name`.
148 fn has_callback(&self, _name: &str) -> bool {
149 false
150 }
151
152 /// Calls the `define_font` callback. Returns the id of the font it
153 /// defined, or `None` if the font could not be loaded.
154 fn define_font(&self, _engine: &mut Engine, _name: &[u8], _size: i32) -> Option<u32> {
155 None
156 }
157
158 /// Calls a node-list filter callback (`pre_linebreak_filter`,
159 /// `hpack_filter`, `post_linebreak_filter`, …) on the list starting at
160 /// `head`. Returns the new head; [`ListFilter::Flush`] means the list
161 /// must be discarded.
162 fn list_filter(
163 &self,
164 _engine: &mut Engine,
165 _callback: &str,
166 head: nodes::NodeRef,
167 _group: &str,
168 ) -> ListFilter {
169 ListFilter::Keep(head)
170 }
171
172 /// Calls the `hpack_quality` or `vpack_quality` callback `cb` for box
173 /// `b` with `incident` (overfull, underfull, loose, tight) and its
174 /// detail; returns the node the callback gave (null if none).
175 #[allow(clippy::too_many_arguments)]
176 fn pack_quality(
177 &self,
178 _engine: &mut Engine,
179 _cb: &str,
180 _incident: &str,
181 _detail: i32,
182 _b: nodes::NodeRef,
183 _first: i32,
184 _last: i32,
185 ) -> nodes::NodeRef {
186 nodes::NodeRef::NULL
187 }
188
189 /// Runs the `hyphenate`, `ligaturing` or `kerning` callback `cb` on
190 /// the list after `head` (a temporary node), with its last node:
191 /// `true` if a function or `false` is registered, which replaces the
192 /// built-in pass.
193 fn node_pass(&self, _engine: &mut Engine, _cb: &str, _head: nodes::NodeRef) -> bool {
194 false
195 }
196
197 /// Calls the `linebreak_filter` callback on paragraph `head`
198 /// (`display`: a display follows): `Some(list)` if it returned a node
199 /// list, which replaces line breaking; `None` otherwise.
200 fn linebreak_filter(
201 &self,
202 _engine: &mut Engine,
203 _head: nodes::NodeRef,
204 _display: bool,
205 ) -> Option<nodes::NodeRef> {
206 None
207 }
208
209 /// Calls the `mlist_to_hlist` callback on math list `head` in style
210 /// `style` (0–7); `None` if the callback failed or none is set.
211 fn mlist_to_hlist(
212 &self,
213 _engine: &mut Engine,
214 _head: nodes::NodeRef,
215 _style: i32,
216 _penalties: bool,
217 ) -> Option<nodes::NodeRef> {
218 None
219 }
220
221 /// Runs shell command `cmd` under the shell escape rules (as Lua's
222 /// `io.popen` does) and returns its output; `None` if it may not run.
223 fn pipe_read(&self, _engine: &mut Engine, _cmd: &[u8]) -> Option<Vec<u8>> {
224 None
225 }
226
227 /// Calls the `input_level_string` callback with input-stack depth `n`;
228 /// `None` if it returned no string.
229 fn input_level_string(&self, _engine: &mut Engine, _n: i64) -> Option<Vec<u8>> {
230 None
231 }
232
233 /// Calls the `glyph_info` callback for glyph node `p`: `Some(text)` is
234 /// what to print, `None` means the callback returned no string.
235 fn glyph_info(&self, _engine: &mut Engine, _p: nodes::NodeRef) -> Option<Vec<u8>> {
236 None
237 }
238
239 /// Runs the Lua value kept under reference number `reference` (see
240 /// [`nodes::LuaRefs`]) at shipout: a function is called with `args`,
241 /// a string is run as Lua code. For the `lua` commands of virtual
242 /// characters and `\latelua` functions.
243 fn call_reference(
244 &self,
245 _engine: &mut Engine,
246 _reference: i32,
247 _args: ReferenceArgs,
248 ) -> Result<(), String> {
249 Ok(())
250 }
251}
252
253/// The arguments of a Lua function called at shipout (see
254/// [`LuaHost::call_reference`]).
255#[derive(Clone, Copy, Debug, PartialEq, Eq)]
256pub enum ReferenceArgs {
257 /// A virtual character's `lua` command: the font id and the
258 /// character.
259 Glyph(u32, u32),
260 /// A `\latelua` function: the whatsit (as a node userdata).
261 Node(nodes::NodeRef),
262}
263
264/// Result of a node-list filter callback.
265#[derive(Clone, Copy, Debug, PartialEq, Eq)]
266pub enum ListFilter {
267 /// Continue with this list (possibly the original head).
268 Keep(nodes::NodeRef),
269 /// The callback returned `false`: discard the list.
270 Flush,
271}
272
273impl Engine {
274 /// Whether the Lua callback `name` is set.
275 pub fn has_callback(&self, name: &str) -> bool {
276 self.lua.as_ref().is_some_and(|h| h.has_callback(name))
277 }
278
279 /// Calls the notification callback `name` (`buildpage_filter`,
280 /// `contribute_filter`) with `info`, if one is set.
281 pub fn notify_callback(&mut self, name: &str, info: &str) {
282 if let Some(h) = self.lua.clone()
283 && h.has_callback(name)
284 && let Err(e) = h.call_with_string(self, name, info)
285 {
286 self.lua_error(&e);
287 }
288 }
289
290 /// Calls `buildpage_filter` with `info` (where the page builder was
291 /// called from, observed), then builds the page.
292 pub fn build_page_from(&mut self, info: &str) {
293 self.notify_callback("buildpage_filter", info);
294 self.build_page();
295 }
296
297 /// Runs a node-list filter callback if one is registered (the hook
298 /// typesetting code calls at LuaTeX's callback points).
299 pub fn run_list_filter(
300 &mut self,
301 callback: &str,
302 head: nodes::NodeRef,
303 group: &str,
304 ) -> ListFilter {
305 match self.lua.clone() {
306 Some(h) if h.has_callback(callback) => h.list_filter(self, callback, head, group),
307 _ => ListFilter::Keep(head),
308 }
309 }
310}
311
312impl Engine {
313 /// Converts a finished formula's math list into an hlist, through the
314 /// `mlist_to_hlist` callback when one is set (LuaTeX calls it for the
315 /// outermost list of each formula and equation number; observed: not
316 /// for an empty one).
317 pub fn formula_to_hlist(
318 &mut self,
319 head: nodes::NodeRef,
320 style: i32,
321 penalties: bool,
322 ) -> nodes::NodeRef {
323 if head.is_null() {
324 return nodes::NodeRef::NULL;
325 }
326 if let Some(h) = self.lua.clone()
327 && h.has_callback("mlist_to_hlist")
328 {
329 if let Some(r) = h.mlist_to_hlist(self, head, style, penalties) {
330 if !r.is_null() {
331 self.nodes.set_prev(r, nodes::NodeRef::NULL);
332 }
333 return r;
334 }
335 return nodes::NodeRef::NULL;
336 }
337 self.mlist_to_hlist(head, style, penalties)
338 }
339
340 /// Prints the input level before a line of macro tracing through the
341 /// `input_level_string` callback (LaTeX's `\tracingstacklevels`);
342 /// returns false if no callback is set. A newline in the string ends
343 /// the line.
344 pub fn print_input_level(&mut self) -> bool {
345 let Some(h) = self.lua.clone() else {
346 return false;
347 };
348 if !h.has_callback("input_level_string") {
349 return false;
350 }
351 let n = self.input.stack.len().saturating_sub(1) as i64;
352 if let Some(s) = h.input_level_string(self, n) {
353 for (i, part) in s.split(|&b| b == b'\n').enumerate() {
354 if i > 0 {
355 self.printer.print_ln();
356 }
357 self.printer.print_bytes(part);
358 }
359 }
360 true
361 }
362
363 /// Runs the `glyph_info` callback for glyph `p` when one is set:
364 /// `None` without a callback, `Some(None)` when it returned no string.
365 pub fn run_glyph_info(&mut self, p: nodes::NodeRef) -> Option<Option<Vec<u8>>> {
366 match self.lua.clone() {
367 Some(h) if h.has_callback("glyph_info") => Some(h.glyph_info(self, p)),
368 _ => None,
369 }
370 }
371}
372
373/// A one-shot callback into the host, run with the engine borrowed.
374pub type EngineHook = Box<dyn FnOnce(&mut Engine)>;
375
376/// Shows diagnostics before the terminal is read (see
377/// [`Engine::prompt_hook`]).
378pub type PromptHook = Box<dyn FnMut(&[diag::Diagnostic], &str) -> bool>;
379
380/// The global state of a TeX run.
381pub struct Engine {
382 /// Control-sequence names.
383 pub hash: CsTable,
384 /// The table of equivalents.
385 pub eqtb: Eqtb,
386 /// The save stack and grouping state.
387 pub save: SaveStack,
388 /// The input stack.
389 pub input: InputState,
390 /// Terminal, log and `\write` output.
391 pub printer: Printer,
392 /// Error-handling state.
393 pub err: ErrorState,
394 /// Conditionals.
395 pub cond: CondState,
396 /// Files: `\openin`/`\read`, `\openout`, input file stack.
397 pub files: FileState,
398 /// The file finder.
399 pub kpse: Option<retex_kpath::Shared>,
400 /// The Lua interpreter, when available.
401 pub lua: Option<std::rc::Rc<dyn LuaHost>>,
402
403 /// The current command code (`cur_cmd`).
404 pub cur_cmd: Cmd,
405 /// The current modifier (`cur_chr`).
406 pub cur_chr: u32,
407 /// The current control sequence (`cur_cs`); [`hash::NO_CS`] for
408 /// characters.
409 pub cur_cs: CsId,
410 /// The current token (`cur_tok`).
411 pub cur_tok: Token,
412
413 /// The value most recently scanned (`cur_val`).
414 pub cur_val: i32,
415 /// The glue most recently scanned, when `cur_val_level` is glue.
416 pub cur_glue: glue::Glue,
417 /// The token list most recently scanned, when `cur_val_level` is tokens.
418 pub cur_toks: Option<token::TokenList>,
419 /// The level of `cur_val`.
420 pub cur_val_level: scan::ValLevel,
421
422 /// Well-known control sequences.
423 pub cs: init::KnownCs,
424 /// Whether the run is in IniTeX mode.
425 pub ini_version: bool,
426 /// Shell escape mode (see [`init::Options::shell_escape`]).
427 pub shell_escape: u8,
428 /// The format identification printed in the banner.
429 pub format_ident: String,
430 /// The job name, once known.
431 pub job_name: Option<Vec<u8>>,
432 /// Token saved by `\afterassignment` (`after_token`).
433 pub after_token: Token,
434 /// Number of nested expansions (LuaTeX's `expand_depth_count`).
435 pub expand_depth: u32,
436 /// The current mode (copy of the innermost nest level's mode).
437 pub mode: maincontrol::Mode,
438 /// The mode last shown by `show_cur_cmd_chr`.
439 pub shown_mode: maincontrol::Mode,
440 /// The format name (`\formatname`).
441 pub format_name: String,
442 /// Math as LuaTeX 1.24 (TeX Live 2026) typesets it, chosen for formats
443 /// of LaTeX 2026-06 and later (see [`Engine::load_format`]); else
444 /// LuaTeX 1.22 (TeX Live 2025), the version retex reports.
445 pub math_124: bool,
446 /// Building an operator's character nucleus, which gets no italic
447 /// correction in OpenType math (LuaTeX 1.24 as 1.22).
448 pub math_op_nucleus: bool,
449 /// Node memory.
450 pub nodes: nodes::Nodes,
451 /// The semantic nest; the last entry is the current list.
452 pub nest: Vec<maincontrol::ListState>,
453 /// Loaded fonts.
454 pub fonts: fonts::FontTable,
455 /// The `long_state` of the macro being called.
456 pub long_state: Cmd,
457 /// The control sequence being defined (for diagnostics).
458 pub def_ref_cs: CsId,
459 /// The partial token list printed by `runaway`.
460 pub runaway_list: Vec<Token>,
461 /// The control sequence last made by `\csname` (`\lastnamedcs`).
462 pub last_cs_name: CsId,
463 /// Frozen copies made by `\primitive`.
464 pub frozen_prims: std::collections::HashMap<Vec<u8>, CsId>,
465 /// Mark texts.
466 pub marks: typeset::Marks,
467 /// Set when a `\read` line has been consumed.
468 pub input_read_finished: bool,
469 /// Whether the long `\errmessage` help has been shown.
470 pub long_help_seen: bool,
471 /// `\deadcycles`.
472 pub dead_cycles: i32,
473 /// `\insertpenalties`.
474 pub insert_penalties: i32,
475 /// `\badness`.
476 pub last_badness: i32,
477 /// Token lists show a macro parameter character once, not doubled
478 /// (`\luaescapestring`).
479 pub single_mac_param: bool,
480 /// The direction the next box made by `hpack` or `vpackage` gets
481 /// (from `dir`/`bdir` of a box specification), or -1. It is set before
482 /// packing because over- and underfull box reports show it.
483 pub pack_dir: i8,
484 /// `\randomseed`: the seed `\setrandomseed` last gave (its absolute
485 /// value), or the one chosen at startup.
486 pub random_seed: i32,
487 /// The state of the random number generator (METAFONT's, see
488 /// [`retex_arith::random`]) behind `\uniformdeviate`, `\normaldeviate`
489 /// and the `tex` library's randomizers.
490 pub randoms: retex_arith::random::Randoms,
491 /// `\lastxpos`.
492 pub last_x_pos: i32,
493 /// `\lastypos`.
494 pub last_y_pos: i32,
495 /// The magnification frozen by `prepare_mag`.
496 pub mag_set: i32,
497 /// The font dimension located by `find_font_dimen`.
498 pub font_dimen_loc: Option<(u32, u32)>,
499 /// `\showboxdepth` in effect while displaying boxes.
500 pub depth_threshold: i32,
501 /// `\showboxbreadth` in effect while displaying boxes.
502 pub breadth_max: i32,
503 /// The paragraph-ending control sequence (`\partokenname`).
504 pub par_token_cs: CsId,
505 /// Whether `\dump` ended the run.
506 pub dump_requested: bool,
507 /// Whether a macro expanded now would have its body executed by main
508 /// control (see [`native`]).
509 pub exec_context: bool,
510 /// Whether the next [`expand`](Engine::expand) is a single expansion
511 /// step whose result is not expanded further (`\expandafter`, `\span`
512 /// in a preamble, Lua's `token.expand`): expandable native
513 /// implementations do not run there (see [`native`]). `expand` clears
514 /// it on entry.
515 pub one_step: bool,
516 /// Where macros are defined (`retex profile`, `retex explain`).
517 pub origins: Option<Box<profile::Origins>>,
518 /// The sampling profiler (`retex profile`).
519 pub profiler: Option<Box<profile::Profiler>>,
520 /// Integer parameters set from the command line when the job starts
521 /// ([`init::Options::int_params`]).
522 pub start_ints: Vec<(u32, i32)>,
523 /// `-output-comment`.
524 pub output_comment: Option<String>,
525 /// The job's start time (`\time`, the banner, the PDF creation date).
526 pub start_time: clock::StartTime,
527 /// The page builder.
528 pub page: typeset::PageState,
529 /// Lua functions registered for `\luafunction` (by number).
530 pub lua_functions: std::collections::HashMap<i32, u32>,
531 /// Called to store the format when `\dump` is executed.
532 pub format_hook: Option<EngineHook>,
533 /// Called at the end of the run to finish output files.
534 pub finish_hook: Option<EngineHook>,
535 /// Non-immediate `\write`s waiting for shipout.
536 pub deferred_writes: Vec<(i32, token::TokenList)>,
537 /// Text directions opened in the current box: (group level,
538 /// direction, the text direction before), innermost last (see
539 /// [`dirs`]).
540 pub text_dirs: Vec<(u16, i8, i8)>,
541 /// Box resources to write after the page or form being written, one
542 /// list per open page or form.
543 pub pending_forms: Vec<Vec<u32>>,
544 /// The packets of virtual characters whose `lua` command is running,
545 /// innermost last: what the `vf` library draws into.
546 pub(crate) vf_frames: Vec<shipout::VfFrame>,
547 /// Objects referred to (`\pdfextension refobj`) in the box resources
548 /// being written, one list per open form.
549 pub form_objects: Vec<Vec<pdfext::PdfObject>>,
550 /// The `text_dirs` of the enclosing boxes.
551 pub outer_text_dirs: Vec<Vec<(u16, i8, i8)>>,
552 /// The math and text directions outside the open formulas, with the
553 /// save level of each formula's group.
554 pub outer_math_dirs: Vec<(u16, i32, i32)>,
555 /// Contents of files written by `\write`, for the pass driver.
556 pub written_sink: files::WrittenSink,
557 /// State of the typesetting routines.
558 pub ts: typeset::TsState,
559 /// Tokens printed from Lua waiting to be pushed as a token list.
560 pub pending_lua_tokens: Option<Vec<Token>>,
561 /// Default output mode: errors and warnings recorded for the driver
562 /// (`None` in compatibility mode).
563 pub diagnostics: Option<Vec<diag::Diagnostic>>,
564 /// Default output mode, interactive: shows the diagnostics recorded
565 /// since the last prompt, and the prompt, before the terminal is read.
566 /// Returns `false` if it showed nothing (the error only repeats one
567 /// already reported): TeX then goes on without asking.
568 pub prompt_hook: Option<PromptHook>,
569 /// Default output mode: called when a page is shipped or a file opened,
570 /// to show progress and the errors recorded so far.
571 pub progress_hook: Option<fn(&mut Engine)>,
572 /// The number of diagnostics the prompt hook has shown.
573 pub diagnostics_shown: usize,
574 /// Whether the terminal was read (an error or a `\read` prompt).
575 pub prompted: bool,
576 /// Image resources (`\saveimageresource`), in the order saved (their
577 /// indices are their object numbers).
578 pub images: Vec<image::ImageResource>,
579 /// `\lastsavedimageresourceindex`.
580 pub last_image_index: i32,
581 /// `\lastsavedimageresourcepages`.
582 pub last_image_pages: i32,
583 /// Whether SVG text has been given its font finder.
584 pub svg_fonts_set: bool,
585 /// Box resources (`\saveboxresource`), in the order saved (their
586 /// indices are their object numbers).
587 pub box_resources: Vec<image::BoxResource>,
588 /// `\lastsavedboxresourceindex`.
589 pub last_box_index: i32,
590 /// Scratch buffer for macro arguments (reused by `macro_call`).
591 pub arg_scratch: Vec<Token>,
592 /// Scratch buffer for the argument list of a macro call.
593 pub param_scratch: Vec<token::TokenList>,
594 /// The file of each `\write` stream opened (see [`snapshot`]).
595 pub write_paths: Vec<Option<std::path::PathBuf>>,
596 /// The macro at whose expansion [`snapshot_hook`](Self::snapshot_hook)
597 /// runs (LaTeX's `\document`).
598 pub snapshot_cs: Option<CsId>,
599 /// Called once, when `snapshot_cs` is expanded (see [`snapshot`]).
600 pub snapshot_hook: Option<snapshot::Hook>,
601 /// Called after each page is shipped out, to take a page checkpoint,
602 /// and once when the document has begun (see [`snapshot`]).
603 pub page_hook: Option<fn(&mut Engine)>,
604 /// Called when the run is over, before the output file is finished
605 /// (see [`snapshot`]).
606 pub final_hook: Option<fn(&mut Engine)>,
607 /// The input level of the file `\begin{document}` was read from: the
608 /// page hook runs before its next line is read.
609 pub(crate) begun_level: Option<usize>,
610 /// Hashes of the code-table pages and macros that existed when
611 /// fingerprints were prepared (see [`fingerprint`]).
612 pub fp_cache: Option<Box<fingerprint::FpCache>>,
613 /// The file and line the user asked to edit at an error (`E`); the
614 /// program runs the editor at the end.
615 pub edit_request: Option<(Vec<u8>, i32)>,
616 /// The output file written at the end: name, pages and bytes.
617 pub output_written: Option<(String, u32, u64)>,
618 /// The line number reported while reading Lua output.
619 pub input_line_for_lua: i32,
620 /// Internal tokens made by `\pdfvariable`, by variable name.
621 pub backend_cs: std::collections::HashMap<&'static str, CsId>,
622 /// Nesting depth of local control loops (`tex.runtoks`).
623 pub local_level: u32,
624 /// The box `token.scan_list` scanned, once finished.
625 pub lua_scanned_box: Option<nodes::NodeRef>,
626 /// Whether `token.scan_list` runs local control for its box.
627 pub lua_scan_waiting: bool,
628 /// The output backend (PDF writer), if any.
629 pub backend: Option<Box<dyn shipout::Backend>>,
630 /// The DVI writer (`\outputmode=0`).
631 pub dvi: dvi::DviWriter,
632 /// Hyphenation languages, by `\language` number.
633 pub languages: Vec<Option<retex_hyph::Language>>,
634 /// Document-level PDF data from `\pdfextension`.
635 pub pdf: pdfext::PdfState,
636 /// Current values of the colour stacks during shipout.
637 pub colorstack_values: std::collections::HashMap<i32, Vec<Vec<u8>>>,
638 /// Number of pages shipped out.
639 pub total_pages: u32,
640 /// Muglue values of `\Umath…` spacing parameters.
641 pub math_glues: Vec<glue::Glue>,
642 /// Whether the parameters set by the first formula are initialized
643 /// (see [`mathparams`]).
644 pub math_params_initialized: bool,
645 /// SyncTeX output.
646 pub synctex: synctex::Synctex,
647}
648
649impl std::fmt::Debug for Engine {
650 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
651 f.debug_struct("Engine")
652 .field("cur_cmd", &self.cur_cmd)
653 .field("cur_chr", &self.cur_chr)
654 .finish_non_exhaustive()
655 }
656}