-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathting.sty
461 lines (410 loc) · 15.4 KB
/
ting.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
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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
\ProvidesPackage{ting}[2020/07/05 Tetris is not a game]
\RequirePackage{lmodern}
\RequirePackage{tikz}
\RequirePackage{calc}
\usetikzlibrary{arrows,
backgrounds,
calc,
decorations,
decorations.pathmorphing,
fit,
intersections,
positioning,
shapes.geometric,
shapes.misc}
\definecolor{tetris_blue}{RGB}{140,175,216}
\definecolor{tetris_yellow}{RGB}{255,217,89}
\definecolor{tetris_red}{RGB}{255,77,77}
\definecolor{tetris_gray}{RGB}{190,190,190}
\definecolor{tetris_green}{RGB}{190,255,0}
\definecolor{tetris_orange}{RGB}{255,165,100}
\definecolor{tetris_light_blue}{RGB}{84,254,253}
\definecolor{tetris_light_green}{RGB}{157,221,88}
\definecolor{tetris_light_yellow}{RGB}{241,253,178}
\definecolor{tetris_mci_blue}{RGB}{113,169,251}
\definecolor{tetris_mci_light_blue}{RGB}{220,230,242}
\definecolor{tetris_purple}{RGB}{204,153,255}
\definecolor{tetris_dark_green}{RGB}{0,176,80}
\definecolor{tetris_itmc_yellow}{RGB}{245,250,85}
\definecolor{tetris_light_red}{RGB}{255,228,253}
\newcommand{\pale}[1]{#1!50!white}
\newlength{\boxwidth}
\newlength{\legendsep}
\newlength{\modulepadding}
\newlength{\semlabelsep}
\newlength{\semsep}
\newlength{\tetrissep}
% Height of the gray boxes in the background of a module and width of a module with 3 CP
\setlength{\boxwidth}{21.5mm}
% Padding of the filling of a module in front of the gray boxes
\setlength{\modulepadding}{1mm}
% Distance between the label of a semester and the semester's modules
\setlength{\semlabelsep}{5mm}
% Distance between to semesters
\setlength{\semsep}{2mm}
% Distance between two tetrises
\setlength{\tetrissep}{12mm}
% Distance between the entries of the legend
\setlength{\legendsep}{5mm}
\newcounter{semesterct}
\setcounter{semesterct}{0}
\newcounter{modulect}
\setcounter{modulect}{0}
\newcounter{tetrisct}
\setcounter{tetrisct}{0}
\newcounter{legendct}
\setcounter{legendct}{0}
\newcounter{modulectoffset}
\setcounter{modulectoffset}{0}
\tikzset{
tetrisnode/.style={
inner sep=0mm,
outer sep=0mm
}
}
% Saved nodes of the last credit box, module filling, etc...
\newcommand{\lastcreditbox}{\relax}
\newcommand{\lastmodulefilling}{\relax}
\newcommand{\lastmodule}{\relax}
\newcommand{\lastintegrated}{\relax}
\makeatletter
% Creates a new legend if necessary and adds an item to it
% #1: Filling of the item
% #2: Label of the item
\newcommand{\legend}[2]{%
\renewcommand{\familydefault}{\sfdefault}
\stepcounter{legendct}%
\ifnum\value{legendct}=1%
\node[draw,black,fill=#1,label={[label distance=1mm]0:\sffamily#2}]%
at ($(sem_\the\value{semesterct}.south west)!1/2!(sem_\the\value{semesterct}.south east)+(0,-1\tetrissep)$)%
(legend_\the\value{legendct}) {};%
\else%
\node[draw,black,fill=#1,label={[label distance=1mm]0:\sffamily#2}]%
at ($(legend_\the\numexpr\value{legendct}-1\relax)+(0,-1\legendsep)$)%
(legend_\the\value{legendct}) {};%
\fi%
}
\newcommand{\insidetetris}{\false}
\newcommand{\insidetetristrue}{\true}
% Creates a tetris environment
% #1: Name of the bounding box of the tetris
\newenvironment{tetris}[1][]{%
\begingroup%
\renewcommand{\insidetetris}{\true}%
\ifx&%
\begin{scope}%
\else%
\begin{scope}[local bounding box=#1]%
\fi%
\stepcounter{tetrisct}%
\ifnum\value{tetrisct}>1%
\stepcounter{semesterct}%
\node [fit={($(sem_\the\numexpr\value{semesterct}-1\relax.south west)+(0mm,-\tetrissep)$)%
($(sem_\the\numexpr\value{semesterct}-1\relax.south east)+(0mm,-\tetrissep)$)},tetrisnode]%
(sem_\the\value{semesterct}) {};%
\fi%
}{%
\end{scope}%
\endgroup%
\setcounter{legendct}{0}
\renewcommand{\insidetetris}{\false}%
}
% Creates a single gray box for the background of a module
% #1: Name of the node to put the box at (north west anchor).
% #2: Prefix of the nodes of the box: #2_NW, #2_SE, #2_SW, #2_NE, #2_W
% (where NW is the north west anchor, ...).
% #3: Width of the box in CP (for 1 and 2 a partition of a square is drawn).
\newcommand{\@creditbox}[3]{%
\ifx\insidetetris\insidetetristrue\relax%
\node [fit={(#1.north east)($(#1.south east)+(#3/3*\boxwidth,0mm)$)},
inner sep=0mm,draw=lightgray,line width=1.5pt,tetrisnode] (#2) {};%
\renewcommand{\lastcreditbox}{#2};%
\else%
\PackageError{mypackage}{Not inside tetris environment}{This macro must be called from a tetris environment}%
\fi%
}
% Draws the number of boxes that are needed for a certain amount of CP
% #1: Name of the node to put the first box at (north west anchor).
% #2: Prefix of the group of boxes (where #2_0 is the first box, ...)
% #3: Number of CP (if not divisible by 3, the last box will be cut)
\newcommand{\@creditboxes}[3]{%
\pgfmathparse{int(ceil(#3))}%
\edef\integercp{\pgfmathresult}%
\ifnum\integercp > 3%
\@creditbox{#1}{#2_0}{3};%
\pgfmathparse{int(int((\integercp+2)/3)-1)}%
\edef\numcpboxes{\pgfmathresult}%
\pgfmathparse{int(\numcpboxes-1)}%
\edef\almostnumcpboxes{\pgfmathresult}%
\ifnum\integercp > 6%
\foreach \i in {1,...,\almostnumcpboxes} {%
\@creditbox{#2_\the\numexpr\i-1\relax}%
{#2_\the\numexpr\i\relax}%
{3};%
}%
\fi%
\pgfmathparse{#3-((int((#3+2.5)/3)-1)*3)}%
\edef\lastboxwidth{\pgfmathresult}%
\@creditbox{#2_\almostnumcpboxes}%
{#2_\numcpboxes}%
{\lastboxwidth};%
\else%
\@creditbox{#1}{#2_0}{#3};%
\fi%
}
% Draws a label
% #1: Text
% #2: Width of the text
\newcommand{\@label}[2]{
\renewcommand{\familydefault}{\sfdefault}%
\shortstack{%
\begin{minipage}{#2}%
\begin{center}%
\renewcommand{\familydefault}{\sfdefault}%
\sffamily%
#1%
\end{center}%
\end{minipage}%
}%
}
% Draws the label of a module
% #1: Text (name of the module)
% #2: Number of CP
\newcommand{\@modulelabel}[2]{%
\@label{#1}{\dimexpr#2\boxwidth/3\relax}%
}
% Creates the filling in the foreground of a module with text
% #1: Prefix of the north west anchor of the filling
% #2: Prefix of the south west anchor of the filling
% #3: Color of the filling
% #4: Color of the outline
% #5: Color of the text
% #6: Text (name of the module)
% #7: Number of CP
\newcommand{\@modulefilling}[7]{%
\ifx\insidetetris\insidetetristrue\relax%
\node[fit={($(#1.north west)+(\modulepadding,-\modulepadding)$)($(#2.south east)+(-\modulepadding,\modulepadding)$)},%
inner sep=0mm,draw=none,tetrisnode] (#1_filling) {};%
\renewcommand{\lastmodulefilling}{#1_filling};%
\draw[#4,fill=#3,fill opacity=0.96,line width=1pt]%
(#1_filling.north west)%
rectangle%
(#1_filling.south east)%
node[pos=.5,#5] {\@modulelabel{#6}{#7}};%
\else%
\PackageError{mypackage}{Not inside tetris environment}{This macro must be called from a tetris environment}%
\fi%
}
% Creates the filling in the foreground of a module with text and a vertical
% color gradient
% #1: Prefix of the north west anchor of the filling
% #2: Prefix of the south west anchor of the filling
% #3: 1st Color of the filling
% #4: 2nd Color of the filling
% #5: Color of the outline
% #6: Color of the text
% #7: Text (name of the module)
% #8: Number of CP
\newcommand{\@modulefillingshade}[8]{%
\ifx\insidetetris\insidetetristrue\relax%
\shadedraw[top color=#3,bottom color=#4, draw=#5, line width=1pt]%
($(#1.north west)+(\modulepadding,-\modulepadding)$)%
rectangle%
($(#2.south east)+(-\modulepadding,\modulepadding)$)%
node[pos=.5,#6] {\@modulelabel{#7}{#8}};%
\else%
\PackageError{mypackage}{Not inside tetris environment}{This macro must be called from a tetris environment}%
\fi%
}
% Draws a module
% #1: Name of the node to put the module at (north west anchor).
% #2: Prefix of the group of boxes (where #2_0 is the first box, ...)
% #3: Number of CP (if not divisible by 3, the last box will be cut)
% #4: Color of the filling
% #5: Color of the outline
% #6: Color of the text
% #7: Text (name of the module)
\newcommand{\@module}[7]{%
\@creditboxes{#1}{#2}{#3}%
\pgfmathparse{int(int(((int(ceil(#3))+2)/3))-1)}%
\edef\numcpboxes{\pgfmathresult}%
\@modulefilling{#2_0}{#2_\numcpboxes}{#4}{#5}{#6}{#7}{#3}%
\node [fit={(#2_0.north west)(#2_\numcpboxes.south east)},inner sep=0mm,draw=none,tetrisnode] (#2) {};%
\renewcommand{\lastmodule}{#2};%
}
% Draws a module with a vertical color gradient
% #1: Name of the node to put the module at (north west anchor).
% #2: Prefix of the group of boxes (where #2_0 is the first box, ...)
% #3: Number of CP (if not divisible by 3, the last box will be cut)
% #4: 1st Color of the filling
% #5: 2nd Color of the filling
% #6: Color of the outline
% #7: Color of the text
% #8: Text (name of the module)
\newcommand{\@moduleshade}[8]{%
\@creditboxes{#1}{#2}{#3}%
\pgfmathparse{int(int(((int(ceil(#3))+2)/3))-1)}%
\edef\numcpboxes{\pgfmathresult}%
\@modulefillingshade{#2_0}{#2_\numcpboxes}{#4}{#5}{#6}{#7}{#8}{#3}%
\node [fit={(#2_0.north west)(#2_\numcpboxes.south east)},inner sep=0mm,draw=none,tetrisnode] (#2) {};%
\renewcommand{\lastmodule}{#2};%
}
% Draws an integrated module part (like a seminar)
% #1: Name of the node to put the module part at (north west anchor).
% #2: Number of CP (is rounded to the next number divisible by 3)
% #3: Offset of the part in CP (is rounded to the previous number divisible by 3)
% #4: Text of the module part
\newcommand{\@integrated}[4]{%
\ifx\insidetetris\insidetetristrue\relax%
\pgfmathparse{int(#3/3)}%
\edef\numcpoffset{\pgfmathresult}%
\pgfmathparse{int(int(((int(ceil(#2))+2)/3))-1+\numcpoffset)}%
\edef\numcpboxes{\pgfmathresult}%
\node[fit={($(#1_\numcpoffset.north west)+(2\modulepadding,-2\modulepadding)$)($(#1_\numcpboxes.south east)+(-2\modulepadding,2\modulepadding)$)},
inner sep=0mm,draw=none,tetrisnode] (#1_integrated) {};%
\renewcommand{\lastintegrated}{#1_integrated};%
\draw[line width=1pt,dashed,black]%
(#1_integrated.north west)%
rectangle%
(#1_integrated.south east)%
node[pos=.5,black] {\@modulelabel{#4}{#2}};%
\else%
\PackageError{mypackage}{Not inside tetris environment}{This macro must be called from a tetris environment}%
\fi%
}
% Draws the label of a semester
% #1: Text of the semester
\newcommand{\@semesterlabel}[1]{
\@label{#1}{\widthof{\shortstack{#1}}}%
}
% Begins a semester
% #1: Name of the node to put the semester below (north west anchor)
% (if empty, {0,0} will be used)
% #2: Prefix of the semester
% #3: Text of the semester
\newcommand{\@semester}[3]{%
\ifx\insidetetris\insidetetristrue\relax%
\ifx&%
\node [fit={(0,0)($(0,0)+(4/3*\boxwidth,-\boxwidth)$)},tetrisnode] (#2) {};
\else%
\node [fit={($(#1.south west)+(0,-\semsep)$)($(#1.south east)+(0,-\semsep-\boxwidth)$)},tetrisnode] (#2) {};
\fi%
\node [left=\semlabelsep of #2.east, anchor=east,tetrisnode] {\@semesterlabel{#3}};%
\else%
\PackageError{mypackage}{Not inside tetris environment}{This macro must be called from a tetris environment}%
\fi%
}
% Draws a new semester with name
% #1: Text (name) of the semester
\newcommand{\drawsemester}[1]{%
\setcounter{modulect}{0}%
\stepcounter{semesterct}%
\ifnum\value{semesterct}=1%
\@semester{}{sem_1}{#1}%
\else%
\@semester{sem_\the\numexpr\value{semesterct}-1\relax}{sem_\the\value{semesterct}}{#1}%
\fi%
\node [fit={(sem_\the\value{semesterct}.north east)(sem_\the\value{semesterct}.south east)},tetrisnode] (sem_\the\value{semesterct}_mod_0) {};%
}
% Draws a new module in the current semester started with \drawsemester
% #1: Number of CP (if not divisible by 3, the last box will be cut)
% #2: Color of the filling
% #3: Color of the outline
% #4: Color of the text
% #5: Text (name of the module)
\newcommand{\drawmodule}[5]{%
\stepcounter{modulect}%
\@module{sem_\the\value{semesterct}_mod_\the\numexpr\value{modulect}-1\relax}%
{sem_\the\value{semesterct}_mod_\the\value{modulect}}%
{#1}{#2}{#3}{#4}{#5}%
}
% Draws a new shaded module in the current semester started with \drawsemester
% #1: Number of CP (if not divisible by 3, the last box will be cut)
% #2: 1st Color of the filling
% #3: 2nd Color of the filling
% #4: Color of the outline
% #5: Color of the text
% #6: Text (name of the module)
\newcommand{\drawmoduleshade}[6]{%
\stepcounter{modulect}%
\@moduleshade{sem_\the\value{semesterct}_mod_\the\numexpr\value{modulect}-1\relax}%
{sem_\the\value{semesterct}_mod_\the\value{modulect}}%
{#1}{#2}{#3}{#4}{#5}{#6}%
}
% Draws a new unfinished module in the current semester started with \drawsemester
% #1: Number of CP (if not divisible by 3, the last box will be cut)
% #2: Color of the filling
% #3: Color of the outline
% #4: Color of the text
% #5: Text (name of the module)
\newcommand{\drawmoduleincomplete}[5]{%
\drawmodule{#1}{\pale{#2}}{#3}{\pale{#4}}{#5}%
}
\def\currentmodulecp{0}
% Draws a new dummy module in the current semester: Only the gray boxes,
% but no filling or text. This is needed for \drawmodulemulti
% #1: Number of CP
\newcommand{\drawdummy}[1]{%
\def\currentmodulecp{#1}
\drawmodule{#1}{none}{transparent}{transparent}{}%
}
% Sets the modulemulti offset to the given value
% #1: The value to set the offset to
\newcommand{\setmodulemultioffset}[1]{%
\setcounter{modulectoffset}{#1}%
}
% Draws a new multi-semester module over the boxes created with \drawdummy.
% Will respect the offset set via \setmodulemultioffset for placement of the
% module in the first semester it takes place in
% #1: Number of semesters this module takes place in
% #2: Color of the filling
% #3: Color of the outline
% #4: Color of the text
% #5: Text (name of the module)
\newcommand{\@modulemultinostar}[5]{%
\@modulefilling{sem_\the\numexpr\value{semesterct}+1-#1\relax_mod_\the\numexpr\value{modulect}+\value{modulectoffset}\relax}%
{sem_\the\value{semesterct}_mod_\the\value{modulect}}%
{#2}{#3}{#4}{#5}{\currentmodulecp}%
}
% Draws a new multi-semester module over the boxes created with \drawdummy
% Also allows to manually override the counter of the dummy box of the first
% semester.
% #1: Number of semesters this module takes place in
% #2: Color of the filling
% #3: Color of the outline
% #4: Color of the text
% #5: Text (name of the module)
% #6: Counter of the dummy box in the first semester the module takes place in
\newcommand{\@modulemultistar}[6]{
\@modulefilling{sem_\the\numexpr\value{semesterct}+1-#1\relax_mod_#6}%
{sem_\the\value{semesterct}_mod_\the\value{modulect}}%
{#2}{#3}{#4}{#5}{\currentmodulecp}%
}
% Draws a new multi-semester module over the boxes created with \drawdummy
% Also allows to manually override the counter of the dummy box of the first
% semester if one uses the starred version. Will otherwise respect the offset
% set with \setmodulemultioffset.
% #1: Number of semesters this module takes place in
% #2: Color of the filling
% #3: Color of the outline
% #4: Color of the text
% #5: Text (name of the module)
% #6: If starred version is used:
% Counter of the dummy box in the first semester the module takes place in
\newcommand{\drawmodulemulti}{%
\@ifstar
\@modulemultistar%
\@modulemultinostar%
}
% Draws a new integrated module part into the current module
% #1: Number of semesters the superordinate module takes place in
% #2: Semester that the module part takes place in
% #3: Number of CP
% #4: Offset of the module part inside the module in CP
% #5: Text (name of the module part)
\newcommand{\drawintegrated}[5]{%
\@integrated{sem_\the\numexpr\value{semesterct}+#2-#1\relax_mod_\the\value{modulect}}%
{#3}{#4}{#5}%
}
\makeatother
\endinput