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 v3 no longer processes Kramdown's math engine's <script type="math/text" /> tags #626

Closed
abevoelker opened this issue Sep 16, 2019 · 3 comments
Assignees

Comments

@abevoelker
Copy link

Just a heads-up for your MathJax support, I tried to add some math to my Jekyll + Kramdown blog, and couldn't figure out why MathJax wasn't rendering Kramdown's emitted <script type="math/tex"> tags.

Turns out MathJax released v3.0.0 a couple weeks ago, and all their "getting started" / installation docs are now pointing to this newer version, which I dutifully followed so am using on my site. It further turns out this version doesn't render the "math/tex" script tags, quietly mentioned in the last bullet point in the upgrading from v2 to v3 docs here.

That bullet point as well as this example in their demos repo provide a configuration snippet that can be slightly modified to make MathJax v3 load Kramdown's <script type="math/tex"> tags:

<script>
  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);
          }
        }, '']
      }
    }
  };
</script>

(note I had to replace the "text/tex" in their snippet with "math/tex")

With that configuration snippet MathJax v3 is now working with Kramdown.

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

@abevoelker Thanks and sorry for the long delay regarding an answer!

So, would it be better to change the output to use \(...\) for inline and \[..\] for displayed math? Since that was supported in v2 and is still the default in v3, there should be no problem regarding backwards-compatibility.

Any thoughts?

@abevoelker
Copy link
Author

No problem. Regarding your question, I don't know to be honest as I'm new to MathJax! 🙃 Sorry I can't be of more help.

@gettalong
Copy link
Owner

I changed the output to use the standard syntax since this works in v2 and v3. The only thing that will not work is using the MathJax preview option since that is not available anymore in v3 (and wouldn't work with the chosen output syntax anyway). However, I don't think that this is a huge problem.

dato added a commit to dato/algo2-web that referenced this issue Aug 14, 2020
Github Pages v207 rompe nuestro rendering de math con KaTeX
(github/pages-gem#705), porque la nueva versión de Kramdown
cambia la sintaxis MathJax que emite (gettalong/kramdown#626).

El fix es usar directamente al auto-render.js de KaTeX, en lugar
del script anterior que usábamos (mathtex-script-type.js).

De paso, actualizar a KaTeX 0.12.
dato added a commit to algoritmos-rw/algoritmos that referenced this issue Aug 14, 2020
Github Pages v207 rompe nuestro rendering de math con KaTeX
(github/pages-gem#705), porque la nueva versión de Kramdown
cambia la sintaxis MathJax que emite (gettalong/kramdown#626).

El fix es usar directamente al auto-render.js de KaTeX, en lugar
del script anterior que usábamos (mathtex-script-type.js).

De paso, actualizar a KaTeX 0.12.
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