1 ;;; cal-tex.el --- calendar functions for printing calendars with LaTeX.
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;; Author: Steve Fisk <fisk@bowdoin.edu>
6 ;; Edward M. Reingold <reingold@cs.uiuc.edu>
8 ;; Human-Keywords: Calendar, LaTeX
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; This collection of functions implements the creation of LaTeX calendars
30 ;; based on the user's holiday choices and diary file.
34 ;; (*) Add holidays and diary entries to daily calendar.
36 ;; (*) Add diary entries to weekly calendar functions.
38 ;; (*) Make calendar styles for A4 paper.
40 ;; (*) Make daily and monthly styles Filofax paper.
42 ;; (*) Improve the LaTeX command that produces the boxes in the monthly
43 ;; calendar to eliminate slight gap--what causes it?!
49 (autoload 'list-diary-entries "diary-lib" nil t)
50 (autoload 'calendar-holiday-list "holidays" nil t)
51 (autoload 'calendar-iso-from-absolute "cal-iso" nil t)
54 ;;; Customizable variables
57 (defvar cal-tex-which-days '(0 1 2 3 4 5 6)
58 "*The days of the week that are displayed on the portrait monthly calendar.
59 Sunday is 0, Monday is 1, and so on. The default is to print from Sunday to
60 Saturday. For example, use
62 (setq cal-tex-which-days '(1 3 5))
64 to only print Monday, Wednesday, Friday.")
66 (defvar cal-tex-holidays t
67 "*If t (default), then the holidays are also printed.
68 If finding the holidays is too slow, set this to nil.")
70 (defvar cal-tex-diary nil
71 "*If t, the diary entries are printed in the calendar.")
73 (defvar cal-tex-daily-string
74 '(let* ((year (extract-calendar-year date))
75 (day (calendar-day-number date))
76 (days-remaining (- (calendar-day-number (list 12 31 year)) day)))
77 (format "%d/%d" day days-remaining))
78 "*An expression in the variable `date' whose value is placed on date.
79 The string resulting from evaluating this expression is placed at the bottom
80 center of `date' on the monthly calendar, next to the date in the weekly
81 calendars, and in the top center of daily calendars.
83 Default is ordinal day number of the year and the number of days remaining.
84 As an example of what you do, setting this to
88 (calendar-hebrew-date-string date))
90 will put the Hebrew date at the bottom of each day.")
92 (defvar cal-tex-buffer "calendar.tex"
93 "*The name for the tex-ed calendar.")
95 (defvar cal-tex-24 nil
96 "*If t, use a 24 hour clock in the daily calendar.")
98 (defvar cal-tex-daily-start 8
99 "*The first hour of the daily calendar page.")
101 (defvar cal-tex-daily-end 20
102 "*The last hour of the daily calendar page.")
105 ;;; Definitions for LaTeX code
108 (defvar cal-tex-day-prefix "\\caldate{%s}{%s}"
109 "The initial LaTeX code for a day.
110 The holidays, diary entries, bottom string, and the text follow.")
112 (defvar cal-tex-day-name-format "\\myday{%s}%%"
113 "The format for LaTeX code for a day name. The names are taken from
114 calendar-day-name-array.")
116 (defvar cal-tex-cal-one-month
117 "\\def\\calmonth#1#2%
119 \\Huge\\bf\\uppercase{#1} #2 \\\\[1cm]%
124 "LaTeX code for the month header")
126 (defvar cal-tex-cal-multi-month
127 "\\def\\calmonth#1#2#3#4%
129 \\Huge\\bf #1 #2---#3 #4\\\\[1cm]%
134 "LaTeX code for the month header")
136 (defvar cal-tex-myday
137 "\\renewcommand{\\myday}[1]%
138 {\\makebox[\\cellwidth]{\\hfill\\large\\bf#1\\hfill}}
141 "LaTeX code for a day heading")
143 (defvar cal-tex-caldate
145 \\long\\def\\caldate#1#2#3#4#5#6{%
146 \\fbox{\\hbox to\\cellwidth{%
147 \\vbox to\\cellheight{%
148 \\hbox to\\cellwidth{%
149 {\\hspace*{1mm}\\Large \\bf \\strut #2}\\hspace{.05\\cellwidth}%
150 \\raisebox{\\holidaymult\\cellheight}%
151 {\\parbox[t]{.75\\cellwidth}{\\tiny \\raggedright #4}}}
152 \\hbox to\\cellwidth{%
153 \\hspace*{1mm}\\parbox{.95\\cellwidth}{\\tiny \\raggedright #3}}
155 \\hbox to\\cellwidth{#6}%
157 \\hbox to\\cellwidth{\\hfill \\tiny #5 \\hfill}%
161 "LaTeX code to insert one box with date info in calendar.
162 This definition is the heart of the calendar!")
164 (defun cal-tex-list-holidays (d1 d2)
165 "Generate a list of all holidays from absolute date D1 to D2."
167 (start (calendar-gregorian-from-absolute d1))
168 (start-month (extract-calendar-month start))
169 (start-year (extract-calendar-year start)))
170 (increment-calendar-month start-month start-year 1)
171 (let* ((end (calendar-gregorian-from-absolute d2))
172 (end-month (extract-calendar-month end))
173 (end-year (extract-calendar-year end)))
174 (if (= (extract-calendar-day end) 1)
175 (increment-calendar-month end-month end-year -1))
176 (let* ((s (calendar-absolute-from-gregorian
177 (list start-month 1 start-year)))
178 (e (calendar-absolute-from-gregorian
179 (list end-month 1 end-year)))
182 (displayed-month start-month)
183 (displayed-year start-year))
184 (while (or never (<= d e))
185 (setq result (append result (calendar-holiday-list)))
187 (increment-calendar-month displayed-month displayed-year 3)
188 (setq d (calendar-absolute-from-gregorian
189 (list displayed-month 1 displayed-year))))))
194 (let ((a (calendar-absolute-from-gregorian (car (car p)))))
195 (and (<= d1 a) (<= a d2)))
196 (setq in-range (append (list (car p)) in-range)))
200 (defun cal-tex-list-diary-entries (d1 d2)
201 "Generate a list of all diary-entries from absolute date D1 to D2."
202 (let ((diary-display-hook nil))
204 (calendar-gregorian-from-absolute d1)
207 (defun cal-tex-preamble (&optional args)
208 "Insert the LaTeX preamble.
209 Preamble Includes initial definitions for various LaTeX commands.
210 Optional ARGS are included."
211 (set-buffer (get-buffer-create cal-tex-buffer))
213 (insert "\\documentstyle")
215 (insert "[" args "]"))
216 (insert "{article}\n"
222 \\evensidemargin -2cm
227 \\newlength{\\cellwidth}
228 \\newlength{\\cellheight}
229 \\newlength{\\boxwidth}
230 \\newlength{\\boxheight}
231 \\newlength{\\cellsize}
232 \\newcommand{\\myday}[1]{}
233 \\newcommand{\\caldate}[6]{}
234 \\newcommand{\\nocaldate}[6]{}
235 \\newcommand{\\calsmall}[6]{}
243 (defun cal-tex-cursor-year (&optional arg)
244 "Make a buffer with LaTeX commands for the year cursor is on.
245 Optional prefix argument specifies number of years."
247 (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
250 (defun cal-tex-cursor-year-landscape (&optional arg)
251 "Make a buffer with LaTeX commands for the year cursor is on.
252 Optional prefix argument specifies number of years."
254 (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
258 (defun cal-tex-year (year n &optional landscape)
259 "Make a one page yearly calendar of YEAR; do this for N years.
260 There are four rows of three months each, unless optional LANDSCAPE is t,
261 in which case the calendar isprinted in landscape mode with three rows of
263 (cal-tex-insert-preamble 1 landscape "12pt")
265 (cal-tex-vspace "-.6cm")
266 (cal-tex-vspace "-3.1cm"))
267 (calendar-for-loop j from 1 to n do
268 (insert "\\vfill%\n")
270 (cal-tex-Huge (number-to-string year))
272 (cal-tex-vspace "1cm")
274 (cal-tex-b-parbox "l" (if landscape "5.9in" "4.3in"))
278 (calendar-for-loop i from 1 to 12 do
279 (insert (cal-tex-mini-calendar i year "month" "1.1in" "1in"))
281 (cal-tex-hspace "0.5in")
282 (if (zerop (mod i (if landscape 4 3)))
283 (cal-tex-nl "0.5in")))
286 (insert "\\vfill%\n")
287 (setq year (1+ year))
290 (cal-tex-end-document))
291 (run-hooks 'cal-tex-year-hook))
292 (run-hooks 'cal-tex-hook))
294 (defun cal-tex-cursor-filofax-year (&optional arg)
295 "Make a Filofax one page yearly calendar of year indicated by cursor.
296 Optional parameter specifies number of years."
298 (let* ((n (if arg arg 1))
299 (year (extract-calendar-year (calendar-cursor-to-date t))))
300 (cal-tex-preamble "twoside")
301 (cal-tex-cmd "\\textwidth 3.25in")
302 (cal-tex-cmd "\\textheight 6.5in")
303 (cal-tex-cmd "\\oddsidemargin 1.6in")
304 (cal-tex-cmd "\\evensidemargin 1.55in")
305 (cal-tex-cmd "\\topmargin 0pt")
306 (cal-tex-cmd "\\headheight -0.875in")
307 (cal-tex-cmd "\\pagestyle{empty}")
309 (calendar-for-loop j from 1 to n do
310 (insert (format "\\hfil {\\Large \\bf %s} \\hfil\\\\\n" year))
312 (cal-tex-b-parbox "l" "\\textwidth")
316 (calendar-for-loop i from 1 to 12 do
317 (insert (cal-tex-mini-calendar i year
318 (calendar-month-name i)
319 "1.05in" ".8in" "tiny")))
321 "\\noindent\\fbox{\\January}\\fbox{\\February}\\fbox{\\March}\\\\
322 \\noindent\\fbox{\\April}\\fbox{\\May}\\fbox{\\June}\\\\
323 \\noindent\\fbox{\\July}\\fbox{\\August}\\fbox{\\September}\\\\
324 \\noindent\\fbox{\\October}\\fbox{\\November}\\fbox{\\December}
328 (setq year (1+ year))
331 (cal-tex-end-document))
332 (run-hooks 'cal-tex-year-hook))
333 (run-hooks 'cal-tex-hook)))
336 ;;; Monthly calendars
339 (defun cal-tex-cursor-month-landscape (&optional arg)
340 "Make a buffer with LaTeX commands for the month cursor is on.
341 Optional prefix argument specifies number of months to be produced.
342 The output is in landscape format, one month to a page."
344 (let* ((n (if arg arg 1))
345 (date (calendar-cursor-to-date t))
346 (month (extract-calendar-month date))
347 (year (extract-calendar-year date))
350 (cal-tex-which-days '(0 1 2 3 4 5 6)))
351 (increment-calendar-month end-month end-year (1- n))
352 (let ((diary-list (if cal-tex-diary
353 (cal-tex-list-diary-entries
354 (calendar-absolute-from-gregorian
356 (calendar-absolute-from-gregorian
358 (calendar-last-day-of-month
361 (holidays (if cal-tex-holidays
362 (cal-tex-list-holidays
363 (calendar-absolute-from-gregorian
365 (calendar-absolute-from-gregorian
367 (calendar-last-day-of-month end-month end-year)
371 (small-months-at-start))
372 (cal-tex-insert-preamble (cal-tex-number-weeks month year 1) t "12pt")
373 (cal-tex-cmd cal-tex-cal-one-month)
374 (calendar-for-loop i from 1 to n do
375 (setq other-month month)
376 (setq other-year year)
377 (increment-calendar-month other-month other-year -1)
378 (insert (cal-tex-mini-calendar other-month other-year "lastmonth"
379 "\\cellwidth" "\\cellheight"))
380 (increment-calendar-month other-month other-year 2)
381 (insert (cal-tex-mini-calendar other-month other-year "nextmonth"
382 "\\cellwidth" "\\cellheight"))
383 (cal-tex-insert-month-header 1 month year month year)
384 (cal-tex-insert-day-names)
386 (setq small-months-at-start
387 (< 1 (mod (- (calendar-day-of-week (list month 1 year))
388 calendar-week-start-day)
390 (if small-months-at-start
391 (insert "\\lastmonth\\nextmonth\\hspace*{-2\\cellwidth}"))
392 (cal-tex-insert-blank-days month year cal-tex-day-prefix)
393 (cal-tex-insert-days month year diary-list holidays
395 (cal-tex-insert-blank-days-at-end month year cal-tex-day-prefix)
396 (if (and (not small-months-at-start)
397 (< 1 (mod (- (1- calendar-week-start-day)
398 (calendar-day-of-week
400 (calendar-last-day-of-month month year)
403 (insert "\\vspace*{-\\cellwidth}\\hspace*{-2\\cellwidth}"
404 "\\lastmonth\\nextmonth"))
407 (run-hooks 'cal-tex-month-hook)
409 (increment-calendar-month month year 1)
410 (cal-tex-vspace "-2cm")
411 (cal-tex-insert-preamble
412 (cal-tex-number-weeks month year 1) t "12pt" t))))
413 (cal-tex-end-document)
414 (run-hooks 'cal-tex-hook))))
416 (defun cal-tex-cursor-month (arg)
417 "Make a buffer with LaTeX commands for the month cursor is on.
418 Optional prefix argument specifies number of months to be produced.
419 Calendar is condensed onto one page."
421 (let* ((date (calendar-cursor-to-date t))
422 (month (extract-calendar-month date))
423 (year (extract-calendar-year date))
427 (increment-calendar-month end-month end-year (1- n))
428 (let ((diary-list (if cal-tex-diary
429 (cal-tex-list-diary-entries
430 (calendar-absolute-from-gregorian
432 (calendar-absolute-from-gregorian
434 (calendar-last-day-of-month
437 (holidays (if cal-tex-holidays
438 (cal-tex-list-holidays
439 (calendar-absolute-from-gregorian
441 (calendar-absolute-from-gregorian
443 (calendar-last-day-of-month end-month end-year)
447 (cal-tex-insert-preamble (cal-tex-number-weeks month year n) nil"12pt")
449 (cal-tex-cmd cal-tex-cal-multi-month)
450 (cal-tex-cmd cal-tex-cal-one-month))
451 (cal-tex-insert-month-header n month year end-month end-year)
452 (cal-tex-insert-day-names)
454 (cal-tex-insert-blank-days month year cal-tex-day-prefix)
455 (calendar-for-loop i from 1 to n do
456 (setq other-month month)
457 (setq other-year year)
458 (cal-tex-insert-days month year diary-list holidays
460 (increment-calendar-month month year 1))
461 (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix)
462 (cal-tex-end-document)))
463 (run-hooks 'cal-tex-hook))
465 (defun cal-tex-insert-days (month year diary-list holidays day-format)
466 "Insert LaTeX commands for a range of days in monthly calendars.
467 LaTeX commands are inserted for the days of the MONTH in YEAR.
468 Diary entries on DIARY-LIST are included. Holidays on HOLIDAYS are included.
469 Each day is formatted using format DAY-FORMAT."
470 (let* ((blank-days;; at start of month
472 (- (calendar-day-of-week (list month 1 year))
473 calendar-week-start-day)
476 (last (calendar-last-day-of-month month year)))
477 (calendar-for-loop i from 1 to last do
478 (setq date (list month i year))
479 (if (memq (calendar-day-of-week date) cal-tex-which-days)
481 (insert (format day-format (calendar-month-name month) i))
482 (cal-tex-arg (cal-tex-latexify-list diary-list date))
483 (cal-tex-arg (cal-tex-latexify-list holidays date))
484 (cal-tex-arg (eval cal-tex-daily-string))
487 (if (and (zerop (mod (+ i blank-days) 7))
493 (defun cal-tex-insert-day-names ()
494 "Insert the names of the days at top of a monthly calendar."
495 (calendar-for-loop i from 0 to 6 do
496 (if (memq i cal-tex-which-days)
497 (insert (format cal-tex-day-name-format
498 (aref calendar-day-name-array
499 (mod (+ calendar-week-start-day i) 7)))))
502 (defun cal-tex-insert-month-header (n month year end-month end-year)
503 "Create a title for a calendar.
504 A title is inserted for a calendar with N months starting with
505 MONTH YEAR and ending with END-MONTH END-YEAR."
506 (let ( (month-name (calendar-month-name month))
507 (end-month-name (calendar-month-name end-month)))
509 (insert (format "\\calmonth{%s}{%s}\n\\vspace*{-0.5cm}"
511 (insert (format "\\calmonth{%s}{%s}{%s}{%s}\n\\vspace*{-0.5cm}"
512 month-name year end-month-name end-year))))
515 (defun cal-tex-insert-blank-days (month year day-format)
516 "Insert code for initial days not in calendar.
517 Insert LaTeX code for the blank days at the beginning of the MONTH in
518 YEAR. The entry is formatted using DAY-FORMAT. If the entire week is
519 blank, no days are inserted."
520 (if (cal-tex-first-blank-p month year)
521 (let* ((blank-days;; at start of month
523 (- (calendar-day-of-week (list month 1 year))
524 calendar-week-start-day)
526 (calendar-for-loop i from 0 to (1- blank-days) do
527 (if (memq i cal-tex-which-days)
528 (insert (format day-format " " " ") "{}{}{}{}%\n"))))))
530 (defun cal-tex-insert-blank-days-at-end (month year day-format)
531 "Insert code for final days not in calendar.
532 Insert LaTeX code for the blank days at the end of the MONTH in YEAR.
533 The entry is formatted using DAY-FORMAT."
534 (if (cal-tex-last-blank-p month year)
535 (let* ((last-day (calendar-last-day-of-month month year))
536 (blank-days;; at end of month
538 (- (calendar-day-of-week (list month last-day year))
539 calendar-week-start-day)
541 (calendar-for-loop i from (1+ blank-days) to 6 do
542 (if (memq i cal-tex-which-days)
543 (insert (format day-format "" "") "{}{}{}{}%\n"))))))
545 (defun cal-tex-first-blank-p (month year)
546 "Determine if any days of the first week will be printed.
547 Return t if there will there be any days of the first week printed
548 in the calendar starting in MONTH YEAR."
550 (the-saturday)) ;the day of week of 1st Saturday
551 (calendar-for-loop i from 1 to 7 do
552 (if (= 6 (calendar-day-of-week (list month i year)))
553 (setq the-saturday i)))
554 (calendar-for-loop i from 1 to the-saturday do
555 (if (memq (calendar-day-of-week (list month i year))
560 (defun cal-tex-last-blank-p (month year)
561 "Determine if any days of the last week will be printed.
562 Return t if there will there be any days of the last week printed
563 in the calendar starting in MONTH YEAR."
565 (last-day (calendar-last-day-of-month month year))
566 (the-sunday)) ;the day of week of last Sunday
567 (calendar-for-loop i from (- last-day 6) to last-day do
568 (if (= 0 (calendar-day-of-week (list month i year)))
569 (setq the-sunday i)))
570 (calendar-for-loop i from the-sunday to last-day do
571 (if (memq (calendar-day-of-week (list month i year))
576 (defun cal-tex-number-weeks (month year n)
577 "Determine the number of weeks in a range of dates.
578 Compute the number of weeks in the calendar starting with MONTH and YEAR,
579 and lasting N months, including only the days in WHICH-DAYS. As it stands,
580 this is only an upper bound."
581 (let ((d (list month 1 year)))
582 (increment-calendar-month month year (1- n))
583 (/ (- (calendar-dayname-on-or-before
584 calendar-week-start-day
585 (+ 7 (calendar-absolute-from-gregorian
586 (list month (calendar-last-day-of-month month year) year))))
587 (calendar-dayname-on-or-before
588 calendar-week-start-day
589 (calendar-absolute-from-gregorian d)))
596 (defun cal-tex-cursor-week (&optional arg)
597 "Make a buffer with LaTeX commands for a two-page one-week calendar.
598 It applies to the week that point is in.
599 Optional prefix argument specifies number of weeks.
600 Holidays are included if `cal-tex-holidays' is t."
602 (let* ((n (if arg arg 1))
603 (date (calendar-gregorian-from-absolute
604 (calendar-dayname-on-or-before
605 calendar-week-start-day
606 (calendar-absolute-from-gregorian
607 (calendar-cursor-to-date t)))))
608 (month (extract-calendar-month date))
609 (year (extract-calendar-year date))
610 (holidays (if cal-tex-holidays
611 (cal-tex-list-holidays
612 (calendar-absolute-from-gregorian date)
614 (calendar-absolute-from-gregorian date))))))
615 (cal-tex-preamble "11pt")
616 (cal-tex-cmd "\\textwidth 6.5in")
617 (cal-tex-cmd "\\textheight 10.5in")
618 (cal-tex-cmd "\\oddsidemargin 0in")
619 (cal-tex-cmd "\\evensidemargin 0in")
620 (insert cal-tex-LaTeX-hourbox)
622 (cal-tex-cmd "\\pagestyle{empty}")
623 (calendar-for-loop i from 1 to n do
624 (cal-tex-vspace "-1.5in")
626 (cal-tex-Huge-bf (format "\\uppercase{%s}"
627 (calendar-month-name month)))
628 (cal-tex-hspace "2em")
629 (cal-tex-Huge-bf (number-to-string year))
632 (cal-tex-hspace "-.2in")
633 (cal-tex-b-parbox "l" "7in")
634 (calendar-for-loop j from 1 to 7 do
635 (cal-tex-week-hours date holidays "3.1")
636 (setq date (cal-tex-incr-date date)))
638 (setq month (extract-calendar-month date))
639 (setq year (extract-calendar-year date))
642 (run-hooks 'cal-tex-week-hook)
644 (cal-tex-end-document)
645 (run-hooks 'cal-tex-hook)))
647 (defun cal-tex-cursor-week2 (&optional arg)
648 "Make a buffer with LaTeX commands for a two-page one-week calendar.
649 It applies to the week that point is in.
650 Optional prefix argument specifies number of weeks.
651 Holidays are included if `cal-tex-holidays' is t."
653 (let* ((n (if arg arg 1))
654 (date (calendar-gregorian-from-absolute
655 (calendar-dayname-on-or-before
656 calendar-week-start-day
657 (calendar-absolute-from-gregorian
658 (calendar-cursor-to-date t)))))
659 (month (extract-calendar-month date))
660 (year (extract-calendar-year date))
662 (holidays (if cal-tex-holidays
663 (cal-tex-list-holidays
664 (calendar-absolute-from-gregorian date)
666 (calendar-absolute-from-gregorian date))))))
667 (cal-tex-preamble "12pt")
668 (cal-tex-cmd "\\textwidth 6.5in")
669 (cal-tex-cmd "\\textheight 10.5in")
670 (cal-tex-cmd "\\oddsidemargin 0in")
671 (cal-tex-cmd "\\evensidemargin 0in")
672 (insert cal-tex-LaTeX-hourbox)
674 (cal-tex-cmd "\\pagestyle{empty}")
675 (calendar-for-loop i from 1 to n do
676 (cal-tex-vspace "-1.5in")
678 (cal-tex-Huge-bf (format "\\uppercase{%s}"
679 (calendar-month-name month)))
680 (cal-tex-hspace "2em")
681 (cal-tex-Huge-bf (number-to-string year))
684 (cal-tex-hspace "-.2in")
685 (cal-tex-b-parbox "l" "\\textwidth")
686 (calendar-for-loop j from 1 to 3 do
687 (cal-tex-week-hours date holidays "5")
688 (setq date (cal-tex-incr-date date)))
691 (insert (cal-tex-mini-calendar
692 (extract-calendar-month (cal-tex-previous-month date))
693 (extract-calendar-year (cal-tex-previous-month date))
694 "lastmonth" "1.1in" "1in"))
695 (insert (cal-tex-mini-calendar
696 (extract-calendar-month date)
697 (extract-calendar-year date)
698 "thismonth" "1.1in" "1in"))
699 (insert (cal-tex-mini-calendar
700 (extract-calendar-month (cal-tex-next-month date))
701 (extract-calendar-year (cal-tex-next-month date))
702 "nextmonth" "1.1in" "1in"))
703 (insert "\\hbox to \\textwidth{")
705 (insert "\\lastmonth")
707 (insert "\\thismonth")
709 (insert "\\nextmonth")
713 (cal-tex-b-parbox "l" "\\textwidth")
714 (calendar-for-loop j from 4 to 7 do
715 (cal-tex-week-hours date holidays "5")
716 (setq date (cal-tex-incr-date date)))
718 (setq month (extract-calendar-month date))
719 (setq year (extract-calendar-year date))
722 (run-hooks 'cal-tex-week-hook)
724 (cal-tex-end-document)
725 (run-hooks 'cal-tex-hook)))
727 (defun cal-tex-cursor-week-iso (&optional arg)
728 "Make a buffer with LaTeX commands for a one page ISO-style weekly calendar.
729 Optional prefix argument specifies number of weeks.
730 Diary entries are included if `cal-tex-diary' is t.
731 Holidays are included if `cal-tex-holidays' is t."
733 (let* ((n (if arg arg 1))
734 (date (calendar-gregorian-from-absolute
735 (calendar-dayname-on-or-before
737 (calendar-absolute-from-gregorian
738 (calendar-cursor-to-date t)))))
739 (month (extract-calendar-month date))
740 (year (extract-calendar-year date))
741 (day (extract-calendar-day date))
742 (holidays (if cal-tex-holidays
743 (cal-tex-list-holidays
744 (calendar-absolute-from-gregorian date)
746 (calendar-absolute-from-gregorian date)))))
747 (diary-list (if cal-tex-diary
748 (cal-tex-list-diary-entries
749 (calendar-absolute-from-gregorian
752 (calendar-absolute-from-gregorian date))))))
753 (cal-tex-preamble "11pt")
754 (cal-tex-cmd "\\textwidth 6.5in")
755 (cal-tex-cmd "\\textheight 10.5in")
756 (cal-tex-cmd "\\oddsidemargin 0in")
757 (cal-tex-cmd "\\evensidemargin 0in")
759 (cal-tex-cmd "\\pagestyle{empty}")
760 (calendar-for-loop i from 1 to n do
761 (cal-tex-vspace "-1.5in")
764 (let* ((d (calendar-iso-from-absolute
765 (calendar-absolute-from-gregorian date))))
766 (format "Week %d of %d"
767 (extract-calendar-month d)
768 (extract-calendar-year d))))
771 (cal-tex-b-parbox "l" "\\textwidth")
772 (calendar-for-loop j from 1 to 7 do
773 (cal-tex-b-parbox "t" "\\textwidth")
774 (cal-tex-b-parbox "t" "\\textwidth")
775 (cal-tex-rule "0pt" "\\textwidth" ".2mm")
777 (cal-tex-b-parbox "t" "\\textwidth")
778 (cal-tex-large-bf (calendar-day-name date))
780 (cal-tex-large-bf (calendar-month-name month))
782 (cal-tex-large-bf (number-to-string day))
783 (if (not (string= "" (cal-tex-latexify-list holidays date)))
786 (cal-tex-large-bf (cal-tex-latexify-list holidays date "; "))))
788 (insert " " (eval cal-tex-daily-string))
792 (cal-tex-b-parbox "t" "\\textwidth")
793 (if (not (string= "" (cal-tex-latexify-list diary-list date)))
795 (insert "\\vbox to 0pt{")
797 (cal-tex-latexify-list diary-list date))
801 (setq date (cal-tex-incr-date date))
802 (setq month (extract-calendar-month date))
803 (setq day (extract-calendar-day date))
805 (cal-tex-e-parbox "2cm")
807 (setq month (extract-calendar-month date))
808 (setq year (extract-calendar-year date)))
812 (run-hooks 'cal-tex-week-hook)
814 (cal-tex-end-document)
815 (run-hooks 'cal-tex-hook)))
817 (defvar cal-tex-LaTeX-hourbox
818 "\\newcommand{\\hourbox}[2]%
819 {\\makebox[2em]{\\rule{0cm}{#2ex}#1}\\rule{3in}{.15mm}}\n"
820 "One hour and a line on the right.")
822 (defun cal-tex-week-hours (date holidays height)
823 "Insert hourly entries for DATE with HOLIDAYS, with line height HEIGHT."
824 (let ((month (extract-calendar-month date))
825 (day (extract-calendar-day date))
826 (year (extract-calendar-year date))
828 (cal-tex-comment "begin cal-tex-week-hours")
829 (cal-tex-cmd "\\ \\\\[-.2cm]")
830 (cal-tex-cmd "\\noindent")
831 (cal-tex-b-parbox "l" "6.8in")
832 (cal-tex-large-bf (calendar-day-name date))
834 (cal-tex-large-bf (calendar-month-name month))
836 (cal-tex-large-bf (number-to-string day))
837 (if (not (string= "" (cal-tex-latexify-list holidays date)))
840 (cal-tex-large-bf (cal-tex-latexify-list holidays date "; "))))
842 (insert " " (eval cal-tex-daily-string))
845 (cal-tex-rule "0pt" "6.8in" ".2mm")
847 (calendar-for-loop i from 8 to 12 do
849 (setq afternoon (+ i 5))
850 (setq afternoon (- i 7)))
851 (cal-tex-cmd "\\hourbox" (number-to-string i))
853 (cal-tex-hspace ".4cm")
854 (cal-tex-cmd "\\hourbox" (number-to-string afternoon))
858 (defun cal-tex-cursor-week-monday (&optional arg)
859 "Make a buffer with LaTeX commands for a two-page one-week calendar.
860 It applies to the week that point is in, and starts on Monday.
861 Optional prefix argument specifies number of weeks.
862 Holidays are included if `cal-tex-holidays' is t."
864 (let* ((n (if arg arg 1))
865 (date (calendar-gregorian-from-absolute
866 (calendar-dayname-on-or-before
868 (calendar-absolute-from-gregorian
869 (calendar-cursor-to-date t))))))
870 (cal-tex-preamble "11pt")
871 (cal-tex-cmd "\\textwidth 6.5in")
872 (cal-tex-cmd "\\textheight 10.5in")
873 (cal-tex-cmd "\\oddsidemargin 0in")
874 (cal-tex-cmd "\\evensidemargin 0in")
876 (calendar-for-loop i from 1 to n do
877 (cal-tex-vspace "-1cm")
878 (insert "\\noindent ")
879 (cal-tex-weekly4-box (cal-tex-incr-date date) nil)
880 (cal-tex-weekly4-box (cal-tex-incr-date date 4) nil)
882 (cal-tex-weekly4-box (cal-tex-incr-date date 2) nil)
883 (cal-tex-weekly4-box (cal-tex-incr-date date 5) nil)
885 (cal-tex-weekly4-box (cal-tex-incr-date date 3) nil)
886 (cal-tex-weekly4-box (cal-tex-incr-date date 6) t)
889 (run-hooks 'cal-tex-week-hook)
890 (setq date (cal-tex-incr-date date 7))
892 (cal-tex-end-document)
893 (run-hooks 'cal-tex-hook)))
895 (defun cal-tex-weekly4-box (date weekend)
896 "Make one box for DATE, different if WEEKEND."
898 (day (extract-calendar-day date))
899 (month (extract-calendar-month date))
900 (year (extract-calendar-year date))
901 (dayname (calendar-day-name date))
902 (date1 (cal-tex-incr-date date))
903 (day1 (extract-calendar-day date1))
904 (month1 (extract-calendar-month date1))
905 (year1 (extract-calendar-year date1))
906 (dayname1 (calendar-day-name date1))
908 (cal-tex-b-framebox "8cm" "l")
909 (cal-tex-b-parbox "b" "7.5cm")
910 (insert (format "{\\Large\\bf %s,} %s/%s/%s\\\\\n" dayname month day year))
911 (cal-tex-rule "0pt" "7.5cm" ".5mm")
915 (calendar-for-loop i from 8 to 12 do
916 (insert (format "{\\large\\sf %d}\\\\\n" i)))
917 (calendar-for-loop i from 1 to 5 do
918 (insert (format "{\\large\\sf %d}\\\\\n" i)))))
922 (cal-tex-vspace "1cm")
923 (insert "\\ \\vfill")
924 (insert (format "{\\Large\\bf %s,} %s/%s/%s\\\\\n"
925 dayname1 month1 day1 year1))
926 (cal-tex-rule "0pt" "7.5cm" ".5mm")
928 (cal-tex-vspace "1cm")))
931 (cal-tex-hspace "1cm")))
933 (defun cal-tex-cursor-filofax-2week (&optional arg)
934 "Two-weeks-at-a-glance Filofax style calendar for week indicated by cursor.
935 Optional prefix argument specifies number of weeks.
936 Diary entries are included if `cal-tex-diary' is t.
937 Holidays are included if `cal-tex-holidays' is t."
939 (let* ((n (if arg arg 1))
940 (date (calendar-gregorian-from-absolute
941 (calendar-dayname-on-or-before
942 calendar-week-start-day
943 (calendar-absolute-from-gregorian
944 (calendar-cursor-to-date t)))))
945 (month (extract-calendar-month date))
946 (year (extract-calendar-year date))
947 (day (extract-calendar-day date))
948 (holidays (if cal-tex-holidays
949 (cal-tex-list-holidays
950 (calendar-absolute-from-gregorian date)
952 (calendar-absolute-from-gregorian date)))))
953 (diary-list (if cal-tex-diary
954 (cal-tex-list-diary-entries
955 (calendar-absolute-from-gregorian
958 (calendar-absolute-from-gregorian date))))))
959 (cal-tex-preamble "twoside")
960 (cal-tex-cmd "\\textwidth 3.25in")
961 (cal-tex-cmd "\\textheight 6.5in")
962 (cal-tex-cmd "\\oddsidemargin 1.75in")
963 (cal-tex-cmd "\\evensidemargin 1.5in")
964 (cal-tex-cmd "\\topmargin 0pt")
965 (cal-tex-cmd "\\headheight -0.875in")
966 (cal-tex-cmd "\\headsep 0.125in")
967 (cal-tex-cmd "\\footskip .125in")
968 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
969 \\long\\def\\rightday#1#2#3#4#5{%
970 \\rule{\\textwidth}{0.3pt}\\\\%
971 \\hbox to \\textwidth{%
974 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
975 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
976 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
977 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
978 \\long\\def\\leftday#1#2#3#4#5{%
979 \\rule{\\textwidth}{0.3pt}\\\\%
980 \\hbox to \\textwidth{%
983 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
984 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
985 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
988 (cal-tex-cmd "\\pagestyle{empty}")
989 (calendar-for-loop i from 1 to n do
991 (insert "\\righthead")
992 (insert "\\lefthead"))
994 (let ((d (cal-tex-incr-date date 6)))
995 (if (= (extract-calendar-month date)
996 (extract-calendar-month d))
999 (extract-calendar-month date))
1000 (extract-calendar-year date))
1001 (if (= (extract-calendar-year date)
1002 (extract-calendar-year d))
1003 (format "%s---%s %s"
1004 (calendar-month-name
1005 (extract-calendar-month date))
1006 (calendar-month-name
1007 (extract-calendar-month d))
1008 (extract-calendar-year date))
1009 (format "%s %s---%s %s"
1010 (calendar-month-name
1011 (extract-calendar-month date))
1012 (extract-calendar-year date)
1013 (calendar-month-name (extract-calendar-month d))
1014 (extract-calendar-year d))))))
1016 (calendar-for-loop j from 1 to 7 do
1018 (insert "\\rightday")
1019 (insert "\\leftday"))
1020 (cal-tex-arg (calendar-day-name date))
1021 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1022 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1023 (cal-tex-arg (cal-tex-latexify-list holidays date))
1024 (cal-tex-arg (eval cal-tex-daily-string))
1026 (setq date (cal-tex-incr-date date)))
1029 (run-hooks 'cal-tex-week-hook)
1030 (cal-tex-newpage))))
1031 (cal-tex-end-document)
1032 (run-hooks 'cal-tex-hook)))
1034 (defun cal-tex-cursor-filofax-week (&optional arg)
1035 "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
1036 Optional prefix argument specifies number of weeks.
1037 Weeks start on Monday.
1038 Diary entries are included if `cal-tex-diary' is t.
1039 Holidays are included if `cal-tex-holidays' is t."
1041 (let* ((n (if arg arg 1))
1042 (date (calendar-gregorian-from-absolute
1043 (calendar-dayname-on-or-before
1045 (calendar-absolute-from-gregorian
1046 (calendar-cursor-to-date t)))))
1047 (month (extract-calendar-month date))
1048 (year (extract-calendar-year date))
1049 (day (extract-calendar-day date))
1050 (holidays (if cal-tex-holidays
1051 (cal-tex-list-holidays
1052 (calendar-absolute-from-gregorian date)
1054 (calendar-absolute-from-gregorian date)))))
1055 (diary-list (if cal-tex-diary
1056 (cal-tex-list-diary-entries
1057 (calendar-absolute-from-gregorian
1058 (list month 1 year))
1060 (calendar-absolute-from-gregorian date))))))
1061 (cal-tex-preamble "twoside")
1062 (cal-tex-cmd "\\textwidth 3.25in")
1063 (cal-tex-cmd "\\textheight 6.5in")
1064 (cal-tex-cmd "\\oddsidemargin 1.75in")
1065 (cal-tex-cmd "\\evensidemargin 1.5in")
1066 (cal-tex-cmd "\\topmargin 0pt")
1067 (cal-tex-cmd "\\headheight -0.875in")
1068 (cal-tex-cmd "\\headsep 0.125in")
1069 (cal-tex-cmd "\\footskip .125in")
1070 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1071 \\long\\def\\rightday#1#2#3#4#5{%
1072 \\rule{\\textwidth}{0.3pt}\\\\%
1073 \\hbox to \\textwidth{%
1076 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1077 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1078 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1079 \\long\\def\\weekend#1#2#3#4#5{%
1080 \\rule{\\textwidth}{0.3pt}\\\\%
1081 \\hbox to \\textwidth{%
1084 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1085 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1086 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1087 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1088 \\long\\def\\leftday#1#2#3#4#5{%
1089 \\rule{\\textwidth}{0.3pt}\\\\%
1090 \\hbox to \\textwidth{%
1093 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1094 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1095 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1097 (cal-tex-b-document)
1098 (cal-tex-cmd "\\pagestyle{empty}\\ ")
1100 (calendar-for-loop i from 1 to n do
1101 (insert "\\lefthead")
1103 (let ((d (cal-tex-incr-date date 2)))
1104 (if (= (extract-calendar-month date)
1105 (extract-calendar-month d))
1107 (calendar-month-name
1108 (extract-calendar-month date))
1109 (extract-calendar-year date))
1110 (if (= (extract-calendar-year date)
1111 (extract-calendar-year d))
1112 (format "%s---%s %s"
1113 (calendar-month-name
1114 (extract-calendar-month date))
1115 (calendar-month-name
1116 (extract-calendar-month d))
1117 (extract-calendar-year date))
1118 (format "%s %s---%s %s"
1119 (calendar-month-name
1120 (extract-calendar-month date))
1121 (extract-calendar-year date)
1122 (calendar-month-name (extract-calendar-month d))
1123 (extract-calendar-year d))))))
1125 (calendar-for-loop j from 1 to 3 do
1126 (insert "\\leftday")
1127 (cal-tex-arg (calendar-day-name date))
1128 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1129 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1130 (cal-tex-arg (cal-tex-latexify-list holidays date))
1131 (cal-tex-arg (eval cal-tex-daily-string))
1133 (setq date (cal-tex-incr-date date)))
1134 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1136 (insert "\\righthead")
1138 (let ((d (cal-tex-incr-date date 3)))
1139 (if (= (extract-calendar-month date)
1140 (extract-calendar-month d))
1142 (calendar-month-name
1143 (extract-calendar-month date))
1144 (extract-calendar-year date))
1145 (if (= (extract-calendar-year date)
1146 (extract-calendar-year d))
1147 (format "%s---%s %s"
1148 (calendar-month-name
1149 (extract-calendar-month date))
1150 (calendar-month-name
1151 (extract-calendar-month d))
1152 (extract-calendar-year date))
1153 (format "%s %s---%s %s"
1154 (calendar-month-name
1155 (extract-calendar-month date))
1156 (extract-calendar-year date)
1157 (calendar-month-name (extract-calendar-month d))
1158 (extract-calendar-year d))))))
1160 (calendar-for-loop j from 1 to 2 do
1161 (insert "\\rightday")
1162 (cal-tex-arg (calendar-day-name date))
1163 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1164 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1165 (cal-tex-arg (cal-tex-latexify-list holidays date))
1166 (cal-tex-arg (eval cal-tex-daily-string))
1168 (setq date (cal-tex-incr-date date)))
1169 (calendar-for-loop j from 1 to 2 do
1170 (insert "\\weekend")
1171 (cal-tex-arg (calendar-day-name date))
1172 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1173 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1174 (cal-tex-arg (cal-tex-latexify-list holidays date))
1175 (cal-tex-arg (eval cal-tex-daily-string))
1177 (setq date (cal-tex-incr-date date)))
1180 (run-hooks 'cal-tex-week-hook)
1181 (cal-tex-newpage))))
1182 (cal-tex-end-document)
1183 (run-hooks 'cal-tex-hook)))
1188 (defun cal-tex-cursor-day (&optional arg)
1189 "Make a buffer with LaTeX commands for the day cursor is on.
1190 Optional prefix argument specifies number of days."
1192 (let ((n (if arg arg 1))
1193 (date (calendar-absolute-from-gregorian (calendar-cursor-to-date t))))
1194 (cal-tex-preamble "12pt")
1195 (cal-tex-cmd "\\textwidth 6.5in")
1196 (cal-tex-cmd "\\textheight 10.5in")
1197 (cal-tex-b-document)
1198 (cal-tex-cmd "\\pagestyle{empty}")
1199 (calendar-for-loop i from 1 to n do
1200 (cal-tex-vspace "-1.7in")
1201 (cal-tex-daily-page (calendar-gregorian-from-absolute date))
1202 (setq date (1+ date))
1206 (run-hooks 'cal-tex-daily-hook))))
1207 (cal-tex-end-document)
1208 (run-hooks 'cal-tex-hook)))
1210 (defun cal-tex-daily-page (date)
1211 "Make a calendar page for Gregorian DATE on 8.5 by 11 paper."
1213 (month-name (calendar-month-name (extract-calendar-month date))))
1214 (cal-tex-banner "cal-tex-daily-page")
1215 (cal-tex-b-makebox "4cm" "l")
1216 (cal-tex-b-parbox "b" "3.8cm")
1217 (cal-tex-rule "0mm" "0mm" "2cm")
1218 (cal-tex-Huge (number-to-string (extract-calendar-day date)))
1220 (cal-tex-bf month-name )
1222 (cal-tex-hspace "1cm")
1223 (cal-tex-scriptsize (eval cal-tex-daily-string))
1224 (cal-tex-hspace "3.5cm")
1227 (cal-tex-b-makebox "4cm" "r")
1228 (cal-tex-bf (calendar-day-name date))
1231 (cal-tex-hspace ".4cm")
1232 (cal-tex-rule "0mm" "16.1cm" "1mm")
1234 (calendar-for-loop i from cal-tex-daily-start to cal-tex-daily-end do
1235 (cal-tex-cmd "\\noindent")
1236 (setq hour (if cal-tex-24
1239 (if (= 0 hour) (setq hour 12))
1240 (cal-tex-b-makebox "1cm" "c")
1241 (cal-tex-arg (number-to-string hour))
1243 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1245 (cal-tex-b-makebox "1cm" "c")
1246 (cal-tex-arg "$\\diamond$" )
1248 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1249 (cal-tex-nl ".2cm"))
1251 (insert (cal-tex-mini-calendar
1252 (extract-calendar-month (cal-tex-previous-month date))
1253 (extract-calendar-year (cal-tex-previous-month date))
1254 "lastmonth" "1.1in" "1in"))
1255 (insert (cal-tex-mini-calendar
1256 (extract-calendar-month date)
1257 (extract-calendar-year date)
1258 "thismonth" "1.1in" "1in"))
1259 (insert (cal-tex-mini-calendar
1260 (extract-calendar-month (cal-tex-next-month date))
1261 (extract-calendar-year (cal-tex-next-month date))
1262 "nextmonth" "1.1in" "1in"))
1263 (insert "\\hbox to \\textwidth{")
1265 (insert "\\lastmonth")
1267 (insert "\\thismonth")
1269 (insert "\\nextmonth")
1272 (cal-tex-banner "end of cal-tex-daily-page")))
1278 (defun cal-tex-mini-calendar (month year name width height &optional size)
1279 "Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT.
1280 Optional SIZE gives the point size; scriptsize is the default,"
1281 (let* ((blank-days;; at start of month
1283 (- (calendar-day-of-week (list month 1 year))
1284 calendar-week-start-day)
1286 (last (calendar-last-day-of-month month year))
1287 (str (concat "\\def\\" name "{\\hbox to" width "{%\n"
1288 "\\vbox to" height "{%\n"
1289 "\\vfil \\hbox to" width "{%\n"
1291 (if size size "scriptsize")
1293 "{@{\\hspace{1mm}}r@{\\hspace{1mm}}r@{\\hspace{1mm}}r@{\\hspace{1mm}}"
1294 "r@{\\hspace{1mm}}r@{\\hspace{1mm}}r@{\\hspace{1mm}}r@{\\hspace{1mm}}}%\n"
1295 "\\multicolumn{7}{c}{"
1296 (calendar-month-name month)
1298 (int-to-string year)
1300 (calendar-for-loop i from 0 to 6 do
1301 (setq str (concat str
1302 (substring (aref calendar-day-name-array
1303 (mod (+ calendar-week-start-day i) 7))
1308 (calendar-for-loop i from 1 to blank-days do
1309 (setq str (concat str " & ")))
1310 (calendar-for-loop i from 1 to last do
1311 (setq str (concat str (int-to-string i)))
1312 (setq str (concat str (if (zerop (mod (+ i blank-days) 7))
1313 (if (/= i last) "\\\\[0.5mm]\n" "")
1315 (setq str (concat str "\n\\end{tabular}\\hfil}\\vfil}}}%\n"))
1319 ;;; Various calendar functions
1322 (defun cal-tex-incr-date (date &optional n)
1323 "The date of the day following DATE.
1324 If optional N is given, the date of N days after DATE."
1325 (calendar-gregorian-from-absolute
1326 (+ (if n n 1) (calendar-absolute-from-gregorian date))))
1328 (defun cal-tex-latexify-list (date-list date &optional separator)
1329 "Return string with concatenated, LaTeXified entries in DATE_LIST for DATE.
1330 Use double backslash as a separator unless optional SEPARATOR is given."
1331 (mapconcat '(lambda (x) (cal-tex-LaTeXify-string x))
1336 (calendar-date-equal date (car (car p)))
1337 (setq result (append (cdr (car p)) result)))
1340 (if separator separator "\\\\")))
1342 (defun cal-tex-previous-month (date)
1343 "Return the date of the first day in the month previous to DATE."
1344 (let* ((month (extract-calendar-month date))
1345 (year (extract-calendar-year date)))
1346 (increment-calendar-month month year -1)
1347 (list month 1 year)))
1349 (defun cal-tex-next-month (date)
1350 "Return the date of the first day in the month following DATE."
1351 (let* ((month (extract-calendar-month date))
1352 (year (extract-calendar-year date)))
1353 (increment-calendar-month month year 1)
1354 (list month 1 year)))
1360 (defun cal-tex-end-document ()
1361 "Finish the LaTeX document.
1362 Insert the trailer to LaTeX document, pop to LaTeX buffer, add
1363 informative header, and run HOOK."
1364 (cal-tex-e-document)
1366 (pop-to-buffer cal-tex-buffer)
1367 (goto-char (point-min))
1368 (cal-tex-comment " This buffer was produced by cal-tex.el.")
1369 (cal-tex-comment " To print a calendar, type")
1370 (cal-tex-comment " M-x tex-buffer RET")
1371 (cal-tex-comment " M-x tex-print RET")
1372 (goto-char (point-min)))
1374 (defun cal-tex-insert-preamble (weeks landscape size &optional append)
1375 "Initialize the output buffer.
1376 Select the output buffer, and insert the preamble for a calendar of
1377 WEEKS weeks. Insert code for landscape mode if LANDSCAPE is true.
1378 Use pointsize SIZE. Optional argument APPEND, if t, means add to end of
1379 without erasing current contents."
1380 (let ((width "18cm")
1385 (setq height "18cm")))
1388 (cal-tex-preamble size)
1391 (cal-tex-cmd "\\oddsidemargin -1.75cm")
1392 (cal-tex-cmd "\\def\\holidaymult{.06}"))
1393 (cal-tex-cmd "\\special{landscape}")
1394 (cal-tex-cmd "\\textwidth 9.5in")
1395 (cal-tex-cmd "\\textheight 7in")
1397 (cal-tex-cmd "\\def\\holidaymult{.08}"))
1398 (cal-tex-cmd cal-tex-caldate)
1399 (cal-tex-cmd cal-tex-myday)
1400 (cal-tex-b-document)
1401 (cal-tex-cmd "\\pagestyle{empty}")))
1402 (cal-tex-cmd "\\setlength{\\cellwidth}" width)
1403 (insert (format "\\setlength{\\cellwidth}{%f\\cellwidth}\n"
1404 (/ 1.1 (length cal-tex-which-days))))
1405 (cal-tex-cmd "\\setlength{\\cellheight}" height)
1406 (insert (format "\\setlength{\\cellheight}{%f\\cellheight}\n"
1408 (cal-tex-cmd "\\ \\par")
1409 (cal-tex-vspace "-3cm")))
1411 (defvar cal-tex-LaTeX-subst-list
1413 ("\"". "''");; Quote changes meaning when list is reversed.
1424 ("\n" . "\\ \\\\")) ;\\ needed for e.g \begin{center}\n AA\end{center}
1425 "List of symbols and their replacements.")
1427 (defun cal-tex-LaTeXify-string (string)
1428 "Protect special characters in STRING from LaTeX."
1433 (list cal-tex-LaTeX-subst-list))
1434 (while (not (string-equal tail ""))
1435 (let* ((ch (substring tail 0 1))
1436 (pair (assoc ch list)))
1437 (if (and pair (string-equal ch "\""))
1438 (setq list (reverse list)));; Quote changes meaning each time.
1439 (setq tail (substring tail 1))
1440 (setq head (concat head (if pair (cdr pair) ch)))))
1443 (defun cal-tex-hfill () "Insert hfill." (insert "\\hfill"))
1445 (defun cal-tex-newpage () "Insert newpage." (insert "\\newpage%\n"))
1447 (defun cal-tex-noindent () "Insert noindent." (insert "\\noindent"))
1449 (defun cal-tex-vspace (space)
1450 "Insert vspace command to move SPACE vertically."
1451 (insert "\\vspace*{" space "}")
1454 (defun cal-tex-hspace (space)
1455 "Insert hspace command to move SPACE horizontally."
1456 (insert "\\hspace*{" space "}")
1459 (defun cal-tex-comment (&optional comment)
1460 "Insert % at end of line, include COMMENT if present, and move
1467 (defun cal-tex-banner (comment)
1468 "Insert the COMMENT separated by blank lines."
1471 (cal-tex-comment (concat "\t\t\t" comment))
1475 (defun cal-tex-nl (&optional skip comment)
1476 "End a line with \\. If SKIP, then add that much spacing.
1477 Add COMMENT if present"
1480 (insert "[" skip "]"))
1481 (cal-tex-comment comment))
1483 (defun cal-tex-arg (&optional text)
1484 "Insert optional TEXT surrounded by braces."
1486 (if text (insert text))
1489 (defun cal-tex-cmd (cmd &optional arg)
1490 "Insert LaTeX CMD, with optional ARG, and end with %"
1499 (defun cal-tex-b-document ()
1500 "Insert beginning of document."
1501 (cal-tex-cmd "\\begin{document}"))
1503 (defun cal-tex-e-document ()
1504 "Insert end of document."
1505 (cal-tex-cmd "\\end{document}"))
1507 (defun cal-tex-b-center ()
1508 "Insert beginning of centered block."
1509 (cal-tex-cmd "\\begin{center}"))
1511 (defun cal-tex-e-center ()
1512 "Insert end of centered block."
1514 (cal-tex-cmd "\\end{center}"))
1522 (defun cal-tex-b-parbox (position width)
1523 "Insert parbox with parameters POSITION and WIDTH."
1524 (insert "\\parbox[" position "]{" width "}{")
1527 (defun cal-tex-e-parbox (&optional height)
1528 "Insert end of parbox. Force it to be a given HEIGHT."
1531 (cal-tex-rule "0mm" "0mm" height))
1533 (cal-tex-comment "end parbox"))
1535 (defun cal-tex-b-framebox ( width position )
1536 "Insert framebox with parameters WIDTH and POSITION (clr)."
1537 (insert "\\framebox[" width "][" position "]{" )
1540 (defun cal-tex-e-framebox ()
1541 "Insert end of framebox."
1544 (cal-tex-comment "end framebox"))
1547 (defun cal-tex-b-makebox ( width position )
1548 "Insert makebox with parameters WIDTH and POSITION (clr)."
1549 (insert "\\makebox[" width "][" position "]{" )
1552 (defun cal-tex-e-makebox ()
1553 "Insert end of makebox."
1556 (cal-tex-comment "end makebox"))
1559 (defun cal-tex-rule (lower width height)
1560 "Insert a rule with parameters LOWER WIDTH HEIGHT."
1561 (insert "\\rule[" lower "]{" width "}{" height "}"))
1567 (defun cal-tex-em (string)
1568 "Insert STRING in bf font."
1569 (insert "{\\em " string "}"))
1571 (defun cal-tex-bf (string)
1572 "Insert STRING in bf font."
1573 (insert "{\\bf " string "}"))
1575 (defun cal-tex-scriptsize (string)
1576 "Insert STRING in scriptsize font."
1577 (insert "{\\scriptsize " string "}"))
1579 (defun cal-tex-huge (string)
1580 "Insert STRING in huge size."
1581 (insert "{\\huge " string "}"))
1583 (defun cal-tex-Huge (string)
1584 "Insert STRING in Huge size."
1585 (insert "{\\Huge " string "}"))
1587 (defun cal-tex-Huge-bf (string)
1588 "Insert STRING in Huge bf size."
1589 (insert "{\\Huge\\bf " string "}"))
1591 (defun cal-tex-large (string)
1592 "Insert STRING in large size."
1593 (insert "{\\large " string "}"))
1595 (defun cal-tex-large-bf (string)
1596 "Insert STRING in large bf size."
1597 (insert "{\\large\\bf " string "}"))
1601 ;;; cal-tex.el ends here