Skip to content

MathJax v3 no longer processes Kramdown's math engine's <script type="math/text" /> tags #626

Description

@abevoelker

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions