Appearance
如何修改数学公式的字体?
可以在导言区引入unicode-math
宏包,并使用 \setmathfont{XITS Math}
修改数学环境下字体:
latex
\usepackage{unicode-math}
\unimathsetup{
math-style = ISO,
bold-style = ISO,
}
\setmathfont{XITSMath-Regular.otf}
(部分环境需手动安装字体)
更多字体与使用方法请参考unicode-math
手册。
可能存在的问题
粗体:\boldsymbol
→ \symbf
unicode
宏包与上世纪的字体管理方式不兼容。使用unicode
宏包后,加粗无法使用amsbsy
宏包的\boldsymbol
、bm
宏包的\bm
、physics
宏包的\vb
等。
建议使用\symbf
加粗,\symup
、\symit
、\symcal
等同理。
也可以考虑兼容手段,例如使用physics2
宏包的bm-um.legacy
,或者自己\renewcommand*
:
latex
% Overwrite some commands from physics to be compatible with unicode-math
\RenewCommandCopy\vb\symbf
\renewcommand*{\vdot}{\symbf{\cdot}}
\renewcommand*{\grad}{\symbf{\nabla}}
\renewcommand*{\divergence}{\symbf{\nabla} \vdot}
参考:LaTeX 排版国标样式的数学符号 - LaTeX工作室。
如需兼容mathtools
宏包
mathtools
宏包提供了gather
环境、\coloneqq
符号(:=)等命令,但个别命令与unicode-math
宏包冲突。如需使用,可在导入时关闭警告:
latex
% 注意导入顺序
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage[
warnings-off={mathtools-colon, mathtools-overbracket},
]{unicode-math}
\unimathsetup{…}
字体字面较大
如果使用 TeX Gyre Pagella Math 等字面较大的字体,略微增加数学行距可能更美观:
latex
\setmathfont{texgyrepagella-math.otf}
\SetMathEnvironmentSinglespace{1.05}
请参考zhlineskip
手册。
混用字体
下例中,主要使用 Latin Modern Math,双线体(如 ℕℤℚℝℂ)使用 TeX Gyre Pagella Math,空集符号 ∅ 使用 Asana Math。
latex
\setmathfont{latinmodern-math.otf}
\setmathfont[range=\mathbb]{texgyrepagella-math.otf}
\setmathfont[range=\varnothing]{Asana-Math.otf}
详情请参考unicode-math
手册。