egui_commonmark icon indicating copy to clipboard operation
egui_commonmark copied to clipboard

LaTeX support

Open kgv opened this issue 2 years ago • 9 comments

Is LaTeX support planned?

kgv avatar Dec 14 '23 08:12 kgv

LaTeX in general i probably too much for this crate. With that said, a subset for math would definitely be nice to have.

lampsitter avatar Dec 14 '23 17:12 lampsitter

seems like pulldown_cmark has merged the support for math expressions: https://github.com/pulldown-cmark/pulldown-cmark/pull/734 (it will emit Event::InlineMath and Event::DisplayMath events that we can handle directly) we could then use MathJax to render it to an SVG and draw it (this crate just shells out to Node or a headless chrome instance)

i think this would be a really cool feature to have, i'll start prototyping on it tomorrow

zeozeozeo avatar Mar 30 '24 18:03 zeozeozeo

It would be really nice. It's just incredibly painful that node or headless chrome must be involved. I would have preferred to avoid that.

lampsitter avatar Mar 30 '24 19:03 lampsitter

It would be really nice. It's just incredibly painful that node or headless chrome must be involved. I would have preferred to avoid that.

True, I guess we could embed a JavaScript engine like QuickJS or Duktape and make MathJax run in it? :P I haven't found any pure Rust TeX -> SVG renderer, aside from Tectonic which seems to only render to HTML There are also libraries that shell out to ghostscript, but I think Node and Chrome are much more common

zeozeozeo avatar Mar 30 '24 19:03 zeozeozeo

Yeah. Your first suggestion is the most sane option. Maybe this gives me an excuse to add support for mermaid too :thinking:

There is definitely a lot to consider. For instance the headless chrome feature in that crate fetches mathjax from CDN and as I would expect most people to use that backend it would mean that it would require internet access to work. At least that would have to be documented.

lampsitter avatar Mar 30 '24 20:03 lampsitter

or we can just leave it to the user and make them pass a closure that will render LaTeX into a texture

zeozeozeo avatar Mar 30 '24 20:03 zeozeozeo

I don't think moving the problem to the user is the solution :laughing:

lampsitter avatar Mar 30 '24 20:03 lampsitter

I don't think moving the problem to the user is the solution :laughing:

I think that's the best option, since there's no easy way of rendering LaTeX in Rust. The implementation would also be different when compiling for web, since there you can directly interface with the browsers' JS engine

zeozeozeo avatar Mar 30 '24 20:03 zeozeozeo

I think that's the best option, since there's no easy way of rendering LaTeX in Rust. The implementation would also be different when compiling for web, since there you can directly interface with the browsers' JS engine

True. I did not think about for web.

lampsitter avatar Mar 30 '24 20:03 lampsitter