Hi Narisuzu, I think I may have made the mistake of not thinking hard enough before answering your question, so apologies for that. Iāll do more to brainstorm here with you.
First, how would KaTeX normally be utilized? In the browser, it would look something like this:
katex.render("c = \\pm\\sqrt{a^2 + b^2}", element, {
throwOnError: false
});
There are two things we need to know: 1. ) what is the KaTeX expression we are looking to render and 2.) where do we want it to be rendered, in the context of the rest of the page?
However, the whole problem weāre looking to solve is provide some SSR solution to utilizing KaTeX, within the framework and design of Zola. Bearing this in mind, I see maybe a few places we could do this.
One, is within the context of a markdown file. In this context, point #2 (I.e. where the element should be rendered) is determined by the location in the markdown file. I could imagine there being two places this could done: a.) within a code block, like:
```KaTeX
c = \pm\sqrt{a^2 + b^2}
```
and b.) the other way I imagine it could be used within markdown would be via a shortcode.
I donāt think thereās any other way to use Tera within markdown other than through shortcode, so it seems like code blocks and shortcodes is all that would be available to use within a markdown context. Although correct me if Iām wrong there.
Besides markdown, I also think weād probably also want the ability to inject rendered KaTeX within the context of the actual HTML code, although I think that would be less common. So in Zola thatās basically sections, pages, and macros I believe.
After thinking about it a bit, I feel like all the templating stuff (which so far is within a shortcode, sections/pages, and macros) could probably be best done at the templating layer. I donāt think this
{{ tex(code = "F = ma", display = true) }}
is honestly so bad. Maybe the one thing Iād add is can I also read KaTeX from a file and pipe it to the tex
function?
That leaves supporting it in markdown via the codeblocks. To be honest, this is where I would use KaTeX 95% of the time anywayā¦ Maybe there could be a branch in the syntax highlighting logic (within Zola) that looks for if the codeblock is marked as katex
. If it is, then it passes it to the KaTeX rendered. Otherwise, then it goes through the normal code highlighting flow. Also, youād probably want the ability to show KaTeX unrendered within code blocks as well, so maybe for that you could saw katex-raw
or something.
Iām not sure if thatās helpful at all. This is just me thinking aloud and where Iām coming from as a user and how I would probably use KaTeX in Zola. Another thing as a user that I would care a lot about is KaTeX support not slowing down how long it takes to compile my site. If using KaTeX in one place on my website slowed down the build by 250ms or something, Iād be pretty annoyed. So, I donāt know if it would work to call out to a nodejs process for each individual case that you have to generate HTML. Maybe thereās a library in rust that can be embedded within the Zola code to do this fast, but you probably know a lot more about that than I do.
Any way, apologies for the wall of text. Iām happy to discuss more offline too. You can find me on GH as asimpletune
, or on my website Contact - Spenc.es and Iām happy to collaborate where I can. Best of luck!