pub struct Math;Expand description
Render $...$ and $$...$$ math spans to MathML.
Two entry points:
Math::preprocess_sourceruns before the dmc lexer; rewrites raw$...$/$$...$$to<MathMl mathml="..."/>JSX so the parser never sees unescaped LaTeX. Required:_and^inside math would otherwise be parsed as Markdown emphasis markers.Transformerimpl runs as a pipeline pass on already-parsed AST. Used by tests and any caller that builds a Document directly.
Implementations§
Source§impl Math
impl Math
Sourcepub fn preprocess_source(source: &str) -> String
pub fn preprocess_source(source: &str) -> String
Rewrite $...$ / $$...$$ in raw MDX source to <MathMl/> JSX.
Skips fenced code blocks, inline code spans, and existing JSX tags.
Sourcepub fn render(latex: &str, display: bool) -> String
pub fn render(latex: &str, display: bool) -> String
Render a LaTeX string. Engine is the active crate::MathEngine
(default KaTeX HTML; can be flipped to MathML via pulldown-latex).
Cached by (latex, display, engine) so repeated math in a doc hits
the renderer once. On parse failure returns a
<span class="math-error"> wrapper around the original LaTeX.
Sourcepub fn set_engine(engine: MathEngine)
pub fn set_engine(engine: MathEngine)
Process-wide active engine. Set once via Math::set_engine
(pipeline does this from PipelineConfig::math_engine); defaults
to KaTeX. Stored as a static so [render] does not need a
per-call engine argument (keeps the source preprocessor signature
engine-agnostic).
Sourcepub fn load_cache(path: &Path)
pub fn load_cache(path: &Path)
Load a previously persisted math cache from path. Silently ignores
missing/corrupt files. Idempotent: existing in-memory entries are
kept (cache wins are additive).
Sourcepub fn save_cache(path: &Path)
pub fn save_cache(path: &Path)
Persist the in-memory math cache to path. Best effort; errors
are swallowed.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Math
impl RefUnwindSafe for Math
impl Send for Math
impl Sync for Math
impl Unpin for Math
impl UnsafeUnpin for Math
impl UnwindSafe for Math
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more