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

Does version 3 support <script type="math/tex">? #2220

Closed
memakura opened this issue Oct 17, 2019 · 5 comments
Closed

Does version 3 support <script type="math/tex">? #2220

memakura opened this issue Oct 17, 2019 · 5 comments
Labels
Expected Behavior This is how MathJax works

Comments

@memakura
Copy link

It seems Mathjax version 3 does not render <script type="math/tex">, which was supported in version 2. (https://docs.mathjax.org/en/v2.7-latest/advanced/model.html#how-mathematics-is-stored-in-the-page)

I found this when I used Github Pages to convert a markdown file with $$...$$. The markdown file was processed on the Github server, but nothing was rendered with Mathjax v3 (v2 had no problem). I also checked this locally with Jekyll and found that $$...$$ in a markdown file is converted to <script type="math/tex; mode=display">…</script> before processed by Mathjax.

I was wondering whether this is an expected behavior in v3 or not. If so, are there any options to turn on the rendering of <script type="math/tex">?

The following is for a simple test.

<script async src="https://cdn.jsdelivr.net/npm/mathjax@3.0.0/es5/tex-chtml.js" id="MathJax-script"></script>
<!-- <script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS_CHTML"></script> -->

<p><script type="math/tex">ax+by+c=0</script></p>
<script type="math/tex; mode=display">\sum_{i=1}^n x_i</script>
@dpvc
Copy link
Member

dpvc commented Oct 17, 2019

This is the expected behavior in version 3. See the last bullet point in the changes to the API section of the upgrading to v3 documentation. This gives a configuration that will process the scripts that you are using.

@dpvc dpvc added the Expected Behavior This is how MathJax works label Oct 17, 2019
@memakura
Copy link
Author

Thank you so much for the information. This is exactly what I was looking for. Adding the following script successfully processed html files generated by Jekyll (from both html and markdown files).

MathJax = {
  options: {
    renderActions: {
      /* add a new named action not to override the original 'find' action */
      find_script_mathtex: [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);
        }
      }, '']
    }
  }
};

@opeltre
Copy link

opeltre commented Apr 20, 2020

Would you consider making this a simple option switch?

@dpvc
Copy link
Member

dpvc commented Apr 28, 2020

@opeltre, No, but it could be made an extension you could load.

ExpectationMax referenced this issue in ExpectationMax/ExpectationMax.github.io May 23, 2020
@Domiii
Copy link

Domiii commented Sep 18, 2020

For anyone still looking: @memakura's code just kinda works very well and out of the box :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Expected Behavior This is how MathJax works
Projects
None yet
Development

No branches or pull requests

4 participants