% calendar.sty allows you to make a one page Gregorian calendar for any
% year.  It does not give the correct Julian dates for the years before
% the Gregorian calendar was introduced.  The use is simple.  Just say
% \year{<year>}.
%
% Copyright, 1989 Michael Barr May be freely used by anyone not an
% employee of a telephone company.  It may be freely distributed as long
% as this notice is included.
 
 
\textheight9in \headsep 0in \headheight0in \topmargin0in
\textwidth 7.05in \oddsidemargin-.255in
\pagestyle{empty}\thispagestyle{empty}
\font\gross=cminch
%\font\gross=cmr17\Huge  %I have trouble with cminch (rags) unless it is bitmapped
 
\def\month#1#2#3{\initialdate{#1}{#2}%
\begin{tabular}{|rrrrrrr|}   \hline
\multicolumn{7}{|c|}{#3}\\ \hline
Su&Mo&Tu&We&Th&Fr&Sa\\ \hline
\day{ 1}&\day{ 2}&\day{ 3}&\day{ 4}&\day{ 5}&\day{ 6}&\day{ 7}\\
\day{ 8}&\day{ 9}&\day{10}&\day{11}&\day{12}&\day{13}&\day{14}\\
\day{15}&\day{16}&\day{17}&\day{18}&\day{19}&\day{20}&\day{21}\\
\day{22}&\day{23}&\day{24}&\day{25}&\day{26}&\day{27}&\day{28}\\
\day{29}&\day{30}&\day{31}&\day{32}&\day{33}&\day{34}&\day{35}\\
\day{36}&\day{37}&\day{38}&\day{39}&\day{40}&\day{41}&\day{42}\\ \hline
\end{tabular}\global\advance\firstdate by #2
\ifnum\firstdate>35 \global\advance\firstdate by -35
   \else\global\advance \firstdate by -28 \fi}
\def\day#1{\advance \date by#1
   \ifnum\date>0 \ifnum\date>\lastdate\else\number\date \fi\fi}
\newcount\firstdate \newcount \lastdate \newcount \date
\def\initialdate#1#2{\date=1 \advance\date by -#1 \lastdate=#2}
 
 
\newif\ifleap
\newcount\yearnum
\newcount\xa\newcount\xb\newcount\xc
\newcount\ya\newcount\yb\newcount\yc\newcount\yd
\xa=0 \xb=235 {\multiply \xb by 2 \global\xc=\xb }
\yd=0 \yc=136 {\multiply \yc by 2 \global \yb=\yc }
{\multiply \yc by 3 \global \ya=\yc }
 
\def\year#1{\begin{center}
{\gross#1}\end{center}
\yearnum=#1
\leaptrue
{\ifodd \yearnum \global\leapfalse \else \divide\yearnum by 2
     \ifodd\yearnum \global\leapfalse\fi\fi}
{\ifleap \divide\yearnum by 100 \multiply\yearnum by 100
     \ifnum\yearnum=#1 \divide\yearnum by 100 \ifodd
       \yearnum\global\leapfalse\else
     \divide\yearnum by 2 \ifodd\yearnum\global\leapfalse\fi\fi\fi\fi}
\unitlength.01in
\begin{picture}(705,543)%(60,100)
\setfirstdate
\put(\xa,\ya){\month{\firstdate}{31}{January}}
\ifleap \put(\xb,\ya){\month{\firstdate}{29}{February}}
\else \put(\xb,\ya){\month{\firstdate}{28}{February}}\fi
\put(\xc,\ya){\month{\firstdate}{31}{March}}
\put(\xa,\yb){\month{\firstdate}{30}{April}}
\put(\xb,\yb){\month{\firstdate}{31}{May}}
\put(\xc,\yb){\month{\firstdate}{30}{June}}
\put(\xa,\yc){\month{\firstdate}{31}{July}}
\put(\xb,\yc){\month{\firstdate}{31}{August}}
\put(\xc,\yc){\month{\firstdate}{30}{September}}
\put(\xa,\yd){\month{\firstdate}{31}{October}}
\put(\xb,\yd){\month{\firstdate}{30}{November}}
\put(\xc,\yd){\month{\firstdate}{31}{December}}
\end{picture}\newpage}
\newcount\tempa \newcount\tempb \newcount\tempc
 
\def\mod(#1,#2,#3){%
\tempa#1 \tempb\tempa
\divide\tempa by #2  \multiply\tempa by #2
\advance\tempb by -\tempa \global#3=\tempb}
 
\def\setfirstdate{%
\mod(\yearnum,400,\tempc)
\ifnum\tempc>0 \global\advance\tempc by -1\else\tempc=4 \fi
\firstdate=2 \advance\firstdate by \tempc
\divide\tempc by 4 \advance \firstdate by \tempc
\divide\tempc by 25 \advance\firstdate by -\tempc
\tempc=\firstdate \mod(\tempc,7,\firstdate)
\ifnum\firstdate=0 \global\firstdate=7 \fi}
 
% Here's a sample file to print out the 1991 calendar:
% \documentstyle[calendar]{article}
% \begin{document}
% \year{1991}
% \end{document}
 
