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

mml3 still not work in MathJax3.2 #2718

Closed
weihaopeng opened this issue Jun 23, 2021 · 10 comments
Closed

mml3 still not work in MathJax3.2 #2718

weihaopeng opened this issue Jun 23, 2021 · 10 comments
Labels
Accepted Issue has been reproduced by MathJax team Code Example Contains an illustrative code example, solution, or work-around Fixed v3 v3.2
Milestone

Comments

@weihaopeng
Copy link

Issue Summary

Follow the experimental mml3 extension, I add the loader in my MathJax configuration. Then in page, the mml3.js is loaded, but the mathml using mlongdiv is not rendered correctly.

Steps to Reproduce:

  • The code example.
  • This is what I expect and what it is.
  • image
  • And the request of mml3.js file is successful.
  • image

Technical details:

  • MathJax Version: 3.2
  • Client OS: Windows10
  • Browser: Chrome 91.0.4472.101

Supporting information:

  • Script tag:
  •  <script>
       window.MathJax = {
             options: {
               renderActions: {
                 addMenu: [0, '', '']
               }
             },
             chtml: {
               matchFontHeight: false,
               adaptiveCSS: false
             },
             loader: {load: ['input/asciimath', 'output/chtml', '[mml]/mml3']}
           };
     </script>
     <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/mml-chtml.js"></script>
    
@dpvc
Copy link
Member

dpvc commented Jun 23, 2021

Try adding

mml: {
  forceReparse: true
},

to your configuration.

@dpvc dpvc added Accepted Issue has been reproduced by MathJax team v3 labels Jun 23, 2021
@weihaopeng
Copy link
Author

Like this?

window.MathJax = {
  options: {
    renderActions: {
      addMenu: [0, '', '']
    }
  },
  chtml: {
    matchFontHeight: false,
    adaptiveCSS: false
  },
  loader: {
    load: ['input/asciimath', 'output/chtml', '[mml]/mml3']
  },
  mml: {
    forceReparse: true
  }
 };

It doesn't work either. Even mathml that doesn't have mlongdiv throws error "MathML must consist of a single element".

image

I've updated the code example

@weihaopeng
Copy link
Author

I saw the code mathml compile function, debugged my code example. Here is why the error was thrown.

image

image

The code here want to check if there is only a single <math> in body, but the childnodes certainly have a textnode, too.

@weihaopeng
Copy link
Author

Then, where is the textnode from?

image

@weihaopeng
Copy link
Author

BTW, a spelling mistake here: ts/core/OutputJax.ts#L223

image

@weihaopeng
Copy link
Author

weihaopeng commented Jun 24, 2021

Something wrong here. During executeFilters, the \n was added. Maybe the output was beautified?

@weihaopeng
Copy link
Author

weihaopeng commented Jun 24, 2021

image

image

The origin problem is transformToDocument function of XSLTProcessor.

@dpvc
Copy link
Member

dpvc commented Jun 24, 2021

Thanks for trying to diagnose the problem. It turns out that your example page works in Firefox, where I was doing my testing, but not in Chrome or Safari, so it seems that WebKit (and Blink) treat the transform differently, and extra line breaks seem to be inserted, as you point out.

For now, you can add an additional preFilter that removes those line breaks before the MathML is parsed. Add

    startup: {
      ready() {
        MathJax.startup.defaultReady();
        MathJax.startup.document.inputJax[0].preFilters.add(function (data) {
          data.data = data.data.replace(/[\s\n]+<math/, '<math')
                               .replace(/math>[\n\s]+/, 'math>');
        }, 10);
      }
    }

to make it

window.MathJax = {
  startup: {
    ready() {
      MathJax.startup.defaultReady();
      MathJax.startup.document.inputJax[0].preFilters.add(function (data) {
        data.data = data.data.replace(/[\s\n]+<math/, '<math')
                             .replace(/math>[\n\s]+/, 'math>');
      }, 10);
    }
  },
  options: {
    renderActions: {
      addMenu: [0, '', '']
    }
  },
  chtml: {
    matchFontHeight: false,
    adaptiveCSS: false
  },
  loader: {
    load: ['input/asciimath', '[mml]/mml3']
  },
  mml: {
    forceReparse: true
  }
 };

to your configuration and that should resolve the issue.

Note, however, that the XSLT is not set up to deal with your msgroup inside the division symbol. You may want to change it to

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mlongdiv charalign="center" charspacing="0px" stackalign="left">
    <mn>48</mn>
    <mrow/>
    <mn>&#x25A1;52</mn>
  </mlongdiv>
</math>

for better results.

@weihaopeng
Copy link
Author

image

It works, though there are still some problems with rendering.


BTW, without msgroup, it won't parse in mathtype editor.

image

@weihaopeng
Copy link
Author

weihaopeng commented Jun 28, 2021

Depending on the business scenario, I'll see if it's necessary to pre parse before calling mathjax, or use mathjax2. Thank you for your reply. I hope mathjax will be better and better.

@dpvc dpvc added Code Example Contains an illustrative code example, solution, or work-around Ready for Development labels Jul 6, 2021
@dpvc dpvc self-assigned this Jan 11, 2022
@dpvc dpvc added this to the 3.2.1 milestone Jan 31, 2022
dpvc added a commit to mathjax/MathJax-src that referenced this issue Feb 2, 2022
Move mml3 filter to an mmlFilter so that forceReparse isn't needed. (mathjax/MathJax#2718)
@dpvc dpvc added Merged Merged into develop branch and removed Ready for Review labels Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Issue has been reproduced by MathJax team Code Example Contains an illustrative code example, solution, or work-around Fixed v3 v3.2
Projects
None yet
Development

No branches or pull requests

2 participants