\subsection{\file{hduthesis-hdu.stationery-module.code} 的实现} 提供模块 \file{hdu.stationery} 文件 \begin{minted} [ linenos, bgcolor = bg, breaklines ] {tex} \hduthesis_provide_module:n {hdu.stationery} \end{minted} 定义文档信息的键 \begin{minted} [ linenos, firstnumber = last, bgcolor = bg, breaklines ] {tex} \keys_define:nn { hdu.stationery / docinfo } { watermark .bool_set:N = \g__docinfo_watermark_bool, watermark .initial:n = false, watermark .default:n = true, title .tl_set:N = \@title, author .tl_set:N = \@author, mail .tl_set:N = \l__docinfo_mail_tl, date .tl_set:N = \@date } \end{minted} 加载所需的宏包 \begin{minted} [ linenos, firstnumber = last, bgcolor = bg, breaklines ] {tex} \RequirePackage{ hyperref, geometry, tikz, twemojis, fancyhdr } \hypersetup{hidelinks} \urlstyle{same} \end{minted} 定义用户端文档信息的输入命令:清空令牌 \cs{@author} 和 \cs{l__docinfo_mail_tl} 用于后续判断,设置键值对,通过 \pkg{hyperref} 设置 PDF 信息 \begin{minted} [ linenos, firstnumber = last, bgcolor = bg, breaklines ] {tex} \NewDocumentCommand \DocInfo { m } { \tl_clear:N \@author \tl_clear:N \l__docinfo_mail_tl \keys_set:nn { hdu.stationery / docinfo } {#1} \hypersetup { pdftitle = Hangzhou Dianzi University, pdfsubject = \@title, pdfauthor = \@author } } \end{minted} 定义页面布局 \begin{minted} [ linenos, firstnumber = last, bgcolor = bg, breaklines ] {tex} \geometry { hmargin = .8in, bottom = .75in, top = 1.95in, footskip = 15.87pt, headheight = 1.2in, headsep = .3in, footskip = .3in } \linespread{1.25} \RequirePackage [ skip = \baselineskip ] { parskip } \renewcommand* \familydefault { \sfdefault } \end{minted} 定义杭州电子科技大学主题色 \begin{minted} [ linenos, firstnumber = last, bgcolor = bg, breaklines ] {tex} \definecolor{hdu}{HTML}{214395} \end{minted} 定义页眉页脚样式 \begin{minted} [ linenos, firstnumber = last, bgcolor = bg, breaklines ] {tex} \renewcommand* \headrulewidth {2pt} \renewcommand* \footrulewidth {2pt} \hook_gput_code:nnn { cmd/headrule/before } { . } { \color{hdu!80} } \hook_gput_code:nnn { cmd/footrule/before } { . } { \color{hdu!80} } \lhead { {}~ \minipage{.6\linewidth} \medskip \leavevmode \lower -.111in \hbox { \includegraphics [ height = .75in ] {hdubadge} } \endminipage \medskip \hfill \minipage{.36\linewidth} \medskip \vbox { \linespread{1.2} \raggedright \small \color{hdu} \texttwemoji{1f4cd}~ 1158~No.2~St.,~ Hangzhou,~ 310018\\ \texttwemoji{1f4de}~ (86)~0571-86915072\\ \texttwemoji{1f310}~ \url{www.hdu.edu.cn} } \medskip \endminipage } \lfoot { \small{}~ \texttwemoji{1f4cd}~ 1158~No.2~Street,~ Qiantang~District,~ Hangzhou,~ Zhejiang~Province,~ 310018,~ P.R.China } \cfoot {} \rfoot { \small \texttwemoji{1f310}~ \url{www.hdu.edu.cn}~ } \pagestyle{fancy} \end{minted} 定义标题样式. 当令牌 \cs{@author} 和 \cs{l__docinfo_mail_tl} 都不为空时,输出 ``From'';当 \cs{@author} 为空时,输出未提供作者警告信息;当 \cs{l__docinfo_mail_tl} 不为空时,输出邮箱;当 \cs{@author} 和 \cs{l__docinfo_mail_tl} 都不为空时,输出换行;输出 ``Date'' 和日期;当 \cs{@title} 为空时,输出未提供标题错误消息;输出 ``Subject'' 和标题 \begin{minted} [ linenos, firstnumber = last, bgcolor = bg, breaklines ] {tex} \renewcommand* \maketitle { \group_begin: \small \bool_if:nT { !\tl_if_empty_p:N \@author || !\tl_if_empty_p:N \l__docinfo_mail_tl } { \makebox [ 4em ] [ l ] { \scshape From } } \tl_if_empty:NTF \@author { \@latex@warning@no@line {No \noexpand \author given} } { \@author{}~ } \tl_if_empty:NF \l__docinfo_mail_tl { \texttt { <\l__docinfo_mail_tl> } } \bool_if:nT { !\tl_if_empty_p:N \@author || !\tl_if_empty_p:N \l__docinfo_mail_tl } { \\ } \makebox [ 4em ] [ l ] { \scshape Date } \tl_if_empty:NTF \@date \today \@date \\ \tl_if_empty:NTF \@title { \@latex@error {No \noexpand \title given}\@ehc } { \makebox [ 4em ] [ l ] { \scshape Subject } \@title } \par \vspace{.5\baselineskip} \group_end: } \end{minted} 更改字体颜色,通过钩子设置背景,添加水印 \begin{minted} [ linenos, firstnumber = last, bgcolor = bg, breaklines ] {tex} \AtBeginDocument { \color_select:n {black!80} } \DeclareHookRule { shipout / background } { hduthesis / stationery } { before } { pgfrcs } \AddToHook { shipout / background } [ hduthesis / stationery ] { \bool_if:NT \g__docinfo_watermark_bool { \tikz [ remember~picture, overlay ] \node [ opacity = .2 ] at (current~page) { \includegraphics [ width = .4\linewidth ] {hdulogo} }; } } \end{minted} 加载宏包 \pkg{tikzpagenodes} 用于定位文本区域. 定义命令 \cs{notelines} 用于绘制线条,参数为行数,默认为 20 行. 使用 \pkg{tikz} 绘制线条,透明度为 0.6,颜色为 \cs{hdu},线宽为 2pt,从当前页文本区域的西北角开始,向东绘制线条 \cs{linewidth} 长,每行间隔为 \cs{textheight} 的 20 分之一 \begin{minted} [ linenos, firstnumber = last, bgcolor = bg, breaklines ] {tex} \RequirePackage{tikzpagenodes} \NewDocumentCommand \notelines { O{20} } { \tikz [ remember~picture, overlay ] { \int_step_inline:nn { #1 - 1 } { \draw [ hdu, very~thick, opacity = .6 ] ([yshift = -##1 * (\textheight + .6in - 15.87pt ) / #1 + .3in] current~page~text~area.north~west) --++ (\linewidth, 0); } } } \end{minted} 从 \cls{ltxdoc} 中抄取命令 \cs{meta} \begin{minted} [ linenos, firstnumber = last, bgcolor = bg, breaklines ] {tex} \newcommand \meta[1] { \ensuremath \langle \ifmmode \expandafter \nfss@text \fi { \itshape\ttfamily \edef \meta@hyphen@restore { \hyphenchar \the \font \the \hyphenchar \font } \hyphenchar \font \m@ne \language \l@nohyphenation #1\/\meta@hyphen@restore } \ensuremath \rangle } \end{minted} 结束模块 \file{hduthesis-stationery-module.code} 文件 \begin{minted} [ linenos, firstnumber = last, bgcolor = bg, breaklines ] {tex} \endinput \end{minted}