\input literate

Comment

   Calendar-generating macros in TeX.
   by Andrew Marc Greene
   Student Information Processing Board, MIT
   <amgreene@mit.edu>

EndComment

%
% Here are the declarations of how large to make each calendar.
%

Dimen CalendarWidth  = 6.5in;
Dimen CalendarHeight = 4in;

% Here are the font declarations for date numbers and notes.

Font datenumfont = cmssbx10 scaled \magstep 4;
Font notefont = cmssq8;
Font smalldatenumfont = cmss10;
Font titlef = cmbx10 scaled \magstep 2;

% Here are the commands that set TeX's parameters for
% calendar-setting.

Define calendar:
  \begingroup
  \boxwidth = 0.1428571\CalendarWidth
  \boxheight = 0.2\CalendarHeight
  \parindent=0pt
  \parskip=0pt
  \hbadness=10000
  \baselineskip=0pt  % Pack it as closely as you can!
EndDefine

Define endcalendar:
  \endgroup
EndDefine

Comment
  Here are the TeX registers used for the actual setting of calendars.
  Date contains the date of the NEXT box.
  Day contains the day of the week (0=Sun)
  OnDate is the next ``interesting date.''
  boxwidth and boxheight are the size of each date's box.
  boxrulewid is the width of the rules that form the grid.
  TopNotes is the box that accumulates the notes for the top of boxes.
  BotNotes is the box that accumulates the notes for the bottom of boxes.
EndComment

Int   Date, Day, OnDate;
Dimen boxwidth   = 0.1428571\CalendarWidth;
Dimen boxheight  = 0.2\CalendarHeight;
Dimen boxrulewid = 1.5pt;
Box   TopNotes, BotNotes;

Define DayBox:
  \hbox{\vsize=\boxheight \hsize=\boxwidth \relax
  \vrule width -\boxrulewid \relax
  \vrule width \boxrulewid \relax
  \vrule width -1sp \relax
    \vbox to \vsize{\vsize=\boxheight \hsize=\boxwidth \relax
    \hrule height \boxrulewid \relax
    \vskip \boxrulewid
    \hbox to \hsize{\vtop{\null\hbox{\datenumfont\number\Date}}\relax
    \vtop{\null\box\TopNotes}\hfill}
    \global\advance\Date by 1 \relax
    \global\advance\Day  by 1 \relax
    \vfill
    \box\BotNotes
    \vskip\boxrulewid
    \hrule depth \boxrulewid}\ignorespaces
  {\vrule width -\boxrulewid
  \vrule width \boxrulewid}}\ignorespaces
EndDefine

Define addbottomnote#1:
  \setbox\BotNotes\vbox{\hsize=\boxwidth\relax
  \unvbox\BotNotes\vskip\boxrulewid\centerline{\notefont #1}}\ignorespaces
EndDefine

Define addtopnote#1:
  \setbox\TopNotes\vbox{\hsize=.5in \hfuzz=4in \relax
  \unvbox\TopNotes\vskip\boxrulewid\line{\notefont #1}}\ignorespaces
EndDefine

%Comment: In following routine, arg is day of week, 0 = Sunday
%EndComment

Define firstmonth#1:
  \Day=#1\relax
  \newmonth
EndDefine

Define newmonth:
  \Date=1\relax
  \vbox\bgroup
  \hbox\bgroup\null\expandafter\hskip\the\Day\boxwidth
  \ignorespaces
EndDefine

Define dodate:\is
  \DayBox
  \ifnum\Day=7\relax
    \egroup\vskip-1.7\boxrulewid\hbox\bgroup
    \global\Day=0\relax
  \fi
  \ifnum\Date<\OnDate
    \let\next=\dodate
  \else
    \let\next=\ignorespaces
  \fi\is
  \next
EndDefine

% pass date of next event:

Define ondate#1,:
  \global\OnDate=#1\relax\dodate
EndDefine

% pass lastdateofmonth +1:

Define endmonth#1.: 
  \ondate #1,\egroup\egroup
EndDefine

Main:

\def\note#1{\addtopnote{\vbox{\hyphenchar\notefont=-1\hsize=.6in\hfuzz=2pt
\raggedright #1\hfil\break}}}
\centerline{\titlef Summer Calendar}

\bigskip

\let\is\ignorespaces
\calendar
\firstmonth 5
\note{June 1990}
\ondate 4,\note{Return to MIT}
\ondate 5,\note{Nana's Birthday}\note{Gondoliers auditions}
\ondate 8,\note{Superman I and II}
\ondate 9,\note{Ladyhawke}
\ondate 14,\note{Flag Day}
\ondate 17,\note{Father's Day}\note{Leave for TUG}
\ondate 20,\note{BaSiX paper}\note{TUG ends}
\ondate 21,\note{Michelle's Birthday}\note{Return to Boston}
\ondate 22,\note{Star Trek Marathon, Part I}
\ondate 23,\note{Star Trek Marathon, Part II}
\endmonth 31.

\medskip

\newmonth
\note{July 1990}
\ondate 4,\note{Indepen- dence Day}
\ondate 7,\note{Ope's Birthday}
\ondate 13,\note{Star Wars Trilogy}
\ondate 14,\note{Bastille Day}
\ondate 17,\note{Dad's Birthday}
\ondate 21,\note{Tangle- wood}
\endmonth 32.
\endcalendar

\end


