latexml/lib.rs
1//! latexml-oxide converts LaTeX documents into HTML5 with MathML, XML and EPUB 3: a Rust port of
2//! [LaTeXML](https://github.com/brucemiller/latexml). This crate, published as `latexml`, holds the command-line
3//! binaries `latexml_oxide` and `latexmlmath_oxide` and the library that drives a conversion. Its developer binaries
4//! (`genschema_oxide`, the audits, `cortex_worker`) install from a source checkout with `--features extended-install`.
5//!
6//! - [`api`]: the stable entry points, `convert_to_xml`, `convert_to_html` and `convert_to_html_with`.
7//! - [`converter::Converter`]: a full conversion with its own configuration (preloads, search paths, split, …).
8//! - [`post`]: the post-processing to HTML, XHTML or EPUB (Perl's `latexmlpost`).
9//! - [`format_dumps`]: the format dumps embedded in the binary or built once for the host TeX tree.
10//! - [`environment`] and [`intermediate_files`]: every environment variable read, and every file written.
11//!
12//! The engine is in `latexml_core` and `latexml_engine`, the bindings in `latexml_package` and `latexml_contrib`,
13//! the math parser in `latexml_math_parser` and the post-processors in `latexml_post`. Start with the
14//! [README](https://github.com/dginev/latexml-oxide/blob/main/README.md) and [USAGE.md](https://github.com/dginev/latexml-oxide/blob/main/docs/USAGE.md).
15
16// Macros (DefMacro!, load_model!, …) live in latexml_engine since the
17// extraction; latexml_package is a regular dep (its prelude is `use`d
18// from binding files, not macros).
19#[macro_use]
20extern crate latexml_engine;
21extern crate latexml_package;
22
23pub mod alloc_hook;
24pub mod api;
25// Every environment variable latexml-oxide reads or sets. The text is docs/ENVIRONMENT.md, copied beside this file so
26// the crate package (and docs.rs) has it; `cluster_cli::environment_doc` fails when the two differ.
27#[doc = include_str!("ENVIRONMENT.md")]
28pub mod environment {}
29// Every file a conversion writes besides its output. The text is docs/INTERMEDIATE_FILES.md, copied beside this
30// file for the crate package; `cluster_cli::intermediate_files_doc` fails when the two differ.
31#[doc = include_str!("INTERMEDIATE_FILES.md")]
32pub mod intermediate_files {}
33pub mod bib_session;
34#[cfg(feature = "test-utils")]
35pub mod conformance;
36pub mod converter;
37pub mod core_interface;
38pub mod format_dumps;
39pub mod heap_trim;
40pub mod identity;
41pub mod ini_tex;
42pub mod lsp_server;
43pub mod main_tex;
44pub mod multidoc;
45pub mod post;
46pub mod render_workers;
47pub mod source_date;
48pub mod streaming_restart;
49pub mod util;
50
51/// Load the embedded LaTeXML schema (compile-time) into the runtime
52/// `MODEL`. Single home for the `load_model!("LaTeXML")` macro
53/// expansion — the macro generates a fresh `_ModelLoader::build_model`
54/// at each call site (~600 KiB of `.text` per copy), so funnelling
55/// all callers through this one function lets LTO keep exactly one
56/// instance in the final binary. Mirrors Perl
57/// `LaTeXML::Common::Model::compileSchema` (Model.pm L121-136).
58// The generated loader builds the whole schema in one frame (opt-level 0); it runs once per process at start-up. Splitting
59// it per element in the `load_model!` proc macro is a post-merge refactor. (A nightly clippy lint, hence `unknown_lints`.)
60#[allow(unknown_lints, clippy::large_unopt_stack_frames)]
61pub fn load_latexml_default_model() {
62 use latexml_codegen::LoadModel;
63 load_model!("LaTeXML");
64}
65
66/// Load the embedded LaTeXML schema and return its compiled-model
67/// serialisation in the `.model` plain-text format. Used by
68/// `tools/compileschema.sh` stage 2 (and the `--dump-model` flag on
69/// the `latexml_oxide` binary) to regenerate `LaTeXML.model` from the
70/// same source the runtime sees.
71pub fn dump_compiled_latexml_model() -> String {
72 load_latexml_default_model();
73 latexml_core::common::model::MODEL
74 .borrow()
75 .dump_compiled_schema()
76}