I have a document whose main font is a sans serif font (Arial if you must know), but whose math mode uses a serif font. They look quite different.

So far, my documents which don't switch looks like this, and I've always used \mathit{} or \mathrm{} in order to fix the spacing in multi-letter expressions such as subscripts. However, after switching fonts (which I am obliged to, this is the official template...), I'm discovering that \mathit{}, notwithstanding the "math" in its name does not actually use the math font but the text font, and suddenly all my multi-letter expressions (especially words or acryonyms in subscripts) look like I'm a five year-old who just discovered they can switch fonts every five words to make it look "more interesting".

I've looked around and found a few topics here:

Typesetting multi-letter variable names in math mode

Problem formatting a subscript in math mode

Difference between \mathit and math-style = TeX

Especially that last one explains that apparently \mathit{} is meant to use the plain text font? \textit{} definitely uses the plain text font, too. So... what then do I need to use to keep using the math font but change the kerning to get a group of letters to look like one word/acronym instead of multiple symbols, without defacing my document?

I've also found some useful hints about the unicode-math package via this question but as far as I can tell right now, the \symit{} and \symrm{} commands, although they stick to the math font, will also stick to the same spacing -- which has me scratching my head about what they are actually for, but that's a different question.

Examples: (requires \usepackage{unicode-math} and \usepackage{tabto})

    single: \tab   $m_k$ \tab           $m_O$\\
    multiple: \tab $tsfc_{ref}$\tab     $m_{OEM}$\\     
    symit: \tab    $\symit{tsfc}_{\symit{ref}}$\tab $m_{\symit{OEM}}$\\
    mathit:\tab    $\mathit{tsfc}_\mathit{ref}$\tab $m_\mathit{OEM}$\\
    text:\tab      $\text{tsfc}_\text{ref}$ \tab    $m_\text{OEM}$\\
    textsf:\tab    $\textsf{tsfc}_\textsf{ref}$\tab $m_\textsf{OEM}$\\
    textrm:\tab    $\textrm{tsfc}_\textrm{ref}$\tab $m_\textrm{OEM}$\\
    mathsf:\tab    $\mathsf{tsfc}_\mathsf{ref}$ \tab$m_\mathsf{OEM}$\\
    mathrm:\tab    $\mathrm{tsfc}_\mathrm{ref}$ \tab$m_\mathrm{OEM}$\\
    manual:\tab    $t\!s\!f\!c_{r\!e\!f}$\tab    $m_{O\!E\!M}$\\

differently-formatted multi-letter variables and subscripts. They're all either in sans-serif or spaced awkwardly

The first line shows what regular single-letter expressions and subscripts look like. None of the other ones looks okay to me, next to that. The last line uses manual negative spaces to get the letters a bit closer together, but this is a very blunt tool and while it happens to kind-of work for the capital-letter expressions, it really does not for the lowercase ones.

So far, \mathit{} (or sometimes \mathrm{}) has been my go-to solution but with text and math fonts looking so differently, it's really not doing it. For better or worse, there are a lot of multi-letter variables in my discipline (I know, I don't like it but that's how it is), and I want them to make clear those letters form a unit, but I really don't want them to look like prose, and entirely out of place.

==> is there any command that uses the math font (upright or italic it not that important to me anymore...) but spaces the letters like normal text?

...or could this possibly be an issue with the choice of math font in my document? The text font is specified explicitly, but I haven't (yet) found out where the math fond is specified in the class. What I did find: \setmainfont{Arial}, \setmathsf{Arial} and \setmathtt{Arial}. Commenting out the last two did not help, and leaving them in still produces serifs in all mathematical expressions (unless I wrap them in formatting commands, of course).

I prefer to keep serifs in the math font, but I'd like to be able to use kerning in multi-letter variables or subscripts.

  • 1
    If it is a named index, then IMO it should always be upright. Best thing to do is to make a macro for it, say, \stxt and then use that. Then you can control from the preamble what is the best choice for your document. One might argue that it should be the up version of the text font, aka \textup, as it then better follow the current text choice. For example in beamer \mathrm is not correctly set to be equal to \mathsf, so \mathrm would be wrong in a standard beamer doc. Therefore define a macro to use in the document, and control it from the preamble.
    – daleif
    Commented May 10 at 10:41
  • the math font has no information or glyphs suitable for multi-letter words, so your choice for an italic word is to use \mathit (which should be set up to use an italic font compatible with your math font) or \textit which should use the italic font used in the non math part. If you are using some custom font setup perhaps one or both of \mmathit or \textit is not set up correctly, that could be fixed but we would need more information Commented May 10 at 10:49
  • @DavidCarlisle what I worked out so far is that if I comment out \setmainfont{Arial} in the .cls file, my whole text has serifs and \mathit indeed behaves as I would like it to. In that case, the characters become visually indistinguishable from the other math expressions but with closer spacing, as I want it. They are then also equal to what \textit produces outside of a math environment. So the question remains: How to I make sure that \mathit produces the same shapes as the math font, independent of the text font? Or: Where do I need to dig to find out?
    – Zak
    Commented May 10 at 11:15
  • You can't ensure that in general. Most math fonts are derived from a text italic font and you need to choose that font, eg by default the math is in latin modern math, and you therefore want latin modern italic. If you have changed the math to say TeX Gyre Termes math, then you want to use TeX Gyre Termes Italic, but the name association is not always so simple and you need to make a choice, eg if using Stix Two math you might still want TeX Gyre Termes Italic as they are both "Times Roman" in style Commented May 10 at 11:33
  • 1
    You really should always provide a test document, anyway I have posted an answer that would apply to most cases, but uses unicode-math in the example. Commented May 10 at 12:58

2 Answers 2


If I understand you correctly you are using latin modern math with Arial text, and want the second of the examples below, rather than the first.

enter image description here




\DeclareMathAlphabet  {\mathlmit}      {TU}{lmr}{m}{it}%
\SetMathAlphabet      {\mathlmit}{bold}{TU}{lmr}{bx}{it}%


deff \textit{deff}
$ d+e+f + deff_{deff} + \mathit{deff}_{\mathit{deff}} $


deff \textit{deff}
$ d+e+f + deff_{deff} + \mathlmit{deff}_{\mathlmit{deff}} $


  • This would work for me, too. Only drawback is that it would require me to replace all (or maybe just most... not sure) occurrences of \mathit with \mathmlit. Also, I would not know how to apply this method if I were using a different math font. To be fair, though, it took me a lot of time to figure out that I'd need Latin Modern Roman as a complement to Latin Modern Math. Had to go and look them up in the system font list. I had not specified latin modern at all, it was simply the default. So without your hint I'd had no idea what font I was looking at...
    – Zak
    Commented May 10 at 13:22
  • @Zak yes original plan was to declare \mathit that way but unicode-math goes to some lengths to reset this very late and I decided to post a simple version that worked ratherthan lots of code trying to defeat Will's code, but I hadn't noticed that \setmathrm set both mathrm and mathit so your version is simpler Commented May 10 at 13:30

Thanks a lot to David Carlisle, whose comments (and my search for answers to his questions) helped me figure a few things out that were unclear to me before, and/or which I had not seen stated explicitly elsewhere:

  1. The font used by \mathit (or \mathrm and \mathsf) is not the math font even if the letters look exactly the same. That's because the math font uses different spacing than text, and kerning/specing appears to be baked into the font file and is not just a setting.
  2. By default, the letters produced are however visually identical to the default math font. That is: If the default math font has serifs, \mathrm should produce the same letters (and \mathit the italic version of the same font). \mathsf can be used in the same way if the math font is sans-serif.
  3. Importing the fontspec package can mess with this, and it appears that without further measures (at least in my case...), it causes the \mathrm font (and therefore \mathit) to follow whatever font is set with \setmainfont{}. This seems to be independent of whether the main font is sans-serif or not.

I found three solutions:

1: with unicode-math

If unicode-math is imported, I can directly specify the math font, using \setmathfont. This command is not available otherwise. It lets me explicitly specify which fonts each of the other commands should use, and make sure that they are compatible:

    \setmainfont{Comic Sans MS} % for comic relief, and to make really obvious which font is used where
    \setmathfont{Libertinus Math} % looks like Libertinus Serif, but makes math
    \setmathrm{Libertinus Serif}  % The corresponding font for normal text
    \setmathsf{Libertinus Sans} % in case I wanted to use sans in math

resulting output from the example above. mathit finally does what I wanted, and so does mathrm!

Yay! \textit and \mathit are visually distinct, and \mathit matches the look of plain math but adds the kerning! \textsf is still using some other font, but I don't care right now. I have a report to finish.

2: Without unicode-math but with fontspec

As remarked somewhere here, there is an option to fontspec called no-math. fontspec is required by the class I'm using, and adding the option to the respective line in the class definition (like so:\RequirePackage[no-math]{fontspec}) removed the issue as well:

again, \math* matches the look of the math font now!

This required no further font definitions on my end. The .cls file specifies \setmainfont{Arial}, \setmathsf{Arial} and \setmathtt{Arial}, and at least the sf definition seems to be without effect (since the mathsf line in the screenshot is not using Arial but something else), but \mathit looks exactly as the math font (but with kerning), and \mathrm is using a serif font that is at least not visually at war with the regular math font.

Since \setmathfont is not available in this case, I'm not sure how I could change the math font in this configuration, or whether I would then need to adapt the \math* font selection manually in that case, but I think I'm okay with it as it is.

3: Without fontspec

Removing fontspec and not explicitly selecting fonts is probably the trivial solution but I did not explore if/how I could then configure the fonts in the document since fontspec is required by the class I'm using, and removing it may break some parts of the 100-page document I already have in a non-obvious way, so I won't experiment with this today.

You must log in to answer this question.

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