MathJax icon indicating copy to clipboard operation
MathJax copied to clipboard

Rendering error in SVG inline of \frac

Open kno10 opened this issue 2 years ago • 3 comments

<html>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/tex-svg.js"></script>
\(\frac{1}{123456789}=\)
\[\frac{1}{123456789}=\]
</html>

It appears to work fine with CHTML output. With SVG output, the frac overlaps the equals sign. The display math below is fine.

It is supposed to look as with earlier MathJax: $\frac{1}{123456789}=$

Fiddle: https://jsfiddle.net/pgce2bj5/

kno10 avatar Nov 21 '23 10:11 kno10

Thanks for this report. This seems to be connected to the in-line line breaking, so turning that off is a work-around for now. I'll look into it further and see what I can do.

dpvc avatar Nov 21 '23 16:11 dpvc

Thank you. My current workaround was manual, using \)\(.

MathJax = { output: { linebreaks: { inline: false } } }; makes this issue disappear.

kno10 avatar Nov 22 '23 09:11 kno10

It turns out that MathJax was descending too far into the internal MathML tree when looking or the position of the potential inline breaks, and rather than stopping at the fraction, continued into the fraction and through the break was in the numerator. Because the scaling factor for the node where the break occurs in used to determine the size of the SVG used for the piece between line breaks, it was getting the wrong scaling factor (the scale of the numerator instead of the fractions as a whole) leading to the fraction no getting the proper width.

I have made a PR to resolve the problem. I the meantime, here is a configuration that you can use to patch the incorrect function:

MathJax = {
  startup: {
    ready() {
      const {CommonWrapper} = MathJax._.output.common.Wrapper;
      const getBreakNode = CommonWrapper.prototype.getBreakNode;
      CommonWrapper.prototype.getBreakNode = function (bbox) {
        if (!bbox.start) return [this, null];
        return getBreakNode.call(this, bbox);
      }
      MathJax.startup.defaultReady();
    }
  }
};

dpvc avatar Nov 24 '23 16:11 dpvc