引言

我是LaTeX未入门爱好者,只是使用它来做些关于社科的笔记。LaTeX强大的排版功能,数学公式的美观,所想即所得的逻辑性让人爱不释手。但是随着时代发展,高质量英文数学字体也出现了很多,并在LaTeX中有着不一样的应用方式。折腾英文数学字体花了我好几个小时时间,为避免初学者走弯路,我写了这篇文章。本文着重介绍两种实现方式,一种是newtxmath,另一种是unicode-math。以下内容没啥新意,都是从各个包和字体的文档中拷贝出来的。

准备工作

请在-math选项。如果确实需要在公式中直接使用中文字体,需要加入下行代码。

1
\xeCJKsetup{CJKmath=true}

方式一:newtxmath

libertine字体借助于newtxtext 和 newtxmath的实现,参考newtx包的文档。希腊、英文字母和公式加粗均无问题,可以使用bm进行整体加粗。各种局限和其他加粗指令其查看文档,命令texdoc newtx。 以下使用libertine type1字体演示。

1
2
3
4
5
6
7
8
9
10
11
12
13
\usepackage{amsmath, amssymb}

\usepackage[lining]{libertine} % a bit lighter than Times--no osf in math
\usepackage[T1]{fontenc} % best for Western European languages
\usepackage{textcomp} % required to get special symbols
\usepackage[varqu,varl]{inconsolata}% a typewriter font must be defined
\usepackage{amsthm}% must be loaded before newtxmath
\usepackage[libertine,vvarbb]{newtxmath}
\usepackage[scr=rsfso]{mathalfa}
\usepackage{bm}% load after all math to give access to bold math
%After loading math package, switch to osf in text.
\useosf % for osf in normal text

方式二:unicode-math

unicode-math是一个实验性的数学字体调用实现,因调用(也必须使用)unicode编码字体,原生支持的符号更多,opentype math字体也自带math表,有别于之前的type1字体实现方式。但是STIX2,Libertinus(libertine的改进版)的等字体的数学字体部份暂时还没有自带的加粗字体。XITS字体倒是自带有加粗等实现,但我还是更喜欢Libertinus字体样式,加粗对我也没有实际用处。具体符号或者英文、希腊文字的加粗实现不同,请查看Libertinus的文档。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
\usepackage{amsmath, amssymb}

\usepackage[math-style=ISO, bold-style=ISO]{unicode-math} %注意,unicode-math与
%被其认为过时的bm包不兼容,不要\usepackage{bm}和使用\bm加粗命令。
\setmainfont{Libertinus Serif}
\setsansfont{Libertinus Sans}
% 因Libertinus目前的数学字体暂还没有粗体,这里设置为允许伪粗体渲染,效果自然比newtxmath + libertine字体的实现差一些。
\setmathfont[AutoFakeBold]{Libertinus Math}


% 也可注销掉以上四行,改为使用STIX2 opentype字体。
% \setmathfont{STIX2Math} [
% Extension={.otf}]
% \setmainfont{STIX2Text}[
% Extension={.otf},
% UprightFont={*-Regular},
% BoldFont={*-Bold},
% ItalicFont={*-Italic},
% BoldItalicFont={*-BoldItalic}]

% 也可使用更为健全,支持字符量较多的XSIT字体
% \setmainfont{XITS}
% \setmathfont{XITS Math}

留言

2018-05-23