]> code.delx.au - gnu-emacs/blobdiff - lisp/calendar/cal-tex.el
Merge from emacs-24; up to 2012-04-30T11:57:47Z!sdl.web@gmail.com
[gnu-emacs] / lisp / calendar / cal-tex.el
index e6ba1ad343977d765dd1993116e9f14cf7f23d58..2452f44448ce7293222fb9fc69a73e44f862e260 100644 (file)
@@ -1,7 +1,6 @@
 ;;; cal-tex.el --- calendar functions for printing calendars with LaTeX
 
 ;;; 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-2012 Free Software Foundation, Inc.
 
 ;; Author: Steve Fisk <fisk@bowdoin.edu>
 ;;         Edward M. Reingold <reingold@cs.uiuc.edu>
 
 ;; Author: Steve Fisk <fisk@bowdoin.edu>
 ;;         Edward M. Reingold <reingold@cs.uiuc.edu>
@@ -238,31 +237,9 @@ The names are taken from `calendar-day-name-array'.")
   "LaTeX code to insert one box with date info in calendar.
 This definition is the heart of the calendar!")
 
   "LaTeX code to insert one box with date info in calendar.
 This definition is the heart of the calendar!")
 
-(autoload 'calendar-holiday-list "holidays")
-
-(defun cal-tex-list-holidays (d1 d2)
-  "Generate a list of all holidays from absolute date D1 to D2."
-  (let* ((start (calendar-gregorian-from-absolute d1))
-         (displayed-month (calendar-extract-month start))
-         (displayed-year (calendar-extract-year start))
-         (end (calendar-gregorian-from-absolute d2))
-         (end-month (calendar-extract-month end))
-         (end-year (calendar-extract-year end))
-         (number-of-intervals
-          (1+ (/ (calendar-interval displayed-month displayed-year
-                                    end-month end-year)
-                 3)))
-         holidays in-range a)
-    (calendar-increment-month displayed-month displayed-year 1)
-    (dotimes (idummy number-of-intervals)
-      (setq holidays (append holidays (calendar-holiday-list)))
-      (calendar-increment-month displayed-month displayed-year 3))
-    (dolist (hol holidays)
-      (and (car hol)
-           (setq a (calendar-absolute-from-gregorian (car hol)))
-           (and (<= d1 a) (<= a d2))
-           (setq in-range (append (list hol) in-range))))
-    in-range))
+(autoload 'holiday-in-range "holidays")
+
+(define-obsolete-function-alias 'cal-tex-list-holidays 'holiday-in-range "24.2")
 
 (autoload 'diary-list-entries "diary-lib")
 
 
 (autoload 'diary-list-entries "diary-lib")
 
@@ -447,7 +424,7 @@ Optional EVENT indicates a buffer position to use instead of point."
                       (calendar-last-day-of-month end-month end-year)
                       end-year))))
          (diary-list (if cal-tex-diary (cal-tex-list-diary-entries d1 d2)))
                       (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)))
+         (holidays (if cal-tex-holidays (holiday-in-range d1 d2)))
          other-month other-year small-months-at-start)
     (cal-tex-insert-preamble (cal-tex-number-weeks month year 1) t "12pt")
     (cal-tex-cmd cal-tex-cal-one-month)
          other-month other-year small-months-at-start)
     (cal-tex-insert-preamble (cal-tex-number-weeks month year 1) t "12pt")
     (cal-tex-cmd cal-tex-cal-one-month)
@@ -517,7 +494,7 @@ indicates a buffer position to use instead of point."
                       (calendar-last-day-of-month end-month end-year)
                       end-year))))
          (diary-list (if cal-tex-diary (cal-tex-list-diary-entries d1 d2)))
                       (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))))
+         (holidays (if cal-tex-holidays (holiday-in-range 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-insert-preamble (cal-tex-number-weeks month year n) nil "12pt")
     (if (> n 1)
         (cal-tex-cmd cal-tex-cal-multi-month)
@@ -526,7 +503,7 @@ indicates a buffer position to use instead of point."
     (cal-tex-insert-day-names)
     (cal-tex-nl ".2cm")
     (cal-tex-insert-blank-days month year cal-tex-day-prefix)
     (cal-tex-insert-day-names)
     (cal-tex-nl ".2cm")
     (cal-tex-insert-blank-days month year cal-tex-day-prefix)
-    (dotimes (idummy n)
+    (dotimes (_idummy n)
       (cal-tex-insert-days month year diary-list holidays cal-tex-day-prefix)
       (when (= (calendar-week-end-day)
                (calendar-day-of-week
       (cal-tex-insert-days month year diary-list holidays cal-tex-day-prefix)
       (when (= (calendar-week-end-day)
                (calendar-day-of-week
@@ -643,7 +620,7 @@ in the calendar starting in MONTH YEAR."
   ;; start of the last week in the month.
   (catch 'found
     (let ((last-day (calendar-last-day-of-month month year))
   ;; start of the last week in the month.
   (catch 'found
     (let ((last-day (calendar-last-day-of-month month year))
-          day dow)
+          dow)
       (dotimes (i 7)
         (if (memq (setq dow (calendar-day-of-week
                              (list month (- last-day i) year)))
       (dotimes (i 7)
         (if (memq (setq dow (calendar-day-of-week
                              (list month (- last-day i) year)))
@@ -698,7 +675,7 @@ entries are not shown).  The calendar shows the hours 8-12am, 1-5pm."
          (d1 (calendar-absolute-from-gregorian date))
          (d2 (+ (* 7 n) d1))
          (holidays (if cal-tex-holidays
          (d1 (calendar-absolute-from-gregorian date))
          (d2 (+ (* 7 n) d1))
          (holidays (if cal-tex-holidays
-                       (cal-tex-list-holidays d1 d2))))
+                       (holiday-in-range d1 d2))))
     (cal-tex-preamble "11pt")
     (cal-tex-cmd "\\textwidth   6.5in")
     (cal-tex-cmd "\\textheight 10.5in")
     (cal-tex-preamble "11pt")
     (cal-tex-cmd "\\textwidth   6.5in")
     (cal-tex-cmd "\\textheight 10.5in")
@@ -718,7 +695,7 @@ entries are not shown).  The calendar shows the hours 8-12am, 1-5pm."
       (cal-tex-e-center)
       (cal-tex-hspace "-.2in")
       (cal-tex-b-parbox "l" "7in")
       (cal-tex-e-center)
       (cal-tex-hspace "-.2in")
       (cal-tex-b-parbox "l" "7in")
-      (dotimes (jdummy 7)
+      (dotimes (_jdummy 7)
         (cal-tex-week-hours date holidays "3.1")
         (setq date (cal-tex-incr-date date)))
       (cal-tex-e-parbox)
         (cal-tex-week-hours date holidays "3.1")
         (setq date (cal-tex-incr-date date)))
       (cal-tex-e-parbox)
@@ -750,11 +727,10 @@ Optional EVENT indicates a buffer position to use instead of point."
                   (calendar-cursor-to-date t event)))))
          (month (calendar-extract-month date))
          (year (calendar-extract-year date))
                   (calendar-cursor-to-date t event)))))
          (month (calendar-extract-month date))
          (year (calendar-extract-year date))
-         (d date)
          (d1 (calendar-absolute-from-gregorian date))
          (d2 (+ (* 7 n) d1))
          (holidays (if cal-tex-holidays
          (d1 (calendar-absolute-from-gregorian date))
          (d2 (+ (* 7 n) d1))
          (holidays (if cal-tex-holidays
-                       (cal-tex-list-holidays d1 d2))))
+                       (holiday-in-range d1 d2))))
     (cal-tex-preamble "12pt")
     (cal-tex-cmd "\\textwidth   6.5in")
     (cal-tex-cmd "\\textheight 10.5in")
     (cal-tex-preamble "12pt")
     (cal-tex-cmd "\\textwidth   6.5in")
     (cal-tex-cmd "\\textheight 10.5in")
@@ -774,7 +750,7 @@ Optional EVENT indicates a buffer position to use instead of point."
       (cal-tex-e-center)
       (cal-tex-hspace "-.2in")
       (cal-tex-b-parbox "l" "\\textwidth")
       (cal-tex-e-center)
       (cal-tex-hspace "-.2in")
       (cal-tex-b-parbox "l" "\\textwidth")
-      (dotimes (jdummy 3)
+      (dotimes (_jdummy 3)
         (cal-tex-week-hours date holidays "5")
         (setq date (cal-tex-incr-date date)))
       (cal-tex-e-parbox)
         (cal-tex-week-hours date holidays "5")
         (setq date (cal-tex-incr-date date)))
       (cal-tex-e-parbox)
@@ -802,7 +778,7 @@ Optional EVENT indicates a buffer position to use instead of point."
       (insert "}")
       (cal-tex-nl)
       (cal-tex-b-parbox "l" "\\textwidth")
       (insert "}")
       (cal-tex-nl)
       (cal-tex-b-parbox "l" "\\textwidth")
-      (dotimes (jdummy 4)
+      (dotimes (_jdummy 4)
         (cal-tex-week-hours date holidays "5")
         (setq date (cal-tex-incr-date date)))
       (cal-tex-e-parbox)
         (cal-tex-week-hours date holidays "5")
         (setq date (cal-tex-incr-date date)))
       (cal-tex-e-parbox)
@@ -838,7 +814,7 @@ position to use instead of point."
          (d1 (calendar-absolute-from-gregorian date))
          (d2 (+ (* 7 n) d1))
          (holidays (if cal-tex-holidays
          (d1 (calendar-absolute-from-gregorian date))
          (d2 (+ (* 7 n) d1))
          (holidays (if cal-tex-holidays
-                       (cal-tex-list-holidays d1 d2)))
+                       (holiday-in-range d1 d2)))
          (diary-list (if cal-tex-diary
                          (cal-tex-list-diary-entries
                           ;; FIXME d1?
          (diary-list (if cal-tex-diary
                          (cal-tex-list-diary-entries
                           ;; FIXME d1?
@@ -864,7 +840,7 @@ position to use instead of point."
       (cal-tex-nl ".5cm")
       (cal-tex-e-center)
       (cal-tex-b-parbox "l" "\\textwidth")
       (cal-tex-nl ".5cm")
       (cal-tex-e-center)
       (cal-tex-b-parbox "l" "\\textwidth")
-      (dotimes (j 7)
+      (dotimes (_j 7)
         (cal-tex-b-parbox "t" "\\textwidth")
         (cal-tex-b-parbox "t" "\\textwidth")
         (cal-tex-rule "0pt" "\\textwidth" ".2mm")
         (cal-tex-b-parbox "t" "\\textwidth")
         (cal-tex-b-parbox "t" "\\textwidth")
         (cal-tex-rule "0pt" "\\textwidth" ".2mm")
@@ -1054,7 +1030,7 @@ Optional EVENT indicates a buffer position to use instead of point."
          (d1 (calendar-absolute-from-gregorian date))
          (d2 (+ (* 7 n) d1))
          (holidays (if cal-tex-holidays
          (d1 (calendar-absolute-from-gregorian date))
          (d2 (+ (* 7 n) d1))
          (holidays (if cal-tex-holidays
-                       (cal-tex-list-holidays d1 d2)))
+                       (holiday-in-range d1 d2)))
          (diary-list (if cal-tex-diary
                          (cal-tex-list-diary-entries
                           ;; FIXME d1?
          (diary-list (if cal-tex-diary
                          (cal-tex-list-diary-entries
                           ;; FIXME d1?
@@ -1113,7 +1089,7 @@ Optional EVENT indicates a buffer position to use instead of point."
                       (cal-tex-month-name (calendar-extract-month d))
                       (calendar-extract-year d))))))
       (insert "%\n")
                       (cal-tex-month-name (calendar-extract-month d))
                       (calendar-extract-year d))))))
       (insert "%\n")
-      (dotimes (jdummy 7)
+      (dotimes (_jdummy 7)
         (if (zerop (mod i 2))
             (insert "\\rightday")
           (insert "\\leftday"))
         (if (zerop (mod i 2))
             (insert "\\rightday")
           (insert "\\leftday"))
@@ -1151,7 +1127,7 @@ Optional EVENT indicates a buffer position to use instead of point."
          (d1 (calendar-absolute-from-gregorian date))
          (d2 (+ (* 7 n) d1))
          (holidays (if cal-tex-holidays
          (d1 (calendar-absolute-from-gregorian date))
          (d2 (+ (* 7 n) d1))
          (holidays (if cal-tex-holidays
-                       (cal-tex-list-holidays d1 d2)))
+                       (holiday-in-range d1 d2)))
          (diary-list (if cal-tex-diary
                          (cal-tex-list-diary-entries
                           ;; FIXME d1?
          (diary-list (if cal-tex-diary
                          (cal-tex-list-diary-entries
                           ;; FIXME d1?
@@ -1217,7 +1193,7 @@ Optional EVENT indicates a buffer position to use instead of point."
                      (cal-tex-month-name (calendar-extract-month d))
                      (calendar-extract-year d))))))
       (insert "%\n")
                      (cal-tex-month-name (calendar-extract-month d))
                      (calendar-extract-year d))))))
       (insert "%\n")
-      (dotimes (jdummy 3)
+      (dotimes (_jdummy 3)
         (insert "\\leftday")
         (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
         (cal-tex-arg (number-to-string (calendar-extract-day date)))
         (insert "\\leftday")
         (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
         (cal-tex-arg (number-to-string (calendar-extract-day date)))
@@ -1248,7 +1224,7 @@ Optional EVENT indicates a buffer position to use instead of point."
                      (cal-tex-month-name (calendar-extract-month d))
                      (calendar-extract-year d))))))
       (insert "%\n")
                      (cal-tex-month-name (calendar-extract-month d))
                      (calendar-extract-year d))))))
       (insert "%\n")
-      (dotimes (jdummy 2)
+      (dotimes (_jdummy 2)
         (insert "\\rightday")
         (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
         (cal-tex-arg (number-to-string (calendar-extract-day date)))
         (insert "\\rightday")
         (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
         (cal-tex-arg (number-to-string (calendar-extract-day date)))
@@ -1257,7 +1233,7 @@ Optional EVENT indicates a buffer position to use instead of point."
         (cal-tex-arg (eval cal-tex-daily-string))
         (insert "%\n")
         (setq date (cal-tex-incr-date date)))
         (cal-tex-arg (eval cal-tex-daily-string))
         (insert "%\n")
         (setq date (cal-tex-incr-date date)))
-      (dotimes (jdummy 2)
+      (dotimes (_jdummy 2)
         (insert "\\weekend")
         (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
         (cal-tex-arg (number-to-string (calendar-extract-day date)))
         (insert "\\weekend")
         (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
         (cal-tex-arg (number-to-string (calendar-extract-day date)))
@@ -1294,7 +1270,7 @@ Optional EVENT indicates a buffer position to use instead of point."
          (d1 (calendar-absolute-from-gregorian date))
          (d2 (+ (* 7 n) d1))
          (holidays (if cal-tex-holidays
          (d1 (calendar-absolute-from-gregorian date))
          (d2 (+ (* 7 n) d1))
          (holidays (if cal-tex-holidays
-                       (cal-tex-list-holidays d1 d2)))
+                       (holiday-in-range d1 d2)))
          (diary-list (if cal-tex-diary
                          (cal-tex-list-diary-entries
                           ;; FIXME d1?
          (diary-list (if cal-tex-diary
                          (cal-tex-list-diary-entries
                           ;; FIXME d1?
@@ -1363,7 +1339,7 @@ Optional EVENT indicates a buffer position to use instead of point."
         (cal-tex-newpage)
         (setq date (cal-tex-incr-date date)))
       (insert "%\n")
         (cal-tex-newpage)
         (setq date (cal-tex-incr-date date)))
       (insert "%\n")
-      (dotimes (jdummy 2)
+      (dotimes (_jdummy 2)
         (insert "\\lefthead")
         (cal-tex-arg (calendar-date-string date))
         (insert "\\weekend")
         (insert "\\lefthead")
         (cal-tex-arg (calendar-date-string date))
         (insert "\\weekend")
@@ -1524,7 +1500,7 @@ Optional string COLSEP gives the column separation (default \"1mm\")."
                     (if (= i 6)
                         "\\\\[0.7mm]\n"
                       " & "))))
                     (if (= i 6)
                         "\\\\[0.7mm]\n"
                       " & "))))
-    (dotimes (idummy blank-days)
+    (dotimes (_idummy blank-days)
       (setq str (concat str " & ")))
     (dotimes (i last)
       (setq str (concat str (number-to-string (1+ i)))
       (setq str (concat str " & ")))
     (dotimes (i last)
       (setq str (concat str (number-to-string (1+ i)))
@@ -1588,6 +1564,15 @@ FINAL-SEPARATOR is non-nil."
 Insert the trailer to LaTeX document, pop to LaTeX buffer, add
 informative header, and run HOOK."
   (cal-tex-e-document)
 Insert the trailer to LaTeX document, pop to LaTeX buffer, add
 informative header, and run HOOK."
   (cal-tex-e-document)
+  (or (and cal-tex-preamble-extra
+           (string-match "inputenc" cal-tex-preamble-extra))
+      (when (re-search-backward "[^[:ascii:]]" nil 'move)
+        (goto-char (point-min))
+        (when (search-forward "documentclass" nil t)
+          (forward-line 1)
+          ;; Eg for some Bahai holidays.
+          ;; FIXME latin1 might not always be right.
+          (insert "\\usepackage[latin1]{inputenc}\n"))))
   (latex-mode)
   (pop-to-buffer cal-tex-buffer)
   (goto-char (point-min))
   (latex-mode)
   (pop-to-buffer cal-tex-buffer)
   (goto-char (point-min))
@@ -1832,5 +1817,4 @@ Add trailing COMMENT if present."
 
 (provide 'cal-tex)
 
 
 (provide 'cal-tex)
 
-;; arch-tag: ca8168a4-5a00-4508-a565-17e3bccce6d0
 ;;; cal-tex.el ends here
 ;;; cal-tex.el ends here