| 1 |
% ^^A -*- latex-*- |
| 2 |
% \iffalse |
| 3 |
%<*package> |
| 4 |
\def\RCSID$#1 #2 #3 #4 #5${\def\fileversion{#3}\def\filedate{#4}} |
| 5 |
\RCSID$Id: termcal.dtx,v 1.8 1997/01/11 17:04:40 mitchell Exp $ |
| 6 |
\def\docdate{1996/01/10} |
| 7 |
% |
| 8 |
%</package> |
| 9 |
% \fi |
| 10 |
% \DoNotIndex{\@tempcnta,\@tempdima\@tempa,\\,\ ,\begin,\begingroup} |
| 11 |
% \DoNotIndex{\centering,\csname,\def,\divide,\edef,\else,\end,\endcsname} |
| 12 |
% \DoNotIndex{\endhead,\endgroup,\expandafter,\fi,\filedate,\fileversion} |
| 13 |
% \DoNotIndex{\framebox,\global,\hbox,\hfill,\hline,\hsize,\if} |
| 14 |
% \DoNotIndex{\ifcase,\ifnum,\ifx,\ignorespaces,\last@,\last@@} |
| 15 |
% \DoNotIndex{\let,\long,\multiply,\NeedsTeXFormat,\newcommand} |
| 16 |
% \DoNotIndex{\newcounter,\newenvironment,\newif,\newlength} |
| 17 |
% \DoNotIndex{\newtoks,\or,\par,\ProvidesPackage,\raggedright} |
| 18 |
% \DoNotIndex{\relax,\RequirePackage,\scshape,\setcounter} |
| 19 |
% \DoNotIndex{\setlength,\sloppy,\small,\space,\stepcounter,\strut} |
| 20 |
% \DoNotIndex{\the,\toks,\value,\vrule,\vspace,\vtop,\whiledo} |
| 21 |
% \DoNotIndex{\tabcolsep,\textbf,\textwidth} |
| 22 |
% \iffalse |
| 23 |
%<*driver> |
| 24 |
\documentclass[12pt]{article} |
| 25 |
\usepackage{doc} |
| 26 |
\usepackage{termcal} |
| 27 |
\CheckSum{384} |
| 28 |
\EnableCrossrefs |
| 29 |
\CodelineIndex |
| 30 |
%\RecordChanges |
| 31 |
% \setlength{\parindent}{0pt} |
| 32 |
\begin{document} |
| 33 |
\DocInput{termcal.dtx} |
| 34 |
\PrintIndex |
| 35 |
\end{document} |
| 36 |
%</driver> |
| 37 |
%<*package> |
| 38 |
% \fi |
| 39 |
% |
| 40 |
% \newcommand\inp[1]{{\it #1}} |
| 41 |
% |
| 42 |
% \MakeShortVerb{\|} |
| 43 |
% \title{Termcal.sty---printing a class calendar\thanks{Version: |
| 44 |
% \fileversion. Date: \filedate. Documentation: \docdate}} |
| 45 |
% \author{Bill Mitchell} |
| 46 |
% \maketitle |
| 47 |
% \begin{abstract} |
| 48 |
% This package is intended to print a term calendar for use in |
| 49 |
% planning a class. It has a flexible mechanism for |
| 50 |
% specifying which days of the week are to be included and for inserting text |
| 51 |
% either regularly on the same day each week, or on selected days, |
| 52 |
% or for a series of consecutive |
| 53 |
% days. It also has a flexible mechinism for specifing class and |
| 54 |
% nonclass days. Text may be inserted into consecutive days so that |
| 55 |
% it |
| 56 |
% automatically flows around nonclass days. |
| 57 |
% \end{abstract} |
| 58 |
% \section{Description} The main command in this package is the |
| 59 |
% |calendar| environment\DescribeEnv{calendar}. Figure~1 shows an |
| 60 |
% example of its use, which might be suitable for a |
| 61 |
% Monday-Wednesday-Friday class with a Thursday recitation in a |
| 62 |
% mercifully short term. The \LaTeX\ input to generate it is given |
| 63 |
% in figure~2. |
| 64 |
% |
| 65 |
% \begin{figure}[!htb] |
| 66 |
% \begin{calendar}{9/26/94}{6} |
| 67 |
% \setlength{\calboxdepth}{.3in} |
| 68 |
% |
| 69 |
% \calday[Monday]{\classday} |
| 70 |
% \skipday |
| 71 |
% \calday[Tuesday]{\classday} |
| 72 |
% \calday[Thursday]{\noclassday} |
| 73 |
% \calday[Friday]{\classday} |
| 74 |
% \skipday\skipday |
| 75 |
% |
| 76 |
% \options{10/31/94}{\noclassday} |
| 77 |
% \caltext{10/31/94}{No Class\\Halloween} |
| 78 |
% |
| 79 |
% \caltext{10/12/94}{Midterm Exam} |
| 80 |
% |
| 81 |
% \caltexton{9}{\S1.2,1.3\\Sorting and disporting} |
| 82 |
% \caltextnext{\S1.3,1,4\\Assembling and dissembling} |
| 83 |
% \caltextnext{} |
| 84 |
% \caltextnext{\S9.9\\Tending and rending} |
| 85 |
% \end{calendar} |
| 86 |
% \caption{Example of the use of the \texttt{calendar} environment} |
| 87 |
% \end{figure} |
| 88 |
% \begin{figure}[!htb] |
| 89 |
% \begin{verbatim} |
| 90 |
% \begin{calendar}{9/26/94}{6} |
| 91 |
% \setlength{\calboxdepth}{.3in} |
| 92 |
% |
| 93 |
% % Description of the Week. |
| 94 |
% \calday[Monday]{\classday} % Monday |
| 95 |
% \skipday % Tuesday (no class) |
| 96 |
% \calday[Tuesday]{\classday} % Wednesday |
| 97 |
% \calday[Thursday]{\noclassday} % Thursday (unnumbered) |
| 98 |
% \calday[Friday]{\classday} % Friday |
| 99 |
% \skipday\skipday % weekend (no class) |
| 100 |
% |
| 101 |
% % Holidays |
| 102 |
% \options{10/31/94}{\noclassday} |
| 103 |
% \caltext{10/31/94}{No Class\\Halloween} |
| 104 |
% |
| 105 |
% % Exams |
| 106 |
% \caltext{10/12/94}{Midterm Exam} |
| 107 |
% |
| 108 |
% % Text on consecutive days |
| 109 |
% % the subject of the 9th lecture |
| 110 |
% \caltexton{9}{\S1.2,1.3\\Sorting and disporting} |
| 111 |
% % the subject of the 10th lecture |
| 112 |
% \caltextnext{\S1.3,1,4\\Assembling and dissembling} |
| 113 |
% \caltextnext{} |
| 114 |
% % the subject of the 12th lecture |
| 115 |
% \caltextnext{\S9.9\\Tending and rending} |
| 116 |
% \end{calendar} |
| 117 |
% \end{verbatim} |
| 118 |
% \caption{\LaTeX\ input for Figure~1} |
| 119 |
% \end{figure} |
| 120 |
% |
| 121 |
% The two arguments to the |calendar| environment are the starting date, |
| 122 |
% in the format |m/d/y|, and the number of weeks to be printed. The |
| 123 |
% contents of the environment describe what is to appear in the |
| 124 |
% calendar. The commands fall into two classes: those which specify |
| 125 |
% what is to be printed on a particular day in each week, and those |
| 126 |
% which specify what is to be printed on specific days during the term. |
| 127 |
% |
| 128 |
% The commands which specify what each week is to look like are |
| 129 |
% |\calday| and |
| 130 |
% |\skipday|. |
| 131 |
% These commands specify the days of the week in order; thus there |
| 132 |
% should be seven of them (athough ten may be prefered for a course |
| 133 |
% covering the French |
| 134 |
% revolution). |
| 135 |
% The macro |\skipday|\DescribeMacro{\skipday}\ |
| 136 |
% simply declares that the corresponding day should |
| 137 |
% not be printed in the exam; thus the sample calendar has boxes only |
| 138 |
% for Monday, Wednesday, Thursday, and Friday. The macro |
| 139 |
% |\calday[|\inp{optional~head}|]{|\inp{option~list}|}| |
| 140 |
% \DescribeMacro{\calday} |
| 141 |
% is used to specify a day which is to be printed. The required |
| 142 |
% argument \inp{option~list} |
| 143 |
% is a (possibly empty) list of \TeX\ commands which are executed |
| 144 |
% before the text for that day is printed. |
| 145 |
% It can (at least in principal) include |
| 146 |
% any \LaTeX\ command, but several commands, described below, are |
| 147 |
% provided specifically for this purpose. The optional argument |
| 148 |
% is the text of a heading for that day |
| 149 |
% which will at the top |
| 150 |
% of each page of the calendar. |
| 151 |
|
| 152 |
% \paragraph{Available options.} |
| 153 |
% The macros |\classday| |
| 154 |
% \DescribeMacro{\classday}\DescribeMacro{\noclassday} |
| 155 |
% and |\noclassday| declare that the specified day is, or is not, a |
| 156 |
% class day. Days specified as class days are numbered and can be |
| 157 |
% refered to by their numbers. |
| 158 |
% The command |\weeklytext{|\inp{text}|}| specifies that the |
| 159 |
% \DescribeMacro{\weeklytext} |
| 160 |
% indicated text should appear every week in the box for that day. |
| 161 |
% The \inp{text} |
| 162 |
% may include \TeX\ commands; for example the following could be used |
| 163 |
% to number regular Monday quizes: |
| 164 |
% \begin{verbatim} |
| 165 |
% \weeklytext{\stepcounter{quiznumber} Quiz~\arabic{quiznumber}} |
| 166 |
% \end{verbatim} |
| 167 |
% |
| 168 |
% \paragraph{Options for a specific day} are specified by the command |
| 169 |
% |\options{|\inp{day}|}{|\inp{option list}|}|. |
| 170 |
% \DescribeMacro{\options} |
| 171 |
% The \inp{option~list} argument is exactly the same as for |\calday|. The |
| 172 |
% options added by |\options| are executed after those for |\calday|, |
| 173 |
% and thus may be used to modify or nullify for a specific day the |
| 174 |
% general instructions specified for a particular day of the week. |
| 175 |
% If there no quiz is planned for Halloween then |
| 176 |
% |\options{10/31/94}{\weeklytext{}}| could be used to supress |
| 177 |
% printing the usual weekly message. |
| 178 |
% |
| 179 |
% There are two ways of specifing the \inp{day} argument of |
| 180 |
% |\options|. First, the date may be specified, in the format |
| 181 |
% \texttt{m/d/y}; for example |
| 182 |
% \begin{verbatim}\options{11/11/94}{\noclass}\end{verbatim} |
| 183 |
% specifies, that November 11th, Veterans's day, is not a class day. |
| 184 |
% The second method of specifying the date is by its number: |
| 185 |
% \begin{verbatim}\options{C6}{\weeklytext{}}\end{verbatim} |
| 186 |
% would supress the normal text on the |
| 187 |
% sixth day of class. Of course, only days specified as class days |
| 188 |
% can be addressed in this style. |
| 189 |
% |
| 190 |
% \paragraph{Inserting Text.} There is a similar provision for text to |
| 191 |
% be printed on a specific day, |
| 192 |
% using the command |\caltext|. \DescribeMacro{\caltext} The command |
| 193 |
% \begin{verbatim}\caltext{10/31/94}{Halloween\\No Quiz!} \end{verbatim} |
| 194 |
% will print the indicated |
| 195 |
% message on October 31, and |
| 196 |
% |\caltext{C6}{Hour Exam}| |
| 197 |
% ^^A \begin{verbatim}\caltext{C6}{Hour Exam}\end{verbatim} |
| 198 |
% will |
| 199 |
% print the indicated message on the sixth class day. |
| 200 |
% |
| 201 |
% Two extra commands are provided to simplify the job of entering text for |
| 202 |
% consecutive class days, as in specifying the lecture topic or |
| 203 |
% homework for each day. The command |
| 204 |
% \DescribeMacro{\caltexton}\DescribeMacro{\caltextnext} |
| 205 |
% |\caltexton{|\inp{class day}|}{|\inp{text}|}| specifies a |
| 206 |
% starting day and inserts the |
| 207 |
% indicated text on that day. The command |
| 208 |
% |\caltextnext{|\inp{text}|}| can then be used to print text on |
| 209 |
% successive class days. The command |\caltextnext{}|, with an empty |
| 210 |
% argument, may be used to skip days. |
| 211 |
% |
| 212 |
% \subsection{Modifying the style of the calendar} |
| 213 |
% Several parameters and commands will allow some modfication of the |
| 214 |
% style of the entire calendar. The size of the calendar is specified |
| 215 |
% by |\calboxdepth|\DescribeMacro{\calboxdepth}, which specifies the |
| 216 |
% minimum height of the box for each day, and |
| 217 |
% |\calwidth|\DescribeMacro{\calwidth}\ which specifies the width of the |
| 218 |
% calendar. The defaults are 1~inch for |\calboxdepth| and |\textwidth| |
| 219 |
% for |\calboxwidth|. |
| 220 |
|
| 221 |
% The printing of the date and classnumber in each box is done by the |
| 222 |
% commands |\calprintdate| and |\calprintclass|. The default |
| 223 |
% definitions of these macros are as follows: |
| 224 |
% \begin{macro}{\calprintdate} |
| 225 |
% \begin{macrocode} |
| 226 |
\newcommand{\calprintdate}{% |
| 227 |
\ifnewmonth\framebox{\monthname\ \ordinaldate}% |
| 228 |
\else \ordinaldate\fi |
| 229 |
} |
| 230 |
% \end{macrocode} |
| 231 |
% \end{macro} |
| 232 |
% \begin{macro}{\calprintclass} |
| 233 |
% \begin{macrocode} |
| 234 |
\newcommand{\calprintclass}{\textbf{\small\theclassnum}} |
| 235 |
% \end{macrocode} |
| 236 |
% \end{macro} |
| 237 |
% They may be changed with |\renewcommand|. |
| 238 |
% |
| 239 |
% By default the calendar will automatically be split over several |
| 240 |
% pages. This can be avoided by putting the entire calendar in a |
| 241 |
% |\vbox|. It will normally also be necessary to change |\calboxdepth| |
| 242 |
% so that the calendar will fit on one page. |
| 243 |
% |
| 244 |
% \StopEventually{} |
| 245 |
% \section{The Code} |
| 246 |
% \begin{macrocode} |
| 247 |
\ProvidesPackage{termcal}[\filedate\space\fileversion\space |
| 248 |
Latex2e package to print a Term calendar] |
| 249 |
\NeedsTeXFormat{LaTeX2e} |
| 250 |
% \end{macrocode} |
| 251 |
% We use the package |longtable| so that the calendar can be split |
| 252 |
% over several pages if desired. |
| 253 |
% \begin{macrocode} |
| 254 |
\RequirePackage{longtable} |
| 255 |
\RequirePackage{ifthen} |
| 256 |
% \end{macrocode} |
| 257 |
% Parameters determining the size of the calendar. |
| 258 |
% |
| 259 |
% \begin{macrocode} |
| 260 |
\newlength{\calboxdepth}\setlength\calboxdepth{1in} |
| 261 |
\newlength\calwidth\setlength\calwidth{\textwidth} |
| 262 |
\newlength{\ca@boxwidth} %% set by \endcalendar |
| 263 |
% \end{macrocode} |
| 264 |
% The following parameters are used to control the construction of the |
| 265 |
% calendar. |
| 266 |
% \begin{macro}{\ca@dpw} The number of days used in a week. |
| 267 |
% \begin{macrocode} |
| 268 |
\newcounter{ca@dpw} |
| 269 |
% \end{macrocode} |
| 270 |
% \end{macro} |
| 271 |
% \begin{macro}{\ca@numwks} The number of weeks in the calendar. |
| 272 |
% \begin{macrocode} |
| 273 |
\newcounter{ca@numwks} %% weeks in calendar |
| 274 |
% \end{macrocode} |
| 275 |
% \end{macro} |
| 276 |
% \begin{macro}{\ca@wknum} Used to keep track of the current week. |
| 277 |
% \begin{macrocode} |
| 278 |
\newcounter{ca@wknum} |
| 279 |
% \end{macrocode} |
| 280 |
% \end{macro} |
| 281 |
% \begin{macro}{\ca@doaweek} Two token boxes used to build up the |
| 282 |
% basic contents of the calendar. |\ca@doaweek| is built up by |
| 283 |
% |\calday|, and prints a typical week. It will be filled up by the macros |
| 284 |
% |\calday| and |\skipday|. |
| 285 |
% \begin{macrocode} |
| 286 |
\newtoks\ca@doaweek |
| 287 |
% \end{macrocode} |
| 288 |
% \end{macro} |
| 289 |
% \begin{macro}{\ca@doweeks} This will be essentially |ca@numwks| copys |
| 290 |
% of |\ca@doaweek|. |
| 291 |
% \begin{macrocode} |
| 292 |
\newtoks\ca@doweeks |
| 293 |
% \end{macrocode} |
| 294 |
% \end{macro} |
| 295 |
% \begin{macro}{\ca@colhead}\begin{macro}{\ifca@chead} The column |
| 296 |
% headings which appear at the top of every page is collected in the |
| 297 |
% token box |\ca@colhead| by |\calday|. The switch |\ifca@chead| is |
| 298 |
% set to true if any such column heads are specified. |
| 299 |
% \begin{macrocode} |
| 300 |
\newtoks\ca@colhead |
| 301 |
\newif\ifca@chead |
| 302 |
% \end{macrocode} |
| 303 |
% \end{macro}\end{macro} |
| 304 |
% \begin{environment}{calendar} |
| 305 |
% This is the basic environment. The |\calendar| command only saves the |
| 306 |
% parameters and initializes some counters. |
| 307 |
% \begin{macrocode} |
| 308 |
\newenvironment{calendar}[2]% |
| 309 |
{% |
| 310 |
\setcounter{ca@numwks}{#2} |
| 311 |
\setdate{#1} |
| 312 |
\setcounter{ca@dpw}{0} |
| 313 |
\setcounter{classnum}{1} |
| 314 |
} |
| 315 |
% \end{macrocode} |
| 316 |
% \begin{macro}{\endcalendar} |
| 317 |
% The calendar is actually created in the code for |\endcalendar|. |
| 318 |
% It will be printed as a longtable. |
| 319 |
% \begin{macrocode} |
| 320 |
{ |
| 321 |
% \end{macrocode} |
| 322 |
% Since the \texttt{longtable} and |
| 323 |
% \texttt{tabular} environments don't work well with loops in their |
| 324 |
% body, we will build up the body in a token box, |\ca@doweeks|. |
| 325 |
%\begin{macro}{\ca@doweeks} |
| 326 |
% \begin{macrocode} |
| 327 |
\ifca@chead\ca@doweeks{\the\ca@colhead\endhead\hline\hline}\fi |
| 328 |
\setcounter{ca@wknum}{0} |
| 329 |
\whiledo{\value{ca@wknum}<\value{ca@numwks}}% |
| 330 |
{\stepcounter{ca@wknum}% |
| 331 |
\addtotoks{\ca@doweeks}{\the\ca@doaweek\\\hline}} |
| 332 |
% \end{macrocode} |
| 333 |
% \end{macro} |
| 334 |
% Now we calculate the widths of the boxes, using a formula from the |
| 335 |
% Latex Companion. |
| 336 |
% \begin{macro}{\ca@boxwidth} |
| 337 |
% \begin{macrocode} |
| 338 |
\ca@boxwidth=\calwidth |
| 339 |
\divide\ca@boxwidth by \c@ca@dpw\relax |
| 340 |
\advance\ca@boxwidth by -2\tabcolsep\relax |
| 341 |
\setlength\@tempdima\arrayrulewidth\relax |
| 342 |
\multiply\@tempdima\c@ca@dpw\relax |
| 343 |
\advance\@tempdima\arrayrulewidth\relax |
| 344 |
\divide\@tempdima\c@ca@dpw\relax |
| 345 |
\advance\ca@boxwidth by -\@tempdima\relax |
| 346 |
% \end{macrocode} |
| 347 |
% \end{macro} |
| 348 |
% Now we use the |longtable| environment to print out the calendar. |
| 349 |
% \begin{macrocode} |
| 350 |
\begin{longtable}[l] |
| 351 |
{|*{\theca@dpw}{p{\ca@boxwidth}|}@{}}% |
| 352 |
\hline |
| 353 |
\the\ca@doweeks |
| 354 |
\end{longtable} |
| 355 |
} |
| 356 |
% \end{macrocode} |
| 357 |
% \end{macro} ^^A \endcalendar |
| 358 |
% \end{environment} ^^A calendar |
| 359 |
% \begin{macro}{\addtotoks} The command |
| 360 |
% |\addtotoks{|\inp{token box}|}{|\inp{new tokens}|}| is used to add |
| 361 |
% new tokens at the end of \inp{token box}. |
| 362 |
% \begin{macrocode} |
| 363 |
\newcommand\addtotoks[2]{#1\expandafter{\the#1#2}} |
| 364 |
% \end{macrocode} |
| 365 |
% \end{macro} |
| 366 |
% \begin{macro}{\calday} |
| 367 |
% \begin{macro}{\ca@doaweek} |
| 368 |
% \begin{macro}{\ca@colhead} |
| 369 |
% The command |\calday| works by adding |
| 370 |
% commands to the token box |\ca@doaweek|, a copy of which is inserted |
| 371 |
% into |\ca@doweeks| for each week in the calendar. |
| 372 |
% inserted |
| 373 |
% If column headings are specified, then they are put into |
| 374 |
% the token box |\ca@colhead|. |
| 375 |
% \begin{macrocode} |
| 376 |
\ca@doaweek={\stepcounter{ca@wknum}\ignorespaces} |
| 377 |
\newcommand\calday[2][]{\stepcounter{ca@dpw}% |
| 378 |
\ifca@fday\addtotoks\ca@doaweek{&}\addtotoks\ca@colhead{&}\fi |
| 379 |
\addtotoks\ca@doaweek{\ca@doaday{#2}} |
| 380 |
\def\@tempa{#1}\ifx\@tempa\@empty |
| 381 |
\else\addtotoks\ca@colhead{\strut\scshape\centering #1}\ca@cheadtrue\fi |
| 382 |
\ca@fdaytrue |
| 383 |
} |
| 384 |
% \end{macrocode} |
| 385 |
% \end{macro} |
| 386 |
% \end{macro} |
| 387 |
% \end{macro} |
| 388 |
% \begin{macro}{\ifca@fday} True if this is not the first day of the week. This determines whether |
| 389 |
% |&| needs to be added as a |
| 390 |
% separator. |
| 391 |
% \begin{macrocode} |
| 392 |
\newif\ifca@fday |
| 393 |
% \end{macrocode} |
| 394 |
% \end{macro} |
| 395 |
% \begin{macro}{\skipday} |
| 396 |
% The command |\skipday| simply advances the date without printing |
| 397 |
% anything in the calendar. |
| 398 |
% \begin{macrocode} |
| 399 |
\newcommand\skipday{\addtotoks\ca@doaweek{\advancedate}} |
| 400 |
% \end{macrocode} |
| 401 |
% \end{macro} |
| 402 |
% After a couple of preliminaries, we will define the command |
| 403 |
% |\ca@doaday| which is |
| 404 |
% actually prints out |
| 405 |
% the text for each day of the calendar. |
| 406 |
% \begin{macro}{c@classnum} This is the counter used to keep track of |
| 407 |
% class days. It is initialized to 1 in the beginning of the |
| 408 |
% |calendar| environment. |
| 409 |
% \begin{macrocode} |
| 410 |
\newcounter{classnum} |
| 411 |
% \end{macrocode} |
| 412 |
% \end{macro} |
| 413 |
% \begin{macro}{\ca@normbs} |
| 414 |
% The meaning of |\\| is changed by the |longtable| environment. |
| 415 |
% We save its standard meaning so that it can be used |
| 416 |
% in the text to be printed in the calendar boxes. |
| 417 |
% \begin{macrocode} |
| 418 |
\let\ca@normbs=\\ |
| 419 |
% \end{macrocode} |
| 420 |
% \end{macro} |
| 421 |
% \begin{macro}{\ca@doaday} |
| 422 |
% The command |\ca@doaday| does the actual printing of the contents of |
| 423 |
% the box for each day. |
| 424 |
% First the options are read, in the following order: |
| 425 |
% options specified in the argument to |\calday|, then options |
| 426 |
% specified by date, and finally |
| 427 |
% options specified by classday. |
| 428 |
% \begin{macrocode} |
| 429 |
\newcommand\ca@doaday[1]{ |
| 430 |
\hbox{\vrule depth \calboxdepth height 0pt width 0pt\vtop{ |
| 431 |
#1% %options specified by |\calday| |
| 432 |
\csname\curdate options\endcsname% % options specified by date |
| 433 |
\ifclassday\csname C\theclassnum options\endcsname\fi %by classnumber |
| 434 |
% \end{macrocode} |
| 435 |
% Then the heading is printed. |
| 436 |
% \begin{macrocode} |
| 437 |
\hbox to \hsize{\calprintdate\hfill\ifclassday\calprintclass\fi} |
| 438 |
\vspace{2pt} |
| 439 |
% \end{macrocode} |
| 440 |
% Now we are ready to print the text. We do it inside a group in which |
| 441 |
% the normal meaning of |\\| is restored. |
| 442 |
% \begin{macrocode} |
| 443 |
\begingroup |
| 444 |
\let\\=\ca@normbs |
| 445 |
\raggedright |
| 446 |
\sloppy |
| 447 |
|
| 448 |
\the\weeklytext\par |
| 449 |
\csname\curdate text\endcsname |
| 450 |
\ifclassday\csname C\theclassnum text\endcsname |
| 451 |
\stepcounter{classnum}\fi |
| 452 |
\endgroup |
| 453 |
}} |
| 454 |
% \end{macrocode} Finally we advance the date. The command |
| 455 |
% |\advancedate| will set |\newmonthtrue| if appropriate. |
| 456 |
% \begin{macrocode} |
| 457 |
\global\newmonthfalse |
| 458 |
\advancedate |
| 459 |
} |
| 460 |
% \end{macrocode} |
| 461 |
% \end{macro} |
| 462 |
% \subsection{Options} |
| 463 |
% The options and text for the individual days are stored in macros, |
| 464 |
% with names of the form |\|\inp{date}|options| or |
| 465 |
% |\|\inp{date}|text|. |
| 466 |
% |
| 467 |
% \begin{macro}{\ca@addmacro} |\ca@addmacro| is like |\ca@addtoks|, |
| 468 |
% except it works on macros instead of token boxes. The first |
| 469 |
% argument is the name of a |
| 470 |
% macro (without the backslash) and the second is a sequence of |
| 471 |
% tokens to be added to its definition. The definition is taken from |
| 472 |
% the |
| 473 |
% \TeX{}book, exercise 20.15. Note that the spaces in the last line |
| 474 |
% are essential. |
| 475 |
% \begin{macrocode} |
| 476 |
\long\def\ca@addmacro#1#2{ |
| 477 |
\expandafter\ifx\csname#1\endcsname\relax% |
| 478 |
\expandafter\def\csname#1\endcsname{#2} |
| 479 |
\else |
| 480 |
\toks0= |
| 481 |
\expandafter\expandafter\expandafter{\csname#1\endcsname} |
| 482 |
\toks2={#2} |
| 483 |
\expandafter |
| 484 |
\edef\csname#1\endcsname{\the\toks0 \the\toks2 }\fi} |
| 485 |
% \end{macrocode} |
| 486 |
% \end{macro} |
| 487 |
% \begin{macro}{\options} |\options#1#2| adds the tokens in the second |
| 488 |
% argument to the macro with the name |\csname #1options\endcsname|. |
| 489 |
% \begin{macrocode} |
| 490 |
\newcommand\options[1]{\ca@addmacro{#1options}} |
| 491 |
% \end{macrocode} |
| 492 |
% \end{macro} |
| 493 |
% Now the code for the varions options. |
| 494 |
% |
| 495 |
% \begin{macro}{\ifclassday} |
| 496 |
% \begin{macro}{\classday}\begin{macro}{\noclassday} |
| 497 |
% A switch determines which days are class days. |
| 498 |
% \begin{macrocode} |
| 499 |
\newif\ifclassday |
| 500 |
\newcommand{\classday}{\classdaytrue} |
| 501 |
\newcommand{\noclassday}{\classdayfalse} |
| 502 |
% \end{macrocode} |
| 503 |
% \end{macro}\end{macro}\end{macro} |
| 504 |
% |
| 505 |
% \begin{macro}{\weeklytext} This token box holds the standard text |
| 506 |
% for each day of the week. It is filled and immediately used by |
| 507 |
% |\ca@doaday|, |
| 508 |
% inside the hbox containing each calendar day. |
| 509 |
% \begin{macrocode} |
| 510 |
\newtoks\weeklytext |
| 511 |
% \end{macrocode} |
| 512 |
% \end{macro} |
| 513 |
% \begin{macro}{\caltext} |
| 514 |
% This macro works like |\options| to save the |
| 515 |
% text for a specific day, saving the text in a macro with the name |
| 516 |
% |\csname #1text\endcsname|. We add |\par| after the text, so |
| 517 |
% successive texts for the same day start on separate lines. We use |
| 518 |
% |\par| instead of |\\| since it is harmless if it is unneeded (but |
| 519 |
% requires that |\ca@addmacro| be long). |
| 520 |
% \begin{macrocode} |
| 521 |
\newcommand\caltext[2]{\ca@addmacro{#1text}{#2\par}} |
| 522 |
% \end{macrocode} |
| 523 |
% \end{macro} |
| 524 |
% \begin{macro}{\c@textdaycount}\begin{macro}{\caltexton} |
| 525 |
% \begin{macro}{\caltextnext} |
| 526 |
% The commands |\caltexton| and |\caltextnext| use |\caltext| with the |
| 527 |
% day determined by the counter |textdaycount|. |
| 528 |
% \begin{macrocode} |
| 529 |
\newcounter{textdaycount}\setcounter{textdaycount}1 |
| 530 |
\newcommand\caltexton[2]{\setcounter{textdaycount}{#1} |
| 531 |
\caltext{C#1}{#2}} |
| 532 |
\newcommand\caltextnext[1]{\advance\c@textdaycount by 1 |
| 533 |
\caltext{C\thetextdaycount}{#1}} |
| 534 |
% \end{macrocode} |
| 535 |
% \end{macro}\end{macro}\end{macro} |
| 536 |
% \subsection{Macros concerned with date calculations} |
| 537 |
% Now we have a selection of macros which are concerned with |
| 538 |
% calculating the dates in the calendar. |
| 539 |
% \begin{macro}{\c@date} Counter for the day of the month. |
| 540 |
% \begin{macrocode} |
| 541 |
\newcounter{date} |
| 542 |
% \end{macrocode} |
| 543 |
% \end{macro} |
| 544 |
% \begin{macro}{\c@month} Counter for month (January = 1) |
| 545 |
% \begin{macrocode} |
| 546 |
\newcounter{month} |
| 547 |
% \end{macrocode} |
| 548 |
% \end{macro} |
| 549 |
% \begin{macro}{\c@year} Counter for year. |
| 550 |
% \begin{macrocode} |
| 551 |
\newcounter{year} |
| 552 |
% \end{macrocode} |
| 553 |
% \end{macro} |
| 554 |
% \begin{macro}{\curdate}Print out the date. |
| 555 |
% \begin{macrocode} |
| 556 |
\newcommand\curdate{\arabic{month}/\arabic{date}/\arabic{year}} |
| 557 |
% \end{macrocode} |
| 558 |
% \end{macro} |
| 559 |
% \begin{macro}{\monthname} Print the name of the Month. |
| 560 |
% \begin{macrocode} |
| 561 |
\newcommand\monthname{\ifcase\c@month\or Jan\or Feb\or Mar\or Apr% |
| 562 |
\or May\or June\or July\or Aug\or Sep\or Oct% |
| 563 |
\or Nov\or Dec\fi} |
| 564 |
% \end{macrocode} |
| 565 |
% \end{macro} |
| 566 |
% \begin{macro}{\advancedate} Move the date forward by one day. |
| 567 |
% \begin{macrocode} |
| 568 |
\newcommand\advancedate{\stepcounter{date} |
| 569 |
\ifnum\thedate>\monthlength\relax |
| 570 |
\addtocounter{date}{-\monthlength}\advancemonth\fi} |
| 571 |
% \end{macrocode} |
| 572 |
% \end{macro} |
| 573 |
% \begin{macro}{\ifnewmonth} True if no days have been printed during |
| 574 |
% the current month. |
| 575 |
% \begin{macrocode} |
| 576 |
\newif\ifnewmonth\newmonthtrue |
| 577 |
% \end{macrocode} |
| 578 |
% \end{macro} |
| 579 |
% \begin{macro}{\advancemonth} |
| 580 |
% \begin{macrocode} |
| 581 |
\newcommand\advancemonth{% |
| 582 |
\global\newmonthtrue\stepcounter{month} |
| 583 |
\ifnum\c@month>12 |
| 584 |
\stepcounter{year}\setleap\setcounter{month}1\fi} |
| 585 |
% \end{macrocode} |
| 586 |
% \end{macro} |
| 587 |
% \begin{macro}{\ifleap} True if the year is a leap year. |
| 588 |
% \begin{macrocode} |
| 589 |
\newif\ifleap |
| 590 |
% \end{macrocode} |
| 591 |
% \end{macro} |
| 592 |
% \begin{macro}{\setleap} Determine whether the year is a leap |
| 593 |
% year. This is valid until 2100, thanks to the 400 year rule. |
| 594 |
% \begin{macrocode} |
| 595 |
\newcommand\setleap{% |
| 596 |
\@tempcnta=\c@year |
| 597 |
\divide\@tempcnta by 4 \multiply\@tempcnta by 4 |
| 598 |
\ifnum\@tempcnta=\c@year\global\leaptrue |
| 599 |
\else\global\leapfalse\fi} |
| 600 |
% \end{macrocode} |
| 601 |
% \end{macro} |
| 602 |
% \begin{macro}{\monthlength} Determine the number of days in the |
| 603 |
% current month. |
| 604 |
% \begin{macrocode} |
| 605 |
\newcommand\monthlength{% |
| 606 |
\ifcase\c@month\or31\or\ifleap29\else28\fi |
| 607 |
\or31\or30\or31\or30\or31\or31\or30\or31\or30\or31\fi% |
| 608 |
\relax} |
| 609 |
% \end{macrocode} |
| 610 |
% \end{macro} |
| 611 |
% \begin{macro}{\setdate} Take argument in the form |m/d/y| and set |
| 612 |
% the counters |month|, |date| and |year|. |
| 613 |
% \begin{macrocode} |
| 614 |
\newcommand\setdate[1]{\setdate@#1!} |
| 615 |
\def\setdate@#1/#2/#3!{ |
| 616 |
\setcounter{month}{#1} |
| 617 |
\setcounter{date}{#2} |
| 618 |
\setcounter{year}{#3} |
| 619 |
\global\newmonthtrue\setleap} |
| 620 |
% \end{macrocode} |
| 621 |
% \end{macro} |
| 622 |
% \begin{macro}{\ordinaldate} Print the day of the month as an ordinal. |
| 623 |
% \begin{macrocode} |
| 624 |
\newcommand\ordinaldate{\ordinal{\c@date}} |
| 625 |
% \end{macrocode} |
| 626 |
% \end{macro} |
| 627 |
% \begin{macro}{\ordinal} Print the contents of a register as ordinal |
| 628 |
% number. |
| 629 |
% \begin{macrocode} |
| 630 |
\newcommand\ordinal[1]{% |
| 631 |
\let\last@=\relax\let\last@@=\relax |
| 632 |
\expandafter\@rd\the#1x} |
| 633 |
\newcommand\@rd[1]{\ifx#1x\if\last@@1th\else\@rdend{\last@}\fi\else |
| 634 |
\let\last@@=\last@\def\last@{#1}#1\expandafter\@rd\fi} |
| 635 |
\newcommand\@rdend[1]{\ifcase#1 th\or st\or nd\or rd\else th\fi} |
| 636 |
% \end{macrocode} |
| 637 |
% \end{macro} |
| 638 |
% \Finale |
| 639 |
%\endinput |
| 640 |
%</package> |
| 641 |
% |
| 642 |
% \iffalse %% don't print this in documentation. |
| 643 |
%<*example> |
| 644 |
\begin{calendar}{9/26/94}{6} |
| 645 |
\setlength{\calboxdepth}{.3in} |
| 646 |
%% Description of the Week. |
| 647 |
\calday[Monday]{\classday} % Monday |
| 648 |
\skipday % Tuesday (no class) |
| 649 |
\calday[Tuesday]{\classday} % Wednesday |
| 650 |
\calday[Thursday]{\noclassday} % Thursday (unnumbered) |
| 651 |
\calday[Friday]{\classday} % Friday |
| 652 |
\skipday\skipday % weekend (no class) |
| 653 |
%% Holidays |
| 654 |
\options{10/31/94}{\noclassday} |
| 655 |
\caltext{10/31/94}{No Class\\Halloween} |
| 656 |
%% Exams |
| 657 |
\caltext{10/12/94}{Midterm Exam} |
| 658 |
%%%%%%% Text on consecutive days |
| 659 |
% the subject of the 9th lecture |
| 660 |
\caltexton{9}{\S1.2,1.3\\Sorting and disporting} |
| 661 |
% the subject of the 10th lecture |
| 662 |
\caltextnext{\S1.3,1,4\\Assembling and dissembling} |
| 663 |
\caltextnext{} |
| 664 |
% the subject of the 12th lecture |
| 665 |
\caltextnext{\S9.9\\Tending and rending} |
| 666 |
\end{calendar} |
| 667 |
%</example> |
| 668 |
% \fi |
| 669 |
% \endinput |
| 670 |
% $Log: termcal.dtx,v $ |
| 671 |
% Revision 1.8 1997/01/11 17:04:40 mitchell |
| 672 |
% Documentation rewritten preprepitory to sending to CTAN |
| 673 |
% |
| 674 |
% Revision 1.7 1997/01/11 00:56:28 mitchell |
| 675 |
% Minor changes to documentation. |
| 676 |
% |
| 677 |
% Revision 1.6 1995/06/15 14:13:05 mitchell |
| 678 |
% Put definition of filedate and fileversion into termcal.sty. |
| 679 |
% |
| 680 |
% Revision 1.5 1995/06/10 16:43:43 mitchell |
| 681 |
% RCS related changes. |
| 682 |
% |
| 683 |
% |
| 684 |
% Revision 1.4 1995/06/10 16:22:20 mitchell |
| 685 |
% Initialized counters, to allow for printing several calendars |
| 686 |
% in a single file. |
| 687 |
% |
| 688 |
% Revision 1.3 1994/08/06 00:57:53 mitchell |
| 689 |
% add Identification stuff. |
| 690 |
% |
| 691 |
% Revision 1.2 1994/08/05 17:22:45 mitchell |
| 692 |
% Added column headings as optional argument to \calday. |
| 693 |
% |
| 694 |
% LocalWords: chead tempdima fday doaday tempa cheadtrue fdaytrue classnum pt |
| 695 |
% LocalWords: normbs addmacro textdaycount Apr Aug Sep Oct Nov tempcnta rdend |