-
Notifications
You must be signed in to change notification settings - Fork 11
/
shortex.sty
637 lines (570 loc) · 24.5 KB
/
shortex.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
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% shortex.sty
%% Latex packages and macros for
%% more efficient, readable math
%%
%% Copyright (c) 2023 Trevor Campbell,
%% Jonathan Huggins, Jeffrey Negrea
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ProvidesPackage{shortex}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Package Imports (packages without dynamic options/inclusion)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{xifthen} % extended if/then commands (needed internally for \isempty)
\usepackage{xstring} % string manipulation (needed internally for \StrLeft, \StrGobbleLeft, \IfStrEqCase, etc in font/style macro expansions)
\usepackage{xspace} % defines \xspace command that automatically determine whether spaces should be eaten (needed internally for many defns)
\usepackage[usenames,dvipsnames]{xcolor} % for using colored text (needed internally for \definecolor to create WowColor and SubtleColor)
\usepackage{xr-hyper} % cross referencing across docs
\usepackage{hyperref} % typical linking package
\usepackage{mathrsfs,dsfont,amsmath,amssymb,amsthm,bm,bbm,amsfonts,mathtools,thmtools} % math
\usepackage[nice]{nicefrac} % nice fraction typesetting
\usepackage[capitalize,sort,compress]{cleveref} % automatic typesetting of references with typed names
\usepackage{crossreftools} % ensure that crefs appear correctly in bookmarks (needed internally for \crtCref, \crtcref)
\usepackage{algpseudocode, algorithm} % typical algorithm typesetting packages
\usepackage{multirow} % multirow tables
\usepackage{wrapfig} % figures wrapped into the text
\usepackage{caption,subcaption} % package for sub-environments (figs, tables, etc)
\usepackage{microtype} % microtypesetting improvements for latex
\usepackage{booktabs} % professional quality tables
\usepackage{import, subfiles} % packages for using subfile/folder structure
\usepackage{url} % nice URL typesetting (used internally for \UrlFont command)
\usepackage{kvoptions} % for defining key-value options for this package
\usepackage{marginnote} % for margin comments within floats
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Color Definitions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\definecolor{SubtleColor}{rgb}{0,0,.50}
\definecolor{CommentColor0}{rgb}{0,0,.8}
\definecolor{CommentColor1}{rgb}{.8,0,.8}
\definecolor{CommentColor2}{rgb}{.8,0,0}
\definecolor{CommentColor3}{rgb}{0,.4,0}
\definecolor{CommentColor4}{rgb}{.8,.3,0}
\definecolor{CommentColor5}{rgb}{.5,0,.5}
\definecolor{CommentColor6}{rgb}{.3,.7,.7}
\definecolor{CommentColor7}{rgb}{0,.4,.8}
\definecolor{CommentColor8}{rgb}{.6,.5,.3}
\newcounter{MaxCommentColor}
\setcounter{MaxCommentColor}{8}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Package Setup, Options, and Fixes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ensures that hyperref generates correct bookmarks when using cleveref
\pdfstringdefDisableCommands{%
\let\Cref\crtCref
\let\cref\crtcref
}
\crefformat{footnote}{#1\footnotemark[#2]#3}
% Fix the algorithm \Comment command
\algrenewcommand{\algorithmiccomment}[1]{\hfill$\triangleright$ #1}
%properly indented algorithm comments
%usage: \LineComment{X}{Here is the comment}, where X = # additional indents.
\newdimen{\algindent}
\setlength\algindent{1.5em}
\makeatletter
\newcommand{\LineComment}[2][0]{\Statex \hspace{#1\algindent} \hskip\ALG@thistlm $\triangleright$ #2}
\makeatother
% set the default hyperref style to dark blue
\hypersetup{colorlinks=true, allcolors=SubtleColor, linkbordercolor={1 1 1}, pdfborder={0 0 0}, pdfborderstyle={/S/U/W 0}}
% allow the user to switch to a black hypersetup if desired
\DeclareVoidOption{blacklinks}{\hypersetup{colorlinks=false, allcolors=black, pdfborder={0 0 0}}}
% use autonum by default
\newif\ifusemanualnum
\usemanualnumfalse
\DeclareVoidOption{noautonum}{\usemanualnumtrue}
% pass draft mode on to graphicx and hyperref
\DeclareVoidOption{draft}{\PassOptionsToPackage{draft}{graphicx}\PassOptionsToPackage{draft}{hyperref}}
% whether to parse common font/accent combinations
\newif\iffontcombos
\fontcombostrue
\DeclareVoidOption{nomathfontdefaults}{\fontcombosfalse}
% an option to specify commenter names
\DeclareStringOption{commenters}
% an option to hide comments
\newif\ifhidecomments
\hidecommentsfalse
\DeclareVoidOption{hidecomments}{\hidecommentstrue}
% process the package options
\ProcessKeyvalOptions*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Package Imports (packages with dynamic options/inclusion)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% load graphicx using draft mode (or not) per above
\usepackage{graphicx}
% load autonum by default; avoid loading it is manualnumbering set
\ifusemanualnum \else \usepackage{autonum} \fi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Environments
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\defineshortenedenvironment}[2]{
\expandafter\def\csname b#1\endcsname{\begin{#2}}
\expandafter\def\csname e#1\endcsname{\end{#2}}
}
\newcommand{\defineshortenedenvironmentwithstar}[2]{
\expandafter\def\csname b#1\endcsname{\begin{#2}}
\expandafter\def\csname e#1\endcsname{\end{#2}}
\expandafter\def\csname b#1s\endcsname{\begin{#2*}}
\expandafter\def\csname e#1s\endcsname{\end{#2*}}
}
\newcommand{\defineshortenedtheoremlike}[5]{
\declaretheorem[name=#3,#5]{#2}
\declaretheorem[name=#3,numbered=no]{#2*}
\expandafter\def\csname b#1\endcsname{\begin{#2}}
\expandafter\def\csname e#1\endcsname{\end{#2}}
\expandafter\def\csname b#1u\endcsname{\begin{#2*}}
\expandafter\def\csname e#1u\endcsname{\end{#2*}}
\crefname{#2}{#3}{#4}
}
% align redef
\AtBeginDocument{ %necessary to stop clash with autonum package
\def\[#1\]{\begin{align}#1\end{align}}
}
% common environments
\defineshortenedenvironment{alg}{algorithm}
\defineshortenedenvironment{algc}{algorithmic}
\defineshortenedenvironment{abs}{abstract}
\defineshortenedenvironment{cent}{center}
\defineshortenedenvironmentwithstar{fig}{figure}
\defineshortenedenvironment{subfig}{subfigure}
\defineshortenedenvironment{tab}{table}
\defineshortenedenvironment{tabr}{tabular}
\defineshortenedenvironment{item}{itemize}
\defineshortenedenvironment{enum}{enumerate}
\defineshortenedenvironment{desc}{description}
\defineshortenedenvironment{prf}{proof}
\newenvironment{proofof}[1]{\renewcommand{\proofname}{Proof of #1}\proof}{\endproof}
\defineshortenedenvironment{prfof}{proofof}
\defineshortenedenvironment{pmat}{pmatrix}
\defineshortenedenvironment{bmat}{bmatrix}
\defineshortenedenvironment{mat}{matrix}
% theorem-like envs
\defineshortenedtheoremlike{thm}{theorem}{Theorem}{Theorems}{numberwithin=section}
\defineshortenedtheoremlike{lem}{lemma}{Lemma}{Lemmas}{numberlike=theorem}
\defineshortenedtheoremlike{prop}{proposition}{Proposition}{Propositions}{numberlike=theorem}
\defineshortenedtheoremlike{cor}{corollary}{Corollary}{Corollaries}{numberlike=theorem}
\defineshortenedtheoremlike{conj}{conjecture}{Conjecture}{Conjectures}{numberlike=theorem}
\defineshortenedtheoremlike{defn}{definition}{Definition}{Definitions}{numberlike=theorem}
\defineshortenedtheoremlike{assum}{assumption}{Assumption}{Assumptions}{numberlike=theorem}
\defineshortenedtheoremlike{exa}{example}{Example}{Examples}{numberlike=theorem}
\defineshortenedtheoremlike{rmk}{remark}{Remark}{Remarks}{numberlike=theorem}
\defineshortenedtheoremlike{fact}{fact}{Fact}{Facts}{numberlike=theorem}
\defineshortenedtheoremlike{exer}{exercise}{Exercise}{Exercises}{numberwithin=section}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Font styles/accents
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Widebar (need to define here for font style usage)
% obtained from https://tex.stackexchange.com/questions/16337/can-i-get-a-widebar-without-using-the-mathabx-package
\makeatletter
\let\save@mathaccent\mathaccent
\newcommand*\if@single[3]{%
\setbox0\hbox{${\mathaccent"0362{#1}}^H$}%
\setbox2\hbox{${\mathaccent"0362{\kern0pt#1}}^H$}%
\ifdim\ht0=\ht2 #3\else #2\fi
}
%The bar will be moved to the right by a half of \macc@kerna, which is computed by amsmath:
\newcommand*\rel@kern[1]{\kern#1\dimexpr\macc@kerna}
%If there's a superscript following the bar, then no negative kern may follow the bar;
%an additional {} makes sure that the superscript is high enough in this case:
\newcommand*\widebar[1]{\@ifnextchar^{{\wide@bar{#1}{0}}}{\wide@bar{#1}{1}}}
%Use a separate algorithm for single symbols:
\newcommand*\wide@bar[2]{\if@single{#1}{\wide@bar@{#1}{#2}{1}}{\wide@bar@{#1}{#2}{2}}}
\newcommand*\wide@bar@[3]{%
\begingroup
\def\mathaccent##1##2{%
%Enable nesting of accents:
\let\mathaccent\save@mathaccent
%If there's more than a single symbol, use the first character instead (see below):
\if#32 \let\macc@nucleus\first@char \fi
%Determine the italic correction:
\setbox\z@\hbox{$\macc@style{\macc@nucleus}_{}$}%
\setbox\tw@\hbox{$\macc@style{\macc@nucleus}{}_{}$}%
\dimen@\wd\tw@
\advance\dimen@-\wd\z@
%Now \dimen@ is the italic correction of the symbol.
\divide\dimen@ 3
\@tempdima\wd\tw@
\advance\@tempdima-\scriptspace
%Now \@tempdima is the width of the symbol.
\divide\@tempdima 10
\advance\dimen@-\@tempdima
%Now \dimen@ = (italic correction / 3) - (Breite / 10)
\ifdim\dimen@>\z@ \dimen@0pt\fi
%The bar will be shortened in the case \dimen@<0 !
\rel@kern{0.6}\kern-\dimen@
\if#31
\overline{\rel@kern{-0.6}\kern\dimen@\macc@nucleus\rel@kern{0.4}\kern\dimen@}%
\advance\dimen@0.4\dimexpr\macc@kerna
%Place the combined final kern (-\dimen@) if it is >0 or if a superscript follows:
\let\final@kern#2%
\ifdim\dimen@<\z@ \let\final@kern1\fi
\if\final@kern1 \kern-\dimen@\fi
\else
\overline{\rel@kern{-0.6}\kern\dimen@#1}%
\fi
}%
\macc@depth\@ne
\let\math@bgroup\@empty \let\math@egroup\macc@set@skewchar
\mathsurround\z@ \frozen@everymath{\mathgroup\macc@group\relax}%
\macc@set@skewchar\relax
\let\mathaccentV\macc@nested@a
%The following initialises \macc@kerna and calls \mathaccent:
\if#31
\macc@nested@a\relax111{#1}%
\else
%If the argument consists of more than one symbol, and if the first token is
%a letter, use that letter for the computations:
\def\gobble@till@marker##1\endmarker{}%
\futurelet\first@char\gobble@till@marker#1\endmarker
\ifcat\noexpand\first@char A\else
\def\first@char{}%
\fi
\macc@nested@a\relax111{\first@char}%
\fi
\endgroup
}
\makeatother
\newcommand{\uppercaseRoman}{ABCDEFGHIJKLMNOPQRSTUVWXYZ}
\newcommand{\lowercaseRoman}{abcdefghijklmnopqrstuvwxyz}
\newcommand{\lowercaseGreek}{\alpha\beta\gamma\delta\eps\zeta\eta\theta\iota\kappa\lam\mu\nu\xi\pi\rho\sigma\tau\ups\phi\chi\psi\omega\veps\vtheta\vkappa\vpi\vrho\vsigma\vphi}
\newcommand{\uppercaseGreek}{\Gamma\Delta\Theta\Lam\Xi\Pi\Sigma\Ups\Phi\Psi\Omega}
\newcommand{\s}[2][]{
\StrLeft{#1}{1}[\fontstylehead]
\StrGobbleLeft{#1}{1}[\fontstyletail]
\IfStrEqCase{\fontstylehead}{%
{}{#2}
{b}{ \widebar{\s[\fontstyletail]{#2}} }%
{k}{ \bm{{\s[\fontstyletail]{#2}}} }%
{d}{ \mathbb{\s[\fontstyletail]{#2}} }%
{h}{ {\widehat {\s[\fontstyletail]{#2}}} }%
{t}{ {\widetilde {\s[\fontstyletail]{#2}}} }%
{c}{ {\mathcal {\s[\fontstyletail]{#2}}} }%
{f}{ {\mathfrak {\s[\fontstyletail]{#2}}} }%
{o}{ {\dot {\s[\fontstyletail]{#2}}} }%
}[{\s[\fontstyletail]{#2}}]
}
% defines the macroname command:
% \macroname{\alpha} -> alpha
% \macroname{alpha} -> alpha
% used for defining greek alphabets
\begingroup\lccode`\|=`\\
\lowercase{\endgroup\def\removebs#1{\if#1|\else#1\fi}}
\newcommand{\macroname}[1]{\expandafter\removebs\string#1}
% essentially the same functionality as charalphabetmacro,
% % except the macro name and the command are passed as one argument
% % since \s is used in the definition
\newcommand{\charfontstylemacro}[2]{
% #1: annotation codes
% #2: characters to define annotations for
% Create a macros of the form
% \newcommand{\s#1##1}{\s[#1]{##1}} for each ##1 in #2
\def\mydeffoo##1{\expandafter\def\csname s#1\macroname{##1}\endcsname{\s[#1]{##1}}}
\def\mydefallfoo##1{\ifx##1\mydefallfoo\else\mydeffoo##1\expandafter\mydefallfoo\fi}
\expandafter \mydefallfoo #2\mydefallfoo
}
% I got this to work by basing it off of \texalphabetmacro above
% % the order of expansion in LaTeX is very opaque to me, so im not 100%
% % sure why it works, but it does, and I wrote it thinking it would work
% % for whatever voodoo reason \texalphabetmacro also worked.
\newcommand{\parsefontstylestrings}[2]{
% #1: annotation codes
% #2: characters to define annotations for
% Create a macros of the form
% \newcommand{\s##1##2}{\s{##1}{##2}} for each ##1 in #1 and each ##2 in #2
\def\mydeftex##1{\expandafter\charfontstylemacro{##1}{#2}}
\def\mydefalltex##1{\ifx\mydefalltex##1\else\mydeftex{##1}%
\lowercase{\mydeftex{##1}}\expandafter\mydefalltex\fi}
\expandafter \mydefalltex #1\mydefalltex
}
% default is to parse common font style/accent combinations
% but can be disabled with the minimal package option
\iffontcombos
\parsefontstylestrings{{b}{k}{d}{h}{t}{c}{o}{bk}{bd}{bc}{hk}{hd}{hc}{tk}{td}{tc}{ok}{od}{oc}}{\lowercaseRoman}
\parsefontstylestrings{{b}{k}{d}{h}{t}{c}{o}{bk}{bd}{bc}{hk}{hd}{hc}{tk}{td}{tc}{ok}{od}{oc}}{\uppercaseRoman}
\parsefontstylestrings{{b}{k}{d}{h}{t}{c}{o}{bk}{bd}{bc}{hk}{hd}{hc}{tk}{td}{tc}{ok}{od}{oc}}{\lowercaseGreek}
\parsefontstylestrings{{b}{k}{d}{h}{t}{c}{o}{bk}{bd}{bc}{hk}{hd}{hc}{tk}{td}{tc}{ok}{od}{oc}}{\uppercaseGreek}
\fi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Commenting
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
% define comment commands only if commenters were specified
\ifdefined\shortex@commenters
% and only if the list of commenters isnt empty
\IfEq{\shortex@commenters}{}{}{
\newcounter{commentcolorcounter}
\newcommand{\definecommenters}[1]{
% extract the name of the next commenter in the list
\IfSubStr{#1}{,}{
% if there is a comma in the list string, split and take the first
\StrBefore{#1}{,}[\thiscommenter]
\StrBehind{#1}{,}[\remainingcommenters]
}{
% if there is no comma in the string, just keep the whole string
\StrDel{#1}{}[\thiscommenter]
\StrBehind{#1}{,}[\remainingcommenters]
}
% define a counter for this commenter, as well as functions to just display or increment
\expandarg\newcounter{commentcounter\thiscommenter}
\edef\displaycounter{\noexpand\noexpand\noexpand\arabic{commentcounter\thiscommenter}}
\edef\incdisplaycounter{\noexpand\noexpand\noexpand\stepcounter{commentcounter\thiscommenter}\noexpand\noexpand\noexpand\arabic{commentcounter\thiscommenter}}
\ifhidecomments
% if comments are hidden, just set the commenting commands to be no-ops
\expandafter\def\csname c\thiscommenter\endcsname##1{}
\expandafter\def\csname e\thiscommenter\endcsname##1{}
\expandafter\def\csname h\thiscommenter\endcsname##1{##1}
\expandafter\def\csname m\thiscommenter\endcsname##1{}
\else
%otherwise, set commenting commands to add comments
\expandafter\edef\csname c\thiscommenter\endcsname##1{\noexpand\textcolor{CommentColor\thecommentcolorcounter}{ {(\thiscommenter\incdisplaycounter)} ##1}}
\expandafter\edef\csname e\thiscommenter\endcsname##1{\noexpand\textcolor{CommentColor\thecommentcolorcounter}{{\noexpand\bf (\thiscommenter\incdisplaycounter) ##1}}}
\expandafter\edef\csname h\thiscommenter\endcsname##1{\noexpand\textcolor{CommentColor\thecommentcolorcounter}{##1}}
\expandafter\edef\csname m\thiscommenter\endcsname##1{%
\noexpand\textcolor{CommentColor\thecommentcolorcounter}{$\,^{(\noexpand\text{\thiscommenter}\incdisplaycounter)}$\noexpand\marginnote{\noexpand\tiny\noexpand\textcolor{CommentColor\thecommentcolorcounter}{(\thiscommenter\displaycounter) ##1}}}}
\fi
% if the color counter exceeded
\stepcounter{commentcolorcounter}
\ifnum\c@commentcolorcounter>\c@MaxCommentColor
\setcounter{commentcolorcounter}{0}
\fi
%% call this command on the remaining names in the list if there are any left
\IfEq{\remainingcommenters}{}{}{\definecommenters{\remainingcommenters}}
}
\definecommenters{\shortex@commenters}
}
\fi
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Delimiters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% define shorthand lt, rt that fixes spacing around \left \right
% per https://tex.stackexchange.com/questions/2607/spacing-around-left-and-right
% originally from Heiko Oberdiek, Re: spacing after \right) and before \left), newsgroup
% comp.text.tex, Message-ID: i6jcc2$8of$1@news.eternal-september.org,
% 2010-09-12.
% https://groups.google.com/group/comp.text.tex/msg/257aa6119bef878b
\newcommand{\lt}{\mathopen{}\mathclose\bgroup\left}
\newcommand{\rt}{\aftergroup\egroup\right}
\newcommand{\m}{\middle}
\newcommand{\lb}{\bigl}
\newcommand{\lB}{\Bigl}
\newcommand{\lbg}{\biggl}
\newcommand{\lBg}{\Biggl}
\newcommand{\rb}{\bigr}
\newcommand{\rB}{\Bigr}
\newcommand{\rbg}{\biggr}
\newcommand{\rBg}{\Biggr}
\DeclarePairedDelimiter\norm{\lVert}{\rVert}
\DeclarePairedDelimiter\inner{\langle}{\rangle}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}
\DeclarePairedDelimiter\rbra{(}{)}
\DeclarePairedDelimiter\cbra{\{}{\}}
\DeclarePairedDelimiter\sbra{[}{]}
\DeclarePairedDelimiter\abs{\lvert}{\rvert}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Greek characters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% original
\newcommand{\eps}{\epsilon}
\newcommand{\lam}{\lambda}
\newcommand{\Lam}{\Lambda}
\newcommand{\ups}{\upsilon}
\newcommand{\Ups}{\Upsilon}
% variants
\newcommand{\veps}{\varepsilon}
\newcommand{\vtheta}{\vartheta}
\newcommand{\vpi}{\varpi}
\newcommand{\vrho}{\varrho}
\newcommand{\vsigma}{\varsigma}
\newcommand{\vphi}{\varphi}
\newcommand{\vkappa}{\varkappa}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Abbreviations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\eg}{e.g.,\ }
\newcommand{\etal}{et al.\xspace}
\newcommand{\ie}{i.e.,\ }
\newcommand{\aka}{a.k.a.\ }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Common Sets and Set Operations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\reals}{\ensuremath{\mathbb{R}}}
\newcommand{\xreals}{\overline{\reals}}
\newcommand{\ints}{\ensuremath{\mathbb{Z}}}
\newcommand{\rats}{\ensuremath{\mathbb{Q}}}
\newcommand{\nats}{\ensuremath{\mathbb{N}}}
\newcommand{\comps}{\ensuremath{\mathbb{C}}}
\newcommand{\msrs}{\mathcal{M}}
\newcommand{\pmsrs}{\mathcal{M}_1}
\newcommand{\union}{\bigcup}
\newcommand{\inter}{\bigcap}
\newcommand{\vol}{\operatorname{vol}}
\newcommand{\diam}{\operatorname{diam}}
\newcommand{\cl}{\operatorname{cl}}
\newcommand{\spann}{\operatorname{span}}
\newcommand{\bdry}{\partial}
\newcommand{\cone}{\operatorname{cone}}
\newcommand{\conv}{\operatorname{conv}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Linear Algebra, Vectors, and Matrices
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\tr}{\operatorname{tr}}
\newcommand{\kron}{\operatorname{\otimes}}
\newcommand{\adjsym}{\dag} % adjoint symbol
\newcommand{\adj}{^{\adjsym}} % adjoint
\newcommand{\spec}{\operatorname{\sigma}}
\newcommand{\diag}{\operatorname{diag}}
\newcommand{\rank}{\operatorname{rank}}
\newcommand{\transposesym}{\top}
\newcommand{\T}{^{\transposesym}}
\newcommand{\nT}{^{-\transposesym}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Calculus
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\let\oldd\d
\renewcommand\d{\ifmmode\mathrm{d}\else\oldd\fi} %make \d be mathrm{d} in math mode, usual defn as underdot(?) in text mode
\newcommand{\pd}{\partial}
\newcommand{\grad}{\nabla}
\newcommand{\der}[3][]{\ensuremath{\frac{{\d}^{#1} #2}{\d {#3}^{#1}}}}
\newcommand{\pder}[3][]{\ensuremath{\frac{{\pd}^{#1} #2}{\pd {#3}^{#1}}}}
\newcommand{\hes}[3]{\ensuremath{\frac{\pd^2 #1}{\pd #2 \pd #3}}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Probability and Statistics
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% text shortcuts
\newcommand{\iid}{\textrm{i.i.d.}\@\xspace}
\newcommand{\as}{\textrm{a.s.}\@\xspace}
\newcommand{\aev}{\textrm{a.e.}\@\xspace}
% convergence
\newcommand{\convas}{\overset{a.s.}{\to}}
\newcommand{\convp}{\overset{p}{\to}}
\newcommand{\convd}{\overset{d}{\to}}
\newcommand{\eqd}{\overset{d}{=}}
\newcommand{\eqas}{\overset{a.s.}{=}}
% unary/functions
\let\oldP\P
\renewcommand\P{\ifmmode\mathbb{P}\else\oldP\fi} %make \P be mathbbP in math mode, usual defn as pilcrow in text mode
\newcommand{\E}{\mathbb{E}} % expectation
\newcommand{\Var}{\operatorname{Var}} % variance
\newcommand{\Cov}{\operatorname{Cov}} % covariance
\newcommand{\Corr}{\operatorname{Corr}} % correlation
\newcommand{\supp}{\operatorname{supp}} %support
% binary operators
\newcommand{\dist}{\sim}
\newcommand{\distiid}{\overset{\text{iid}}{\dist}}
\newcommand{\distind}{\overset{\text{ind}}{\dist}}
% independence
\def\independenT#1#2{\mathrel{\rlap{$#1#2$}\mkern4mu{#1#2}}}
\newcommand\indep{\protect\mathpalette{\protect\independenT}{\perp}} % independent
% divergences
\newcommand{\KL}{\operatorname{KL}}
\newcommand{\TV}{\operatorname{TV}}
\newcommand{\Wass}{\operatorname{W}}
\newcommand{\Hell}{\operatorname{H}}
% parametric distributions
\newcommand{\distNamed}[1]{{\mathrm{#1}}}
\newcommand{\Norm}{\mathcal{N}}
\newcommand{\StudentT}{\mathcal{T}}
\newcommand{\Wish}{\mathcal{W}}
\newcommand{\InvWish}{\mathcal{IW}}
\newcommand{\Lap}{\distNamed{Lap}}
\newcommand{\ChiSq}{\chi^2}
\newcommand{\Unif}{\distNamed{Unif}}
\newcommand{\Gam}{\distNamed{Gam}}
\newcommand{\Gum}{\distNamed{Gumbel}}
\newcommand{\GEV}{\distNamed{GEV}}
\newcommand{\Cat}{\distNamed{Categorical}}
\newcommand{\InvGam}{\distNamed{InvGam}}
\newcommand{\Poiss}{\distNamed{Poiss}}
\newcommand{\Exp}{\distNamed{Exp}}
\newcommand{\Beta}{\distNamed{Beta}}
\newcommand{\Dir}{\distNamed{Dir}}
\newcommand{\Binom}{\distNamed{Binom}}
\newcommand{\Multi}{\distNamed{Multi}}
\newcommand{\Bern}{\distNamed{Bern}}
\newcommand{\Geom}{\distNamed{Geom}}
\newcommand{\Cauchy}{\distNamed{Cauchy}}
\newcommand{\VMF}{\distNamed{vMF}}
% nonparametric distributions
\newcommand{\BeP}{\distNamed{BeP}}
\newcommand{\DP}{\distNamed{DP}}
\newcommand{\CRP}{\distNamed{CRP}}
\newcommand{\PYP}{\distNamed{PY}}
\newcommand{\GP}{{\distNamed{GP}}}
\newcommand{\PP}{\distNamed{PP}}
\newcommand{\BP}{\distNamed{BP}}
\newcommand{\BPP}{\distNamed{BPP}}
\newcommand{\GamP}{\distNamed{\Gamma P}}
\newcommand{\NGamP}{\distNamed{N\Gamma P}}
\newcommand{\LP}{\distNamed{LP}}
\newcommand{\Obs}{\distNamed{Obs}}
\newcommand{\CRM}{\distNamed{CRM}}
\newcommand{\NCRM}{\distNamed{NCRM}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Other
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\1}{\mathds{1}} % indicator function
\newcommand{\sgn}{\operatorname{sgn}} % sign function
% Words in math
\newcommand{\st}{\ \text{s.t.}\ }
\newcommand{\andd}{\ \text{and}\ }
\newcommand{\orr}{\ \text{or}\ }
\newcommand{\where}{\ \text{where}\ }
\newcommand{\with}{\ \text{with}\ }
% Min and max
\def\argmax{\operatornamewithlimits{arg\,max}}
\def\argmin{\operatornamewithlimits{arg\,min}}
\def\esssup{\operatornamewithlimits{ess\,sup}}
\def\essinf{\operatornamewithlimits{ess\,inf}}
% Equality operators
\mathtoolsset{centercolon}
%\newcommand{\definedas}{:=}
%\newcommand{\defines}{=:}
%
%% Fractions
%\newcommand{\half}{\ensuremath{\nicefrac{1}{2}}\xspace}
%\newcommand{\third}{\ensuremath{\nicefrac{1}{3}}\xspace}
%\newcommand{\quarter}{\ensuremath{\nicefrac{1}{4}}\xspace}
%
%\newcommand{\prox}[2]{\ensuremath{\operatorname{prox}_{#1}\rbra{#2}}}
%
%\newcommand*\pFq[2]{{}_{#1}F_{#2}}
%
%\DeclareMathOperator{\notimplies}{\centernot\implies}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Squeezed math
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% taken from https://tex.stackexchange.com/questions/467942/how-to-squeeze-a-long-equation
\newcommand*\scalemuskip[2]{%
\muexpr #1*\numexpr\dimexpr#2pt\relax\relax/65536\relax
} %% <- based on https://tex.stackexchange.com/a/198966/156366
%% <- #1 is a number between 0 and 1
\newcommand*\squish[1]{%
\thickmuskip=\scalemuskip{\thickmuskip}{#1}%
\medmuskip=\scalemuskip{\medmuskip}{#1}%
\thinmuskip=\scalemuskip{\thinmuskip}{#1}%
\nulldelimiterspace=#1\nulldelimiterspace
\scriptspace=#1\scriptspace
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Improved square root
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\let\oldsqrt\sqrt % rename \sqrt as \oldsqrt
\def\sqrt{\mathpalette\DHLhksqrt} % define the new \sqrt in terms of the old one
\def\DHLhksqrt#1#2{%
\setbox0=\hbox{$#1\oldsqrt{#2\,}$}\dimen0=\ht0
\advance\dimen0-0.2\ht0
\setbox2=\hbox{\vrule height\ht0 depth -\dimen0}%
{\box0\lower0.4pt\box2}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Words/names with accents
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\cadlag{c\`adl\`ag\xspace}
\def\Gronwall{Gr\"onwall\xspace}
\def\Renyi{R\'enyi\xspace}
\def\Holder{H\"older\xspace}
\def\Ito{It\^o\xspace}
\def\Nystrom{Nystr\"om\xspace}
\def\Schatten{Sch\"atten\xspace}
\def\Matern{Mat\'ern\xspace}
\def\Frechet{Fr\'echet\xspace}
\def\Levy{L\'evy\xspace}