2 releases
0.1.1 | May 28, 2023 |
---|---|
0.1.0 | May 28, 2023 |
#947 in Graphics APIs
Used in 2 crates
5.5MB
50K
SLoC
Contains (WOFF font, 41KB) MathJax_AMS-Regular.woff, (WOFF font, 35KB) MathJax_Main-Bold.woff, (WOFF font, 35KB) MathJax_Main-Regular.woff, (WOFF font, 23KB) MathJax_Fraktur-Bold.woff, (WOFF font, 22KB) MathJax_Fraktur-Regular.woff, (WOFF font, 21KB) MathJax_Main-Italic.woff and 17 more.
Render MathJax expressions into either SVG or PNG formats.
See the docs for documentation.
lib.rs
:
Render MathJax expressions into either SVG or PNG formats.
Crate Feature Flags
node
- Enables the NodeJs backend, this will attempt to use a system installation of NodeJs at runtime as the renderer. This will be priotized over any other features if enabled.browser
- Enables theheadless_chrome
backend, this will create a headless Chrome instance to use as the renderer. If this is enabled in conjunction with thenode
feature flag, this will be used as a fall back when NodeJs is not available.auto
- This is equivelent to enabling all backends (currently justnode
andbrowser
) seeMathJax::new
for what this specifically does.image
- Allows converting the rendered SVG into animage::DynamicImage
viaRender::into_image
.
By default, the auto
crate feature is enabled.
Usage
- Create an instance of
MathJax
throughMathJax::new
. - Call
MathJax::render
with the expression you want to render. - Call one of the conversion methods on
Render
to get the desired output format.
For example, if we wanted to render the expression y=\frac{1}{x}
into the file test.svg
:
use mathjax::MathJax;
let expression = r#"y=\frac{1}{x}"#;
let renderer = MathJax::new().unwrap();
let result = renderer.render(expression).unwrap();
let svg_string = result.into_raw(); // This is a `<svg></svg>` element.
std::fs::write("test.svg", svg_string).unwrap();
Which produces the following image:
If we had the image
feature flag enabled, we could do the following to convert into an image::DynamicImage
and save it into the file test.png
:
use mathjax::MathJax;
let expression = r#"y=\frac{1}{x}"#;
let renderer = MathJax::new().unwrap();
let result = renderer.render(expression).unwrap();
let image = result.into_image(10.0).unwrap(); // This is an image::DynamicImage.
image.save("test.png").unwrap();
(see Render::into_image
for what 10.0
means here)
Producing:
Dependencies
~7–20MB
~266K SLoC