# Use text font for punctuations in xelatex with unicode-math

Suppose I have the following declarations in the preamble

\usepackage[utf8]{inputenc}
\usepackage{unicode-math}

\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?

Thanks!

• 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 Mar 11 '19 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 Mar 11 '19 at 12:57

You can use the range option to exchange chars.

\documentclass{article}
\usepackage{unicode-math}

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

$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

\end{document}


• 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 Mar 11 '19 at 13:27
• What do you mean? TeX Gyre Termes in my example is normal text font. – Ulrike Fischer Mar 11 '19 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 Mar 11 '19 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 Mar 11 '19 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. – Ulrike Fischer Mar 11 '19 at 16:27