marimo icon indicating copy to clipboard operation
marimo copied to clipboard

KaTeX Macro Support

Open claudiushaag opened this issue 1 year ago • 3 comments

Description

As outlined in https://github.com/marimo-team/marimo/discussions/1941, I would love to be able to have some Macro Support for KaTeX. This would come in handy for repeated use of convoluted symbols and would really help us for teaching and presenting our stuff in notebooks.

Our current workflow for jupyter notebooks is a workaround, where we do

import IPython.display
IPython.display.display_latex(IPython.display.Latex(filename="macros.tex"))

where macros.tex looks like

\newcommand{\rot}[1]{{\rm curl }\left( #1 \right)}
\newcommand{\Grad}[1]{{\rm Grad}\left( #1 \right)}
\newcommand{\Div}[1]{{\rm Div }\left( #1 \right)}

A feature like that would be great!

Suggested solution

In an optimal case, we would love to be able to point to a file populated by KaTeX macro commands, which would then be available to use in all markdown cells without any additional import.

claudiushaag avatar Feb 13 '25 12:02 claudiushaag

@mscolnick, an issue regarding the macro usage in KaTeX, as talked about on twitter. Thanks for having a look into this!

claudiushaag avatar Feb 13 '25 12:02 claudiushaag

@claudiushaag, i've started the work here to support global macros defined from other cells. https://github.com/marimo-team/marimo/pull/3785

This should unblock you, but the ergonomics is not great. With this change, you can do:

import marimo as mo

# Register globals
mo.md(f"$$\n{(mo.notebook_dir() / 'macros.tex').read_text().strip()}\n$$")

This is not great, so in future, we will do one of the below

Option 1:

import marimo as mo
mo.latex(filename="macros.tex")

Option 2:

[display]
latex_files = ['macros.tex'] # this will preload the tex files. 

mscolnick avatar Feb 13 '25 16:02 mscolnick

@mscolnick wow, this is really great, thank you so much!

claudiushaag avatar Feb 14 '25 07:02 claudiushaag