Skip to content

Commit 5006fc6

Browse files
committed
feat: add options for custom mathFont.
Special thanks to https://github.com/note286/xduts
1 parent 6cb367e commit 5006fc6

File tree

5 files changed

+389
-5
lines changed

5 files changed

+389
-5
lines changed

Diff for: bithesis.dtx

+145-5
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,43 @@
948948
% \end{optdesc}
949949
% \end{function}
950950
%
951+
% \begin{function}[added=2023-03-29]{style/mathFont}
952+
% \begin{bitsyntax}[emph={[1]mathFont}]
953+
% mathFont = (*(cm)|asana|fira|...|xits|none*)
954+
% \end{bitsyntax}
955+
% 设置数学字体,具体配置见表~\ref{tab:math-font}。除 |Computer Mordern| (默认)字体以外,均使用 \pkg{unicode-math} 宏包调用字体。
956+
%
957+
% \end{function}
958+
%
959+
% \begin{table}[]
960+
% \begin{tabular}{cc|cc}
961+
% \toprule
962+
% \textbf{选项名称} & \textbf{字体名称} & \textbf{选项名称} & \textbf{字体名称} \\ \midrule
963+
% cm & Computer Mordern & \cellcolor[HTML]{EFEFEF}newcm & \cellcolor[HTML]{EFEFEF}New Computer Modern Math \\
964+
% \cellcolor[HTML]{EFEFEF}asana & \cellcolor[HTML]{EFEFEF}Asana Math & stix & STIX Math \\
965+
% concrete & Concrete Math & \cellcolor[HTML]{EFEFEF}stix2 & \cellcolor[HTML]{EFEFEF}STIX Two Math \\
966+
% \cellcolor[HTML]{EFEFEF}erewhon & \cellcolor[HTML]{EFEFEF}Erewhon Math & xcharter & XCharter Math \\
967+
% euler & Euler Math & \cellcolor[HTML]{EFEFEF}xits & \cellcolor[HTML]{EFEFEF}XITS Math \\
968+
% \cellcolor[HTML]{EFEFEF}fira & \cellcolor[HTML]{EFEFEF}Fira Math & bonum & TeX Gyre Bonum Math \\
969+
% garamond & Garamond Math & \cellcolor[HTML]{EFEFEF}dejavu & \cellcolor[HTML]{EFEFEF}TeX Gyre DejaVu Math \\
970+
% \cellcolor[HTML]{EFEFEF}gfsneohellenic & \cellcolor[HTML]{EFEFEF}GFS Neohellenic Math & pagella & TeX Gyre Pagella Math \\
971+
% kp & KpMath & \cellcolor[HTML]{EFEFEF}schola & \cellcolor[HTML]{EFEFEF}TeX Gyre Schola Math \\
972+
% \cellcolor[HTML]{EFEFEF}libertinus & \cellcolor[HTML]{EFEFEF}Libertinus Math & termes & TeX Gyre Termes Math \\
973+
% lm & Latin Modern Math & & \\ \bottomrule
974+
% \end{tabular}
975+
% \caption{数学字体配置选项与名称说明}
976+
% \label{tab:math-font}
977+
% \end{table}
978+
%
979+
% \begin{function}[added=2023-03-29]{style/unicodeMathOptions}
980+
% \begin{bitsyntax}[emph={[1]unicodeMathOptions}]
981+
% unicodeMathOptions = (*({})|任意选项*)
982+
% \end{bitsyntax}
983+
%
984+
% 传递给 \pkg{unicode-math} 的选项。
985+
%
986+
% \end{function}
987+
%
951988
% \subsubsection{目录选项}
952989
%
953990
% \begin{function}{TOC}
@@ -1080,11 +1117,11 @@
10801117
% \end{bitsyntax}
10811118
%
10821119
% 影响所有名称列表(author、editor 等)的限制值。如果某个列表包含的姓名数量超
1083-
%\marg{正整数},那么就会自动截断至 |minbibnames| 个姓名。|minbibnames| 的值必须小于或
1120+
%|maxbibnames| 个,那么就会自动截断至 |minbibnames| 个姓名。|minbibnames| 的值必须小于或
10841121
% 等于 |maxbibnames|。
10851122
%
10861123
% 对于用户来说,可以将 |minbibnames| 理解为「姓名列表的最小长度」。
1087-
% 例如,你在全部文献中最低排在第四位,那么可以将 |minbibnames| 和 |maxbibnames| 都设置为 4。
1124+
% \textbf{例如,你在全部文献中最低排在第四位,那么可以将 |minbibnames| 和 |maxbibnames| 都设置为 4。}
10881125
%
10891126
% \end{function}
10901127
%
@@ -2293,6 +2330,15 @@
22932330
{ \flushbottom }
22942331
},
22952332
pageVerticalAlign .initial:n = {top},
2333+
% 数学字体配置
2334+
mathFont .choices:nn = {
2335+
asana, bonum, cm, concrete, dejavu, erewhon, euler,
2336+
fira, garamond, gfsneohellenic, kp, libertinus, lm, newcm,
2337+
pagella, schola, stix, stix2, termes, xcharter, xits, none,
2338+
} { \tl_set_eq:NN \l_@@_style_math_font_tl \l_keys_choice_tl },
2339+
mathFont .initial:n = {cm},
2340+
% Options that will be pass to `unicode-math` pkgs.
2341+
unicodeMathOptions .tl_set:N = \l_@@_unicode_math_options_tl,
22962342
}
22972343
% \end{macrocode}
22982344
%
@@ -2468,16 +2514,112 @@
24682514
}
24692515
% \end{macrocode}
24702516
%
2517+
% \subsubsection{定义字体相关选项}
2518+
%
24712519
% 设置 Times New Roman 字体。
24722520
% 根据学校规范要求,默认情况下也使用 Times New Roman 字体。
24732521
% \begin{macrocode}
24742522
\setmainfont{Times~New~Roman}
24752523
\setromanfont{Times~New~Roman}
24762524
% \end{macrocode}
24772525
%
2526+
% \begin{macro}{\@@_font_path:}
2527+
% 当选择使用字体文件配置字体时,设置字体文件路径。
2528+
% \begin{macrocode}
2529+
\cs_new:Npn \@@_font_path:
2530+
{
2531+
\str_if_eq:NNTF { \l_@@_font_type_tl } { font }
2532+
{ }
2533+
{ Path = \l_@@_font_path_tl / , }
2534+
}
2535+
% \end{macrocode}
2536+
% \end{macro}
2537+
%
2538+
% \begin{macro}{\@@_load_unicode_math_pkg:}
2539+
% 加载\pkg{unicode-math}宏包。
2540+
% \begin{macrocode}
2541+
\cs_new:Npn \@@_load_unicode_math_pkg:
2542+
{
2543+
\PassOptionsToPackage { \l_@@_unicode_math_options_tl } { unicode-math }
2544+
\RequirePackage { unicode-math }
2545+
}
2546+
% \end{macrocode}
2547+
% \end{macro}
2548+
%
2549+
% \begin{macro}{\@@_define_math_font:nn}
2550+
% 批量定义数学字体配置。
2551+
% \begin{arguments}
2552+
% \item 配置名称。
2553+
% \item 字体名称。
2554+
% \end{arguments}
2555+
% \begin{macrocode}
2556+
\cs_new:Npn \@@_define_math_font:nn #1#2
2557+
{
2558+
\cs_new:cpn { @@_load_math_font_ #1 : }
2559+
{
2560+
\@@_load_unicode_math_pkg:
2561+
\setmathfont { #2 }
2562+
}
2563+
}
2564+
\clist_map_inline:nn
2565+
{
2566+
{ asana } { Asana-Math.otf },
2567+
{ concrete } { Concrete-Math.otf },
2568+
{ erewhon } { Erewhon-Math.otf },
2569+
{ euler } { Euler-Math.otf },
2570+
{ fira } { FiraMath-Regular.otf },
2571+
{ garamond } { Garamond-Math.otf },
2572+
{ gfsneohellenic } { GFSNeohellenicMath.otf },
2573+
{ kp } { KpMath-Regular.otf },
2574+
{ libertinus } { LibertinusMath-Regular.otf },
2575+
{ lm } { latinmodern-math.otf },
2576+
{ newcm } { NewCMMath-Regular.otf },
2577+
{ stix } { STIXMath-Regular.otf },
2578+
{ stix2 } { STIXTwoMath-Regular.otf },
2579+
{ xcharter } { XCharter-Math.otf },
2580+
{ xits } { XITSMath-Regular.otf },
2581+
{ bonum } { texgyrebonum-math.otf },
2582+
{ dejavu } { texgyredejavu-math.otf },
2583+
{ pagella } { texgyrepagella-math.otf },
2584+
{ schola } { texgyreschola-math.otf },
2585+
{ termes } { texgyretermes-math.otf }
2586+
}
2587+
{ \@@_define_math_font:nn #1 }
2588+
% \end{macrocode}
2589+
% \end{macro}
2590+
%
2591+
% \begin{macro}{\@@_load_math_font_cm:}
2592+
% 数学字体配置 |cm|。
2593+
% \begin{macrocode}
2594+
\cs_new:Npn \@@_load_math_font_cm: { }
2595+
% \end{macrocode}
2596+
% \end{macro}
2597+
%
2598+
% \begin{macro}{\@@_load_math_font_none:}
2599+
% 数学字体配置 |none|。
2600+
% \begin{macrocode}
2601+
\cs_new:Npn \@@_load_math_font_none: { }
2602+
% \end{macrocode}
2603+
% \end{macro}
2604+
%
2605+
% \begin{macro}{\@@_load_font:}
2606+
% 加载数学字体
2607+
% \begin{macrocode}
2608+
\cs_new:Npn \@@_load_font:
2609+
{
2610+
\use:c { @@_load_math_font_ \l_@@_style_math_font_tl : }
2611+
}
2612+
% \end{macrocode}
2613+
% \end{macro}
2614+
%
2615+
% \paragraph{定义导言区末尾加载内容}
2616+
%
24782617
% 在 |preamble| 中,加载各个模板需要的字体。
24792618
% \begin{macrocode}
24802619
\ctex_at_end_preamble:n {
2620+
% 在导言区末尾加载数学字体。
2621+
\@@_load_font:
2622+
24812623
\@@_if_thesis_english:TF {
24822624
\@@_if_thesis_int_type:nT {3} {
24832625
% 对于本科全英文专业模板
@@ -6310,7 +6452,7 @@ footskip=0.7cm% 页脚 1.8cm %
63106452
\RequirePackage{array,longtable,booktabs}
63116453
\RequirePackage{listings}
63126454
\RequirePackage{fancyhdr}
6313-
\RequirePackage[dvipsnames]{xcolor}
6455+
\RequirePackage[dvipsnames,table,xcdraw]{xcolor}
63146456
\RequirePackage{awesomebox}
63156457
% \RequirePackage{etoolbox}
63166458
\RequirePackage{dirtree}
@@ -6404,8 +6546,6 @@ footskip=0.7cm% 页脚 1.8cm %
64046546
}
64056547
}
64066548

6407-
6408-
64096549
\ifthenelse{\equal{\@nameuse{g__ctex_fontset_tl}}{mac}}{
64106550
\setmainfont{Palatino}
64116551
\setsansfont[Scale=MatchLowercase]{Helvetica}

Diff for: templates/graduate-thesis/bithesis.cls

+61
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,15 @@
389389
{ \flushbottom }
390390
},
391391
pageVerticalAlign .initial:n = {top},
392+
% 数学字体配置
393+
mathFont .choices:nn = {
394+
asana, bonum, cm, concrete, dejavu, erewhon, euler,
395+
fira, garamond, gfsneohellenic, kp, libertinus, lm, newcm,
396+
pagella, schola, stix, stix2, termes, xcharter, xits, none,
397+
} { \tl_set_eq:NN \l__bithesis_style_math_font_tl \l_keys_choice_tl },
398+
mathFont .initial:n = {cm},
399+
% Options that will be pass to `unicode-math` pkgs.
400+
unicodeMathOptions .tl_set:N = \l__bithesis_unicode_math_options_tl,
392401
}
393402
\keys_define:nn { bithesis / TOC }
394403
{
@@ -500,7 +509,59 @@
500509
}
501510
\setmainfont{Times~New~Roman}
502511
\setromanfont{Times~New~Roman}
512+
\cs_new:Npn \__bithesis_font_path:
513+
{
514+
\str_if_eq:NNTF { \l__bithesis_font_type_tl } { font }
515+
{ }
516+
{ Path = \l__bithesis_font_path_tl / , }
517+
}
518+
\cs_new:Npn \__bithesis_load_unicode_math_pkg:
519+
{
520+
\PassOptionsToPackage { \l__bithesis_unicode_math_options_tl } { unicode-math }
521+
\RequirePackage { unicode-math }
522+
}
523+
\cs_new:Npn \__bithesis_define_math_font:nn #1#2
524+
{
525+
\cs_new:cpn { __bithesis_load_math_font_ #1 : }
526+
{
527+
\__bithesis_load_unicode_math_pkg:
528+
\setmathfont { #2 }
529+
}
530+
}
531+
\clist_map_inline:nn
532+
{
533+
{ asana } { Asana-Math.otf },
534+
{ concrete } { Concrete-Math.otf },
535+
{ erewhon } { Erewhon-Math.otf },
536+
{ euler } { Euler-Math.otf },
537+
{ fira } { FiraMath-Regular.otf },
538+
{ garamond } { Garamond-Math.otf },
539+
{ gfsneohellenic } { GFSNeohellenicMath.otf },
540+
{ kp } { KpMath-Regular.otf },
541+
{ libertinus } { LibertinusMath-Regular.otf },
542+
{ lm } { latinmodern-math.otf },
543+
{ newcm } { NewCMMath-Regular.otf },
544+
{ stix } { STIXMath-Regular.otf },
545+
{ stix2 } { STIXTwoMath-Regular.otf },
546+
{ xcharter } { XCharter-Math.otf },
547+
{ xits } { XITSMath-Regular.otf },
548+
{ bonum } { texgyrebonum-math.otf },
549+
{ dejavu } { texgyredejavu-math.otf },
550+
{ pagella } { texgyrepagella-math.otf },
551+
{ schola } { texgyreschola-math.otf },
552+
{ termes } { texgyretermes-math.otf }
553+
}
554+
{ \__bithesis_define_math_font:nn #1 }
555+
\cs_new:Npn \__bithesis_load_math_font_cm: { }
556+
\cs_new:Npn \__bithesis_load_math_font_none: { }
557+
\cs_new:Npn \__bithesis_load_font:
558+
{
559+
\use:c { __bithesis_load_math_font_ \l__bithesis_style_math_font_tl : }
560+
}
503561
\ctex_at_end_preamble:n {
562+
% 在导言区末尾加载数学字体。
563+
\__bithesis_load_font:
564+
504565
\__bithesis_if_thesis_english:TF {
505566
\__bithesis_if_thesis_int_type:nT {3} {
506567
% 对于本科全英文专业模板

Diff for: templates/paper-translation/bithesis.cls

+61
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,15 @@
389389
{ \flushbottom }
390390
},
391391
pageVerticalAlign .initial:n = {top},
392+
% 数学字体配置
393+
mathFont .choices:nn = {
394+
asana, bonum, cm, concrete, dejavu, erewhon, euler,
395+
fira, garamond, gfsneohellenic, kp, libertinus, lm, newcm,
396+
pagella, schola, stix, stix2, termes, xcharter, xits, none,
397+
} { \tl_set_eq:NN \l__bithesis_style_math_font_tl \l_keys_choice_tl },
398+
mathFont .initial:n = {cm},
399+
% Options that will be pass to `unicode-math` pkgs.
400+
unicodeMathOptions .tl_set:N = \l__bithesis_unicode_math_options_tl,
392401
}
393402
\keys_define:nn { bithesis / TOC }
394403
{
@@ -500,7 +509,59 @@
500509
}
501510
\setmainfont{Times~New~Roman}
502511
\setromanfont{Times~New~Roman}
512+
\cs_new:Npn \__bithesis_font_path:
513+
{
514+
\str_if_eq:NNTF { \l__bithesis_font_type_tl } { font }
515+
{ }
516+
{ Path = \l__bithesis_font_path_tl / , }
517+
}
518+
\cs_new:Npn \__bithesis_load_unicode_math_pkg:
519+
{
520+
\PassOptionsToPackage { \l__bithesis_unicode_math_options_tl } { unicode-math }
521+
\RequirePackage { unicode-math }
522+
}
523+
\cs_new:Npn \__bithesis_define_math_font:nn #1#2
524+
{
525+
\cs_new:cpn { __bithesis_load_math_font_ #1 : }
526+
{
527+
\__bithesis_load_unicode_math_pkg:
528+
\setmathfont { #2 }
529+
}
530+
}
531+
\clist_map_inline:nn
532+
{
533+
{ asana } { Asana-Math.otf },
534+
{ concrete } { Concrete-Math.otf },
535+
{ erewhon } { Erewhon-Math.otf },
536+
{ euler } { Euler-Math.otf },
537+
{ fira } { FiraMath-Regular.otf },
538+
{ garamond } { Garamond-Math.otf },
539+
{ gfsneohellenic } { GFSNeohellenicMath.otf },
540+
{ kp } { KpMath-Regular.otf },
541+
{ libertinus } { LibertinusMath-Regular.otf },
542+
{ lm } { latinmodern-math.otf },
543+
{ newcm } { NewCMMath-Regular.otf },
544+
{ stix } { STIXMath-Regular.otf },
545+
{ stix2 } { STIXTwoMath-Regular.otf },
546+
{ xcharter } { XCharter-Math.otf },
547+
{ xits } { XITSMath-Regular.otf },
548+
{ bonum } { texgyrebonum-math.otf },
549+
{ dejavu } { texgyredejavu-math.otf },
550+
{ pagella } { texgyrepagella-math.otf },
551+
{ schola } { texgyreschola-math.otf },
552+
{ termes } { texgyretermes-math.otf }
553+
}
554+
{ \__bithesis_define_math_font:nn #1 }
555+
\cs_new:Npn \__bithesis_load_math_font_cm: { }
556+
\cs_new:Npn \__bithesis_load_math_font_none: { }
557+
\cs_new:Npn \__bithesis_load_font:
558+
{
559+
\use:c { __bithesis_load_math_font_ \l__bithesis_style_math_font_tl : }
560+
}
503561
\ctex_at_end_preamble:n {
562+
% 在导言区末尾加载数学字体。
563+
\__bithesis_load_font:
564+
504565
\__bithesis_if_thesis_english:TF {
505566
\__bithesis_if_thesis_int_type:nT {3} {
506567
% 对于本科全英文专业模板

0 commit comments

Comments
 (0)