Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mhchem #3311

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion frontend/src/plugins/layout/TexPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
25 changes: 22 additions & 3 deletions marimo/_tutorials/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -138,7 +155,6 @@ def _sine_plot():
plt.plot(_x, np.sin(_x))
return plt.gca()


mo.md(
f"""
### Plots
Expand Down Expand Up @@ -214,7 +230,6 @@ def make_dataframe():
y = np.sin(x)
return pd.DataFrame({"x": x, "sin(x)": y})


mo.md(
f"""
### Other objects
Expand Down Expand Up @@ -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,)


Expand Down Expand Up @@ -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."
)
Expand Down Expand Up @@ -367,6 +385,7 @@ def __():
import math

import marimo as mo

return math, mo


Expand Down
Loading