Expand description
Stable, high-level conversion API for using latexml as a library.
Downstream Rust crates depend on latexml and call one function — no
binary, no manual Config or
binding-dispatch wiring:
let xml = latexml::api::convert_to_xml(r"\documentclass{article}\begin{document}Hi\end{document}")?;
let html = latexml::api::convert_to_html(r"\documentclass{article}\begin{document}Hi\end{document}")?;§What these encapsulate
The engine is a thread-local singleton, so each call runs on an engine
worker thread with a large (256 MiB) stack — matching the latexml_oxide
binary — so deeply nested math can’t overflow the 8 MiB default stack.
A call blocks its thread until the result is back; an async caller wraps it
in its runtime’s blocking pool (tokio::task::spawn_blocking), not on an
executor thread.
Workers are pooled. A call takes an idle worker or starts one, so calls made
from several threads at once convert in parallel, one worker each. After each
call the worker’s engine is reset
(reset_thread_engine): no definition,
counter or cache of one call reaches the next. The pool is bounded: at most one
idle worker per available core stays parked (a worker finishing beyond that
exits), and idle workers exit after a few seconds without a call, all but the
newest: one worker stays parked, so a caller converting now and then reuses it
instead of starting a worker per call. A parked worker holds one reset engine
(~39 MB of heap) and the stack pages its deepest conversion touched. A worker
that exits first empties its engine
(shrink_thread_engine): the engine’s
per-thread roots do not run destructors at thread exit, so an exiting
worker would otherwise leave its engine behind. A call that panics returns
Err, and its worker exits. A child forked while no call is in flight starts
with an empty pool (one forked mid-call may inherit a held pool or dump-cache
lock). The
standard package + contrib binding-dispatch chain is wired for you.
Like the latexml_oxide binary, these calls interpret a .sty/.cls that has no binding raw
(Perl LaTeXML’s --includestyles) and use the arXiv profile’s runaway limits; a caller wanting
Perl LaTeXML’s binding-only default drives a Converter with its
own Config (include_styles: Some(false); OXIDIZED_DESIGN_DIVERGENCES #1080).
§Requirements at runtime
Same host dependencies as the binary: a TeX distribution on PATH for
packages/classes/fonts, and (only for figure-bearing HTML) the graphics
tools. XML/XSLT/RelaxNG assets are embedded.
For finer control (preloads, search paths, encoding, whatsin/out, split,
…), drive crate::converter::Converter and crate::post directly; this
module is the batteries-included entrypoint.
Structs§
- Html
Options - The settings
convert_to_html_withtakes.Defaultis whatconvert_to_htmldoes. Start fromHtmlOptions::default()and use its builder methods so future options remain backwards-compatible:
Functions§
- convert_
to_ html - Convert a TeX/LaTeX source string all the way to a standalone HTML5 document (LaTeXML XML + the HTML post-processing pipeline, with Presentation MathML).
- convert_
to_ html_ with convert_to_htmlwith the givenHtmlOptions, on a pooled engine worker asconvert_to_html.- convert_
to_ xml - Convert a TeX/LaTeX source string to LaTeXML XML (the intermediate representation, before any HTML post-processing).