Re: [mathjax-users] Fonts

31 views
Skip to first unread message

Davide Cervone

unread,
Jan 24, 2023, 3:40:45 PM1/24/23
to mathja...@googlegroups.com
MathJax 3 currently only supports one font, the usual MathJax TeX fonts, but version 4 (currently in alpha release) provides 11 fonts to choose from, and one of them is a sans-serif font (mathjax-fira).  But the MathJax TeX fonts do include sans-serif characters, and it is possible to use those for letters and numbers in v3.  The following configuration does that:

MathJax = {
  startup: {
    ready() {
      const CommonWrapper = MathJax._.output.common.Wrapper.CommonWrapper;
      const getVariant = CommonWrapper.prototype.getVariant;
      const remap = {
        normal: 'sans-serif',
        italic: 'sans-serif-italic',
        bold: 'bold-sans-serif',
        'bold-italic': 'sans-serif-bold-italic',
        '-tex-mathit': 'sans-serif-italic'
      };
      CommonWrapper.BOLDVARIANTS.bold.normal = 'bold-sans-serif';
      CommonWrapper.BOLDVARIANTS.bold.italic = 'sans-serif-bold-italic';
      CommonWrapper.BOLDVARIANTS.normal.bold = 'sans-serif';
      CommonWrapper.BOLDVARIANTS.normal['bold-italic'] = 'sans-serif-italic';
      CommonWrapper.ITALICVARIANTS.italic.normal = 'sans-serif-italic';
      CommonWrapper.ITALICVARIANTS.italic.bold = 'sans-serif-bold-italic';
      CommonWrapper.ITALICVARIANTS.normal.italic = 'sans-serif';
      CommonWrapper.ITALICVARIANTS.normal['bold-italic'] = 'bold-sans-serif';
      CommonWrapper.prototype.getVariant = function () {
        getVariant.call(this);
        this.variant = remap[this.variant] || this.variant;
      };
      MathJax.startup.defaultReady();
    }
  }
}

If you are using version 2, then using

<script type="text/x-mathjax-config">
MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
  var VARIANT = MathJax.OutputJax["HTML-CSS"].FONTDATA.VARIANT;
  VARIANT["normal"].fonts.unshift("MathJax_SansSerif");
  VARIANT["bold"].fonts.unshift("MathJax_SansSerif-bold");
  VARIANT["italic"].fonts.unshift("MathJax_SansSerif-italic");
  VARIANT["-tex-mathit"].fonts.unshift("MathJax_SansSerif-italic");
});
MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
  var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;
  VARIANT["normal"].fonts.unshift("MathJax_SansSerif");
  VARIANT["bold"].fonts.unshift("MathJax_SansSerif-bold");
  VARIANT["italic"].fonts.unshift("MathJax_SansSerif-italic");
  VARIANT["-tex-mathit"].fonts.unshift("MathJax_SansSerif-italic");
});
</script>

somewhere BEFORE the script that loads MathJax.js itself would do something similar.

I'm not sure what you mean by "change the font for the entire document" unless it means change the MathJax font for every expression all at once.  The code samples above do that.  If you mean change the text font used by the document, you would use normal CSS rules for that.

Davide



On Jan 24, 2023, at 12:58 PM, Mastermaticus <master...@gmail.com> wrote:

Is there a way to write a script so that I can write mathematical expressions in sans serif format automatically?
Also, how can you change the font for the entire document?
Thank you very much for your time and attention.

--
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/74fd4616-c41c-4b7b-a25e-88ee6f3f5d84n%40googlegroups.com.

Mastermaticus

unread,
Jan 27, 2023, 12:07:42 PM1/27/23
to MathJax Users
Thank you.

Mastermaticus

unread,
Feb 14, 2023, 1:53:43 PM2/14/23
to MathJax Users
Hello again!

I meant change the MathJax font for every math expression all at once. For example, I would like to write all math expressions with the command mathsf.

I'll use this code and write with the results.

Thank you.

El martes, 24 de enero de 2023 a las 21:40:45 UTC+1, Davide Cervone escribió:

Mastermaticus

unread,
Feb 14, 2023, 2:00:17 PM2/14/23
to MathJax Users
Hello!

I'm using eXe, but the script is written inside the code of eXe. How could I add this code?

Thank you,

Davide Cervone

unread,
Feb 14, 2023, 4:18:28 PM2/14/23
to mathja...@googlegroups.com
It looks like this is where the MathJax configuration is:


so you could modify that, but the comments suggest that you can

Change this from your Style or your elp using $exe.math.engine="..."

I'm not sure what that means, but it looks like there may be a customization file ("elp"?) where you can set a variable ($exe.math.engine) that holds the MathJax configuration without having to modify the code for eXe (which would be a good thing).  So you should try that method, if that makes sense to you.  You may need to copy for the configuration in the link above, and add to it the configuration that I gave you below.

See if you can get that to work.  Otherwise, you may need to ask the eXe community how to make changes to the MathJax configuration properly.

Davide


Mastermaticus

unread,
Feb 15, 2023, 6:07:17 PM2/15/23
to MathJax Users
Ok. Thank you for your help.
Reply all
Reply to author
Forward
0 new messages