Discourse Math Plugin


(Sam Saffron) #24

I can easily make this work, but the styling will be the inline style.

So stuff like 200$ and 300$ is not mistaken as math.

(xiasummer) #25

Why? How will $$30$$ be reconized as 30$?

(cpradio) #26

More info needed. What errors are you seeing?

(xiasummer) #27

I don’t know what error info. I find only when I disable the plugin Checklist, the Math-Plugin will take effect.

(cpradio) #28

Can you look into what error is being produced (open the Dev Console, usually by pressing F12)

(xiasummer) #29

Do you mean this?

(Mark McClure) #30

I have not yet tried the new math plugin; I am looking forward to trying it in a few days. I’ve run plenty of forums with MathJax enabled, though, and my initial inclination is to think that most users of such forums will expect that input that processes through LaTeX will also process when they type it into a forum. By contrast, they would not be surprised if you had to escape dollar signs and type your example as

Stuff like 200\$ and 300\$ is not mistaken as math.

That’s exactly how you do it in TeX.

(cpradio) #31

@xiasummer, I can’t reproduce the issue you are experiencing:

Checklist Test Latest Version 2 - Playground - Discourse Sandbox by cpradio

(Mark McClure) #32

I’ve just installed a development version of Discourse on my laptop so that I could try out this new Math Plugin. I generally agree with the comments that have been made so far. I’d certainly like to echo @fefrei’s ginormous expression of thanks and strongly agree that it’s good idea to make this an “official” plugin. I can verify that the old MathJax plugin could be quite buggy.

I afraid I also have to agree with the sentiments expressed by @xiasummer, however. I don’t see it as quite the deal breaker that he seems to, though. As I already said in one previous post,

Note also that LaTeX is mixed with markdown in quite a few other contexts, like math.se (where I’ve been active for 5 1/2 years), other forum software (like AskBot), and the Jupyter Notebook. In none of those contexts have I seen the space surrounding the dollar signs heuristic.

More generally, it seems to me that the LaTeX and MathJax communities have already invested an enormous amount of thought into parsing and displaying mathematics. I’m not sure it makes much sense to try to outdo that. MathJax supports asciimath as well, if you’d like to add it.

Finally, here’s a concrete example that I was not able to get working as a TeX user would like:

The expression $x+x$ has two $x$s.

I would expect that to render as

rather than

(Nordize) #33

This plugin does not work with the Details plugin, i.e. using $...$ inside [details] Does not render maths. I’m using v1.9.0.beta4+52 … I just discovered this and it affects a great deals of posts on our board. It seems I have to revert to v1.8 … or does anyone have a quick fix?

(Nordize) #34

In reply to myself above - downgrading is not really an option (too many new posts since we upgraded to v1.9beta). Does anyone here know of a quick hack to enable mathjax inside [details]?

(Sam Saffron) #35

I will have a look tomorrow, sample breaking markdown please

(Nordize) #36


Let $x=1$. Find $x$.

Let $x=1$. Find $x$.

(Mark McClure) #37

@sam Typically, when math is exposed in response to an event like this, you’ve got to call window.MathJax.Hub.Typeset or something like that on the newly exposed math element. I’m guessing the difficulty is that you need to make that call based on an event that’s unrelated to the Math Plugin.

(Mark McClure) #38

MathJax is highly configurable. It would be great if the plugin allowed some way to specify some configuration options. By no means should an attempt be made to interface every MathJax option but there are a few important options that I think should be considered. Specifically:

  • An option to specify the location of that MathJax script, as I already mentioned.
  • Options to load specific extensions, like
    • The accessibility extension
    • I like the ability of zoom on click - which is great in a classroom setting.

I’ve fiddled with this a bit and have something like the following on my development version:

My Math Plugin settings panel

A post after a math element has been clicked

(Sam Saffron) #39

Sure, go for it, a PR is totally welcome!

Also if you are feeling adventurous I am happy to allow for some other stuff:

  1. ignore all math boundary checks (default off), once enabled aaa$test$aaa treats test as math. (escaping is the only way of eliminating it)

  2. Add support for $$test$$ inline which should be trivial.

(Rafael dos Santos Silva) #40

Is this really necessary? Is there a use case where every Discourse asset is served locally (jquery, emberjs, font-awesome, etc) and only MathJax should come from a CDN? Considering HTTP/2 isn’t this slower?

If you have a CDN configured for Discourse, MathJax will come from the same CDN already.

(Mark McClure) #41

@Falco I don’t think it’s necessary to add an option to point to a CDN but it certainly seems reasonable. The MathJax team seems adamant that serving MathJax locally is not a good idea and I, for one, don’t currently have a CDN setup for my site.

I will definitely look into adding a CDN for my site and I appreciate the recommendation to do so. But, a quick look indicates that it might be a small pain, as it involves signing up for an account on a CDN (which I don’t have) and fiddling with my DNS (which I do twice a year).

(Mark McClure) #42

@sam Yes, I’d be happy to make a pull request with a couple of simple modifications allowing access to MathJax configurations. @Falco pointed out that the CDN seemed unnecessary which agreed with your earlier opion so I’ll remove that and perhaps make a separate pull request.

I’ll take a look at that too as I already indicated that I think that’s a good idea. That appears to happen in the Ruby code in the spec sub-directory, though, which I don’t know. When I look at, for example,

it 'can handle inline math' do
  cooked = PrettyText.cook('I like $\{a,b\}\$<a>$ etc')
  html = '<p>I like <span class="math">\{a,b\}\$&lt;a&gt;</span> etc</p>'
  expect(cooked).to eq(html)

I’m pretty baffled. The changes I’ve made so far are all YML and Javascript, which I’m good with.

(Sam Saffron) #43

That is just the test harness, all the logic is still in JavaScript … to run it you would run

bin/rake autospec

And save the file.

Note, I am fine with adding that site setting for the CDN, it is a bit odd but I am not really that much against it provided it is default off.