Suppose I have the following declarations in the preamble


\setmathfont{My Best Math Font}
\setmainfont{My Best Font}

and then some texts like so in the document:

$X, Y$ vs. $X$, $Y$

the commas within math and non-math environments will be different.

Is there anyway to make the math environment to use My Best Font for punctuations?


  • Personally I don't think you should do that. Assume that your main font is Helvetica and your math font is Computer Modern Serif. It is easy to see the difference then. Doing like so will make your document inconsistent.
    – user156344
    Commented Mar 11, 2019 at 12:51
  • @JouleV Essentially I don't have the math font for the text font I'm using, but they are really very close. So I just want the punctuations to match better.
    – QcH
    Commented Mar 11, 2019 at 12:57

1 Answer 1


You can use the range option to exchange chars.


\setmathfont{Fira Math}
\setmainfont{TeX Gyre Termes}

$X, Y $ X, Y

%should go in the preamble, in the body only for the example 
\setmathfont[range={44}]{TeX Gyre Termes}
\setmathfont[range=\int]{Fira Math}

$X, Y $ X, Y


enter image description here

  • Thanks a lot! It seems like the solution only works when the text font I use also supports unicode math. But it's not the case (which is the reason why I have to use a different font). Is there any work around?
    – QcH
    Commented Mar 11, 2019 at 13:27
  • 1
    What do you mean? TeX Gyre Termes in my example is normal text font. Commented Mar 11, 2019 at 13:31
  • My bad. For some reason, when I do ``` \setmathfont[ Extension={.otf}, range={44}, Path=./Stix2/ ]{STIX2Text-Regular} ``` it doesn't use the font from Stix2 but from the default math font I set.
    – QcH
    Commented Mar 11, 2019 at 16:01
  • Now I understand. I had another \setmainfont later on, which is only for version=bold, but somehow it undoes the effect of this range setting. If I load otf fonts from local folder using setmathfont, is it possible to have different versions for bold/etc. along with the range setting like above? I mimic the syntax of setmainfont but xelatex always complains that font cannot be found.
    – QcH
    Commented Mar 11, 2019 at 16:25
  • If you have new question, don't do it in the comment. Ask a new question. And show a real minimal example. Commented Mar 11, 2019 at 16:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .