
我正在使用 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 和類似的東西是一種半解決方案。
是否可以將配置中的“拉丁現代”系列替換為“CMU”(“計算機現代 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}