使用 unicode-math 的多种字体时设置定理环境字体

使用 unicode-math 的多种字体时设置定理环境字体
\documentclass{article}

\usepackage{unicode-math}
\setmathfont[version=xcharter]{XCharter Math}
\setmathfont[version=fira]{Fira Math}
\newfontfamily\xcharterfont{XCharter}
\newfontfamily\firafont{Fira Sans}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}

\begin{document}
    \xcharterfont \mathversion{xcharter}
    Some text. \(123 \alpha a \text{a}\)
    \begin{theorem}
        This is a theorem. \(\alpha = 1, 2\).
    \end{theorem}
    \firafont \mathversion{fira}
    Some text. \(123 \alpha a \text{a}\)
    \begin{theorem}
        This is a theorem. \(\alpha = 1, 2\).
    \end{theorem}
\end{document}

使用 XeLaTeX 编译时会生成以下输出(没有警告或错误)。

输出

我希望 XCharter 字体用于 Theorem 1,Fira Sans 用于 Theorem 2。我该如何获取它们?为什么在两种情况下(用于文本)都使用 LM 字体,而不是 XCharter 和 Fira?

答案1

有些地方的包裹amsthm有问题\normalfont,但您想保留当前的包裹系列。

\documentclass{article}
\usepackage{unicode-math}
\usepackage{amsthm}
\usepackage{xpatch}

\setmathfont[version=xcharter]{XCharter-Math.otf}
\setmathfont[version=fira]{Fira Math}
\newfontfamily\xcharterfont{XCharter}
\newfontfamily\firafont{Fira Sans}

% patch the amsthm commands to replace \normalfont
% with a similar command that reinstates the current font family
\makeatletter
\xpatchcmd{\@thm}{\normalfont}{\apoorv@keepcurrentfamily}{}{}
\xpatchcmd{\deferred@thm@head}{\normalfont}{\apoorv@keepcurrentfamily}{}{}
\xpatchcmd{\th@definition}{\normalfont}{\apoorv@keepcurrentfamily}{}{}
\xpatchcmd{\th@remark}{\normalfont}{\apoorv@keepcurrentfamily}{}{}
\newcommand{\apoorv@keepcurrentfamily}{%
  \expandafter\normalfont\expandafter\fontfamily\expandafter{\f@family}\selectfont
}
\makeatother

\newtheorem{theorem}{Theorem}
\theoremstyle{definition}
\newtheorem{definition}{Definition}
\theoremstyle{remark}
\newtheorem{remark}{Remark}

\begin{document}

\xcharterfont \mathversion{xcharter}
Some text. \(123 \alpha a \text{a}\)

\begin{definition}
This is a \emph{definition}
\end{definition}

\begin{theorem}
This is a theorem. \(\alpha = 1, 2\).
\end{theorem}

\begin{remark}
This is a remark.
\end{remark}

\firafont \mathversion{fira}
Some text. \(123 \alpha a \text{a}\)

\begin{definition}
This is a \emph{definition}
\end{definition}

\begin{theorem}
This is a theorem. \(\alpha = 1, 2\).
\end{theorem}

\begin{remark}
This is a remark.
\end{remark}

\end{document}

在此处输入图片描述

相关内容