%                       Calendar Style
%
%               Author: C. E. Chew
%               Date:   May 1989
%
% This style file contains the calendar generating macros for LaTeX.
% The following macros are defined:
%
%       \DayOfWeek      computed the day of week
%       \Calendar       generate a box contained a calendar
%       \date           mark a date with an event
%
% Patchlevel 1.1
%
% Edit History:
%
% 04-Dec-1989   Corrected \lc computation bug. Allow 6 week months.
% 11 Aug 1989   Updated for release
%
\typeout{Calendar Style  Version 1.1 May 1989}%
% The \dow macro computes the day of the week for a given date.
% The arguments are:
%
%       #1      day 1..31
%       #2      month 1..12
%       #3      year
%
% The result in returned in \dow with 0=Sunday and 6=Saturday.
%
\newcount\dow%                          day of week
\def\DayOfWeek#1#2#3{{%
\def\Day{\count0 }\def\Month{\count2 }\def\Year{\count4 }\def\Century{\count6 }%
\Day=#1 \Month=#2 \Year=#3 %
\advance\Month by-2 %
\ifnum\Month<1 \advance\Month by12 \advance\Year by-1 \fi%
\Century=\Year \divide\Century by100 \multiply\Century by-100 %
\advance\Year by\Century \divide\Century by100 %
\dow=\Month \multiply\dow by26 \advance\dow by-2 \divide\dow by10 %
\advance\dow by\Day \advance\dow by\Year%
\advance\dow by\Century \advance\dow by\Century%
\divide\Century by-4 \advance\dow by\Century%
\divide\Year by4 \advance\dow by\Year%
\count255=\dow \divide\count255 by7 \multiply\count255 by-7 %
\advance\dow by\count255 %
\ifnum\dow<0 \advance\dow by7 \fi%
\global\dow=\dow%
}}%
%
% The \Calendar macro prints a the calendar for one month on
% one page. The arguments are:
%
%       #1      month 1=January 12=December
%       #2      year
%       #3      size of calendar entries --- empty if not required
%       #4      size of header
%       #5      format for tabular environment
%       #6      days of week header, this should be consister with #5
%               and should probably use \horizontal in place of \hline
%       #7      \iftrue to print horizontal lines: this causes \horizontal
%               to be defined as \hline or \empty
%       #8      height of vbox --- only used if #3 is not empty
%       #9      \iftrue to print 6 week months
%
\newcount\ld%                   last day in month
\newcount\td%                   today --- first day of month
\newcount\w%                    number of weeks in this month
\newcount\lc%                   number of days in last week
\newdimen\baseskip%             saved baseline skip
\newdimen\digitheight%          how high to make the digits
%
\def\Calendar#1#2#3#4#5#6#7#8#9{{%
%
% Remember the size of calendar entries.
%
\def\entrysize{#3}%
%
% Determine the size of the digits.
%
\setbox0=\hbox{0123456789}%
\digitheight=1\tabcolsep \advance\digitheight by\ht0 %
%
% Remember \baselineskip
%
\baseskip=1\baselineskip%
%
% Compute the number of days in this month. The result is left in
% \ld.
%
\ifcase#1 %
\or\def\name{Januar}\ld=31 %
\or\def\name{Februar}\ld=28 %
   \count0=#2 \divide\count0 by4 \multiply\count0 by4 %
   \ifnum\count0=#2 \count0=#2 \divide\count0 by100 \multiply\count0 by100 %
     \ifnum\count0=#2 \count0=#2 \divide\count0 by400 \multiply\count0 by400 %
       \ifnum\count0=#2 \ld=29 %
       \fi%
     \else \ld=29 %
     \fi%
   \fi%
\or\def\name{Maerz}\ld=31 %
\or\def\name{April}\ld=30 %
\or\def\name{Mai}\ld=31 %
\or\def\name{Juni}\ld=30 %
\or\def\name{Juli}\ld=31 %
\or\def\name{August}\ld=31 %
\or\def\name{September}\ld=30 %
\or\def\name{Oktober}\ld=31 %
\or\def\name{November}\ld=30 %
\or\def\name{Dezember}\ld=31 \fi%
\expandafter\lowercase\expandafter{%
                       \expandafter\def\expandafter\lname\expandafter{\name}}%
%\showthe\ld%
%
% Compute the day of the week on which the 1st of this month
% begins. The answer is left in \td with 0=Sunday and 6=Saturday.
%
\DayOfWeek{1}{#1}{#2}\td=\dow%
%
% Compute the last day in the month. Leave the answer in \lc with
% 1=Sunday 7=Saturday. This enumeration differs from \td since
% \lc is used later for \cline.
%
\lc=\ld \advance\lc by\td \advance\lc by-1 \divide\lc by7 \multiply\lc by-7 %
\advance\lc by\ld \advance\lc by\td%
%\showthe\lc%
%
% Compute the number of weeks in the month. This is used to set
% up the \weekx macros. It is not possible to do this on the fly
% within the tabular environment since it introduces empty columns.
%
\w=\ld \advance\w by\td \advance\w by6 \divide\w by7 %
\ifnum\w>0 \def\weeki{\oneweek}\else\def\weeki{}\fi \advance\w by-1 %
\ifnum\w>0 \def\weekii{\oneweek}\else\def\weekii{}\fi \advance\w by-1 %
\ifnum\w>0 \def\weekiii{\oneweek}\else\def\weekiii{}\fi \advance\w by-1 %
\ifnum\w>0 \def\weekiv{\oneweek}\else\def\weekiv{}\fi \advance\w by-1 %
\ifnum\w>0 \def\weekv{\oneweek}\else\def\weekv{}\fi \advance\w by-1 %
#9\ifnum\w>0 \def\weekvi{\oneweek}\else\def\weekvi{}\fi \advance\w by-1 \fi%
%
% Compute the weekday of the Sunday before the 1st of the month. The
% result not taken mod 7 and will not be positive.
%
\multiply\td by-1 \advance\td by1 %
%
% Process today's date looking for any significant events.
%
\def\dotoday{\ifx\entrysize\empty \the\td%
             \else \vbox to#8{\vrule height\digitheight width0pt depth0pt%
                   \the\td%
                   \vfill%
                   #3\raggedright%
                   \csname\lname\romannumeral\the\td\endcsname%
                   \vbox{}%
                   }\fi}%
%
% This macro will process one day of the calendar. It will then
% advance the day counter.
%
\def\oneday{%
\ifnum\td>0 %
  \ifnum\td>\ld \multicolumn{1}{}{}\else \dotoday \fi%
\else%
  #9%
  \else%
    \global\advance\td by35 %
    \ifnum\td>\ld \else \dotoday \fi%
    \global\advance\td by-35 %
  \fi%
\fi%
\global\advance\td by1 %
}%
%
% This macro will process one week of the calendar. This assumes that
% there will be at least one non-empty day in the week. If this is
% the last week, only the week up until the last day is printed.
%
\def\oneweek{%
\oneday & \oneday & \oneday & \oneday & \oneday & \oneday & \oneday \\
#7\ifnum\td>\ld\cline{1-\the\lc}\else\hline\fi\fi%
}%
%
% Set the macro to print horizontal lines
%
#7\def\horizontal{\hline}\else\let\horizontal=\empty \fi
%
% Print the calendar for this month
%
\begin{tabular}{#5}
\multicolumn{7}{c}{#4 \name\ #2} \\[1\baseskip] \horizontal
#6
\weeki \weekii \weekiii \weekiv \weekv #9 \weekvi \fi
\end{tabular}}}
%
% The \date macro allows the user to declare events on particular
% days. The arguments are:
%
%       #1              the month (eg January) --- not case sensitive
%       #2              the day
%       #3              text for the event
%
\def\date#1#2#3{{\lowercase{\def\ldate{#1}}%
                \expandafter\gdef\csname\ldate\romannumeral #2 \endcsname{#3}}}%
