% This macro source file is from the four volume series
% "TeX in Practice" by Stephan von Bechtolsheim, published
% 1993 by Springer-Verlag, New York.
% Copyright 1993 Stephan von Bechtolsheim.
% No warranty or liability is assumed.
% This macro may be copied freely if no fees other than
% media cost or shipping charges are charged and as long
% as this copyright and the following source code itself
% is not changed. Please see the series for further information.
%
% Version: 1.0
% Date: May 1, 1993
%
%
% This source code is documented in 26.19, p. III-385.
% Original source in file "macros6.TEX", starting line 1327.
\wlog{L: "mocal.tip" ["macros6.TEX," l. 1327, p. III-385]}%
% This file DOES belong to format "texip."
\InputD{dateofw.tip}
\InputD{doloop.tip}
\InputD{arbday.tip}
\InputD{nextday.tip}
\InputD{numdyr.tip}
\InputD{prmonth.tip}
\catcode`\@ = 11
\newcount\@InitialDayOfMonth
\newcount\@MCDays
\newcount\@MonthlyCalendarBodyTemp
\def\MonthlyCalendarBody #1#2#3{%
   {%
       \CheckDate{#1}{#2}{1}%
       \ArbitraryDayOfWeek{#1}%
           {#2}{1}{\@InitialDayOfMonth}%
       \gdef #3{}%
       \DoLoop{\@MonthlyCalendarBodyTemp}%
           {1}{1}{\@InitialDayOfMonth}%
           {\xdef#3{#3&}}
       \NumberOfDaysInMonth{#1}{#2}{\@MCDays}%
       \DoLoop{\@MonthlyCalendarBodyTemp}{1}{1}{\@MCDays}{%
           \xdef#3{#3\the\@MonthlyCalendarBodyTemp}%
           \ifnum\@InitialDayOfMonth = \Saturday
               \xdef#3{#3\cr}%
           \else
               \xdef#3{#3&}%
           \fi
           \advance\@InitialDayOfMonth by 1
           \IModN{\@InitialDayOfMonth}{7}{\@InitialDayOfMonth}%
       }%
   }%
   \xdef#3{#3\crcr}%
}
\newcount\@MonthlyCalendarCount
\def\MonthlyCalendar #1#2#3{%
   {%
       \MonthlyCalendarBody{#1}{#2}{\TableBody}%
       \vtop{
           \hsize = #3\relax
           \ProvideMonth{#2}{0}{\MonthNameTemp}%
           \@MonthlyCalendarCount = #1\relax
           \centerline{\MyStrut\MonthNameTemp\space
               \the\@MonthlyCalendarCount}%
           \smallskip
           \hrule
           \smallskip
                               \tabskip = 0pt
           \halign to \hsize{
                                   % So
               \hfil##\relax   \tabskip = 0pt plus 1fil&
               \hfil##&            % Mo
               \hfil##&            % Tu
               \hfil##&            % We
               \hfil##&            % Th
               \hfil##&            % Fr
               \hfil##\relax   \tabskip = 0pt
           \cr
               \omit\hfil So\hfil&
               \omit\hfil Mo\hfil&
               \omit\hfil Tu\hfil&
               \omit\hfil We\hfil&
               \omit\hfil Th\hfil&
               \omit\hfil Fr\hfil&
               \omit\hfil Sa\hfil\cr
               \TableBody
           }%
           \smallskip
           \hrule
       }%
   }%
}%
\catcode`\@ = 12