mtextInheritFont causes text subscript spacing issue

Skip to first unread message

David Farmer

Oct 18, 2021, 4:34:36 PM10/18/21

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

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

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.



Davide Cervone

Oct 21, 2021, 11:19:47 AM10/21/21

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) {
          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');

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.


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
To view this discussion on the web visit

Reply all
Reply to author
0 new messages