4 ms·
I wish there was a native version of this. Every SSG seems to have the problem of having to depend on node in order to prerender html for math with katex.
by sureglymop 1y ago
I wish there was a native version of this. Every SSG seems to have the problem of having to depend on node in order to prerender html for math with katex.
- notpushkin 1y agoPort it? Or maybe bundle a tiny interpreter instead of Node.
- koito17 1y agoI've been using katex-rs, a Rust rewrite, to implement LaTeX rendering for a Rust web app. It was easy enough to hook into pulldown_cmark, so that $ and $$ and render a decent subset of LaTeX. Since pulldown_cmark is a proper Markdown parser, you listen for Event::InlineMath and Event::DisplayMath then call KaTeX directly. No regex or HTML escaping necessary. In my web app, this is all encapsulated into a single function that I can call within Tera templates. It's as SSR as it gets; no Node.js or client-side JavaScript necessary. The costliest asset is a minified stylesheet served through a CDN. (I do this out of laziness, and because the web app as-is needs nothing more than the standard Rust toolchain). https://github.com/katex-rs/katex-rs https://github.com/katex-rs/katex-rs
- nicoburns 1y agoDo you have a reference on how to hook it into pulldown_cmark? I'd love to add math support into to my markdown rendering app but I haven't had time to investigate this myself yet.
- koito17 1y agohttps://gist.github.com/akar1ngo/7d4ea6e9dfc369526beb75092cbd6cb8 https://gist.github.com/akar1ngo/7d4ea6e9dfc369526beb75092cb...
- sureglymop 1y agoThank you for your account and reply! Awesome stuff :)
- MillironX 1y agoHugo includes native KaTeX: https://gohugo.io/functions/transform/tomath/ https://gohugo.io/functions/transform/tomath/ The docs recommend setting up KaTeX CSS (which requires either a CDN link or Node), but by changing output to 'mathml,' you can have the browser render equations with zero dependencies.
- sureglymop 1y agoThat's news to me! The last time I used Hugo it didn't support that yet and I had to serve the js bundle to run in the browser.
- rustybolt 1y agoI use it in my static site generator in Python via https://github.com/rubenvannieuwpoort/PyKaTeX https://github.com/rubenvannieuwpoort/PyKaTeX. Disclaimer: I am the author of PyKaTeX.
- generichuman 1y agoIf your use case is generating html, MathML is supported in all modern browsers: https://developer.mozilla.org/en-US/docs/Web/MathML#browser_compatibility https://developer.mozilla.org/en-US/docs/Web/MathML#browser_...