-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommonSetup2.tex
407 lines (359 loc) · 12.9 KB
/
CommonSetup2.tex
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
% ------------- GENERAL -------------- %
\usepackage[utf8]{inputenc} % allows for online editing
\usepackage{amsfonts} % fonts package
% math, symbols, and theorems packages (esint -> oiint, mathrsfs -> \mathscr{L})
\usepackage{amsmath, amsthm, amssymb, esint, mathrsfs}
\usepackage{mathtools} % Provides \Aboxed{...}, boxed align equations.
\usepackage{enumitem} % Allows for roman numbering of lists
% colour package (colour!num -> colour @ num% opacity)
\usepackage{xcolor}
\usepackage{listings} % nicely formatted code
% -------------- HEADER --------------- %
\usepackage{fancyhdr} % creates header
\pagestyle{fancy}
\fancyhf{}
\lhead{\leftHeader} % left header
\rhead{\rightHeader} % right header
% page number bottom right (instead of default middle)
\rfoot{\thepage}
% ------------ PAGE SIZES ------------ %
% Long side of A4 paper
\defineLength{\aflong}{29.7cm}
% Short side of A4 paper
\defineLength{\afshort}{21cm}
% Long side of A3 paper
\defineLength{\atlong}{42cm}
% Short side of A3 paper
\defineLength{\atshort}{29.7cm}
% Text width can be determined using (pagewidth - 2\totalmargin)
% Set page size with:
% \eject \pdfpagewidth=<width> \pdfpageheight=<height>
% Set a page to a new size (\setpagesize{width}{height})
\newcommand{\setpagesize}[2]{
\eject
% set height and width
\pdfpagewidth = #1 \pdfpageheight = #2
% adjust horizontal and vertical offset w.r.t. a4 portrait basis
\newgeometry{
top = \topMargin,
bottom = \bottomMargin - (#2 - \aflong),
left = \leftMargin,
right = \rightMargin - (#1 - \afshort)
}
% refresh header and footer to suit new page size
\fancyheadoffset[R]{0cm} \fancyfootoffset[R]{0cm}
}
% Sets page to A4 portrait
\newcommand{\setafport}{\setpagesize{\afshort}{\aflong}}
% Sets page to A3 landscape
\newcommand{\setatland}{\setpagesize{\atlong}{\atshort}}
% Sets page to A4 landscape
\newcommand{\setafland}{\setpagesize{\aflong}{\afshort}}
% Sets page to A3 portrait
\newcommand{\setatport}{\setpagesize{\atshort}{\atlong}}
%------------------- LABELS ---------------------%
% Label with a prefix
% \plabel[prefix]{label}
\newcommand{\plabel}[2][]{\label{#1: #2}}
% Label for an equation
% \eqlabel{label}
\newcommand{\eqlabel}[1]{\plabel[eq]{#1}}
%------------------- FIGURES --------------------%
\usepackage{graphicx, float, caption}
% package enabling subfigures
\usepackage{subcaption}
% Insert a centered figure
% \fig[alignment]{scale}{filename}{caption}
% *alignment: H by default for 'exactly in place' - can also be:
% h (approximately in place)
% b (at the bottom)
% t (at the top)
% p (on a page for figures/tables)
% (some others possible if necessary)
% scale: the scale of the inputted image (1 = real size)
% filename: don't include the extension (e.g. use photo instead of photo.png)
% unless multiple files called photo exist with different extensions
% caption: figure caption
%
% auto-labelling labels by the filename, reference with \figref{filename} or
% \reffig{filename} for just the number
\newcommand{\fig}[4][H]{
\begin{figure}[#1]
\centering
\includegraphics[scale=#2]{#3}
\caption{#4 \plabel[fig]{#3}}
\end{figure}
}
% Width-sized figure \figw[alignment]{width}{filename}{caption}
% e.g. \figw{0.9\textwidth}{my_img}{I am scaled to 9/10 of the textwidth}
\newcommand{\figw}[4][H]{
\begin{figure}[#1]
\centering
\includegraphics[width=#2]{#3}
\caption{#4 \plabel[fig]{#3}}
\end{figure}
}
% Insert a centered figure with a frame
% \framefig[alignment]{scale}{filename}{caption}
\newcommand{\framefig}[4][H]{
\begin{figure}[#1]
\centering
\frame{\includegraphics[scale=#2]{#3}}
\caption{#4 \plabel[fig]{#3}}
\end{figure}
}
% Insert multiple subfigures
% \multifig[alignment]{\subfigs}{caption}
%
% auto-labelling labels by the caption, reference with \figref{caption} or
% \reffig{caption} for just the number
\newcommand{\multifig}[3][H]{
\begin{figure}[#1]
\centering
#2
\caption{#3 \plabel[fig]{#3}}
\end{figure}
}
% Insert sub-figures (within a multifig)
% \subfig[img-scale/height/width]{alignment}{fig-width}{filename}{caption}
% alignment: applies to within the figure (normally want t (top))
%
% auto-labelling labels by the filename, reference with \sfigref{filename} or
% \reffig[s]{filename} for just the number
\newcommand{\subfig}[5][width=\textwidth]{
\begin{subfigure}[#2]{#3}
\centering
\includegraphics[#1]{#4}
\caption{#5 \plabel[sfig]{#4}}
\end{subfigure}
}
%--------------------TABLES----------------------%
\usepackage{array} % extended column definitions
% setup
\newcolumntype{^}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{;}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
#1\ignorespaces
}
\newcolumntype{b}{>{\bfseries}} % bold column
\newcolumntype{i}{>{\itshape}} % italicised column
% useful shortcuts
\newcommand{\bfrow}{\rowstyle{\bfseries}}
\newcommand{\itrow}{\rowstyle{\itshape}}
\newcommand{\headingrow}{\hline\bfrow}
\newcommand{\row}{\\ \hline} % end rows with this
% Create a table
% \easytable[alignment]{caption}{columns}{contents}
% *alignment: H by default for 'exactly in place' - can also be:
% h (approximately in place)
% b (at the bottom)
% t (at the top)
% p (on a page for figures/tables)
% (some others possible if necessary)
% caption: table caption
% columns: column distribution, types, and separation
% To allow for full row styling, first column specifier should be preceded
% by ^ and following column specifiers should each be preceded by ;
% e.g. |^c|;c|;p{0.5\linewidth}|
% p{width} = justified, with width as specified
% (requires units (2cm, 5em, 12pt), or relative measure (n\linewidth))
% c = centered, with width auto-scaled
% l = left aligned
% r = right aligned
% | = vertical border line (can be repeated, e.g. |^c||;l;r)
% spaces are ignored
% To style a whole column, precede its alignment specifier with:
% b (bold)
% i (italicised)
% >{style} (styled as specified)
% contents: table contents
% e.g.
% \headingrow Heading 1 & Heading 2 & Heading 3 \row
% Side Heading & Text & Text \row
% To style a single cell, use
% \textbf{text} (bold)
% \textit{text} (italicised)
% \normalfont{text} (ignore column/row styling)
% To style a row, precede it with:
% \boldrow (bold)
% \italicrow (italicised)
% \rowstyle{style} (styled as specified)
\newcommand{\easytable}[4][H]{
\begin{table}[#1]
\footnotesize % sets text size to that of footnotes, within table
\centering % centers table on screen
\caption{#2}
\plabel[tab]{#2}
\begin{tabular}{#3}
#4
\end{tabular}
\end{table}
}
%-------------------COMMENTS---------------------%
% Insert multi-line comments with \comment{<text>}
\newcommand{\comment}[1]{}
% Insert displayed multi-line comments using \dcom{<text>}
\newcommand{\dcom}[1]{\textcolor{red}{\textit{#1}}}
%------------------GENERAL TEXT------------------%
% removes indent at beginning of all paragraph
\setlength\parindent{0pt}
% removes line spacing between list items.
\setlist{noitemsep}
%-------------CODE FORMATTING---------------%
%-------------CODE FORMATTING---------------%
% Matlab
\usepackage[numbered,framed]{matlab-prettifier} % MATLAB nice code
% Python
% Default fixed font does not support bold face
\DeclareFixedFont{\ttb}{T1}{txtt}{bx}{n}{10} % for bold
\DeclareFixedFont{\ttm}{T1}{txtt}{m}{n}{10} % for normal
% Custom colors
\definecolor{deepblue}{rgb}{0,0,0.5}
\definecolor{deepred}{rgb}{0.6,0,0}
\definecolor{deepgreen}{rgb}{0,0.5,0}
\definecolor{lightgrey}{rgb}{0.7,0.7,0.7}
\definecolor{orange}{rgb}{0.9,0.5,0.2}
\definecolor{blue}{rgb}{0,0,0.7}
\definecolor{lightblue}{rgb}{0.24,0.65,1}
\newcounter{codeCounter}
% use as \codeCaption[label]{caption}
% if no label is provided, the caption is used as the label
\newcommand{\codeCaption}[2][]{
\refstepcounter{codeCounter}
\begin{center}
Listing \arabic{codeCounter}: {#2
\ifx&%
\plabel[code]{#2} % optional arg is empty, use caption as label
\else
\plabel[code]{#1} % optional arg available, use it as label
\fi
}
\end{center}
}
\lstdefinestyle{python-IDLE}{
language=Python,
numbers=left,
numberstyle=\color{lightgrey}\small,
numbersep=8pt,
basicstyle=\ttm,
basewidth={.012\textwidth}, % Inter-letter spacing
%otherkeywords={self,cls}, % Custom keywords
keywordstyle=\ttb\color{deepblue}, % Keywords style
emph={__init__,__call__,__eq__,__str__,__repr__,@abstractmethod,
@classmethod,@staticmethod}, % Custom highlighting
emphstyle=\ttb\color{deepred}, % Highlighting style
stringstyle=\color{deepgreen},
commentstyle=\color{deepred},
frame=single,
showstringspaces=false,
breaklines=true
}
\lstdefinestyle{C-MPLAB-X}{
language=C,
numbers=left,
numberstyle=\color{lightgrey}\small,
numbersep=8pt,
basicstyle=\ttm,
basewidth={.0125\textwidth}, % Inter-letter spacing
otherkeywords={uint8_t,uint16_t,int16_t,bool,\#define}, % Custom keywords
keywordstyle=\ttb\color{blue}, % Keywords style
emph={__delay_ms, defined, true, false}, % Custom highlighting
emphstyle=\ttb\color{lightblue}, % Highlighting style
stringstyle=\color{orange},
commentstyle=\color{deepgreen},
frame=single,
showstringspaces=false,
breaklines=true
}
\lstdefinestyle{pseudocode}{
language=Java,
numbers=left,
numberstyle=\color{lightgrey}\small,
numbersep=8pt,
basicstyle=\ttm,
basewidth={.0125\textwidth}, % Inter-letter spacing
keywordstyle=\ttb\color{blue}, % Keywords style
otherkeywords={Algorithm, Input, Output, then, <, >, -, =, +, *, true, false},
emph={O, ops}, % Custom highlighting
emphstyle=\ttb\color{red}, % Highlighting style
stringstyle=\color{orange},
commentstyle=\color{deepgreen},
frame=single,
showstringspaces=false,
breaklines=true
}
\lstset{basicstyle=\ttfamily, basewidth={0.0125\textwidth}}
% \intextCode[options]{caption}{code}
\newcommand{\intextCode}[3][]{
\codeCaption{#2}
\begin{lstlisting}[#1]
#3
\end{lstlisting}
}
% \inputCode[options]{filename}{caption}
\newcommand{\inputCode}[3][]{
\codeCaption[#2]{#3}
\lstinputlisting[#1]{#2}
}
% use as \python[options]{filename}{caption}
\newcommand{\python}[3][]{
\inputCode[style=python-IDLE, #1]{#2}{#3}
}
% use as \matlab[options]{filename}{caption}
\newcommand{\matlab}[3][]{
\inputCode[style=Matlab-editor, #1]{#2}{#3}
}
% use as \C[options]{filename}{caption}
\newcommand{\C}[3][]{
\inputCode[style=C-MPLAB-X, #1]{#2}{#3}
}
%-----------------REFERENCING------------------%
% Just the number
\newcommand{\reftab}[1]{\ref{tab: #1}} % tables
\newcommand{\reffig}[2][]{\ref{#1fig: #2}} % figures/subfigures
\newcommand{\refcode}[1]{\ref{code: #1}} % code/listings
\renewcommand{\eqref}[1]{(\ref{eq: #1})} % equations
% Number + relevant intro
\newcommand{\figref}[1]{Figure \reffig{#1}} % figures
\newcommand{\sfigref}[1]{Figure \reffig[s]{#1})} % subfigures
\newcommand{\tabref}[1]{Table \reftab{#1}} % tables
\newcommand{\coderef}[1]{Listing \refcode{#1}} % code/listings
%--------------MATHS NOTATIONS---------------%
% Insert units with \unit[power]{<unit>} (e.g. \unit[3]{m} -> m^3)
\newcommand{\unit}[2][]{\,\text{#2}^{#1}}
\newcommand{\nsunit}[2][]{\text{#2}^{#1}}
% Insert *10^n with \E{n} (e.g. \E{-5})
\newcommand{\E}[1]{\times 10^{#1}}
\newcommand{\tE}[1]{$\E{#1}$}
% Command for math formatted differentials (use \D var)
\newcommand{\D}{\,\mathrm{d}}
% Command for degrees symbol
\renewcommand{\deg}[1][]{{}^\circ\nsunit{#1}}
% Command for short bolded vector notation
\newcommand{\ve}[1]{\mathbf{#1}}
% Commands for left/right surrounding brackets
\newcommand{\lr}[1]{\left( #1 \right)}
\newcommand{\lrs}[1]{\left[ #1 \right]}
\newcommand{\lra}[1]{\left | #1 \right |}
% Commands for integrals
\newcommand{\eint}[2]{\int #1 \D #2}
\newcommand{\eiint}[3]{\iint #1 \D #2 \D #3}
\newcommand{\dint}[4]{\int_{#1}^{#2} #3 \D #4} % definite integral
\newcommand{\diint}[7]{\dint{#1}{#2}{\dint{#3}{#4}{#5}{#6}}{#7}}
% Command for partial derivatives
\newcommand{\del}[3][]{\dfrac{\partial^{#1} #2}{\partial #3^{#1}}}
% Command for full derivatives (nth order)
\newcommand{\der}[3][]{\dfrac{\D ^{#1} #2}{\D {#3}^{#1}}}
% Command for common redefinitions (brackets included)
\renewcommand{\cos}[2][]{\mathrm{cos}^{#1}\!\lr{#2}} % optional power
\renewcommand{\sin}[2][]{\mathrm{sin}^{#1}\!\lr{#2}} % optional power
\renewcommand{\tan}[2][]{\mathrm{tan}^{#1}\!\lr{#2}} % optional power
\renewcommand{\arccos}[1]{\mathrm{arccos}\!\lr{#1}}
\renewcommand{\arcsin}[1]{\mathrm{arcsin}\!\lr{#1}}
\renewcommand{\arctan}[1]{\mathrm{arctan}\!\lr{#1}}
\renewcommand{\ln}[1]{\mathrm{ln}\!\lr{#1}}
\renewcommand{\log}[2][]{\mathrm{log}_{#1}\!\lr{#2}} % optional base
\renewcommand{\exp}[1]{\mathrm{exp}\!\lr{#1}}
\newcommand{\limit}[2]{\lim\limits_{{#1}\rightarrow{#2}}}
% Command for quadratic formula
\newcommand{\qf}[3]{\dfrac{-(#2)\pm\sqrt{(#2)^2-4\cdot #1 \cdot #3}}{2\cdot #1}}