forked from alexmingzhang/amznotes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathamznotes.cls
More file actions
384 lines (316 loc) · 10.7 KB
/
Copy pathamznotes.cls
File metadata and controls
384 lines (316 loc) · 10.7 KB
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
% ------------------------------------------------------------
% amznotes - Alex M Zhang notes
% Credit to David Zhang for the original template
% To fix header for unnumbered chapters, do:
% \chapter*{Chapter Title}
% \markboth{Chapter Title}{Chapter Title}
% TODO:
% - make math in box titles bold
% - make macro for lower case namerefs
% - macro \chapter* as the unnumbered chapter fix above
\ProvidesClass{amznotes}[2023/04/23 amznotes]
\NeedsTeXFormat{LaTeX2e}
\LoadClass[12pt]{report}
% ------------------------------------------------------------
% PROCESS OPTIONS
\RequirePackage{kvoptions}
\DeclareBoolOption{math} % enables thmbox and math macros
\DeclareBoolOption{code} % enables codebox, amzcode, and \amzinputcode
\DeclareBoolOption{fastcompile} % turns off some features for faster compiling
\ProcessKeyvalOptions{amznotes}
% ------------------------------------------------------------
% LOAD REQUIRED PACKAGES
\RequirePackage[margin=1in]{geometry} % set margins
\RequirePackage{fontspec} % set main font
\RequirePackage{unicode-math} % set math font; replaces amssymb
\RequirePackage[dvipsnames]{xcolor} % pretty colors
\RequirePackage{hyperref} % hyperlinks in pdf viewers; will appear underlined only in pdf viewer
\RequirePackage{fancyhdr} % fancy headers
\RequirePackage{lastpage} % "X of Y" footer
\RequirePackage{parskip} % new line after each paragraph w/o indent
\RequirePackage{setspace} % 1.5 line spacing
\RequirePackage[explicit]{titlesec} % chapter styling
\RequirePackage[most]{tcolorbox} % pretty boxes
\RequirePackage{ifthen} % disable index entries not being used
\RequirePackage{multicol}
\RequirePackage{enumitem} % customize itemize spacing
\RequirePackage{xfrac} % small fractions
\RequirePackage[textsize=scriptsize]{todonotes} % todo notes
\RequirePackage{tabularx}
\ifamznotes@math
\RequirePackage{mathtools} % for math macros; also loads amsmath
\RequirePackage{amsthm}
\renewcommand\qedsymbol{$\squoval$}
\RequirePackage{derivative}
\fi
\ifamznotes@code
\RequirePackage{minted} % syntax coloring for code
\tcbuselibrary{minted}
\fi
% ------------------------------------------------------------
% FONTS
\setmainfont{STIXTwoText}[
Extension = .otf,
UprightFont = *-Regular,
BoldFont = *-SemiBold,
ItalicFont = *-Italic,
BoldItalicFont = *-SemiBoldItalic,
]
\setmathfont{STIXTwoMath-Regular.otf}
\setmathfont{STIXTwoMath-Regular.otf}[range={scr,bfscr},StylisticSet=01]
\setmonofont{Inconsolata}
% ------------------------------------------------------------
% PAGE LAYOUT
\onehalfspacing
\renewcommand{\arraystretch}{1.25}
% ------------------------------------------------------------
% COLORS
% Color palette from https://flatuicolors.com/palette/us
\definecolor{amzchaptercolor}{HTML}{0984e3}
\definecolor{amzdfnboxcolor}{HTML}{0984e3}
\definecolor{amzthmboxcolor}{HTML}{6c5ce7}
\definecolor{amzexboxcolor}{HTML}{fdcb6e}
\definecolor{amzgenboxcolor}{HTML}{00b894}
\definecolor{amztecboxcolor}{HTML}{e17055}
\definecolor{amzcodeboxcolor}{HTML}{2d3436}
\definecolor{amznoteboxcolor}{HTML}{d63031}
% ------------------------------------------------------------
% LINKS
\hypersetup{
colorlinks=false,
linkbordercolor=black,
urlbordercolor=blue,
pdfborderstyle={/S/U/W 1} % Underline links; only appears in pdf viewer, not printed
}
% ------------------------------------------------------------
% CHAPTER STYLING
\ifamznotes@fastcompile
\else
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}
{}
{20pt}
{
\begin{tcolorbox}[
enhanced,
left=23mm,
right=25mm,
top=2mm,
spread sidewards,
sharp corners,
colback=amzchaptercolor,
colframe=amzchaptercolor,
boxrule=1mm,
title=\thechapter,
attach boxed title to top right={xshift=-15mm, yshift=-4mm},
boxed title style={
size=small,
colback=amzchaptercolor,
colframe=white
}
]
\strut \textcolor{white}{#1}
\end{tcolorbox}
}
\titleformat{name=\chapter,numberless}[display]{\normalfont\huge\bfseries}
{}
{20pt}
{
\begin{tcolorbox}[
enhanced,
left=23mm,
right=25mm,
top=2mm,
spread sidewards,
sharp corners,
colback=amzchaptercolor,
colframe=amzchaptercolor,
boxrule=1mm,
]
\strut \textcolor{white}{#1}
\end{tcolorbox}
}
\titlespacing*{\chapter}{0pt}{-40mm}{-10mm}
\fi %\ifamznotes@fastcompile
% ------------------------------------------------------------
% SECTION STYLING
% \sectionfont{\color{amzchaptercolor}} % sets colour of sections
% ------------------------------------------------------------
% HEADER STYLING
\ifamznotes@fastcompile
\else
\pagestyle{fancy}
\lhead{\footnotesize\nouppercase{\leftmark}}
\rhead{\footnotesize\nouppercase{\rightmark}}
\cfoot{\thepage\ of \pageref{LastPage}}
\fancypagestyle{plain}{
\renewcommand{\headrulewidth}{0pt}
\fancyhead{}
\cfoot[C]{\thepage\ of \pageref{LastPage}}
}
\fi %\ifamznotes@fastcompile
% ------------------------------------------------------------
% COLOR BOXES
\newcommand{\amzcolorboxtitlesep}{\ \raisebox{2.3pt}{\scalebox{0.5}{ $\blacktriangleright$}}}
\ifamznotes@fastcompile
\tcbset{
amzdefaultstyle/.style={
fonttitle=\strut\bfseries, % strut for uniform title height
separator sign=\amzcolorboxtitlesep,
breakable
},
genboxstyle/.style={
amzdefaultstyle,
},
noteboxstyle/.style={breakable},
codeboxstyle/.style={
overlay={\begin{tcbclipinterior}\fill[darkgray!20!white] (frame.south west) rectangle ([xshift=6mm]frame.north west);\end{tcbclipinterior}},
skin=bicolor,
collower=white,
colbacklower=darkgray
},
}
%test
\else %\ifamznotes@fastcompile
\tcbset{
amzdefaultstyle/.style={
enhanced,
drop fuzzy shadow,
fonttitle=\strut\bfseries, % strut for uniform title height
boxrule=0pt,
frame hidden,
separator sign=\amzcolorboxtitlesep,
% parbox=false, % normal paragraph spacing
breakable,
},
genboxstyle/.style={
amzdefaultstyle,
frame style={fill=amzgenboxcolor!85!black},
interior style={fill=amzgenboxcolor!5!white},
segmentation style={solid,draw=amzgenboxcolor!50!black,opacity=0.25,line width=1pt}
},
noteboxstyle/.style={
enhanced,
boxrule=0pt,
frame hidden,
borderline west={4pt}{0pt}{amznoteboxcolor},
colback=amznoteboxcolor!7!white,
sharp corners,
},
codeboxstyle/.style={
overlay={\begin{tcbclipinterior}\fill[darkgray!20!white] (frame.south west) rectangle ([xshift=6mm]frame.north west);\end{tcbclipinterior}},
skin=bicolor,
collower=white,
colbacklower=darkgray
},
}
\fi %\ifamznotes@fastcompile
% Give the index numbers some more space
\renewcommand{\l@tcolorbox}{\@dottedtocline{1}{0pt}{3em}}
\setlength{\columnsep}{3em}
\newcommand{\amzindex}{
\addcontentsline{toc}{chapter}{Index}
\chapter*{Index}
% Remove header for index
\renewcommand{\headrulewidth}{0pt}
\fancyhead{}
\begin{multicols}{2}
\amzindexbody
\end{multicols}
}
\newcommand{\amzindexbody}{}
\newcommand{\addindexentry}[2]{%
\appto\amzindexbody{
\iftoggle{#2}{
\tcblistof[\section*]{#2}{#1}
}{}
}
}
%\newamzbox{environment name}{title}{ref label}{color}[tcolorbox style]
\newcounter{amzboxcounter}
\NewDocumentCommand{\newamzbox}{m m m m O{}}{
\newtcbtheorem[use counter=amzboxcounter,number within=section,list inside={#3}]{tc#1}{#2}{
amzdefaultstyle,
frame style={fill=#4!85!black},
interior style={fill=#4!5!white},
segmentation style={solid,draw=#4!50!black,opacity=0.25,line width=1pt},
#5
}{#3}
\providetoggle{#3}
\settoggle{#3}{false}
\newenvironment{#1}[2]{
\global\settoggle{#3}{true}
\begin{tc#1}{##1}{##2}
}{
\end{tc#1}
}
\newenvironment{#1*}[1]{
\begin{tc#1*}{##1}
}{
\end{tc#1*}
}
\addindexentry{#2s}{#3}
}
\newamzbox{dfnbox}{Definition}{dfn}{amzdfnboxcolor}
\newamzbox{exbox}{Example}{ex}{amzexboxcolor}
\newamzbox{tecbox}{Technique}{tec}{amztecboxcolor}
\newtcolorbox{genbox}[1]{amzdefaultstyle, genboxstyle, title={#1}}
\newtcolorbox{notebox}{noteboxstyle}
\ifamznotes@math
\newamzbox{lembox}{Lemma}{lem}{amzthmboxcolor}
\newamzbox{thmbox}{Theorem}{thm}{amzthmboxcolor}
\fi
\ifamznotes@code
\renewcommand{\theFancyVerbLine}{\ttfamily\scriptsize{\arabic{FancyVerbLine}}}
\newamzbox{codebox}{Code Snippet}{code}{amzcodeboxcolor}[codeboxstyle]
\newenvironment{amzcode}[2][]{
\VerbatimEnvironment
\begin{minted}[
linenos, % Display line numbers
breaklines, % Allow line breaks
autogobble, % Collapse extra white spaces
xleftmargin=3.75mm,
]{#2}}
{\end{minted}}
\newcommand{\amzinputcode}[2]{\inputminted[
linenos, % Display line numbers
breaklines, % Allow line breaks
autogobble, % Collapse extra white spaces
xleftmargin=3.75mm,
]{#1}{#2}}
\fi
% ------------------------------------------------------------
% TEXT MACROS
\newcommand{\dfntxt}[1]{\textit{\textbf{#1}}}
% from https://tex.stackexchange.com/a/150650
\newcommand{\tabitem}{~~\llap{\textbullet}~~}
% ------------------------------------------------------------
% MATH MACROS
\ifamznotes@math
\newcommand{\rel}[1]{\mathrel{\mathcal{#1}}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\F}{\mathbb{F}}
\DeclareMathOperator{\laplace}{\mathscr{L}}
\DeclareMathOperator{\proj}{proj}
\DeclareMathOperator{\comp}{comp}
\DeclareMathOperator{\TIME}{TIME}
\newcommand{\id}{\text{id}}
\newcommand{\bigO}{\mathcal{O}}
\newcommand{\symdiff}{\bigtriangleup}
\newcommand{\alg}[1]{{\left\langle {#1} \right\rangle}}
\DeclarePairedDelimiter\abs{\lvert}{\rvert} \DeclarePairedDelimiter\norm{\lVert}{\rVert}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}
% Function Restriction
% From https://tex.stackexchange.com/a/22255
\newcommand\restrict[2]{{
\left.\kern-\nulldelimiterspace
#1
\vphantom{\big|}
\right|_{#2}
}}
\fi %\ifamznotes@math