Skip to content
Snippets Groups Projects
font.sty 5.54 KiB
Newer Older
\ProvidesExplPackage{profile/font}{2021-09-04}{0.1}{NJU Thesis Undergraduate font configuration}
% \RequireXeTeX
% \RequireLuaTeX
Yichen Zhao's avatar
Yichen Zhao committed

Yu Xiong's avatar
Yu Xiong committed
% 设置西文字体
\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]
}

Yu Xiong's avatar
Yu Xiong committed
% 设置中文字体
\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" 警告
Yu Xiong's avatar
Yu Xiong committed
  \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{}{
Yu Xiong's avatar
Yu Xiong committed
  \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]
Yu Xiong's avatar
Yu Xiong committed
  \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]
Yu Xiong's avatar
Yu Xiong committed
% 方正字符集
\NewDocumentCommand\set_chinese_fontset_founder{}{
Yu Xiong's avatar
Yu Xiong committed
  \setCJKmainfont{FZSSK}[
    Extension=.ttf,
    BoldFont=FZXBSK,
    ItalicFont=FZKTK]
  \setCJKsansfont{FZXH1K}[
    Extension=.ttf,
    BoldFont=FZHTK]
  \setCJKmonofont{FZFSK}[Extension=.ttf]
Yu Xiong's avatar
Yu Xiong committed
  \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]
Yu Xiong's avatar
Yu Xiong committed
  \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}
Yichen Zhao's avatar
Yichen Zhao committed

  % 思源黑体 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}
Yichen Zhao's avatar
Yichen Zhao committed

  \setCJKfamilyfont{zhsong}{Noto~Serif~CJK~SC}
  \setCJKfamilyfont{zhhei}{Noto~Sans~CJK~SC}
Yu Xiong's avatar
Yu Xiong committed

Yu Xiong's avatar
Yu Xiong committed
  % 方正楷体、方正仿宋为免费商用字体,且支持CJK字符集
Yu Xiong's avatar
Yu Xiong committed
  % 方正仿宋 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]
}

% 检测是否是 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
  }
}

Yu Xiong's avatar
Yu Xiong committed
% 使用方正字体
% \set_chinese_fontset_founder

% 使用思源宋体+思源黑体
% \set_chinese_fontset_noto
\NewDocumentCommand\songti{}{\CJKfamily{zhsong}}
\NewDocumentCommand\heiti{}{\CJKfamily{zhhei}}
\NewDocumentCommand\fangsong{}{\CJKfamily{zhfs}}
\NewDocumentCommand\kaishu{}{\CJKfamily{zhkai}}