mtextInheritFont causes text subscript spacing issue

33 views
Skip to first unread message

David Farmer

unread,
Oct 18, 2021, 4:34:36 PM10/18/21
to mathja...@googlegroups.com

This page has "mtextInheritFont: false", and things look fine:

https://aimath.org/~farmer/tmp/textinheritfalse.html

This one has "true" and is identical otherwise. There is extra space
after the \text{...} which occur in a subscript.

https://aimath.org/~farmer/tmp/textinherittrue.html

For \text{...} outside a subscript, it looks the okay but the font sizes
are different.

If I eliminate the inline style:

mjx-utext {
display: inline-block;
}

then the spacing is okay.

Is it reasonable for me to just add css to set display: inline on those
elements? If I do it only when inside a mjx-msub then it seems unlikely
there will be undesirable side-effects.

Regards,

David

Davide Cervone

unread,
Oct 21, 2021, 11:19:47 AM10/21/21
to mathja...@googlegroups.com
David:

Thanks for reporting the issue.  It turns out that this is due to a workaround for a Safari bug.  MathJax needs to add an explicit width to the mjx-utext node in to avoid a rendering error in Safari, but MathJax is neglecting to scale the size properly for subscripts (or other scaled content).

A work-around would be the following configuration:

MathJax = {
  chtml: {
    mtextInheritFont: true
  },
  startup: {
    ready() {
      const {CHTMLTextNode} = MathJax._.output.chtml.Wrappers.TextNode;
      const {CHTMLWrappers} = MathJax._.output.chtml.Wrappers_ts;
      
      CHTMLWrappers[CHTMLTextNode.kind] = class extends CHTMLTextNode {
        toCHTML(parent) {
          super.toCHTML(parent);
          if (this.parent.variant === '-explicitFont') {
            const adaptor = this.adaptor;
            const node = adaptor.lastChild(parent);
            if (!adaptor.getStyle(node, 'width')) return;
            const metrics = this.jax.math.metrics;
            const scale = this.parent.getBBox().scale;
            const width = this.getBBox().w * metrics.em * metrics.scale * scale;
            adaptor.setStyle(node, 'width', Math.round(width) + 'px');
          }
        }
      }
      
      MathJax.startup.defaultReady();
    }
  }
};

It appears, however, that recent versions of Safari no longer have the bug, so you could use

mjx-utext {
  width: initial ! important;
}

to have these widths ignored if you don't care about older versions of Safari.  I don't know about the status of this bug in other WebKit-based browsers, but I assume some of them will also have the problem that these widths are supposed to be fixing.

Davide


--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mathjax-users/alpine.LRH.2.21.2110181619370.30351%40li375-150.members.linode.com.

Reply all
Reply to author
Forward
0 new messages