;;; cal-tex.el --- calendar functions for printing calendars with LaTeX
-;; Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
-;; Free Software Foundation, Inc.
+;; Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+;; 2009, 2010 Free Software Foundation, Inc.
;; Author: Steve Fisk <fisk@bowdoin.edu>
;; Edward M. Reingold <reingold@cs.uiuc.edu>
(year (calendar-extract-year date))
(end-month month)
(end-year year)
+ ;; FIXME -landscape sets cal-tex-which-days?
(d1 (calendar-absolute-from-gregorian (list month 1 year)))
(d2 (progn
(calendar-increment-month end-month end-year (1- n))
(calendar-last-day-of-month end-month end-year)
end-year))))
(diary-list (if cal-tex-diary (cal-tex-list-diary-entries d1 d2)))
- (holidays (if cal-tex-holidays (cal-tex-list-holidays d1 d2)))
- other-month other-year)
+ (holidays (if cal-tex-holidays (cal-tex-list-holidays d1 d2))))
(cal-tex-insert-preamble (cal-tex-number-weeks month year n) nil "12pt")
(if (> n 1)
(cal-tex-cmd cal-tex-cal-multi-month)
(cal-tex-nl ".2cm")
(cal-tex-insert-blank-days month year cal-tex-day-prefix)
(dotimes (idummy n)
- (setq other-month month
- other-year year)
(cal-tex-insert-days month year diary-list holidays cal-tex-day-prefix)
- (when (= 6 (mod (calendar-absolute-from-gregorian
- (list month
- (calendar-last-day-of-month month year)
- year))
- 7)) ; last day of month was Saturday
+ (when (= (calendar-week-end-day)
+ (calendar-day-of-week
+ (list month
+ (calendar-last-day-of-month month year)
+ year))) ; last day of month was last day of week
(cal-tex-hfill)
(cal-tex-nl))
(calendar-increment-month month year 1))
(defun cal-tex-insert-day-names ()
"Insert the names of the days at top of a monthly calendar."
- (dotimes (i 7)
- (if (memq i cal-tex-which-days)
- (insert (format cal-tex-day-name-format
- (cal-tex-LaTeXify-string
- (aref calendar-day-name-array
- (mod (+ calendar-week-start-day i) 7))))))
- (cal-tex-comment)))
+ (let (j)
+ (dotimes (i 7)
+ (if (memq (setq j (mod (+ calendar-week-start-day i) 7))
+ cal-tex-which-days)
+ (insert (format cal-tex-day-name-format
+ (cal-tex-LaTeXify-string
+ (aref calendar-day-name-array j)))))
+ (cal-tex-comment))))
(defun cal-tex-insert-month-header (n month year end-month end-year)
"Create a title for a calendar.
calendar-week-start-day)
7)))
(dotimes (i blank-days)
- (if (memq i cal-tex-which-days)
+ (if (memq (mod (+ calendar-week-start-day i) 7) cal-tex-which-days)
(insert (format day-format " " " ") "{}{}{}{}%\n"))))))
(defun cal-tex-insert-blank-days-at-end (month year day-format)
7))
(i blank-days))
(while (<= (setq i (1+ i)) 6)
- (if (memq i cal-tex-which-days)
+ (if (memq (mod (+ calendar-week-start-day i) 7) cal-tex-which-days)
(insert (format day-format "" "") "{}{}{}{}%\n"))))))
(defun cal-tex-first-blank-p (month year)
"Determine if any days of the first week will be printed.
Return t if there will there be any days of the first week printed
in the calendar starting in MONTH YEAR."
- (let (any-days the-saturday) ; the day of week of 1st Saturday
- (dotimes (i 7)
- (if (= 6 (calendar-day-of-week (list month (1+ i) year)))
- (setq the-saturday (1+ i))))
- (dotimes (i the-saturday)
- (if (memq (calendar-day-of-week (list month (1+ i) year))
- cal-tex-which-days)
- (setq any-days t)))
- any-days))
+ ;; Check days 1-7 of the month, until we find the last day of the week.
+ (catch 'found
+ (let (dow)
+ (dotimes (i 7)
+ (if (memq (setq dow (calendar-day-of-week (list month (1+ i) year)))
+ cal-tex-which-days)
+ (throw 'found t)
+ (if (= dow (calendar-week-end-day)) (throw 'found nil)))))))
(defun cal-tex-last-blank-p (month year)
"Determine if any days of the last week will be printed.
Return t if there will there be any days of the last week printed
in the calendar starting in MONTH YEAR."
- (let* ((last-day (calendar-last-day-of-month month year))
- (i (- last-day 7))
- any-days the-sunday) ; the day of week of last Sunday
- (while (<= (setq i (1+ i)) last-day)
- (if (zerop (calendar-day-of-week (list month i year)))
- (setq the-sunday i)))
- (setq i (1- the-sunday))
- (while (<= (setq i (1+ i)) last-day)
- (if (memq (calendar-day-of-week (list month i year)) cal-tex-which-days)
- (setq any-days t)))
- any-days))
+ ;; Check backwards from the last day of the month, until we find the
+ ;; start of the last week in the month.
+ (catch 'found
+ (let ((last-day (calendar-last-day-of-month month year))
+ day dow)
+ (dotimes (i 7)
+ (if (memq (setq dow (calendar-day-of-week
+ (list month (- last-day i) year)))
+ cal-tex-which-days)
+ (throw 'found t)
+ (if (= dow calendar-week-start-day) (throw 'found nil)))))))
(defun cal-tex-number-weeks (month year n)
"Determine the number of weeks in a range of dates.
(- (calendar-day-of-week (list month 1 year))
calendar-week-start-day)
7))
- (last (calendar-last-day-of-month month year))
+ (last( calendar-last-day-of-month month year))
(str (concat "\\def\\" name "{\\hbox to" width "{%\n"
"\\vbox to" height "{%\n"
"\\vfil \\hbox to" width "{%\n"