-
Notifications
You must be signed in to change notification settings - Fork 0
/
preamble.sty
391 lines (343 loc) · 12.6 KB
/
preamble.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
\RequirePackage[T1]{fontenc}
\RequirePackage{verbatim}
\RequirePackage[table]{xcolor}
\RequirePackage[svgnames]{xcolor}
\RequirePackage{colortbl}
\definecolor{myblue}{rgb}{0.0,0.2,0.4}%
\colorlet{themecolor}{myblue}
\RequirePackage{enumitem}
\setlist*[enumerate,1]{labelindent=0pt,label={(\alph*)}}
\RequirePackage{setspace}
\RequirePackage[singlelinecheck=false]{caption}
\RequirePackage{xurl}
\RequirePackage[pdfpagelabels,
colorlinks = true,
linkcolor = black,
urlcolor = myblue,
citecolor = black,
anchorcolor = black]{hyperref}
\RequirePackage{tabularray}
\UseTblrLibrary{booktabs}
\RequirePackage{booktabs, cellspace, multirow}
\RequirePackage{amssymb}% \nless, \square and \blacksquare
\RequirePackage{float}% option [H] to figure
\RequirePackage{array}% \newcolumntype macro
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{Q}[1]{>{\vfil\hfil$}m{#1}<{$\hfill\vfill}} % centered, automatic math mode
\newcolumntype{X}{>{$}l<{$}}
\newcolumntype{Y}{>{$}c<{$}}
\newcolumntype{Z}{>{$}r<{$}}
\newcolumntype{M}{Z@{${}={}$}X}% align around the equality sign | uses X and Z above
\RequirePackage{amsfonts}
\RequirePackage{fontawesome5}% useful symbols
\RequirePackage[fleqn]{amsmath}
\RequirePackage{bm}% \boldsymbol
\setlength\parindent{0pt}% no indents
%\setlength{\parskip}{0.75\baselineskip plus 2pt}% control space between paragraphs
\RequirePackage[parfill]{parskip}% no indents, lineskip
\RequirePackage{scalerel}% \scaleleftright[1.75ex]{<}
\RequirePackage{nccmath}% fleqn environment, medium-sized fraction \mfrac
\RequirePackage{mathtools}%\DeclarePairedDelimiter, etc.
% degree symbol
% \newcommand*{\degree}{\textup{°}}% suddenly stopped working
\usepackage{gensymb}% substitute for the above
% radian symbol
\newcommand{\radian}{\,\textrm{rad}}
% set notation
\renewcommand{\emptyset}{\varnothing}% empty set
\newcommand{\intersect}{\cap}% intersection
\newcommand{\union}{\cup}% union
\newcommand{\ci}{\perp\!\!\!\perp}% conditional independence
% number sets
\newcommand{\N}{\ensuremath{\mathbb{N}} }% set of natural numbers
\newcommand{\Z}{\ensuremath{\mathbb{Z}} }% set of integers
\newcommand{\Q}{\ensuremath{\mathbb{Q}} }% set of rational numbers
\newcommand{\R}{\ensuremath{\mathbb{R}} }% set of real numbers
\newcommand{\Cx}{\ensuremath{\mathbb{C}} }% set of complex numbers
\let\Natural\N
\let\Integer\Z
\let\Rational\Q
\let\Real\R
\let\Complex\Cx
% better notation for sets
\let\union\cup
\let\Union\bigcup
\let\inter\cap
\let\Inter\bigcap
% mathematical symbols
\newcommand{\e}{\mathrm{e}}% exponential
\newcommand{\diff}{\mathop{}\!\mathrm{d}}% differential symbol
\DeclareMathOperator{\sign}{\mathrm{sign}}% sign
\DeclareMathOperator*{\argmax}{argmax}
\DeclareMathOperator*{\argmin}{argmin}
\DeclareMathOperator*{\freq}{freq}% freq
\DeclareMathOperator*{\indep}{\perp \!\!\! \perp}% independence symbol
\DeclareMathOperator{\trace}{Tr}
% statistical symbols
\DeclareMathOperator{\PROB}{\mathbb{P}}% probability
\DeclareMathOperator{\EXP}{\mathbb{E}}% expectation
\DeclareMathOperator{\VAR}{\mathbb{V}}% variance
\DeclareMathOperator{\COV}{\mathbb{C}}% covariance
\DeclareMathOperator{\SE}{\mathrm{SE}}% standard error
\DeclareMathOperator{\SD}{\mathrm{SD}}% standard deviation
\DeclareMathOperator{\MSE}{\mathrm{MSE}}% mean squared error
% trigonometric operators
\DeclareMathOperator{\arcsec}{arcsec}
\DeclareMathOperator{\arccot}{arccot}
\DeclareMathOperator{\arccsc}{arccsc}
% floor/ceiling
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}
% auto-scaling parentheses
\DeclarePairedDelimiter{\parens}{(}{)}
% auto-scaling brackets
\DeclarePairedDelimiter{\bracks}{[}{]}
% absolute value
\DeclarePairedDelimiter\abs{\lvert}{\rvert}
% mathematical norm
\DeclarePairedDelimiter\norm{\lVert}{\rVert}
% placeholder
\newcommand*{\placeholder}{\makebox[1ex]{\textbf{$\cdot$}}}
% tighter modulo command
\newcommand{\modulo}[1]{\;(\mathrm{mod}\,#1)}
% Smaller binomial command
\newcommand{\binomial}[3][0.8]{\scalebox{#1}{$\dbinom{#2}{#3}$}}
% smaller multiplication symbol
\DeclareMathOperator{\mult}{\mbox{\scriptsize$\times$}}
% right slash
\newcommand{\rslash}{\raisebox{.15ex}{/}}
% bold+underline command
\newcommand\underbold[1]{\underline{\bfseries\boldmath#1}}
% displaystyle commands
\newcommand*{\Sum}{\displaystyle\sum}
\newcommand*{\Prod}{\displaystyle\prod}
\newcommand*{\Frac}[2]{\displaystyle\frac{#1}{#2}}
\newcommand*{\Int}{\displaystyle\int}
\newcommand*{\Sqrt}[1]{\displaystyle\sqrt{#1}}
\newcommand*{\Binom}[1]{\displaystyle\binom{#1}}
% command \sfrac for small fractions | alternative to package xfrac
\newcommand{\sfrac}[2]{\scalebox{0.65}{\ensuremath{\left.#1\middle/#2\right.}}}
% Permutations/Combinations
\newcommand*{\permcomb}[4][0mu]{{{}^{#3}\mkern#1#2_{#4}}}
\newcommand*{\perm}[1][-3mu]{\permcomb[#1]{P}}
\newcommand*{\comb}[1][-1mu]{\permcomb[#1]{C}}
% Arrangements / Derangements
\newcommand*{\arr}[1][-1mu]{\,\permcomb[#1]{A}}% arrangements
\newcommand*{\arrange}[2]{A_{#1,#2}}
\newcommand*{\derange}[3][0mu]{{\mkern#1#2_{#3}}}
% multiset | double-parenthesis notation
\newcommand{\multiset}[2]{\bigl(\!{\binom{#1}{#2}}\!\bigr)}
\newcommand{\Multiset}[2]{\left(\!\!{\displaystyle\binom{#1}{#2}}\!\!\right)}
%% define commands for ticking in or crossing out
\RequirePackage{amssymb}
\RequirePackage{pifont}
\newcommand{\cmark}{\mbox{\ding{51}}}
\newcommand{\xmark}{\mbox{\ding{55}}}
% crossing-out digits
\newcommand{\crossout}[2][1]{%
\vphantom{\rslash}%
{\ooalign{\hidewidth$\crosses{#1}$\hidewidth\cr$#2$\cr}}%
}
\newcommand{\crosses}[1]{%
\ifcase#1\relax
\or
\rslash\or
\rslash\mskip-5.5mu\rslash\or
\rslash\mskip-5.5mu\rslash\mskip-5.5mu\rslash%
\fi
}
% Triangle and Arc/Sector hat symbols
%\RequirePackage{amsmath}% already loaded
\DeclareSymbolFont{yhlargesymbols}{OMX}{yhex}{m}{n}
\DeclareMathAccent{\trianglehat}{\mathord}{yhlargesymbols}{"E6}
\DeclareMathAccent{\sectorhat}{\mathord}{yhlargesymbols}{"F3}
% minipagex correctly applies paragraph skip preferences
\newlength{\currentparskip}
\newlength{\currentparindent}
\newenvironment{minipagex}[2][]
{\setlength{\currentparskip}{\parskip}% save the value
\setlength{\currentparindent}{\parindent}%
\begin{minipage}[#1]{#2}% open the minipage
\setlength{\parskip}{\currentparskip}% restore the value
\setlength{\parindent}{\currentparindent}% restore the value
}
{\end{minipage}}
% load tikz and libraries
\RequirePackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{positioning}
\usetikzlibrary{angles}
\usetikzlibrary{quotes}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.markings, decorations.text}
\usetikzlibrary{shapes,shapes.misc}
\usetikzlibrary{backgrounds}
\newcommand{\tikzmark}[1]{\tikz[baseline={(#1.base)},remember picture] \node[draw=red,thick,circle,inner sep=0.5pt,minimum width=3ex] (#1) {$#1$};}
\tikzset{connect/.style={
red,in=225,out=315,thick}}
% load pgfplots and library for coordinate system
\RequirePackage{pgfplots}
\pgfplotsset{compat=newest}% use bleeding edge version: risky
\usetikzlibrary{arrows.meta}
% text box with tikz, to use inside a node
\tikzstyle{textbox} = [draw=blue!80!black, fill=blue!1!white, very thick,
rectangle, rounded corners, inner sep=10pt, inner ysep=20pt]
% angled brackets to use as an option to \begin{cases} \end{cases}
% does not stretch if linespacing is increased
\makeatletter
\renewenvironment{cases}[1][\lbrace]{%
\def\@ldelim{#1}
\matrix@check\cases\env@cases
}{%
\endarray\right.%
}
\patchcmd{\env@cases}{\lbrace}{\@ldelim}{}{}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set Graphics Paths
\RequirePackage{graphicx}
%\graphicspath{}% initialize the graphicspath, no longer needed with new version
\DeclareGraphicsExtensions{.pdf,.png,.jpg,.jpeg}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% append paths to the existing graphicspath
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% https://tex.stackexchange.com/questions/171587/
% usage: \appendtographicspath{{a}{b}{c}}
\ExplSyntaxOn
\NewDocumentCommand{\appendtographicspath}{m}
{
\tl_if_exist:cF { Ginput@path } { \tl_new:c { Ginput@path } }
\clist_map_function:nN { #1 } \steven_gpath_append:n
}
\cs_new_protected:Nn \steven_gpath_append:n
{
\tl_gput_right:cn { Ginput@path } { {#1} }
}
% for debugging
\NewDocumentCommand{\showgraphicspath}{}{\tl_show:c { Ginput@path }}
\ExplSyntaxOff
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% append path to existing paths for input files
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% https://tex.stackexchange.com/questions/79058/
\makeatletter
\newcommand\appendtoinputpath[1]{%
\providecommand*{\input@path}{}%
\edef\input@path{#1\input@path}% prepend new path to path list
}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% ENVIRONMENTS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Proof | based on theorem environment
\RequirePackage{amssymb}% required
%\RequirePackage{amsthm}% ntheorem and amsthm not compatible
\newcommand*{\qed}{\null\nobreak\hfill\ensuremath{\square}}% \qed already defined by amsthm
\RequirePackage[thmmarks,amsthm]{ntheorem}
\theoremheaderfont{\bfseries}
\theorembodyfont{\normalfont}
\theoremseparator{:}
%\theoremsymbol{$\blacksquare$}
%\newtheorem*{theorem}{Theorem}% already defined
\newtheorem*{definition}{Definition}
%\newtheorem*{proof}{Proof}% already defined
\AtEndEnvironment{proof}{\hfill$\blacksquare$}
%% Question/Solution | based on tcolorbox
% solution | show/hide toggle
\RequirePackage{etoolbox}\newtoggle{showSolution}\togglefalse{showSolution}%
\ifsolution
\toggletrue{showSolution}% default is false
\fi
% math box with empheq+tcolorbox
\RequirePackage{empheq}
\RequirePackage[many]{tcolorbox}
\newtcbox{\mathbox}[1][]{%
nobeforeafter, math upper, tcbox raise base, enhanced, sharp corners, colframe=black, colback=white, boxrule=1pt, #1}
\newtcbox{\alignbox}[1][]{%
nobeforeafter, math upper, tcbox raise base, enhanced, colframe=black, colback=white, boxrule=1pt, #1}
% usage: \begin{solution}[Optional title]
\tcbset{onecolummnstyle/.style={
breakable,
enhanced,
lower separated=false,
text width=\linewidth,
%colframe=themecolor,
coltext=themecolor,
frame hidden,
colback=white,
sharp corners,
attach boxed title to top left={yshift=0ex,xshift=5pt},% negative xshift
boxed title style={
colframe=white,
colback=white,
sharp corners,
},
overlay={
\draw[themecolor!80!white, line width=1.5pt] (frame.north west)--(frame.south west);
},
%fonttitle=\sffamily
fonttitle={\normalsize\itshape\bfseries\color{themecolor}}
}
}
\newtcolorbox[auto counter]{question}[1][]{
title={Question},
onecolummnstyle,
#1
}
% conditionally define solution environment
% omit solution if \ifsolution is False
\iftoggle{showSolution}{
\newtcolorbox[auto counter]{solution}[1][]{
title={Solution},
onecolummnstyle,
#1
}
}{%
%\RequirePackage{verbatim}% already loaded
\newenvironment{solution}{\vspace{0em}\expandafter\comment}{\expandafter\endcomment}
}%
% box inside a box
\usepackage{varwidth}
\newtcolorbox{boxinbox}[2][]{
enhanced,
colback=gray!10!white,
boxrule=0.1pt,
colframe=themecolor,
fonttitle=\bfseries,
%center title,
width=\linewidth,
nobeforeafter,
%lifted shadow={1mm}{-2mm}{3mm}{0.1mm}{black!50!white},
title={#2},
#1
}
% answer environment | redundant with solution | somewhat earlier version
\RequirePackage{etoolbox}\newtoggle{showAnswers}\togglefalse{showAnswers}%
\ifanswer
\toggletrue{showAnswers}% default is false
\fi
\ifsolution% added to accommodate both answer and solution environments
\toggletrue{showAnswers}% default is false
\fi
% define answer environment
\iftoggle{showAnswers}{
\newtcolorbox{answer}{%
breakable,
enhanced,
width=\linewidth,
parbox=false, % normal paragraph spacing
colback=blue!2!white,
opacityback=0.5,enhanced jigsaw,
colframe=blue!80!black
}
%\newenvironment{answer}{\vspace{1em}}{}
}{%
%\RequirePackage{verbatim}% already loaded
\newenvironment{answer}{\vspace{0em}\expandafter\comment}{\expandafter\endcomment}
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%