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

Latin Modern をデフォルトのテキストおよび数式フォントとして維持したい場合は、\setmainfont命令を実行しないでください。逆に、メインのテキスト フォントを Linux Libertine O に切り替えたい場合は、パッケージをロードしてunicode-mathを実行する必要があります。一方、テキスト モードの資料には Libertine を使用し、数式モードの資料には Latin Modern を使用する場合は、を に\setmathfont{Libertinus Math}置き換える必要があります。\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 がコメントで指摘しているように、一部の TeX ディストリビューション/オペレーティング システムの組み合わせでは動作しない可能性があります。これが問題になる場合は、および命令を実行する代わりに、、、またはパッケージをロードする\setmainfont{Linux Libertine O}方が望ましい場合があります。libertinelibertinuslibertinus-otf\setmainfont\setmathfont

関連情報