Answers to the question Switching back to Computer Modern within XeLaTeX provides a way to switch back to the default font in XeLaTex. However, the solution there doesn't work if I use \mathrm
in a formula:
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
%\newfontfamily\lmodern{Latin Modern Roman} % If font exists on your system
% Optical sizes need to be set up manually using the [SizeFeatures] option
% or select the font using the regular font selection methods
\newcommand{\lmr}{\fontfamily{lmr}\selectfont} % Latin Modern Roman
\newcommand{\lmss}{\fontfamily{lmss}\selectfont} % Latin Modern Sans
\newcommand{\lmtt}{\fontfamily{lmtt}\selectfont} % Latin Modern Mono
\begin{document}
\[\mathrm{e}^{\mathrm{i}\pi}+1=0\]
{\lmr\[\mathrm{e}^{\mathrm{i}\pi}+1=0\]}
\end{document}
You can see that the letters e and i are still not in the default font. Using some other fonts will make formulas look even worse, such as Consolas.
What should I do to solve it?
libertine
to load Linux Libertine? It works out of the box with LuaLaTeX and XeLaTeX.unicode-math
.