Discourse Math Plugin


(xiasummer) #64

I don’t know, from my point of view, it is recalculating——quite strange.

Because when I’m editing another formula, all the other formulas are in their raw shapes, either $xxx$ or xxx without rendering effects.

(Agustín Santiago Gutiérrez) #65

I have just updated to the latest version of discourse-math, and the problem remains the same.

(Agustín Santiago Gutiérrez) #66

After all of the most recent updates, it still remains the same.

(Mark McClure) #67

I’ve just submitted a pull request to modify the plugin so that it can process input expressed in asciimath, as well as LaTeX. The code is on GitHub and (for a brief time only) you can see it in action on this temporary discourse instance.

I mention it here because, as you said:

I chose to delimit asciimath input with a single percent sign (%). The aciimath webpage indicates a preference for a backtick (`); that seems a poor choice because markdown typically uses this to denote inline code. There’s not a whole lot of other choices of single character delimiters that aren’t either very commonly used in math (like +/-/=) or captured by discourse for some special purpose (like @ or #). I went with the percent sign, in part, because it’s right next to the dollar sign used for TeX. Note that you can still use a percent sign in math input by escaping it with a backslash.

(Sam Saffron) #68

Hmm :thinking: what if we did something like %` some math ` , I know it is 2 keys but it would save us from escaping percents and we could have a block form with % triple backtick?

What do other markdown implementations do like math stack exchange etc?

(Mark McClure) #69

One thing that I like about the code the way I’ve set it up now is that it uses your original inlineMath function almost verbatim. I’ve just added a third argument to specify the delimiter - 36 for $ for LaTeX and 37 for % for asciimath. I rather like that simplicity and multi-purposing of code. Also, I’m a bit of a novice at this and not sure how much time it would take me to figure out to scan two symbols.

I’m definitely open to using some other single symbol; I’m just not sure of a better choice.

It would not be hard to set up a block form (I’d prefer to delimit it with %%) which would be passed to a div rather than a span. The typesetting itself, though, would be unaffected because asciimath itself does not distinguish between inline and display math. That’s why I didn’t specify a block form to begin with and I’m still not totally sure if it’s a good idea.

I don’t believe that math.stackexchange uses asciimath and I’m fairly active there. I honestly don’t know just how widely used it is. My own interest arises because I use Discourse to set up fora for college students and I’d like something that’s a bit more intuitive for them to use. I think the fact that asciimath is, to some degree, a “simpler” LaTeX supports the idea to use a single delimiter as well.

(Sam Saffron) #70

Ok so I am fine to accept % but let’s make this optional default off with a site setting

(Mark McClure) #71

I can definitely do that!


It looks like the math formulas aren’t rendered in polls. They render in the preview of the polls, but not when the polls are actually posted. Is this something that can be fixed?

(Daniel Hollas) #73

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.

(Jouni Seppänen) #74

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.

(Sam Saffron) #75

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

(Daniel Hollas) #76

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…

(Sam Saffron) #77

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?

(Yihan "Misaka 0x4e21" X.) #78

(Daniel Hollas) #79

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.

(Sam Saffron) #80

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

(Daniel Hollas) #81

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.