Discourse Math

Absolutely, code will be very helpful here, perhaps fork discourse and then push your changes to a branch, then I can pull changes from your branch into the PR.

So happy you are making progress, trying to diagnose this issue.

Can you also pull latest, I did a round of cleanup.

1 Like

OK, here is the code:

Beware, though, I did not work directly from your latest commit. I started directly from Discourse main and made changes from there. Thus, I learned a fair amount from your work but the overall structure is different.

I think you could summarize the main difference as follows: Where you (naturally) use Discourse features inherited from Ember to coordinate the timings associated with things like loading and typesetting, I use MathJax features. Thus, my load-mathjax and mathjax bundles (one for svg and one for chtml) are much simpler than yours. The loading is all coordinated via the window.MathJax object in discourse-math-mathjax.

I still have the same problem that I described before, namely that this commented out loader doesn’t work; I’ve got to use this CDN version instead. I really don’t know why.

I think that your code suffers from the same problem. That’s why AsciiMath doesn’t seem to work.

1 Like

can you double check my latest commit, I think I added a funnel for ember so now the ember build puts all the files in the right place.

2 Likes

OK, I’ve got some very good news and some frustrating news.

First, you’re absolutely right that adding the funnel places those files in the correct place. I added the funnel to my branch and it now works great without the CDN dependancy. :tada:

Unfortunately, I am unable to run your code at the moment. Whenever I navigate to a page with math on it, the math does not typeset and I see the following error message in the console:
Uncaught (in promise) Error: State EXPLORER already exists

I’m certain I had your code working before so I suppose it’s something I did. To be clear, though, I literally started an entirely fresh directory using the techniques described in Install Discourse on macOS for development.

git clone https://github.com/discourse/discourse.git ./discourse
cd ./discourse
bundle install
pnpm install
bundle exec rake db:create
bundle exec rake db:migrate
RAILS_ENV=test bundle exec rake db:create db:migrate

# In one terminal
bundle exec rails server

# In another terminal
bin/ember-cli

I then grabbed your code with

git checkout 71ad0305f812311f2a4570edf7c33f97de46c457
git switch -c mathjax-sam

Even from that fresh setup, I get the error.


At this point, I’m pretty happy with my version of the code but still curious about what’s going on with yours. I need to take a break from this for the holiday, though. I’m happy to take another look at it in a few days time.

One final point, though: As far as I know,

await import("tex-mml-chtml.js") // followed by
await import("input/asciimath.js")

shouldn’t work, which is effectively what your code is doing, I think.

I’m being imprecise with paths there but my point is that I don’t know that consecutive dynamic calls to import lead to the correct MathJax structure. I think that loading MathJax components is pretty complicated and that’s why they’ve got such a detailed loading process with the MathJax object and all.

Thanks so much for your help and patience @sam!

1 Like