如何在 XeLaTeX 中的公式中切換回 Computer Modern?

如何在 XeLaTeX 中的公式中切換回 Computer Modern?

問題的答案在 XeLaTeX 中切換回 Computer Modern提供了一種切換回 XeLaTex 中預設字體的方法。但是,如果我\mathrm在公式中使用,該解決方案將無法運作:

\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}

您可以看到字母 e 和 i 仍然不是預設字體。使用其他一些字體會使公式看起來更糟糕,例如 Consolas。

我該怎麼做才能解決它?

答案1

如果您想將拉丁現代字體保留為預設文字和數學字體,請不要執行\setmainfont指令。相反,如果您確實想將主文字字體切換到 Linux Libertine O,您可能應該加載該unicode-math套件並執行\setmathfont{Libertinus Math}.另一方面,如果您想要 Libertine 作為文字模式材料,但希望 Latin Modern 作為數學模式材料,您可能需要替換\setmathfont{Libertinus Math}\setmathfont{Latin Modern Math}[Scale=MatchLowercase].

在此輸入影像描述

%% 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}

附錄:正如 @cabohah 在評論中指出的那樣,\setmainfont{Linux Libertine O}可能不適用於某些 TeX 發行版/作業系統組合。如果這對您來說是個問題,最好載入libertinelibertinuslibertinus-otf套件,而不是執行\setmainfont\setmathfont指示。

相關內容