geoffo@elecvax.UUCP (10/30/87)
Here is a TeX `program' I have written to generate a two-sided calendar.
Printed on both sides of a piece of A4 it makes a handy diary I can carry
in my wallet.
The calendar is centred on the page, the calendar size and page size can
be changed easily. Printer limitations may require a smaller calendar.
For example, to print properly here I had to drop \calendarheight to 253mm.
The year can also be changed simply, in which case the entire calendar is
appropriately reformatted. At present any number in 1980-1999 will work.
If I still need it for 2000, the additions are trivial.
Due to my own taste, the week runs from sunday to saturday. With a small
amount of effort this could be changed.
This was written on my Amiga, using Tom Rokicki's AmigaTeX (thanks Tom).
Geoff Oakley Telephone:
School of EE and CS +61 2 697 4043
University of NSW Network mail:
PO Box 1 ACSNetwork: geoffo@elecvax.oz
Kensington NSW 2033 UUCP: {{uunet, hplabs, ubc-vision, mcvax, enea, ukc,
AUSTRALIA prlb2}!munnari, decvax!mulga}!elecvax.oz!geoffo
-=+##+=--=+##+=--=+##+=--=+##+=--=+##+=--=+##+=--=+##+=--=+##+=--=+##+=-
% TeX program to print 2-sided calendar
% Year and calendar size can be changed
\newcount\yearnum \yearnum=1988
\newdimen\calendarheight \calendarheight=277mm
\newdimen\calendarwidth \calendarwidth=190mm
% paper size (centred on full [A4] paper size)
\hsize=210mm \hoffset=-1in
\vsize=297mm \voffset=-1in
% fonts used
\font\datefont=cmr8
\font\titlefont=cmti10 scaled\magstep3
% dimension registers
\newdimen\daywidth % width of 1 day
\newdimen\dayheight % height of 1 row
\newdimen\bannerheight % banner (days-of-week title) height
\newdimen\bannersep % sep twixt banner and dates
\newdimen\tmpdimen
% number registers
\newcount\monthnum % current month (1..12)
\newcount\endofmonth % last date for current month (28..31)
\newcount\datenum % current date (1..31)
\newcount\daynum % current dayofweek (0..6) == (sun..sat)
\newcount\pagenum % current page (0..1)
\newcount\startpage % 1 before page starts, 0 otherwise
\newcount\leapyear % 1 for leapyear, 0 otherwise
\newcount\startday % first dayofweek for page 0
\newcount\nextstartday % first dayofweek for page 1
\newcount\endofpage % see use for description
\newcount\tmp
% initialisations
\daywidth=\calendarwidth
\divide\daywidth by7
% of the many definitions
\def\titlestring{\titlefont\number\yearnum} % can be changed,
% but be wary of long titles
\def\setleap{\tmp=\yearnum
\divide\tmp by4
\multiply\tmp by4
\advance\tmp by-\yearnum
\global\leapyear= \ifnum\tmp=0 1
\else 0
\fi}
\def\setstartday{\tmp=\yearnum
\advance\tmp by-1980
\global\startday=\ifcase\tmp
2\or4\or5\or6\or0\or2\or3\or4\or5\or0\or %1980-89
1\or2\or4\or5\or6\or0\or1\or3\or4\or5 %1990-99
\fi}
\def\seteom{\global\endofmonth=\ifcase\monthnum
\or31%jan
\or\ifnum\leapyear=1 29%feb
\else28
\fi
\or31%mar
\or30%apr
\or31%may
\or30%jun
\or31%jul
\or31%aug
\or30%sep
\or31%oct
\or30%nov
\or31%dec
\or31%next jan
\fi}
\def\setrowheight{\tmp=27 %calculate weeks on page
\ifcase\pagenum
\ifnum\startday=1
\ifnum\leapyear=0
\tmp=26
\fi
\fi
\or
\ifnum\nextstartday=6
\tmp=28
\fi
\fi
\advance\tmp by2 %allow for day names (banner)
\dayheight=\calendarheight
\divide\dayheight by\tmp
\bannersep=\dayheight
\divide\bannersep by10
\bannerheight=\dayheight
\advance\bannerheight by-\bannersep
\advance\bannerheight by-0.4pt}
\def\incrday{\ifnum\daynum=6
\global\daynum=0
\else
\global\advance\daynum by1
\fi}
\def\incrdate{\ifnum\datenum=\endofmonth
\global\advance\monthnum by1
\global\datenum=1
\seteom
\ifnum\monthnum=7
\global\endofpage=1
\else
\ifnum\monthnum=13
\global\endofpage=1
\fi
\fi
\else
\global\advance\datenum by1
\fi}
\def\datestring{\hbox{\ifnum\datenum>1
\datefont\number\datenum
\else
\bf\ifcase\monthnum
day0
\or Jan \or Feb \or Mar \or Apr
\or May \or Jun \or Jul \or Aug
\or Sep \or Oct \or Nov \or Dec
\fi
\fi}
\incrdate}
\def\weekday#1{\vbox to\bannerheight{\vfil\hbox{#1}\vfil}}
\def\dayofweek#1{\unskip\hbox to\daywidth{\hfil\weekday{#1}\hfil}}
\def\vbar#1{\unskip\vrule height#1depth0mm\kern-0.4pt}
\def\bannerbar{\vbar{\bannerheight}}
\def\daybar{\vbar{\dayheight}}
\def\rule#1{\hrule width#1\kern-0.4pt}
\def\weekrule{\rule{\calendarwidth}}
\def\banner{\weekrule
\hbox{\bannerbar\dayofweek{Sunday}
\bannerbar\dayofweek{Monday}
\bannerbar\dayofweek{Tuesday}
\bannerbar\dayofweek{Wednesday}
\bannerbar\dayofweek{Thursday}
\bannerbar\dayofweek{Friday}
\bannerbar\dayofweek{Saturday}
\bannerbar
\unskip}
\weekrule}
\def\printtitle{\tmpdimen=\daywidth
\multiply\tmpdimen by\daynum
\daybar
\hbox{\vbox to\dayheight
{\vfil
\hbox to\tmpdimen
{\hfil
\ifcase\pagenum \titlestring \or\fi
\hfil}
\vfil}}}
\def\widetitle{\weekrule
\hbox{\daybar
\vbox to\dayheight
{\vfil
\hbox to\calendarwidth{\hfil\titlestring\hfil}
\vfil}
\daybar}}
\def\daydate#1{\vbox to\dayheight{\vskip1mm\hbox{#1}\vfil}}
\def\printday#1{\unskip\hbox to\daywidth{\hskip1mm\daydate{#1}\hfil}}
\def\printalldays{\ifnum\startpage=1
\printtitle
\global\startpage=0
\fi
\loop
\ifcase\endofpage %0=not eop
\daybar
\printday{\datestring}
\or %1=eop first time
\daybar
\printday{}
\global\endofpage=2
\global\nextstartday=\daynum %for next page
\or %2=eop
\printday{}
\fi
\incrday
\ifnum\daynum>0
\repeat
\daybar} % next day is Sunday-> finish
\def\printallweeks{\loop
\weekrule
\hbox{\printalldays}
\ifnum\endofpage=0
\repeat
\weekrule}
% let the fun begin
\setleap
\setstartday
\monthnum=1
\datenum=1
\seteom
\nopagenumbers
\nointerlineskip
\pagenum=0
\setrowheight
\startpage=1
\endofpage=0
\daynum=\startday
\hbox to \hsize
{\hfil
\vbox to \vsize
{\vfil
\banner
\vskip\bannersep
\ifnum\daynum=0
\widetitle
\startpage=0
\fi
\printallweeks
\vskip\bannersep
\banner
\vfil}
\hfil}
\eject
\pagenum=1
\setrowheight
\startpage=1
\endofpage=0
\daynum=\nextstartday
\hbox to \hsize
{\hfil
\vbox to \vsize
{\vfil
\banner
\vskip\bannersep
\ifnum\daynum=0
\startpage=0
\fi
\printallweeks
\vskip\bannersep
\banner
\vfil}
\hfil}
\eject
\end