diff --git a/frontend/src/plugins/layout/TexPlugin.tsx b/frontend/src/plugins/layout/TexPlugin.tsx index 8312dcbb475..4300d10721c 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 { - 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 ec9238a8f16..f0b2aad7edf 100644 --- a/marimo/_tutorials/markdown.py +++ b/marimo/_tutorials/markdown.py @@ -103,6 +103,23 @@ def __(mo): return +@app.cell(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 _sine_plot(): plt.plot(_x, np.sin(_x)) return plt.gca() - mo.md( f""" ### Plots @@ -214,7 +230,6 @@ def make_dataframe(): y = np.sin(x) return pd.DataFrame({"x": x, "sin(x)": y}) - mo.md( f""" ### Other objects @@ -297,6 +312,7 @@ def plotsin(amplitude, period): 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