Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

Add mhchem (#3311)

Lionel Sergent09ea9ae247c9
diff --git a/frontend/src/plugins/layout/TexPlugin.tsx b/frontend/src/plugins/layout/TexPlugin.tsx
index 8312dcbb47..4300d10721 100644
--- a/frontend/src/plugins/layout/TexPlugin.tsx
+++ b/frontend/src/plugins/layout/TexPlugin.tsx
@@ -30,8 +30,13 @@ const importKatex = once(async () => {
return (await import("katex")).default;
});
+const importMhChem = once(async () => {
+ // @ts-ignore : type is not exported by katex
+ await import("katex/contrib/mhchem");
+});
+
async function renderLatex(mount: HTMLElement, tex: string): Promise<void> {
- const katex = await importKatex();
+ const [katex] = await Promise.all([importKatex(), importMhChem()]);
if (tex.startsWith("||(||(") && tex.endsWith("||)||)")) {
// when $$...$$ is used without newlines before/after the $$.
katex.render(tex.slice(6, -6), mount, {
diff --git a/marimo/_tutorials/markdown.py b/marimo/_tutorials/markdown.py
index ec9238a8f1..f0b2aad7ed 100644
--- a/marimo/_tutorials/markdown.py
+++ b/marimo/_tutorials/markdown.py
@@ -103,6 +103,23 @@ def __(mo):
return
[email protected](hide_code=True)
+def __(mo):
+ mo.accordion(
+ {
+ "Note: KaTeX": mo.md(
+ """
+ marimo actually uses KaTeX, a math typesetting library for the
+ web which supports a subset of LaTeX. For a list of
+ (un)supported commands, visit
+ https://katex.org/docs/support_table
+ """
+ )
+ }
+ )
+ return
+
+
@app.cell(hide_code=True)
def __(mo):
mo.md(
@@ -138,7 +155,6 @@ def __(
plt.plot(_x, np.sin(_x))
return plt.gca()
-
mo.md(
f"""
### Plots
@@ -214,7 +230,6 @@ def __(missing_numpy_msg, mo, np, numpy_installed):
y = np.sin(x)
return pd.DataFrame({"x": x, "sin(x)": y})
-
mo.md(
f"""
### Other objects
@@ -297,6 +312,7 @@ def __(
plt.plot(x, amplitude * np.sin(2 * np.pi / period * x))
plt.ylim(-2.2, 2.2)
return plt.gca()
+
return (plotsin,)
@@ -334,7 +350,9 @@ def __(amplitude, mo, period, plotsin):
def __(mo):
matplotlib_installed = False
numpy_installed = False
- missing_numpy_msg = mo.md("Oops! Looks like you don't have `numpy` installed.")
+ missing_numpy_msg = mo.md(
+ "Oops! Looks like you don't have `numpy` installed."
+ )
missing_matplotlib_msg = mo.md(
"Oops! Looks like you don't have `matplotlib` installed."
)
@@ -367,6 +385,7 @@ def __():
import math
import marimo as mo
+
return math, mo