mtextFontInherit & scale interactions

43 views
Skip to first unread message

Sébastien Boisgérault

unread,
Aug 16, 2016, 4:20:00 PM8/16/16
to MathJax Users

Hi everyone,

Say that for a better integration between a given font and the math font, I use a scale of 90% for MathJax.
The font is Alegreya; MathJax does a perfect job of matching the x-heights, but with this setting,
the math font "feels" a bit larger in my opinion. The scaling of 90% is supposed to improve this.

Now, if I set mtextFontInherit to true, the font of mtext elements into the math formulas will identical to the
document font, which is nice for consistency !
But it will also be subject to the 90% scaling, thus it won't be integrated as nicely (not to mention that in
a paragraph with inline formulas we will have the same font with two different sizes ...).

Is there a known method to reverse the effect of the scaling for mtext elements (say for the CommonHTML output) ?

I tried to inspect the generated HTML, but the font-size differs from 100% in at least two parents of any such text,
and the final scale factor is the product of these numbers. So it's not simply a matter of finding the mtext and
unset its font-size ...

Cheers,

SB

Davide Cervone

unread,
Aug 17, 2016, 8:37:59 AM8/17/16
to mathja...@googlegroups.com
I understand your desire to try to make the fonts look as good as possible for you, but I should point out that font tendering technology differs from OS to OS, and even browser to browser with the same OS.  So what the result looks like for you may not be what it looks like for others, and making it look better for you may make it look worse for others.  For example, here is an example using Alegreya in Firefox on Mac OS X at 100%:

        

The size and weight seem quite appropriate to me.  The bottom line of x's alternate between non-math x's and $\text{x}$ math text x's.  These seem to match very well.

On the other hand, here is 90% scaling:

        

As you can see, the math is too small, and the line of X's make that rather clear.

So setting the scale to 90%, while it may look better for you, will make it look worse for me.  in my experience, the kind of micro-managing that you are trying to accomplish usually is counter-productive in the long run.  One of the reasons that the scaling factor is settable in the MathJax contextual menu is so that individual users can set it to what they like.  My recommended solution for you is to leave the scaling factor at 100 for your site, and to use the menu to set it to 90% for you personally.  Alternatively, you could set the scaling factor based on the browser/OS combination, but such arrangements are notoriously fickle (and as browsers and OSes change, they require upkeep).

Be that as it may, you are correct that, even with mtextFontInherit, the text font will be scaled to match the size of the MathJax font.  If you want to prevent that, here is one possibility.  Add the following

<script type="text/x-mathjax-config">
MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
  var CHTML = MathJax.OutputJax.CommonHTML,
      MML = MathJax.ElementJax.mml;
  var TOCHTML = MML.mtext.prototype.toCommonHTML;
  MML.mtext.Augment({
    toCommonHTML: function () {
      this.mathsize = 100/CHTML.config.scale;
      return TOCHTML.apply(this,arguments);
    }
  });
});
</script>

to the page just BEFORE the script that loads MathJax.js itself.  This will cause mtext elements to set their size so that it undoes the scaling factor.  (Note that if you are using MathML input, this will override any mathsize setting already in place.  It could be made more sophisticated if that is a problem.  If you are using TeX input, it should not be an issue.)

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.
For more options, visit https://groups.google.com/d/optout.

Sébastien Boisgérault

unread,
Aug 20, 2016, 4:29:06 PM8/20/16
to MathJax Users

Davide,

Thanks for your time and your detailed answer.

I only considered the variation of the rendering for a very limited set of browser/OS platforms.
I was aware of the differences in the rendering (in my experience Firefox performs a much better job with Linux that with Windows for example),
but I naively assumed that it was "good enough" to select a scale factor anyway ...
Your example proves otherwise. Thanks for setting this up and sharing!

I will probably have a look at the online services that generate screenshots of web pages for large sets of platforms
to get a better grasp of the differences in the rendering ; I guess that I'll end up following your advice and unset the scale factor!

Regards,

SB
Reply all
Reply to author
Forward
0 new messages