Skip to content

Commit

Permalink
v0.5a,通过 shell-escape 自动生成博士书脊
Browse files Browse the repository at this point in the history
  • Loading branch information
tanukihee committed Feb 20, 2021
1 parent ccd7908 commit 5391d06
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 78 deletions.
Binary file removed spine-demo.pdf
Binary file not shown.
13 changes: 0 additions & 13 deletions spine-demo.tex

This file was deleted.

Binary file added spine.pdf
Binary file not shown.
Binary file modified whu-thesis-demo.pdf
Binary file not shown.
Binary file modified whu-thesis-doc.pdf
Binary file not shown.
16 changes: 9 additions & 7 deletions whu-thesis-doc.tex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

\title{\cls{whu-thesis}\bfseries :武汉大学毕业论文模板\thanks{\url{https://github.com/whutug/whu-thesis}}}
\author{WHUTUG\thanks{\url{https://github.com/whutug}}}
\date{2021/02/08 \quad v0.5}
\date{2021/02/20 \quad v0.5a}

\begin{document}
\maketitle
Expand Down Expand Up @@ -110,18 +110,19 @@ \subsection{模板选项}

\begin{function}{type}
\begin{fdusyntax}[emph={[1]type}]
type = (*<(doctor)|master|bachelor|opening|spine>*)
type = (*<(doctor)|master|bachelor|opening>*)
\end{fdusyntax}
选择学位类型。五种选项分别代表博士学位论文、硕士学位论文、本科毕业论文、本科开题报告与博士论文书脊
选择学位类型。四种选项分别代表博士学位论文、硕士学位论文、本科毕业论文与本科开题报告
\end{function}

\kvopt{type}{opening} 时,whu-thesis 会加载 \pkg{ctexart} 文档类\kvopt{type}{spine} 时,由于 \CTeX{} 宏集暂时不支持竖排,此时 whu-thesis 加载的是 \pkg{\LuaTeX-ja} 的 \cls{ltjtarticle} 文档类;其他时候 whu-thesis 则会加载 \cls{ctexbook} 文档类。
\kvopt{type}{opening} 时,\cls{whu-thesis} 会加载 \pkg{ctexart} 文档类,其他时候 \cls{whu-thesis} 则会加载 \cls{ctexbook} 文档类。

\begin{function}{class}
\begin{fdusyntax}[emph={[1]class}]
class = (*<(academic)|professional|(paper)|design>*)
class = (*<(academic)|professional>*)
class = (*<(paper)|design>*)
\end{fdusyntax}
选择论文类型。前二选项表示 \kvopt{type}{master} 时的学术硕士与专业硕士,影响论文封面设计。后二选项表示 \kvopt{type}{bachelor} 时的毕业论文与毕业设计,这一要求在《印制规范》中并未体现,只影响论文标题上方显示为“武汉大学本科毕业论文”还是“武汉大学本科毕业设计”。
选择论文类型。上二选项表示 \kvopt{type}{master} 时的学术硕士与专业硕士,影响论文封面设计。下二选项表示 \kvopt{type}{bachelor} 时的毕业论文与毕业设计,这一要求在《印制规范》中并未体现,只影响论文标题上方显示为“武汉大学本科毕业论文”还是“武汉大学本科毕业设计”。
\end{function}

\begin{function}{draft}
Expand Down Expand Up @@ -408,7 +409,7 @@ \subsubsection{论文样式}
\end{tabularx}
\vspace*{10pt}
\begin{tablenotes}
\item[a] \kvopt{cjk-font}{overleaf} 调用的字体与 \kvopt{cjk-font}{windows} 完全相同,区别只在于 \kvopt{cjk-font}{overleaf} 时,whu-thesis 会以文件名方式调用字体。 Overleaf 用户在使用 \kvopt{cjk-font}{overleaf} 时,需要手动在目录中上传字体。
\item[a] \kvopt{cjk-font}{overleaf} 调用的字体与 \kvopt{cjk-font}{windows} 完全相同,区别只在于 \kvopt{cjk-font}{overleaf} 时,\cls{whu-thesis} 会以文件名方式调用字体。 Overleaf 用户在使用 \kvopt{cjk-font}{overleaf} 时,需要手动在目录中上传字体。
\end{tablenotes}
\end{threeparttable}
\end{table}
Expand Down Expand Up @@ -489,6 +490,7 @@ \section{宏包依赖}
\item \pkg{ti\emph{k}z}、\pkg{pgfplots},提供绘图(如圆圈数字)支持。
\item \pkg{ulem},提供绘制下划线功能。
\item \pkg{siunitx}、\pkg{physics},提供方便的单位、物理符号输入支持。
\item \pkg{shellesc},用于跳出至终端执行命令(编译书脊)。\XeLaTeX{} 下与 \cs{write18} 命令效果相同,\LuaTeX{} 删除了 \cs{write18} 命令,转而使用 "os.execute()" 跳出至终端。
\item \pkg{algorithm2e},用于提供编写算法/伪代码的支持。
\item \pkg{geometry},用于调整页面尺寸。
\item \pkg{fancyhdr},处理页眉页脚。
Expand Down
125 changes: 67 additions & 58 deletions whu-thesis.cls
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

\NeedsTeXFormat{LaTeX2e}
\RequirePackage{xparse , l3keys2e}
\ProvidesExplClass{whu-thesis}{2021/02/08}{0.5}
\ProvidesExplClass{whu-thesis}{2021/02/20}{0.5a}
{Wuhan University Thesis Template}

\msg_new:nnn { whuthesis } { 引擎不支持 }
Expand Down Expand Up @@ -52,7 +52,7 @@
{
type .value_required:n = true,
type .choices:nn =
{ doctor , master , bachelor , opening , spine }
{ doctor , master , bachelor , opening }
{ \tl_gset_eq:NN \g__whu_option_type_tl \l_keys_choice_tl },
type .initial:n = doctor,
% 学位,默认本科生
Expand Down Expand Up @@ -144,24 +144,9 @@
\LoadClass { ctexart }
}
{
\tl_if_eq:NnTF \g__whu_option_type_tl { spine }
{
\sys_if_engine_luatex:F
{
\msg_fatal:nnx { whuthesis } { 书脊引擎不支持 }
{ \c_sys_engine_str }
}
\PassOptionsToPackage { force } { lltjp-geometry }
\LoadClass { ltjtarticle }
\RequirePackage { ctexsize }
\RequirePackage { luatexja-fontspec }
\NewDocumentCommand { \ctexset } { m } {}
}
{
\PassOptionsToClass { \g__whu_option_to_class_clist } { ctexbook }
\LoadClass { ctexbook }
\bool_gset_true:N \g__whu_option_twoside_bool
}
\PassOptionsToClass { \g__whu_option_to_class_clist } { ctexbook }
\LoadClass { ctexbook }
\bool_gset_true:N \g__whu_option_twoside_bool
}
\ProcessKeysOptions { whu / option }

Expand Down Expand Up @@ -218,14 +203,16 @@
group-digits = false
}

\RequirePackage { shellesc }

\RequirePackage { algorithm2e } % 算法代码
\tl_set:Nn \algorithmcfname { 算法 }
\SetAlCapSty {}
\SetAlCapFnt { \heiti }
\box_new:N \l__whu_space_box
\hbox_set:Nn \l__whu_space_box { \nobreakspace }
\SetAlgoCaptionSeparator
{ \skip_horizontal:n { 1 em - \box_wd:N \l__whu_space_box } \hbox:n {} }
{ \hbox_to_wd:nn { 1 em - \box_wd:N \l__whu_space_box } {} }
% 算法标题后会跟一个不间断空格 ~,这里将其宽度减掉

%%% ---- 定义页面样式 ----- %%%
Expand Down Expand Up @@ -275,7 +262,7 @@
\tl_gremove_all:Nn \g__whu_head_odd_tl { \\ }
\tl_gset:Nn \g__whu_head_even_tl { 武汉大学硕士学位论文 }
}

% 默认页面页眉页脚样式
\fancypagestyle { plain }
{
Expand Down Expand Up @@ -350,6 +337,7 @@
\clist_map_inline:nn { before , after }
{ \skip_zero:c { cft ##1 #1 title skip } }
}
\skip_set:Nn \cftaftertoctitleskip { 0.5 \baselineskip }

\clist_map_inline:nn { doctor , bachelor }
{
Expand Down Expand Up @@ -516,45 +504,36 @@
% 中文字体
\cs_new_protected:Npn \__whu_set_cjk_font_song:nn #1#2
{
\tl_if_eq:NnF \g__whu_option_type_tl { spine }
{
\setCJKmainfont {#1} [#2]
\newCJKfontfamily { \songti } {#1} [#2]
}
\setCJKmainfont {#1} [#2]
\newCJKfontfamily { \songti } {#1} [#2]
}
\cs_new_protected:Npn \__whu_set_cjk_font_hei:nn #1#2
{
\tl_if_eq:NnF \g__whu_option_type_tl { spine }
{
\setCJKsansfont {#1} [#2]
\newCJKfontfamily { \heiti } {#1} [#2]
}
\setCJKsansfont {#1} [#2]
\newCJKfontfamily { \heiti } {#1} [#2]
}
\cs_new_protected:Npn \__whu_set_cjk_font_fang:nn #1#2
{
\tl_if_eq:NnTF \g__whu_option_type_tl { spine }
\setCJKmonofont {#1} [#2]
\newCJKfontfamily { \fangsong } {#1} [#2]
\cs_new:Npn \__whu_set_spine_font:
{
\file_if_exist:nTF { jfm-zh_CN.lua }
{
\setmainjfont {#1}
\exp_not:N \setmainjfont {#1}
[
#2 , TateFeatures =
{ JFM = zh_CN / { \g__whu_option_punct_tl , vert } }
{
JFM = zh_CN / { \exp_not:o \g__whu_option_punct_tl , vert }
}
]
}
{ \setmainjfont {#1} [#2] }
}
{
\setCJKmonofont {#1} [#2]
\newCJKfontfamily { \fangsong } {#1} [#2]
{ \exp_not:N \setmainjfont {#1} [ #2 ] }
}
}
\cs_new_protected:Npn \__whu_set_cjk_font_kai:nn #1#2
{
\tl_if_eq:NnF \g__whu_option_type_tl { spine }
{
\newCJKfontfamily { \kaishu } {#1} [#2]
}
\newCJKfontfamily { \kaishu } {#1} [#2]
}

\cs_new_protected:Npn \__whu_set_cjk_font_windows:
Expand Down Expand Up @@ -1030,17 +1009,6 @@
\__whu_set_table_font:
}

\cs_new_protected:Npn \__whu_make_front_matter_spine:
{
\pagestyle { empty }
\mode_leave_vertical: \vfil
\noindent \hbox_to_wd:nn { \textwidth }
{
\zihao { 4 } \g__whu_info_title_tl
\hfill \g__whu_info_author_tl
}
}

%%%% ---- 论文封面 ---- %%%%
\cs_new_protected:Npn \__whu_make_cover_bachelor:
{
Expand Down Expand Up @@ -1164,7 +1132,7 @@
\g__whu_info_direction_tl \\ [ 0.5 em ]
}
{
\__whu_spread_with:nn { 专业类别 { (领 } { 域) } } { \hfill }
\__whu_spread_with:nn { 专业类别 { (领 } { 域) } } { \hfill }
& \g__whu_info_major_tl \\ [ 0.5 em ]
}
}
Expand Down Expand Up @@ -1372,6 +1340,7 @@
\__whu_make_achievements:
\__whu_make_thanks:
\__whu_make_appendix:
\__whu_make_spine:
}

\cs_new_protected:Npn \__whu_make_back_matter_master:
Expand Down Expand Up @@ -1400,8 +1369,6 @@
\hfill\qquad\qquad
}

\cs_new_protected:Npn \__whu_make_back_matter_spine: {}

%%%% ---- 参考文献 ---- %%%%
\cs_new_protected:Npn \__whu_make_bibliography:
{
Expand Down Expand Up @@ -1469,4 +1436,46 @@
\clist_map_inline:Nn \g__whu_element_appendix_clist
{ \file_input:n {##1} }
}
}

%%%% ---- 书脊 ---- %%%%
\cs_new_protected:Npn \__whu_make_spine:
{
\iow_new:N \g__whu_spine_iow
\iow_open:Nn \g__whu_spine_iow { spine.tex }
\iow_now:Nx \g__whu_spine_iow
{
\tl_to_str:n
{
\documentclass { ltjtarticle }
\usepackage { ctexsize }
\usepackage { geometry }
\geometry { margin = 2.5 cm , ignoreall }
\usepackage { luatexja-fontspec }
\ExplSyntaxOn
}
\__whu_set_spine_font:
\tl_to_str:n
{
\begin { document }
\pagestyle { empty }
\mode_leave_vertical: \vfil
\noindent \hbox_to_wd:nn { \textwidth }
}
\iow_char:N \{ \iow_newline:
\tl_to_str:n { \zihao { 4 } } \exp_not:o \g__whu_head_odd_tl
\tl_to_str:n { \hfill } \exp_not:o \g__whu_info_author_tl
\iow_char:N \}
\tl_to_str:n { \end { document } }
}
\iow_close:N \g__whu_spine_iow
\__whu_compile_spine:
}

\cs_new_protected:Npn \__whu_compile_spine:
{
\ShellEscape { lualatex ~ spine }
\sys_if_platform_windows:TF
{ \ShellEscape { del ~ spine.tex } }
{ \ShellEscape { rm ~ spine.tex } }
}

0 comments on commit 5391d06

Please sign in to comment.