Expand description
§MathQuill JS
An idiomatic Rust wrapper for the MathQuill JavaScript library. Builds upon mathquill-js-sys
If your using Leptos, you want to use the leptos wrapper mathquill-leptos.
You need to load the JQuery JS library and the MathQuill JS library before using this crate,
download from their github releases page
and a copy of jQuery (e.g. here).
You will then need to include <script>
tags to load them.
See the MathQuill documentation for more details
§API Structure
Read the docs on the MathQuill struct, everything starts from there.
§Contrived example
From their docs:
var answerSpan = document.getElementById('answer');
var answerMathField = MQ.MathField(answerSpan, {
handlers: {
edit: function() {
var enteredMath = answerMathField.latex(); // Get entered math in LaTeX format
checkAnswer(enteredMath);
}
}
});
This would translate to something like:
use mathquill_js::{Config, MathField, MathQuill};
fn check_answer(latex: String) {
// Whatever you want here
}
fn main() {
// getting this is usually the responsibility of
// a web framework, e.g. leptos
let element: web_sys::HtmlElement = todo!();
let mq = MathQuill::get_global_interface();
let mut config = Config::default();
config.handlers().on_edit_field(|| {
let field: Option<MathField> = MathQuill::get_global_interface().get_field(&element);
let latex = field.unwrap().latex();
check_answer(latex);
});
let _field = mq.mount_field(&element, &config);
// dropping config invalidates closures,
// read docs on Config
}
If you don’t want the field to be editable, you can use a static field and manually set the latext content to be whatever you want, like this:
use mathquill_js::MathQuill;
fn main() {
// getting this is usually the responsibility of
// a web framework, e.g. leptos
let element: web_sys::HtmlElement = todo!();
let mq = MathQuill::get_global_interface();
let field = mq.mount_static_field(&element);
// this is often set in response to application demands
field.set_latex(r"\text{Hey, this is cool!}");
}
See the examples directory for more information
Structs§
- Config
- Read docs on mathquill_js_sys::Config about manual memory management
- Handlers
Mut - Math
Field - Wrapper around mathquill_js_sys::MathField
- Math
Quill - The primary interface to the MathQuill library.
- Static
Math - Wrapper around mathquill_js_sys::StaticMath
Traits§
- Into
Inner - Used internally, exposed for correctness in case you are also using mathquill_js_sys