-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmpscheatsheet.cls
More file actions
235 lines (210 loc) · 6.22 KB
/
mpscheatsheet.cls
File metadata and controls
235 lines (210 loc) · 6.22 KB
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
% MIT License
% Copyright (c) 2020 Marlin Strub, Micha Bosshart
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the "Software"), to deal
% in the Software without restriction, including without limitation the rights
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
% copies of the Software, and to permit persons to whom the Software is
% furnished to do so, subject to the following conditions:
% The above copyright notice and this permission notice shall be included in all
% copies or substantial portions of the Software.
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
% SOFTWARE.
% Authors
% Marlin Strub - mstrub@robots.ox.ac.uk
% Micha Bosshart - bmicha@ethz.ch
\NeedsTeXFormat{LaTeX2e}%
\ProvidesClass{mpscheatsheet}[2020/10/02 LaTeX class for cheatsheets]%
%% Options
\RequirePackage{xcolor}
\RequirePackage{kvoptions-patch}
\RequirePackage{xkeyval}
\RequirePackage{xifthen}
% Columns
\newcommand{\@@colnum}{4}
\define@key{mpscheatsheet.cls}{columns}{
\ifthenelse{#1 < 2 \OR \isempty{#1}}{
\ClassError{mpscheatsheet}{Invalid column number}{Number of columns must be two or more.}
}{
\renewcommand{\@@colnum}{#1}
}
}
% Section colors
\define@key{mpscheatsheet.cls}{sectioncolor}{%
\definecolor{sectioncolor}{RGB}{#1}%
}
% We can't allow the user to pass the 'twocolumn' option to the underlying article class.
\DeclareOptionX{twocolumn}{
\ClassError{mpscheatsheet}{Invalid option 'twocolumn'}{Use 'columns=2' instead.}
}
% Pass any unknown option to underlying article class.
\DeclareOptionX*{\PassOptionsToClass{\CurrentOption}{extarticle}}
% Set default options and process any passed options.
\ExecuteOptionsX{sectioncolor={11, 93, 174}, columns=4}
\ProcessOptionsX\relax
% Load the underlying class.
\LoadClass{extarticle}%
%% Geometry
\RequirePackage[
a4paper,%
landscape,%
left = 0.4cm,%
right = 0.4cm,%
top = 0.2cm,%
bottom = 0.2cm,%
includeheadfoot%
]{geometry}%
%% Whitespace
% Reduce the amount of whitespace.
\setlength{\headheight}{0.1cm}%
\setlength{\headsep}{1.3em}%
\setlength{\footskip}{0.1cm}%
\setlength{\textheight}{19.7cm}%
\setlength{\parindent}{0.0em}%
\setlength{\parskip}{0em}%
\setlength{\topskip}{-2em}%
\setlength{\topsep}{0.4em}%
\setlength{\partopsep}{0.1em}%
\setlength{\tabcolsep}{0.2em}%
\renewcommand{\arraystretch}{1}%
\renewcommand{\arraycolsep}{0.5em}%
% Also reduce the amount of whitespace around enumerations.
\RequirePackage{enumitem}%
\setlist[enumerate]{
itemsep = 0.0em,%
topsep = 0.2em,%
parsep = 0.2em,%
itemindent = 0.1em,%
leftmargin = 1.2em %
}
\setlist[itemize]{
itemsep = 0.0em,%
topsep = 0.2em,%
parsep = 0.2em,%
itemindent = 0.1em,%
leftmargin = 1.2em %
}
%% Header and footer
% Define custom commands for title, author, and email.
\def\@doctitle{}
\long\def\title#1{\def\@doctitle{#1}}
\def\@docauthor{}
\long\def\author#1{\def\@docauthor{#1}}
\def\@docemail{}
\long\def\email#1{\def\@docemail{#1}}
% Date format with month and year.
\usepackage{datetime}
\newdateformat{onlymonthandyear}{\monthname[\THEMONTH] \THEYEAR}
% Set header and footer.
\RequirePackage{fancyhdr}
% Ignore warnings about headheight and footskip being too small,
% they are set automatically by fancyhdr.
\RequirePackage{silence}
\WarningFilter{Fancyhdr}{\headheight}
\WarningFilter{Fancyhdr}{\footskip}
\RequirePackage{lastpage}
\pagestyle{fancy}
\fancyhf{}
\lhead{\textbf{\@doctitle}, \onlymonthandyear\today}
\rhead{\@docauthor{}, \texttt{\@docemail{}}}
\chead{Page \thepage{} of \pageref{LastPage}}
\cfoot{}
%% Columns
\RequirePackage{multicol}%
\AtBeginDocument{%
\begin{multicols*}{\@@colnum}%
}%
\AtEndDocument{%
\end{multicols*}%
}%
%% Section headings
\RequirePackage[framemethod=TikZ]{mdframed}
% Section
\newcommand*{\sect}[1]{%
\begin{mdframed}[%
backgroundcolor = sectioncolor,%
linecolor = none,%
leftmargin = -3pt,%
rightmargin = -3pt,%
skipabove = 0pt,%
skipbelow = 0pt,%
innertopmargin = 0.4em,%
innerbottommargin = 0.4em,%
innerleftmargin = 3pt,%
innerrightmargin = 3pt,%
roundcorner = 1pt%
]%
\color{white}%
\Large\textbf{#1}%
\end{mdframed}%
\vspace{-6pt}%
}%
\renewcommand\section{\@startsection%
{section}% name
{1}% level
{0pt}% indent
{0.4em plus 0.3em minus 0.1em}% beforeskip
{0.2em plus 0.1em minus 0.0em}% afterskip
{\sect}% style
}
% Subsection
\newcommand*{\subsect}[1]{%
\begin{mdframed}[%
backgroundcolor = sectioncolor!40,%
linecolor = none,%
leftmargin = -3pt,%
rightmargin = -3pt,%
skipabove = 0pt,%
skipbelow = 0pt,%
innertopmargin = 0.3em,%
innerbottommargin = 0.3em,%
innerleftmargin = 3pt,%
innerrightmargin = 3pt,%
roundcorner = 1pt%
]%
\color{black}%
\textbf{#1}%
\end{mdframed}%
\vspace{-6pt}%
}%
\renewcommand\subsection{\@startsection%
{subsection}% name
{2}% level
{0pt}% indent
{0.4em plus 0.1em minus 0.0em}% beforeskip
{0.2em plus 0.1em minus 0.0em}% afterskip
{\subsect}% style
}
% Subsubsection
\newcommand*{\subsubsect}[1]{%
\begin{mdframed}[%
backgroundcolor = sectioncolor!20,%
linecolor = none,%
leftmargin = -3pt,%
rightmargin = -3pt,%
skipabove = 0pt,%
skipbelow = 0pt,%
innertopmargin = 0.2em,%
innerbottommargin = 0.2em,%
innerleftmargin = 3pt,%
innerrightmargin = 3pt,%
roundcorner = 1pt%
]%
\color{black}%
\textbf{#1}%
\end{mdframed}%
\vspace{-6pt}
}%
\renewcommand\subsubsection{\@startsection%
{subsubsection}% name
{3}% level
{0pt}% indent
{0.4em plus 0.1em minus 0.0em}% beforeskip
{0.2em plus 0.1em minus 0.0em}% afterskip
{\subsubsect}% style
}