summaryrefslogtreecommitdiff
path: root/macros/unicodetex/latex/njuthesis/profile/font.sty
blob: d939fb4842f4990c2f4bca1962723b47d322099a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
\ProvidesExplPackage{profile/font}{2021-09-11}{0.7.0}{NJU Thesis font configuration}

% \RequireXeTeX
% \RequireLuaTeX

% 设置西文字体
\NewDocumentCommand\set_latin_fontset_windows{}{
  \setmainfont{Times~New~Roman}
  \setsansfont{Arial}
  \setmonofont{Courier~New}[Scale=MatchLowercase]
}

\NewDocumentCommand\set_latin_fontset_macos{}{
  \setmainfont{Times~New~Roman}
  \setsansfont{Arial}
  \setmonofont{Menlo}[Scale=MatchLowercase]
}

\NewDocumentCommand\set_latin_fontset_gyre{}{
  \setmainfont{texgyretermes}[
    Extension=.otf,
    UprightFont=*-regular,
    BoldFont=*-bold,
    ItalicFont=*-italic,
    BoldItalicFont=*-bolditalic]
  \setsansfont{texgyreheros}[
    Extension=.otf,
    UprightFont=*-regular,
    BoldFont=*-bold,
    ItalicFont=*-italic,
    BoldItalicFont=*-bolditalic]
  \setmonofont{texgyrecursor}[
    Extension=.otf,
    UprightFont=*-regular,
    BoldFont=*-bold,
    ItalicFont=*-italic,
    BoldItalicFont=*-bolditalic,
    Scale=MatchLowercase,
    Ligatures=CommonOff]
}

% 设置中文字体
\NewDocumentCommand\set_chinese_fontset_windows{}{
  \setCJKmainfont{SimSun}[
    AutoFakeBold=2.17, 
    ItalicFont=KaiTi]
  \setCJKsansfont{SimHei}
  \setCJKmonofont{FangSong}
  \setCJKfamilyfont{zhsong}{SimSun}[AutoFakeBold=2.17]
  \setCJKfamilyfont{zhhei}{SimHei}
  \setCJKfamilyfont{zhfs}{FangSong}
  \setCJKfamilyfont{zhkai}{KaiTi}[AutoFakeBold=2.17]
  \setCJKfamilyfont{zhnewhei}{Microsoft~YaHei}[BoldFont=Microsoft~YaHei~Bold]
}

\NewDocumentCommand\set_chinese_fontset_macos{}{
  \msg_redirect_name:nnn {fontspec} {no-script} {info} % 移除 does not contain script "CJK" 警告
  \setCJKmainfont{Songti~SC~Light}[
    BoldFont=Songti~SC~Bold,
    ItalicFont=Kaiti~SC,
    BoldItalicFont=Kaiti~SC~Bold]
  \setCJKsansfont{Heiti~SC~Light}[BoldFont=Heiti~SC~Medium]
  \setCJKmonofont{STFangsong}
  \setCJKfamilyfont{zhsong}{Songti~SC~Light}[BoldFont=Songti~SC~Bold]
  \setCJKfamilyfont{zhhei}{Heiti~SC~Light}[BoldFont=Heiti~SC~Medium]
  \setCJKfamilyfont{zhfs}{STFangsong}
  \setCJKfamilyfont{zhkai}{Kaiti~SC}[BoldFont=Kaiti~SC~Bold]
  \setCJKfamilyfont{zhnewhei}{PingFang~SC}
}

\NewDocumentCommand\set_chinese_fontset_fandol{}{
  \msg_redirect_name:nnn {fontspec} {no-script} {info} % 移除 does not contain script "CJK" 警告
  \setCJKmainfont{FandolSong-Regular}[
    Extension=.otf,
    BoldFont=FandolSong-Bold,
    ItalicFont=FandolKai-Regular]
  \setCJKsansfont{FandolHei-Regular}[
    Extension=.otf,
    BoldFont=FandolHei-Bold]
  \setCJKmonofont{FandolFang-Regular}[Extension=.otf]
  \setCJKfamilyfont{zhsong}{FandolSong-Regular}[
    Extension=.otf,
    BoldFont=FandolSong-Bold]
  \setCJKfamilyfont{zhhei}{FandolHei-Regular}[
    Extension=.otf,
    BoldFont=FandolHei-Bold]
  \setCJKfamilyfont{zhfs}{FandolFang-Regular}[Extension=.otf]
  \setCJKfamilyfont{zhkai}{FandolKai-Regular}[
    Extension=.otf,
    AutoFakeBold=2.17]
}

% 方正字符集
\NewDocumentCommand\set_chinese_fontset_founder{}{
  % FZSSK 方正书宋(简繁扩展) http://www.foundertype.com/index.php/FontInfo/index/id/151 免费商用
  % FZXBSK 方正小标宋(简繁扩展) http://www.foundertype.com/index.php/FontInfo/index/id/164 设计师非商免费
  % FZKTK 方正楷体(简繁扩展) http://www.foundertype.com/index.php/FontInfo/index/id/137 免费商用
  \setCJKmainfont{FZSSK}[
    Extension=.ttf,
    BoldFont=FZXBSK,
    ItalicFont=FZKTK]
  % FZXH1K 方正细黑一(简繁扩展) http://www.foundertype.com/index.php/FontInfo/index/id/161 设计师非商免费
  % FZHTK 方正黑体(简繁扩展) http://www.foundertype.com/index.php/FontInfo/index/id/131 免费商用
  \setCJKsansfont{FZXH1K}[
    Extension=.ttf,
    BoldFont=FZHTK]
  % FZFSK 方正仿宋(简繁扩展) http://www.foundertype.com/index.php/FontInfo/index/id/128
  \setCJKmonofont{FZFSK}[Extension=.ttf]

  \setCJKfamilyfont{zhsong}{FZSSK}[
    Extension=.ttf,
    BoldFont=FZXBSK]
  \setCJKfamilyfont{zhhei}{FZHTK}[
    Extension=.ttf,
    AutoFakeBold=2.17]
  \setCJKfamilyfont{zhfs}{FZFSK}[Extension=.ttf]
  \setCJKfamilyfont{zhkai}{FZKTK}[Extension=.ttf]
  % FZYouHK_508R 方正悠黑508R(简繁扩展) http://www.foundertype.com/index.php/FontInfo/index/id/244 设计师非商免费
  % FZYouHK_511M 方正悠黑511M(简繁扩展) http://www.foundertype.com/index.php/FontInfo/index/id/244 设计师非商免费
  \setCJKfamilyfont{zhnewhei}{FZYouHK_508R}[
    Extension=.ttf,
    BoldFont=FZYouHK_511M]
}

\NewDocumentCommand\set_chinese_fontset_noto{}{
  % 思源宋体 https://www.google.com/get/noto/#serif-hans
  \setCJKmainfont[
    UprightFont=NotoSerifCJKsc-Regular,
    BoldFont=NotoSerifCJKsc-Bold,
    ItalicFont=NotoSerifCJKsc-Regular,
    BoldItalicFont=NotoSerifCJKsc-Bold,
    ItalicFeatures=FakeSlant,
    BoldItalicFeatures=FakeSlant]{Noto~Serif~CJK~SC}

  % 思源黑体 https://www.google.com/get/noto/#sans-hans
  \setCJKsansfont[
    UprightFont=NotoSansCJKsc-Regular,
    BoldFont=NotoSansCJKsc-Bold,
    ItalicFont=NotoSansCJKsc-Regular,
    BoldItalicFont=NotoSansCJKsc-Bold,
    ItalicFeatures=FakeSlant,
    BoldItalicFeatures=FakeSlant]{Noto~Sans~CJK~SC}

  % 包含于上述思源黑体
  \setCJKmonofont[
    UprightFont=NotoSansMonoCJKsc-Regular,
    BoldFont=NotoSansMonoCJKsc-Bold,
    ItalicFont=NotoSansMonoCJKsc-Regular,
    BoldItalicFont=NotoSansMonoCJKsc-Bold,
    ItalicFeatures=FakeSlant,
    BoldItalicFeatures=FakeSlant]{Noto~Sans~Mono~SC}

  \setCJKfamilyfont{zhsong}{Noto~Serif~CJK~SC}
  \setCJKfamilyfont{zhhei}{Noto~Sans~CJK~SC}

  % 方正楷体、方正仿宋为免费商用字体,且支持CJK字符集
  % 方正仿宋 http://www.foundertype.com/index.php/FontInfo/index/id/128.html
  % 方正楷体 http://www.foundertype.com/index.php/FontInfo/index/id/137.html
  \setCJKfamilyfont{zhfs}{方正仿宋简体}[AutoFakeBold=2.17]
  \setCJKfamilyfont{zhkai}{方正楷体简体}[AutoFakeBold=2.17]
}

% 字体判断
\bool_if:NTF \nju_systemfont
% 根据操作系统自动选择相应字体
{
  % 检测是否是 Windows
  \sys_if_platform_windows:TF
  {
    \set_latin_fontset_windows
    \set_chinese_fontset_windows
  }
  {
    % 检测是否是 macOS
    \ctex_if_platform_macos:TF
    {
      \set_latin_fontset_macos
      \set_chinese_fontset_macos
    }
    % 其余系统一律使用自由字体
    {
      \set_latin_fontset_gyre
      \set_chinese_fontset_fandol
    }
  }
}
{
  % 如果用户需要自定义字体
  % 此处需要使用\str_case_e而不是\str_case使宏展开为字符串
  \str_case_e:nn { \nju_customlatinfont }
  {
    { windows } { \set_latin_fontset_windows }
    { macos } { \set_latin_fontset_macos }
    { gyre } { \set_latin_fontset_gyre }
    { null } {}
  }
  \str_case_e:nn { \nju_customchinesefont }
  {
    { windows } { \set_chinese_fontset_windows }
    { macos } { \set_chinese_fontset_macos }
    { gyre } { \set_chinese_fontset_gyre }
    { founder } { \set_chinese_fontset_founder }
    { noto } { \set_chinese_fontset_noto }
    { null } {}
  }
}
% 选择其他字体,请确保相应字体已安装

% 设置数学字体 (XITS, 或者 STIX, 与 Times New Roman 最为相近)
% \setmathfont{STIXTwoMath-Regular}[Extension = .otf]
\setmathfont{XITSMath-Regular}[
  BoldFont = XITSMath-Bold,
  Extension = .otf]

\NewDocumentCommand\songti{}{\CJKfamily{zhsong}}
\NewDocumentCommand\heiti{}{\CJKfamily{zhhei}}
\NewDocumentCommand\fangsong{}{\CJKfamily{zhfs}}
\NewDocumentCommand\kaishu{}{\CJKfamily{zhkai}}
% \NewDocumentCommand\lishu{}{\CJKfamily{zhli}}