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.

fix: nested display math (#7873)

Akshay Agrawala51ef8eb3a60
diff --git a/frontend/src/plugins/layout/TexPlugin.tsx b/frontend/src/plugins/layout/TexPlugin.tsx
index 074057ce68..1099374874 100644
--- a/frontend/src/plugins/layout/TexPlugin.tsx
+++ b/frontend/src/plugins/layout/TexPlugin.tsx
@@ -115,16 +115,18 @@ const TexComponent = ({
// isn't a simple way to do that in Python without bringing in a new
// dependency.
//
- // The number of children is always 1 (the LaTeX) or 3 redundant ||(, ||)
- // delimiters as the first and third child, another marimo-tex tag as the
- // second. Only try to render latex in the former case.
+ // When nested, the inner marimo-tex should not render because the outer
+ // marimo-tex's textContent includes the nested delimiters (||(||(x||)||))
+ // and will render correctly with displayMode: true. We detect this by
+ // checking if the parent element is also a marimo-tex.
+ const isNested = host.parentElement?.tagName.toLowerCase() === "marimo-tex";
// Re-render when the text content changes.
useLayoutEffect(() => {
- if (ref.current) {
+ if (ref.current && !isNested) {
renderLatex(ref.current, currentTex);
}
- }, [currentTex]);
+ }, [currentTex, isNested]);
return <span ref={ref} />;
};