% vim:ft=tex:ts=2:sw=2
%
% Peking University dissertation document class
%
% Copyright (c) 2008-2009 solvethis
% Copyright (c) 2010-2013 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}
	[2014/07/04 v1.5.4 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 use some common settings for adjusting spacing.
\pkuthssextra@int@boolopt{spacing}{true}
% Whether to use list environments that are tighter than LaTeX defaults.
\pkuthssextra@int@boolopt{tightlist}{true}
% Whether to let captions use a different font from the main text.
\pkuthssextra@int@boolopt{caption}{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 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@spacing
	% Automatically ignore spaces between CJK characters and preserve spaces in other
	% situations. 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}
	% Make the text area centered in the page.
	\geometry{centering}
	% Set line skip.
	\linespread{1.41}\selectfont
	% Automatically insert a space between the label and the text in footnotes.
	\RequirePackage{footmisc}
	\renewcommand*{\footnotelayout}{\ }
\fi

\ifpkuthssextra@opt@tightlist
	% 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.
	% Biblatex uses `\itemsep' as default `\bibitemsep', no need to change it.
	\RequirePackage{enumitem}
	\setlist{nolistsep}
\fi

\ifpkuthssextra@opt@caption
	% According to common aesthetics of typography, it is nice to make the font of
	% captions lighter than main text, and tables lighter than captions.
	\RequirePackage[font = it]{caption}
\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
	% the headers and footers in the chapter.
	\newcommand\specialchap[1]{
		\chapter*{#1}\addcontentsline{toc}{chapter}{#1}
		\markboth{#1}{}\phantomsection
	}
\fi

\AtBeginDocument{
	\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 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 = true}
	\fi
}

\endinput
