Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mathjax 3 compatibility #651

Closed
opeltre opened this issue Apr 20, 2020 · 3 comments
Closed

mathjax 3 compatibility #651

opeltre opened this issue Apr 20, 2020 · 3 comments
Assignees

Comments

@opeltre
Copy link

opeltre commented Apr 20, 2020

Kramdown's output is not compatible with mathjax 3's defaults!

The <script type="tex/math"> tags are not parsed anymore, although it was the recommended
output in v2 💣

Having a markdown parser go along with mathjax can be a real mind breaker and it is a huge relief that kramdown does its job at protecting equations properly.

It took me a day to identify the problem and it turns out it's all mathjax's fault.

Until an eventual fix, I still think it would be much appreciated, and save math users a lot of time, if kramdown advertised on this issue in its docs:

  • kramdown + mathjax should really mention this
  • math syntax should also precise that kramdown does not ship with a math engine and link to the above page

I'd say this is all the more called for as the mathjax docs are completely uneatable, and the internet is full with misleading, outdated similar threads!

@opeltre
Copy link
Author

opeltre commented Apr 20, 2020

Here are the mathjax API changes one may run into after a lot of web wandering (last bullet).

You could have math rendered with kramdown by including a distribution of mathjax 2, if only. The cdn script tag for v2 I pasted from their landing page didn't work.

To use mathjax 3, one should include before loading the mathjax script this complicated configuration object, which essentially supplies the function looking for the script tag v2 used.

MathJax = {
  options: {
    renderActions: {
      find: [10, function (doc) {
        for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
          const display = !!node.type.match(/; *mode=display/);
          const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
          const text = document.createTextNode('');
          node.parentNode.replaceChild(text, node);
          math.start = {node: text, delim: '', n: 0};
          math.end = {node: text, delim: '', n: 0};
          doc.math.push(math);
        }
      }, '']
    }
  }
};

Then kramdown's output script tags will be parsed to math :)

Hoping you could highlight this somewhere in the docs,
Cheers!

@opeltre
Copy link
Author

opeltre commented Apr 20, 2020

See also mathjax/MathJax#2220

@gettalong gettalong self-assigned this Apr 20, 2020
@gettalong
Copy link
Owner

This is already fixed in c3acf8d and will be part of the next release. You could try the repository version of kramdown to see if that works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants