-
Notifications
You must be signed in to change notification settings - Fork 737
/
prelude.sty
392 lines (335 loc) · 12.3 KB
/
prelude.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
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{prelude}[2020/10/06 AlgoXY Prelude LaTeX package]
\usepackage[hyphens]{url}
\urlstyle{rm}
\RequirePackage{ifpdf}
\RequirePackage{ifxetex}
\RequirePackage[bookmarksnumbered,
colorlinks,
linkcolor=blue,
hyperindex,
plainpages=false,
pdfstartview=FitH]{hyperref}
\usepackage{fontspec}
\usepackage[nil,english]{babel}
\usepackage{graphicx, color}
\usepackage{adjustbox}
\usepackage{wrapfig}
\usepackage{caption}
\usepackage{subcaption} % subfig is deprecated
\usepackage{enumerate}
\usepackage{multicol}
\usepackage{pdfpages} % to include pdf
\usepackage{xcolor} % for colored table
\usepackage{hhline}
\usepackage[super, square]{natbib}
\usepackage{tikz}
\usetikzlibrary{patterns,matrix,positioning,shapes,arrows}
\usepackage{amsmath, amsthm, amssymb, amsbsy, nccmath} % for math
\usepackage{textgreek, upgreek}
\usepackage{gensymb}
\usepackage{mathtools}
\usepackage{extarrows}
\usepackage{polynom}
\usepackage[lastexercise, answerdelayed]{exercise} % for exercise
\usepackage{stmaryrd} % for banana brackets
\usepackage{pict2e} % for customize lens brackets
\usepackage[normalem]{ulem}
\usepackage{suffix} % for starred command
\usepackage{import} % for nested input
\usepackage{standalone}
\usepackage{tocloft}
\usepackage{verbatim}
\usepackage{fancyvrb}
\usepackage{listings}
\usepackage{algorithm} %to remove rules change to \usepackage[plain]{algorithm}
\usepackage[noend]{algpseudocode} %for pseudo code, include algorithmicsx automatically
\usepackage{appendix}
\usepackage{makeidx} % for index support
\usepackage{titlesec}
\usepackage{epigraph}
\usepackage{ifplatform} % for platform detection
\usepackage{textcomp}
\usepackage{mdframed}
\usepackage{sourcecodepro}
\usepackage{cleveref}
\usepackage{etoolbox}
\usepackage{csquotes}
\titleformat{\paragraph}
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\newcommand\doubleplus{\ensuremath{\mathbin{+\mkern-10mu+}}}
%\newcommand\doubleplus{+\kern-1.3ex+\kern0.8ex}
%\newcommand\mdoubleplus{\ensuremath{\mathbin{+\mkern-10mu+}}}
\newcommand\cons{\ensuremath{\mathbin{\!:\!}}}
% for literate Haskell code
\lstdefinestyle{Haskell}{
language=Haskell,
flexiblecolumns=false,
numberstyle=\ttfamily\tiny,
emphstyle={\bf},
escapeinside={*'}{'*},
stringstyle=\mdseries\ttfamily, %rmfamily,
keywordstyle=\bfseries\ttfamily, %rmfamily
basicstyle=\footnotesize\ttfamily, %sffamily
commentstyle = \footnotesize\rmfamily,
showstringspaces=false,
morecomment=[l]--,
literate={+}{{$+$}}1 {/}{{$/$}}1 {*}{{$*$}}1 {=}{{$=$}}1
{++}{{$\doubleplus$}}2 {/=}{{$\neq$}}2
{>}{{$>$}}1 {<}{{$<$}}1 {\\}{{$\lambda$}}1
{`}{{\texttt{`}}}1
{\\\\}{{\char`\\\char`\\}}1
{->}{{$\rightarrow$}}2 {>=}{{$\geq$}}2 {<-}{{$\leftarrow$}}2
{<=}{{$\leq$}}2 {=>}{{$\Rightarrow$}}2
%{\ .}{{$\circ$}}2
{\ .\ }{{$\circ$}}2
{>>}{{>>}}2 {>>=}{{>>=}}2
{|}{{$\mid$}}1
}
% A virtual programming language, named after Nicolas Bourbaki, a collective
% pseudonym of a group of mathematicians, including André Weil, Henri Cartan,
% Jean Dieudonné, etc.
% https://en.wikipedia.org/wiki/Nicolas_Bourbaki
% The name emphasises its virtual, ideal, and humor
\lstdefinelanguage{Bourbaki}{
morekeywords={abstract, case, catch, class, struct,
and, or, not, data, void, to, loop, in, then, repeat, until,
do, else, false, for, if, new, null, return, break,
throw, true, try, type, val, var, while, yield },
otherkeywords={=>,<-,<\%,<:,>:,\#,@},
literate={+}{{$+$}}1 {/}{{$/$}}1 {*}{{$*$}}1 {=}{{$=$}}1
{>}{{$>$}}1 {<}{{$<$}}1 {\\}{{$\lambda$}}1
{\\\\}{{\char`\\\char`\\}}1
{!=}{{$\neq$}}2
{->}{{$\rightarrow$}}2 {>=}{{$\geq$}}2 {<-}{{$\leftarrow$}}2
{<=}{{$\leq$}}2 {=>}{{$\Rightarrow$}}2
%{\ .}{{$\circ$}}2
{\ .\ }{{$\circ$}}2
{|}{{$\mid$}}1,
sensitive = true,
morecomment=[l]{//},
morecomment=[n]{/*}{*/},
morestring=[b]",
morestring=[b]'
}
\lstloadlanguages{C, C++, Java, Lisp, Haskell, Python, Bourbaki}
\lstset{
basicstyle = \footnotesize\ttfamily,
commentstyle = \normalsize\rmfamily,
texcl = true,
showstringspaces = false,
upquote = true,
flexiblecolumns = false
}
\lstnewenvironment{Haskell}[1][]
{\lstset{
language = Haskell,
style=Haskell,
#1}}{}
\lstnewenvironment{Bourbaki}[1][]
{\lstset{
language = Bourbaki,
#1}}{}
\newcommand{\inlineHaskell}{\lstinline[style=Haskell]}
\newcommand{\arrowto}[2][]{\xlongrightarrow[#1]{\displaystyle #2}}
\newcommand{\lbb}{\llparenthesis} % left banana bracket
\newcommand{\rbb}{\rrparenthesis} % right banana bracket
\newcommand{\nil}{\varnothing} % short for \varnothing
\newcommand{\lbparen}{%
\mathopen{%
\sbox0{$()$}%
\setlength{\unitlength}{\dimexpr\ht0+\dp0}%
\raisebox{-\dp0}{%
\begin{picture}(.32,1)
\linethickness{\fontdimen8\textfont3}
\roundcap
\put(0,0){\raisebox{\depth}{$($}}
\polyline(0.32,0)(0,0)(0,1)(0.32,1)
\end{picture}%
}%
}%
}
\newcommand{\rbparen}{%
\mathclose{%
\sbox0{$()$}%
\setlength{\unitlength}{\dimexpr\ht0+\dp0}%
\raisebox{-\dp0}{%
\begin{picture}(.32,1)
\linethickness{\fontdimen8\textfont3}
\roundcap
\put(-0.08,0){\raisebox{\depth}{$)$}}
\polyline(0,0)(0.32,0)(0.32,1)(0,1)
\end{picture}%
}%
}%
}
\newcommand{\llb}{\lbparen} % left lens bracket
\newcommand{\rlb}{\rbparen} % right lens bracket
% =================================================================
\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
%
% mathematics
%
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
% numbered equation array
\newcommand{\bea}[1]{\begin{equation} \begin{array}{#1}}
\newcommand{\eea}{\end{array} \end{equation}}
% equation array not numbered
\WithSuffix\newcommand{\bea}*[1]{\[ \begin{array}{#1}}
\WithSuffix\newcommand{\eea}*{\end{array} \]}
% left aligned equations (but not right/left aligned for odd/even col)
\newenvironment{laligned}{
\begin{array}{l@{\hspace{0.5\arraycolsep}}ll@{\hspace{0.5\arraycolsep}}l}
}{\end{array}}
\newenvironment{lalign}{\begin{equation}\begin{laligned}}{\end{laligned}\end{equation}}
\newenvironment{lalign*}{\[ \begin{laligned}}{\end{laligned} \]}
% single eq-number for aligned equations
\newenvironment{salign}{\begin{equation}\begin{aligned}}{\end{aligned}\end{equation}}
% begin/end reasoning
\newcommand{\bre}{\[ \begin{array}{rcll}}
\newcommand{\ere}{\end{array} \]}
% begin/end long reasoning
\newcommand{\blre}{\[ \begin{array}{cll}}
\newcommand{\elre}{\end{array} \]}
% common functions
\DeclareMathOperator{\gcm}{gcm}
\DeclareMathOperator{\fold}{fold}
\newcommand{\foldn}{\textit{foldn}}
\newcommand{\foldr}{\textit{foldr}}
\newcommand{\btab}[1]{\vspace{5mm} \begin{center} \begin{tabular}{#1}}
\newcommand{\etab}{\end{tabular} \end{center} \vspace{5mm}}
\makeatletter
\newcommand{\verbatimfont}[1]{\renewcommand{\verbatim@font}{\ttfamily#1}}
\makeatother
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}
\renewcommand{\thesubsubsection}{} % \arabic{subsubsection}, \Alph{subsubsection}, {}
\setlength{\cftsubsubsecindent}{30pt} % indent for \subsubsection
\renewcommand{\theQuestion}{\theExercise.\arabic{Question}} % for question reference
\renewcommand{\QuestionNB}{\theExercise.\arabic{Question}.\ } % for question presentation
\crefname{Exercise}{Exercise}{Exercises}
\crefalias{Question}{Exercise}
% For Chinese Language support
\DeclareOption{cn}{
% detect and select Chinese font
% ------------------------------
% fc-list :lang=zh % list all Chinese fonts
% fc-list :mono % list all mono fonts
% fc-cache % refresh cache to load new installed fonts
\IfFontExistsTF{Noto Serif CJK SC}{ % prefer Noto CJK for all platforms
\message{Apply CN font: Noto CJK}
\setCJKmainfont{Noto Serif CJK SC} % Noto Serif CJK SC (思源宋体)
\setCJKsansfont{Noto Sans CJK SC} % Noto Sans CJK SC(思源黑体)
\setCJKmonofont{Noto Sans Mono CJK SC}
}{ % else
\ifwindows{
\message{Apply CN font for Windows: SimSun, SimHei}
\setCJKmainfont{SimSun} % you can replace with other font, e.g. Microsoft YaHei
\setCJKsansfont{SimHei}
}\else{
% ifplatform need --shell-escape being turned on to detect Mac OS X
\IfFontExistsTF{STSong}{
\message{Apply CN font for Mac OS X: STSong, STHeiti, STFangsong}
%
% Mac OS X specific:
% Some system fonts, e.g. STKaiti were moved to
% /System/Library/AssetsV2/com_apple_MobileAsset_Font7 (or Font6 in Catalina)
% as of Monterey, we need add the path into local TeXLive configuration:
% sudo tlmgr conf texmf OSFONTDIR /System/Library/AssetsV2/com_apple_MobileAsset_Font7
%
\setCJKmainfont[BoldFont=STHeiti, ItalicFont=STKaiti]{STSong} % or DengXian, Ping Fang SC
\setCJKsansfont{STHeiti}
\setCJKmonofont{STFangsong}
}{ % else
\message{Apply CN font: default}
} % end if exits STSong
}\fi % end if windows
} % end if exits noto cjk
%% \XeTeXlinebreaklocale "zh" % to solve the line breaking issue
%% \XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt
% Simplified way to customize Chinese. Or \usepackage[chinese, english]{babel}
% However, it need install the additional texlive-lang-chinese.
\addto\captionsenglish{\renewcommand{\contentsname}{目录}}
\addto\captionsenglish{\renewcommand{\appendixname}{附录}}
\addto\captionsenglish{\renewcommand\bibname{参考文献}}
\addto\captionsenglish{\renewcommand\indexname{索引}}
\addto\captionsenglish{\renewcommand{\figurename}{图}}
\addto\captionsenglish{\renewcommand{\tablename}{表}}
\addto\captionsenglish{\renewcommand{\proofname}{证明}}
\newtheorem{axiom}{公理}[section]
\newtheorem{theorem}{定理}[section]
\newtheorem{lemma}[theorem]{引理}
\newtheorem{proposition}[theorem]{命题}
\newtheorem{corollary}[theorem]{推论}
\newtheorem{definition}{定义}[section]
\newtheorem{example}{例}[section]
\renewcommand\ExerciseName{练习}
\renewcommand\AnswerName{答案}
\renewcommand\AnswerListName{答案}
\crefname{Exercise}{练习}{练习}
\crefname{equation}{式}{式}
\crefname{figure}{图}{图}
\crefname{table}{表}{表}
\crefname{theorem}{定理}{定理}
\crefname{lemma}{引理}{引理}
\crefname{corollary}{推论}{推论}
\crefname{section}{章节}{章节}
\crefname{appendix}{附录}{附录}
\crefname{page}{页}{页}
\AtEndEnvironment{Exercise}{
\par \rightline{\AnswerListName: \labelcpageref{\ExerciseLabel-Answer}页}}
}
\DeclareOption{en}{
\IfFontExistsTF{Noto Serif CJK SC}{
\message{Apply Noto Serif CJK SC for bible}
\babelfont[chinese]{rm}{Noto Serif CJK SC}
}{ % else
\IfFontExistsTF{Noto Serif SC}{
\message{Apply Noto Serif SC for bible}
\babelfont[chinese]{rm}{Noto Serif SC}
}{ % else
\ifwindows{
\message{Apply SimSun for bible}
\babelfont[chinese]{rm}{SimSun}
}\else{
\IfFontExistsTF{STSong}{
\message{Apply STSong for bible}
\babelfont[chinese]{rm}{STSong}
}{ % else
\message{No CN default font}
} % end if exits STSong
}\fi % end if windows
} % end if exits Noto Serif SC
} % end if exits Noto Serif CJK SC
\theoremstyle{plain}
\ifdefined\theorem\else
\newtheorem{theorem}{Theorem}[section]
\fi
\ifdefined\lemma\else
\newtheorem{lemma}[theorem]{Lemma}
\fi
\ifdefined\proposition\else
\newtheorem{proposition}[theorem]{Proposition}
\fi
\ifdefined\corollary\else
\newtheorem{corollary}[theorem]{Corollary}
\fi
\theoremstyle{definition}
\ifdefined\axiom\else
\newtheorem{axiom}{Axiom}[section]
\fi
\ifdefined\definition\else
\newtheorem{definition}{Definition}[section]
\fi
\ifdefined\example\else
\newtheorem{example}{Example}[section]
\fi
\AtEndEnvironment{Exercise}{
\par \rightline{\AnswerListName: \cpageref{\ExerciseLabel-Answer}}}
}
\DeclareOption*{\PackageWarning{prelude}{Unknown ‘\CurrentOption’}}
\ProcessOptions\relax