Skip to content
Snippets Groups Projects
njuthesis.dtx 189 KiB
Newer Older
Yu Xiong's avatar
Yu Xiong committed
          {
            \tl_set:Nn \g_@@_latin_font_tl { gyre   }
            \tl_set:Nn \g_@@_cjk_font_tl   { fandol }
          }
      }
Yu Xiong's avatar
Yu Xiong committed
% \subsubsection{定义英文字库}
%
Yu Xiong's avatar
Yu Xiong committed
% 接下来逐个定义所需要使用的字库。
% \begin{macro}{\@@_load_latin_font_win:}
% Windows 西文字体
%    \begin{macrocode}
\cs_new_protected:Npn \@@_load_latin_font_win:
Yu Xiong's avatar
Yu Xiong committed
    \setmainfont { Times~New~Roman }
    \setsansfont { Arial           }
    \setmonofont { Courier~New     }
      [ Scale = MatchLowercase ]
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
Yu Xiong's avatar
Yu Xiong committed
%
% \begin{macro}{\@@_load_latin_font_mac:}
Yu Xiong's avatar
Yu Xiong committed
% macOS 西文字体。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
\cs_new_protected:Npn \@@_load_latin_font_mac:
Yu Xiong's avatar
Yu Xiong committed
    \setmainfont { Times~New~Roman }
    \setsansfont { Arial           }
    \setmonofont { Menlo           }
      [ Scale = MatchLowercase ]
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
Yu Xiong's avatar
Yu Xiong committed
%
% \begin{macro}{\@@_load_latin_font_gyre:}
Yu Xiong's avatar
Yu Xiong committed
% 开源的 gyre 西文字体。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
\cs_new_protected:Npn \@@_load_latin_font_gyre:
Yu Xiong's avatar
Yu Xiong committed
    \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
%    \end{macrocode}
Yu Xiong's avatar
Yu Xiong committed
%
Yu Xiong's avatar
Yu Xiong committed
% \subsubsection{定义中文字库}
%
Yu Xiong's avatar
Yu Xiong committed
% \begin{macro}{\@@_hide_no_script_msg:}
% 隐藏 |does not contain script "CJK"| 警告。
Yu Xiong's avatar
Yu Xiong committed
\cs_new_protected:Npn \@@_hide_no_script_msg:
  { \msg_redirect_name:nnn { fontspec } { no-script } { info } }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_load_cjk_font_win:}
Yu Xiong's avatar
Yu Xiong committed
% Windows 中文字体。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
\cs_new_protected:Npn \@@_load_cjk_font_win:
    \setCJKmainfont { SimSun   }
      [ AutoFakeBold = 2.17, ItalicFont = KaiTi ]
    \setCJKsansfont { SimHei   } [ AutoFakeBold = 2.17 ]
    \setCJKmonofont { FangSong } [ AutoFakeBold = 2.17 ]
    \setCJKfamilyfont { zhsong } { SimSun   } [ AutoFakeBold = 2.17 ]
    \setCJKfamilyfont { zhhei  } { SimHei   } [ AutoFakeBold = 2.17 ]
    \setCJKfamilyfont { zhfs   } { FangSong } [ AutoFakeBold = 2.17 ]
    \setCJKfamilyfont { zhkai  } { KaiTi    } [ AutoFakeBold = 2.17 ]
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
Yu Xiong's avatar
Yu Xiong committed
%
% \begin{macro}{\@@_load_cjk_font_mac:}
Yu Xiong's avatar
Yu Xiong committed
% macOS 字体。
Yu Xiong's avatar
Yu Xiong committed
% TODO: 修复 macOS 字体支持,实现开箱即用。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
\cs_new_protected:Npn \@@_load_cjk_font_mac:
Yu Xiong's avatar
Yu Xiong committed
    \@@_hide_no_script_msg:
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}
  }
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
Yu Xiong's avatar
Yu Xiong committed
%
% \begin{macro}{\@@_load_cjk_font_fandol:}
% Fandol 字体
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
\cs_new_protected:Npn \@@_load_cjk_font_fandol:
Yu Xiong's avatar
Yu Xiong committed
    \@@_hide_no_script_msg:
    \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
      ]
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
Yu Xiong's avatar
Yu Xiong committed
%
%
% \begin{macro}{\@@_load_cjk_font_founder:}
% 方正字库(简繁扩展)
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
\cs_new_protected:Npn \@@_load_cjk_font_founder:
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
% 调整方正字体括号位置。\footnote{\hologo{XeTeX} 的调整方法来自 \url{https://www.zhihu.com/question/46241367/answer/101660183}。}
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
    \sys_if_engine_xetex:T
      { \xeCJKEditPunctStyle {quanjiao} { optimize-kerning = true } }
    \sys_if_engine_luatex:T
      { \defaultCJKfontfeatures { JFM = { zh_CN/{quanjiao,fzpr} } } }
    \setCJKmainfont { FZShuSong-Z01  }
      [ BoldFont = FZXiaoBiaoSong-B05, ItalicFont = FZKai-Z03 ]
    \setCJKsansfont { FZXiHeiI-Z08   } [ BoldFont = FZHei-B01 ]
    \setCJKmonofont { FZFangSong-Z02 }
    \setCJKfamilyfont { zhsong } { FZShuSong-Z01  }
      [ BoldFont = FZXiaoBiaoSong-B05 ]
    \setCJKfamilyfont { zhhei  } { FZHei-B01      }
Yu Xiong's avatar
Yu Xiong committed
      [ AutoFakeBold = 2.17 ]
    \setCJKfamilyfont { zhkai  } { FZKai-Z03      }
Yu Xiong's avatar
Yu Xiong committed
      [ AutoFakeBold = 2.17 ]
    \setCJKfamilyfont { zhfs   } { FZFangSong-Z02 }
Yu Xiong's avatar
Yu Xiong committed
    \defaultCJKfontfeatures{}
  }
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
Yu Xiong's avatar
Yu Xiong committed
%
% \begin{macro}{\@@_load_cjk_font_noto:}
% Noto 思源字体。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
\cs_new_protected:Npn \@@_load_cjk_font_noto:
    \setCJKmainfont
      [
        UprightFont        = NotoSerifCJKsc-Regular,
        BoldFont           = NotoSerifCJKsc-Bold,
        ItalicFont         = NotoSerifCJKsc-Regular,
        BoldItalicFont     = NotoSerifCJKsc-Bold,
        ItalicFeatures     = FakeSlant,
        BoldItalicFeatures = FakeSlant
      ] { Noto~Serif~CJK~SC     }
    \setCJKsansfont
      [
        UprightFont        = NotoSansCJKsc-Regular,
        BoldFont           = NotoSansCJKsc-Bold,
        ItalicFont         = NotoSansCJKsc-Regular,
        BoldItalicFont     = NotoSansCJKsc-Bold,
        ItalicFeatures     = FakeSlant,
        BoldItalicFeatures = FakeSlant
      ] { Noto~Sans~CJK~SC      }
    \setCJKmonofont { Noto~Sans~Mono~CJK~SC }
    \setCJKfamilyfont { zhsong } { Noto~Serif~CJK~SC }
    \setCJKfamilyfont { zhhei  } { Noto~Sans~CJK~SC  }
    \setCJKfamilyfont { zhfs   } { FZFangSong-Z02    }
    \setCJKfamilyfont { zhkai  } { FZKai-Z03         }
      [AutoFakeBold=2.17]
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_load_cjk_font_source:}
% \changes{v0.14}{2021/12/20}{增加 Adobe Source Han 作为思源字体。}
% Source Han 思源字体。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_load_cjk_font_source:
  {
    \setCJKmainfont
      [
        UprightFont        = SourceHanSerifSC-Regular,
        BoldFont           = SourceHanSerifSC-Bold,
        ItalicFont         = SourceHanSerifSC-Regular,
        BoldItalicFont     = SourceHanSerifSC-Bold,
        ItalicFeatures     = FakeSlant,
        BoldItalicFeatures = FakeSlant
      ] { Source~Han~Serif~SC     }
    \setCJKsansfont
      [
        UprightFont        = SourceHanSansSC-Regular,
        BoldFont           = SourceHanSansSC-Bold,
        ItalicFont         = SourceHanSansSC-Regular,
        BoldItalicFont     = SourceHanSansSC-Bold,
        ItalicFeatures     = FakeSlant,
        BoldItalicFeatures = FakeSlant
      ] { Source~Han~Sans~SC      }
    \setCJKmonofont { FZFangSong-Z02      }
    \setCJKfamilyfont { zhsong } { Source~Han~Serif~SC }
    \setCJKfamilyfont { zhhei  } { Source~Han~Sans~SC  }
    \setCJKfamilyfont { zhfs   } { FZFangSong-Z02      }
    \setCJKfamilyfont { zhkai  } { FZKai-Z03           }
      [AutoFakeBold=2.17]
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
Yu Xiong's avatar
Yu Xiong committed
%
% \subsubsection{定义数学字库}
%
% \begin{macro}{\@@_load_math_font:}
% 设置数学字体 (XITS, 或者 \href{https://www.stixfonts.org}{STIX}, 与 Times New Roman 最为相近)
% 通用数学字体。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_load_math_font:
  {
    % \setmathfont{STIXTwoMath-Regular}[Extension = .otf]
    \setmathfont{XITSMath-Regular}[
      BoldFont = XITSMath-Bold,
      Extension = .otf]
    \setmathfont{NewCMMath-Regular.otf}[range={cal,bb,frak}]
    \setmathfont{NewCMMath-Regular.otf}[version=bold,range={bfcal}]
  }
%    \end{macrocode}
% \end{macro}
%
%
Yu Xiong's avatar
Yu Xiong committed
% \subsubsection{载入指定字库}
%
Yu Xiong's avatar
Yu Xiong committed
% 载入字体命令。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
\cs_new_protected:Npn \@@_load_font:
    \use:c { @@_load_latin_font_ \g_@@_latin_font_tl : }
    \use:c { @@_load_cjk_font_   \g_@@_cjk_font_tl   : }
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
% \changes{v0.10}{2021/09/28}{修正了数学字体。}
%    \begin{macrocode}
%    \end{macrocode}
Yu Xiong's avatar
Yu Xiong committed
% 自行定义 C\hologo{TeX} 中的四类字体命令。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
    \NewDocumentCommand \songti   { } { \CJKfamily { zhsong } }
    \NewDocumentCommand \heiti    { } { \CJKfamily { zhhei  } }
    \NewDocumentCommand \fangsong { } { \CJKfamily { zhfs   } }
    \NewDocumentCommand \kaishu   { } { \CJKfamily { zhkai  } }
%    \end{macrocode}
% 重定义字号命令。
%    \begin{macrocode}
    \RenewDocumentCommand \large  { } { \zihao     { 4      } }
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% 载入设置的字体。此处设置与文档类一同载入,否则在导言区后载入字体可能导致一部分覆盖字体的命令失效。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
% \BeforeBeginEnvironment { document } { \@@_load_font: }
\@@_load_font:
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
Yu Xiong's avatar
Yu Xiong committed
% \subsection{页面布局}
%
Yu Xiong's avatar
Yu Xiong committed
% \subsubsection{页边距}
Yu Xiong's avatar
Yu Xiong committed
% 使用\pkg{geometry}设置页边距。
%    \begin{macrocode}
\geometry
  {
    vmargin    = 2.5 cm,
    headheight = 15 pt
  }
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
Yu Xiong's avatar
Yu Xiong committed
% 草稿模式下显示页面文字范围边界以及页眉、页脚线。
%    \begin{macrocode}
\bool_if:NT \g_@@_draft_bool { \geometry { showframe } }
%    \end{macrocode}
%
% \subsubsection{页眉页脚}
Yu Xiong's avatar
Yu Xiong committed
%
Yu Xiong's avatar
Yu Xiong committed
% \begin{macro}{\@@_fancy_head:nn}
% 页眉样式,设置为小号字体、楷书。这里对 \pkg{fancyhdr} 的命令进行了包装。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_fancy_head:nn #1#2
  { \fancyhead [#1] { \small \kaishu \nouppercase {#2} } }
%    \end{macrocode}
% \end{macro}
%
% 重定义 \pkg{fancyhdr} 的 \opt{plain} 样式,即本科生正文和部分特殊页面使用的的
% 页眉页脚样式。页眉无内容;页脚为居中的页码,使用五号新罗马体数字。注意标记页眉
% 页脚横线宽度的变量并不是 |dim| 类型的,但是采取了该类型的格式。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
\fancypagestyle { plain }
  {
Yu Xiong's avatar
Yu Xiong committed
    \fancyfoot [ C ] { \zihao { 5 } \rmfamily \thepage }
    \tl_set:Nn \headrulewidth { \c_zero_dim }
    \tl_set:Nn \footrulewidth { \c_zero_dim }
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
Yu Xiong's avatar
Yu Xiong committed
% \begin{macro}{\@@_set_heading_g:}
Yu Xiong's avatar
Yu Xiong committed
% \changes{v0.15}{2022/01/17}{修复单页模式的页眉问题。}
% 以 \opt{plain} 样式为基础,单独设置研究生模板的页眉内容。在 \cs{fancyhead} 的
% 可选参数中,\opt{E} 和 \opt{O} 分别表示在偶数页(even)和奇数页(odd), 而
% \opt{L}、\opt{R} 和 \opt{C} 则分别表示左(left)、右(right)和中间(center)
% 。按照通常的排版规则,在双面模式下,偶数页的中间页眉文字在左,奇数页则在右。
% 单面模式下,左右页眉都要显示。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
Yu Xiong's avatar
Yu Xiong committed
\cs_new_protected:Npn \@@_set_heading_g:
Yu Xiong's avatar
Yu Xiong committed
    \bool_if:NTF \g_@@_twoside_bool
      {
Yu Xiong's avatar
Yu Xiong committed
        \@@_fancy_head:nn { EL } { \leftmark  }
        \@@_fancy_head:nn { OR } { \rightmark }
Yu Xiong's avatar
Yu Xiong committed
        \@@_fancy_head:nn { L  } { \leftmark  }
        \@@_fancy_head:nn { R  } { \rightmark }
Yu Xiong's avatar
Yu Xiong committed
    \tl_set:Nn \headrulewidth { 0.4 pt }
    \dim_set:Nn \headheight { 20 pt }
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
Yu Xiong's avatar
Yu Xiong committed
% \end{macro}
Yu Xiong's avatar
Yu Xiong committed
%
% \begin{macro}{\frontmatter}
% 重定义 \cs{frontmatter},清空页眉页脚以及页码设置。
Yu Xiong's avatar
Yu Xiong committed
% 此命令仅为解决原 \cls{book} 类中默认使用小写罗马字母序号的冲突,并不建议使用。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
\RenewDocumentCommand \frontmatter { }
    \cleardoublepage
Yu Xiong's avatar
Yu Xiong committed
    \pagestyle     { empty }
    \pagenumbering { Roman }
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\mainmatter}
Yu Xiong's avatar
Yu Xiong committed
% \changes{v0.12}{2021/12/03}{修复了摘要页字体格式泄漏到正文的问题。}
% \changes{v0.12}{2021/12/03}{修复了页眉上长标题重叠的问题。}
Yu Xiong's avatar
Yu Xiong committed
% 重定义 \cs{mainmatter},在论文主体部分载入页眉页脚设置,使用阿拉伯数字重新进行
% 页码编号。
%    \begin{macrocode}
\RenewDocumentCommand \mainmatter { }
  {
    \cleardoublepage
Yu Xiong's avatar
Yu Xiong committed
    \pagestyle { plain }
Yu Xiong's avatar
Yu Xiong committed
    \int_compare:nF { \g_@@_info_degree_int == 1 }
Yu Xiong's avatar
Yu Xiong committed
      { \@@_set_heading_g: }
Yu Xiong's avatar
Yu Xiong committed
    \pagenumbering { arabic }
    \normalfont \normalsize
  }
%    \end{macrocode}
% \end{macro}
Yu Xiong's avatar
Yu Xiong committed
%
Yu Xiong's avatar
Yu Xiong committed
% \subsection{章节标题格式}
% \begin{macro}{\c_@@_sec_format_tl}
% 各部分章节以及目录中章标题的格式。设置为四号、不加粗、黑体。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
\tl_const:Nn \c_@@_sec_format_tl { \large \normalfont \sffamily }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_add_tocline:n,\@@_add_tocline:V}
% 添加目录条目。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
\cs_new_protected:Npn \@@_add_tocline:n #1
  { \addcontentsline { toc } { chapter } { \c_@@_sec_format_tl #1 } }
\cs_generate_variant:Nn \@@_add_tocline:n { V }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_chapter:n,\@@_chapter:V}
% 含有目录和 PDF 标签的无编号章。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_chapter:n #1
  {
    \chapter *           { #1 }
    \@@_add_tocline:n    { #1 }
    \@@_chapter_header:n { #1 }
  }
\cs_generate_variant:Nn \@@_chapter:n { V }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_chapter_header:n}
Yu Xiong's avatar
Yu Xiong committed
% 单页模式下,目录、摘要、符号表等特殊页面的页眉中间为相应标题,左右为空。这里通
% 过居中的 \tn{leftmark} 实现。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_chapter_header:n #1
  {
    \bool_if:NTF \g_@@_twoside_bool
      { \markboth { #1 } { #1 } }
Yu Xiong's avatar
Yu Xiong committed
      { \markboth { \hfill #1 \hfill } { } }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\njuchapter}
Yu Xiong's avatar
Yu Xiong committed
% 封装无编号章环境,供用户在正文中使用。
%    \begin{macrocode}
Yu Xiong's avatar
Yu Xiong committed
\NewDocumentCommand \njuchapter { m } { \@@_chapter:n { #1 } }
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
% \end{macro}
%
Yu Xiong's avatar
Yu Xiong committed
% |\keys_set:nn{ctex}| 实际相当于 \cs{ctexset}。
%    \begin{macrocode}
Yu Xiong's avatar
Yu Xiong committed
\keys_set:nn { ctex }
Yu Xiong's avatar
Yu Xiong committed
    chapter        / beforeskip = 10 pt,
    chapter        / afterskip  = 60 pt,
    chapter        / format     = \c_@@_sec_format_tl \centering,
    section        / format     = \c_@@_sec_format_tl,
    subsection     / format     = \c_@@_sec_format_tl,
    subsubsection  / format     = \c_@@_sec_format_tl,
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
Yu Xiong's avatar
Yu Xiong committed
% \subsection{目录格式}
Yu Xiong's avatar
Yu Xiong committed
% \changes{v0.13}{2021/12/09}{移除 \pkg{tocloft},用 \pkg{ctex} 修改目录样式。}
% 设置目录标题默认名称。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
    contentsname   = { 目\hspace{2em}录 },
    listfigurename = { 插图目录         },
    listtablename  = { 表格目录         },
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
Yu Xiong's avatar
Yu Xiong committed
% 设置目录中章标题的样式。
Yu Xiong's avatar
Yu Xiong committed
    chapter / tocline = \c_@@_sec_format_tl \CTEXnumberline { #1 } #2
%    \begin{macrocode}
\keys_define:nn { nju / style }
  {
%    \end{macrocode}
% \begin{macro}{style/toc-in-toc}
% \changes{v0.15}{2022/02/04}{可选择目录自身是否出现在目录中。}
% 是否在目录中显示目录自身。
%    \begin{macrocode}
    toc-in-toc .bool_gset:N = \g_@@_toc_in_toc_bool,
    toc-in-toc   .initial:n = true
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_make_toc:nn,\@@_make_toc:Vn}
Yu Xiong's avatar
Yu Xiong committed
% 通过 group 内修改标题设置,将目录页标题格式单独设置为三号粗宋体。
% 目录自身不出现在目录中时需特别处理。参考
% \url{https://tex.stackexchange.com/a/1821}。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
\cs_new_protected:Npn \@@_make_toc:nn #1#2
Yu Xiong's avatar
Yu Xiong committed
  {
    \group_begin:
      \keys_set:nn { ctex }
        { chapter/format = \centering \zihao { 3 } \bfseries }
      \bool_if:NTF \g_@@_toc_in_toc_bool
        { \@@_chapter:n { #1 } }
        {
          \chapter * { #1 }
          \pdfbookmark [0] { #1 } { #2 }
          \@@_chapter_header:n { #1 }
        }
Yu Xiong's avatar
Yu Xiong committed
    \group_end:
    \@starttoc { #2 }
  }
\cs_generate_variant:Nn \@@_make_toc:nn { Vn }
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
Yu Xiong's avatar
Yu Xiong committed
% \end{macro}
Yu Xiong's avatar
Yu Xiong committed
% \begin{macro}{\tableofcontents,\listoffigures,\listoftables}
% 重定义目录命令,修改标题格式并插入书签。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
Yu Xiong's avatar
Yu Xiong committed
\RenewDocumentCommand \tableofcontents { }
  { \@@_make_toc:Vn \contentsname   { toc } }
Yu Xiong's avatar
Yu Xiong committed
\RenewDocumentCommand \listoffigures   { }
  { \@@_make_toc:Vn \listfigurename { lof } }
Yu Xiong's avatar
Yu Xiong committed
\RenewDocumentCommand \listoftables    { }
  { \@@_make_toc:Vn \listtablename  { lot } }
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
Yu Xiong's avatar
Yu Xiong committed
% \end{macro}
Yu Xiong's avatar
Yu Xiong committed
% \subsection{参考文献}
% \begin{variable}{\g_@@_biblatex_option_clist}
% 存储传入 \pkg{biblatex} 的选项列表。
%    \begin{macrocode}
\clist_new:N \g_@@_biblatex_option_clist
%    \end{macrocode}
% \end{variable}
%
% \begin{variable}{\g_@@_bib_resource_clist}
% 存储参考文献数据源列表。
%    \begin{macrocode}
\clist_new:N \g_@@_bib_resource_clist
%    \end{macrocode}
% \end{variable}
%
%    \begin{macrocode}
\msg_new:nnn { njuthesis } { extra-bib-style }
  {
    Wrongly-placed~ bib~ style.\\
    Please~ use~ the~ `bib/style`~ field.
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\keys_define:nn { nju / bib }
  {
%    \end{macrocode}
% \begin{macro}{bib/style}
% \changes{v0.14}{2021/12/19}{提供选择参考文献样式的接口。}
% \changes{v0.15}{2022/02/11}{可使用国标以外的文献样式。}
% 参考文献样式。国家标准为顺序编码制 \opt{numeric} 和著者-出版年制
% \opt{author-year},分别对应 \pkg{biblatex} 的 \opt{gb7714-2015}
% 和 \opt{gb7714-2015ay} 样式。其余样式一律视作 \opt{unknown}。用户
% 选取的样式会被加入选项列表中,以待传进 \pkg{biblatex} 宏包。
%    \begin{macrocode}
    style             .choice:,
    style / numeric     .code:n =
        \clist_gput_right:Nn \g_@@_biblatex_option_clist
          { style = gb7714-2015      }
      },
    style / author-year .code:n =
        \clist_gput_right:Nn \g_@@_biblatex_option_clist
          { style = gb7714-2015ay    }
      },
    style / unknown     .code:n =
        \clist_gput_right:Nx \g_@@_biblatex_option_clist
          { style = \l_keys_value_tl }
      },
    style            .initial:n = numeric,
%    \end{macrocode}
% \end{macro}
% \begin{macro}{bib/option}
% \changes{v0.15}{2022/02/15}{提供传入 \pkg{biblatex} 宏包选项的接口。}
% 待传入 \pkg{biblatex} 的额外宏包选项,以列表形式储存。
% 更为常见的参考文献样式设置已由 \opt{bib/style} 提供,
% 此处对重复的样式设置进行了检查。本设置项等效于在导言区使用
% |\PassoptionToPackage{|\meta{key}|=|\meta{value}|}{biblatex}| 命令。
%    \begin{macrocode}
    option              .code:n =
      {
        \tl_if_in:VnTF \l_keys_value_tl { style = }
          { \msg_error:nn { njuthesis } { extra-bib-style } }
          {
            \clist_gput_right:NV \g_@@_biblatex_option_clist
              \l_keys_value_tl
          }
      },
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{bib/resource}
Yu Xiong's avatar
Yu Xiong committed
% \changes{v0.14}{2021/12/19}{提供批量导入参考文献数据源的接口。}
% 参考文献数据源,以列表形式储存。
%    \begin{macrocode}
    resource            .code:n =
      {
        \clist_gput_right:NV \g_@@_bib_resource_clist
          \l_keys_value_tl
      },
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\addbibresource}
Yu Xiong's avatar
Yu Xiong committed
% 为了吸收用户在导言区设置的选项,\pkg{biblatex} 宏包被设置在导言区末尾才会载
% 入。此处单独定义了可以在导言区使用的 \cs{addbibresource} 命令,用于兼容传统的
% 添加参考文献数据源的方法。
%    \begin{macrocode}
\NewDocumentCommand \addbibresource { m }
  { \clist_gput_right:Nn \g_@@_bib_resource_clist { #1 } }
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@@_biblatex_pre_setup:}
% 载入 \pkg{biblatex} 宏包前,必须禁用自行定义的 \cs{addbibresource}
% 命令,并传入用户设置的选项。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_biblatex_pre_setup:
  {
    \cs_undefine:N \addbibresource
    \clist_gput_right:Nn \g_@@_biblatex_option_clist { backend = biber }
    \exp_args:NV \PassOptionsToPackage
      \g_@@_biblatex_option_clist { biblatex }
  }
%    \end{macrocode}
% \begin{macro}{\@@_biblatex_post_setup:}
Yu Xiong's avatar
Yu Xiong committed
% \pkg{biblatex} 宏包载入后的设置。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_biblatex_post_setup:
  {
%    \end{macrocode}
% \changes{v0.12}{2021/12/06}{设置输出参考文献的默认选项。}
% \changes{v0.15}{2022/02/17}{可在每章后附上参考文献表。}
% 修改参考文献的头部样式,自动添加目录条目。默认为 |chapter| 级别。
% 如果需要在每章后附上一个参考文献表,即对 \pkg{biblatex} 传入了
%  |refsection = chapter| 选项,则默认为 |section| 级别。
%    \begin{macrocode}
Yu Xiong's avatar
Yu Xiong committed
    \defbibheading { njubibintoc } [ \bibname ] { \@@_chapter:n { ##1 } }
    \tl_if_eq:NnTF \blx@refsecreset@level { 2 }
      { \DeclarePrintbibliographyDefaults { heading = subbibintoc } }
      { \DeclarePrintbibliographyDefaults { heading = njubibintoc } }
%    \end{macrocode}
Yu Xiong's avatar
Yu Xiong committed
% 传入参考文献源文件,此时可正常使用 \cs{addbibresource} 命令。
%    \begin{macrocode}
    \clist_map_inline:Nn \g_@@_bib_resource_clist
      { \addbibresource { ##1 } }
  }
%    \end{macrocode}
% \end{macro}
%
Yu Xiong's avatar
Yu Xiong committed
% 使用 \pkg{etoolbox} 提供的 \tn{BeforeBeginEnvironment},在 \env{document} 环境
% 开始的钩子前载入 \pkg{biblatex} 并进行相关设置。
%    \begin{macrocode}
\BeforeBeginEnvironment { document }
    \@@_biblatex_pre_setup:
    \RequirePackage { biblatex }
    \@@_biblatex_post_setup:
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
Yu Xiong's avatar
Yu Xiong committed
% \subsection{引用}
Yu Xiong's avatar
Yu Xiong committed
%
Yu Xiong's avatar
Yu Xiong committed
% 在导言区末尾进行 \pkg{hyperref} 设置。
% \changes{v0.11}{2021/10/01}{写入 PDF 元数据。}
%    \begin{macrocode}
\ctex_at_end_preamble:n
%    \end{macrocode}
Yu Xiong's avatar
Yu Xiong committed
% 忽略 PDF 字符串中的换行符,从而抑制 \pkg{hyperref} 警告。
%    \begin{macrocode}
Yu Xiong's avatar
Yu Xiong committed
    \pdfstringdefDisableCommands
      { \cs_set_eq:NN \\ \prg_do_nothing: }
Yu Xiong's avatar
Yu Xiong committed
    \hypersetup
      {
        bookmarksnumbered = true,
        psdextra          = true,
        unicode           = true,
        hidelinks,
%    \end{macrocode}
% 填写 PDF 元信息。
%    \begin{macrocode}
        pdftitle    = \l_@@_info_title_tl,
Yu Xiong's avatar
Yu Xiong committed
        pdfauthor   = \l_@@_info_author_tl,
        pdfkeywords = \l_@@_info_keywords_clist,
        pdfcreator  = \c_@@_name_pdf_creator_tl
      }
  }
%    \end{macrocode}
% \begin{macro}{\@@_cref_name:n,\@@_cref_name:V}
% 用于修改 \pkg{cleverref} 的标签名称的辅助函数。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_cref_name:n #1
  {
    \clist_map_inline:nn { #1 }
        \crefname { ##1 }
          { \@@_name:n { ##1 } } { \@@_name:n { ##1 _en } }
      }
\cs_generate_variant:Nn \@@_cref_name:n { V }
%    \end{macrocode}
% \end{macro}
%
Yu Xiong's avatar
Yu Xiong committed
% 修改 \pkg{cleverref} 的标签格式。默认在名称后面添加空格,删除公式编号的括号。
%    \begin{macrocode}
Yu Xiong's avatar
Yu Xiong committed
\crefdefaultlabelformat { #2#1#3\, }
\crefformat { equation      } { 公式~#2#1#3~   }
\crefformat { chapter       } { 第#2#1#3章     }
\crefformat { section       } { 第~#2#1#3~节   }
\crefformat { subsection    } { 第~#2#1#3~小节 }
\crefformat { subsubsection } { 第~#2#1#3~小节 }
%    \end{macrocode}
%
% 修改 \pkg{cleverref} 的标签名称。
%    \begin{macrocode}
\@@_cref_name:n { figure, table, appendix, proof }
\@@_cref_name:V \g_@@_theorem_type_clist
%    \end{macrocode}
% \subsection{图片表格}
%
% 设置默认图片扩展名,允许在不键入扩展名时自动进行补全。
%    \begin{macrocode}
Yu Xiong's avatar
Yu Xiong committed
\DeclareGraphicsExtensions { .pdf, .eps, .jpg, .png }
%    \end{macrocode}
% \changes{v0.12}{2021/12/06}{删除了可能导致冲突的 \pkg{floatrow}。}
% 图表标题样式。文字设置为五号宋体,标签设置为粗体,间隔一个全角空格。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
\DeclareCaptionStyle{njucap}
  {
    font          = small,
    labelfont     = bf,
    labelsep      = quad,
    justification = centering
  }
\captionsetup [ figure ] { style = njucap }
\captionsetup [ table  ] { style = njucap }
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
Yu Xiong's avatar
Yu Xiong committed
%
% \subsection{列表环境}
% \changes{v0.12}{2021/12/07}{删除了 \pkg{enumitem} 的部分列表环境设置。}
Yu Xiong's avatar
Yu Xiong committed
%
% 缩减列表环境的条目间距。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
\setlist { noitemsep }
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
Yu Xiong's avatar
Yu Xiong committed
% \subsection{定理环境}
% \begin{macro}{\@@_new_theorem:N}
% 用于定义普通定理环境的辅助函数。
% \begin{arguments}
%   \item 定理名称列表,|clist| 型变量
% \end{arguments}
% 除证明以外的环境都不需要证毕符号,在此清空其设置。
%    \begin{macrocode}
\cs_new_protected:Npn \@@_new_theorem:N #1
    \theoremsymbol { }
    \clist_map_inline:Nn #1
      { \newtheorem { ##1 } { \@@_name:n { ##1 } } }
  }
%    \end{macrocode}
% \end{macro}
%
Yu Xiong's avatar
Yu Xiong committed
% 定义证明环境。证毕符号使用 \tn{mdlgwhtsquare} 绘制,对应于 |U+25A1| 字符
% \footnote{\url{https://tex.stackexchange.com/questions/567135/how-get-box-like-symbol-with-xelatex}}。
%    \begin{macrocode}
\theoremsymbol { \ensuremath { \mdwhtsquare } }
\newtheorem* { proof } { \c_@@_name_proof_tl }
%    \end{macrocode}
%
% 定义普通定理环境,需要排除 \env{proof}。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
\group_begin:
  \clist_remove_all:Nn \g_@@_theorem_type_clist { proof }
  \@@_new_theorem:N \g_@@_theorem_type_clist
\group_end:
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
Yu Xiong's avatar
Yu Xiong committed
% \subsection{封面}
%
Yu Xiong's avatar
Yu Xiong committed
% \subsubsection{内部命令}
Yu Xiong's avatar
Yu Xiong committed
% \begin{macro}{\@@_split_title:n,\@@_split_title:V}
% 分割标题。
Yu Xiong's avatar
Yu Xiong committed
%    \begin{macrocode}
\cs_new_protected:Npn \@@_split_title:n #1
Yu Xiong's avatar
Yu Xiong committed
    \tl_if_in:nnTF { #1 } { \\ }
%    \end{macrocode}
% 从 |\\| 进行分割,存入 |clist|。
%    \begin{macrocode}
Yu Xiong's avatar
Yu Xiong committed
        \seq_set_split:Nnn \l_@@_tmp_seq { \\ } { #1 }
        \clist_set_from_seq:NN \l_@@_tmp_clist \l_@@_tmp_seq
%    \end{macrocode}
Yu Xiong's avatar
Yu Xiong committed
% 如果没找到换行符,则手动从固定宽度的位置进行分割。
%    \begin{macrocode}
        \@@_put_inempty_seg:nnn { #1 } { 1  } { 15 }
        \@@_put_inempty_seg:nnn { #1 } { 16 } { 15 }
        \@@_put_inempty_seg:nnn { #1 } { 31 } { 15 }
Yu Xiong's avatar
Yu Xiong committed
\cs_generate_variant:Nn \@@_split_title:n { V }
%    \end{macrocode}
Yu Xiong's avatar
Yu Xiong committed
%
% \begin{macro}{\@@_multiline_title:nnn}
% 生成多行标题。
% \begin{arguments}
%   \item 内容格式
%   \item 名称盒子宽度,|dim| 型变量
%   \item 内容盒子宽度,|dim| 型变量
% \end{arguments}
%    \begin{macrocode}
\cs_new_protected:Npn \@@_multiline_title:nnn #1#2#3
Yu Xiong's avatar
Yu Xiong committed
    \@@_split_title:V \l_@@_info_title_tl
    \@@_spread_box:nnV { #2 } { \kaishu } \c_@@_name_title_tl
    \@@_hskip:
    \clist_map_inline:Nn \l_@@_tmp_clist
      { \@@_ulined_center_box:nn { #3 } { #1 ##1 } \@@_vskip: }
%    \end{macrocode}
% \end{macro}
%
Yu Xiong's avatar
Yu Xiong committed
% \begin{macro}{\@@_cover_entry:nnn}
% 生成单项信息条目。
% \begin{arguments}
%   \item 条目名称
%   \item 名称盒子宽度,|dim| 型变量
%   \item 内容盒子宽度,|dim| 型变量
% \end{arguments}
%    \begin{macrocode}
Yu Xiong's avatar
Yu Xiong committed
\cs_new_protected:Npn \@@_cover_entry:nnn #1#2#3
Yu Xiong's avatar
Yu Xiong committed
    \@@_spread_box:nnx { #2 } { \kaishu } { \@@_name:n { #1 } }
Yu Xiong's avatar
Yu Xiong committed
    \@@_ulined_center_box:nn { #3 }       { \@@_info:n { #1 } }
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
Yu Xiong's avatar
Yu Xiong committed
%
Yu Xiong's avatar
Yu Xiong committed
% \begin{macro}{\@@_cover_bientry:nnnn}
% 生成两项信息条目,仅用于本科生封面。
% \begin{arguments}
%   \item 左侧条目名称
%   \item 右侧条目名称
%   \item 名称盒子宽度,|dim| 型变量
%   \item 内容盒子宽度,|dim| 型变量
% \end{arguments}
%    \begin{macrocode}
Yu Xiong's avatar
Yu Xiong committed
\cs_new_protected:Npn \@@_cover_bientry:nnnn #1#2#3#4
Yu Xiong's avatar
Yu Xiong committed
    \@@_spread_box:nnx { #3 } { \kaishu } { \@@_name:n { #1 } }
Yu Xiong's avatar
Yu Xiong committed
    \@@_ulined_center_box:nn { #4 }       { \@@_info:n { #1 } }
    \skip_horizontal:n { 0.5 em }
Yu Xiong's avatar
Yu Xiong committed
    \@@_spread_box:nnx { #3 } { \kaishu } { \@@_name:n { #2 } }
Yu Xiong's avatar
Yu Xiong committed
    \@@_ulined_center_box:nn { #4 }       { \@@_info:n { #2 } }
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
% \begin{macro}{\@@_cover_supv_entry:nnn}
% 生成两项导师信息条目,仅用于本科生封面。
% \begin{arguments}
%   \item 条目名称
%   \item 长内容盒子宽度,|dim| 型变量
%   \item 短内容盒子宽度,|dim| 型变量
% \end{arguments}
%    \begin{macrocode}
\cs_new_protected:Npn \@@_cover_supv_entry:nnn #1#2#3
  {
Yu Xiong's avatar
Yu Xiong committed
    \@@_spread_box:nnx { #2 } { \kaishu } { \@@_name:n { #1 } }
    \@@_hskip:
    \@@_ulined_center_box:nn { #3 }
      { \clist_item:cn { l_@@_info_ #1 _clist } { 1 } }
    \skip_horizontal:n { 0.5 em }
Yu Xiong's avatar
Yu Xiong committed
    \@@_spread_box:nnV { #2 } { \kaishu } \c_@@_name_supv_ttl_tl
    \@@_hskip:
    \@@_ulined_center_box:nn { #3 }
      { \clist_item:cn { l_@@_info_ #1 _clist } { 2 } }
    \@@_vskip:
  }
%    \end{macrocode}
% \end{macro}
%
%
% \subsubsection{绘制部件}
Yu Xiong's avatar
Yu Xiong committed
%
% \changes{v0.16}{2022/03/01}{将封面部件分离到 \file{.def} 文件。}
% \paragraph{本科生}
%
% \begin{macro}{cover/ug/emblem-img}
% 本科生封面校徽图片实例。
%    \begin{macrocode}
\@@_declare_element:nn { cover / ug / emblem-img }
  {
    content = \njuemblem [ black ] { ! } { 3.35 cm },
    bottom-skip = 1 cm,
    align   = l
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{cover/ug/name-img}
% 本科生封面校名图片实例。
%    \begin{macrocode}
\@@_declare_element:nn { cover / ug / name-img }
  {
    content     = \njuname [ black ] { ! } { 3 cm },
    bottom-skip = 1 cm
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{cover/ug/title}
% 本科生封面标题实例。
%    \begin{macrocode}
\@@_declare_element:nn { cover / ug / title }
Yu Xiong's avatar
Yu Xiong committed
      \@@_spread_box:nnV { 9 em } { \bf } \l_@@_info_type_tl,
    format   = \zihao { -1 },
    bottom-skip = 0 pt plus 1.5 fill
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{cover/ug/info}
% 本科生封面信息栏实例。
%    \begin{macrocode}
\@@_declare_element:nn { cover / ug / info }
      \@@_cover_info_ug:nnn { 4.2 em } { 16 em } { 5.5 em },
    format   = \zihao { 3 }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_cover_info_ug:nnn}
% 本科生封面信息栏。
Yu Xiong's avatar
Yu Xiong committed
% \begin{arguments}
%   \item 名称盒子宽度,|dim| 型变量
%   \item 长内容盒子宽度,|dim| 型变量
%   \item 短内容盒子宽度,|dim| 型变量
Yu Xiong's avatar
Yu Xiong committed
% \end{arguments}
%    \begin{macrocode}
\cs_new_protected:Npn \@@_cover_info_ug:nnn #1#2#3