-
Notifications
You must be signed in to change notification settings - Fork 400
/
ustcthesis.cls
3447 lines (3225 loc) · 96.7 KB
/
ustcthesis.cls
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%
% Copyright (C) 2015-2024 by USTC TeX Users Group <https://github.com/ustctug>
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in
% https://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2008 or later.
%
\NeedsTeXFormat{LaTeX2e}[2017/04/15]
\newcommand\ustcthesisversion{3.3.5}
\ProvidesClass{ustcthesis}[2024/05/09 v\ustcthesisversion\space USTC thesis template]
% 报错和警告
\newcommand\ustc@error[1]{%
\ClassError{ustcthesis}{#1}{}%
}
\newcommand\ustc@warning[1]{%
\ClassWarning{ustcthesis}{#1}%
}
% 检查 \LaTeXe{} kernel 版本
\@ifl@t@r\fmtversion{2017/04/15}{}{
\ustc@error{%
TeX Live 2017 or later version is required to compile this document%
}
}
% 检查编译引擎,要求使用 XeLaTeX 或 LuaLaTeX。
\RequirePackage{iftex}
\ifXeTeX\else
\ifLuaTeX\else
\ustc@error{XeLaTeX or LuaLaTeX is required to compile this document}
\fi
\fi
% \subsection{处理选项}
\RequirePackage{kvdefinekeys}
\RequirePackage{kvsetkeys}
\RequirePackage{kvoptions}
% 提供一个 \cs{ustcsetup} 命令支持 \emph{key-value} 的方式来设置。
\let\ustc@setup@hook\@empty
\newcommand\ustcsetup[1]{%
\let\ustc@setup@hook\@empty
\kvsetkeys{ustc}{#1}%
\ustc@setup@hook
}
% 同时用 \emph{key-value} 的方式来定义这些接口:
% \begin{latex}
% \ustc@define@key{
% <key> = {
% name = <name>,
% choices = {
% <choice1>,
% <choice2>,
% },
% default = <default>,
% code = <code>,
% },
% }
% \end{latex}
% 其中 |choices| 设置允许使用的值,默认为第一个(或者 \meta{default});
% \meta{code} 是相应的内容被设置时执行的代码。
\newcommand\ustc@define@key[1]{%
\kvsetkeys{ustc@key}{#1}%
}
\kv@set@family@handler{ustc@key}{%
%
% \cs{ustcsetup} 会将 \meta{value} 存到 \cs{ustc@\meta{key}},
% 但是宏的名字包含 “-” 这样的特殊字符时不方便直接调用,比如 |key = math-style|,
% 这时可以用 |name| 设置 \meta{key} 的别称,比如 |key = math@style|,
% 这样就可以通过 \cs{ustc@math@style} 来引用。
% |default| 是定义该 \meta{key} 时默认的值,缺省为空。
%
\@namedef{ustc@#1@@name}{#1}%
\def\ustc@@default{}%
\def\ustc@@choices{}%
\kv@define@key{ustc@value}{name}{%
\@namedef{ustc@#1@@name}{##1}%
}%
%
% 由于在定义接口时,\cs{ustc@\meta{key}@@code} 不一定有定义,
% 而且在文档类/宏包中还有可能对该 |key| 的 |code| 进行添加。
% 所以 \cs{ustc@\meta{key}@@code} 会检查如果在定义文档类/宏包时则推迟执行,否则立即执行。
%
\@namedef{ustc@#1@@check}{}%
\@namedef{ustc@#1@@code}{}%
%
% 保存下 |choices = {}| 定义的内容,在定义 \cs{ustc@\meta{name}} 后再执行。
%
\kv@define@key{ustc@value}{choices}{%
\def\ustc@@choices{##1}%
\@namedef{ustc@#1@@reset}{}%
%
% \cs{ustc@\meta{key}@check} 检查 |value| 是否有效,
% 并设置 \cs{ifustc@\meta{name}@\meta{value}}。
%
\@namedef{ustc@#1@@check}{%
\@ifundefined{%
ifustc@\@nameuse{ustc@#1@@name}@\@nameuse{ustc@\@nameuse{ustc@#1@@name}}%
}{%
\ustc@error{Invalid value "#1 = \@nameuse{ustc@\@nameuse{ustc@#1@@name}}"}%
}%
\@nameuse{ustc@#1@@reset}%
\@nameuse{ustc@\@nameuse{ustc@#1@@name}@\@nameuse{ustc@\@nameuse{ustc@#1@@name}}true}%
}%
}%
\kv@define@key{ustc@value}{default}{%
\def\ustc@@default{##1}%
}%
\kvsetkeys{ustc@value}{#2}%
\@namedef{ustc@\@nameuse{ustc@#1@@name}}{}%
%
% 第一个 \meta{choice} 设为 \meta{default},
% 并且对每个 \meta{choice} 定义 \cs{ifustc@\meta{name}@\meta{choice}}。
%
\kv@set@family@handler{ustc@choice}{%
\ifx\ustc@@default\@empty
\def\ustc@@default{##1}%
\fi
\expandafter\newif\csname ifustc@\@nameuse{ustc@#1@@name}@##1\endcsname
\expandafter\g@addto@macro\csname ustc@#1@@reset\endcsname{%
\@nameuse{ustc@\@nameuse{ustc@#1@@name}@##1false}%
}%
}%
\kvsetkeys@expandafter{ustc@choice}{\ustc@@choices}%
%
% 将 \meta{default} 赋值到 \cs{ustc@\meta{name}},如果非空则执行相应的代码。
%
\expandafter\let\csname ustc@\@nameuse{ustc@#1@@name}\endcsname\ustc@@default
\expandafter\ifx\csname ustc@\@nameuse{ustc@#1@@name}\endcsname\@empty\else
\@nameuse{ustc@#1@@check}%
\fi
%
% 定义 \cs{ustcsetup} 接口。
%
\kv@define@key{ustc}{#1}{%
\@namedef{ustc@\@nameuse{ustc@#1@@name}}{##1}%
\@nameuse{ustc@#1@@check}%
\@nameuse{ustc@#1@@code}%
}%
}
% 定义接口向 |key| 添加 |code|:
\newcommand\ustc@option@hook[2]{%
\expandafter\g@addto@macro\csname ustc@#1@@code\endcsname{#2}%
}
\ustc@define@key{
degree = {
choices = {
doctor,
master,
bachelor,
},
default = doctor,
},
degree-type = {
name = degree@type,
choices = {
academic,
professional,
},
default = academic,
},
main-language = {
name = main@language,
choices = {
chinese,
english,
},
default = chinese,
},
language = {
choices = {
chinese,
english,
},
default = chinese,
},
system = {
choices = {
auto,
mac,
unix,
windows,
},
default = auto,
},
fontset = {
choices = {
auto,
windows,
mac,
ubuntu,
fandol,
none,
},
default = auto,
},
font = {
choices = {
auto,
times,
termes,
stix,
xits,
libertinus,
newcm,
lm,
newtx,
none,
},
default = auto,
},
cjk-font = {
name = cjk@font,
choices = {
auto,
windows,
mac,
noto,
fandol,
none,
},
default = auto,
},
math-font = {
name = math@font,
choices = {
auto,
stix,
xits,
libertinus,
newcm,
cm,
lm,
newtx,
none,
},
default = auto,
},
math-style = {
name = math@style,
choices = {
GB,
ISO,
TeX,
},
},
uppercase-greek = {
name = uppercase@greek,
choices = {
italic,
upright,
},
},
less-than-or-equal = {
name = leq,
choices = {
slanted,
horizontal,
},
},
integral = {
choices = {
upright,
slanted,
},
},
integral-limits = {
name = integral@limits,
choices = {
true,
false,
},
},
partial = {
choices = {
upright,
italic,
},
},
math-ellipsis = {
name = math@ellipsis,
choices = {
centered,
lower,
AMS,
},
},
real-part = {
name = real@part,
choices = {
roman,
fraktur,
},
},
cite-style = {
name = cite@style,
choices = {
super,
inline,
authoryear,
},
},
output = {
choices = {
print,
electronic,
},
default = print,
},
section-style = {
name = section@style,
choices = {
chinese,
arabic,
},
default = chinese,
},
badge-color = {
name = badge@color,
choices = {
blue,
black,
},
default = blue,
},
reviewer = {
choices = {
true,
false,
},
default = false,
},
}
% 将 \ustc@cite@style 置空方便后续进行判断。
\def\ustc@cite@style{}
\newif\ifustc@degree@graduate
\newcommand\ustc@set@graduate{%
\ifustc@degree@bachelor
\ustc@degree@graduatefalse
\else
\ustc@degree@graduatetrue
\fi
}
\ustc@set@graduate
\ustc@option@hook{degree}{%
\ustc@set@graduate
}
% 使用 \pkg{kvoptions} 提供的 key-value 接口,
\SetupKeyvalOptions{
family = ustc,
prefix = ustc@,
setkeys = \kvsetkeys,
}
% 设置默认 \option{openany}。
\DeclareBoolOption[false]{openright}
\DeclareComplementaryOption{openany}{openright}
% 兼容旧版本的文档类选项。
% Reserved for compatibility until 2020-07-01.
\DeclareVoidOption{doctor}{\ustcsetup{degree=doctor}}
\DeclareVoidOption{master}{\ustcsetup{degree=master}}
\DeclareVoidOption{bachelor}{\ustcsetup{degree=bachelor}}
\DeclareVoidOption{chinese}{\ustcsetup{language=chinese}}
\DeclareVoidOption{english}{\ustcsetup{language=english}}
\DeclareVoidOption{academic}{\ustcsetup{degree-type=academic}}
\DeclareVoidOption{professional}{\ustcsetup{degree-type=professional}}
\DeclareVoidOption{print}{\ustcsetup{output=print}}
\DeclareVoidOption{pdf}{\ustcsetup{output=electronic}}
\newif\ifustc@legacy@cite@style
\DeclareVoidOption{super}{\ustcsetup{cite-style=super}\ustc@legacy@cite@styletrue}
\DeclareVoidOption{numbers}{\ustcsetup{cite-style=inline}\ustc@legacy@cite@styletrue}
\DeclareVoidOption{authoryear}{\ustcsetup{cite-style=authoryear}\ustc@legacy@cite@styletrue}
\DeclareVoidOption{arabic}{\ustcsetup{section-style=arabic}}
\DeclareVoidOption{colorlogo}{\ustcsetup{badge-color=blue}}
\DeclareVoidOption{bwlogo}{\ustcsetup{badge-color=black}}
% 载入 \cls{ctexbook}。
\DeclareDefaultOption{\PassOptionsToClass{\CurrentOption}{ctexbook}}
\ProcessKeyvalOptions*
% \subsection{加载文档类和宏包}
\ifustc@openright
\PassOptionsToClass{openright}{book}
\else
\PassOptionsToClass{openany}{book}
\fi
\ifustc@output@electronic
\PassOptionsToClass{oneside}{book}
\fi
\PassOptionsToPackage{no-math}{fontspec}
% 载入 \cls{ctexbook} 文档类,注意要求为 2.4.9 或更高的版本。
\LoadClass[UTF8,a4paper,scheme=plain,zihao=-4,fontset=none]{ctexbook}[2017/04/01]
% 建议在模板开始处载入全部宏包,不要轻易改变加载顺序。
% \pkg{hyperref} 一般在最后加载。
\RequirePackage{etoolbox}
\RequirePackage{amsmath}
\RequirePackage{fontspec}[2017/03/31]
\RequirePackage{geometry}
\RequirePackage{graphicx}
\RequirePackage{fancyhdr}
\RequirePackage{color}
\RequirePackage{titletoc}
\RequirePackage{caption}
\RequirePackage[perpage]{footmisc}
\RequirePackage{url}
\RequirePackage{notoccite}
\RequirePackage{multirow}
% 如果用户在导言区未调用 \pkg{biblatex},则自动调用 \pkg{natbib}。
\AtEndPreamble{
\@ifpackageloaded{biblatex}{}{
\RequirePackage{natbib}
}
}
% 对冲突的宏包报错。
\RequirePackage{filehook}
\newcommand\ustc@package@conflict[2]{
\AtEndOfPackageFile*{#1}{%
\AtBeginOfPackageFile*{#2}{%
\ustc@error{The "#2" package is incompatible with "#1"}%
}%
}%
}
\ustc@package@conflict{biblatex}{bibunits}
\ustc@package@conflict{biblatex}{chapterbib}
\ustc@package@conflict{biblatex}{cite}
\ustc@package@conflict{biblatex}{multibib}
\ustc@package@conflict{biblatex}{natbib}
\ustc@package@conflict{bibunits}{biblatex}
\ustc@package@conflict{bibunits}{chapterbib}
\ustc@package@conflict{bibunits}{multibib}
\ustc@package@conflict{unicode-math}{amscd}
\ustc@package@conflict{unicode-math}{amsfonts}
\ustc@package@conflict{unicode-math}{amssymb}
\ustc@package@conflict{unicode-math}{bbm}
\ustc@package@conflict{unicode-math}{bm}
\ustc@package@conflict{unicode-math}{eucal}
\ustc@package@conflict{unicode-math}{eufrak}
\ustc@package@conflict{unicode-math}{mathrsfs}
\ustc@package@conflict{unicode-math}{newtxmath}
\ustc@package@conflict{unicode-math}{upgreek}
\ustc@package@conflict{natbib}{biblatex}
\ustc@package@conflict{natbib}{cite}
\ustc@package@conflict{newtxmath}{amsfonts}
\ustc@package@conflict{newtxmath}{amssymb}
\ustc@package@conflict{newtxmath}{unicode-math}
\ustc@package@conflict{newtxmath}{upgreek}
% \pkg{amsthm} 需要在 \pkg{newtx} 前载入,参考 \pkg{newtx} 的文档。
\AtBeginOfPackageFile*{amsthm}{
\@ifpackageloaded{newtxmath}{
\ustc@error{The "amsthm" package should be loaded before setting "newtxmath"}
}{}
}%
% \subsection{处理语言}
% 定义 \cs{ustc@main@language},当在导言区修改 \option{language} 时,
% 保存为论文的主要语言;
% \cs{ustc@reset@main@language} 则用于正文中恢复为主要语言。
% \begin{macrocode}
\ustcsetup{main-language=\ustc@language}%
\let\ustc@main@language\ustc@language
\ustc@option@hook{language}{%
\ifx\@begindocumenthook\@undefined\else
\ustcsetup{main-language=\ustc@language}%
\let\ustc@main@language\ustc@language
\fi
}
\newcommand\ustc@reset@main@language{%
\ustcsetup{language = \ustc@main@language}%
\let\ustc@language\ustc@main@language
}
% 带圈数字和星号使用中文字体。
\ifLuaTeX
% ctex 将带圈数字 U+2460–U+24FF 归入字符范围 3(ALchar),这里改回范围 6(JAchar)
\ltjdefcharrange{3}{%
"2000-"243F, "2500-"27BF, "2900-"29FF, "2B00-"2BFF}
\ltjdefcharrange{6}{%
"2460-"24FF, "2E80-"2EFF, "3000-"30FF, "3190-"319F, "31F0-"4DBF,
"4E00-"9FFF, "F900-"FAFF, "FE10-"FE1F, "FE30-"FE6F, "FF00-"FFEF,
"1B000-"1B16F, "1F100-"1F2FF, "20000-"3FFFF, "E0100-"E01EF}
\else
\ifXeTeX
\xeCJKDeclareCharClass{CJK}{"2460 -> "2473}
\xeCJKDeclareCharClass{CJK}{"2605}
\fi
\fi
% 由于 Unicode 的一些标点符号是中西文混用的:
% U+00B7、U+2013、U+2014、U+2018、U+2019、
% U+201C、U+201D、U+2025、U+2026、U+2E3A,
% 所以要根据语言设置正确的字体。
% https://github.com/CTeX-org/ctex-kit/issues/389
\newcommand\ustc@set@punctuations{%
\ifustc@language@chinese
\ifLuaTeX
\ltjsetparameter{jacharrange={+9}}
\else
\ifXeTeX
\xeCJKDeclareCharClass{FullLeft}{"2018, "201C}%
\xeCJKDeclareCharClass{FullRight}{
"00B7, "2019, "201D, "2013, "2014, "2025, "2026, "2E3A,
}%
\fi
\fi
\else
\ifLuaTeX
\ltjsetparameter{jacharrange={-9}}
\else
\ifXeTeX
\xeCJKDeclareCharClass{HalfLeft}{"2018, "201C}%
\xeCJKDeclareCharClass{HalfRight}{
"00B7, "2019, "201D, "2013, "2014, "2025, "2026, "2E3A,
}%
\fi
\fi
\fi
}
\ustc@set@punctuations
\ustc@option@hook{language}{\ustc@set@punctuations}
% 根据语言设置各章节的名称,只有在导言区设置 \option{language} 时会修改,
% 而在正文局部切换语言时则不变。
% 由于《撰写手册》中的“speciality”一词使用的是英式拼法,
% 所以“acknowledgements”也保持一致。
\newcommand\ustc@set@chapter@names{%
\ifustc@main@language@chinese
\def\contentsname{目录}%
\def\listfigurename{插图清单}%
\def\listtablename{表格清单}%
\ctexset{
chapter/name = {第,章},
}%
\def\bibname{参考文献}%
\def\appendixname{附录}%
\def\ustc@acknowledgements@name{致谢}%
\def\ustc@publication@name{在读期间发表的学术论文与取得的研究成果}%
\newcommand\ustc@notation@name{符号说明}%
\else
\def\contentsname{Contents}%
\def\listfigurename{List of Figures}%
\def\listtablename{List of Tables}%
\ctexset{
chapter/name = {\chaptername\space},
}%
\def\bibname{Bibliography}%
\def\appendixname{Appendix}%
\def\ustc@acknowledgements@name{Acknowledgements}%
\def\ustc@publication@name{Publications}%
\def\ustc@notation@name{Notation}%
\fi
}
\ustc@set@chapter@names
\ustc@option@hook{main-language}{\ustc@set@chapter@names}
% 这部分名称在正文中局部地修改语言时会发生变化。
\newcommand\ustc@set@names{%
\ifustc@language@chinese
\def\figurename{图}%
\def\tablename{表}%
\else
\def\figurename{Figure}%
\def\tablename{Table}%
\fi
}
\ustc@set@names
\ustc@option@hook{language}{\ustc@set@names}
% \subsection{字体}
% 字号
% 正文字号12bp,研究生行距20bp,本科生行距22bp;
% 其他命令的行距按照相同的的比例设置,如表~\ref{tab:fontsize}。
% \begin{table}[htb]
% \centering
% \caption{标准字体命令与字号、行距的对应}
% \label{tab:fontsize}
% \begin{tabular}{lllll}
% \toprule
% 字体命令 & 字号 & bp & 研究生行距 & 本科生行距 \\
% \midrule
% \cs{tiny} & 小六 & 6.5 & 10.83 & 11.92 \\
% \cs{scriptsize} & 六号 & 7.5 & 12.5 & 13.75 \\
% \cs{footnotesize} & 小五 & 9 & 15 & 16.5 \\
% \cs{small} & 五号 & 10.5 & 17.5 & 19.25 \\
% \cs{normalsize} & 小四 & 12 & 20 & 22 \\
% \cs{large} & 小三 & 15 & 25 & 27.5 \\
% \cs{Large} & 小二 & 18 & 30 & 33 \\
% \cs{LARGE} & 二号 & 22 & 36.67 & 40.33 \\
% \cs{huge} & 小一 & 24 & 40 & 44 \\
% \cs{Huge} & 一号 & 26 & 43.33 & 47.67 \\
% \bottomrule
% \end{tabular}
% \end{table}
%
% 注意重定义 \normalsize 应在 \pkg{unicode-math} 的 \cs{setmathfont} 前。
\newcommand\ustc@set@font@size{%
\ifustc@degree@graduate
\renewcommand\normalsize{%
\@setfontsize\normalsize{12bp}{20bp}%
\abovedisplayskip 12bp \@plus3bp \@minus7bp%
\abovedisplayshortskip \z@ \@plus3bp%
\belowdisplayshortskip 6.5bp \@plus3.5bp \@minus3bp%
\belowdisplayskip \abovedisplayskip
\let\@listi\@listI}%
%
% 注意第~\ref{sec:list} 节去掉了列表的间距,所以不再修改 \cs{@listi}。
\else
\renewcommand\normalsize{%
\@setfontsize\normalsize{12bp}{22bp}%
\abovedisplayskip 12bp \@plus3bp \@minus7bp%
\abovedisplayshortskip \z@ \@plus3bp%
\belowdisplayshortskip 6.5bp \@plus3.5bp \@minus3bp%
\belowdisplayskip \abovedisplayskip
\let\@listi\@listI}%
\fi
\normalsize
\ifx\MakeRobust\@undefined \else
\MakeRobust\normalsize
\fi
}
\ustc@set@font@size
\ustc@option@hook{degree}{\ustc@set@font@size}
% 设置行距的倍数为 1。
\linespread{1}\selectfont
% 检测系统
\ifustc@system@auto
\IfFileExists{/System/Library/Fonts/Menlo.ttc}{
\ustcsetup{system = mac}
}{
\IfFileExists{/dev/null}{
\IfFileExists{null:}{
\ustcsetup{system = windows}
}{
\ustcsetup{system = unix}
}
}{
\ustcsetup{system = windows}
}
}
\fi
% 处理 \opt{fontset}
\ifustc@fontset@auto
\ifustc@system@windows
\ustcsetup{fontset = windows}
\else
\IfFontExistsTF{SimSun}{
\ustcsetup{fontset = windows}
}{
\ifustc@system@mac
\ustcsetup{fontset = mac}
\else
\IfFontExistsTF{Noto Serif CJK SC}{
\ustcsetup{fontset = ubuntu}
}{
\ustcsetup{fontset = fandol}
}
\fi
}
\fi
\fi
% 《撰写手册》要求西文字体使用 Times New Roman 和 Arial,
% 但是在 Linux 下没有这两个字体,所以使用它们的克隆版 TeX Gyre Termes 和
% TeX Gyre Heros。
\ifustc@font@auto
\ifustc@fontset@windows
\ustcsetup{font=times}
\else
\ifustc@fontset@mac
\ustcsetup{font=times}
\else
\ustcsetup{font=termes}
\fi
\fi
\fi
% Times New Roman + Arial
\newcommand\ustc@set@font@times{%
\setmainfont{Times New Roman}%
\setsansfont{Arial}%
\ifustc@system@mac
\setmonofont{Menlo}[Scale = MatchLowercase]%
\else
\setmonofont{Courier New}[Scale = MatchLowercase]%
\fi
}
% TeX Gyre Termes
\newcommand\ustc@set@font@termes{%
\setmainfont{texgyretermes}[
Extension = .otf,
UprightFont = *-regular,
BoldFont = *-bold,
ItalicFont = *-italic,
BoldItalicFont = *-bolditalic,
]%
\ustc@set@texgyre@sans@mono
}
\newcommand\ustc@set@texgyre@sans@mono{%
\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,
]%
}
% STIX Two 字体。
% STIX 文件名在 v2.10 2020-12-19 从
% \file{STIX2Text-Regular.otf}、\file{STIX2Math.otf} 分别改为
% \file{STIXTwoText-Regular.otf}、\file{STIXTwoMath-Regular.otf}。
\let\ustc@font@family@stix\@empty
\newcommand\ustc@set@stix@names{%
\ifx\ustc@font@family@stix\@empty
\IfFontExistsTF{STIXTwoText-Regular.otf}{%
\gdef\ustc@font@family@stix{STIXTwoText}%
\gdef\ustc@font@name@stix@math{STIXTwoMath-Regular}%
}{%
\gdef\ustc@font@family@stix{STIX2Text}%
\gdef\ustc@font@name@stix@math{STIX2Math}%
}%
\fi
}
\newcommand\ustc@set@font@stix{%
\ustc@set@stix@names
\setmainfont{\ustc@font@family@stix}[
Extension = .otf,
UprightFont = *-Regular,
BoldFont = *-Bold,
ItalicFont = *-Italic,
BoldItalicFont = *-BoldItalic,
]%
\ustc@set@texgyre@sans@mono
}
% XITS 字体。
% XITS 的文件名在 v1.109 2018-09-30
% 从 \file{xits-regular.otf}、\file{xits-math.otf} 分别改为
% \file{XITS-Regular.otf}、\file{XITSMath-Regular.otf}。
\let\ustc@font@family@xits\@empty
\newcommand\ustc@set@xits@names{%
\ifx\ustc@font@family@xits\@empty
\IfFontExistsTF{XITSMath-Regular.otf}{%
\gdef\ustc@font@family@xits{XITS}%
\gdef\ustc@font@style@xits@rm{Regular}%
\gdef\ustc@font@style@xits@bf{Bold}%
\gdef\ustc@font@style@xits@it{Italic}%
\gdef\ustc@font@style@xits@bfit{BoldItalic}%
\gdef\ustc@font@name@xits@math{XITSMath-Regular}%
}{%
\gdef\ustc@font@family@xits{xits}%
\gdef\ustc@font@style@xits@rm{regular}%
\gdef\ustc@font@style@xits@bf{bold}%
\gdef\ustc@font@style@xits@it{italic}%
\gdef\ustc@font@style@xits@bfit{bolditalic}%
\gdef\ustc@font@name@xits@math{xits-math}%
}%
\fi
}
\newcommand\ustc@set@font@xits{%
\ustc@set@xits@names
\setmainfont{\ustc@font@family@xits}[
Extension = .otf,
UprightFont = *-\ustc@font@style@xits@rm,
BoldFont = *-\ustc@font@style@xits@bf,
ItalicFont = *-\ustc@font@style@xits@it,
BoldItalicFont = *-\ustc@font@style@xits@bfit,
]%
\ustc@set@texgyre@sans@mono
}
% Libertinus 的文件名在 v6.7 2019-04-03 从小写改为驼峰式,
% 在大小写敏感的平台上需要进行判断。
\let\ustc@font@family@libertinus\@empty
\newcommand\ustc@set@libertinus@names{%
\ifx\ustc@font@family@libertinus\@empty
\IfFontExistsTF{LibertinusSerif-Regular.otf}{%
\gdef\ustc@font@family@libertinus@serif{LibertinusSerif}%
\gdef\ustc@font@family@libertinus@sans{LibertinusSans}%
\gdef\ustc@font@name@libertinus@math{LibertinusMath-Regular}%
\gdef\ustc@font@style@libertinus@rm{Regular}%
\gdef\ustc@font@style@libertinus@bf{Bold}%
\gdef\ustc@font@style@libertinus@it{Italic}%
\gdef\ustc@font@style@libertinus@bfit{BoldItalic}%
}{%
\gdef\ustc@font@family@libertinus@serif{libertinusserif}%
\gdef\ustc@font@family@libertinus@sans{libertinussans}%
\gdef\ustc@font@name@libertinus@math{libertinusmath-regular}%
\gdef\ustc@font@style@libertinus@rm{regular}%
\gdef\ustc@font@style@libertinus@bf{bold}%
\gdef\ustc@font@style@libertinus@it{italic}%
\gdef\ustc@font@style@libertinus@bfit{bolditalic}%
}%
\fi
}
\newcommand\ustc@set@font@libertinus{%
\ustc@set@libertinus@names
\setmainfont{\ustc@font@family@libertinus@serif}[
Extension = .otf,
UprightFont = *-\ustc@font@style@libertinus@rm,
BoldFont = *-\ustc@font@style@libertinus@bf,
ItalicFont = *-\ustc@font@style@libertinus@it,
BoldItalicFont = *-\ustc@font@style@libertinus@bfit,
]%
\setsansfont{\ustc@font@family@libertinus@sans}[
Extension = .otf,
UprightFont = *-\ustc@font@style@libertinus@rm,
BoldFont = *-\ustc@font@style@libertinus@bf,
ItalicFont = *-\ustc@font@style@libertinus@it,
]%
\setmonofont{lmmonolt10}[
Extension = .otf,
UprightFont = *-regular,
BoldFont = *-bold,
ItalicFont = *-oblique,
BoldItalicFont = *-boldoblique,
]%
}
% New Computer Modern
\newcommand\ustc@set@font@newcm{%
\setmainfont{NewCM10}[
Extension = .otf,
UprightFont = *-Book,
BoldFont = *-Bold,
ItalicFont = *-BookItalic,
BoldItalicFont = *-BoldItalic,
]%
\setsansfont{NewCMSans10}[
Extension = .otf,
UprightFont = *-Book,
BoldFont = *-Bold,
ItalicFont = *-BookOblique,
BoldItalicFont = *-BoldOblique,
]%
\setmonofont{NewCMMono10}[
Extension = .otf,
UprightFont = *-Book,
ItalicFont = *-BookItalic,
BoldFont = *-Bold,
BoldItalicFont = *-BoldOblique,
]%
}
% Latin Modern
\newcommand\ustc@set@font@lm{%
\setmainfont{lmroman10}[
Extension = .otf,
UprightFont = *-regular,
BoldFont = *-bold,
ItalicFont = *-italic,
BoldItalicFont = *-bolditalic,
]%
\setsansfont{lmsans10}[
Extension = .otf,
UprightFont = *-regular,
BoldFont = *-bold,
ItalicFont = *-oblique,
BoldItalicFont = *-boldoblique,
]%
\setmonofont{lmmonolt10}[
Extension = .otf,
UprightFont = *-regular,
BoldFont = *-bold,
ItalicFont = *-oblique,
BoldItalicFont = *-boldoblique,
]%
}
\newcommand\ustc@set@font@newtx{%
\RequirePackage{newtxtext}%
}
\newcommand\ustc@set@font{%
\@nameuse{ustc@set@font@\ustc@font}%
}
\ustc@set@font
\ustc@option@hook{font}{\ustc@set@font}
% 中文字体
\ifustc@cjk@font@auto
\ifustc@fontset@mac
\ustcsetup{cjk-font = mac}
\else
\ifustc@fontset@windows
\ustcsetup{cjk-font = windows}
\else
\ifustc@fontset@ubuntu
\ustcsetup{cjk-font = noto}
\else
\ustcsetup{cjk-font = fandol}
\fi
\fi
\fi
\fi
% Windows 的中易字体。
\newcommand\ustc@set@cjk@font@windows{%
\setCJKmainfont{SimSun}[
AutoFakeBold = 3,
ItalicFont = KaiTi,
]%
\setCJKsansfont{SimHei}[AutoFakeBold = 3]%
\setCJKmonofont{FangSong}%
\setCJKfamilyfont{zhsong}{SimSun}[AutoFakeBold = 3]%
\setCJKfamilyfont{zhhei}{SimHei}[AutoFakeBold = 3]%
\setCJKfamilyfont{zhkai}{KaiTi}%
\setCJKfamilyfont{zhfs}{FangSong}%
}
% macOS 的华文字体。
\newcommand\ustc@set@cjk@font@mac{%
\defaultCJKfontfeatures{}%
\setCJKmainfont{Songti SC}[
UprightFont = * Light,
BoldFont = * Bold,
ItalicFont = Kaiti SC Regular,
BoldItalicFont = Kaiti SC Bold,
]%
\setCJKsansfont{Heiti SC}[
UprightFont = * Light,
BoldFont = * Medium,
]%
\setCJKmonofont{STFangsong}
\setCJKfamilyfont{zhsong}{Songti SC}[
UprightFont = * Light,
BoldFont = * Bold,
]%
\setCJKfamilyfont{zhhei}{Heiti SC}[
UprightFont = * Light,
BoldFont = * Medium,
]%
\setCJKfamilyfont{zhfs}{STFangsong}%
\setCJKfamilyfont{zhkai}{Kaiti SC}[
UprightFont = * Regular,
BoldFont = * Bold,
]%
\setCJKfamilyfont{zhli}{Baoli SC}%
\setCJKfamilyfont{zhyuan}{Yuanyi SC}[
UprightFont = * Light,
BoldFont = * Bold,
]%
}