comparison lisp/calendar/cal-tex.el @ 109492:2bd8f25ebb95

merge trunk
author Kenichi Handa <handa@etlken>
date Fri, 23 Jul 2010 15:50:31 +0900
parents d916e52744cb
children 280c8ae2476d 376148b31b5e
comparison
equal deleted inserted replaced
109388:64d1dc916ed8 109492:2bd8f25ebb95
1 ;;; cal-tex.el --- calendar functions for printing calendars with LaTeX 1 ;;; cal-tex.el --- calendar functions for printing calendars with LaTeX
2 2
3 ;; Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 3 ;; Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
4 ;; Free Software Foundation, Inc. 4 ;; 2009, 2010 Free Software Foundation, Inc.
5 5
6 ;; Author: Steve Fisk <fisk@bowdoin.edu> 6 ;; Author: Steve Fisk <fisk@bowdoin.edu>
7 ;; Edward M. Reingold <reingold@cs.uiuc.edu> 7 ;; Edward M. Reingold <reingold@cs.uiuc.edu>
8 ;; Maintainer: Glenn Morris <rgm@gnu.org> 8 ;; Maintainer: Glenn Morris <rgm@gnu.org>
9 ;; Keywords: calendar 9 ;; Keywords: calendar
505 (let* ((date (calendar-cursor-to-date t event)) 505 (let* ((date (calendar-cursor-to-date t event))
506 (month (calendar-extract-month date)) 506 (month (calendar-extract-month date))
507 (year (calendar-extract-year date)) 507 (year (calendar-extract-year date))
508 (end-month month) 508 (end-month month)
509 (end-year year) 509 (end-year year)
510 ;; FIXME -landscape sets cal-tex-which-days?
510 (d1 (calendar-absolute-from-gregorian (list month 1 year))) 511 (d1 (calendar-absolute-from-gregorian (list month 1 year)))
511 (d2 (progn 512 (d2 (progn
512 (calendar-increment-month end-month end-year (1- n)) 513 (calendar-increment-month end-month end-year (1- n))
513 (calendar-absolute-from-gregorian 514 (calendar-absolute-from-gregorian
514 (list end-month 515 (list end-month
515 (calendar-last-day-of-month end-month end-year) 516 (calendar-last-day-of-month end-month end-year)
516 end-year)))) 517 end-year))))
517 (diary-list (if cal-tex-diary (cal-tex-list-diary-entries d1 d2))) 518 (diary-list (if cal-tex-diary (cal-tex-list-diary-entries d1 d2)))
518 (holidays (if cal-tex-holidays (cal-tex-list-holidays d1 d2))) 519 (holidays (if cal-tex-holidays (cal-tex-list-holidays d1 d2))))
519 other-month other-year)
520 (cal-tex-insert-preamble (cal-tex-number-weeks month year n) nil "12pt") 520 (cal-tex-insert-preamble (cal-tex-number-weeks month year n) nil "12pt")
521 (if (> n 1) 521 (if (> n 1)
522 (cal-tex-cmd cal-tex-cal-multi-month) 522 (cal-tex-cmd cal-tex-cal-multi-month)
523 (cal-tex-cmd cal-tex-cal-one-month)) 523 (cal-tex-cmd cal-tex-cal-one-month))
524 (cal-tex-insert-month-header n month year end-month end-year) 524 (cal-tex-insert-month-header n month year end-month end-year)
525 (cal-tex-insert-day-names) 525 (cal-tex-insert-day-names)
526 (cal-tex-nl ".2cm") 526 (cal-tex-nl ".2cm")
527 (cal-tex-insert-blank-days month year cal-tex-day-prefix) 527 (cal-tex-insert-blank-days month year cal-tex-day-prefix)
528 (dotimes (idummy n) 528 (dotimes (idummy n)
529 (setq other-month month
530 other-year year)
531 (cal-tex-insert-days month year diary-list holidays cal-tex-day-prefix) 529 (cal-tex-insert-days month year diary-list holidays cal-tex-day-prefix)
532 (when (= 6 (mod (calendar-absolute-from-gregorian 530 (when (= (calendar-week-end-day)
533 (list month 531 (calendar-day-of-week
534 (calendar-last-day-of-month month year) 532 (list month
535 year)) 533 (calendar-last-day-of-month month year)
536 7)) ; last day of month was Saturday 534 year))) ; last day of month was last day of week
537 (cal-tex-hfill) 535 (cal-tex-hfill)
538 (cal-tex-nl)) 536 (cal-tex-nl))
539 (calendar-increment-month month year 1)) 537 (calendar-increment-month month year 1))
540 (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix)) 538 (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix))
541 (cal-tex-end-document) 539 (cal-tex-end-document)
568 (cal-tex-hfill) 566 (cal-tex-hfill)
569 (cal-tex-nl))))) 567 (cal-tex-nl)))))
570 568
571 (defun cal-tex-insert-day-names () 569 (defun cal-tex-insert-day-names ()
572 "Insert the names of the days at top of a monthly calendar." 570 "Insert the names of the days at top of a monthly calendar."
573 (dotimes (i 7) 571 (let (j)
574 (if (memq i cal-tex-which-days) 572 (dotimes (i 7)
575 (insert (format cal-tex-day-name-format 573 (if (memq (setq j (mod (+ calendar-week-start-day i) 7))
576 (cal-tex-LaTeXify-string 574 cal-tex-which-days)
577 (aref calendar-day-name-array 575 (insert (format cal-tex-day-name-format
578 (mod (+ calendar-week-start-day i) 7)))))) 576 (cal-tex-LaTeXify-string
579 (cal-tex-comment))) 577 (aref calendar-day-name-array j)))))
578 (cal-tex-comment))))
580 579
581 (defun cal-tex-insert-month-header (n month year end-month end-year) 580 (defun cal-tex-insert-month-header (n month year end-month end-year)
582 "Create a title for a calendar. 581 "Create a title for a calendar.
583 A title is inserted for a calendar with N months starting with 582 A title is inserted for a calendar with N months starting with
584 MONTH YEAR and ending with END-MONTH END-YEAR." 583 MONTH YEAR and ending with END-MONTH END-YEAR."
601 (mod 600 (mod
602 (- (calendar-day-of-week (list month 1 year)) 601 (- (calendar-day-of-week (list month 1 year))
603 calendar-week-start-day) 602 calendar-week-start-day)
604 7))) 603 7)))
605 (dotimes (i blank-days) 604 (dotimes (i blank-days)
606 (if (memq i cal-tex-which-days) 605 (if (memq (mod (+ calendar-week-start-day i) 7) cal-tex-which-days)
607 (insert (format day-format " " " ") "{}{}{}{}%\n")))))) 606 (insert (format day-format " " " ") "{}{}{}{}%\n"))))))
608 607
609 (defun cal-tex-insert-blank-days-at-end (month year day-format) 608 (defun cal-tex-insert-blank-days-at-end (month year day-format)
610 "Insert code for final days not in calendar. 609 "Insert code for final days not in calendar.
611 Insert LaTeX code for the blank days at the end of the MONTH in YEAR. 610 Insert LaTeX code for the blank days at the end of the MONTH in YEAR.
617 (- (calendar-day-of-week (list month last-day year)) 616 (- (calendar-day-of-week (list month last-day year))
618 calendar-week-start-day) 617 calendar-week-start-day)
619 7)) 618 7))
620 (i blank-days)) 619 (i blank-days))
621 (while (<= (setq i (1+ i)) 6) 620 (while (<= (setq i (1+ i)) 6)
622 (if (memq i cal-tex-which-days) 621 (if (memq (mod (+ calendar-week-start-day i) 7) cal-tex-which-days)
623 (insert (format day-format "" "") "{}{}{}{}%\n")))))) 622 (insert (format day-format "" "") "{}{}{}{}%\n"))))))
624 623
625 (defun cal-tex-first-blank-p (month year) 624 (defun cal-tex-first-blank-p (month year)
626 "Determine if any days of the first week will be printed. 625 "Determine if any days of the first week will be printed.
627 Return t if there will there be any days of the first week printed 626 Return t if there will there be any days of the first week printed
628 in the calendar starting in MONTH YEAR." 627 in the calendar starting in MONTH YEAR."
629 (let (any-days the-saturday) ; the day of week of 1st Saturday 628 ;; Check days 1-7 of the month, until we find the last day of the week.
630 (dotimes (i 7) 629 (catch 'found
631 (if (= 6 (calendar-day-of-week (list month (1+ i) year))) 630 (let (dow)
632 (setq the-saturday (1+ i)))) 631 (dotimes (i 7)
633 (dotimes (i the-saturday) 632 (if (memq (setq dow (calendar-day-of-week (list month (1+ i) year)))
634 (if (memq (calendar-day-of-week (list month (1+ i) year)) 633 cal-tex-which-days)
635 cal-tex-which-days) 634 (throw 'found t)
636 (setq any-days t))) 635 (if (= dow (calendar-week-end-day)) (throw 'found nil)))))))
637 any-days))
638 636
639 (defun cal-tex-last-blank-p (month year) 637 (defun cal-tex-last-blank-p (month year)
640 "Determine if any days of the last week will be printed. 638 "Determine if any days of the last week will be printed.
641 Return t if there will there be any days of the last week printed 639 Return t if there will there be any days of the last week printed
642 in the calendar starting in MONTH YEAR." 640 in the calendar starting in MONTH YEAR."
643 (let* ((last-day (calendar-last-day-of-month month year)) 641 ;; Check backwards from the last day of the month, until we find the
644 (i (- last-day 7)) 642 ;; start of the last week in the month.
645 any-days the-sunday) ; the day of week of last Sunday 643 (catch 'found
646 (while (<= (setq i (1+ i)) last-day) 644 (let ((last-day (calendar-last-day-of-month month year))
647 (if (zerop (calendar-day-of-week (list month i year))) 645 day dow)
648 (setq the-sunday i))) 646 (dotimes (i 7)
649 (setq i (1- the-sunday)) 647 (if (memq (setq dow (calendar-day-of-week
650 (while (<= (setq i (1+ i)) last-day) 648 (list month (- last-day i) year)))
651 (if (memq (calendar-day-of-week (list month i year)) cal-tex-which-days) 649 cal-tex-which-days)
652 (setq any-days t))) 650 (throw 'found t)
653 any-days)) 651 (if (= dow calendar-week-start-day) (throw 'found nil)))))))
654 652
655 (defun cal-tex-number-weeks (month year n) 653 (defun cal-tex-number-weeks (month year n)
656 "Determine the number of weeks in a range of dates. 654 "Determine the number of weeks in a range of dates.
657 Compute the number of weeks in the calendar starting with MONTH and YEAR, 655 Compute the number of weeks in the calendar starting with MONTH and YEAR,
658 and lasting N months, including only the days in WHICH-DAYS. As it stands, 656 and lasting N months, including only the days in WHICH-DAYS. As it stands,
1497 (let ((blank-days ; at start of month 1495 (let ((blank-days ; at start of month
1498 (mod 1496 (mod
1499 (- (calendar-day-of-week (list month 1 year)) 1497 (- (calendar-day-of-week (list month 1 year))
1500 calendar-week-start-day) 1498 calendar-week-start-day)
1501 7)) 1499 7))
1502 (last (calendar-last-day-of-month month year)) 1500 (last( calendar-last-day-of-month month year))
1503 (str (concat "\\def\\" name "{\\hbox to" width "{%\n" 1501 (str (concat "\\def\\" name "{\\hbox to" width "{%\n"
1504 "\\vbox to" height "{%\n" 1502 "\\vbox to" height "{%\n"
1505 "\\vfil \\hbox to" width "{%\n" 1503 "\\vfil \\hbox to" width "{%\n"
1506 "\\hfil\\" ptsize 1504 "\\hfil\\" ptsize
1507 "\\begin{tabular}" 1505 "\\begin{tabular}"