\chapter{配置环境} \section{概述} 下表是目前经过测试的环境。如果有其他可用不可用的环境,欢迎补充。 \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存在格式问题 \\ Ubuntu 20.04 & \hologo{TeX}\,Live 2021 & 通过 \\ 南大\hologo{TeX} & \hologo{TeX}\,Live 2021 & 通过 \\ \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{配置前端} 推荐使用 VSCode + LaTeX Workshop(VSCode插件)完成论文编写,也可以使用其他编辑器,如 TeXworks、TeXstudio。 若使用 LaTeX Workshop 插件,本项目在\lstinline|.vscode/|中提供一份简易配置,可以直接使用。 \subsection{编译顺序} 应采用以下顺序进行编译,以生成正确的参考文献目录和编号。 \begin{enumerate} \item \lstinline|xelatex| / \lstinline|lualatex| \item \hologo{biber} \item \lstinline|xelatex| / \lstinline|lualatex| \item \lstinline|xelatex| / \lstinline|lualatex| \end{enumerate} 编译产物为\lstinline|njuthesis.pdf|。 \section{在线编译} 本地编译器占用空间过大,对于磁盘空间紧张或者处理器性能有限的同学,不妨尝试本节介绍的在线编译方法。 \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按钮进行预览 \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平台进行编译\footnote{出于编译速度考虑,不推荐在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} 各个系统的默认字体请参考\cref{tab:defaultfontset}。指定字体的相关命令写于\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 & Courier~New & 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{修改字体配置} 如果希望覆盖检测系统字体的命令(譬如在Linux编译时使用Windows字体样式),在\texttt{profile/font.sty}中注释掉操作系统判断语句,并保留希望使用的字符集即可。全部字符集命令如下所示。 \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}