summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/pkuthss/pkuthss-extra.sty
blob: 570f8c48bb0f11d936d1224f0059bb28b458de9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
% vim:ft=tex:ts=2:sw=2
%
% Peking University dissertation document class
%
% Copyright (c) 2008-2009 solvethis
% Copyright (c) 2010-2015 Casper Ti. Vector
%
% This work may be distributed and/or modified under the conditions of the
% LaTeX Project Public License, either version 1.3 of this license or (at
% your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX version
% 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
% The current maintainer of this work is Casper Ti. Vector.
%
% This work consists of the following files:
%   pkuthss.cls
%   pkuthss-gbk.def
%   pkuthss-utf8.def
%   pkuthss-extra.sty
%   pkulogo.eps
%   pkuword.eps

\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{pkuthss-extra}
	[2015/04/28 v1.6.0 Common extra settings for the pkuthss document class]

% Check the dependency of pkuthss.
\@ifclassloaded{pkuthss}{}{
	\PackageError{pkuthss-extra}%
		{The pkuthss document class is not loaded}%
		{The pkuthss-extra package depends on the pkuthss document class.}
}

% eg. `\pkuthssextra@int@boolopt{spacing}{true}' will expand to:
%   \newif\ifpkuthssextra@opt@spacing \pkuthssextra@opt@spacingtrue
%   \DeclareOption{spacing}{\pkuthssextra@opt@spacingtrue}
%   \DeclareOption{nospacing}{\pkuthssextra@opt@spacingfalse}
\def\pkuthssextra@int@boolopt#1#2{
	\expandafter\newif\csname ifpkuthssextra@opt@#1\endcsname
	\@nameuse{pkuthssextra@opt@#1#2}
	\DeclareOption{#1}{\@nameuse{pkuthssextra@opt@#1true}}
	\DeclareOption{no#1}{\@nameuse{pkuthssextra@opt@#1false}}
}
% Whethet to modify footnote format.
\pkuthssextra@int@boolopt{footfmt}{true}
% Whethet to modify spacing according to school regulation.
\pkuthssextra@int@boolopt{pkuspace}{true}
% Whethet to use some common settings for adjusting spacing.
\pkuthssextra@int@boolopt{spacing}{true}
% Add PDF bookmark for table of contents.
\pkuthssextra@int@boolopt{pdftoc}{true}
% Whether to enable the `\spacialchap' command.
\pkuthssextra@int@boolopt{spechap}{true}
% Whether to automatically set up properties for generated PDF from user
% defined document information (author, title, etc.).
\pkuthssextra@int@boolopt{pdfprop}{true}
% Whether to use coloured hyperlinks in generated PDF.
\pkuthssextra@int@boolopt{colorlinks}{true}
% Process all class options now.
\ProcessOptions\relax

\ifpkuthssextra@opt@footfmt
	% Handle the `Unparsed material' issue with latex/dvipdfmx compilation.
	\unless\ifxetex\unless\ifpdf
		\newcommand*\pgfsysdriver{pgfsys-dvipdfm.def}
	\fi\fi
	% Circled text, cf. <https://tex.stackexchange.com/questions/7032/>.
	\RequirePackage{tikz}
	\newcommand*\pkuthssextra@int@circled[1]{%
		\scalebox{0.8}{\tikz[baseline = (char.base)]{
			\node[
				shape = circle, draw = black, minimum size = 1.25em, inner sep = 0pt
			] (char) {#1};
		}}%
	}
	% Use circled numbers as footnote symbols. Does not affect title page, but
	% footnote is rarely used in dissertation covers ;)
	\renewcommand\thefootnote%
		{\protect\pkuthssextra@int@circled{\arabic{footnote}}}
	% Provides utility to modify footnote spacing.
	% Option used to make sure it does not render interleaf pages totally blank.
	\RequirePackage[cleardoublepage = current]{scrextend}
	% Set up footnote spacing: symbol indent 2 ccwd, paragraph indent 3.5 ccwd,
	% 0.75 ccwd between symbol and paragraph.
	\deffootnote{2\ccwd}{3.5\ccwd}{\thefootnotemark\hspace{0.75\ccwd}}
\fi

\ifpkuthssextra@opt@pkuspace
	% lineskip / baselineskip = 20 bp / (12 bp * (6 / 5)).
	\linespread{1.39}\selectfont
	% Quite harmless and frequently used package. Loaded together with `tocloft'
	% plus a compatibility option to avoid package clash.
	\RequirePackage{subfig}
	% Provides utilities for setting TOC format; `titles' applied to avoid
	% interfering with LaTeX's own title mechanism.
	\RequirePackage[subfigure, titles]{tocloft}
	\setlength{\cftbeforechapskip}{6bp plus 1bp}
	\setlength{\cftsecindent}{\ccwd}
	\setlength{\cftsubsecindent}{2\ccwd}
	% Modify font size and separator of captions.
	\RequirePackage{caption}
	\DeclareCaptionFont{cfive}{\zihao{5}}
	\DeclareCaptionLabelSeparator{quad}{\quad}
	\captionsetup{font = cfive, labelsep = quad}
\fi

\ifpkuthssextra@opt@spacing
	% Automatically ignore spaces between CJK characters, or otherwise preserve
	% spaces. XeCJK itself will handle this issue, therefore we do not use
	% `CJKspace' when using XeLaTeX.
	\unless\ifxetex\RequirePackage{CJKspace}\fi
	% Make spacing nicer in some situations (eg. footnotes and verbatims).
	\RequirePackage{setspace}
	% Lists often appear to be too sparse when items are just one or two lines
	% long. Here we cancel the extra vertical spacing between list items.
	\RequirePackage{enumitem}
	\setlist{nolistsep}
\fi

\ifpkuthssextra@opt@pdftoc
	% Add PDF bookmark for table of contents.
	\let\pkuthssextra@tmp@tableofcontents\tableofcontents
	\renewcommand{\tableofcontents}{
		% Make the `Contents' bookmark point correctly to the title of the table of
		% contents.
		\cleardoublepage
		% Actually add the PDF bookmark.
		\pdfbookmark[1]{\contentsname}{contents}
		\pkuthssextra@tmp@tableofcontents
	}
\fi

\ifpkuthssextra@opt@spechap
	% This command is used to start a chapter without numbering, and correctly set
	% up the headers and footers in the chapter.
	\newcommand\specialchap[1]{
		\chapter*{#1}\addcontentsline{toc}{chapter}{#1}
		\markboth{#1}{}\phantomsection
	}
\fi

\AtBeginDocument{
	\ifpkuthssextra@opt@pkuspace
		% Kludge for `tocloft' used with `ctex'.
		% <http://bbs.ctex.org/forum.php?mod=redirect&goto=findpost&ptid=43535&pid=310238>.
		\renewcommand{\numberline}[1]{%
			\settowidth\@tempdimb{#1\hspace{0.5em}}%
			\ifdim\@tempdima<\@tempdimb%
				\@tempdima=\@tempdimb%
			\fi%
			\hb@xt@\@tempdima{\@cftbsnum #1\@cftasnum\hfil}\@cftasnumb%
		}%
	\fi

	\ifpkuthssextra@opt@pdfprop
		% Automatically generate properties for generated PDF.
		% Use English properties to avoid problems with character encodings.
		\newcommand*{\setpdfproperties}{
			\hypersetup{
				pdfauthor = {\@eauthor}, pdftitle = {\@etitle},
				pdfsubject = {\euniversity\ \ethesisname}, pdfkeywords = {\@ekeywords}
			}
		}
		% Set up the properties when generating the title page because the document
		% information should have been all defined before this.
		\let\pkuthssextra@tmp@maketitle\maketitle
		% NOTE: `\hypersetup' must appear before `\maketitle', otherwise it might not
		% act as wished.
		\renewcommand\maketitle{\setpdfproperties\pkuthssextra@tmp@maketitle}
	\fi

	\ifpkuthssextra@opt@colorlinks
		% Use coloured hyperlinks in generated PDF.
		\hypersetup{colorlinks = true, allcolors = blue}
	\else
		% Set hyperlink colour to black in order to prevent hyperlinks from being
		% too hard-to-recognise in printed thesis.
		\hypersetup{hidelinks}
	\fi
}

\endinput