How dificult would it be to add KaTeX?

I wonder how dificult it would be to add KaTeX and whether smoebody is considering this. It seems that their code is maturing fast.

It would have an added benefit in our case to have the same rendering as Khan Academy on the forum about Khan Academy translations.

1 Like

I hacked together some code that will render the equations on the server:

There’s no error handling, and the font size doesn’t quite match the client-side version, but it seems to basically work in my development environment.

4 Likes

I really like the idea of this, should help performance quite a bit in some cases and starts unlocking email support! We still need to convert svg to png at some point for email.

Got to keep it optional for accessibility reasons though

@danekhollas I support a PR to add optional KaTeX

4 Likes

Because plugin development is currently way above my league, I just wanted to try adding KaTex via custom theme, using the autorender Katex extension. It kinda worked, but I ran into an issue with supporting a single $ sign as a math delimiter.

It seems that even though I turned off the MathJax math plugin, the text enclosed in $ $ is converted to text inside <span class=math> and the dollar signs dissappear. Weirdly, I cannot reproduce this on META. Any ideas?

At the and of this Katex github issue, somebody reported a very similar problem, that was tracked down to Kramdown doing this auto conversion…

Yeah the auto render stuff if very likely going to be extremely janky on Discourse. We rely on proper hooks that “decorate” chunks of HTML as they are being added to the DOM. We got to do this thing properly.

Maybe @misaka4e21 can have a look at making KaTeX optional default off in the math plugin?

5 Likes
6 Likes

Wow, that was fast, thanks so much!

One thing to consider. KaTex still lacks certain features as compared to MathJax. In Khan Academy, they actually fallback to MathJax when KaTeX fails. This would probably make sense to implement once the server-side rendering is in place, cause otherwise you’d always need to ship both Katex and mathjax, which is likely undesirable.

3 Likes

How do you make the decision when to fall back? Curious, can this also be decided on the client?

I am not actually involved directly, but my guess would be simply when KaTex throws an error they use MathJax?
And I am pretty sure they do it on the client as well.

For more info I’d suggest asking them directly on their github.

2 Likes