1

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?

3
  • 2
    Off topic, but are you aware of the libertinus fonts, that also include an OpenType math font?
    – mickep
    Commented Mar 15, 2023 at 8:16
  • I agree with mickep, but if you do not want libertinus for some reasong: Why not using package libertine to load Linux Libertine? It works out of the box with LuaLaTeX and XeLaTeX.
    – cabohah
    Commented Mar 15, 2023 at 8:37
  • And if you want to setup (a different) math font with XeLaTeX or LuaLaTeX, I would suggest unicode-math.
    – cabohah
    Commented Mar 15, 2023 at 8:41

1 Answer 1

2

If you want to keep Latin Modern as the default text and math font, don't execute \setmainfont instructions. Conversely, if you do want to switch the main text font to Linux Libertine O, you should probably load the unicode-math package and execute \setmathfont{Libertinus Math}. On the other hand, if you want Libertine for text-mode material but Latin Modern for math-mode material, you may want to replace \setmathfont{Libertinus Math} with \setmathfont{Latin Modern Math}[Scale=MatchLowercase].

enter image description here

%% execute this test file under XeLaTeX or LuaLaTeX

\documentclass{article}

\usepackage{unicode-math}
\setmainfont{Linux Libertine O}

\begin{document}

\setmathfont{Libertinus Math}
$\mathrm{e}^{\mathrm{i}\pi}+1=0$

\setmathfont{Latin Modern Math}[Scale=MatchLowercase] % or Scale=MatchUppercase
$\mathrm{e}^{\mathrm{i}\pi}+1=0$

\end{document}

Addendum: As @cabohah points out in a comment, \setmainfont{Linux Libertine O} may not work with some TeX distribution/operating system combinations. If that's an issue for you, it may be preferable to load the libertine, libertinus, or libertinus-otf packages instead of executing \setmainfont and \setmathfont instructions.

2
  • 1
    Why not loading package libertine resp. libertinus resp. libertinus-otf? \setmainfont{Linux Libertine O} usually does not work out of the box with XeLaTeX from Vanilla TeX Live but the packages do.
    – cabohah
    Commented Mar 15, 2023 at 8:47
  • @cabohah - Thanks for this. I've posted an addendum to mention the points you've made.
    – Mico
    Commented Mar 15, 2023 at 8:57

You must log in to answer this question.

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