summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/termcal/termcal.dtx
blob: 753b846fe3aea27ba13ed99287f8e4bdae27a276 (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
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
% ^^A                    -*- latex-*- 
% \iffalse
%<*package>
\def\RCSID$#1 #2 #3 #4 #5${\def\fileversion{#3}\def\filedate{#4}}
\RCSID$Id: termcal.dtx,v 1.8 1997/01/11 17:04:40 mitchell Exp $
\def\docdate{1996/01/10}
%
%</package>
% \fi
% \DoNotIndex{\@tempcnta,\@tempdima\@tempa,\\,\ ,\begin,\begingroup}
% \DoNotIndex{\centering,\csname,\def,\divide,\edef,\else,\end,\endcsname}
% \DoNotIndex{\endhead,\endgroup,\expandafter,\fi,\filedate,\fileversion} 
% \DoNotIndex{\framebox,\global,\hbox,\hfill,\hline,\hsize,\if}
% \DoNotIndex{\ifcase,\ifnum,\ifx,\ignorespaces,\last@,\last@@}
% \DoNotIndex{\let,\long,\multiply,\NeedsTeXFormat,\newcommand}
% \DoNotIndex{\newcounter,\newenvironment,\newif,\newlength}
% \DoNotIndex{\newtoks,\or,\par,\ProvidesPackage,\raggedright}
% \DoNotIndex{\relax,\RequirePackage,\scshape,\setcounter}
% \DoNotIndex{\setlength,\sloppy,\small,\space,\stepcounter,\strut}
% \DoNotIndex{\the,\toks,\value,\vrule,\vspace,\vtop,\whiledo}
% \DoNotIndex{\tabcolsep,\textbf,\textwidth}
% \iffalse
%<*driver> 
\documentclass[12pt]{article}
\usepackage{doc}
\usepackage{termcal}
\CheckSum{384}
\EnableCrossrefs
\CodelineIndex
%\RecordChanges
% \setlength{\parindent}{0pt}
\begin{document}
  \DocInput{termcal.dtx}
  \PrintIndex
\end{document}
%</driver>
%<*package>
% \fi
%
% \newcommand\inp[1]{{\it #1}}
% 
% \MakeShortVerb{\|}
% \title{Termcal.sty---printing a class calendar\thanks{Version:
% \fileversion. Date: \filedate.  Documentation: \docdate}}
% \author{Bill Mitchell}
% \maketitle
% \begin{abstract}
% This package is intended to print a term calendar for use in
% planning a class.  It has a flexible mechanism for
% specifying which days of the week are to be included and for inserting text
% either regularly on the same day each week, or on selected days,  
% or for a series of consecutive
% days.  It also has a flexible mechinism for specifing class and
% nonclass days.  Text may be inserted into consecutive days so that
% it 
% automatically flows around nonclass days.
% \end{abstract}
% \section{Description}  The main command in this package is the
% |calendar| environment\DescribeEnv{calendar}.  Figure~1 shows an 
% example of its use, which might be suitable for a
% Monday-Wednesday-Friday class with a Thursday recitation in a
% mercifully short term.  The \LaTeX\ input to generate it is given
% in figure~2.
% 
% \begin{figure}[!htb]
% \begin{calendar}{9/26/94}{6}
% \setlength{\calboxdepth}{.3in}
% 
% \calday[Monday]{\classday}
% \skipday
% \calday[Tuesday]{\classday}
% \calday[Thursday]{\noclassday}
% \calday[Friday]{\classday}
% \skipday\skipday
% 
% \options{10/31/94}{\noclassday}
% \caltext{10/31/94}{No Class\\Halloween}
% 
% \caltext{10/12/94}{Midterm Exam}
% 
% \caltexton{9}{\S1.2,1.3\\Sorting and disporting}
% \caltextnext{\S1.3,1,4\\Assembling and dissembling}
% \caltextnext{}
% \caltextnext{\S9.9\\Tending and rending}
% \end{calendar}
% \caption{Example of the use of the \texttt{calendar} environment}
% \end{figure}
% \begin{figure}[!htb]
% \begin{verbatim}
% \begin{calendar}{9/26/94}{6}
% \setlength{\calboxdepth}{.3in}
% 
%           % Description of the Week.
% \calday[Monday]{\classday}     % Monday
% \skipday                       % Tuesday  (no class)
% \calday[Tuesday]{\classday}    % Wednesday
% \calday[Thursday]{\noclassday} % Thursday (unnumbered)
% \calday[Friday]{\classday}     % Friday
% \skipday\skipday               % weekend  (no class)
% 
%           % Holidays
% \options{10/31/94}{\noclassday}
% \caltext{10/31/94}{No Class\\Halloween}
% 
%           % Exams
% \caltext{10/12/94}{Midterm Exam}
% 
%           % Text on consecutive days
%                        % the subject of the 9th lecture
% \caltexton{9}{\S1.2,1.3\\Sorting and disporting}
%                        % the subject of the 10th lecture
% \caltextnext{\S1.3,1,4\\Assembling and dissembling}
% \caltextnext{}
%                        % the subject of the 12th lecture
% \caltextnext{\S9.9\\Tending and rending}
% \end{calendar}
% \end{verbatim}
% \caption{\LaTeX\ input for Figure~1}
% \end{figure}
% 
% The two arguments to the |calendar| environment are the starting date,
% in the format |m/d/y|, and the number of weeks to be printed.  The
% contents of the environment describe what is to appear in the
% calendar.  The commands fall into two classes: those which specify
% what is to be printed on a particular day in each week, and those
% which specify what is to be printed on specific days during the term.
% 
% The commands which specify what each week is to look like are
% |\calday| and
% |\skipday|.
% These commands specify the days of the week in order; thus there
% should be seven of them (athough ten may be prefered for a course
% covering the French 
% revolution).
% The macro |\skipday|\DescribeMacro{\skipday}\
%  simply declares that the corresponding day should
% not be printed in the exam; thus the sample calendar has boxes only
% for Monday, Wednesday, Thursday, and Friday.  The macro
% |\calday[|\inp{optional~head}|]{|\inp{option~list}|}|
% \DescribeMacro{\calday}
% is used to specify a day which is to be printed.  The required
% argument \inp{option~list}
% is a (possibly empty) list of \TeX\ commands which are executed
% before the text for that day is printed.
% It can (at least in principal) include 
% any \LaTeX\ command, but several commands, described below, are
% provided  specifically for this purpose.  The optional argument
% is the text of a heading for that day 
% which will at the top
% of each page of the calendar.

% \paragraph{Available options.}
% The macros |\classday| 
% \DescribeMacro{\classday}\DescribeMacro{\noclassday}
% and |\noclassday| declare that the specified day is, or is not, a
% class day.  Days specified as class days are numbered and can be
% refered to by their numbers.
% The command |\weeklytext{|\inp{text}|}| specifies that the
% \DescribeMacro{\weeklytext}
% indicated text should appear every week in the box for that day.
% The \inp{text}
% may include \TeX\ commands;  for example the following could be used
% to number regular Monday quizes:
% \begin{verbatim}
% \weeklytext{\stepcounter{quiznumber} Quiz~\arabic{quiznumber}}
% \end{verbatim}
%
% \paragraph{Options for a specific day}  are specified by the command 
% |\options{|\inp{day}|}{|\inp{option list}|}|.
% \DescribeMacro{\options}
% The \inp{option~list} argument is exactly the same as for |\calday|.  The
% options added by |\options| are executed after those for |\calday|,
% and thus may be used to modify or nullify for a specific day the
% general instructions specified for a particular day of the  week.
%  If there  no quiz is planned for  Halloween then  
% |\options{10/31/94}{\weeklytext{}}| could be used to supress
% printing the usual weekly message.
% 
% There are two ways of specifing the \inp{day} argument of
% |\options|.  First, the date may be specified, in the format
% \texttt{m/d/y}; for example 
% \begin{verbatim}\options{11/11/94}{\noclass}\end{verbatim}
% specifies, that November 11th, Veterans's day, is not a class day. 
% The second method of specifying the date is by its number: 
% \begin{verbatim}\options{C6}{\weeklytext{}}\end{verbatim}
%  would supress the normal text on the
% sixth day of class.  Of course, only days specified as class days
% can be addressed in this style.
% 
% \paragraph{Inserting Text.} There is a similar provision for text to
% be printed on a specific day, 
% using the command |\caltext|. \DescribeMacro{\caltext}  The command 
% \begin{verbatim}\caltext{10/31/94}{Halloween\\No Quiz!} \end{verbatim}
%  will print the indicated
% message on October 31, and 
%  |\caltext{C6}{Hour Exam}|
% ^^A \begin{verbatim}\caltext{C6}{Hour Exam}\end{verbatim} 
%  will  
% print the indicated message on the sixth class day.
% 
% Two extra commands are provided to simplify the job of entering text for
% consecutive class days, as in specifying the lecture topic or
% homework for each day.  The command 
% \DescribeMacro{\caltexton}\DescribeMacro{\caltextnext}
% |\caltexton{|\inp{class day}|}{|\inp{text}|}| specifies a
% starting day and inserts the
% indicated text on that day.  The command
% |\caltextnext{|\inp{text}|}| can  then be used to print text on 
% successive class days.  The command |\caltextnext{}|, with an empty
% argument, may be used to skip days.
% 
% \subsection{Modifying the style of the calendar}
% Several parameters and commands will allow some modfication of the
% style of the entire calendar.  The size of the calendar is specified
% by |\calboxdepth|\DescribeMacro{\calboxdepth}, which specifies the
% minimum height of the box for each day, and
% |\calwidth|\DescribeMacro{\calwidth}\ which specifies the width of the
% calendar. The defaults are 1~inch for |\calboxdepth| and |\textwidth|
% for |\calboxwidth|. 

% The printing of the date and classnumber in each box is done by the
% commands |\calprintdate| and |\calprintclass|.  The default
% definitions of these macros are as follows:
% \begin{macro}{\calprintdate}
%    \begin{macrocode}
\newcommand{\calprintdate}{%
    \ifnewmonth\framebox{\monthname\ \ordinaldate}%
    \else \ordinaldate\fi
  }
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\calprintclass}
%    \begin{macrocode}
\newcommand{\calprintclass}{\textbf{\small\theclassnum}}
%    \end{macrocode}
% \end{macro}
% They may be changed with |\renewcommand|.
%
% By default the calendar will automatically be split over several
% pages.  This can be avoided by putting the entire calendar in a
% |\vbox|. It will normally also be necessary to change |\calboxdepth|
% so that the calendar will fit on one page.
% 
% \StopEventually{}
% \section{The Code}
%    \begin{macrocode}
\ProvidesPackage{termcal}[\filedate\space\fileversion\space 
                          Latex2e package to print a Term calendar]    
\NeedsTeXFormat{LaTeX2e}
%    \end{macrocode} 
% We use the package |longtable| so that the calendar can be split
% over several pages if desired.
%    \begin{macrocode}
\RequirePackage{longtable}
\RequirePackage{ifthen}
%    \end{macrocode}
% Parameters determining the size of the calendar.
% 
%    \begin{macrocode} 
\newlength{\calboxdepth}\setlength\calboxdepth{1in}
\newlength\calwidth\setlength\calwidth{\textwidth}
\newlength{\ca@boxwidth}   %% set by \endcalendar
%    \end{macrocode} 
% The following parameters are used to control the construction of the
% calendar. 
% \begin{macro}{\ca@dpw}  The number of days used in a week.
%    \begin{macrocode}
\newcounter{ca@dpw}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ca@numwks} The number of weeks in the calendar.
%    \begin{macrocode}
\newcounter{ca@numwks} %% weeks in calendar
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ca@wknum}  Used to keep track of the current week.
%    \begin{macrocode}
\newcounter{ca@wknum}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ca@doaweek}  Two token boxes used to build up the
% basic contents of the calendar.  |\ca@doaweek| is built up by
% |\calday|, and prints a typical week.  It will be filled up by the macros
% |\calday| and |\skipday|.
%    \begin{macrocode} 
\newtoks\ca@doaweek
%    \end{macrocode} 
% \end{macro}
% \begin{macro}{\ca@doweeks} This will be essentially |ca@numwks| copys
% of |\ca@doaweek|.
%    \begin{macrocode}
\newtoks\ca@doweeks
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ca@colhead}\begin{macro}{\ifca@chead} The column
% headings which appear at the top of every page is collected in the
% token box |\ca@colhead| by |\calday|.  The switch |\ifca@chead| is
% set to true if any such column heads are specified.
%    \begin{macrocode}  
\newtoks\ca@colhead
\newif\ifca@chead
%    \end{macrocode}
% \end{macro}\end{macro}
% \begin{environment}{calendar} 
% This is the basic environment.  The |\calendar| command only saves the
% parameters and initializes some counters.
%    \begin{macrocode} 
\newenvironment{calendar}[2]%
 {%   
   \setcounter{ca@numwks}{#2}
   \setdate{#1} 
   \setcounter{ca@dpw}{0}
   \setcounter{classnum}{1}
 }
%    \end{macrocode} 
% \begin{macro}{\endcalendar}
% The calendar is actually created in the code for |\endcalendar|.
% It will be printed as a longtable. 
%    \begin{macrocode}  
  {
%    \end{macrocode}
% Since the \texttt{longtable} and
% \texttt{tabular} environments don't work well with loops in their
% body, we will build up the body in a token box, |\ca@doweeks|.
%\begin{macro}{\ca@doweeks}
%    \begin{macrocode}  
   \ifca@chead\ca@doweeks{\the\ca@colhead\endhead\hline\hline}\fi
   \setcounter{ca@wknum}{0}
   \whiledo{\value{ca@wknum}<\value{ca@numwks}}%
            {\stepcounter{ca@wknum}%
             \addtotoks{\ca@doweeks}{\the\ca@doaweek\\\hline}}
%    \end{macrocode} 
% \end{macro}
% Now we calculate the widths of the  boxes, using a formula from the
% Latex Companion.
% \begin{macro}{\ca@boxwidth}
%    \begin{macrocode} 
   \ca@boxwidth=\calwidth
   \divide\ca@boxwidth by \c@ca@dpw\relax
   \advance\ca@boxwidth by -2\tabcolsep\relax
   \setlength\@tempdima\arrayrulewidth\relax
   \multiply\@tempdima\c@ca@dpw\relax
   \advance\@tempdima\arrayrulewidth\relax
   \divide\@tempdima\c@ca@dpw\relax
   \advance\ca@boxwidth by -\@tempdima\relax
%    \end{macrocode} 
% \end{macro}
% Now we use the |longtable| environment to print out the calendar.
%    \begin{macrocode} 
   \begin{longtable}[l]
	   {|*{\theca@dpw}{p{\ca@boxwidth}|}@{}}%
      \hline
      \the\ca@doweeks
    \end{longtable}
   }
%    \end{macrocode}
%  \end{macro}	^^A \endcalendar
% \end{environment} ^^A calendar
% \begin{macro}{\addtotoks} The command 
% |\addtotoks{|\inp{token box}|}{|\inp{new tokens}|}| is used to add
% new tokens at the end of \inp{token box}.
%    \begin{macrocode}
\newcommand\addtotoks[2]{#1\expandafter{\the#1#2}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\calday}  
% \begin{macro}{\ca@doaweek}
% \begin{macro}{\ca@colhead}
% The command |\calday| works by adding
% commands to the token box |\ca@doaweek|, a copy of which is inserted
% into |\ca@doweeks| for each week in the calendar.
% inserted 
% If column headings are specified, then they are put into 
% the  token box |\ca@colhead|.
%    \begin{macrocode} 
\ca@doaweek={\stepcounter{ca@wknum}\ignorespaces}
\newcommand\calday[2][]{\stepcounter{ca@dpw}%
        \ifca@fday\addtotoks\ca@doaweek{&}\addtotoks\ca@colhead{&}\fi
       \addtotoks\ca@doaweek{\ca@doaday{#2}}
        \def\@tempa{#1}\ifx\@tempa\@empty
           \else\addtotoks\ca@colhead{\strut\scshape\centering #1}\ca@cheadtrue\fi
        \ca@fdaytrue
}
%    \end{macrocode}
% \end{macro} 
% \end{macro}
% \end{macro}
% \begin{macro}{\ifca@fday} True if this is not the first day of the week. This determines whether
% |&| needs to be added as a 
% separator. 
%    \begin{macrocode}
\newif\ifca@fday        
%    \end{macrocode}
% \end{macro} 
% \begin{macro}{\skipday} 
% The command |\skipday| simply advances the date without printing
% anything in the calendar.
%    \begin{macrocode}
\newcommand\skipday{\addtotoks\ca@doaweek{\advancedate}}
%    \end{macrocode}
% \end{macro}
% After a couple of preliminaries, we will define the command
% |\ca@doaday| which is
% actually prints out
% the text for each day of the calendar.
% \begin{macro}{c@classnum} This is the counter used to keep track of
% class days.  It is initialized to 1 in the beginning of the
% |calendar| environment.
%    \begin{macrocode}
\newcounter{classnum}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ca@normbs} 
% The meaning of |\\| is changed by the |longtable| environment.
% We save its standard meaning so that it can be used 
% in the text to be printed in the calendar boxes.
%    \begin{macrocode}
\let\ca@normbs=\\
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ca@doaday} 
% The command |\ca@doaday| does the actual printing of the contents of
% the box for each day.
% First the options are read, in the following order:
% options specified in the argument to |\calday|, then options
% specified by date, and finally 
% options specified by  classday.  
%    \begin{macrocode} 
\newcommand\ca@doaday[1]{
   \hbox{\vrule depth \calboxdepth height 0pt width 0pt\vtop{
   #1%                                 %options specified by |\calday|
   \csname\curdate options\endcsname%  % options specified by date
   \ifclassday\csname C\theclassnum options\endcsname\fi  %by classnumber
%    \end{macrocode} 
% Then the heading is printed.
%    \begin{macrocode} 
   \hbox to \hsize{\calprintdate\hfill\ifclassday\calprintclass\fi}
   \vspace{2pt}
%    \end{macrocode} 
% Now we are ready to print the text.   We do it inside a group in which
% the normal meaning of |\\| is restored.
%    \begin{macrocode}
      \begingroup
        \let\\=\ca@normbs
        \raggedright
        \sloppy

        \the\weeklytext\par
        \csname\curdate text\endcsname
        \ifclassday\csname C\theclassnum text\endcsname
                   \stepcounter{classnum}\fi
      \endgroup
   }} 
%    \end{macrocode} Finally we advance the date.  The command
%    |\advancedate| will set |\newmonthtrue| if appropriate.
%    \begin{macrocode} 
    \global\newmonthfalse
    \advancedate
}
%    \end{macrocode}
% \end{macro}
% \subsection{Options}
% The options and text for the individual days are stored in macros,
% with names of the form |\|\inp{date}|options| or
% |\|\inp{date}|text|. 
%
% \begin{macro}{\ca@addmacro} |\ca@addmacro| is like |\ca@addtoks|,
% except it works on macros instead of token boxes.  The first
% argument is the name of a 
% macro (without the backslash) and the second is a sequence of
% tokens to be added to its definition.  The definition is taken from
% the 
% \TeX{}book, exercise 20.15.  Note that the spaces in the last line
% are essential. 
%    \begin{macrocode}
\long\def\ca@addmacro#1#2{
 \expandafter\ifx\csname#1\endcsname\relax%
        \expandafter\def\csname#1\endcsname{#2}
  \else
  \toks0=
     \expandafter\expandafter\expandafter{\csname#1\endcsname}
  \toks2={#2}
  \expandafter
    \edef\csname#1\endcsname{\the\toks0 \the\toks2 }\fi}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\options} |\options#1#2| adds the tokens in the second
% argument to the macro with the name |\csname #1options\endcsname|.
%    \begin{macrocode}
\newcommand\options[1]{\ca@addmacro{#1options}}
%    \end{macrocode}
% \end{macro}
% Now the code for the varions options.
%
% \begin{macro}{\ifclassday}
% \begin{macro}{\classday}\begin{macro}{\noclassday}  
% A switch determines which days are class days.
%    \begin{macrocode}
\newif\ifclassday
\newcommand{\classday}{\classdaytrue}
\newcommand{\noclassday}{\classdayfalse}
%    \end{macrocode}
% \end{macro}\end{macro}\end{macro}
%
% \begin{macro}{\weeklytext} This token box holds the standard text
% for each day of the week.  It is filled and immediately used by
% |\ca@doaday|,
% inside the hbox containing each calendar day.
%    \begin{macrocode}
\newtoks\weeklytext
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\caltext}
% This macro works like |\options| to save the
% text for a specific day, saving the text in a macro  with the name
% |\csname #1text\endcsname|.  We add |\par| after the text, so
% successive texts for the same day start on separate lines.  We use
% |\par| instead of |\\| since it is harmless if it is unneeded (but
% requires that |\ca@addmacro| be long).
%    \begin{macrocode}
\newcommand\caltext[2]{\ca@addmacro{#1text}{#2\par}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\c@textdaycount}\begin{macro}{\caltexton}
% \begin{macro}{\caltextnext}
% The commands |\caltexton| and |\caltextnext| use |\caltext| with the
% day determined by the counter |textdaycount|.
%    \begin{macrocode}
\newcounter{textdaycount}\setcounter{textdaycount}1
\newcommand\caltexton[2]{\setcounter{textdaycount}{#1}
        \caltext{C#1}{#2}}
\newcommand\caltextnext[1]{\advance\c@textdaycount by 1
        \caltext{C\thetextdaycount}{#1}}
%    \end{macrocode}
% \end{macro}\end{macro}\end{macro}
% \subsection{Macros concerned with date calculations}
% Now we have a selection of macros which are concerned with
% calculating the dates in the calendar.
% \begin{macro}{\c@date} Counter for the day of the month.
%    \begin{macrocode}
   \newcounter{date}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\c@month} Counter for  month (January = 1)
%    \begin{macrocode}
   \newcounter{month}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\c@year} Counter for year.
%    \begin{macrocode}
   \newcounter{year}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\curdate}Print out the date.
%    \begin{macrocode}
\newcommand\curdate{\arabic{month}/\arabic{date}/\arabic{year}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\monthname} Print the name of the Month.
%    \begin{macrocode}
\newcommand\monthname{\ifcase\c@month\or Jan\or Feb\or Mar\or Apr%
        \or May\or June\or July\or Aug\or Sep\or Oct%
        \or Nov\or Dec\fi}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\advancedate} Move the  date forward by one day.
%    \begin{macrocode}
\newcommand\advancedate{\stepcounter{date}
    \ifnum\thedate>\monthlength\relax
       \addtocounter{date}{-\monthlength}\advancemonth\fi}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ifnewmonth} True if no days have been printed during
% the current month.
%    \begin{macrocode}
\newif\ifnewmonth\newmonthtrue
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\advancemonth}
%    \begin{macrocode}
\newcommand\advancemonth{%
   \global\newmonthtrue\stepcounter{month}
   \ifnum\c@month>12
      \stepcounter{year}\setleap\setcounter{month}1\fi}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ifleap} True if the year is a leap year.
%    \begin{macrocode}
   \newif\ifleap
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\setleap} Determine whether the  year is a leap
% year. This is valid until 2100, thanks to the 400 year rule.
%    \begin{macrocode}
\newcommand\setleap{%
   \@tempcnta=\c@year
   \divide\@tempcnta by 4 \multiply\@tempcnta by 4
   \ifnum\@tempcnta=\c@year\global\leaptrue
   \else\global\leapfalse\fi}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\monthlength} Determine the number of days in the
% current month.
%    \begin{macrocode}
\newcommand\monthlength{%
   \ifcase\c@month\or31\or\ifleap29\else28\fi
     \or31\or30\or31\or30\or31\or31\or30\or31\or30\or31\fi%
   \relax}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\setdate} Take argument in the form |m/d/y| and set
% the counters |month|, |date| and |year|.
%    \begin{macrocode}
\newcommand\setdate[1]{\setdate@#1!}
\def\setdate@#1/#2/#3!{
       \setcounter{month}{#1}
       \setcounter{date}{#2}
       \setcounter{year}{#3}   
       \global\newmonthtrue\setleap}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ordinaldate} Print the day of the month as an ordinal.
%    \begin{macrocode}
\newcommand\ordinaldate{\ordinal{\c@date}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ordinal} Print the contents of a register as ordinal
% number.
%    \begin{macrocode}
\newcommand\ordinal[1]{%
   \let\last@=\relax\let\last@@=\relax
   \expandafter\@rd\the#1x}
\newcommand\@rd[1]{\ifx#1x\if\last@@1th\else\@rdend{\last@}\fi\else
   \let\last@@=\last@\def\last@{#1}#1\expandafter\@rd\fi}
\newcommand\@rdend[1]{\ifcase#1 th\or st\or nd\or rd\else th\fi}
%    \end{macrocode}
% \end{macro}
% \Finale
%\endinput
%</package>
%
% \iffalse       %% don't print this in documentation.
%<*example>
\begin{calendar}{9/26/94}{6}
\setlength{\calboxdepth}{.3in}  
          %%                            Description of the Week.
\calday[Monday]{\classday}     % Monday 
\skipday                       % Tuesday  (no class)
\calday[Tuesday]{\classday}    % Wednesday 
\calday[Thursday]{\noclassday} % Thursday (unnumbered)
\calday[Friday]{\classday}     % Friday 
\skipday\skipday               % weekend  (no class)
          %%                                            Holidays 
\options{10/31/94}{\noclassday}       
\caltext{10/31/94}{No Class\\Halloween}
          %%                                               Exams 
\caltext{10/12/94}{Midterm Exam}
        %%%%%%% Text on consecutive days 
                       % the subject of the 9th lecture 
\caltexton{9}{\S1.2,1.3\\Sorting and disporting}     
                       % the subject of the 10th lecture 
\caltextnext{\S1.3,1,4\\Assembling and dissembling}
\caltextnext{}
                       % the subject of the 12th lecture 
\caltextnext{\S9.9\\Tending and rending}              
\end{calendar}
%</example>
% \fi
% \endinput
% $Log: termcal.dtx,v $
% Revision 1.8  1997/01/11 17:04:40  mitchell
% Documentation rewritten preprepitory to sending to CTAN
%
% Revision 1.7  1997/01/11 00:56:28  mitchell
% Minor changes to documentation.
%
% Revision 1.6  1995/06/15  14:13:05  mitchell
% Put definition of filedate and fileversion into termcal.sty.
%
% Revision 1.5  1995/06/10  16:43:43  mitchell
% RCS related changes.
%
%
% Revision 1.4  1995/06/10  16:22:20  mitchell
% Initialized counters, to allow for printing several calendars
% in a single file.
% 
% Revision 1.3  1994/08/06  00:57:53  mitchell
% add Identification stuff.
%
% Revision 1.2  1994/08/05  17:22:45  mitchell
% Added column headings as optional argument to \calday.
%
% LocalWords:  chead tempdima fday doaday tempa cheadtrue fdaytrue classnum pt
% LocalWords:  normbs addmacro textdaycount Apr Aug Sep Oct Nov tempcnta rdend