在 unicode-math 下使用更改数学字体时\mathversion
,数学运算符命令(例如\lim
或\cos
)会导致错误消息,指出“\mathrm
数学版本中的数学字母标识符未定义...”(尽管在错误提示后单击三次将获得正确的输出)。通过手动重置运算符字体可以消除错误消息,例如\setoperatorfont\symup
。下面的 MWE 说明了这种行为;它设置为对 GFS 字体产生错误,但不会对 Fira 字体产生错误。
unicode-math 文档(第 4.4.1 和 4.4.3 节)似乎建议\mathrm
在切换数学版本时自动重置,但错误消息声称并非如此。也可以通过在前言中添加类似 的命令来手动消除此问题\setmathfontface\mathrm[version=GFS]{GFS Neohellenic Math}
;但是,当我阅读文档时,这应该不是必要的。
所以,我的问题是我使用的代码或我对unicode-math的理解是否存在问题?
据我所知,字体的具体选择对于问题来说并不重要。
% !TEX TS-program = lualatex
% !TEX encoding = UTF-8 Unicode
\documentclass[11pt]{article}
\usepackage{mathtools}
\usepackage{xparse}
\usepackage[math-style=TeX]{unicode-math}
\setmainfont[]{STIX Two Text}
\setmathfont[Scale=MatchUppercase]{STIX Two Math}
\setmathfont[version = Fira, Scale=MatchUppercase]{Fira Math}
\setmathfont[version = GFS, Scale=MatchUppercase]{GFS Neohellenic Math}
% \setmathfontface\mathrm[version=GFS]{GFS Neohellenic Math} %... unclear that this should be needed, but does resolve the matter if used...
%%% Environments for changing text and math fonts
\DeclareDocumentEnvironment{Firasans}{}{%
\setmainfont{FiraGO}[Scale=MatchUppercase]\mathversion{Fira}\setoperatorfont\symup}{%
}
\DeclareDocumentEnvironment{GFSsans}{}{%
\setmainfont{GFS Neohellenic}[Scale=MatchUppercase, WordSpace=0.7]\mathversion{GFS}}{%\setoperatorfont\symup}{ % commented out for illustration
}
%%% An equation and some text to use
\DeclareDocumentCommand{\Equation}{}{%
\[ \lim_{n\rightarrow\infty} \lim_{m\rightarrow\infty} \cos^{2n}\left( m!\pi x \right) = \begin{cases} 1 & \text{if $x$ is rational} \\ 0 & \text{if $x$ is irrational} \end{cases}
\]
}
\DeclareDocumentCommand{\Proof}{}{%
\paragraph{Proof:} If $x$ is rational, then $x = p/q$ for integers $p$ and $q$. As $m$ becomes large, eventually $m!$ will include $q$ as a factor\ldots%
}
%%%
\begin{document}
\Equation\Proof\bigskip
\begin{Firasans}
\Equation\Proof
\end{Firasans}
\bigskip
\begin{GFSsans}
\Equation\Proof
\end{GFSsans}
\end{document}