The Literal Answer
As of 2019, fontspec
should find the bold and italic fonts, and load \mathrm
, \mathbf
and \mathit
when you \setmathrm
.
If you need additional set-up for \mathit
, the ItalicFont
and ItalicFeatures
options of \setmathrm
set up \mathit
, just as the Boldfont
and BoldFeatures
options set up \mathbf
.
\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{fontspec}
\usepackage[paperwidth=10cm]{geometry}
\setmainfont{TeX Gyre Schola}
\setmathrm{TeX Gyre Schola}[
ItalicFeatures = {Color = green}]
\begin{document}
Text \textit{italic} \(\mathrm{math}\) \(\mathit{italic}\)
\end{document}

What You Also Might Have Meant
In practice, someone asking about how to set the \mathit
alphabet likely means the alphabet used for $x$
.
To set that, you want to load the unicode-math
package, set a math font that matches your main font and then, if necessary, add a line such as
\setmathfont[range=it]{Gotham Book Italic}
You can do likewise for up
, bfup
, bfit
and the other math alphabets.
In unicode-math
, you would normally use \symit
, \symup
, etc. for individual letters used as variables, and \mathit
, \mathrm
, \mathup
, etc. for complete words. However, you can give a package option to interpret \mathit
as \symit
and make migrated code compile correctly.
mathspec
is replaced byunicode-math
. commands like\setmathrm
are very limited.mathastext
package.