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:
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
\documentclass[15pt]{article}
% define paper margins
\usepackage[
a4paper,
portrait,
top=1.2cm,
bottom=1.2cm,
left=1.5cm,
right=1.5cm,
headheight=15pt, % avoid warning by fancyhdr
includehead,includefoot,
heightrounded % to avoid underfull messages
]{geometry}
% Make justifications better.
\usepackage{microtype}
% Allows inclusion of sample text.
\usepackage{blindtext}
% Gets outlines right.
\usepackage{bookmark}
% ams stuff
\usepackage{amsmath, amsthm, amssymb}
% Allows inclusion of special spaces
\usepackage{xspace}
% fancy headers
\usepackage{fancyhdr}
\pagestyle{fancy}
% Allows inclusion of custom fonts.
\usepackage[no-math]{fontspec}
% Allows the use of custom enumerators in lists.
\usepackage{enumitem}
% Allows drawing of graphical images.
\usepackage{tikz}
% Allows inclusion of images.
\usepackage{graphicx}
% Automatic paragraph spacing
\usepackage{parskip}
% Allows inclusion of links
\usepackage{hyperref}
% Allows boxes to be drawn around text and math environments.
\usepackage{tcolorbox}
% Includes extra mathtools.
\usepackage{mathtools}
% Use Unicode math fonts.
\usepackage{unicode-math}
% hyperref setup
\hypersetup {
colorlinks=true,
linkcolor=blue,
filecolor=magenta,
urlcolor=cyan
}
% Augmented Matrix environment.
\newenvironment{amatrix}[1]
{\left[\begin{array}{@{}#1@{}}}
{\end{array}\right]}
% Commands
\newcommand{\latex}{\LaTeX\xspace}
\renewcommand\qedsymbol{$\blacksquare$}
\newcommand{\reals}{\mathbb{R}}
\newcommand{\naturals}{\mathbb{N}}
\newcommand{\integers}{\mathbb{Z}}
\newcommand{\rationals}{\mathbb{Q}}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
% Fixing brackets
%\let\originalleft\left
%\let\originalright\right
%\renewcommand{\left}{\mathopen{}\mathclose\bgroup\originalleft}
%\renewcommand{\right}{\aftergroup\egroup\originalright}
% Line spacing
\renewcommand{\baselinestretch}{1.22}
\DeclareMathOperator{\Tr}{Tr}
\DeclareMathOperator{\sgn}{sgn}
\DeclareMathOperator{\lcm}{lcm}
\DeclareMathOperator{\Span}{Span}
\DeclareMathOperator{\Col}{Col}
\DeclareMathOperator{\Null}{Null}
\DeclareMathOperator{\Row}{Row}
\DeclareMathOperator{\Rank}{Rank}
\DeclareMathOperator{\Nullity}{Nullity}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}
\DeclarePairedDelimiter\sqb{[}{]}
\DeclarePairedDelimiter\pr{(}{)}
\DeclarePairedDelimiter\cb{\{}{\}}
\DeclarePairedDelimiter\vbar{|}{|}
\newcommand{\ro}[1]{%
\xrightarrow{\mathmakebox[\rowidth]{#1}}%
}
\newlength{\rowidth}% row operation width
\AtBeginDocument{\setlength{\rowidth}{6.8em}}
% Font
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\setmainfont{Roboto}
%\setmathfont{Fira Math}[Color=7a4cef]
\setmonofont{Ubuntu Mono}
% Miscellaneous Variables
\newcommand{\me}{Kookie}
% Title
\title{\Huge Something}
\author{\me}
\date{\today}
\begin{document}
$$\Rank A + \Nullity A = c$$
$$\lim_{h\to 0}\frac{f(x+h) - f(x)}{h}$$
\end{document}
Best Answer
Use
mathrm=sym
to forceunicode-math
to use the math font:An alternative is to set the mathrm font to a better text font or e.g. to the math font itself: