mathjax / MathJax

Beautiful and accessible math in all browsers
http://www.mathjax.org/
Apache License 2.0
10.12k stars 1.16k forks source link

Spacing issue around parenthesis when explorer accessibility is turned on #2881

Open henok-outlier opened 2 years ago

henok-outlier commented 2 years ago

Issue Summary

When the accessibility explorer is activated, there's a spacing issue. The spaces after 'f', 'M', and 'cos' are way too big, and I can't figure out how to make them look right. It's important that those spaces are small for readability reasons, since (for instance) "M(x)" is a single object, not two separate things as "M (x)" might suggest.

Current behavior

Screen Shot 2022-05-31 at 12 20 33 AM

Expected behavior

Screen Shot 2022-05-31 at 12 21 15 AM

Steps to Reproduce:

  1. Open https://jsbin.com/bohitetaka/edit?html,js,output
  2. Check how math expression is displayed by making accessibility explorer property to false and true.

When explorer is set to false the spacing is correct, but I also want the accessibility feature.

Technical details:

Supporting information:

https://jsbin.com/bohitetaka/edit?html,js,output

dpvc commented 2 years ago

This is due to the fact that the explorer uses semantic-enrichment that modifies the underlying MathML for the expression, and that adds mrows around the parentheses, which in turn causes MathJax to interpret the parentheses as though they came from \left...\right, which are spaced differently.

This was fixed in v3.1.3 via mathjax/MathJax-src#583, but the fix has not been back-ported to v2.7.

For now, you can use the following configuration to work around the issue:

MathJax.Hub.Register.StartupHook('MathML Jax Ready', function () {
  var PARSE = MathJax.InputJax.MathML.Parse;
  PARSE.Augment({
    _AddChildren: PARSE.prototype.AddChildren,
    AddChildren: function (mml, node) {
      this._AddChildren(mml, node);
      if (mml.type === "mrow" && (mml.open || mml.close)) {
        if (mml.open && !mml.data[0].stretchy) delete mml.open;
        if (mml.close && !mml.data[mml.data.length-1].stretchy) delete mml.close;
      }
    }
  });
});
henok-outlier commented 2 years ago
MathJax.Hub.Register.StartupHook('MathML Jax Ready', function () {
  var PARSE = MathJax.InputJax.MathML.Parse;
  PARSE.Augment({
    _AddChildren: PARSE.prototype.AddChildren,
    AddChildren: function (mml, node) {
      this._AddChildren(mml, node);
      if (mml.type === "mrow" && (mml.open || mml.close)) {
        if (mml.open && !mml.data[0].stretchy) delete mml.open;
        if (mml.close && !mml.data[mml.data.length-1].stretchy) delete mml.close;
      }
    }
  });
});

@dpvc thanks, I'm thinking the last statement array call is stretchy instead of sretchy. And we don't need the 394 number.

dpvc commented 2 years ago

Quite correct. Sorry about the typos and copy/paste artifact!