-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmodern-latex.tex
417 lines (351 loc) · 12.1 KB
/
modern-latex.tex
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
% Build this document with LuaTeX, a modern Unicode-aware LaTeX engine
% that uses system TTF and OTF font files.
% This is needed for the fontspec, microtype, and nolig packages.
%
% We're using KOMA Script to hand-tune footnotes and TOC appearance.
% It should be available in your texlive distribution,
% which is how most distros package LaTeX.
\documentclass[fontsize=11bp, numbers=endperiod, draft=false]{scrbook}
% Margins: see http://practicaltypography.com/page-margins.html and
% http://practicaltypography.com/line-length.html
% We're aiming for 80-ish characters per line.
\usepackage[a5paper,
inner=0.65in,outer=0.55in,top=0.75in,bottom=0.5in,
footnotesep=11bp,
footskip=3em,
includefoot,
]{geometry}
\usepackage[fleqn]{amsmath}
\usepackage{fontspec}
\setmainfont[
Ligatures=TeX,
Numbers={Proportional,Lowercase},
Contextuals=NoAlternate, % No long Q
% Coefficients for font-provided space, stretch, and shrink.
% Garamond Premier is a bit tighter than Adobe Garamond,
% but stretching it out about 20% gives about the same metrics.
%WordSpace={1.2,1.2,1},
UprightFeatures={
SizeFeatures={
{Size={-10},Font=garamondpremrpro-capt},
{Size={10-15},Font=garamondpremrpro},
{Size={15-23},Font=garamondpremrpro-subh},
{Size={23-},Font=garamondpremrpro-disp}
},
},
BoldFeatures={
SizeFeatures={
{Size={-10},Font=garamondpremrpro-smbdcapt},
{Size={10-15},Font=garamondpremrpro-smbd},
{Size={15-23},Font=garamondpremrpro-smbdsubh},
{Size={23-},Font=garamondpremrpro-smbddisp}
},
},
ItalicFeatures={
SizeFeatures={
{Size={-10},Font=garamondpremrpro-itcapt},
{Size={10-15},Font=garamondpremrpro-it},
{Size={15-23},Font=garamondpremrpro-itsubh},
{Size={23-},Font=garamondpremrpro-itdisp}
},
},
BoldItalicFeatures={
SizeFeatures={
{Size={-10},Font=garamondpremrpro-smbditcapt},
{Size={10-15},Font=garamondpremrpro-smbdit},
{Size={15-23},Font=garamondpremrpro-smbditsubh},
{Size={23-},Font=garamondpremrpro-smbditdisp}
},
},
]{Garamond Premier Pro}
\setsansfont[Ligatures=TeX,
Scale=MatchUppercase,
Style=Alternate, % Straight-legged R
UprightFont = *-55Rg,
ItalicFont = *-56It,
BoldFont = *-65Md,
BoldItalicFont = *-66MdIt
]{NHaasGroteskTXPro}
\setmonofont[
Numbers=SlashedZero,
Scale=MatchLowercase,
UprightFeatures={
SizeFeatures={
{Size={-10}, Font=DriveMono-Book},
{Size={10-}, Font=DriveMono-Regular},
},
},
ItalicFeatures={
SizeFeatures={
{Size={-10}, Font=DriveMono-BookItalic},
{Size={10-}, Font=DriveMono-Italic},
},
},
BoldFont=DriveMono-Bold,
BoldItalicFont=DriveMono-BoldItalic
]{Drive Mono}
\setmathrm{Latin Modern Roman}
% We'll be using this quite a bit:
\newfontfamily{\lm}[
Ligatures=TeX,
SmallCapsFont = * Caps
]{Latin Modern Roman}
\newfontfamily{\lt}{Latin Modern Mono}
\usepackage{polyglossia}
\setdefaultlanguage[variant=american]{english}
\setotherlanguage{french}
\usepackage{microtype} % Font expansion, protrusion, and other goodness
% Disable ligatures across grapheme boundaries
% (see the package manual for details.)
\usepackage[american]{selnolig}
% I have no idea why Garamond has this on by default.
\nolig{Th}{T|h}
% Use symbols for footnotes, resetting each page
\usepackage[perpage,bottom,symbol*]{footmisc}
% Left flush footnotes. See the KOMA Script manual.
\deffootnote[1em]{1em}{1em}{\thefootnotemark}
% Set the width of the rule separating body text and footnotes
\setfootnoterule{0.8\textwidth}
% Like many fonts, Equity's asterisk is already set in a "superscripted" form.
% Superscripting *that* makes it annoyingly small.
% To fix this, we have to redefine footnote marks so that they aren't superscript,
% then raise all the other symbols.
%
% Feel free to remove this if your body type doesn't have this peculiarity,
% but unfortunately many do.
% See http://tex.stackexchange.com/a/16241
%
% We use the Unicode symbols themselves (instead of \dagger, \ddagger, \P, etc.)
% because the latter fall back to Computer Modern/Latin Modern in some cases,
% (e.g., if you're using mathastext instead of unicode-math).
% Alternatively, you could use \textdagger, \textddagger, etc.,
% but this seems more concise.
\DefineFNsymbols*{tweaked}{%
{*}%
{\textsuperscript†}%
{\textsuperscript‡}%
{\textsuperscript{◊}}%
{\textsuperscript{§}}%
{**}%
{\textsuperscript{††}}%
{\textsuperscript{‡‡}}%
}
\setfnsymbol{tweaked}
\deffootnotemark{\thefootnotemark}
\DeclareTOCStyleEntry[%
beforeskip=8bp,
entryformat = \bfseries,
entrynumberformat = \addfontfeature{Numbers={Tabular,Uppercase}},
pagenumberformat = \addfontfeature{Numbers={Tabular,Uppercase}},
linefill = \TOCLineLeaderFill
]{tocline}{chapter}
\DeclareTOCStyleEntry[%
beforeskip=1bp,
entrynumberformat = \addfontfeature{Numbers={Tabular,Uppercase}},
pagenumberformat = \addfontfeature{Numbers={Tabular,Uppercase}},
indent=0.4in
]{tocline}{section}
\DeclareTOCStyleEntry[%
beforeskip=0pt,
entrynumberformat = \addfontfeature{Numbers={Tabular,Uppercase}},
pagenumberformat = \addfontfeature{Numbers={Tabular,Uppercase}},
indent=0.6in
]{tocline}{subsection}
% Don't use a sans font for description labels.
\addtokomafont{descriptionlabel}{\rmfamily}
% Sections and such use serif type.
\setkomafont{disposition}{\rmfamily}
% Uppercase numbers for chapters.
\addtokomafont{chapter}{\addfontfeature{Numbers=Uppercase}}
% Set size and style of section and subsections
\setkomafont{section}{\Large\itshape}
\setkomafont{subsection}{\large\itshape}
\setcapwidth[c]{.75\textwidth}
%\setcapmargin{0pt}
\setkomafont{caption}{\sffamily\footnotesize}
\setkomafont{captionlabel}{\sffamily\footnotesize}
\renewcommand*{\figureformat}{}
\renewcommand*{\tableformat}{}
\renewcommand*{\captionformat}{}
% Use uppercase numbers for numbered lists.
% (We're using lowercase ones for the body text.)
% See http://tex.stackexchange.com/a/133186
\usepackage{enumitem}
\setlist[enumerate]{font=\addfontfeatures{Numbers=Uppercase}}
\setlist[description]{leftmargin=1em}
\usepackage{tabularx}
% Custom footer
\usepackage[draft=false]{scrlayer-scrpage}
\clearpairofpagestyles
\pagestyle{scrheadings}
\setkomafont{pagefoot}{\upshape}
\lefoot*{\thepage}
\rofoot*{\thepage}
\usepackage{changepage} % For adjustwidth
\usepackage{mflogo} % for METAFONT
\usepackage{metalogo} % for \LuaLaTeX
\usepackage{multicol}
\usepackage{endnotes}
% OTF goodness...
\renewcommand\makeenmark{{\addfontfeature{VerticalPosition=Superior}\theenmark}}
\usepackage{listings}
\lstset
{
language=[LaTeX]TeX,
breaklines=false,
basicstyle=\ttfamily,
keywordstyle=\ttfamily,
commentstyle=\ttfamily,
}
% Indent code examples, etc., by double the text size.
\newenvironment{leftfigure}
{\par\vspace{0.5\baselineskip minus 0.3\baselineskip}\begin{adjustwidth}{22bp}{0pt}}
{\end{adjustwidth}\vspace{0.5\baselineskip minus 0.3\baselineskip}}
% Like the above, but with no adjustwidth
\newenvironment{flushleftfigure}
{\par\vspace{0.5\baselineskip minus 0.3\baselineskip}\noindent\ignorespacesafterend}
{\vspace{0.5\baselineskip minus 0.3\baselineskip}\par\noindent\ignorespacesafterend}
\newenvironment{centerfigure}
{\par\vspace{0.5\baselineskip minus 0.3\baselineskip}\begin{adjustwidth}{22bp}{22bp}\centering}
{\end{adjustwidth}\vspace{0.5\baselineskip minus 0.3\baselineskip}}
\usepackage{graphicx}
\usepackage{csquotes}
\title{Modern \texorpdfstring{\LaTeX}{LaTeX}}
\author{Matt Kline}
\date{\today}
% Custom footer
% Hyperlinks
\usepackage[unicode,pdfusetitle,hidelinks]{hyperref}
% Use \punckern to overlap periods, commas, and footnote markers
% for a tighter look.
% Care should be taken to not make it too tight - f" and the like can overlap
% if you're not careful.
\newcommand{\punckern}{\kern-0.2ex}
% For placing commas close to, or under, quotes they follow.
% We're programmers, and we blatantly disregard American typographical norms
% to put the quotes inside, but we can at least make it look a bit nicer.
\newcommand{\quotekern}{\kern-0.6ex}
% Create an unbreakable string of text in a monospaced font.
% Useful for `command --line --args`
\newcommand{\monobox}[1]{\mbox{\texttt{#1}}}
\newcommand{\otffrac}[2]{\mbox{%
{\addfontfeature{VerticalPosition=Superior}#1}%
^^^^2044% Unicode fraction slash
{\addfontfeature{VerticalPosition=Inferior}#2}%
}}
\newcommand{\otford}[2]{\mbox{%
{\addfontfeature{Numbers=LowercaseOff}#1}%
{\addfontfeature{VerticalPosition=Superior}#2}%
}}
% C++ looks nicer if the ++ is in a monospace font and raised a bit.
% Also, use uppercase numbers to match the capital C.
\newcommand{\plusplus}{\raisebox{0.1ex}{++}}
\newcommand{\cpp}[1]{C\kern-0.1ex\plusplus{\addfontfeature{Numbers=LowercaseOff}#1}}
% Italicize new terms
\newcommand{\introduce}[1]{\textit{#1}}
% Letterspace acronyms a bit.
\newcommand{\acronym}[1]{\textsc{\addfontfeature{LetterSpace=5}#1}}
% "Chapter <num>" references
\newcommand{\chapref}[1]{chapter~\ref{#1}}
% monospace URLs (without setting the http://...)
\newcommand{\http}[1]{\href{http://#1}{\texttt{#1}}}
\newcommand{\https}[1]{\href{https://#1}{\texttt{#1}}}
\newcommand{\edition}{Second edition}
\newcommand{\exercises}{\section{On your own}}
% See http://tex.stackexchange.com/a/68310
\makeatletter
\let\runauthor\@author
\let\rundate\@date
\let\runtitle\@title
\makeatother
% Spend a bit more time to get better word spacing.
% See http://tex.stackexchange.com/a/52855/92465
\emergencystretch=1ex
% Do as I say, not as I do.
\widowpenalty=10000
\clubpenalty=10000
\begin{document}
\fontsize{11bp}{13bp}\selectfont
\frontmatter
\setcounter{secnumdepth}{0}
\setlength\parindent{0pt}
% Custom title instead of \maketitle
\pagenumbering{gobble}
\vspace*{1in}
\begin{center}
\fontsize{0.5in}{0.7in}\selectfont
Modern
\fontsize{1in}{0.9in}\selectfont
\LaTeX
\normalsize
\vspace{1.5\baselineskip}
\edition
\vspace{2in}
\LARGE
\runauthor
\end{center}
\clearpage
{\raggedright%For the page
\null
\vfill
{\addfontfeature{Numbers={Proportional,Uppercase}}
Copyright © 2018--2022 \\
by \runauthor
\bigskip
This book is licensed under the \\
Creative Commons Attribution-ShareAlike~4.0 International License. \\
In short, you are free to share, translate, adapt, or improve this book
so long as you give proper credit and provide your contributions under
the same license. \\
The license's full text is available at \\
\https{creativecommons.org/licenses/by-sa/4.0/legalcode}
}
\vfill
The author apologizes for any typos,
f\raisebox{-0.1ex}{o}rmatt\raisebox{0.1ex}{i}ng mistakes,
inaccuracies,
and other flubs.
He welcomes fixes and improvements in this book's Git repository at \\
\https{github.com/mrkline/latex-book}
\vspace{\baselineskip}
Questions, comments, concerns, and diatribes can also be emailed to \\
\texttt{matt <at> bitbashing.io}
\vspace{\baselineskip}
The author does not have a checking account with the Bank of San Serriffe,
but he will happily buy you a drink when we meet as thanks for your help.
\vspace{0.5in}
\edition, typeset \today.
} % end ragged right
\clearpage
\vspace*{1in}
{\itshape%
To Max, who once told me about a cool program he used to type up
his college papers.
}
\cleardoublepage
\pagenumbering{roman}
\tableofcontents
\mainmatter
% Indent by one lead, as suggested in The Elements of Typographic Style.
\setlength\parindent{14bp}
\pagenumbering{arabic}
\setcounter{page}{1} % Restart page numbering after the ToC.
\cleardoublepage
\input{why}
\input{installation}
\input{hello}
\input{structure}
\input{textformatting}
\input{punctuation}
\input{pagelayout}
\input{math}
\input{fonts}
\input{micro}
\input{international}
\input{troubleshooting}
\appendix
% Don't put big spaces before appendices
\renewcommand{\chapterheadstartvskip}{\vspace{0.15in}}
\input{history}
\input{back}
\end{document}