summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/seu-ml-assign/seu-ml-assign.cls
blob: eedc7c2f0b5e3090ddd9b68768303191a3bf86dc (plain)
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                    %%
%%                 seu-ml-assign.cls                  %%
%%                                                    %%
%% ================================================== %%
%%                                                    %%
%% Version:     1.0 (2022/03/20)                      %%
%% Author:      Teddy van Jerry (Wuqiong Zhao)        %%
%% License:     MIT LICENSE                           %%
%% GitHub Repo: https://tvj.one/ml-tex                %%
%% Compiler:    pdflatex, xelatex, lualatex           %%
%%                                                    %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{seu-ml-assign}[2022/02/20 SEU Machine Learning Assignment Template]

%% Class and Options
\def\@@ptsize{10pt} % font size
\DeclareOption{9pt}{\def\@@ptsize{9pt}}
\DeclareOption{10pt}{\def\@@ptsize{10pt}}
\DeclareOption{11pt}{\def\@@ptsize{11pt}}
\DeclareOption{12pt}{\def\@@ptsize{12pt}}
\def\@@solutionmode{1} % default as the solution mode
\DeclareOption{solution}{\def\@@solutionmode{1}} % solution mode
\DeclareOption{problem}{\def\@@solutionmode{0}} % problem mode
\ProcessOptions\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

%% Document Propertities
\global\let\@assignno\@empty
\global\let\@semester\@empty
\global\let\@studentID\@empty
\global\let\@instructor\@empty
\global\let\@duedate\@empty
\global\let\@author\@empty
\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

%% Fonts and Colors
\RequirePackage[T1]{fontenc}
\RequirePackage[usenames,dvipsnames]{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
% 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}[3][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-0.33em}] (content)
            at ($(counter.base east)+(0.33em,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}
}}
% \titleformat{<command>}
%     [<shape>]{<format>}{<label>}{<sep>}{<before-code>}[<after-code>]
\titleformat{\section}%   
    {\Large\bfseries}%
    {}%
    {0pt}%
    {\boxedsection{\sectionheadname{} \thesection:}{#1}}%
    [%
        \vspace{-2.1\baselineskip}\hfill{\normalfont\small\problemptsprint}%
        \problempts{}% clear the problem points
    ]%
\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{#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%
            \solutionname{}\\[-0.2em]%
        }%
        \noindent%
        \tikzrule[WildStrawberry, path fading=west]{.5\textwidth}{.2em}% <-- Do not remove this
        \tikzrule[WildStrawberry, path fading=east]{.5\textwidth}{.2em}
    }\fi%
}
\titlespacing*{\section}{0em}{2.5\baselineskip}{1\baselineskip}
\titleformat{\subsection}[runin]{\large\bfseries}{}{0pt}{(\arabic{subsection}) #1}%
\newcommand{\subproblem}[2][]{\subsection[#1]{#2}}
\titleformat{\subsubsection}[runin]{}{}{0pt}{(\arabic{subsubsection}. #1}

%% Maths Settings
\RequirePackage{mathtools}
\RequirePackage{amssymb}
\RequirePackage{amsthm} % proof environment and others
\RequirePackage{bm} % \bm command
\RequirePackage{nicematrix}
\numberwithin{equation}{section}

%% 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{blue},
    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
}

%% Header and Footer
\RequirePackage{fancyhdr}
\RequirePackage[colorlinks=true,urlcolor=blue,linkcolor=purple,citecolor=red]{hyperref}
\setlength{\headheight}{52pt}
\setlength{\marginparwidth}{2cm}
\pagestyle{fancy}
\lhead{
    \fontfamily{LinuxLibertineT-OsF}\selectfont
    \if\@@solutionmode1
        \textsc{\@title~\@assignno} -- \@studentID~\@author
    \else
        \textsc{Machine Learning \@title~\@assignno}
    \fi
}

\rhead{\thepage}
\renewcommand\headrule{\vspace{-0.7em}\tikzrule[BrickRed, path fading=east]{.5\textwidth}{0.3mm}}
\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}% <-- Do not remove this
        \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:me@tvj.one}{me@tvj.one} 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 Machine Learning}
        }\\[.5em]
        {
            \if\@@solutionmode1
                \@studentID~\@author
                \qquad
            \fi
            \textit{Instructor:~\@instructor}
        }
    \end{minipage}
    \begin{minipage}{5cm}
        \vspace{0.7em}
        \centering
        {
            \large
            \textcolor{BrickRed}{\sffamily \@semester}
            \vspace{2mm}
        }
        \LARGE\@title~{\fontfamily{bch}\selectfont\@assignno}
    \end{minipage}
    \\[.3em]
    \tikzrule[cyan, path fading=east]{\textwidth}{.4em}
    \vspace{2mm}

    \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
            - Machine Learning
        },
        pdfsubject={Machine Learning},
        pdfkeywords={Machine Learning, \@title},
        pdfcreator={LaTeX with SEU-ML-Assign class},
        pdfproducer={LaTeX}
    }
}
\makeatother