forked from ZiFy/unplugged
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prelude.sty
307 lines (266 loc) · 8.7 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
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{prelude}[2019/06/19 Unplug Prelude LaTeX package]
%
% loading packages
%
\RequirePackage{ifpdf}
\RequirePackage{ifxetex}
\ifpdf
\RequirePackage[pdftex,%
bookmarksnumbered,%
colorlinks,%
linkcolor=blue,%
hyperindex,%
plainpages=false,%
pdfstartview=FitH]{hyperref}
\else\ifxetex
\RequirePackage[bookmarksnumbered,%
colorlinks,%
linkcolor=blue,%
hyperindex,%
plainpages=false,%
pdfstartview=FitH]{hyperref}
\else
\RequirePackage[dvipdfm,%
bookmarksnumbered,%
colorlinks,%
linkcolor=blue,%
hyperindex,%
plainpages=false,%
pdfstartview=FitH]{hyperref}
\fi\fi
%\usepackage{hyperref}
% other packages
%--------------------------------------------------------------------------
\usepackage{graphicx, color}
\usepackage{adjustbox}
\usepackage{wrapfig}
\usepackage{subcaption} % subfig is deprecated
\usepackage{enumerate}
\usepackage{multicol}
\usepackage{pdfpages} % to include pdf
\usepackage[table]{xcolor} % for colored table
\usepackage{hhline}
\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{exercise} % for exercise
\usepackage{stmaryrd} % for banana brackets
\usepackage{pict2e} % for customize lens brackets
\usepackage[normalem]{ulem}
\usepackage{import} % for nested input
\usepackage{standalone}
%
% for programming
%
\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{fontspec}
\usepackage{xunicode}
\usepackage{textcomp}
\usepackage{mdframed}
\usepackage{url}
\usepackage{xeCJK}
\usepackage{sourcecodepro}
\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+}}}
% for literate Haskell code
\lstdefinestyle{Haskell}{
language=Haskell,
flexiblecolumns=false,
numberstyle=\ttfamily\tiny,
emphstyle={\bf},
escapeinside={*'}{'*},
stringstyle=\mdseries\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,
do, else, false, for, if, new, null, return,
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}}{}
\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}{\begin{eqnarray}}
\newcommand{\eea}{\end{eqnarray}}
% equation array not numbered
\newcommand{\bean}{\begin{eqnarray*}}
\newcommand{\eean}{\end{eqnarray*}}
% 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{\btab}{\vspace{5mm} \begin{tabular}}
\newcommand{\etab}{\end{tabular} \vspace{5mm}}
\makeatletter
\newcommand{\verbatimfont}[1]{\renewcommand{\verbatim@font}{\ttfamily#1}}
\makeatother
\setcounter{tocdepth}{4}
%\setcounter{secnumdepth}{4}
%\verbatimfont{\footnotesize}
% 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
\ifmacosx{ % Mac OS X
\message{Apply CN font: STSong, STHeiti, STFangsong}
\setCJKmainfont[BoldFont=STHeiti, ItalicFont=STKaiti]{STSong}
\setCJKsansfont{STHeiti}
\setCJKmonofont{STFangsong}
}\else{
\ifwindows{ % Windows
\message{Apply CN font: SimSun, SimHei}
\setCJKmainfont{SimSun}
\setCJKsansfont{SimHei}
}\else{ % unknown OS
\IfFontExistsTF{Noto Serif CJK SC}{ % prefer Noto to the default font Fandol
\message{Apply CN font: Noto CJK}
\setCJKmainfont{Noto Serif CJK SC} % (思源宋体)
\setCJKsansfont{Noto Sans CJK SC} % (思源黑体)
\setCJKmonofont{Noto Sans Mono CJK SC}
}{
\message{Apply CN font: xeCJK default Fandol}
}
}\fi
}\fi
\xeCJKsetup{PunctStyle=kaiming}
\XeTeXlinebreaklocale "zh" % to solve the line breaking issue
\XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt
\newtheorem{axiom}{公理}[section]
\newtheorem{theorem}{定理}[section]
\newtheorem{lemma}[theorem]{引理}
\newtheorem{proposition}[theorem]{命题}
\newtheorem{corollary}[theorem]{推论}
\newtheorem{definition}{定义}[section]
\newtheorem{example}{例}[section]
% 中文书籍设置
% ====================================
\renewcommand\ExerciseName{练习}
\renewcommand{\sectionautorefname}{节}
}
\DeclareOption{en}{
\newtheorem{axiom}{Axiom}[section]
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}{Definition}[section]
\newtheorem{example}{Example}[section]
}
\DeclareOption*{\PackageWarning{prelude}{Unknown ‘\CurrentOption’}}
\ProcessOptions\relax