-
Notifications
You must be signed in to change notification settings - Fork 3
/
seu-ml-assign.cls
387 lines (363 loc) · 14.3 KB
/
seu-ml-assign.cls
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% %%
%% seu-ml-assign.cls %%
%% %%
%% ================================================== %%
%% %%
%% Version: 1.1 (2022/03/28) %%
%% Author: Teddy van Jerry (Wuqiong Zhao) %%
%% License: MIT LICENSE %%
%% GitHub Repo: https://tvj.one/ml-tex %%
%% Compiler: latex, pdflatex, xelatex, lualatex %%
%% %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{seu-ml-assign}[2022/03/28 SEU Machine Learning Assignment Template]
%% Class and Options
\RequirePackage{xkeyval}
\def\@@ptsize{10pt} % font size
\DeclareOptionX{9pt}{\def\@@ptsize{9pt}}
\DeclareOptionX{10pt}{\def\@@ptsize{10pt}}
\DeclareOptionX{11pt}{\def\@@ptsize{11pt}}
\DeclareOptionX{12pt}{\def\@@ptsize{12pt}}
\def\@@solutionmode{1} % default as the solution mode
\DeclareOptionX{solution}{\def\@@solutionmode{1}} % solution mode
\DeclareOptionX{problem}{\def\@@solutionmode{0}} % problem mode
\def\@twoside{0} % default as oneside
\DeclareOptionX{oneside}{\def\@twoside{0}} % one-side document
\DeclareOptionX{twoside}{\def\@twoside{1}} % two-side document
\def\@@lang@en{en} % English
\def\@@lang@cn{cn} % Chinese
\def\@@lang{\@@lang@en} % default as English (en)
\DeclareOptionX{lang}{\def\@@lang{#1}}
\DeclareOptionX*{\PackageWarning{lang}{`\CurrentOption' ignored}}% For unknown options
\ProcessOptionsX\relax
\LoadClass[a4paper,onecolumn,\@@ptsize]{article}
%% Page Settings
\RequirePackage[inner=2.0cm,outer=2.0cm,top=1.2cm,bottom=3.5cm]{geometry}
\newcommand{\firstfooteradditionalheight}{2em} % additional height for footer on the first page
\hfuzz=.5em % disable false positive of overfull \hbox
%% Default Names
\def\@course@default{Machine Learning}
%% Language Settings
\ifx
\@@lang\@@lang@cn\RequirePackage{ctex}
\def\@course@default{机器学习}
\fi
%% Document Propertities
\global\let\@course\@course@default
\global\let\@assignno\@empty
\global\let\@semester\@empty
\global\let\@studentID\@empty
\global\let\@instructor\@empty
\global\let\@duedate\@empty
\global\let\@author\@empty
\global\let\@mainproblem\@empty
\global\let\@mainproblem\@empty
\newcommand{\course}[1]{\gdef\@course{#1}} % Assignment Number
\newcommand{\assignno}[1]{\gdef\@assignno{#1}} % Assignment Number
\newcommand{\semester}[1]{\gdef\@semester{#1}} % Semester
\newcommand{\studentID}[1]{\gdef\@studentID{#1}} % Student ID
\newcommand{\instructor}[1]{\gdef\@instructor{#1}} % Instructor
\newcommand{\duedate}[1]{\gdef\@duedate{#1}} % Due Date of the Assignment
\newcommand{\mainproblem}[1]{\gdef\@mainproblem{#1}} % The main problem of the assignment
%% Fonts and Colors
\RequirePackage[T1]{fontenc}
\RequirePackage[usenames,dvipsnames,table]{xcolor}
%% TikZ Rule
\RequirePackage{tikz}
\usetikzlibrary{fadings, calc}
\newcommand{\tikzrule}[3][]{\tikz{\fill[#1] (0,0) rectangle (#2,#3);}}
%% Sections Settings
\RequirePackage[explicit]{titlesec} % explained in https://tex.stackexchange.com/a/292307/234654
\RequirePackage{suffix}
% http://mirrors.ctan.org/macros/latex/contrib/titlesec/titlesec.pdf
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\global\let\@problempts\@empty
\newcommand{\problempts}[1]{\gdef\@problempts{#1}} % Points of the Problem
\newcommand{\problemptsprint}{\ifx\@problempts\@empty\else(\@problempts~points)\fi}
\newcommand{\sectionheadname}{Problem} % Name for the Section (default as 'Problem')
% Reference: https://tex.stackexchange.com/a/12269/234654
\newcommand{\boxedsection}[4][blue!20]{{%
\begin{tikzpicture}[inner sep=0pt, inner ysep=0.3ex]
\node[anchor=base west] at (0,0) (counter) {#2};
\path let \p1 = (counter.base east) in node[anchor=base west, text width={\textwidth-\x1-#4}] (content)
at ($(counter.base east)+(#4,0)$) {#3};
\begin{pgfonlayer}{background}
\shade[left color=#1,right color=white] let \p1=(counter.north), \p2=(content.north) in
(0,{max(\y1,\y2)}) rectangle (content.south east);
\end{pgfonlayer}
\end{tikzpicture}
}}
% For numbered section, i.e. \section{}
\titleformat{\section}% <command>
{\Large\bfseries}% <format>
{}% <label>
{0pt}% <sep>
{\boxedsection{\sectionheadname{} \thesection:}{#1}{0.33em}}% <before-code>
[%
\vspace{-2.2\baselineskip}\hfill{\normalfont\small\problemptsprint}%
\problempts{}% clear the problem points
]% <after-code>
% For unnumbered section, i.e. \section*{}
\titleformat{name=\section,numberless}% <command>
{\Large\bfseries}% <format>
{}% <label>
{0pt}% <sep>
{\boxedsection{}{#1}{0em}}% <before-code>
[%
\vspace{-2.2\baselineskip}\hfill{\normalfont\small\problemptsprint}%
\problempts{}% clear the problem points
]% <after-code>
\newcommand{\setproblem}[1]{\ifx#1\@empty\else\setcounter{section}{#1}\fi} % force the number of problem
\newcommand{\setsubproblem}[1]{\ifx#1\@empty\else\setcounter{subsection}{#1}\fi} % force the number of subproblem
\newcommand{\problem}[2][]{\problempts{#1}\section[\thesection~#2]{#2}}%
\WithSuffix\newcommand\problem*[2][]{\problempts{#1}\section*{#2}}%
\newcommand{\solutionname}{Solution}%
\newcommand{\startsolution}[1][print]{%
\setproblem{0}% reset the section counter
\def\startsolutionprintoption{print}
\def\startsolutionprintuseroption{#1}
\ifx\startsolutionprintuseroption\startsolutionprintoption{%
{%
\fontfamily{LinuxLibertineT-OsF}\selectfont% select font as Linux Libertine
\centering\LARGE\scshape%
\vspace{\baselineskip}%
\solutionname{}\\[-0.2em]%
}%
\noindent%
\tikzrule[WildStrawberry, path fading=west]{.5\textwidth}{.2em}%
\tikzrule[WildStrawberry, path fading=east]{.5\textwidth}{.2em}%
}\fi%
}
\titlespacing*{\section}{0em}{2.5\baselineskip}{1\baselineskip}
\titleformat{\subsection}[runin]{\large\bfseries}{(\arabic{subsection})}{0.33em}{#1}
\newcommand{\subproblem}[1]{\subsection[(\arabic{subsection}) #1]{#1}}
\WithSuffix\newcommand\subproblem*[1]{\subsection*{#1}}
\titleformat{\subsubsection}[runin]{\bfseries}{\arabic{subsubsection}.}{0.33em}{#1}
\newcommand{\subsubproblem}[1]{\subsubsection[\arabic{subsubsection}. #1]{#1}}
\WithSuffix\newcommand\subsubproblem*[1]{\subsubsection*{#1}}
%% Maths Settings
\RequirePackage{mathtools}
\RequirePackage{amssymb}
\RequirePackage{amsthm} % proof environment and others
\RequirePackage{bm} % \bm command
\RequirePackage{nicematrix}
\numberwithin{equation}{section}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}{Proposition}[section]
\newtheorem{lemma}{Lemma}[section]
\newtheorem{corollary}{Corollary}[section]
\newcommand{\hintstyle}{\itshape}
\newcommand{\hint}[1]{({\hintstyle Hint: #1})}
\DeclareMathOperator*{\argmin}{\arg\min}
\DeclareMathOperator*{\argmax}{\arg\max}
%% Code Block Settings
\RequirePackage{listings}
\definecolor{dkgreen}{rgb}{0,0.5,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\lstset{
numbers=left,
frame=tb,
aboveskip=3mm,
belowskip=3mm,
showstringspaces=false,
columns=fixed,
framerule=1pt,
rulecolor=\color{gray!35},
backgroundcolor=\color{gray!5},
basicstyle={\ttfamily\small},
numberstyle=\footnotesize\color{gray},
keywordstyle=\bfseries\color{MidnightBlue!95!black},
commentstyle=\color{dkgreen},
stringstyle=\color{mauve},
breaklines=true,
breakatwhitespace=true,
tabsize=2,
extendedchars=false,
postbreak=\mbox{\hspace{-1.4em}\textcolor{purple}{$\hookrightarrow$}\space}
}
%% Captions Settings
\RequirePackage[font=footnotesize,labelfont=bf]{caption}
%% Color Boxes
\RequirePackage[many]{tcolorbox}
\RequirePackage{varwidth}
\newtcolorbox{fancybox}[2][]{enhanced,skin=enhancedlast jigsaw,
attach boxed title to top left={xshift=-4mm,yshift=-0.5mm},
fonttitle=\bfseries\sffamily,varwidth boxed title=0.7\linewidth,
colbacktitle=blue!45!white,colframe=red!50!black,
interior style={top color=blue!10!white,bottom color=red!10!white},
boxed title style={empty,arc=0pt,outer arc=0pt,boxrule=0pt},
underlay boxed title={
\fill[blue!45!white] (title.north west) -- (title.north east)
-- +(\tcboxedtitleheight-1mm,-\tcboxedtitleheight+1mm)
-- ([xshift=4mm,yshift=0.5mm]frame.north east) -- +(0mm,-1mm)
-- (title.south west) -- cycle;
\fill[blue!45!white!50!black] ([yshift=-0.5mm]frame.north west)
-- +(-0.4,0) -- +(0,-0.3) -- cycle;
\fill[blue!45!white!50!black] ([yshift=-0.5mm]frame.north east)
-- +(0,-0.3) -- +(0.4,0) -- cycle; },
title={#2},#1
}
\newtcolorbox{notice}[2][]{enhanced,
colframe=blue!50!black,colback=blue!10!white,colbacktitle=blue!5!yellow!10!white,
fonttitle=\bfseries,coltitle=black,attach boxed title to top center=
{yshift=-0.25mm-\tcboxedtitleheight/2,yshifttext=2mm-\tcboxedtitleheight/2},
boxed title style={boxrule=0.5mm,
frame code={ \path[tcb fill frame] ([xshift=-4mm]frame.west)
-- (frame.north west) -- (frame.north east) -- ([xshift=4mm]frame.east)
-- (frame.south east) -- (frame.south west) -- cycle; },
interior code={ \path[tcb fill interior] ([xshift=-2mm]interior.west)
-- (interior.north west) -- (interior.north east)
-- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west)
-- cycle;} },
title={#2},#1
}
%% Footnote Settings
\RequirePackage[bottom]{footmisc} % glue footnote to bottom
\renewcommand{\footnoterule}{\noindent\tikzrule[SeaGreen, path fading=east]{.4\textwidth}{.1em}}
\renewcommand{\footnotesep}{1em}
%% Header and Footer
\RequirePackage{fancyhdr}
\RequirePackage[colorlinks=true, urlcolor=blue, linkcolor=purple, citecolor=red, hypertexnames=false]{hyperref}
\setlength{\headheight}{52pt}
\setlength{\marginparwidth}{2cm}
\pagestyle{fancy}
\if\@twoside0
\lhead{
\fontfamily{LinuxLibertineT-OsF}\selectfont
\if\@@solutionmode1
\textsc{\@title~\@assignno} -- \@studentID~\@author
\else
\textsc{\@course \@title~\@assignno}
\fi
}
\rhead{\thepage}
\renewcommand\headrule{\vspace{-0.7em}\tikzrule[BrickRed, path fading=east]{.5\textwidth}{0.3mm}}
\else
\fancyhf{}
\renewcommand\headrule{%
\ifodd\thepage
\vspace{-0.7em}\tikzrule[BrickRed, path fading=east]{.5\textwidth}{0.3mm}
\else
\vspace{-0.7em}\hfill\tikzrule[BrickRed, path fading=west]{.5\textwidth}{0.3mm}
\fi
}
\fancyhead[LO]{
\fontfamily{LinuxLibertineT-OsF}\selectfont
\if\@@solutionmode1
\textsc{\@title~\@assignno} -- \@studentID~\@author
\else
\textsc{\@course \@title~\@assignno}
\fi
\renewcommand\headrule{\vspace{-0.7em}\tikzrule[BrickRed, path fading=east]{.5\textwidth}{0.3mm}}
}
\fancyhead[RE]{
\fontfamily{LinuxLibertineT-OsF}\selectfont
\textsc{\@course \@title~\@assignno}
}
\fancyhead[LE,RO]{\thepage}
\fi
\cfoot{}
% header and footer style for the first page
\fancypagestyle{firstpage}{
\renewcommand\headrule{}
\lhead{}
\rhead{}
\cfoot{
\fontfamily{LinuxLibertineT-OsF}\selectfont
\vspace*{-\firstfooteradditionalheight}
\vspace{-1.5em}
\tikzrule[purple, path fading=west]{.5\textwidth}{.15em}%
\tikzrule[purple, path fading=east]{.5\textwidth}{.15em}
\footnotesize\centering
\if\@@solutionmode1
This \MakeLowercase{\@title{}} is due \@duedate{} and the date of submission is \@date.
\else
This \MakeLowercase{\@title{}} is due \textbf{\@duedate{}} and the version of the problem set is \@date.
\fi
% LaTeX template information
\LaTeX{} template for this \MakeLowercase{\@title{}} is \textit{SEU-ML-Assign}
open source at \href{https://tvj.one/ml-tex}{tvj.one/ml-tex} under the MIT License.
E-mail \href{mailto:[email protected]}{[email protected]} for support.
}
}
%% Title Settings
\RequirePackage{tabularx}
\RequirePackage{afterpage}
\newcommand{\pdftitleadditionalname}{Solution}
\makeatletter
\renewcommand\maketitle{
\if\@@solutionmode0
\ifx\@instructor\@empty
\let\@instructor\@author % author is the instructor (if not specified)
\else
\ifx\@author\@empty
\let\@author\@instructor % instructor is the author (if not specified)
\fi
\fi
\fi
\thispagestyle{firstpage}
\fontfamily{LinuxLibertineT-OsF}\selectfont % set font as Linux Libertine
\enlargethispage{-\firstfooteradditionalheight} % make room for the footer
\begin{minipage}{10.5cm}
\centering
{
\fontsize{36}{48}\selectfont
\textcolor{Plum}{\scshape \@course}
}\\[.5em]
{
\if\@@solutionmode1
\@studentID~\@author
\qquad
\fi
\textit{Instructor:~\@instructor}
}
\end{minipage}
\begin{minipage}{5cm}
\vspace{0.7em}
\centering
{
\large
\fontfamily{LinuxBiolinumT-OsF}\selectfont
\textcolor{BrickRed}{\@semester}
}
\LARGE\@title~{\fontfamily{bch}\selectfont\@assignno}
\end{minipage}
\\[.3em]
\tikzrule[cyan, path fading=east]{\textwidth}{.4em}
\ifx\@mainproblem\@empty
\vspace{2mm}
\else
\begin{center}
\vspace{-1\baselineskip}\color{RoyalPurple!50!black}
\LARGE\S~\@mainproblem~\S
\end{center}
\fi
\fontfamily{cmr}\selectfont % Computer Modern
% Set up document meta data
% Note that it should be placed here because
% by now \@author and \@title have been set.
\hypersetup{
pdfauthor={\@author},
pdftitle={%
\@title~\@assignno~
\if\@@solutionmode1
\pdftitleadditionalname{}
\fi
- \@course%
},
pdfsubject={\@course},
pdfkeywords={%
\@course, \@title%
\ifx\@mainproblem\@empty\else%
, \@mainproblem%
\fi%
},
pdfcreator={LaTeX with SEU-ML-Assign class},
pdfproducer={LaTeX}
}
}
\makeatother