forked from cbx33/gitt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitt.cls
426 lines (362 loc) · 11 KB
/
gitt.cls
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
%
% Book design for Git in the Trenches
%
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesClass{gitt}[2011/05/15 v1.0.0 GITT book design]
\RequirePackage{xifthen}
% The 'screen' option creates a PDF suitable for reading on a computer screen
% The 'print' option creates a PDF suitable for printing
\providecommand{\gitt@format}{screen}% default format
\DeclareOption{screen}{\gdef\gitt@format{screen}}
\DeclareOption{print}{\gdef\gitt@format{print}}
\newboolean{gitt@debug}
\setboolean{gitt@debug}{false}
\DeclareOption{debug}{\setboolean{gitt@debug}{true}}
% All other options are passed along to the base class
\DeclareOption*{%
\PassOptionsToClass{\CurrentOption}{book}%
}
\ProcessOptions*\relax
\LoadClass[openright,11pt]{book}
% set paper size
%\setstocksize{24.59cm}{18.90cm}
%%\settrims{1.91cm}{0cm}
%\settrimmedsize{\stockheight}{\stockwidth}{*}
%\setlrmarginsandblock{2.79cm}{2.29cm}{*}
%\setulmarginsandblock{2.91cm}{2.91cm}{*}
%%\setmarginnotes{0.5cm}{2cm}{0.2cm}
%\checkandfixthelayout
\RequirePackage[paperheight=9.68in,paperwidth=7.44in,headheight=\baselineskip,textheight=35\baselineskip]{geometry}
\ifthenelse{\equal{\gitt@format}{screen}}{%
\geometry{asymmetric}%
}
% Some special processing for debug mode
\ifthenelse{\boolean{gitt@debug}}{%
%\geometry{showframe}% draws lines showing the margins
\RequirePackage[letter,center,cam]{crop}% draw crop marks on the page
}{}
% Reset the figure numbering at the beginning of each chapter and print only
% the figure number (not including the chapter number).
\renewcommand{\thefigure}{\arabic{figure}}
% Import packages
% Load colors
\PassOptionsToPackage{usenames,dvipsnames,svgnames}{xcolor}
\RequirePackage{xcolor}
\RequirePackage[final]{graphicx}
\RequirePackage{fancyvrb,relsize}
\RequirePackage{tikz}
\RequirePackage{makeidx}
\RequirePackage{eso-pic}
\makeindex
% Font settings
\RequirePackage{fontspec}
\setmainfont[Mapping=tex-text,Numbers=OldStyle]{Linux Libertine O}
%\setsansfont[Mapping=tex-text,Scale=MatchLowercase]{LMSans10}
%\setsansfont[Mapping=tex-text,Scale=MatchLowercase,SmallCapsFont={* Small Caps}]{Fontin Sans}
%\setsansfont[Mapping=tex-text,Scale=MatchLowercase]{PT Sans}
\setmonofont[Mapping=tex-text,Scale=MatchLowercase]{DejaVu Sans Mono}
% Small caps
\newcommand{\smallcaps}[1]{%
{\addfontfeature{LetterSpace=5.0}\textsc{\MakeTextLowercase{#1}}}%
}
% Running heads and feet
\RequirePackage{textcase}
\RequirePackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE]{\thepage\quad\smallcaps{\leftmark}}
\fancyhead[RO]{\smallcaps{\rightmark}\quad\thepage}
\renewcommand{\headrulewidth}{0pt}
% Front matter
\renewcommand\frontmatter{%
\cleardoublepage%
\@mainmatterfalse%
\pagenumbering{roman}%
\fancyhf{}%
\renewcommand{\chaptermark}[1]{\markboth{##1}{}}%
\renewcommand{\sectionmark}[1]{\markright{##1}}%
\fancyhead[LE]{\thepage\quad\smallcaps{\leftmark}}% chapter title
\fancyhead[RO]{\smallcaps{\rightmark}\quad\thepage}% section title
}
% Main matter
\renewcommand\mainmatter{%
\cleardoublepage%
\@mainmattertrue%
\pagenumbering{arabic}%
\fancyhf{}%
\renewcommand{\chaptermark}[1]{\markboth{##1}{}}%
\renewcommand{\sectionmark}[1]{\markright{##1}}%
\fancyhead[LE]{\thepage\quad\smallcaps{\leftmark}}% chapter title
\fancyhead[RO]{\smallcaps{\rightmark}\quad\thepage}% section title
}
% When cleardoublepage is called, produce a blank (empty) page -- i.e.,
% without headers and footers
\def\cleardoublepage{%
\clearpage
\if@twoside%
\ifodd\c@page\else
\hbox{}%
%\vspace*{\fill}
%\begin{center}
% This page intentionally contains only this sentence.
%\end{center}
%\vspace{\fill}
\thispagestyle{empty}%
\newpage%
\if@twocolumn\hbox{}\newpage\fi%
\fi%
\fi%
}
% Put chapters and sections in the toc, only number the chapter
\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{0}
% Make chapter names disappear
\renewcommand{\chaptername}{}
\renewcommand{\thechapter}{}
\renewcommand{\tablename}{}
\renewcommand{\thetable}{}
% Print just the chapter name without 'Chapter #.' in the running heads
%\renewcommand\chaptermark[1]{\markboth{\memUChead{#1}}{}}%
% Make the pdf have clickable links
\RequirePackage{hyperref}
\hypersetup{%
bookmarks,
bookmarksopen,
bookmarksnumbered=false,
colorlinks=true,
pdfpagemode=None,
pdfborder = {0 0 0},
citecolor = DarkGreen,
linkcolor = DarkBlue,
urlcolor = DarkGreen,
plainpages=false,
pdfpagelabels,
pdftitle={Git in the Trenches},
pdfauthor={Peter Savage}
}
% Use black link colors for print edition
\ifthenelse{\equal{\gitt@format}{print}}{%
\hypersetup{%
colorlinks=false
}%
}
\AtBeginDocument{
\hyphenpenalty=1000
\tolerance=1000
}
% give us a begin{trenches}
\newenvironment{trenches}{%
\begin{quote}%
\begin{sffamily}%
\noindent\textbf{In the trenches\ldots}\quad%
}{%
\end{sffamily}%
\end{quote}%
}
% Callout boxes
\newsavebox{\callout@contents}
\newcommand{\callout@type}{}
\newcommand{\callout@title}{}
\newenvironment{callout}[2]{%
\xdef\callout@type{#1}% typeset in a box along the left
\xdef\callout@title{#2}% typeset in a box along the top
\begin{lrbox}{\callout@contents}%
\begin{minipage}{\textwidth-30pt}%
}{%
\end{minipage}%
\end{lrbox}%
\begin{figure}[hbt]%
\tikzstyle{mybox} = [draw=black, fill=gray!20, very thick, rectangle, rounded corners, inner sep=15pt, inner ysep=20pt, font={\sffamily\bfseries}]
\tikzstyle{fancytitle} = [fill=black, text=white, font={\sffamily\bfseries}]
\hskip-10pt% allows the type block to hang into the left margin
\begin{tikzpicture}%
\node[mybox] (box) {\usebox{\callout@contents}};
\node[fancytitle, right=16pt] at (box.north west) {\callout@title};
\node[fancytitle, rounded corners] at (box.west) {\rotatebox{90}{\callout@type}};
\end{tikzpicture}%
\end{figure}%
}
% Indicates thought breaks
\newcommand{\thoughtbreak}{%
\par\begin{center}*\quad*\quad*\end{center}\par
}
% Clear page commands from memoir.cls
\newcommand{\cleartoevenpage}[1][\@empty]{%
\clearpage%
\ifodd\c@page\hbox{}#1\clearpage\fi%
}
\newcommand{\cleartooddpage}[1][\@empty]{%
\clearpage%
\ifodd\c@page\else\hbox{}#1\clearpage\fi%
}
% Inserts full-page graphics for cover pages.
\newcommand{\coverpage}[1]{%
\thispagestyle{empty}%
\IfFileExists{#1}{%
\AddToShipoutPicture*{\put(0,0){\includegraphics[width=\paperwidth,height=\paperheight]{#1}}}%
}{%
\ClassWarningNoLine{gitt}{Missing cover page graphic:\MessageBreak #1}%
}%
}
\newcommand{\frontcover}[1]{%
\ifthenelse{\equal{\gitt@format}{screen}}{%
\coverpage{#1}%
\null\cleardoublepage
}{%
\ClassWarningNoLine{gitt}{Ignoring \string\frontcover because we're not generating a screen format.}%
}%
}
\newcommand{\backcover}[1]{%
\ifthenelse{\equal{\gitt@format}{screen}}{%
\cleartoevenpage[\thispagestyle{empty}]%
\coverpage{#1}%
\null%
}{%
\ClassWarningNoLine{gitt}{Ignoring \string\backcover because we're not generating a screen format.}%
}%
}
\newcommand{\indexref}[1]{%
\index{#1|textit}%
}
\newcommand{\indexcom}[2]{%
\index{#1@\texttt{#2}}%
}
\newcommand{\indexgit}[1]{%
\texttt{git #1}%
\index{git commands!#1@\texttt{#1}}%
}
\newcommand{\figuregit}[3]{%
\begin{figure}[bt]%
\centering
\includegraphics[width=#1]{#2}%
\caption{#3}%
\end{figure}%
}
\newcommand{\figuregith}[3]{%
\begin{figure}[hbt]%
\centering
\includegraphics[width=#1]{#2}%
\caption{#3}%
\end{figure}%
}
\RequirePackage{listings}
\lstnewenvironment{code}{
\lstset{
basicstyle=\footnotesize\ttfamily,
identifierstyle=\footnotesize\ttfamily,
commentstyle=\footnotesize\ttfamily,
stringstyle=\footnotesize\ttfamily,
keywordstyle=\footnotesize\bfseries\ttfamily,
frame=leftline,
rulecolor=\color{lightgray},
framerule=1mm,
framextopmargin=0pt,
framexbottommargin=0pt,
framexleftmargin=2pt,
framexrightmargin=2pt,
xleftmargin=8pt,
xrightmargin=2pt,
breaklines=true,
breakatwhitespace=true,
breakindent=4pt,
postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\hookrightarrow}},
tabsize=2,
showstringspaces=false,
aboveskip=\abovedisplayskip,
belowskip=\belowdisplayskip,
morecomment=[l][\footnotesize\bfseries\ttfamily]{john@satsuki:},
morecomment=[l][\footnotesize\bfseries\ttfamily]{rob@mimi:}
%moredelim=[is][\tiny\bfseries\ttfamily]{|||}{|||}
}
}{}
% Table of contents
\renewcommand\tableofcontents{%
\if@twocolumn
\@restonecoltrue\onecolumn
\else
\@restonecolfalse
\fi
\chapter*{\contentsname
\@mkboth{\contentsname}{\contentsname}
}%
\@starttoc{toc}%
\if@restonecol\twocolumn\fi
}
% Index
\renewenvironment{theindex}{%
\if@twocolumn
\@restonecolfalse
\else
\@restonecoltrue
\fi
\twocolumn[\@makeschapterhead{\indexname}]%
\@mkboth{\indexname}{\indexname}%
\thispagestyle{plain}%
\parindent\z@
\parskip\z@ \@plus .3\p@\relax
\columnseprule \z@
\columnsep 35\p@
\let\item\@idxitem
}{%
\if@restonecol
\onecolumn
\else
\clearpage
\fi
}
% Headings
\RequirePackage{titlesec}
\titleformat{\chapter}%
[hang]% shape
{\sffamily\huge\itshape\bfseries}% format applied to label+text
{\thechapter}% label
{0pt}% horizontal separation between label and title body
{\sffamily\huge\itshape}% before the title body
[]% after the title body
\titleformat{\section}%
[hang]% shape
{\sffamily\Large\itshape\bfseries}% format applied to label+text
{\thesection}% label
{1em}% horizontal separation between label and title body
{}% before the title body
[]% after the title body
\titleformat{\subsection}%
[hang]% shape
{\sffamily\large\itshape\bfseries}% format applied to label+text
{\thesubsection}% label
{1em}% horizontal separation between label and title body
{}% before the title body
[]% after the title body
\titleformat{\subsubsection}%
[hang]% shape
{\sffamily\normalsize\itshape\bfseries}% format applied to label+text
{\thesubsection}% label
{1em}% horizontal separation between label and title body
{}% before the title body
[]% after the title body
\titleformat{\paragraph}%
[runin]% shape
{\normalfont\itshape}% format applied to label+text
{\theparagraph}% label
{1em}% horizontal separation between label and title body
{}% before the title body
[]% after the title body
\titlespacing*{\chapter}{0pt}{2\baselineskip}{1\baselineskip}
\titlespacing*{\section}{0pt}{2.5ex plus 1ex minus 1ex}{1.3ex plus .2ex minus .2ex}
\titlespacing*{\subsection}{0pt}{2.25ex plus 1ex minus .75ex}{0.7ex plus.2ex minus .2ex}
\titlespacing*{\subsubsection}{0pt}{1.25ex plus 1ex minus .2ex}{0.7ex plus.2ex minus .2ex}
% Float placement parameters
\setcounter{topnumber}{3}
\setcounter{bottomnumber}{2}
\setcounter{totalnumber}{4}
\renewcommand{\topfraction}{0.9}
\renewcommand{\bottomfraction}{0.1}
\renewcommand{\textfraction}{0.1}
\renewcommand{\dbltopfraction}{\topfraction}
\renewcommand{\floatpagefraction}{0.7}
\renewcommand{\dblfloatpagefraction}{0.5}
% Caption formatting
\RequirePackage{caption}
\captionsetup{%
font={small,sf},
}