\chapter{配置环境} \textbf{特别提醒:本章文字仅供格式示例,内容已停止维护,请参考宏包手册进行设置} 下表是目前经过测试的环境。如果有其他可用不可用的环境,欢迎补充。 \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{本地编译} \subsection{安装\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} \subsection{选择编辑器} 配置完编译器后,还需要一个\textbf{文本编辑器}作为前端来完成\texttt{.tex}文件内容的写作。 至今仍有相当一部分人认为Windows自带的\textit{记事本}是最好的文本编辑器,但对于本项目而言,在此诚心诚意地推荐你使用\textbf{更现代更美观更多功能}的编辑器,譬如\emph{安装了 LaTeX Workshop 插件 的 \href{https://code.visualstudio.com/}{Visual Studio Code}},来完成论文编写。你也可以根据个人的喜好随便使用其他编辑器,如 TeXworks、TeX Studio 等,顺手就行。 若使用 LaTeX Workshop 插件,本项目在\lstinline|.vscode/|中提供一份简易配置,可以省略初始配置步骤直接使用。 \subsection{编译顺序} 应采用以下命令顺序进行编译,以生成正确的目录、编号和参考文献条目。 \begin{enumerate} \item \lstinline|xelatex| / \lstinline|lualatex| \item \lstinline|biber| \item \lstinline|xelatex| / \lstinline|lualatex| \item \lstinline|xelatex| / \lstinline|lualatex| \end{enumerate} 编译产物\footnote{作为化学学生,俺认为用“产物”代替“编译生成的文件”是一个通俗易懂的说法}为\lstinline|njuthesis.pdf|,位于主目录下。此外还会生成一系列中间文件,可以选择使用\lstinline|latexmk -c|进行清理。 \section{在线编译} 相信你在接触了本地编译以后,很快就会意识到一些十分显然的事实,譬如\hologo{TeX}编译器安装过程较为漫长,占用空间过大,而且在一部分处理器性能不佳的电脑上需要较长编译时间\footnote{其实这三点都是对广大的Windows用户说的,同一个模板在Linux编译可以节省一半耗时}。拒绝接受这些麻烦的同学不妨尝试本节介绍的在线编译方法。 \subsection{南大\hologo{TeX}平台简介} \href{https://tex.nju.edu.cn}{南大\hologo{TeX}}基于开源的ShareLaTeX平台\footnote{理论上在\href{https://doc.nju.edu.cn/books/latex}{这个网站}能找到一段平台简介,实际上大家都有意无意地鸽了,下次一定补上。},于2021年3月4日正式上线,面向南京大学全体师生开放,首次使用需凭学校邮箱自助注册账号。 \subsection{操作步骤} \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等文件应在根目录,目录结构如\cref{{sec:directory}}所示 \item 在项目页面左上角的Menu中,将编译器改为\hologo{XeLaTeX}或者\hologo{LuaLaTeX} \item 编写论文 \item 点击Compile按钮进行编译和预览 \item 点击编译按钮右侧第三个按钮下载产物 \end{enumerate} \subsection{关于Overleaf平台} 由于\href{https://www.overleaf.com/}{Overleaf平台}的\hologo{TeX}\,Live版本停留在2020,\texttt{cleveref}包在引用章节时会生成错误的标签,引发格式错误;而南大\hologo{TeX}通过及时更新规避了这一问题。因此\emph{请务必不要使用Overleaf官网进行编译}。 \section{字体} 学校论文格式要求使用的字体一般已经预装在各个操作系统,本模板针对不同平台进行了自动检测适配,可以开箱即用。 各个系统的默认字体请参考\cref{tab:defaultfontset}。可以看到,不同系统上使用的字体有所差别,实际输出结果可能存在细微不同, 使用时请注意。例如,在Linux平台或者使用了Ubuntu后端的南大\hologo{TeX}上,宋体加粗效果更明显;另一方面,在Windows平台进行编译的效果更接近Word加粗\footnote{因为SimSun没有原生粗体,通过AutoFakeBold=2.17进行模仿}。 % \begin{enumerate} % \item Ubuntu 下遇到缺失字体 WenQuanYi Zen Hei Mono 或 Times New Roman的问题: % 安装对应字体即可。使用以下指令下载: % \begin{lstlisting} % sudo apt install fonts-wqy-zenhei ttf-mscorefonts-installer % \end{lstlisting} % \item macOS 下提示 Package fontspec Warning: Font "STSong" does not contain requested Script "CJK" % 忽略即可,不影响使用。该警告已被抑制。 % \end{enumerate} 指定字体的相关命令写于\texttt{profile/font.sty}。 该文件中也预留有使用方正字体或者思源字体的命令,涉及的字体见\cref{tab:userfontset},可根据个人喜好进行修改选择。 \begin{table}[htbp] \caption{操作系统预装字体清单} \label{tab:defaultfontset} \begin{tabular}{cccc} \toprule 类型 & Windows & macOS & Linux \\ \midrule 西文衬线 & Times~New~Roman & Times~New~Roman & TeX~Gyre~Termes \\ 西文无衬线 & Arial & Arial & TeX~Gyre~Heros \\ 西文等宽 & Courier~New & Menlo & TeX~Gyre~Cursor \\ 宋体 & SimSun & Songti~SC~Light &FandolSong-Regular \\ 黑体 & SimHei & Heiti~SC~Light & FandolHei-Regular \\ 仿宋 & FangSong & STFangsong & FandolFang-Regular \\ 楷体 & KaiTi & Kaiti~SC & FandolKai-Regular \\ \bottomrule \end{tabular} \end{table} 如果 Ubuntu 下遇到缺失字体 Times New Roman 的问题,安装对应字体即可。使用以下指令下载: \begin{lstlisting} sudo apt install ttf-mscorefonts-installer \end{lstlisting} \begin{table}[htbp] \caption{预留的自定义中文字体清单} \label{tab:userfontset} \begin{tabular}{ccc} \toprule 类型 & 方正 & 思源 \\ \midrule 宋体 & FZSSK & Noto~Serif~CJK~SC \\ 黑体 & FZHTK & Noto~Sans~CJK~SC \\ 仿宋 & FZFSK & 方正仿宋简体 \\ 楷体 & FZKTK & 方正楷体简体 \\ \bottomrule \end{tabular} \end{table} \subsection{修改字体配置} 本模板提供了若干个字体相关的控制选项,已于\cref{sec:classoptions}初步进行介绍。如果希望覆盖检测系统字体的命令(譬如在Linux编译时使用Windows字体样式),请将 systemfont设置为false,并通过customlatinfont和customchinesefont进行选择。 全部字符集命令如下所示。 \begin{description} \item[\texttt{\textbackslash set\textunderscore latin\textunderscore fontset\textunderscore windows}] Windows英文字符集 \item[\texttt{\textbackslash set\textunderscore chinese\textunderscore fontset\textunderscore windows}] Windows中文字符集 \item[\texttt{\textbackslash set\textunderscore latin\textunderscore fontset\textunderscore macos}] macOS英文字符集 \item[\texttt{\textbackslash set\textunderscore chinese\textunderscore fontset\textunderscore macos}] macOS中文字符集 \item[\texttt{\textbackslash set\textunderscore latin\textunderscore fontset\textunderscore gyre}] Linux英文字符集 \item[\texttt{\textbackslash set\textunderscore chinese\textunderscore fontset\textunderscore fandol}] Linux中文字符集 \item[\texttt{\textbackslash set\textunderscore chinese\textunderscore fontset\textunderscore founder}] 方正中文字符集 \item[\texttt{\textbackslash set\textunderscore chinese\textunderscore fontset\textunderscore noto}] 思源中文字符集 \end{description} 对于需要进一步自定义的同学,可以将CustomEnFont和CustomZhFont设置为null,自行在导言区设置字体。