Skip to content

Handle marimo tex components when exporting to PDF#8062

Merged
mscolnick merged 6 commits intomainfrom
sham/handle-latex-export-pdf
Feb 5, 2026
Merged

Handle marimo tex components when exporting to PDF#8062
mscolnick merged 6 commits intomainfrom
sham/handle-latex-export-pdf

Conversation

@Light2Dark
Copy link
Collaborator

@Light2Dark Light2Dark commented Jan 30, 2026

📝 Summary

Fix LaTeX rendering in ipynb/PDF exports by converting marimo's internal <marimo-tex> HTML format back to standard $...$ / $$...$$ delimiters.

\[...\]$$...$$ conversion is also implemented but disabled. However, it seems nbconvert/jupyter doesn't handle them jupyter/nbconvert#477.

Example cell-output

[{'output_type': 'display_data', 'metadata': {}, 
  'data': {'text/markdown': '<span class="markdown prose dark:prose-invert contents">
  <span class="paragraph">The exponential function 
  <marimo-tex class="arithmatex">||(f(x) = e^x||)</marimo-tex> can be represented as</span></span>'}
}]

🔍 Description of Changes

We wrap LaTeX in custom tags with ||(...) delimiters (via pymdownx.arithmatex). The frontend renders these with KaTeX, but nbconvert doesn't understand them, causing broken math in exports.

Not included

📋 Checklist

  • I have read the contributor guidelines.
  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • Tests have been added for the changes made.
  • Documentation has been updated where applicable, including docstrings for API changes.
  • Pull request title is a good summary of the changes - it will be used in the release notes.

@vercel
Copy link

vercel bot commented Jan 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Feb 3, 2026 7:14pm

Request Review

Copy link
Collaborator

@dmadisetti dmadisetti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. But we're not converting \[ notation? A little confused, if jupyter doesn't support it, then we should convert right?

import marimo

__generated_with = "0.15.5"
__generated_with = "0.19.6"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a sanity check, can you convert this to our markdown format too?

@dmadisetti
Copy link
Collaborator

Yeah, I see a natural ask being to include .sty and .cls files for things like mhchem support and other libraries. But maybe we can cross that bridge when we get there

@Light2Dark
Copy link
Collaborator Author

Light2Dark commented Jan 30, 2026

Nice. But we're not converting \[ notation? A little confused, if jupyter doesn't support it, then we should convert right?

They don't support rendering this syntax afaik. And nbconvert doesn't support parsing this syntax either hence raises an error. So, we are altering the code we send to nbconvert to make it work. From my understanding, \[ is basically escaping a bracket and hence treated like normal markdown. This issue jupyter/nbconvert#477 and consequent PR attempts to add more parsing for nbconvert but was rejected.

image

I don't really know what the state is now, maybe use jupyter with this extension? https://github.com/jfbercher/jupyter_latex_envs

@Light2Dark
Copy link
Collaborator Author

@dmadisetti I think I'm okay to support it. My worry was false positives but the regex looks right. Also seems like it's the recommended way to write LaTeX now.

mscolnick
mscolnick previously approved these changes Feb 3, 2026
("SELECT (", ["syntax", "error"]),
("SELECT * FROM", ["syntax", "error"]),
("SELECT ,", ["syntax", "error"]),
("SELEC * FROM table", ["syntax", "error"]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i assume this syntax error was intentional. but typo is re-writing it? we can create a different syntax error

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in the pre-commit PR, but yeah, that's also possible lol

@Light2Dark Light2Dark force-pushed the sham/handle-latex-export-pdf branch from 07c149a to 94b70c4 Compare February 3, 2026 19:13
@mscolnick mscolnick merged commit b36ff2e into main Feb 5, 2026
31 of 43 checks passed
@mscolnick mscolnick deleted the sham/handle-latex-export-pdf branch February 5, 2026 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants