Skip to content

Commit

Permalink
feat: 新增参考文献设置选项
Browse files Browse the repository at this point in the history
仿照fduthesis添加了参考文献的设置域, 然而在禁用bibtex的前提下, 理应在导言区以前设置biblatex的文献样式
  • Loading branch information
atxy-blip committed Dec 19, 2021
1 parent 883531d commit e71994e
Show file tree
Hide file tree
Showing 5 changed files with 254 additions and 91 deletions.
220 changes: 144 additions & 76 deletions source/njuthesis.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
\csname fi\endcsname
%</internal>
%
%<*batchfile>
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
Expand Down Expand Up @@ -72,7 +72,7 @@ through XeTeX.
\file{\jobname.cls} {\from{\jobname.dtx}{class}}
%<*internal>
\usedir{source/latex/njuthesis}
\file{\jobname.ins} {\from{\jobname.dtx}{batchfile}}
\file{\jobname.ins} {\from{\jobname.dtx}{install}}
%</internal>
}

Expand All @@ -95,7 +95,7 @@ through XeTeX.
\Msg{*************************************************************}

\endbatchfile
%</batchfile>
%</install>
%
%<*internal>
\fi
Expand All @@ -115,7 +115,6 @@ through XeTeX.
\usepackage[firstpage=true]{background}
\backgroundsetup{contents={\njuemblem[white!85!gray]{22cm}{!}},scale=1,angle=0,hshift=-4cm}
\newcommand*\scite[1]{\textsuperscript{\cite{#1}}}
\setlist[1]{labelindent=0.5em}
\hypersetup{pdftitle={The njuthesis class - LaTeX thesis template for Nanjing University}}
\UseTblrLibrary{booktabs,siunitx,diagbox}
\DefTblrTemplate{caption-tag}{default}{表\hspace{0.25em}\thetable}
Expand All @@ -133,9 +132,9 @@ through XeTeX.
xrightmargin = 3 em,
escapeinside = {(*}{*)},
breaklines = true,
basicstyle = \small\ttfamily,
keywordstyle = \bfseries\color{njuviolet},
commentstyle = \itshape\color{white!50!gray},
basicstyle = \small\tt,
keywordstyle = \bf\color{njuviolet},
commentstyle = \it\color{white!50!gray},
stringstyle = \color{nju-chem-red},
backgroundcolor = \color{white!95!gray}
}
Expand Down Expand Up @@ -247,14 +246,14 @@ through XeTeX.
%
% 十几年来,多位热心校友发布过自己编写的模板,在GitHub上可考的包括
% \begin{enumerate}
% \item 杨文博(\href{http://yangwenbo.com/}{@solrex})的\href{https://github.com/solrex/njuthesis}{南京大学学位论文\hologo{LaTeX}模板}(2010
% \item \href{https://github.com/fireblue}{@fireblue}基于solrex模板的的\href{https://github.com/fireblue/NJUThesis}{南京大学学位论文\hologo{LaTeX}模板}(2013)
% \item \href{https://github.com/wenhai-zheng}{@wenhai-zheng}的\href{https://github.com/wenhai-zheng/NJUThesis}{NJUThesis}(2013)
% \item 曹增乐(\href{https://github.com/ZLCao}{@ZLCao})的\href{https://github.com/ZLCao/NJUBachelor}{NJUBachelor}(2013-2016)
% \item 杨文博(\href{http://yangwenbo.com/}{@solrex})的 njuthesis(2010 - 2018) \scite{wenboyang2013}
% \item \href{https://github.com/fireblue}{@fireblue} 基于杨文博模板的 NJUThesis(2013)\scite{fireblue2013}
% \item \href{https://github.com/wenhai-zheng}{@wenhai-zheng} 的 NJUThesis(2013)\scite{wenhai-zheng2013}
% \item 曹增乐(\href{https://github.com/ZLCao}{@ZLCao})的 NJUBachelor(2013 - 2016)\scite{zenglecao2013}
% \item 胡海星(\href{http://haixing-hu.github.io/}{@Haixing-Hu})的 NJU-Thesis(2013 - 2018)\scite{haixinghu2013}
% \item 张楚珩(\href{https://github.com/zhangchuheng123}{@zhangchuheng123})基于胡海星模板的\href{https://github.com/zhangchuheng123/NJUThesis}{NJUThesis}(2016)
% \item 蒋炎岩(\href{http://ics.nju.edu.cn/~jyy/}{@jiangyy})的\href{https://github.com/jiangyy/njuthesis}{南京大学山寨\hologo{LyX}研究生毕业论文模板}(2017
% \item \href{https://github.com/njuHan}{@njuHan}基于胡海星模板的\href{https://github.com/njuHan/njuthesis-nju-thesis-template/}{NJU-Thesis}(2018 - 2021)
% \item 张楚珩(\href{https://github.com/zhangchuheng123}{@zhangchuheng123})基于胡海星模板的 NJUThesis(2016)\scite{chuhengzhang2016}
% \item 蒋炎岩(\href{http://ics.nju.edu.cn/~jyy/}{@jiangyy})的 njuthesis(2017 - 2019)\scite{yanyanjiang2017}
% \item \href{https://github.com/njuHan}{@njuHan} 基于胡海星模板的 NJU-Thesis(2018 - 2021)
% \item 饶安逸(\href{https://anyirao.com/}{@AnyiRao})基于张楚珩模板的 NJU Thesis 2018(2018)\scite{anyirao2018}
% \item 赵懿晨(\href{https://fengchendian.github.io/about.html}{@FengChendian})基于饶安逸模板的 NJU Thesis 2021(2021)\scite{yichenzhao2021}
% \end{enumerate}
Expand Down Expand Up @@ -627,15 +626,16 @@ through XeTeX.
%
%
% \subsubsection{指定字体}
% \changes{v0.13}{2021/12/18}{使用 Adobe Source Han 替代 Google Noto 作为思源字体。}
%
% 学校论文格式要求使用的字体一般已经预装在各个操作系统,本模板针对不同平台进行了自动检测适配,可以开箱即用。
%
% 如果希望更改本模板使用的字体,请填写以下两个选项以覆盖操作系统检测得到的设置。
%
% \begin{function}[added=2021-09-07,updated=2021-12-12]{cjk-font,latin-font}
% \begin{function}[added=2021-09-07,updated=2021-12-18]{cjk-font,latin-font}
% \begin{syntax}
% cjk-font = <(win)|mac|fandol|founder|noto|none>
% latin-font = <(win)|mac|gyre|none>
% cjk-font = <win|mac|fandol|founder|source|none>
% latin-font = <win|mac|gyre|none>
% \end{syntax}
% 手动指定字体。
% \end{function}
Expand All @@ -657,31 +657,35 @@ through XeTeX.
% \begin{talltblr}[
% caption = {中文字体配置列表},
% label = {tab:chinesefontset},
% note{a} = {使用
% note{a} = {请下载简繁扩展(即 GBK 编码)版本},
% note{b} = {使用
% \href{http://www.foundertype.com/index.php/FontInfo/index/id/164}{方正小标宋}
% 作为方正书宋的粗体,使用
% 作为方正书宋的粗体},
% note{c} = {使用
% \href{http://www.foundertype.com/index.php/FontInfo/index/id/131}{方正黑体}
% 作为方正细黑一的粗体},
% note{b} = {思源字体并不包含楷书和仿宋,而Adobe楷体和仿宋难以直接下载,
% 因此使用方正字体代替;考虑到获取字体的难易程度,采用
% \href{https://www.google.com/get/noto}{noto} 字体表示思源字体},
% ] { cell{2}{2,4} = {njuyellow}, cell{4}{4} = {njuyellow}, colspec = {ccccc} }
% note{d} = {考虑到获取字体的难易程度,采用
% \href{https://mirrors.nju.edu.cn/download/Adobe%20Source%20Han}{Adobe Source Han}
% 字体表示思源字体,请下载 Simplified Chinese(即后缀名为 SC)的版本},
% note{e} = {思源字体并不包含楷书和仿宋,而 Adobe 楷体和仿宋难以直接下载,
% 因此使用方正字体代替},
% ] { cell{2}{2,4} = {white!70!njuyellow}, cell{4}{4} = {white!70!njuyellow}, colspec = {ccccc} }
% \toprule
% 配置名称 & 宋体 & 黑体 & 楷书 & 仿宋 \\
% 配置名称 & 宋体 & 黑体 & 楷书 & 仿宋 \\
% \midrule
% Windows & 中易宋体 & 中易黑体 & 中易楷体 & 中易仿宋 \\
% macOS & 华文宋体 & 华文黑体 & 华文楷体 & 华文仿宋 \\
% Windows & 中易宋体 & 中易黑体 & 中易楷体 & 中易仿宋 \\
% macOS & 华文宋体 & 华文黑体 & 华文楷体 & 华文仿宋 \\
% \href{https://www.ctan.org/pkg/fandol} {Fandol}
% & Fandol宋体 & Fandol黑体 & Fandol楷体 & Fandol仿宋 \\
% \href{https://www.foundertype.com} {方正}\TblrNote{a}
% & \href{http://www.foundertype.com/index.php/FontInfo/index/id/151}{方正书宋}
% & \href{http://www.foundertype.com/index.php/FontInfo/index/id/161}{方正细黑一}
% & \href{http://www.foundertype.com/index.php/FontInfo/index/id/137}{方正楷体}
% & \href{http://www.foundertype.com/index.php/FontInfo/index/id/128}{方正仿宋} \\
% \href{https://github.com/adobe-fonts} {思源}\TblrNote{b}
% & \href{https://fonts.google.com/noto/specimen/Noto+Serif+SC}{思源宋体}
% & \href{https://fonts.google.com/noto/specimen/Noto+Sans+SC}{思源黑体}
% & 方正楷体 & 方正仿宋 \\
% & Fandol宋体 & Fandol黑体 & Fandol楷体 & Fandol仿宋 \\
% \href{https://www.foundertype.com}{方正}\TblrNote{a}
% & \href{http://www.foundertype.com/index.php/FontInfo/index/id/151}{方正书宋}\TblrNote{b}
% & \href{http://www.foundertype.com/index.php/FontInfo/index/id/161}{方正细黑一}\TblrNote{c}
% & \href{http://www.foundertype.com/index.php/FontInfo/index/id/137}{方正楷体}
% & \href{http://www.foundertype.com/index.php/FontInfo/index/id/128}{方正仿宋} \\
% \href{https://github.com/adobe-fonts}{思源}\TblrNote{d}
% & \href{https://mirrors.nju.edu.cn/adobe-fonts/source-han-serif/OTF/SimplifiedChinese/}{思源宋体}
% & \href{https://mirrors.nju.edu.cn/adobe-fonts/source-han-sans/OTF/SimplifiedChinese/}{思源黑体}
% & 方正楷体\TblrNote{e} & 方正仿宋 \\
% \bottomrule
% \end{talltblr}
% \end{table}
Expand Down Expand Up @@ -1369,12 +1373,54 @@ through XeTeX.
%
% \emph{以下模版现已停止更新。}
%
% \bibitem{wenboyang2013}
% 杨文博.
% \newblock \textit{南京大学学位论文 \hologo{LaTeX} 模板} [EB/OL].
% \newblock (2018-06-23)
% \urlprefix\url{https://github.com/solrex/njuthesis}
%
% \bibitem{fireblue2013}
% \textsc{fireblue}.
% \newblock \textit{南京大学学位论文 \hologo{LaTeX} 模板} [EB/OL].
% \newblock (2013-04-13)
% \urlprefix\url{https://github.com/fireblue/NJUThesis}
%
% \bibitem{wenhai-zheng2013}
% \textsc{wenhai-zheng}.
% \newblock \textit{南京大学本科毕业论文 \hologo{LaTeX} 模板} [EB/OL].
% \newblock (2013-08-12)
% \urlprefix\url{https://github.com/wenhai-zheng/NJUThesis}
%
% \bibitem{zenglecao2013}
% 曹增乐.
% \newblock \textit{南京大学本科毕业论文(设计) \hologo{LaTeX} 模板} [EB/OL].
% \newblock (2019-06-26)
% \urlprefix\url{https://github.com/ZLCao/NJUBachelor}
%
% \bibitem{haixinghu2013}
% 胡海星.
% \newblock \textit{南京大学学位论文 \hologo{XeLaTeX} 模板} [EB/OL].
% \newblock (2018-08-08)
% \urlprefix\url{https://github.com/Haixing-Hu/nju-thesis}
%
% \bibitem{chuhengzhang2016}
% 张楚珩.
% \newblock \textit{南京大学本科生毕业论文 \hologo{LaTeX} 模板} [EB/OL].
% \newblock (2016-06-01)
% \urlprefix\url{https://github.com/zhangchuheng123/NJUThesis}
%
% \bibitem{yanyanjiang2017}
% 蒋炎岩.
% \newblock \textit{南京大学山寨 \hologo{LyX} 研究生毕业论文模板} [EB/OL].
% \newblock (2019-01-16)
% \urlprefix\url{https://github.com/jiangyy/njuthesis}
%
% \bibitem{njuHan2018}
% \textsc{njuHan}.
% \newblock \textit{南京大学学位论文(本科/硕士/博士),毕业论文 \hologo{LaTeX} 模板} [EB/OL].
% \newblock (2021-06-15)
% \urlprefix\url{https://github.com/njuHan/njuthesis-nju-thesis-template}
%
% \bibitem{anyirao2018}
% 饶安逸.
% \newblock \textit{南京大学本科生毕业论文 \hologo{LaTeX} 模板 2018 新版} [EB/OL].
Expand Down Expand Up @@ -2008,6 +2054,7 @@ through XeTeX.
% \end{macrocode}
%
% \subsection{个人信息}
% \changes{v0.11}{2021/10/01}{将个人信息变量名改为小写字母加连字符的形式。}
% 输入个人信息的区域。
% \begin{macrocode}
\keys_define:nn { nju } { info.meta:nn = { nju / info } { #1 } }
Expand Down Expand Up @@ -2109,8 +2156,7 @@ through XeTeX.
%
% \begin{macro}{\njusetup}
% \changes{v0.6}{2021/09/10}{改用键值对输入信息。}
% \changes{v0.11}{2021/10/01}{将个人信息变量名改为小写字母加连字符的形式。}
% 定义用于设置个人信息的命令
% 定义用于设置信息的命令
% \begin{macrocode}
\NewDocumentCommand \njusetup { m } { \keys_set:nn { nju } { #1 } }
% \end{macrocode}
Expand Down Expand Up @@ -2743,54 +2789,76 @@ through XeTeX.
%
% \subsection{参考文献}
%
% biblatex设置
% \begin{macrocode}
\RequirePackage[
style=gb7714-2015,
%style=numeric-comp,
%citestyle=authortitle-icomp,
% citestyle=numeric-comp,
%bibstyle=authoryear,
% bibstyle=numeric,
sorting=none,
%sorting=nyt,
%sortcites=true,
%autocite=footnote,
backend=biber, % Compile the bibliography with biber
hyperref=true,
backref=false,
citecounter=true,
pagetracker=true,
citetracker=true,
ibidtracker=context,
autopunct=true,
autocite=plain,
% gbpub=false, % Uncomment if you do NOT want '[S.l. : s.n.]'
% in reference entries, GitHub Issue (#47)
% gbnamefmt=lowercase, % Uncomment if you do NOT want uppercase author
% names in reference entries, GitHub Issue (#23)
]{biblatex}
% \end{macrocode}
%
% \changes{v0.12}{2021/12/06}{设置输出参考文献的默认选项。}
% 设置参考文献名称
% 设置参考文献名称
% \begin{macrocode}
\ctexset{ bibname = {参考文献} }
% \end{macrocode}
% 修改参考文献的头部样式并插入目录。
%
% \begin{macrocode}
\defbibheading { njubib } [ \bibname ] { \njuchapter { #1 } }
\DeclarePrintbibliographyDefaults { heading = njubib }
\keys_define:nn { nju } { bib.meta:nn = { nju / bib } { #1 } }
% \end{macrocode}
% \begin{macrocode}
\keys_define:nn { nju / bib }
{
% \end{macrocode}
% \begin{macro}{bib/style}
% 参考文献样式。分为顺序编码制 \opt{numeric}(gb7714-2015)和著者-出版年制 \opt{author-year}(gb7714-2015ay)。
% \begin{macrocode}
style .choice:,
style / numeric .code:n =
{ \clist_set:Nn \l_@@_tmp_clist { style = gb7714-2015 } },
style / author-year .code:n =
{ \clist_set:Nn \l_@@_tmp_clist { style = gb7714-2015ay } },
style .initial:n = numeric,
source .clist_set:N = \l_@@_bib_source_clist
}
% \end{macrocode}
%
% \begin{macro}{\@@_biblatex_pre_setup:,\@@_biblatex_post_setup:}
% 将设置传入 \pkg{biblatex} 宏包。
% \begin{macrocode}
\cs_new_protected:Npn \@@_biblatex_pre_setup:
{
\clist_put_right:Nn \l_@@_tmp_clist { backend = biber }
\exp_args:NV \PassOptionsToPackage \l_@@_tmp_clist { biblatex }
}
% \end{macrocode}
%
% \begin{macrocode}
\cs_new_protected:Npn \@@_biblatex_post_setup:
{
% \end{macrocode}
% 修改参考文献的头部样式并插入目录。
% \begin{macrocode}
\defbibheading { njubib } [ \bibname ] { \njuchapter { ##1 } }
\DeclarePrintbibliographyDefaults { heading = njubib }
% \end{macrocode}
% 传入参考文献源文件。
% \begin{macrocode}
\clist_map_inline:Nn \l_@@_bib_source_clist { \addbibresource { ##1 } }
% \end{macrocode}
% 忽略不需要的文献信息。
% \begin{macrocode}
\AtEveryBibitem
\AtEveryBibitem
{
\clist_map_inline:nn
{ abstract, issn, isbn, archivePrefix, arxivId, pmid, eprint }
{ \clearfield { ##1 } }
\ifentrytype{online}{}{\ifentrytype{misc}{}{\clearfield{url}}}
}
}
% \end{macrocode}
% \end{macro}
%
% 导入 \pkg{biblatex}。
% \begin{macrocode}
\hook_gset_rule:nnnn { begindocument/before } { . } { < } { xeCJK }
\hook_gput_code:nnn { env/document/begin } { . }
{
\clist_map_inline:nn
{ abstract, issn, isbn, archivePrefix, arxivId, pmid, eprint }
{ \clearfield { #1 } }
\ifentrytype{online}{}{\ifentrytype{misc}{}{\clearfield{url}}}
\@@_biblatex_pre_setup:
\RequirePackage{biblatex}
\@@_biblatex_post_setup:
}
% \end{macrocode}
%
Expand Down
9 changes: 9 additions & 0 deletions test/chapters/Bibliography.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ \chapter{引用参考文献}
\section{引用命令}

南京大学模板\cite{njuthesis}

顺序编码制的 \cite{qiujinhengetal2010}(上标可设置页码)、\parencite{qiujinhengetal2010}(非上标可设置页码)、\pagescite{qiujinhengetal2010}(上
标加自动页码)、\textcite{qiujinhengetal2010}(提供作者为主语加非上标编号)、\authornumcite{qiujinhengetal2010}(提供作
者为主语加上标编号)、\footfullcite{qiujinhengetal2010}(脚注方式)

著者-年份制的\cite{qiujinhengetal2010}(作者加年份用
括号包围可设置页码)、\pagescite{qiujinhengetal2010}(作者加年份用括号包围自动页码)、\yearcite{qiujinhengetal2010}(提供
年份用括号包围)、\yearpagescite{qiujinhengetal2010}(提供年份用括号包围自动页码)、\textcite{qiujinhengetal2010}(提供主
语作者加括号包围年份)、\footfullcite{qiujinhengetal2010}(脚注方式)。

0 comments on commit e71994e

Please sign in to comment.