This library provides helper functions for integrating Mathics3 into notebook environments. Currently, it supports Jupyter(Lite), marimo, and Observable.
See the Mathics3 live project for a live demo.
%load_ext mathics3_kernel.frontend.jupyter
Usage is as simple as executing the above code in a notebook cell, and then Mathics3 code can be directly run in all subsequent cells.
from mathics3_kernel.frontend.marimo import mathics3
Then run Mathics3 code like so:
mathics3("ArcCos[0]")
See the examples directory for a sample notebook:
marimo edit --sandbox examples/marimo_notebook.py
For other notebook environments, this library provides a generic interface:
from mathics3_kernel.frontend.generic import mathics3
See https://observablehq.com/@davidar/mathics for an example of how this can be used with Observable notebooks. This notebook loads the library with pyodide, then implements a simple interface in JavaScript:
async function mathics3(strings) {
const [type, result] = await py`${mathics3_kernel}(${strings[0]})`
if (type === "code") {
return md`\`\`\`\n${result}\n\`\`\``;
} else if (type === "math") {
return tex.block`${result}`;
} else if (type === "json") {
return JSON.parse(result);
} else if (type === "html") {
return html`${result}`;
} else {
return result;
}
}