* calendar/cal-tex.el (cal-tex-cursor-week-at-a-glance): New function.
[bpt/emacs.git] / lisp / calendar / cal-tex.el
index e6ba1ad..c8c8037 100644 (file)
@@ -1,7 +1,6 @@
 ;;; 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>
@@ -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!")
 
-(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.3")
 
 (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)))
-         (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)
@@ -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)))
-         (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)
@@ -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)
-    (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
@@ -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))
-          day dow)
+          dow)
       (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
-                       (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")
@@ -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")
-      (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)
@@ -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))
-         (d date)
          (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")
@@ -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")
-      (dotimes (jdummy 3)
+      (dotimes (_jdummy 3)
         (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")
-      (dotimes (jdummy 4)
+      (dotimes (_jdummy 4)
         (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
-                       (cal-tex-list-holidays d1 d2)))
+                       (holiday-in-range d1 d2)))
          (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")
-      (dotimes (j 7)
+      (dotimes (_j 7)
         (cal-tex-b-parbox "t" "\\textwidth")
         (cal-tex-b-parbox "t" "\\textwidth")
         (cal-tex-rule "0pt" "\\textwidth" ".2mm")
@@ -1033,6 +1009,168 @@ shown are hard-coded to 8-12, 13-17."
      (cal-tex-e-framebox)
      (cal-tex-hspace "1cm")))
 
+(defun cal-tex-cursor-week-at-a-glance (&optional n event)
+  "One-week-at-a-glance full page calendar for week indicated by cursor.
+Optional prefix argument N specifies number of weeks (default 1),
+starting on Mondays.  The calendar shows holiday and diary entries
+if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
+It does not show hours of the day. Optional EVENT indicates a buffer
+position to use instead of point."
+  (interactive (list (prefix-numeric-value current-prefix-arg)
+                     last-nonmenu-event))
+  (or n (setq n 1))
+  (let* ((date (calendar-gregorian-from-absolute
+                (calendar-dayname-on-or-before
+                 1
+                 (calendar-absolute-from-gregorian
+                  (calendar-cursor-to-date t event)))))
+         (month (calendar-extract-month date))
+         (year (calendar-extract-year date))
+         (day (calendar-extract-day date))
+         (d1 (calendar-absolute-from-gregorian date))
+         (d2 (+ (* 7 n) d1))
+         (holidays (if cal-tex-holidays
+                       (holiday-in-range d1 d2)))
+         (diary-list (if cal-tex-diary
+                         (cal-tex-list-diary-entries d1 d2))))
+    (cal-tex-preamble "twoside,12pt")
+    (cal-tex-cmd "\\usepackage{color}")
+    (cal-tex-cmd "\\textwidth   7in")
+    (cal-tex-cmd "\\textheight 10.5in")
+    (cal-tex-cmd "\\oddsidemargin 0in")
+    (cal-tex-cmd "\\evensidemargin 0in")
+    (cal-tex-cmd "\\topmargin 0pt")
+    (cal-tex-cmd "\\headheight -0.875in")
+    (cal-tex-cmd "\\headsep 0.125in")
+    (cal-tex-cmd "\\footskip .125in")
+    (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
+\\long\\def\\rightday#1#2#3#4#5{%
+   \\rule{\\textwidth}{0.3pt}\\\\%
+   \\hbox to \\textwidth{%
+     \\vbox to 2.75in{%
+          \\vspace*{2pt}%
+          \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
+          \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em \\textcolor{red}{#4}}}%
+          \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize \\textcolor{blue}{#3}}}}}\\\\}
+\\long\\def\\weekend#1#2#3#4#5{%
+   \\rule{\\textwidth}{0.3pt}\\\\%
+   \\hbox to \\textwidth{%
+     \\vbox to 1.8in{%
+          \\vspace*{2pt}%
+          \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
+          \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em \\textcolor{red}{#4}}}%
+          \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize \\textcolor{blue}{#3}}}}}\\\\}
+\\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
+\\long\\def\\leftday#1#2#3#4#5{%
+   \\rule{\\textwidth}{0.3pt}\\\\%
+   \\hbox to \\textwidth{%
+     \\vbox to 2.75in{%
+          \\vspace*{2pt}%
+          \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
+          \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em \\textcolor{red}{#4}}}%
+          \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize \\textcolor{blue}{#3}}}}}\\\\}
+")
+    (cal-tex-b-document)
+    (cal-tex-cmd "\\pagestyle{empty}\\ ")
+    (cal-tex-newpage)
+    (dotimes (i n)
+      (insert "\\lefthead")
+      (cal-tex-arg
+       (let ((d (cal-tex-incr-date date 2)))
+         (if (= (calendar-extract-month date)
+                (calendar-extract-month d))
+             (format "%s %s"
+                     (cal-tex-month-name (calendar-extract-month date))
+                     (calendar-extract-year date))
+           (if (= (calendar-extract-year date)
+                  (calendar-extract-year d))
+               (format "%s---%s %s"
+                       (cal-tex-month-name (calendar-extract-month date))
+                       (cal-tex-month-name (calendar-extract-month d))
+                       (calendar-extract-year date))
+             (format "%s %s---%s %s"
+                     (cal-tex-month-name (calendar-extract-month date))
+                     (calendar-extract-year date)
+                     (cal-tex-month-name (calendar-extract-month d))
+                     (calendar-extract-year d))))))
+      (insert "%\n")
+      (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)))
+        (cal-tex-arg (cal-tex-latexify-list diary-list date))
+        (cal-tex-arg (cal-tex-latexify-list holidays date))
+        (cal-tex-arg (eval cal-tex-daily-string))
+        (insert "%\n")
+        (setq date (cal-tex-incr-date date)))
+      (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
+      (cal-tex-nl)
+      (insert (cal-tex-mini-calendar
+               (calendar-extract-month (cal-tex-previous-month date))
+               (calendar-extract-year (cal-tex-previous-month date))
+               "lastmonth" "1.1in" "1in"))
+      (insert (cal-tex-mini-calendar
+               (calendar-extract-month date)
+               (calendar-extract-year date)
+               "thismonth" "1.1in" "1in"))
+      (insert (cal-tex-mini-calendar
+               (calendar-extract-month (cal-tex-next-month date))
+               (calendar-extract-year (cal-tex-next-month date))
+               "nextmonth" "1.1in" "1in"))
+      (insert "\\hbox to \\textwidth{")
+      (cal-tex-hfill)
+      (insert "\\lastmonth")
+      (cal-tex-hfill)
+      (insert "\\thismonth")
+      (cal-tex-hfill)
+      (insert "\\nextmonth")
+      (cal-tex-hfill)
+      (insert "}")
+      (cal-tex-newpage)
+      (insert "\\righthead")
+      (cal-tex-arg
+       (let ((d (cal-tex-incr-date date 3)))
+         (if (= (calendar-extract-month date)
+                 (calendar-extract-month d))
+             (format "%s %s"
+                     (cal-tex-month-name (calendar-extract-month date))
+                     (calendar-extract-year date))
+           (if (= (calendar-extract-year date)
+                  (calendar-extract-year d))
+               (format "%s---%s %s"
+                       (cal-tex-month-name (calendar-extract-month date))
+                       (cal-tex-month-name (calendar-extract-month d))
+                       (calendar-extract-year date))
+             (format "%s %s---%s %s"
+                     (cal-tex-month-name (calendar-extract-month date))
+                     (calendar-extract-year date)
+                     (cal-tex-month-name (calendar-extract-month d))
+                     (calendar-extract-year d))))))
+      (insert "%\n")
+      (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)))
+        (cal-tex-arg (cal-tex-latexify-list diary-list date))
+        (cal-tex-arg (cal-tex-latexify-list holidays date))
+        (cal-tex-arg (eval cal-tex-daily-string))
+        (insert "%\n")
+        (setq date (cal-tex-incr-date date)))
+      (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)))
+        (cal-tex-arg (cal-tex-latexify-list diary-list date))
+        (cal-tex-arg (cal-tex-latexify-list holidays date))
+        (cal-tex-arg (eval cal-tex-daily-string))
+        (insert "%\n")
+        (setq date (cal-tex-incr-date date)))
+      (unless (= i (1- n))
+        (run-hooks 'cal-tex-week-hook)
+        (cal-tex-newpage)))
+    (cal-tex-end-document)
+    (run-hooks 'cal-tex-hook)))
+
 ;;;###cal-autoload
 (defun cal-tex-cursor-filofax-2week (&optional n event)
   "Two-weeks-at-a-glance Filofax style calendar for week cursor is in.
@@ -1054,7 +1192,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
-                       (cal-tex-list-holidays d1 d2)))
+                       (holiday-in-range d1 d2)))
          (diary-list (if cal-tex-diary
                          (cal-tex-list-diary-entries
                           ;; FIXME d1?
@@ -1113,7 +1251,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")
-      (dotimes (jdummy 7)
+      (dotimes (_jdummy 7)
         (if (zerop (mod i 2))
             (insert "\\rightday")
           (insert "\\leftday"))
@@ -1151,7 +1289,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
-                       (cal-tex-list-holidays d1 d2)))
+                       (holiday-in-range d1 d2)))
          (diary-list (if cal-tex-diary
                          (cal-tex-list-diary-entries
                           ;; FIXME d1?
@@ -1217,7 +1355,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")
-      (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)))
@@ -1248,7 +1386,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")
-      (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)))
@@ -1257,7 +1395,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)))
-      (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)))
@@ -1294,7 +1432,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
-                       (cal-tex-list-holidays d1 d2)))
+                       (holiday-in-range d1 d2)))
          (diary-list (if cal-tex-diary
                          (cal-tex-list-diary-entries
                           ;; FIXME d1?
@@ -1363,7 +1501,7 @@ Optional EVENT indicates a buffer position to use instead of point."
         (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")
@@ -1524,7 +1662,7 @@ Optional string COLSEP gives the column separation (default \"1mm\")."
                     (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)))
@@ -1588,6 +1726,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)
+  (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))
@@ -1832,5 +1979,4 @@ Add trailing COMMENT if present."
 
 (provide 'cal-tex)
 
-;; arch-tag: ca8168a4-5a00-4508-a565-17e3bccce6d0
 ;;; cal-tex.el ends here