Mico’s solution works, but here’s a more comprehensive set of options.
Traditional TeX used commands such as \mathit
, \mathrm
and \mathbf
both for words in math mode and also for math symbols. The unicode-math
package attempts to separate these two things. Compare:
\documentclass{article}
\usepackage{unicode-math}
\begin{document}
\noindent\texttt{\textbackslash mathit} \(\mathit{iff}\) \\
\texttt{\textbackslash symit} \(\symit{iff}\)
\end{document}
By default in fontspec
, \mathit
gives you the first (iff typeset as a word, not the product of the three math symbols i, f and f). As you’ve seen, it defaults to using the text font for \mathrm
, \mathit
and \mathbf
. Here are some ways to override that.
The Simple Fix
You’re using \mathit
and want it to behave like \symit
. There’s a unicode-math
package option for that, mathit=sym
.
\documentclass{article}
\usepackage[mathit=sym]{unicode-math}
\setmainfont{Arial}
\defaultfontfeatures{Scale=MatchLowercase}
\setmonofont{Fira Mono}
\setmathfont{Fira Math} % Or your math font of choice.
\begin{document}
\noindent Arial \textit{Italic} \\
\texttt{\textbackslash mathit} \(\mathit{iff} \) \\
\texttt{\textbackslash symit} \(\symit{iff}\)
\end{document}
Here. I used Fira Math as a sans-serif math font that matches reasonably well. You mentioned that you’re using any serif math font; the default for Office’s Equation Editor is Cambria Math.
If you still want to use words in math mode, and have them appear in the main text font, you can use the commands \textnormal
and \textit
in math mode.
If you’re using \mathit
this way, you might also expect \mathrm
and \mathbf
to work the same way, so the command you want might in fact be
\usepackage[mathbf=sym, mathit=sym, mathrm=sym]{unicode-math}
Say Precisely What You Mean
You want the behavior of \symit
, rather than the default behavior of \mathit
under unicode-math
, which isn’t precisely the same as the default behavior of \mathit
under other packages. Your code will be much less likely to break unexpectedly when you copy it into another document if you write \symit
or \textit
in your source, instead of the ambiguous \mathit
.
Change the \mathit
Font
The \setmathrm
command from fontspec
also lets you set the \mathit
, \mathbf
and \mathbfit
fonts, as the ItalicFont
, BoldFont
and BoldItalicFont
of \mathrm
:
\documentclass{article}
\usepackage{unicode-math}
\setmainfont{Arial}
\defaultfontfeatures{Scale=MatchLowercase}
\setmonofont{Fira Mono}
\setmathfont{Fira Math} % Or your math font of choice.
\setmathrm{FiraSans}[ Extension = .otf ,
UprightFont = *-Regular ,
ItalicFont = *-Italic ,
BoldFont = *-Bold,
BoldItalicFont = *-BoldItalic ]
\begin{document}
\noindent Arial \textit{Italic} \\
\texttt{\textbackslash mathit} \(\mathit{iff} \) \\
\texttt{\textbackslash symit} \(\symit{iff}\)
\end{document}
Use a Legacy Math Font
You don’t have to use unicode-math
. If you load fontspec
with the no-math
option, it will leave the existing definition of \mathit
unchanged. Here is one of the few combinations of legacy sans-serif math packages that works, more or less:
\documentclass{article}
\usepackage{newtxsf}
\usepackage[tx]{sfmath}
\usepackage[no-math]{fontspec}
\setmainfont{Arial}
\begin{document}
\noindent Arial \textit{Italic} \\
\texttt{\textbackslash mathit} \(\mathit{iff} \) \\
\texttt{\textbackslash textit} \(\textit{iff}\)
\( \displaystyle\int \frac{\partial y}{\partial t} \sum_{S} y(t) \)
\end{document}
Best Answer
If I understand your question correctly, you're asking why TeX uses different fonts for (Latin-alphabet) letters and numbers depending on whether they are set in text or math mode. Put differently, if a well-designed math font happens to contain all letters, digits, and punctuation marks that can possibly occur in text mode settings, why not use this math font for text mode too? Why use two different fonts in such cases? (Of course, math frequently also requires symbols -- e.g., summation and integral symbols, fraction bars, and primes -- which don't occur in text mode at all. I take it that symbol fonts are not a part of your question.)
You already mention one reason for having different fonts: Text fonts frequently provide ligatures for character pairs and triples such as
ff
,fi
,fl
,ffi
,ffl
, possibly also forft
,fft
,fj
,fh
,ct
,st
,sp
, etc. In math mode, replacing these character pairs and triples with ligatures is almost certainly undesirable.A second, and probably more important, reason, for having separate fonts is that the side bearings around letters can (and should!) differ considerably depending on whether they occur in text or math mode. Consider the character strings
fly
andoffice
; in the following example they're first set in text italic mode, with ligatures suppressed via\kern0pt
instructions, and then in math italic mode. (The vertical bar is provided to indicate the left-hand edge of the text block.)(Point two, continued.) Observe that in text-italic mode, the letter f actually has a negative left-hand side bearing, so that its descender can "encroach" into the space occupied by the preceding character or interword space; its right-hand side-bearing seems to be pretty much zero, so that it touches subsequent characters such as l. In contrast, in math-italic mode the left-hand side bearing of f is zero and its right-hand side bearing is positive. I suppose this is done so that if and when the character combinations
ff
andfl
occur in math mode, it'll be abundantly clear that we're dealing with the products of one-letter variables namedf
andl
, respectively, rather than with two-letter variables namedff
andfl
. To be extra-super clear, some people may resort to writingf\cdot f
andf\cdot l
. If the math font is designed correctly, it shouldn't be necessary to do so.Observe that the spaces between "l" and "y", "f" and "i", "i" and "c", and "c" and "e" are also greater in math mode than they are in text mode. This is true not only for the font family used in the example above (
newtx
) but for all well-designed font families that have both text and math modes.The issue of setting the side bearings differently in text and math mode contexts extends to punctuation marks: Characters such as
,
(comma),:
(colon),;
(semi-colon), and!
(exclamation mark/factorial) generally have different meanings in text and math mode; the spacing around them reflect the context in which they occur. (Note that I'm not talking about symbols such as+
and=
which usually occur only in math mode. The appearance of the latter two symbols in text mode is generally a signal of poor typography.)Third, using different fonts for text and math provides an important degree of freedom from the point of view of document design: Even though you, personally, may be content using the same font family (e.g., Computer Modern, Latin Modern, newtx, or newpx) for both text and math material, others may not. E.g., somebody might prefer to use
newpxtext
(a Palatino clone) withnexpxmath
, whereas someone else might prefer to combine it witheulervm
. To provide this degree of design freedom, it's almost certainly necessary to store math and text fonts in separate files.Finally, here's the code used to generate the example shown above.