我正在使用 xelatex,我想在数学公式中使用西里尔字母,就像使用普通字母一样。使用以下代码,我在生成的 PDF 中的公式中使用空格而不是西里尔字母:
\documentclass{letter}
\usepackage{fontspec}
\setmainfont{Liberation Serif}
\setmathrm{Liberation Serif}
\begin{document}
Cyrillics: {абВ 0123456789} \it{абВ 0123456789}
$ abC = 1,234567890 = абВ = \sin {1,234567890 {абВ}_{абВ} } \Phi \alpha $
\end{document}
在日志文件中显示
Missing character: There is no а in font cmmi10!
Missing character: There is no б in font cmmi10!
Missing character: There is no В in font cmmi10!
Missing character: There is no а in font cmmi7!
Missing character: There is no б in font cmmi7!
Missing character: There is no В in font cmmi7!
对每一个西里尔字母片段使用 \mathit 及其类似物是一种半解决方案。
是否可以将配置中的“Latin Modern”系列替换为“CMU”(“Computer Modern Unicode”)系列,该系列既有西里尔字母,又有不错的字形覆盖率?(我尝试使用“unicode-math”包解决问题,但产生了类似的问题)。
答案1
如果没有hyperref
和polyglossia
(它们之间发生了一些我没有跟踪的交互),我得到了以下结果:
平均能量损失
\documentclass[12pt]{article}
\usepackage{amsmath,amssymb}
\usepackage{unicode-math}
%\usepackage{polyglossia}
%\setdefaultlanguage{russian}
%\setotherlanguage{english}
%\newcommand\cyrillicfont{Noto Serif}
\setmainfont{Liberation Serif}
\setmathrm{Liberation Serif}
%\usepackage[russian]{hyperref}
\setmathfont{XITS Math}
%See: https://tex.stackexchange.com/questions/201239/cant-get-unicode-symbols-in-math-mode
\DeclareSymbolFont{cyrletters}{\encodingdefault}{\familydefault}{m}{it}
\newcommand{\makecyrmathletter}[1]{%
\begingroup\lccode`a=#1\lowercase{\endgroup
\Umathcode`a}="0 \csname symcyrletters\endcsname\space #1
}
\count255="409
\loop\ifnum\count255<"44F
\advance\count255 by 1
\makecyrmathletter{\count255}
\repeat
\begin{document}
\[
(д+ф)^{2}=д^{2}+2дф+ф^{2}м
\]
\[
г л а м н я^{2^{i}}
\]
Inline math mode: $ abC = 1,234 = абВ = \sin ({1,67895 \times {абВ}_{абВ} }) \Phi \alpha $
xxx $а + ц ж + е$ xxx
\end{document}
使用 xelatex (Windows 上为 miktex)编译:
This is XeTeX, Version 3.14159265-2.6-0.999992 (MiKTeX 2.9.7300 64-bit) entering extended mode (cyrillic_maths_egreg2a.tex LaTeX2e <2020-02-02> patch level 5 L3 programming layer <2020-03-06>
答案2
实际上,@Cicada 建议的字形重新定义方法(代码中引用)与“mathfont”包(单击一下即可访问 CTAN 主页)相结合,非常接近地回答了我的问题。也适用于 OpenOffice 的 TexMaths 插件。
\documentclass{letter}
\usepackage{mathfont}
\setmainfont{Liberation Serif}
\mathfont{Liberation Serif}
% The glyphs redefinition code by https://tex.stackexchange.com/users/182648/cicada
% as posted at https://tex.stackexchange.com/a/534590/210048
% See also: https://tex.stackexchange.com/questions/201239/cant-get-unicode-symbols-in-math-mode
\DeclareSymbolFont{cyrletters}{\encodingdefault}{\familydefault}{m}{it}
\newcommand{\makecyrmathletter}[1]{%
\begingroup\lccode`a=#1\lowercase{\endgroup
\Umathcode`a}="0 \csname symcyrletters\endcsname\space #1
}
\count255="409
\loop\ifnum\count255<"44F
\advance\count255 by 1
\makecyrmathletter{\count255}
\repeat
\begin{document}
Text: {\it{abC}} = 1,234567890 = {\it{абВ}\footnotesize{абВ}} = {sin} 1,234567890 \, {Φ} {\it{α}}
Math: $ abC = 1,234567890 = {абВ}_{абВ} = \sin {1,234567890} \, \Phi \, \alpha $
\end{document}
更新:更好的方法是使用“mathspec”包,它与“amsmath”不冲突,与“mathfont”也不冲突。在同一个示例代码中替换
\usepackage{mathfont}
\setmainfont{Liberation Serif}
\mathfont{Liberation Serif}
和
\usepackage{amsmath}
\usepackage{mathspec}
\setmainfont{Liberation Serif}
\setallmainfonts{Liberation Serif}