-
Notifications
You must be signed in to change notification settings - Fork 2
/
calcnotes.sty
540 lines (415 loc) · 14.6 KB
/
calcnotes.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
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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
\ProvidesPackage{calcnotes}
%% LOAD PACKAGES
% Load AMS-LaTeX packages for math typesetting
\RequirePackage{amsfonts}
\RequirePackage{amssymb}
\RequirePackage{amsthm}
\RequirePackage{mathtools}
% Load COntent-Oriented LaTeX for semantic math
\RequirePackage{cool}
% Load SIUnitX for units handling
\RequirePackage[per-mode=symbol]{siunitx}
% Load xfrac for nice fractions
\RequirePackage{xfrac}
% Set up font handling
\RequirePackage{libertinus}
\RequirePackage{libertinust1math}
\RequirePackage[T1]{fontenc}
\RequirePackage{microtype}
% Use subfiles for chapter includes
\RequirePackage{subfiles}
% Load the csquotes package for semantic quotation marks
\RequirePackage{csquotes}
% Load the TikZ package for header design
\RequirePackage{tikz}
% Load the Asymptote package for figures and diagrams
\RequirePackage[inline]{asymptote}
% Load the float package for fine-grained control over float placement
\RequirePackage{float}
% Load the fullwidth package for figures that span the margin
\RequirePackage{fullwidth}
% Load the booktabs package for professional-looking tables
\RequirePackage{booktabs}
% Load the listings package for code listings
\RequirePackage{listings}
% Load the answers package for exercises
\RequirePackage{answers}
% Load the ccicons package for Creative Commons icons
\RequirePackage{ccicons}
% Load the gitinfo package to show git commit information in footer
\RequirePackage{gitinfo}
% Load the makeidx package to build the index
\RequirePackage[xindy]{imakeidx}
% Load the xparse package to support some fancy defines
\RequirePackage{xparse}
% Load the hyperref package for hyperlinking (MUST BE LAST)
\RequirePackage{hyperref}
% Load the cleveref package for intelligent cross-referencing (MUST BE AFTER HYPERREF)
\RequirePackage[capitalize]{cleveref}
% Load the foreign package for intelligent formatting of non-english words
\RequirePackage{foreign}
%% SET OPTIONS
% Configure listings
\lstset{
basicstyle=\footnotesize\ttfamily,
commentstyle=\color{gray},
numbers=left,
breaklines=true,
breakatwhitespace=true,
numberstyle=\footnotesize,
stepnumber=2,
showstringspaces=false,
}
% Configure cleveref
\crefname{lstlisting}{listing}{listings}
\Crefname{lstlisting}{Listing}{Listings}
\crefname{equation}{equation}{equations}
% Configure theorem styles
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{observation}[theorem]{Observation}
\newtheorem*{theorem*}{Theorem}
\newtheorem*{corollary*}{Corollary}
\newtheorem*{lemma*}{lemma}
\newtheorem*{proposition*}{Proposition}
\newtheorem*{observation*}{Observation}
\newtheorem*{motprob}{Problem}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem*{definition*}{Definition}
\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}
\newtheorem*{remark*}{Remark}
\newtheorem{example}[theorem]{Example}
\newtheorem*{example*}{Example}
\newtheorem*{motex}{Motivating example}
\newtheorem{note}[theorem]{Note}
\newtheorem*{note*}{Note}
\newtheorem*{soln}{Solution}
% Number equations within sections
\numberwithin{equation}{section}
% Define command to format defined term
\NewDocumentCommand{\defterm}{mO{#1}O{|textbf}}{\emph{#1}\index{#2#3}}
% Define command to render chosen license mark
\newcommand{\licensemark}{\ccbysa}
\newcommand{\licensemarklink}{\href{http://creativecommons.org/licenses/by-sa/4.0/}{\ccbysa}}
% Define command to print Git hash as a Github url
\newcommand{\hashurl}{\href{http://github.com/againerdewar/calculus-reader/tree/\gitHash}{\gitAbbrevHash}}
% Use roman d for differentiation and integration
\Style{DSymb=\mathrm{d},DShorten=true,IntegrateDifferentialDSymb=\mathrm{d}}
% Define command for writing differentials
\newcommand*{\diff}[1]{\ensuremath{\COOL@notation@IntegrateDifferentialDSymb #1}}
% Override CoOL's derivative command, which breaks with some font packages
\renewcommand*{\D}[3][]{\ensuremath{\frac{\COOL@notation@DSymb^{#1} {#2}}{\COOL@notation@DSymb {#3}^{#1}}}}
% Define command for antidifferentiation
\newcommand*{\AD}[2]{\D[-1]{#1}{#2}}
% Define command for difference quotients
\newcommand{\diffquot}[3][\Delta]{\ensuremath{\frac{{#1} {#2}}{{#1} {#3}}}}
% Use fancy paired delimiters
\DeclarePairedDelimiter{\pbrac}{(}{)}
\DeclarePairedDelimiter{\sbrac}{[}{]}
\DeclarePairedDelimiter{\cbrac}{\{}{\}}
\DeclarePairedDelimiter{\floor}{\lfloor}{\rfloor}
\DeclarePairedDelimiter{\ceil}{\lceil}{\rceil}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
\DeclarePairedDelimiter{\closedint}{[}{]}
\DeclarePairedDelimiter{\openint}{(}{)}
\DeclarePairedDelimiter{\eval}{.}{\rvert}
\DeclarePairedDelimiterX{\setbuilder}[2]{\{}{\}}{#1 \delimsize\vert #2}
% Add some imperial units
\DeclareSIUnit{\year}{yr}
\DeclareSIUnit{\foot}{ft}
\DeclareSIUnit{\inch}{in}
\DeclareSIUnit{\mile}{mi}
\DeclareSIUnit{\gallon}{gal}
\DeclareSIUnit{\bit}{b}
\DeclareSIUnit{\byte}{B}
\DeclareSIUnit{\dollar}{\$}
% Commands for names of important fields
\newcommand*{\fieldname}[1]{\ensuremath{\mathbf{#1}}}
\newcommand*{\RR}[1][]{\ensuremath{\fieldname{R}^{#1}}}
\newcommand*{\QQ}{\fieldname{Q}}
\newcommand*{\CC}{\fieldname{C}}
% Notation for average value
\newcommand*{\avg}[1]{\ensuremath{\overline{#1}}}
% Area function from integral calculus
\newcommand*{\areafunc}[3]{\ensuremath{A_{{#1},{#2}} \pbrac*{#3}}}
\begin{asydef}
import graph;
import graph3;
import patterns;
settings.prc = false;
real marginwidth = 1.5inches;
real blockwidth = 5.0inches;
real blockscrunch = 1.0inches;
real blockintermargin = 0.25inches;
void smallsize() {size(marginwidth, 0);}
void medsize() {size(blockwidth, 0);}
void medsizescrunch() {size(blockwidth - blockscrunch, 0);}
void medhalf() {size((blockwidth - blockintermargin)/2, 0);}
void medthird() {size((blockwidth - 2*blockintermargin)/3, 0);}
pen lineplot = defaultpen;
pen thickplot = linewidth(1);
pen dashedline = dashed+linewidth(1);
pen dash1 = dashed;
pen dash2 = longdashed;
pen dash3 = dotted;
pen transparency = opacity(0.25);
pen box1 = gray + transparency;
pen box2 = black + transparency;
pen box3 = heavygray + transparency;
pen solid1 = gray;
pen dot1 = black;
void drawbox(real left, real right, real height, pen fillpen = lightgray)
{
path thebox = box((left,0),(right,height));
filldraw(thebox, fillpen);
}
void drawrects(real[][] samplepoints, pen fillpen = lightgray){
for(real[] rect : samplepoints){
drawbox(rect[0], rect[1], rect[3], fillpen);
}
}
void drawtests(real[][] samplepoints, pen drawpen = dashed){
for(real[] rect : samplepoints){
draw((rect[2], 0) -- (rect[2], rect[3]), drawpen);
}
}
real[][] leftrierects(real f(real), real a, real b, int n)
{
real dx = (b-a)/n;
real[][] rects;
for(int i=0; i<n; ++i) {
real left = a + i*dx;
real right = left + dx;
real test = left;
rects[i] = new real[] {left, right, test, f(test)};
}
return rects;
}
real[][] midrierects(real f(real), real a, real b, int n)
{
real dx = (b-a)/n;
real[][] rects;
for(int i=0; i<n; ++i) {
real left = a + i*dx;
real right = left + dx;
real mid = (left + right)/2;
real test = mid;
rects[i] = new real[] {left, right, test, f(test)};
}
return rects;
}
real[][] rightrierects(real f(real), real a, real b, int n)
{
real dx = (b-a)/n;
real[][] rects;
for(int i=0; i<n; ++i) {
real left = a + i*dx;
real right = left + dx;
real test = right;
rects[i] = new real[] {left, right, test, f(test)};
}
return rects;
}
void labelxticks(real[] xtickpoints)
{
int n = xtickpoints.length;
for(int i=1; i<n; ++i) {
string ilabel = (string) i;
labelx("$x_{"+ilabel+"}$", xtickpoints[i-1]);
}
}
void labelxstarticks(real[] xtickpoints)
{
int n = xtickpoints.length;
for(int i=1; i<=n; ++i) {
string ilabel = (string) i;
labelx("$x^{*}_{"+ilabel+"}$", xtickpoints[i-1]);
}
}
void fillbetween(real f(real), real g(real), real a, real b, pen fillpen, pen linepen = lineplot)
{
path uppercurve = graph(f, a, b, operator ..);
path lowercurve = graph(g, b, a, operator ..);
fill (uppercurve -- lowercurve -- cycle, fillpen);
path leftline = (a,g(a))--(a,f(a));
path rightline = (b,f(b))--(b,g(b));
draw(leftline, linepen);
draw(rightline, linepen);
}
void fillunder(real f(real), real a, real b, pen fillpen, pen linepen = lineplot)
{
real zero(real x) {return 0;}
fillbetween(f, zero, a, b, fillpen, linepen);
}
path funcplot(real f(real), real a, real b, pen drawpen = thickplot)
{
path fplot = graph(f, a, b, operator ..);
draw(fplot, drawpen);
return fplot;
}
path tanplot(real f(real), real df(real), real a, real start, real end, pen drawpen = thickplot, pen dotpen = dot1)
{
real tanline(real x) {return f(a) + df(a)*(x-a);}
path lineplot = graph(tanline, start, end);
draw(lineplot, drawpen);
dot((a, f(a)), dotpen);
return lineplot;
}
path secplot(real f(real), real a, real b, real start, real end, pen drawpen = thickplot, pen dotpen = thickplot)
{
real secline(real x) {return f(a) + (f(b) - f(a))/(b - a) * (x - a);}
path lineplot = graph(secline, start, end);
draw(lineplot, drawpen);
dot((a, f(a)), dotpen);
dot((b, f(b)), dotpen);
return lineplot;
}
ticklabel Unlabel(real[] x)
{
return new string(real v)
{
return "";
};
}
\end{asydef}
%% CONFIGURE LAYOUT
% Use an index
\makeindex[intoc]
% Set up title page
\setlength{\droptitle}{1in}
\newcommand{\subtitle}[1]{\gdef\thesubtitle{#1}}
\definecolor{titlecolor}{gray}{0} % Black title
\newcommand{\titlefont}{\color{titlecolor}\fontsize{3cm}{0cm}\sffamily\bfseries} % Printed in giant bold sans-serif
\definecolor{subtitlecolor}{gray}{0.5} % Gray subtitle
\newcommand{\subtitlefont}{\color{subtitlecolor}\fontsize{3cm}{0cm}\sffamily\itshape} % Printed in giant italic sans-serif
\newcommand{\authorfont}{\fontsize{1cm}{0cm}\sffamily}
\renewcommand{\maketitle}{
\thispagestyle{empty}
\vspace*{\stretch{1}}
\begin{flushright}
{\titlefont\thetitle}\\[\baselineskip]
{\subtitlefont\thesubtitle}
\end{flushright}
\vspace*{\stretch{2}}
\begin{flushright}
{\authorfont\theauthor}
\end{flushright}
\vspace*{\stretch{4}}
}
% Next, we define the part style
\aliaspagestyle{part}{empty} % No page numbers on part pages
\definecolor{partnumbercolor}{gray}{0.9} % Light gray part number
\renewcommand{\partnumfont}{\fontsize{8cm}{0cm}\bfseries} % Printed in giant bold serif face (because Biolinum I looks silly)
\definecolor{parttitlecolor}{gray}{0} % Black part name
\renewcommand{\parttitlefont}{\fontsize{1.5cm}{0cm}\bfseries\sffamily} % Printed in large bold sans-serif
\renewcommand{\printpartname}{} % Suppress internal part printing
\renewcommand{\printpartnum}{} % Suppress internal number printing
%\setlength{\midpartskip}{0pt} % Suppress space before printout
\renewcommand{\printparttitle}[1]{%
\begin{tikzpicture}%
\draw[color=partnumbercolor] (0, 0) node { \partnumfont \thepart };%
\draw[color=parttitlecolor] (0, 0) node[text width=\textwidth, align=center] { \parttitlefont #1 };%
\end{tikzpicture}%
}
% Next, we configure the chapter style
\makechapterstyle{calcnotes}{
\renewcommand*{\chapterheadstart}{} % Don't do anything (like vertical space) before printing chapter heading
\definecolor{chaptertitlecolor}{gray}{0} % Black chapter title
\renewcommand*{\chaptitlefont}{\fontsize{1.5cm}{0cm}\bfseries\sffamily} % Printed in large bold sans-serif
\definecolor{chapternumbercolor}{gray}{0.8} % Light gray chapter number
\renewcommand*{\chapnumfont}{\fontsize{6cm}{0cm}\bfseries\sffamily} % Printed in huge bold sans-serif
\renewcommand*{\printchaptername}{} % Suppress internal chapter name printing
\renewcommand*{\printchapternum}{} % Suppress internal number printing
\renewcommand*{\printchaptertitle}[1]{%
\null
\begin{tikzpicture}%
\ifm@m@And
\draw[color=chapternumbercolor] (0, 0) node[anchor=west] (number) { \chapnumfont \thechapter };
\fi
\draw[color=chaptertitlecolor] (-0.3cm, 0) node[anchor=east,text width=\textwidth,align=flush right] (name) { \chaptitlefont ##1};
\end{tikzpicture}
}
\renewcommand*{\afterchapternum}{}
}
\chapterstyle{calcnotes}
% Next, we configure section headings
\newcommand*{\seccommonfont}{\bfseries\sffamily}
\renewcommand{\secheadstyle}{\huge\seccommonfont}
\renewcommand{\subsecheadstyle}{\Large\seccommonfont}
\renewcommand{\subsubsecheadstyle}{\large\seccommonfont}
\renewcommand{\paraheadstyle}{\normalsize\seccommonfont}
\renewcommand{\subparaheadstyle}{\normalsize\seccommonfont}
% Next, we configure the page style
\copypagestyle{calcnotes}{companion}
\newcommand{\headerfont}{\seccommonfont}
\makeevenhead{calcnotes}{\headerfont\thepage}{}{\headerfont\licensemarklink \quad (\hashurl)\\\leftmark}
\makeoddhead{calcnotes}{\headerfont(\hashurl) \quad \licensemarklink\\\rightmark}{}{\headerfont\thepage}
\pagestyle{calcnotes}
% Memoir only numbers down to sections by default. We need to go deeper.
\setsecnumdepth{subsection}
% Manually configure page layout
% Add some space to the outer margin for marginalia
\setlrmarginsandblock{1in}{2.5in}{*}
\setulmarginsandblock{1.25in}{1.25in}{*}
\setmarginnotes{0.5in}{1.5in}{5pt}
\setheadfoot{2\onelineskip}{\onelineskip}
\checkandfixthelayout
% Use small font for captions
\captionnamefont{\tiny}
\captiontitlefont{\tiny}
\newenvironment*{medfig}[1][hbtp]{
\begin{figure}[{#1}]
\centering
}{
\end{figure}
}
\newenvironment*{smallfig}{
\begin{marginfigure}
\centering
}{
\end{marginfigure}
}
% Let memoir set up subfigure stuff
\newsubfloat{figure}
%% CONFIGURE ANSWERS
% Set up file handlers
\newcommand{\exsolns@fn}{calcnotes-ex}
\newcommand{\openansfiles}{
\Opensolutionfile{exsolns}[\exsolns@fn]
}
\newcommand{\closeansfiles}{
\Closesolutionfile{exsolns}
}
\newcommand{\printsolns}{
\Readsolutionfile{exsolns}
}
% Set up exercise environments
\newenvironment*{gps}{
\subsection*{Guided practice}
}{
}
\newenvironment*{exercises}{
\subsection*{Exercises}
}{
\clearpage
}
\theoremstyle{definition}
\newtheorem{exc}{}[section]
\crefname{exc}{exercise}{exercises}
\Crefname{exc}{Exercise}{Exercises}
\newtheorem{gp}{GP}[section]
\crefname{gp}{GP}{GPs}
\Newassociation{exsol}{Solution}{exsolns}
\theoremstyle{remark}
\newtheorem*{gpsol}{Solution}
% TODO: Set up end-of-book answers with chapter, section names
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "book/calcnotes.tex"
%%% End: