2

I'm using a scrartcl document class and LuaLatex to write an article which contains math equations. I am required to use Arial as my main text font, which I've set using the package fontspec (to "unlock" the Arial font) and \setmainfont{Arial}. I can use "any" serif font for equations, so I've kept the default one.

Whenever I encounter multi-letter variables I'd like to use \mathit{} to avoid having space between each letter and still keep it in italics, but unfortunately then the font changes to Arial, instead of the math mode font:

result1

As I understand mathit is not supposed to change the font. I've tried to force the math font to change using \setmathrm{Asana-Math} (I don't have to use this one specifically, Asana Math is just the first font I've encountered in this document under "Math fonts"), but then the normal math mode is still in the default font and everything else in Asana-Math WITHOUT italics (even mathit), see result:

result2

\documentclass[12pt,a4paper]{scrartcl} 
\usepackage{fontspec} % get additional fonts
\setmainfont{Arial} % sets the main font for the document
\setmathrm{Asana-Math} % change math mode font; only used in second result
\begin{document} 
    Normal text.
    
    $f = MATHMODE$ 
    
    $\mathit{f = mathit}$
    
    $\mathrm{f = mathrm}$
\end{document}

How can I have control over both my main text font and the math mode font? How can I get both the math mode and the result of \mathit{} in my desired math font and in italics?

1
  • Welcome to TeX.SE.
    – Mico
    Mar 14, 2022 at 20:50

2 Answers 2

4

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}

Latin Modern sample

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}

Arial + Fira sample

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}

Arial + Fira sample

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}

Newtxsf + Arial

2

First, do load the unicode-math package (which, incidentally, loads fontspec automatically). Second, I suggest you replace the legacy commands \mathit and \mathrm with \symit and \symrm (which, you guessed it, are provided by the unicode-math package).

enter image description here

\documentclass[12pt,a4paper]{scrartcl} 
\usepackage{unicode-math} % loads fontspec automatically
\setmainfont{Arial} % sets the main font for the document
\setmathfont{Latin Modern Math}[Scale=MatchLowercase]
\begin{document} 

\obeylines % just for this test document
Normal text.
$f = MATHMODE$ 
$\symit{f = mathit}$
$\symrm{f = mathrm}$
$\mathit{f = mathit}$
$\mathrm{f = mathrm}$

\end{document}

Addendum: The unicode-math package offers the following five new basic commands: \symup (alias: \symrm), \symit, \symbf, \symsf, and \symtt. There are quite a few additional new commands, listed in Table 1 of the package's user guide. Here's a screenshot of Table 1:

enter image description here

3
  • Thanks for this! I've tried it and found that the normal math mode and \symit look exactly the same (if I use the same example word, I should've done that earlier). The original reason why I did this was to have the characters of multi-letter variables close together, like a normal text (but still in math mode font and italics). This is particularly an issue for variables in all capital letters. It this possible in any way? Or is it a general restriction of the font? Mar 15, 2022 at 11:37
  • Is the \symrm command undocumented? I have used it in the past and it works, but now I cannot find it in the unicode-math package documentation for some reason. Jun 23, 2022 at 20:49
  • @ApoorvPotnis - It's true that \symrm is not documented the user guide of the now-current version of unicode-math (viz., 2020/01/31 v0.8q). I can only guess that I learned about \symrm some time ago, while using an older version of the package. FWIW, \symrm and \symup do seem the produce the same output if a serif math font is in use. (I don't think I have any sans-serif math fonts; hence, I can't check the conjecture for a sans-serif math font...)
    – Mico
    Jun 23, 2022 at 21:01

You must log in to answer this question.

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