-
Notifications
You must be signed in to change notification settings - Fork 0
/
assign.sty
432 lines (432 loc) · 15.4 KB
/
assign.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
\ProvidesPackage{assign}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%OPTIONS%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%highlight option
\newif\ifassign@highlight
\assign@highlightfalse
\DeclareOption{highlight}{
\assign@highlighttrue
}
%completion boxes option
\newif\ifassign@boxey
\assign@boxeyfalse
\DeclareOption{boxes}{
\assign@boxeytrue
}
%red overdue assignment option
\newif\ifassign@od
\assign@odfalse
\DeclareOption{od}{
\assign@odtrue
}
%process the options
\ProcessOptions\relax
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%DEPENDENCIES%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%need to make calendar
\RequirePackage{termcal}
%turn termcal's \setdate into \termcalsetdate (adapted from savesym package)
\expandafter\let\csname termcalsetdate\expandafter\endcsname\csname setdate\endcsname
%undefine setdate
\expandafter\let\csname setdate\endcsname\relax
%need for date manipulation
\RequirePackage{datenumber}
%need for making function with optional arguments work well
\RequirePackage{xparse}
%need for various programming things
\RequirePackage{etoolbox}
%need for processing lengths
\RequirePackage{calc}
\ifassign@highlight
%need for coloring the highlighting
\RequirePackage{color}
%need for highlighting
\RequirePackage{soul}
\fi
\ifassign@boxey
%need for making squares and checked squares for completion boxes
\RequirePackage{wasysym}
\fi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%VARIABLES%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\newif\ifassign@done
\assign@donefalse
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%COUNTERS%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%INTERNAL%%%%%%%%%%%%%%%%%%%%%
%for subtracting
\newcounter{assign@assignmentdatenum}
%reference, for subtracting
\newcounter{assign@truemonth}
%reference value
\setcounter{assign@truemonth}{\month}
%reference, for subtracting
\newcounter{assign@trueyear}
%reference value
\setcounter{assign@trueyear}{\year}
%accessible through setstablemonth
\newcounter{assign@stablemonth}
%initial value
\setcounter{assign@stablemonth}{\month}
%accessible through setstablemonth
\newcounter{assign@stableyear}
%initial value
\setcounter{assign@stableyear}{\year}
%value to subtract assign@assignmentdatenum against
\newcounter{assign@todaysdatenum}
%actual perpetual value
\setmydatenumber{assign@todaysdatenum}{\theassign@trueyear}{\theassign@truemonth}{\day}%
%%%%%%%%%%%%%EXTERNAL%%%%%%%%%%%%%%%%%%%%%
%number of days between now and an assignment for it to be highlighted
\newcounter{hlthreshold}
%default value
\setcounter{hlthreshold}{1}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%REGISTERS%%%%%%%%%%%%%%%%%%%%
%making token register that will hold the entire item based planner
\newtoks{\assign@ibp}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%FUNCTIONS%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%INTERNAL%%%%%%%%%%%%%%%%%%%%
%internal highlighting command
\newcommand{\assign@high}{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%internal command to reset the datenumber date to the "stable" date
\newcommand{\assign@makedatestabledate}{
\setdate{\theassign@stableyear}{\theassign@stablemonth}{\day}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%internal line divider command
\newcommand{\assign@linedivide}[2]{
\vskip\csname #1skipamount\endcsname
\leaders\vrule width \linewidth\vskip0.4pt
\vskip\csname #2skipamount\endcsname
\nointerlineskip
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\assign@status}{
\ifassign@boxey
\ifassign@done
{\huge\CheckedBox}
\else
{\huge\Square}
\fi
\else
\fi
\assign@donefalse}
\newcommand{\done}{
\assign@addtoplanner{\relax\assign@donetrue}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%repeatedly used date setting function
\DeclareDocumentCommand \assign@adaptivedate { o o o}{
\ifboolexpr{
%Check if there are none of the optional values (month, day, year)
test {\IfNoValueTF{#1}}
and
test {\IfNoValueTF{#2}}
and
test {\IfNoValueTF{#3}}
}
%if so, make a command to do nothing
{\def\assign@internaldate{}}
{
\ifboolexpr{
%Check if there is only one optional value (day)
not test {\IfNoValueTF{#1}}
and
test {\IfNoValueTF{#2}}
and
test {\IfNoValueTF{#3}}
}
%if so, make a command setting the datenumber package date to stable year, stable month, specified day
{\def\assign@internaldate{\setdate{\theassign@stableyear}{\theassign@stablemonth}{#1}}}
{
\ifboolexpr{
%Check if there are two optional values (month, day)
not test {\IfNoValueTF{#1}}
and
not test {\IfNoValueTF{#2}}
and
test {\IfNoValueTF{#3}}
}
%if so, make a command setting the datenumber package date to stable year, specified month, specified day
{\def\assign@internaldate{\setdate{\theassign@stableyear}{#1}{#2}}}
%if not, then all three optional arguments must have been given, make a command setting the datenumber package date to specified year, specified month, specified day
{\def\assign@internaldate{\setdate{#3}{#1}{#2}}}
}
}
%set the date to what it should be
\assign@internaldate
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Quick command for the standard format of expressing a due date
\def\assign@preentrytail{\datedayname,~\datemonthname~{\thedateday},~\thedateyear}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Builder functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%adds tokens to calendar, expanding first token
\newcommand{\assign@addtocalendar}[1]{
\expandafter\caltext\expandafter{\expandafter\thedatemonth\expandafter/\expandafter\thedateday\expandafter/\expandafter\thedateyear\expandafter}\expandafter{#1}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%add a string of tokens #2 to a token register #1
\newcommand\assign@appendtotokenreg[2]{
#1\expandafter{\the#1#2}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%adds tokens to planner, expanding first token
\newcommand{\assign@addtoplanner}[1]{
\expandafter\assign@appendtotokenreg\expandafter{\expandafter\assign@ibp\expandafter}\expandafter{#1}
}
%adds tokens to planner in a parbox without expanding
\newlength\assign@statusspace
\ifassign@boxey
\newcommand{\assign@boxtoplanner}[1]{
\assign@addtoplanner{\relax
\parbox{\linewidth-19pt}{#1}
}
}
\else
\newcommand{\assign@boxtoplanner}[1]{
\assign@addtoplanner{\relax
\parbox{\linewidth}{#1}
}
}
\fi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ifassign@od
\definecolor{overduecolor}{rgb}{.768,.118,.227}
\else
\definecolor{overduecolor}{cmyk}{0,0,1,0}
\fi
\newcommand{\enablehighlighting}[1]{
\sethlcolor{#1}
\ifassign@highlight
%making the \assign@highcommand into a real highlighting command
\renewcommand{\assign@high}[1]{\hl{##1}}
\else
%if no highlight option, make the highlight command into a dummy command that just passes back the argument
\renewcommand{\assign@high}[1]{##1}
\fi
}
\newcommand{\disablehighlighting}{
\renewcommand{\assign@high}[1]{##1}
}
\newcommand{\assign@highlightdefiner }[3]{%
%add the date you know to the register, expanded, but not executed
\assign@addtoplanner{\assign@adaptivedate[#1][#2][#3]}
%set the date to the specified date
\assign@adaptivedate[#1][#2][#3]
%set the assign@assignmentdatenum to the absolute datenum of the given datenumber package date for the assignment date, not the real date, remember that was set at the top of the function
\setmydatenumber{assign@assignmentdatenum}{\thedateyear}{\thedatemonth}{\thedateday}%
%find the difference between the two absolute datenums, or the number of days between
\addtocounter{assign@assignmentdatenum}{-\theassign@todaysdatenum}%
%check if this gap is less than the supplied threshold value or the default, 2
\ifnumcomp{\theassign@assignmentdatenum}{<}{\thehlthreshold+1}
{
\ifnumcomp{\theassign@assignmentdatenum}{<}{0}
{
\assign@addtoplanner{\relax
\enablehighlighting{overduecolor}
}
}
{
\assign@addtoplanner{\relax
\enablehighlighting{yellow}
}
}
}
{
%if not, don't highlight the assignment, description or the due date, add it to token register
\assign@addtoplanner{\relax
\disablehighlighting
}
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%EXTERNAL%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%for archival purposes, allow a planner to evaluate like its a month it isn't.
%syntax: \setstablemonth{month}{year}
\newcommand{\setstablemonth}[2]{
\setcounter{assign@stablemonth}{#1}
\setcounter{assign@stableyear}{#2}
\month=#1
\year=#2
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%command to make a new class (or group) on the planner, and tags for the calendar.
%syntax: \class{title}
\newcommand{\class}[1]{
%add class header to token register
\assign@ibp\expandafter{\the\assign@ibp{
%low priority pagebreak
\pagebreak[1]
%make a page spanning line
\assign@linedivide{big}{med}
%Indented and bolded class title
\noindent\hspace*{15pt} \textbf{\uppercase{#1}}\\[10pt]}}
%Make the current class accessible from other commands
\def\assign@currentclass{#1: }
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%command to unset the currentclass command, to make assignments without classes on calendar
\newcommand{\nullclass}{
\def\assign@currentclass{}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%command to add an assignment. Syntax: \assign{title}{month}{day}{year} or \assign{title}{month}{day} or \assign{title}{day} or \assign{title}
\DeclareDocumentCommand \assign { m o o o}{
%within an evaluation, start with the date, as established either by truth or by \setstablemonth
\assign@makedatestabledate
%every type of entry requires some vertical space
\assign@addtoplanner{\relax\vspace{2pt}}
\ifboolexpr{
%Check if there are none of the optional values (month, day, year)
test {\IfNoValueTF{#2}}
and
test {\IfNoValueTF{#3}}
and
test {\IfNoValueTF{#4}}
}
{
%if so, just put the description and the question mark into the token register, never with highlighting
\assign@addtoplanner{\relax\assign@status}
\assign@boxtoplanner{
{#1}\\
\hspace*{15pt} ?
}
}
{
%for the instances that some optional argument, hence date, has been given, now we'll make the actual formatted entry
\assign@highlightdefiner{#2}{#3}{#4}
\assign@addtoplanner{\relax\assign@status}
\assign@boxtoplanner{
\assign@high{#1}\\
\hspace*{15pt}\assign@high{\mbox{\assign@preentrytail}}
}
%Adding entry to calendar using assign@addtocalendar
\assign@addtocalendar{\assign@currentclass #1\assign@linedivide{small}{small}}
}
\assign@addtoplanner{\relax\\}
%just so no other function is messed up, set the datenumber package date back to the stable date
\assign@makedatestabledate
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%command to make an assignment with an italicized description that isn't printed on the calendar
%syntax: \assign{title}{description}{month}{day}{year} or \assign{title}{description}{month}{day} or \assign{title}{description}{day} or \assign{title}{description}
\DeclareDocumentCommand \dassign { m m o o o}{
%within an evaluation, start with the date, as established either by truth or by \setstablemonth
\assign@makedatestabledate
%every type of entry requires some vertical space
\assign@addtoplanner{\relax\vspace{2pt}}
\ifboolexpr{
%Check if there are none of the optional values (month, day, year)
test {\IfNoValueTF{#3}}
and
test {\IfNoValueTF{#4}}
and
test {\IfNoValueTF{#5}}
}
{
\assign@addtoplanner{\relax\assign@status}
%if so, just put the title, description and the question mark into the token register, never with highlighting
\assign@boxtoplanner{{#1:}\\
\hspace*{15pt}\parbox{\linewidth-15pt}{\emph{#2}}\\
\hspace*{15pt} ?}
}
{
%for the instances that some optional argument, hence date, has been given, now we'll make the actual formatted entry
\assign@highlightdefiner{#3}{#4}{#5}
\assign@addtoplanner{\relax\assign@status}
\assign@boxtoplanner{
\assign@high{#1:}\\
\hspace*{15pt}\parbox{\linewidth-15pt}{\emph{\assign@high{#2}}}\\
\hspace*{15pt}\assign@high{\mbox{\assign@preentrytail}}
}
%Adding entry to calendar using assign@addtocalendar
\assign@addtocalendar{\assign@currentclass #1\assign@linedivide{small}{small}}
}
\assign@addtoplanner{\relax\\}
%just so no other function is messed up, set the datenumber package date back to the stable date
\assign@makedatestabledate
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%command to add an event to calendar, without showing in planner.
%Syntax: \event{title}{month}{day}{year} or \event{title}{month}{day} or \event{title}{day} or \event{title}
\DeclareDocumentCommand \event{ m o o o}{
%within an evaluation, start with the date, as established either by truth or by \setstablemonth
\assign@makedatestabledate
\ifboolexpr{
%Check if there are none of the optional values (month, day, year)
test {\IfNoValueTF{#2}}
and
test {\IfNoValueTF{#3}}
and
test {\IfNoValueTF{#4}}
}
{
%if so, just put the title and the question mark into the token register, never with highlighting
%if not, don't add a description
\assign@addtoplanner{\relax\vspace{2pt}}
\ifassign@boxey
\assign@addtoplanner{\hspace{18pt}}
\fi
\assign@boxtoplanner{{\textbf{#1}}\\
\hspace*{15pt} \textbf{?}}
\assign@addtoplanner{\relax\\}
}
{
%set the date to the specified date
\assign@adaptivedate[#2][#3][#4]
%Adding entry to calendar using assign@addtocalendar
\assign@addtocalendar{\expandafter\textbf\expandafter{\assign@currentclass #1\assign@linedivide{small}{small}}}
}
\assign@donefalse
%just so no other function is messed up, set the datenumber package date back to the stable date
\assign@makedatestabledate
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%DISPLAY%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%command to actually print the item based planner. No arguments
\newcommand\printplanner{\raggedright\the\assign@ibp}
%The Calendar Command Syntax: \printcalendar{startdate mm/dd/yyyy}{no. of weeks}
\newcommand\printcalendar[2]
{
%Make datenumbersetdate off of setdate
\expandafter\global\expandafter\let\csname datenumbersetdate\expandafter\endcsname%
\csname setdate\endcsname
%Make setdate off of termcalsetdate
\expandafter\global\expandafter\let\csname setdate\expandafter\endcsname%
\csname termcalsetdate\endcsname
%start the calendar with the right date and weeks
\begin{calendar}{#1}{#2}
%all the days are important, but not numbered
\calday[Sunday]{\noclassday}
\calday[Monday]{\noclassday}
\calday[Tuesday]{\noclassday}
\calday[Wednesday]{\noclassday}
\calday[Thursday]{\noclassday}
\calday[Friday]{\noclassday}
\calday[Saturday]{\noclassday}
\end{calendar}
%Make calsetdate off of setdate
\expandafter\global\expandafter\let\csname calsetdate\expandafter\endcsname%
\csname setdate\endcsname
%Make setdate off of datenumbersetdate
\expandafter\global\expandafter\let\csname setdate\expandafter\endcsname%
\csname datenumbersetdate\endcsname
}