-
Notifications
You must be signed in to change notification settings - Fork 0
/
booktemplate.sty
249 lines (216 loc) · 6.46 KB
/
booktemplate.sty
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{booktemplate}
\RequirePackage[explicit]{titlesec}
\RequirePackage{ebgaramond}
\RequirePackage[utf8]{inputenc}
\RequirePackage[english]{babel}
\RequirePackage[T1]{fontenc}
\RequirePackage{etoolbox}
\RequirePackage{graphicx}
\RequirePackage{adjustbox}
%%%%%%% Page size and general typesetting %%%%%%%
\setstocksize{216.41mm}{154.43mm}
\settrimmedsize{210mm}{148mm}{*}
%% 3.2 mm (top), 6.43 (left or right), 3.21 mm (bottom)
\settrims{3.2mm}{6.43mm}
%% To check what this looks like sans trims:
% \setstocksize{210mm}{148mm}
% \settrimmedsize{210mm}{148mm}{*}
% \settrims{0mm}{0mm}
% To see the outlines of the trims, use the memoir class's
% `showtrims' option in your main tex file:
% \documentclass[11pt,showtrims]{memoir}
\setlrmarginsandblock{22mm}{22mm}{*}
\setulmarginsandblock{20mm}{20mm}{*}
\checkandfixthelayout
% Typesetting details from
% http://www.khirevich.com/latex/microtype/
\usepackage[activate={true,nocompatibility},final,tracking=true,kerning=true,spacing=true,factor=1100,stretch=10,shrink=10]{microtype}
\frenchspacing
% Prefer increasing the inter-word spacing over creating overlong lines
\setlength{\emergencystretch}{.5em}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% Custom design elements %%%%%%%
\newcommand{\chapterstart}[1]{%
\noindent\textsc{#1}%
}
\newcommand{\sectionrule}{%
\begin{center}
$\infty$
\end{center}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% Chapter/section titles %%%%%%%
% Chapter titles:
% Horizontal rule, chapter title in italics, horizontal rule
% Based on the style 'daleif3' in http://tug.ctan.org/info/MemoirChapStyles/MemoirChapStyles.pdf
\makeatletter
\makechapterstyle{customchapter}{
% don't print "Chapter ..."
\renewcommand\chapternamenum{}\renewcommand\printchaptername{}
% don't print the chapter number
\renewcommand\printchapternum{}
\setlength\midchapskip{7pt}
\renewcommand\chaptitlefont{\huge\itshape\centering}
\renewcommand\afterchapternum{%
\hrule\vskip\midchapskip%
}
\renewcommand\afterchaptertitle{%
\par\vskip-2\midchapskip%
\rule\textwidth\normalrulethickness
\nobreak\vskip\afterchapskip%
}
}
\makeatother
\chapterstyle{customchapter}
% Mid-height horizontal rules
% Based on https://tex.stackexchange.com/a/451330 (CC BY-SA 4.0)
\makeatletter
\def\myrulefill#1#2{\leavevmode\leaders\hrule\@height#1\@depth#2\hfill \kern\z@}
\makeatother
\newcommand*\crulefilllower[1][0.4pt]{\myrulefill{\dimexpr(1ex+#1)/2}{\dimexpr(-1ex+#1)/2}}
\newcommand*\crulefillupper[1][0.9pt]{\myrulefill
{\dimexpr(\fontcharht\font`X+#1)/2}{\dimexpr(-\fontcharht\font`X+#1)/2}}
% Section titles:
% Title in italics, between horizontal rules
\titleformat{\section}{}{}{0pt}{\itshape\crulefilllower~#1~\crulefilllower}
% Subsection titles:
% Title in boldface
\titleformat{\subsection}{}{}{0pt}{\bfseries#1}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% Headers/footers %%%%%%%
% Even pages: book title in small caps
% Odd pages: chapter title in italics
% Based on https://tex.stackexchange.com/a/38449 (CC BY-SA 3.0)
\nouppercaseheads
\makepagestyle{mystyle}
\setlength{\headwidth}{\textwidth}
\makerunningwidth{mystyle}{\headwidth}
\makeevenhead{mystyle}{\thepage}{\textsc\booktitle}{}
\makeoddhead{mystyle}{}{\itshape\leftmark}{\thepage}
\makeatletter
\makepsmarks{mystyle}{%
\createmark{chapter}{left}{nonumber}{}{}
}
\makeatother
\pagestyle{mystyle}
% No page numbers on chapter opening pages
\makeoddfoot{plain}{}{}{}
\chapterstyle{plain}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% Front matter pages %%%%%%%
% Half-title (page that contains just the title)
\newcommand{\halftitlepage}[1][\booktitle]{
\vspace*{\fill}
\begin{center}
\Huge{#1}
\end{center}
\vspace{0.6\textheight}
\newpage
% Also add empty page
\null
\newpage
}
% Title page (styled like the cover)
% - extra large font sizes
\newcommand{\extrahuge}[1]{%
\fontsize{50}{60}\selectfont#1%
}
\newcommand{\veryhuge}[1]{%
\fontsize{35}{42}\selectfont#1%
}
% - the actual title page
\newcommand{\titlepage}[5]{
\begin{center}
{\Large #1}\\ % Designer
\vspace{2em}
{\huge #2}\\ % Author
\vspace{\fill}
#3\\ % Book title
\vspace{\fill}
{\LARGE\bfseries\scshape #4}\\ % Series title
\vspace{0.5em}
{\LARGE\bfseries\scshape\crulefilllower~#5~\crulefilllower} % Number in series
\end{center}
\newpage
}
% Colophon page
\newcommand{\colophonpage}[3]{
\vspace*{\fill}
\begin{center}
\begin{minipage}{0.7\textwidth}
{\centering
{\large\textit{\booktitle}}\\
#1\\% "designed by..."
}
\sectionrule
#2 % main part
\sectionrule
{\centering
This is the \_\_\_ copy of this edition.\\
}
\end{minipage}
\end{center}
\newpage
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% Front matter style %%%%%%%
% No page numbers in the front matter
% https://tex.stackexchange.com/a/53491 (CC BY-SA 3.0)
\makeatletter
\aliaspagestyle{title}{empty}
\let\origps@chapter\ps@chapter
\preto\frontmatter{\let\ps@chapter\ps@empty\pagestyle{empty}}
\preto\mainmatter{%
\cleardoublepage
\let\ps@chapter\origps@chapter\pagestyle{headings}}
\makeatother
% Table of contents:
% - no chapter/section numbers
\renewcommand{\chapternumberline}[1]{}
\renewcommand{\thesection}{}
% - dots for chapters
\renewcommand{\cftchapterdotsep}{\cftdotsep}
% - include subsections
\setcounter{tocdepth}{2}
% - indent subsections further
\makeatletter
\renewcommand*\l@subsection{\@dottedtocline{1}{6em}{0em}}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% Main matter %%%%%%%
\newcommand{\startmainmatter}[1][7]{
\mainmatter
\pagestyle{mystyle}
\setcounter{page}{#1}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% Appendix %%%%%%%
\newcommand{\startappendix}{
\cleardoublepage
\chapter{Appendix}
\setcounter{page}{1}
\pagenumbering{roman}
}
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% Hyphenation %%%%%%%
% Minimum extra line length before the compiler starts complaining
\hfuzz=2.2pt
% Ways to fix line breaks:
% - \\
% - \allowbreak{}
% - \- (inserts hyphen if LaTeX breaks the line)
% - \mbox{ ... } (no break!)
% - ~ (non-breaking space)
% Use these when custom hyphenation doesn't do the trick.
% They stretch the whitespace in otherwise too short lines
% (include up to the word before the one that's overlong).
\newcommand{\spreadlinepar}[1]{%
\makebox[\dimexpr\linewidth-\parindent][s]{#1}\\%
}
\newcommand{\spreadlinemid}[1]{%
\makebox[\dimexpr\linewidth][s]{#1}\\%
}
\hyphenation{ex-am-ple}
%%%%%%%%%%%%%%%%%%%%%%%%%%%
\endinput