Skip to content
Snippets Groups Projects
njuthesis.dtx 56.1 KiB
Newer Older
% \iffalse meta-comment
% !TeX program  = XeLaTeX
% !TeX encoding = UTF-8
% Copyright (C) 2021 by Nanjing University Linux User Group <my@yaoge123.com>
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
% license or (at your option) any later version.  The latest version
% of this license is in the file
%    https://www.latex-project.org/lppl.txt
% -----------------------------------------------------------------------
% The development version of the template can be found at
%    https://github.com/nju-lug/NJUThesis
%
% for those people who are interested.
%
%<*internal>
\iffalse
%</internal>
%
%<*readme>
Yichen Zhao's avatar
Yichen Zhao committed
# NJU Thesis
Yu Xiong's avatar
Yu Xiong committed

[![njuthesis](https://img.shields.io/badge/njuthesis-latex-blue)](https://git.nju.edu.cn/nju-lug/nju-latex-templates)
[![overleaf](https://img.shields.io/badge/overleaf-supported-brightgreen)](https://tex.nju.edu.cn)
![build status](https://github.com/nju-lug/NJUThesis/actions/workflows/build.yml/badge.svg)

> 此项目是基于[NJU thesis 2021](https://github.com/FengChendian/NJUThesis2021)的重构版本,目前本科生版本**已经基本重构完成**,硕博论文**正在**根据研究生院的文件重构,但研究生院的规定并不完善,因此部分格式可能会参考本科的,**如果院系另有要求,请自行修改或者提交issue**。

原来的[NJU thesis 2021](https://github.com/FengChendian/NJUThesis2021)模板太过古老并且不支持硕士、博士论文,目前难以维护,因此为了模板的可持续发展,现在将对该项目进行重构,项目挂载于[NJU-LUG](https://github.com/nju-lug)组织仓库下,目前已[发布在CTAN](https://ctan.org/pkg/njuthesis)。

相关文档请参见[本项目wiki](https://github.com/nju-lug/NJUThesis/wiki)。

## 快速开始

从0.9.0版以后,本模板以DocStrip(`.dtx`)格式发布,同时在release区提供cls文件。

### 使用DocStrip文件

DocStrip合并了LaTeX源代码和文档,更有利于宏包的发布。要使用该文件,请在当前工作目录下打开终端:

- 输入`xetex njuthesis.dtx`以解出宏包内容
- 输入`latexmk njuthesis.dtx`以生成并查看内置的文档

请注意,由于文件重名原因,项目中的示例论文模板已被重命名为`njuthesis-sample.tex`。

### 本地编译

1. 推荐[从南大镜像站下载](https://mirror.nju.edu.cn/download/app/TeX%20%E6%8E%92%E7%89%88%E7%B3%BB%E7%BB%9F)并安装TeXLive或者MiKTeX最新版
2. 从release下载包含[模板全部文件](https://github.com/nju-lug/NJUThesis/releases/latest)的压缩包
3. 根据需要更改`njuthesis-sample.tex`文件中的内容
4. 在模板根目录下运行`latexmk -xelatex`编译文件,得到对应的PDF

#### **关于本地编译**

- 模板支持`latexmk`、`xelatex`、`lualatex`三种编译方式
- 如果使用`latexmk`,请务必使用完整的命令`latexmk -xelatex`以免产生不必要的问题
- 如果使用`xelatex`或`lualatex`,需要按照`xelatex/lualatex` -> `biber` -> `xelatex/lualatex` -> `xelatex/lualatex`的顺序编译四次
- 仓库中`.vscode`附带一份VScode的LaTeX WorkShop的配置文件,可根据需要使用

### [南大TeX](https://tex.nju.edu.cn)编译

1. 从release下载包含[模板全部文件](https://github.com/nju-lug/NJUThesis/releases/latest)的压缩包
2. 登录[南大TeX](https://tex.nju.edu.cn),点击New Project -> Upload Project上传刚刚得到的zip文件,上传后`njuthesis-sample.tex`、`njuthesis.cls`等文件应在根目录,0.9.0以后的目录结构如下所示:

    ```shell
    NJUThesis-master/

    ├─figure/
    │   njulogo.pdf
    │   njuname.pdf

    │ njuthesis.bib
    │ njuthesis.cls
    │ njuthesis-sample.tex
    ```
    
3. 在南大TeX项目内页面左上角的`Menu`中,将编译器改为`XeLaTeX`
4. 编写TeX文档

### 其他

更多内容请参见项目Wiki中的[使用说明](https://github.com/nju-lug/NJUThesis/wiki/%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E)。

你也可以下载[Release](https://github.com/nju-lug/NJUThesis/releases/latest)中附带的`njuthesis.pdf`,里面详尽阐述了模板的特性和使用方法。

## 常见问题

请参见[常见问题](https://github.com/nju-lug/NJUThesis/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98)。

## 贡献

如果你发现了模板的问题,欢迎在Github中[提交issue](https://github.com/nju-lug/NJUThesis/issues)或者PR。

## 许可

本模板的发布遵守 LaTeX Project Public License(版本 1.3c 或更高)。
%</readme>
%
%<*readme-en>
# NJU Thesis

## Overview

This is A LaTex Template for Nanjing University Thesis. This template supports bachelor, master, and doctoral thesis. The Template needs `xelatex` or `lualatex`.

## License

-----
    This work may be distributed and/or modified under the conditions of
    the [LaTeX Project Public License](http://www.latex-project.org/lppl.txt),
    either version 1.3c of this license or (at your option) any later
    version.
-----

## Contributing

If you find a problem with the template, please submit an issue or PR in Github

## Wiki

Please see [Chinese wiki](https://github.com/nju-lug/NJUThesis/wiki)。

-----

Copyright © NJU-LUG
Yu Xiong's avatar
Yu Xiong committed
%</readme-en>
%
%<*internal>
\fi
\begingroup
  \def\NameOfLaTeXe{LaTeX2e}
\expandafter\endgroup\ifx\NameOfLaTeXe\fmtname\else
\csname fi\endcsname
%</internal>
%
%<*install>
\input l3docstrip.tex
\keepsilent
\askforoverwritefalse

\preamble

Copyright (C) 2021 by Nanjing University Linux User Group <my@yaoge123.com>

This file may be distributed and/or modified under the conditions of
the LaTeX Project Public License, either version 1.3 of this license
or (at your option) any later version.  The latest version of this
license is in:

   http://www.latex-project.org/lppl.txt

and version 1.3 or later is part of all distributions of LaTeX version
2005/12/01 or later.

To produce the documentation run the original source files ending with `.dtx'
through XeTeX.
    
\endpreamble

\generate{
  \usedir{tex/latex/njuthesis}
    \file{\jobname.cls}        {\from{\jobname.dtx}{class}}
%</install>
%<*internal>
  \usedir{source/latex/njuthesis}
    \file{\jobname.ins}        {\from{\jobname.dtx}{install}}
%</internal>
%<*install>
  \usedir{doc/latex/njuthesis}
  \nopreamble\nopostamble
Yu Xiong's avatar
Yu Xiong committed
    \file{README.md}           {\from{\jobname.dtx}{readme}}
Yu Xiong's avatar
Yu Xiong committed
    \file{README_EN.md}        {\from{\jobname.dtx}{readme-en}}
}

\obeyspaces
\Msg{*************************************************************}
\Msg{*                                                           *}
\Msg{* To finish the installation you have to move the following *}
\Msg{* files into a directory searched by TeX:                   *}
\Msg{*                                                           *}
\Msg{* The recommended directory is TDS:tex/latex/njuthesis      *}
\Msg{*                                                           *}
\Msg{*     njuthesis.cls                                         *}
\Msg{*     njuthesis.ins                                         *}
Yu Xiong's avatar
Yu Xiong committed
\Msg{*     README.md                                             *}
\Msg{*     README_EN.md                                          *}
\Msg{*                                                           *}
\Msg{* To produce the documentation, run the file njuthesis.dtx  *}
\Msg{* through XeLaTeX.                                          *}
\Msg{*                                                           *}
\Msg{* Happy TeXing!                                             *}
\Msg{*                                                           *}
\Msg{*************************************************************}

\endbatchfile
%</install>
%
%<*internal>
\fi
%</internal>
%
Yu Xiong's avatar
Yu Xiong committed
%<class>\NeedsTeXFormat{LaTeX2e}
%<class>\RequirePackage{expl3}
Yu Xiong's avatar
Yu Xiong committed
%<*driver|class>
\def\ExplFileName{njuthesis}
\def\ExplFileDescription{Nanjing University thesis template class}
\def\ExplFileDate{2021-09-14}
Yu Xiong's avatar
Yu Xiong committed
\def\ExplFileVersion{0.9.0}
Yu Xiong's avatar
Yu Xiong committed
%</driver|class>
Yu Xiong's avatar
Yu Xiong committed
%<class>\ProvidesExplClass{\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
Yu Xiong's avatar
Yu Xiong committed
\ProvidesFile{\ExplFileName.dtx}
\documentclass{ctxdoc}
\begin{document}
  \DocInput{njuthesis.dtx}
\end{document}
%</driver>
% \fi
%
Yu Xiong's avatar
Yu Xiong committed
% \title{The \pkg{njuthesis} package\\ 南京大学学位论文模板}
% 
% \author{^^A
% Nanjing University Linux User Group\thanks{E-mail: \href{mailto:my@yaoge123.com}{my@yaoge123.com}}}
%
% \date{Released 2021-09-13}
Yu Xiong's avatar
Yu Xiong committed
% \tableofcontents
% \EnableDocumentation
%^^A \DisableDocumentation
% 
%<*class>
% \begin{documentation}
Yu Xiong's avatar
Yu Xiong committed
% \section{模板介绍}
%
% \section{贡献者}
% \label{sec:contributors}
%
% Put text here.
%
Yu Xiong's avatar
Yu Xiong committed
% \section{配置环境}
% \label{sec:setup}
%
% 下表是目前经过测试的环境。如果有其他可用不可用的环境,欢迎补充。
%
% \begin{table}[ht]
%     \caption{经过测试的环境}
%     % \label{tab:1}
%     \begin{tabular}{ccc}
%         \toprule
%         OS & TeX & 测试情况 \\
%         \midrule
%         Windows 10 & \hologo{TeX}\,Live 2021 & 通过 \\
%         Windows 10 & \hologo{MiKTeX} & 通过 \\
%         Windows 10 & \hologo{TeX}\,Live 2020 & cref存在格式问题  \\
%         macOS 10.15 & \hologo{TeX}\,Live 2021 & 通过 \\
%         Ubuntu 20.04 & \hologo{TeX}\,Live 2021 & 通过 \\
%         南大\hologo{TeX} & \hologo{TeX}\,Live 2021 & 通过 \\
%         Overleaf & \hologo{TeX}\,Live 2020 & cref存在格式问题  \\
%         \bottomrule
%     \end{tabular}
% \end{table}
%
% \section{本地编译}
%
% \subsubsection{安装\hologo{TeX}发行版}
%
% 首先需要下载\hologo{TeX}软件发行版,校园网环境中使用\href{https://mirror.nju.edu.cn/download/app/TeX%20%E6%8E%92%E7%89%88%E7%B3%BB%E7%BB%9F}{南大镜像站}可以获得最好的体验。\textbf{推荐使用最新的\hologo{TeX}\,Live 2021或者\hologo{MiKTeX} 21以避免潜在的兼容性问题。}
%
% \begin{itemize}
%     \item 为了避免不必要的麻烦,请尽可能下载 full 版本,如 texlive-full。简而言之,下载大的那个。
%     \item 并且,尽可能使用最新版(截至目前是 2021)。2020 及之前版本使用 PDF 格式的图片可能会出现加粗问题。
% \end{itemize}
%
% \subsubsection{选择编辑器}
%
% 配置完编译器后,还需要一个\textbf{文本编辑器}作为前端来完成\texttt{.tex}文件内容的写作。
%
% 至今仍有相当一部分人认为Windows自带的\textit{记事本}是最好的文本编辑器,但对于本项目而言,在此诚心诚意地推荐你使用\textbf{更现代更美观更多功能}的编辑器,譬如\emph{安装了 LaTeX Workshop 插件 的 \href{https://code.visualstudio.com/}{Visual Studio Code}},来完成论文编写。你也可以根据个人的喜好随便使用其他编辑器,如 TeXworks、TeX Studio 等,顺手就行。
%
% 若使用 LaTeX Workshop 插件,本项目在|.vscode/|中提供一份简易配置,可以省略初始配置步骤直接使用。
Yu Xiong's avatar
Yu Xiong committed
%
% \subsubsection{编译顺序}
% 应采用以下命令顺序进行编译,以生成正确的目录、编号和参考文献条目。
% \begin{enumerate}
%     \item |xelatex| / |lualatex|
%     \item |biber|
%     \item |xelatex| / |lualatex|
%     \item |xelatex| / |lualatex|
Yu Xiong's avatar
Yu Xiong committed
% \end{enumerate}
%
% 编译产物\footnote{作为化学学生,俺认为用“产物”代替“编译生成的文件”是一个通俗易懂的说法}为|njuthesis.pdf|,位于主目录下。此外还会生成一系列中间文件,可以选择使用|latexmk -c|进行清理。
Yu Xiong's avatar
Yu Xiong committed
%
% \subsection{在线编译}
%
% 相信你在接触了本地编译以后,很快就会意识到一些十分显然的事实,譬如\hologo{TeX}编译器安装过程较为漫长,占用空间过大,而且在一部分处理器性能不佳的电脑上需要较长编译时间\footnote{其实这三点都是对广大的Windows用户说的,同一个模板在Linux编译可以节省一半耗时}。拒绝接受这些麻烦的同学不妨尝试本节介绍的在线编译方法。
%
% \subsubsection{南大\hologo{TeX}平台简介}
%
% \href{https://tex.nju.edu.cn}{南大\hologo{TeX}}基于开源的ShareLaTeX平台\footnote{理论上在\href{https://doc.nju.edu.cn/books/latex}{这个网站}能找到一段平台简介,实际上大家都有意无意地鸽了,下次一定补上。},于2021年3月4日正式上线,面向南京大学全体师生开放,首次使用需凭学校邮箱自助注册账号。
%
% \subsubsection{操作步骤}
%
% \begin{enumerate}
%     \item 下载\href{https://github.com/nju-lug/NJUThesisUndergraduate/archive/refs/heads/master.zip}{模板全部文件}
%     \item 访问\href{https://tex.nju.edu.cn}{南大\hologo{TeX}},点击界面右上方Register,使用\emph{南京大学邮箱}注册账号并登录
%     \item 点击New Project -> Upload Project上传刚刚得到的zip文件,上传后njuthesis.tex、njuthesis.cls等文件应在根目录,目录结构如{{sec:directory}}所示
%     \item 在项目页面左上角的Menu中,将编译器改为\hologo{XeLaTeX}或者\hologo{LuaLaTeX}
%     \item 编写论文
%     \item 点击Compile按钮进行编译和预览
%     \item 点击编译按钮右侧第三个按钮下载产物
% \end{enumerate}
%
% \subsubsection{关于Overleaf平台}
%
% 由于\href{https://www.overleaf.com/}{Overleaf平台}的\hologo{TeX}\,Live版本停留在2020,\texttt{cleveref}包在引用章节时会生成错误的标签,引发格式错误;而南大\hologo{TeX}通过及时更新规避了这一问题。因此\emph{请务必不要使用Overleaf官网进行编译}。
%
% \subsection{字体}
%
% 学校论文格式要求使用的字体一般已经预装在各个操作系统,本模板针对不同平台进行了自动检测适配,可以开箱即用。
%
% 各个系统的默认字体请参考{tab:defaultfontset}。可以看到,不同系统上使用的字体有所差别,实际输出结果可能存在细微不同, 使用时请注意。例如,在Linux平台或者使用了Ubuntu后端的南大\hologo{TeX}上,宋体加粗效果更明显;另一方面,在Windows平台进行编译的效果更接近Word加粗\footnote{因为SimSun没有原生粗体,通过AutoFakeBold=2.17进行模仿}。
%
%
% \section{Usage}
%
% Put text here.
%
% \subsection{学位}
% \DescribeOption{degree}
% 选择学位,可选:
% -option{ug}(默认),-option{mg},-option{mf},-option{phd}。
%
% \subsection{类型}
% \DescribeOption{type}
% 选择学位,可选:
% -option{thesis}(默认),-option{design}。
%
% \DescribeOption{systemfont}
% 是否使用系统预装的字体,可选:
% -option{true}(默认),-option{false}。
%
% This is a stub file to allow extraction of \texttt{l3docstrip}: all
% functionality has been moved to the main DocStrip program.
%
% \end{documentation}
%
% \begin{implementation}
%
% \section{\pkg{njuthesis} implementation}
%
%    \begin{macrocode}
\LoadClass[
  a4paper,
  twoside,
  UTF8,
  scheme=chinese,
  linespread=1.625,% laTex默认1.2行距,word默认行距是1.3,要求1.5倍word行距,故1.5/1.2*1.3 = 1.625
  fontset=none,
  zihao=-4
  ]{ctexbook}[2018/04/01]
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
\RequirePackage{l3keys2e}
%    \end{macrocode}
%
% \DescribeMacro{\dummyMacro}
% This macro does nothing.\index{doing nothing|usage} It is merely an
% example.  If this were a real macro, you would put a paragraph here
% describing what the macro is supposed to do, what its mandatory and
% optional arguments are, and so forth.
%    \begin{macrocode}
\keys_define:nn { nju }
{
  titlelength       .int_set:N    =   \nju_titlelength,
  titlelength       .initial:n    =   1,
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
  secondmentor      .bool_set:N   =   \nju_second_mentor,
  secondmentor      .initial:n    =   false,
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
  nlcover           .bool_set:N   =   \nju_nl_cover,
  nlcover           .initial:n    =   false,
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
%    \begin{macrocode}
  degree            .tl_set:N     =   \nju_degree,
Yu Xiong's avatar
Yu Xiong committed
  degree            .initial:n    =   ug,
%    \end{macrocode}
%
%    \begin{macrocode}
  type              .tl_set:N     =   \nju_type,
  type              .initial:n    =   thesis,
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
%    \begin{macrocode}
  systemfont        .bool_set:N   =   \nju_systemfont,
  systemfont        .initial:n    =   true,
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
  customlatinfont   .tl_set:N     =   \nju_customlatinfont,
  customlatinfont   .initial:n    =   windows,
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
  customchinesefont .tl_set:N     =   \nju_customchinesefont,
  customchinesefont .initial:n    =   windows,
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
  info              .meta:nn      =   { nju / info } { #1 }
}
%    \end{macrocode}
%
% Put text here.
%
%    \begin{macrocode}
\keys_define:nn { nju / info }
{
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
  % 题目
  TitleA            .tl_set:N     =   \nju_title_a,
  TitleB            .tl_set:N     =   \nju_title_b,
  TitleC            .tl_set:N     =   \nju_title_c,
  TitleEN           .tl_set:N     =   \nju_title_en,
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
  % 年级学号姓名
  Grade             .tl_set:N     =   \nju_grade,
  StudentID         .tl_set:N     =   \nju_student_id,
  StudentName       .tl_set:N     =   \nju_student_name,
  StudentNameEN     .tl_set:N     =   \nju_student_name_en,
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
  % 院系专业方向
  Department        .tl_set:N     =   \nju_department,
  DepartmentEN      .tl_set:N     =   \nju_department_en,
  Major             .tl_set:N     =   \nju_major,
  MajorEN           .tl_set:N     =   \nju_major_en,
  Field             .tl_set:N     =   \nju_field,
  FieldEN           .tl_set:N     =   \nju_field_en,
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
  % 导师
  MentorA           .tl_set:N     =   \nju_mentor_a,
  MentorAEN         .tl_set:N     =   \nju_mentor_a_en,
  MentorATitle      .tl_set:N     =   \nju_mentor_a_title,
  MentorATitleEN    .tl_set:N     =   \nju_mentor_a_title_en,
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
  % 第二导师
  MentorB           .tl_set:N     =   \nju_mentor_b,
  MentorBEN         .tl_set:N     =   \nju_mentor_b_en,
  MentorBTitle      .tl_set:N     =   \nju_mentor_b_title,
  MentorBTitleEN    .tl_set:N     =   \nju_mentor_b_title_en,
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
  % 提交日期
  SubmitDate        .tl_set:N     =   \nju_submit_date,
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
  % 答辩
  DefendDate        .tl_set:N     =   \nju_defend_date,
  ReviewerChairman  .tl_set:N     =   \nju_reviewer_chairman,
  ReviewerA         .tl_set:N     =   \nju_reviewer_a,
  ReviewerB         .tl_set:N     =   \nju_reviewer_b,
  ReviewerC         .tl_set:N     =   \nju_reviewer_c,
  ReviewerD         .tl_set:N     =   \nju_reviewer_d,
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
  % 国家图书馆封面相关
  Classification    .tl_set:N     =   \nju_classification,
  SecurityLevel     .tl_set:N     =   \nju_securitylevel,
  UDC               .tl_set:N     =   \nju_udc,
  MentorInfo        .tl_set:N     =   \nju_mentor_info,
}
%    \end{macrocode}
%
% This environment does nothing.  It is merely an example.
% If this were a real environment, you would put a paragraph here
% describing what the environment is supposed to do, what its
% mandatory and optional arguments are, and so forth.
%    \begin{macrocode}
\NewDocumentCommand \njusetup { m }
{ \keys_set:nn { nju } { #1 } }
%    \end{macrocode}
% mandatory and optional arguments are, and so forth.
%    \begin{macrocode}
\ProcessKeysOptions { nju }
%    \end{macrocode}
%
% mandatory and optional arguments are, and so forth.
%    \begin{macrocode}
\RequirePackage{expl3}
\RequirePackage{fontspec}
\RequirePackage[    
    top=2.5cm,
    bottom=2.5cm,
    left=3.2cm,
    right=3.2cm
]{geometry}
% \RequirePackage{ifthen}
\RequirePackage{xparse}
% \RequirePackage{etoolbox}
% \RequirePackage{titlesec} % 修改章节标题功能由CTeX提供
\RequirePackage{titletoc} % 修改目录内标题格式
% \RequirePackage{appendix} % 定义附录样式
\RequirePackage{fancyhdr} % 调整页眉页脚
\RequirePackage[hyphens]{url} % generate better linebreaks in the url
% \RequirePackage[normalem]{ulem} % 绘制下划线
% \RequirePackage{soul} % 用不起来
% \RequirePackage{soulutf8} 
\RequirePackage{dashundergaps}
\RequirePackage{setspace}
\RequirePackage{lastpage}
\RequirePackage{emptypage} % 清除空白页的页码
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
\RequirePackage{listings} % 代码环境
\RequirePackage{enumitem} % 用于修改列表环境
\RequirePackage{caption}
\RequirePackage{floatrow} % 用于图表等页面元素的定位
\RequirePackage{booktabs} % 用于绘制三线表
\RequirePackage{multirow} % Cells occupying multiple rows in tables
\RequirePackage{multicol} % Multiple columns in dictionary
\RequirePackage{siunitx} % 用于书写单位符号
\RequirePackage[version=4]{mhchem} % 用于绘制分子式
\RequirePackage{hologo} % 用于生成可以被插入书签的LaTeX logo
% \RequirePackage{needspace} % Required to prevent page break right after a sectioning command
% \RequirePackage{xspace} % Better print trailing whitespace
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
\sys_if_engine_xetex:T
{
    \RequirePackage{microtype}

    % 加中文下划线,不能用于lualatex
    \RequirePackage{xeCJKfntef} 
    \cs_new:Npn \nju_underline:n #1 {\CJKunderline{#1}}
}
\sys_if_engine_luatex:T{
    % 加中文下划线
    \RequirePackage{lua-ul}
    \cs_new:Npn \nju_underline:n #1 {\underLine{#1}}

    % emoji支持
    % \RequirePackage{emoji}
    % \setemojifont{Segoe~UI~Emoji} % windows
    % \setemojifont{Apple~Color~Emoji} % macos
    % \setemojifont{Noto~Color~Emoji}
    % For windows. 
    % Shipped with the best `grinning-face-with-sweat' support.
}
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% 几个用来进行开发测试的包
%    \begin{macrocode}
\RequirePackage{blindtext} % 生成用于测试的大段无意义英文文字
\RequirePackage{zhlipsum} % 生成用于测试的大段无意义中文文字
% \RequirePackage{showframe} % 加载以后展示内容边界
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% 数学
%    \begin{macrocode}
\RequirePackage{amsmath} % Must be loaded before unicode-math
\RequirePackage{amsthm} % Mathematical environments
\RequirePackage{mathtools} % Mathematical tools to use with amsmath
\RequirePackage{thmtools} % Theorem styles
\RequirePackage[
    warnings-off={% 消除与mathtools合用产生的警告
        mathtools-colon,
        mathtools-overbracket}
        ]{unicode-math} % Math fonts in xetex or luatex
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
\RequirePackage{graphicx}
\DeclareGraphicsExtensions{.pdf,.eps,.jpg,.png}
\graphicspath{{figure/}} % 图片路径
\RequirePackage{wrapfig} % Wrap text around figures
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
% 必须以该顺序加载以下三个包
% \RequirePackage{varioref}
\RequirePackage[hidelinks,bookmarksnumbered=true]{hyperref}
\RequirePackage[capitalise,nameinlink,noabbrev]{cleveref}
%    \end{macrocode}
%
% and so forth.
%    \begin{macrocode}
% 设置西文字体
\NewDocumentCommand\set_latin_fontset_windows{}{
  \setmainfont{Times~New~Roman}
  \setsansfont{Arial}
  \setmonofont{Courier~New}[Scale=MatchLowercase]
}
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
\NewDocumentCommand\set_latin_fontset_macos{}{
  \setmainfont{Times~New~Roman}
  \setsansfont{Arial}
  \setmonofont{Menlo}[Scale=MatchLowercase]
}
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
\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
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
% 设置中文字体
\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]
}
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
\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,      
      % 参考CTeX手册第9节 LuaLATEX 下的中文支持方式
      % AlternateFont =
      %   {
      %   {⟨character range1⟩} {⟨alternate font name1⟩} 
      %   {⟨alternate font features2⟩} ,
      %   ......
      %   }
    ]
  \setCJKfamilyfont{zhnewhei}{PingFang~SC}
}
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
\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]
}
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
% 方正字符集
\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]
}
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
\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]
}
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
% 字体判断
\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 } {}
  }
}
% 选择其他字体,请确保相应字体已安装
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
% 设置数学字体 (XITS, 或者 STIX, 与 Times New Roman 最为相近)
% \setmathfont{STIXTwoMath-Regular}[Extension = .otf]
\setmathfont{XITSMath-Regular}[
  BoldFont = XITSMath-Bold,
  Extension = .otf]
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
\NewDocumentCommand\songti{}{\CJKfamily{zhsong}}
\NewDocumentCommand\heiti{}{\CJKfamily{zhhei}}
\NewDocumentCommand\fangsong{}{\CJKfamily{zhfs}}
\NewDocumentCommand\kaishu{}{\CJKfamily{zhkai}}
% \NewDocumentCommand\lishu{}{\CJKfamily{zhli}}
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
% 本科生页眉页脚 
\fancypagestyle{njuplain}{%
   \fancyhead{}               
   \fancyfoot[C]{\zihao{5}\thepage} % 页脚居中 五号新罗马体数字
}
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
% TODO: 研究生页眉页脚 
\fancypagestyle{njuheadings}{%
   \fancyhead{}               
   \fancyfoot[C]{\zihao{5}\thepage}        
}
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
\str_if_eq:NNTF {\nju_degree} { ug } 
{
  % the header line
  \tl_set:Nn \headrulewidth {0pt}
  % the footer line
  \tl_set:Nn \footrulewidth {0pt}
  
  \AtBeginDocument{\pagestyle{njuplain}} % 本科无页眉页脚
}
{
  % the header line
  \tl_set:Nn \headrulewidth {1pt}
  % the footer line
  \tl_set:Nn \footrulewidth {0pt}

  % \AtBeginDocument{\pagestyle{njuplain}} % 无页眉页脚
  \AtBeginDocument{\pagestyle{headings}} % 研究生有页眉页脚
}
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
% ctex格式设置
% 目录标题 三号宋体加粗
% 各部分标题 四号黑体
\ctexset{
    contentsname = 目录,
    listfigurename = 插图清单, 
    listtablename = 表格清单,
    chapter/format = \zihao{4}\heiti\centering,
    chapter/beforeskip = 10pt,
    chapter/afterskip = 60pt,
    section/format = \zihao{4}\heiti\raggedright,
    subsection/format = \zihao{4}\heiti\raggedright,
    subsubsection/format = \zihao{4}\heiti\raggedright
}

% 重定义目录中章节标题样式
% 目录内容中章的标题 四号黑体
% 目录中其他内容 小四号宋体
\titlecontents{chapter}% 标题级别
                [5em]% 标题左间距
                {\heiti\zihao{4}\vspace{10pt}}% 标题格式
                {\contentslabel{4em}}% 标题标志
                {\hspace*{-4em}}% 无序号标题
                {~\titlerule*[0.6pc]{$.$}~\contentspage}% 指引线与页码

                \titlecontents{section}
                [5em]
                {\zihao{-4}\vspace{0pt}}
                {\contentslabel{2.5em}}
                {\hspace*{-4em}}
                {~\titlerule*[0.6pc]{$.$}~\contentspage}

\titlecontents{subsection}
                [8em]
                {\zihao{-4}\vspace{0pt}}
                {\contentslabel{3em}}
                {\hspace*{-4em}}
                {~\titlerule*[0.6pc]{$.$}~\contentspage}
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
\cs_set:Npn \CTEX@addtocline #1#2
{ 
  \addcontentsline { toc } {#1} 
  { \use:c { CTEX@#1@tocline } {#1} {#2} } 
}
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}
%
% Put text here.
%    \begin{macrocode}
% 目录页面格式修改
\cs_new:Npn \nju_tocpagestyle:nnn #1 #2 #3
{
  \newpage
  \hspace{0pt}
  \vskip 10pt
  \begin{center}
    \mbox{\songti\bf\zihao{3}{#1}} % 目录页面标题
    \phantomsection
    \addcontentsline{toc}{chapter}{#2} % 插入目录
  \end{center}
  \vskip 40pt 
  \@starttoc{#3}%
  \cleardoublepage
}
Yu Xiong's avatar
Yu Xiong committed
%    \end{macrocode}