Sans serif Fonst

12 views
Skip to first unread message

Balint Toth

unread,
Sep 23, 2025, 5:23:57 AM (11 days ago) Sep 23
to MathJax Users
Greeting, MJ Community!

I've started to use MJ v4.0 in documents, which have Latin Modern Sans serif font family.

Therefore, I set the MJ font to mathjax-modern fonts (A version of Latin-Modern), but MJ uses the "Roman variant". I've read in the supported commands page that \textsf and \mathsf will do the job, but it's not an effective way to do that manually.

Is there an elegant way to render all characters to Sans Serif in all formulas, while I use  mathjax-modern fonts? I tried the following code, which i've found in this group chat, and it worked perfectly for TeX fonts,:

https://groups.google.com/g/mathjax-users/c/sTP-zoQD6kU/m/qFnnBe0SBAAJ

CODE:

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();
    }

I've already tried mathjax-fira (A version of the Fira and Fira-Math fonts (a sans-serif font)), but i prefer the latin modern.

Kind regards:
Balint

Davide Cervone

unread,
Sep 25, 2025, 7:46:03 AM (8 days ago) Sep 25
to mathja...@googlegroups.com
Balint:

The configuration you give below works for me with mathjax-modern, so I'm not sure if you are asking for a different method or whether you are having trouble with this one.

I would recommend sticking with mathjax-newcm for this, as its glyphs are very close to the Latin Modern ones, but with more coverage.  in particular, mathjax-newcm has coverage for the lower-case Greek letters, while mathjax-modern does not, if that makes a difference to you.

The reason that the mathjax-modern font is serifed is because the Latin Modern math font is serifed, so all the math symbols (like summation signs and things like braces and parentheses) are serifed, and it looks strange to have a sans-serif font mixed with those.  Your configuration will use sans-serif characters when they are available, but not everything has sans-serif versions.

Currently, mathjax-fira is the only sans-serif font available in MathJax.  There are a few other fonts with sans-serif math characters, and we will be able to make some of those available in the future, but for now, either Fira or the configuration approach you have already cited are the only alternatives.

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 visit https://groups.google.com/d/msgid/mathjax-users/55d71fea-3138-4ef1-973c-32bad9d8f75cn%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages