This library provides helper functions via a Jupyter Extension to integrate Mathics3 into notebook environments.
Currently, it supports Jupyter, JupyterLite, marimo, and Observable.
For Jupyter, see also the Jupyter Kernel GitHub repository.
Set up your Python environment:
python3 -m venv .venv
source .venv/bin/activateor using pyenv:
pyenv local 3.14Next, start Jupyter Notebook:
jupyter notebook # or make run-jupyter-notebookYou should see a URL to connect to:
To access the server, open this file in a browser:
file:/usr/local/share/jupyter/runtime/jpserver-3279554-open.html
Or copy and paste one of these URLs:
http://localhost:8888/tree?token=1833fd2ac0fecd651c3f2d44931bd44c06673dd4701af3ca
http://127.0.0.1:8888/tree?token=1833fd2ac0fecd651c3f2d44931bd44c06673dd4701af3ca
The URLS and file access will be different than the above. Also, remove any browser connections to the URLS, e.g., localhost:8888 or 127.0.0.1:8888 or else you'll see errors.
Inside a standard Python3 Jupyter Kernel (ipykernel), run:
%load_ext mathics3_kernel.frontend.jupyter
After this, entering code in a Notebook cell will be interpreted as Mathics3 input. , Here is a sample notebook that can be used with a local Jupyter installation.
For an already set up and no install version, running in a browser, see Mathics3 Live. The GitHub repository for this is at https://github.com/Mathics3/Mathics3-live
from mathics3_kernel.frontend.marimo import mathics3Then run Mathics3 code like so:
mathics3("ArcCos[0]")See the examples directory for a sample notebook:
marimo edit --sandbox examples/marimo_notebook.pyIt also works in marimo's Pyodide-powered online environment, see https://marimo.io/p/@davidar/mathics for an example.
For other notebook environments, this library provides a generic interface:
from mathics3_kernel.frontend.generic import mathics3See 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;
}
}