Currently, I'm using LuaLatex and fontspec to manage the fonts in my document. However, I found that when I wanted to use a sans-serif font like Roboto as "normal text", the maths mode text is in Roboto too, although the letters and symbols are in the serif maths font. This is problematic because it can make things harder to read. Below are a few examples of my problem:

Rank-Nullity Theorem

First Principles

Notice how both examples are in math mode, but the text is all in sans serif.

Does anyone know how I can force all text in maths mode to be computer modern math font?

I've read this post here: Force font to computer modern (serif) in math mode although it is set to sans serif, but the solution posted requires me to write \mathrm{} in pretty much every maths environment that I encouter, which would be a pain.

I've also read this post here: Force Computer Modern in math mode but I am not using beamer.

Edit: Code below


% define paper margins
    headheight=15pt, % avoid warning by fancyhdr
    heightrounded % to avoid underfull messages

% Make justifications better.

% Allows inclusion of sample text.

% Gets outlines right.

% ams stuff
\usepackage{amsmath, amsthm, amssymb}

% Allows inclusion of special spaces

% fancy headers

% Allows inclusion of custom fonts.

% Allows the use of custom enumerators in lists.

% Allows drawing of graphical images.

% Allows inclusion of images.

% Automatic paragraph spacing

% Allows inclusion of links

% Allows boxes to be drawn around text and math environments.

% Includes extra mathtools.

% Use Unicode math fonts.

% hyperref setup
\hypersetup {

% Augmented Matrix environment.

% Commands

% Fixing brackets

% Line spacing



\newlength{\rowidth}% row operation width

% Font
%\setmathfont{Fira Math}[Color=7a4cef]
\setmonofont{Ubuntu Mono}

% Miscellaneous Variables

% Title
\title{\Huge Something}
$$\Rank A + \Nullity A = c$$
$$\lim_{h\to 0}\frac{f(x+h) - f(x)}{h}$$
  • \usepackage[no-math]{fontspec}. If this doesn't work you will have to show a small complete example. Commented Jun 4, 2020 at 15:41
  • @UlrikeFischer Just tried it. It didn't change anything
    – Kookie
    Commented Jun 4, 2020 at 15:43
  • well as I said: you will have to show your code. Commented Jun 4, 2020 at 15:44
  • @UlrikeFischer I've added it, sorry I misread your message.
    – Kookie
    Commented Jun 4, 2020 at 15:51

3 Answers 3


Use mathrm=sym to force unicode-math to use the math font:





\[\Rank A + \Nullity A = c\]
\[\lim_{h\to 0}\frac{f(x+h) - f(x)}{h}\]

enter image description here

An alternative is to set the mathrm font to a better text font or e.g. to the math font itself:




\setmathrm{Latin Modern Math}

\[\Rank A + \Nullity A = c\]
\[\lim_{h\to 0}\frac{f(x+h) - f(x)}{h}\]
  • Yep, it works. Thank you so much! Could you tell me what mathrm is all about in the unicode-math package?
    – Kookie
    Commented Jun 4, 2020 at 16:12
  • 1
    I'd probably use \setmathrm{Latin Modern Roman}
    – egreg
    Commented Jun 4, 2020 at 21:49
  • @egreg Normally I prefer to ensure "math unicode" in math. But for mathrm it shouldn't make much difference (as long as only ascii is used) - the unicode values are the same. Commented Jun 4, 2020 at 22:15
  • @UlrikeFischer \mathrm and \operatorname are only to be used with text.
    – egreg
    Commented Jun 4, 2020 at 22:19
  • @egreg I agree for \mathrm, but operatornames are math for me. Also if operatorname uses \symrm, stuff like lím don't work ;-). Commented Jun 4, 2020 at 22:30

LaTeX documents have traditionally used \mathrm to do two distinct things: typeset upright math symbols (such as constants in ISO style), and typeset short passages of text in math mode. The fontspec package, by default, sets \mathrm to the main font, but it provides a \setmathrm command to override that. So, if you wanted to use Roboto in text mode but Latin Modern as \mathrm, you might write:

\defaultfontfeatures{Scale = MatchLowercase}
\setmainfont{Roboto}[Scale = 1.0]
\setmathrm{Latin Modern Roman}

It provides \setboldmathrm for the \mathrm font in \boldmath, which is distinct from the \mathbf font you get with \setmathrom[BoldFont = .... It also has \setmathsf and \setmathtt.

The unicode-math package, in addition to these, provides another set of math alphabets for math symbols. Normally, you would access these with the alphabets \symup, \symit, etc. However, since authors traditionally used \mathrm, \mathit, and so on, the package has the option mathrm=sym to make \mathrm a synonym for \symup. It also allows you to declare an arbitrary number of math alphabets with \setmathfontface.

By default, operators such as \sin and \log will use \mathrm, but unicode-math lets you override this with \setoperatorfont. You will definitely want to do this if you have redefined \mathrm to \symup.

Here is an example of Euler’s equations set in ISO style, with the upright math symbols in Hermann Zapf’s Euler. The other math symbols are from a clone of his Palatino, and for the operators sin and cos, I use a clone of his Optima. You’ll notice the difference between the imaginary constant i and the i in sin.


\setmainfont{TeX Gyre Pagella}[Scale=1.0]
\setsansfont{URW Classico}
\setmathfont{Asana Math}
            {Neo Euler}
\setmathsf[Ligatures={Common, TeX}]{URW Classico}

  \mathup{e}^{\mathup{i} \theta}  &= \sin \theta + \mathup{i} \cos \theta \\
  \mathup{e}^{\mathup{i \pi}} - 1 &= 0

Euler/Asana/Optima sample

Here is a version that more literally does what you ask, setting upright math constants as Computer Modern Upright Italic, but math operators as Computer Modern Roman:


\setmathfont{Latin Modern Math}
\setmathfont[range=up/{Latin,latin,Greek,greek}]{CMU Serif Upright Italic}
\setmathfontface\mathcmr{CMU Serif}

  \mathup{e}^{\mathup{i} \theta}  &= \sin \theta + \mathup{i} \cos \theta \\
  \mathup{e}^{\mathup{i \pi}} - 1 &= 0

Computer Modern sample

You would use commands such as \lim, \textnormal{otherwise}, \operatorname{Nullity} or \DeclareMathOperator\Rank{Rank} to get your output.


If you want all in Sans Serif:





\[\Rank A + \Nullity A = c\]
\[\lim_{h\to 0}\frac{f(x+h) - f(x)}{h}\]


<code>enter image description here</code>

  • Yeah, so I think this is a good idea too. Unfortunately, I've done this before and I found that the text was harder to read because it was more difficult to tell if some text was inline math or not and vice versa. It got to a point where I started colouring the math environment text purple just to make it more distinguishable. But by then it was a complete mess. So I came back to using sans serif lettering with serif math font. Thanks for your answer!
    – Kookie
    Commented Jun 4, 2020 at 16:24
  • You should use it the other way round: All in serif text! This is the font which is easier to read especially for long texts.
    – user187802
    Commented Jun 4, 2020 at 17:57
  • Unfortunately, I'm not a fan of serif font. I actually find it harder to read.
    – Kookie
    Commented Jun 5, 2020 at 0:53

You must log in to answer this question.

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