summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/schedule/schedule.dtx
blob: 602671021c3ac23080705d68031a2a86a4fcb0a1 (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
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
% \iffalse
%
% Single-source dtx file built on Will Robertson's dtxgallery single-source.dtx example. 
%
%<*internal>
\iffalse
%</internal>
%<*readme>
----------------------------------------------------------------
schedule.sty --- A style for personal weekly schedules
E-mail: edeneault@ut.edu
Released under the LaTeX Project Public License v1.3c or later
See http://www.latex-project.org/lppl.txt
----------------------------------------------------------------

This package defines the {\ttfamily schedule} environment. This is primarily intended for
constructing charts of recurring weekly appointments.  It may also
be used to create a schedule of events and sign-up sheets (for example,
scheduling mandatory office visits with students for discussing paper topics,
etc.)

This package requires the packages {\ttfamily calc} and {\ttfamily xcolor}.
%</readme>
%<*internal>
\fi
\begingroup
%</internal>
%<*batchfile>
\input docstrip.tex
\keepsilent\askforoverwritefalse
\preamble

This is a generated file.

Copyright (c) Ethan Deneault <edeneault@ut.edu>, 2019
                      (current maintainer)
Copyright (c) Jason Alexander, 1997-2001
                       (author)
                       
This file may be distributed and/or modified under the
conditions of the LaTeX Project Public License, either
version 1.3 of this license or (at your option) any later
version. The latest version of this license is in:

	http://www.latex-project.org/lppl.txt

and version 1.3 or later is part of all distributions of
LaTeX version 2005/12/01 or later.

\endpreamble
\usedir{tex/latex/schedule}
\generate{\file{\jobname.sty}{\from{\jobname.dtx}{package}}}
%</batchfile>
%<batchfile>\endbatchfile
%<*internal>
\generate{\file{\jobname.ins}{\from{\jobname.dtx}{batchfile}}}
\generate{\file{README.txt}{\from{\jobname.dtx}{readme}}}
\endgroup
%</internal>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{schedule}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
%\OnlyDescription
\begin{document}
\DocInput{\jobname.dtx} 
\end{document}
%</driver>
% \fi
%
%
% \changes{v1.00}{1997/10/11}{Initial version.}
% \changes{v1.10}{2019/7/26}{Clarified `noon' and `midnight' for 12:00}
%
% \GetFileInfo{schedule.sty}
%
% \DoNotIndex{\if,\else,\fi,\expandafter}
% \DoNotIndex{\csname,\endcsname}
% \DoNotIndex{\addtocounter,\stepcounter,\advance,\Alph,\alph,\arabic}
% \DoNotIndex{\begin,\end,\begingroup,\endgroup,\catcode,\centerline,\day,\def}
% \DoNotIndex{\divide,\do,\edef,\endgroup,\evensidemargin,\fbox,\gdef,\global}
% \DoNotIndex{\headheight,\headsep,\hfill,\hphantom,\Huge,\ifnum,\ifx,\large}
% \DoNotIndex{\long,\m@ne,\mbox,\medskip,\message,\month,\multiply}
% \DoNotIndex{\noindent,\nopagebreak,\normalsize,\oddsidemargin,\pagebreak}
% \DoNotIndex{\par,\relax,\rightmargin,\roman,\setcounter,\setlength}
% \DoNotIndex{\smallskipamount,\space,\textheight,\textsf,\textwidth}
% \DoNotIndex{\the,\topmargin,\undefined,\underline,\value,\vspace}
% \DoNotIndex{\xdef,\year,\z@,\time,\topsep}
%
% \title{The \textsf{schedule} package\thanks{This file
%        has version number \fileversion, last
%        revised \filedate.}}
% \author{Jason Alexander \\
%		Ethan Deneault\footnote{Current maintainer, please send bug reports to:
%              \texttt{edeneault@ut.edu}}}
% \date{\filedate}
% \maketitle
%
% \MakeShortVerb{\|}
%
% \begin{abstract}
%This package defines the {\ttfamily schedule} environment. This is primarily intended for
%constructing charts of recurring weekly appointments.  It may also
%be used to create a schedule of events and sign-up sheets (for example,
%scheduling mandatory office visits with students for discussing paper topics,
%etc.)
%
%This package requires the packages {\ttfamily calc} and {\ttfamily xcolor}.
% \end{abstract}
%
% \section{Introduction}
% \texttt{schedule} provides a simple interface for creating graphical charts
% displaying weekly appointments.  Many respects of the overall layout can be
% customized to suit the user's desires.  Unless these default settings are
% changed, the created schedule will run from Monday to Friday, 8:00am to 5:00pm,
% and the only predefined command to insert appointments will be |\class|, which
% draws the appointment using black text on a medium-gray background.
%
% The main feature of the \texttt{schedule} package is its accuracy in
% diagramming the length of appointments.  Unlike some professionally available
% schedule creation programs, the representation of the length of appointments in
% the \texttt{schedule} package is accurate to the minute.  In other
% words, if you have two appointments, one running from 2:00pm to 3:30pm on
% Tuesday and another running from 2:00pm to 3:31pm on Wednesday, there is a
% visible difference between the two representations.  Unfortunately, unless you
% have a high-resolution printer (by which I mean more than 600 dpi) these
% differences will likely only be noticeable by a on-screen previewing program like
% \texttt{ghostview}.
%
% \section{Examples}
%
% The following schedule is typeset using the commands:
%
% \pagebreak
%
% \begin{verbatim}
% \CellHeight{.4in}
% \CellWidth{1in}
% \TimeRange{12:00-15:00}
% \SubUnits{30}
% \BeginOn{Monday}
% \TextSize{\tiny}
% \FiveDay
%
% \NewAppointment{meeting}{red}{white}
% \NewAppointment{workshop}{green}{blue}
%
% \begin{schedule}[Fall Quarter, 1997]
%   \class{Moral Philosophy}{HOB2 233}{M}{14:00-16:50}
%   \class{Math Logic}{EIC 128}{T,Th}{11:00-12:20}
%   \class{Critical Reasoning}{SSL 290}{M,W,F}{13:00-13:50}
%   \meeting{Departmental Meeting}{HOB2 233}{W}{12:00-12:50}
%   \workshop{Crit. Reas. Workshop}{HOB2 233}{T}{13:00-13:50}
%   \class{Office Hours}{HOB2 210}{W,F}{14:00-14:50}
% \end{schedule}
% \end{verbatim}
%
% The result is:
% \CellHeight{.4in}
% \CellWidth{1in}
% \TimeRange{12:00-15:00}
% \SubUnits{30}
% \BeginOn{Monday}
% \TextSize{\tiny}
% \FiveDay
%
% \NewAppointment{meeting}{red}{white}
% \NewAppointment{workshop}{green}{blue}
%
%\begin{schedule}[Fall Quarter, 1997]%
%  \class{Moral Philosophy}{HOB2 233}{M}{14:00-16:50}
%  \class{Math Logic}{EIC 128}{T,Th}{11:00-12:20}
%  \class{Critical Reasoning}{SSL 290}{M,W,F}{13:00-13:50}
%  \meeting{Departmental Meeting}{HOB2 233}{W}{12:00-12:50}
%  \workshop{Crit. Reas. Workshop}{HOB2 233}{T}{13:00-13:50}
%  \class{Office Hours}{HOB2 210}{W,F}{14:00-14:50}
%\end{schedule}%
%
% This example demonstrates all of the user-customizable options.  Note
% several ``features'' of the package:
% \begin{enumerate}
%    \item Appointments falling outside of the specified time range
%          for the schedule are automatically truncated to fit.  If the
%          appointment falls entirely outside of the time range, it is not
%          printed at all.
%
%    \item The command |\class| is predefined to chart appointments pertaining
%          to class attendence.  New appointment types may be defined by the
%          user via the |\NewAppointment| command.  The new appointments may
%          use any predefined color for the text or background.  Note that the
%          \textsf{color} package allows one to define new colors.
%
%    \item The boxes created to represent appointments are sized to be
%          accurate to the minute.  In other words, if you have two
%          appointments, one 52 minutes long and the other 53 minutes long, the
%          box representing the second appointment will be slightly longer.
%
%    \item The schedule is typeset in a centered displayed environment.
% \end{enumerate}
%
% \section{User Commands}
%
% \begin{macro}{\CellHeight}
% Including |\CellHeight|\meta{length} before the \textsf{schedule} environment
% tells \LaTeXe\ what height to make the cells in the schedule (all cells have
% the same height).  Since a
% cell corresponds to an hour in the schedule, this command allows the user to
% specify how much vertical space a single hour ought to take up.
% \end{macro}
%
% \begin{macro}{\CellWidth}
% Including |\CellWidth|\meta{width} before the \textsf{schedule} environment
% tells \LaTeXe\ how wide to make every cell in the schedule.  The overall
% width of the schedule is determined by multiplying this value by the number of
% days (set by the |\FiveDay| or |\SevenDay| command), plus the width of the
% time labels on the left-hand side.
% \end{macro}
%
% \begin{macro}{\TimeRange}
% This command must appear before the \textsf{schedule} environment, otherwise
% \LaTeXe\ will not know how deep to make the grid.  It is important to note
% that the time range is specified using a 24-hour format, with a \emph{single}
% hyphen between the two times.  Deviating from this format will generate an
% error.
% \end{macro}
%
% \begin{macro}{\SubUnits}
% The |\SubUnits|\meta{number} tells the package how to subdivide the hour.  If
% one does not want any subdivisions, simply use |\SubUnits{60}|.  The value of
% \meta{number} can be any number than evenly divides 60.  It is assumed that,
% in specifying this value, you know what you are doing: i.e., if you tell
% \LaTeXe\ to use a |\CellHeight| of 1in, but then set |\SubUnits{3}|, you will
% get 20 subdivisions (with times) in a cell only 1in high.  In other words, the
% text on the left-hand side of the schedule will be typeset as a horrible mess.
% The solution is simple: if you want a large number of subdivisions, simply set
% |\CellHeight| to a greater value.
% \end{macro}
%
% \begin{macro}{\BeginOn}
% Including |\BeginOn|\meta{day} tells \LaTeX\ what day of the week to start
% the schedule on.  The possible values are `Sunday', `Monday', `Tuesday', `Wednesday',
% `Thursday', `Friday', or `Saturday'.  My apologies for non-English speaking
% users of \LaTeX.  If there is a demand for it, I will fix this in future
% releases.
% \end{macro}
%
% \begin{macro}{\TextSize}
% With the |\TextSize|\meta{font-size} command, the user tells \LaTeX\ what
% size font to use when typesetting the text inside the boxes.  This command
% ought to be one of the standard \LaTeX\ font-size commands, e.g., |\tiny|,
% |\scriptsize|, etc.  Using two large of a font will almost always result in
% bad line breaks inside the boxes, though, due to the narrow width of a cell.
% \end{macro}
%
% \begin{macro}{\FiveDay}
% Tells \LaTeX\ to typeset a five-day schedule.
% \end{macro}
%
% \begin{macro}{\SevenDay}
% Tells \LaTeX\ to typeset a seven-day schedule.
% \end{macro}
%
% \begin{macro}{\NewAppointment}
% By using the |\NewAppointment| command, the user can customize the appearance
% of the schedule by changing the color of the text or the background color.
% The syntax is |\NewAppointment|\meta{appointment-name}\meta{background-color}\meta{text-color}.
% \end{macro}
%
% \StopEventually{}
%\newpage
%\section{Source Code}
% \iffalse
%<*package> 
% \fi
%    \begin{macrocode}
\ProvidesFile{schedule.sty}
\NeedsTeXFormat{LaTeX2e}[2005/12/01]
\ProvidesPackage{schedule}[2019/7/26 v1.10 schedule package]
\RequirePackage{calc}
\RequirePackage{xcolor}
\definecolor{dark}{gray}{.75}
%
% CONSTANTS FOR THE WEEK
%
\def\@sunday{Su}
 \def\@Sunday{Sunday}
\def\@monday{M}
 \def\@Monday{Monday}
\def\@tuesday{T}
 \def\@Tuesday{Tuesday}
\def\@wednesday{W}
 \def\@Wednesday{Wednesday}
\def\@thursday{Th}
 \def\@Thursday{Thursday}
\def\@friday{F}
 \def\@Friday{Friday}
\def\@saturday{Sa}
 \def\@Saturday{Saturday}
%
% COUNTERS, LENGTHS, ETC.
%
\newlength{\cell@height}
 \setlength{\cell@height}{1in}
\newlength{\cell@width}
 \setlength{\cell@width}{1in}
\newlength{\box@depth}
\newcounter{sch@col@width} \setcounter{sch@col@width}{60}
\newlength{\box@width}
 \setlength{\box@width}{1in*(\value{sch@col@width}/60)}
\newlength{\col@width}
 \setlength{\col@width}{1in*(\value{sch@col@width}/60)}
\newlength{\sch@depth} \setlength{\sch@depth}{9in}
\newlength{\fill@length}
\newlength{\@temp@length}
\newlength{\@@temp@length}
\newlength{\line@thickness} % The thickness of the lines in the drawing
 \setlength{\line@thickness}{.4pt}
\newlength{\adjusted@cell@width}
\newlength{\adjusted@cell@height}

\newcounter{picture@units@wide}
\newcounter{xcoords}
\newcounter{ycoords}
\newcounter{timea}
\newcounter{timeb}
\newcounter{grid@width}
\newcounter{grid@height}
\newcounter{number@of@cells} % The number of VERTICAL cells
\newcounter{number@of@subcells}
\newcounter{number@of@days} % The number of days in the grid
\newcounter{dp@vlines} % The number of vertical lines actually needed is
                       % \value{number@of@days} + 1 ...
\newcounter{dp@hlines} % The number of horizontal lines actually needed is
                       % \value{number@of@cells} + 1 ...
\newcounter{dp@hcell@lines} % The number of horizontal lines that are
                       % either (1) associated with an hour, or
                       %        (2) on the top or bottom of the grid.
\newcounter{pu@cell@width}
\newcounter{pu@cell@height}
 \setcounter{pu@cell@height}{60}
\newcounter{pu@grid@top}
\newcounter{pu@grid@width}
\newcounter{pu@subticks}
\newcounter{start@time}
\newcounter{end@time}
\newcounter{x@coord} % Temporary x-coordinate
\newcounter{y@coord} % Temporary y-coordinate
\newcounter{@tempc}
\newcounter{@tempd}
\newcounter{label@sep}  % distance from label to gride
 \setcounter{label@sep}{5} %initialized to 5 picture units

\newcounter{x@Sunday}
\newcounter{x@Monday}
\newcounter{x@Tuesday}
\newcounter{x@Wednesday}
\newcounter{x@Thursday}
\newcounter{x@Friday}
\newcounter{x@Saturday}

\newsavebox{\temp@box}
\newif\ifweekends
\newcount\@i
\newcount\@j

\def\TimeRange#1{\compute@number@of@cells #1\end@compute}
\def\compute@number@of@cells#1:#2-#3:#4\end@compute{%
  \setcounter{number@of@cells}{#3-#1}%
  \setcounter{start@time}{#1}%
  \setcounter{end@time}{#3}}

\def\TextSize#1{\def\appt@textsize{#1}}
\TextSize{\scriptsize}

\def\IncludeWeekends{\weekendstrue}
\def\NoWeekends{\weekendsfalse}

\def\SevenDay{\weekendstrue}
\def\FiveDay{\weekendsfalse}

\def\CellHeight#1{\setlength{\cell@height}{#1}%
                  \setlength{\unitlength}{\cell@height*\ratio{1pt}{60pt}}}
\def\CellWidth#1{\setlength{\cell@width}{#1}%
                 \setcounter{pu@cell@width}{1*\ratio{\cell@width}{\unitlength}}}
\def\SubUnits#1{\setcounter{pu@subticks}{#1}%
                \setcounter{number@of@subcells}{60/\value{pu@subticks}}}

\def\calculate@grid@dimensions{%
  \ifweekends \setcounter{number@of@days}{7}
   \else \setcounter{number@of@days}{5}%
    \fi%
  \setcounter{dp@hcell@lines}{\value{number@of@cells}+1}
  \setcounter{grid@width}{\value{number@of@days}*\value{pu@cell@width}}%
  \setcounter{grid@height}{\value{number@of@cells}*60}
  \setcounter{dp@vlines}{\value{number@of@days}+1}
  \setcounter{dp@hlines}{\value{number@of@cells}*(60/\value{pu@subticks}) + 1}}


\def\draw@grid{%\calculate@grid@dimensions
  \linethickness{.2pt}%
  \multiput(0,0)(0,\value{pu@subticks}){\value{dp@hlines}}{\line(1,0){\value{grid@width}}}%
  \thicklines
  \multiput(0,0)(0,60){\value{dp@hcell@lines}}{\line(1,0){\value{grid@width}}}
  \thinlines}

\def\LineThickness#1{\setlength{\line@thickness}{#1}%
                     \linethickness{\line@thickness}%
                     \setlength{\adjusted@cell@width}{\cell@width - 1\line@thickness}
                     \setlength{\adjusted@cell@height}{\cell@height - 1\line@thickness}}


\def\@Su@week{{Sunday} {Monday} {Tuesday} {Wednesday} {Thursday} {Friday} {Saturday}}
\def\@M@week{{Monday} {Tuesday} {Wednesday} {Thursday} {Friday} {Saturday} {Sunday}}
\def\@T@week{{Tuesday} {Wednesday} {Thursday} {Friday} {Saturday} {Sunday} {Monday}}
\def\@W@week{{Wednesday} {Thursday} {Friday} {Saturday} {Sunday} {Monday} {Tuesday}}
\def\@Th@week{{Thursday} {Friday} {Saturday} {Sunday} {Monday} {Tuesday} {Wednesday}}
\def\@F@week{{Friday} {Saturday} {Sunday} {Monday} {Tuesday} {Wednesday} {Thursday}}
\def\@Sa@week{{Saturday} {Sunday} {Monday} {Tuesday} {Wednesday} {Thursday} {Friday}}

\def\BeginOn#1{\def\start@day{#1}}

\def\add@labels{%
 \ifx\start@day\@Sunday \expandafter\do@days\@Su@week \relax
  \else\ifx\start@day\@Monday \expandafter\do@days\@M@week \relax
   \else\ifx\start@day\@Tuesday \expandafter\do@days\@T@week \relax
    \else\ifx\start@day\@Wednesday \expandafter\do@days\@W@week \relax
     \else\ifx\start@day\@Thursday \expandafter\do@days\@Th@week \relax
      \else\ifx\start@day\@Friday \expandafter\do@days\@F@week \relax
       \else\expandafter\do@days\@Sa@week \relax
    \fi\fi\fi\fi\fi\fi}


\def\@sfor #1:=#2 \upto #3 \step #4 \do #5{%
  #1=#2\relax%
  \@whilenum #1<#3 \do {#5 \advance#1 by #4}#5}

\def\add@times{%
  \setcounter{@tempc}{\value{start@time}}%
  \@sfor \@i :=0 \upto \value{number@of@cells} \step 1 \do%
    {\setcounter{x@coord}{0}%                               Set the x-coord right
     \setcounter{y@coord}{\value{grid@height}-60*\@i}%      adjust for the right hour cell
     \ifnum\value{@tempc}=0%
        \setcounter{@tempd}{\value{@tempc}+12}%
         \put(\value{x@coord},\value{y@coord}){%
         \makebox(0,0)[r]{\the@tempd:00 midnight\ }}% Midnight Hack
     \else\ifnum\value{@tempc}=24%
        \setcounter{@tempd}{\value{@tempc}-12}%
         \put(\value{x@coord},\value{y@coord}){%
         \makebox(0,0)[r]{\the@tempd:00 midnight\ }}% Midnight Hack
     \else\ifnum\value{@tempc}>12%
        \setcounter{@tempd}{\value{@tempc}-12}%
        \put(\value{x@coord},\value{y@coord}){%
         \makebox(0,0)[r]{\the@tempd:00 pm\ }}%
     \else\ifnum\value{@tempc}=12%
        \setcounter{@tempd}{\value{@tempc}}%
          \put(\value{x@coord},\value{y@coord}){%
           \makebox(0,0)[r]{\the@tempd:00 noon\ }}% Noontime Hack
     \else\put(\value{x@coord},\value{y@coord}){%
      \makebox(0,0)[r]{\the@tempc:00 am\ }}%
     \fi\relax%
     \fi\relax%
     \fi\relax%
     \fi\relax%
     \@sfor \@j := \value{pu@subticks} \upto 59 \step \value{pu@subticks} \do%
       {\ifnum\@i=\value{number@of@cells}%  Test to see if this should be the last label
           \relax%
        \else%
           \ifnum\@j=60%
             \relax%
           \else%
             \ifnum\@j<10%
               \def\the@minutes{0\the\@j}%
             \else\def\the@minutes{\the\@j}%
             \fi%
             \setcounter{y@coord}{\value{y@coord}-\@j}%
             \ifnum\value{@tempc}=0%
                \setcounter{@tempd}{\value{@tempc}+12}%
                \put(\value{x@coord},\value{y@coord}){%
                 \makebox(0,0)[r]{\tiny\the@tempd:\the@minutes\ am\ }}% Hack to get 12:xx AM right.
             \else\ifnum\value{@tempc}=24%
                \setcounter{@tempd}{\value{@tempc}-12}%
                \put(\value{x@coord},\value{y@coord}){%
                 \makebox(0,0)[r]{\tiny\the@tempd:\the@minutes\ am\ }}% Hack to get 12:xx AM right.
             \else\ifnum\value{@tempc}>12%
                \setcounter{@tempd}{\value{@tempc}-12}%
                \put(\value{x@coord},\value{y@coord}){%
                 \makebox(0,0)[r]{\tiny\the@tempd:\the@minutes\ pm\ }}% ...write the time (using pm)...
             \else\ifnum\value{@tempc}=12%
                \setcounter{@tempd}{\value{@tempc}}%
                \put(\value{x@coord},\value{y@coord}){%
                 \makebox(0,0)[r]{\tiny\the@tempd:\the@minutes\ pm\ }}% Hack to get 12:xx PM right.
             \else\put(\value{x@coord},\value{y@coord}){%
              \makebox(0,0)[r]{\tiny\the@tempc:\the@minutes\ am\ }}% ...write the time (using am).
             \fi%
             \fi%
     \fi%
           \fi%
        \fi%
        \fi%
        \setcounter{y@coord}{\value{y@coord}+\@j}}
     \addtocounter{@tempc}{1}}}%

\def\do@days#1#2#3#4#5#6#7{%
  \setcounter{x@coord}{1*\ratio{\value{pu@cell@width} pt}{2 pt}}%
  \setcounter{y@coord}{\value{grid@height}+\value{label@sep}}%
  \put(\value{x@coord},\value{y@coord}){\makebox(0,0)[b]{\large #1}}%
  \setcounter{x@coord}{\value{x@coord}+\value{pu@cell@width}}%
  \put(\value{x@coord},\value{y@coord}){\makebox(0,0)[b]{\large #2}}%
  \setcounter{x@coord}{\value{x@coord}+\value{pu@cell@width}}%
  \put(\value{x@coord},\value{y@coord}){\makebox(0,0)[b]{\large #3}}%
  \setcounter{x@coord}{\value{x@coord}+\value{pu@cell@width}}%
  \put(\value{x@coord},\value{y@coord}){\makebox(0,0)[b]{\large #4}}%
  \setcounter{x@coord}{\value{x@coord}+\value{pu@cell@width}}%
  \put(\value{x@coord},\value{y@coord}){\makebox(0,0)[b]{\large #5}}%
  \setcounter{x@coord}{\value{x@coord}+\value{pu@cell@width}}%
  \ifweekends
  \put(\value{x@coord},\value{y@coord}){\makebox(0,0)[b]{\large #6}}%
  \setcounter{x@coord}{\value{x@coord}+\value{pu@cell@width}}%
  \put(\value{x@coord},\value{y@coord}){\makebox(0,0)[b]{\large #7}}\fi}


\def\set@x@coords@for@days{%
  \ifx\start@day\@Sunday%
    \@i=0\relax%
    \@tfor \@temp := {Sunday} {Monday} {Tuesday} {Wednesday} {Thursday} {Friday} {Saturday} \do%
      {\setcounter{x@\@temp}{\@i*\value{pu@cell@width}}%
       \advance\@i by 1}
    \def\skipday@i{F}
    \def\skipday@ii{Sa}\fi
  \ifx\start@day\@Monday
    \@i=0\relax%
    \@tfor \@temp := {Monday} {Tuesday} {Wednesday} {Thursday} {Friday} {Saturday} {Sunday} \do%
      {\setcounter{x@\@temp}{\@i*\value{pu@cell@width}}%
       \advance\@i by 1}
    \def\skipday@i{Sa}
    \def\skipday@ii{Su}\fi
  \ifx\start@day\@Tuesday
    \@i=0\relax%
    \@tfor \@temp := {Tuesday} {Wednesday} {Thursday} {Friday} {Saturday} {Sunday} {Monday} \do%
      {\setcounter{x@\@temp}{\@i*\value{pu@cell@width}}%
       \advance\@i by 1}
    \def\skipday@i{Su}
    \def\skipday@ii{M}\fi
  \ifx\start@day\@Wednesday
    \@i=0\relax%
    \@tfor \@temp := {Wednesday} {Thursday} {Friday} {Saturday} {Sunday} {Monday} {Tuesday} \do%
      {\setcounter{x@\@temp}{\@i*\value{pu@cell@width}}%
       \advance\@i by 1}
    \def\skipday@i{M}
    \def\skipday@ii{T}\fi
  \ifx\start@day\@Thursday
    \@i=0\relax%
    \@tfor \@temp := {Thursday} {Friday} {Saturday} {Sunday} {Monday} {Tuesday} {Wednesday} \do%
      {\setcounter{x@\@temp}{\@i*\value{pu@cell@width}}%
       \advance\@i by 1}
    \def\skipday@i{T}
    \def\skipday@ii{W}\fi
  \ifx\start@day\@Friday
    \@i=0\relax%
    \@tfor \@temp := {Friday} {Saturday} {Sunday} {Monday} {Tuesday} {Wednesday} {Thursday} \do%
      {\setcounter{x@\@temp}{\@i*\value{pu@cell@width}}%
       \advance\@i by 1}
    \def\skipday@i{W}
    \def\skipday@ii{Th}\fi
  \ifx\start@day\@Saturday
    \@i=0\relax%
    \@tfor \@temp := {Saturday} {Sunday} {Monday} {Tuesday} {Wednesday} {Thursday} {Friday} \do%
      {\setcounter{x@\@temp}{\@i*\value{pu@cell@width}}%
       \advance\@i by 1}
    \def\skipday@i{Th}
    \def\skipday@ii{F}\fi
  }

% ------------------------------------------------------------------------
% Commands to insert info about an appointment
% ------------------------------------------------------------------------
\newif\ifset@start@time
\newif\ifset@end@time
\newif\ifsetboxdepth
\newif\ifinrange

\def\NewAppointment#1#2#3{% #1 = name, #2 = background color, #3 = textcolor
  \expandafter\def\csname #1\endcsname##1##2##3##4{%
     \setboxdepthtrue% assume we want to calculate the box depth
     \inrangetrue% assume the appt is in range
     \set@start@timetrue% assume we want to calculate the start time
     \set@end@timetrue% assume we want to calculate the end time
     \@includetrue% assume we will include it
     \edef\appt@name{#1}% save the appt name
     \edef\appt@color{#2}% save the background color
     \edef\appt@textcolor{#3}% save the save color
     \expandafter\def\csname #1@name\endcsname{##1}% save the name
     \expandafter\def\csname #1@location\endcsname{##2}% save the loc.
     \expandafter\def\csname #1@days\endcsname{##3}% save the days
     \expandafter\def\csname #1@time\endcsname{##4}% save the time
     \place@appt@box##3,\stop}}

\NewAppointment{class}{dark}{black}

\def\place@appt@box#1{%
  \ifx#1\stop \let\@next=\@gobble%
   \else \let\@next=\set@x@coords\fi\@next#1}

\def\set@x@coords#1,{\def\the@day{#1}%
 \ifx\the@day\@sunday\setcounter{xcoords}{\value{x@Sunday}}%
  \else\ifx\the@day\@monday\setcounter{xcoords}{\value{x@Monday}}%
   \else\ifx\the@day\@tuesday\setcounter{xcoords}{\value{x@Tuesday}}%
    \else\ifx\the@day\@wednesday\setcounter{xcoords}{\value{x@Wednesday}}%
     \else\ifx\the@day\@thursday\setcounter{xcoords}{\value{x@Thursday}}%
      \else\ifx\the@day\@friday\setcounter{xcoords}{\value{x@Friday}}%
       \else\setcounter{xcoords}{\value{x@Saturday}}%
        \fi\fi\fi\fi\fi\fi%
         \edef\@@temp{\csname \appt@name @time\endcsname}%
          \expandafter\set@y@coords\@@temp\stop}

\def\set@y@coords#1:#2-#3:#4\stop{%
  \def\@starthour{#1}%
  \def\@startminutes{#2}
  \def\@endhour{#3}%
  \def\@endminutes{#4}%
  \ifnum#1<\value{start@time} \setcounter{ycoords}{\value{grid@height}}%
                              \edef\@starthour{\value{start@time}}
                              \def\@startminutes{0}
                              \set@start@timefalse%
                              \fi%
  \ifnum#3<\value{end@time} \relax%
    \else \edef\@endhour{\value{end@time}}
          \def\@endminutes{0}%
          \setcounter{ycoords@bot}{0}
          \set@end@timefalse
  \fi %
  \ifset@start@time%
   \setcounter{ycoords}{\value{grid@height}-(60*(#1-\value{start@time})+#2)}\fi%
  \ifset@end@time%
    \setcounter{ycoords@bot}{\value{grid@height}-(60*(#3-\value{start@time})+#4)}\fi%
  \setlength{\box@depth}{\@endhour\cell@height + (\cell@height*\ratio{\@endminutes pt}{60pt}) %
         - \@starthour\cell@height - (\cell@height*\ratio{\@startminutes pt}{60pt})}%
  \ifnum#1<\value{end@time} \relax\else \inrangefalse \fi%
  \draw@appt@box\place@appt@box}

\newif\if@include

\def\draw@appt@box{%
   \ifweekends \relax % if we use 7-days, this won't change
   \else \ifx \the@day\skipday@i \@includefalse \fi % first condition for change
         \ifx \the@day\skipday@ii \@includefalse \fi\fi % second condition for change
  \ifinrange \relax\else \@includefalse \fi %
  \if@include %
  \put(\value{xcoords},\value{ycoords}){\colorbox{\appt@color}{\parbox[t]{\cell@width}{\ %
        \vspace{\box@depth}}}}
  \thinlines
  \put(\value{xcoords},\value{ycoords}){\line(1,0){\value{pu@cell@width}}}
  \put(\value{xcoords},\value{ycoords@bot}){\line(1,0){\value{pu@cell@width}}}
  \put(\value{xcoords},\value{ycoords}){%
        \  \parbox[t]{\cell@width-8pt}{\mbox{}\\ \appt@textsize %
        \ifdim\box@depth>\baselineskip
        \textcolor{\appt@textcolor}{\csname \appt@name @name\endcsname} \\ %
        \ifdim\box@depth>2\baselineskip
        \textcolor{\appt@textcolor}{\csname \appt@name
        @location\endcsname}\fi\fi }}\fi}

\def\convert@class@time#1:#2-#3:#4\end@time{%
  {\count1=#1\relax%
   \count3=#3\relax%
   \ifnum#1>12 \advance\count1 by -12\fi\relax%
   \ifnum#3>12 \advance\count3 by -12\fi\relax%
   \ifnum#1<12\relax%
    \ifnum#3<12\relax \mbox{\the\count1:#2am--\the\count3:#4am}\relax%
     \else \mbox{\the\count1:#2am--\the\count3:#4pm}\fi\relax%
      \else \mbox{\the\count1:#2pm--\the\count3:#4pm}\fi\relax}}

\def\compute@box@depth#1:#2-#3:#4\end@bx{%
  \setlength{\box@depth}{#3\cell@height + (\cell@height*\ratio{#4pt}{60pt}) %
         - #1\cell@height - (\cell@height*\ratio{#2pt}{60pt})}}

\newcounter{ycoords@bot}

\newcounter{x@tempa}
\newcounter{x@tempb}
\newcounter{y@tempa}
\newcounter{y@tempb}
\newcounter{temp@cnt@a}

\newlength{\title@height}
\newlength{\label@height}
 \settoheight{\label@height}{Wednesday}

\newcounter{pu@label@width}
\newlength{\center@hack}

\newenvironment{schedule}[1][:]%
{\bigskip
 \calculate@grid@dimensions%
 \setcounter{pu@grid@width}{\value{pu@cell@width}*\value{number@of@days}}%
 \settowidth{\@temp@length}{\normalsize 12:00\ pm\ }%
 \setcounter{pu@label@width}{1*\ratio{\@temp@length}{\unitlength}}%
 \setcounter{pu@grid@top}{\value{grid@height}+(1*\ratio{\label@height}{\unitlength}) + %
    (1*\ratio{.25in}{\unitlength})}%
 \if#1:\relax \else%
  \settoheight{\title@height}{\large #1}%
  \addtocounter{pu@grid@top}{1*\ratio{\title@height}{\unitlength}}%
 \fi%
 \setlength{\center@hack}{(.5\linewidth-.5\unitlength*\value{pu@grid@width}+%
   .5\unitlength*\value{pu@label@width})}%
 \noindent\hspace*{\center@hack}%
 \begin{picture}(\value{pu@grid@width},\value{pu@grid@top})%
 \draw@grid
 \add@labels
 \if#1:\relax \else
  \setcounter{ycoords}{\value{grid@height}+(1*\ratio{\label@height}{\unitlength}) + %
     (1*\ratio{.25in}{\unitlength})}
  \setcounter{xcoords}{1*\ratio{\value{pu@grid@width} pt}{2 pt}}
 \put(\value{xcoords},\value{ycoords}){\makebox(0,0)[b]{\Large #1}}
 \fi
 \add@times
 \set@x@coords@for@days}
{\multiput(0,0)(\value{pu@cell@width},0){\value{dp@vlines}}{\line(0,1){\value{grid@height}}}
 \end{picture}\bigskip}

\setlength{\fboxsep}{0in}
%    \end{macrocode} 
% \iffalse
%</package> 
% \fi
% \newpage
% \PrintChanges
% \PrintIndex
% \Finale