]> code.delx.au - gnu-emacs/blobdiff - lisp/calendar/cal-tex.el
Update for rename islamic-diary-entry-symbol to diary-islamic-entry-symbol.
[gnu-emacs] / lisp / calendar / cal-tex.el
index 45de885afcbdd9e2ca63bef100c46dcbefc8b6e7..e613bdda497cd194126055d351a8312307bef5ed 100644 (file)
@@ -4,7 +4,7 @@
 ;;   Free Software Foundation, Inc.
 
 ;; Author: Steve Fisk <fisk@bowdoin.edu>
-;;      Edward M. Reingold <reingold@cs.uiuc.edu>
+;;         Edward M. Reingold <reingold@cs.uiuc.edu>
 ;; Maintainer: Glenn Morris <rgm@gnu.org>
 ;; Keywords: calendar
 ;; Human-Keywords: Calendar, LaTeX
 
 (require 'calendar)
 
-(autoload 'diary-list-entries "diary-lib" nil t)
-(autoload 'calendar-holiday-list "holidays" nil t)
-(autoload 'calendar-iso-from-absolute "cal-iso" nil t)
-
 ;;;
 ;;; Customizable variables
 ;;;
 
+(defgroup calendar-tex nil
+  "Options for printing calendar with LaTeX."
+  :prefix "cal-tex-"
+  :group 'calendar)
+
 (defcustom cal-tex-which-days '(0 1 2 3 4 5 6)
   "The days of the week that are displayed on the portrait monthly calendar.
 Sunday is 0, Monday is 1, and so on.  The default is to print from Sunday to
@@ -149,7 +150,7 @@ For example, to include extra packages:
 
 (defcustom cal-tex-hook nil
   "List of functions called after any LaTeX calendar buffer is generated.
-You can use this to do postprocessing on the buffer.  For example, to change
+You can use this to do post-processing on the buffer.  For example, to change
 characters with diacritical marks to their LaTeX equivalents, use
     (add-hook 'cal-tex-hook
               (lambda () (iso-iso2tex (point-min) (point-max))))"
@@ -236,6 +237,8 @@ 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))
@@ -260,6 +263,8 @@ This definition is the heart of the calendar!")
            (setq in-range (append (list hol) in-range))))
     in-range))
 
+(autoload 'diary-list-entries "diary-lib")
+
 (defun cal-tex-list-diary-entries (d1 d2)
   "Generate a list of all diary-entries from absolute date D1 to D2."
   (let ((diary-list-include-blanks nil)
@@ -307,6 +312,7 @@ Optional string ARGS are included as options for the article document class."
 ;;;  Yearly calendars
 ;;;
 
+;;;###cal-autoload
 (defun cal-tex-cursor-year (&optional arg)
   "Make a buffer with LaTeX commands for the year cursor is on.
 Optional prefix argument ARG specifies number of years."
@@ -314,6 +320,7 @@ Optional prefix argument ARG specifies number of years."
   (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
                 (or arg 1)))
 
+;;;###cal-autoload
 (defun cal-tex-cursor-year-landscape (&optional arg)
   "Make a buffer with LaTeX commands for the year cursor is on.
 Optional prefix argument ARG specifies number of years."
@@ -357,6 +364,7 @@ landscape mode with three rows of four months each."
     (run-hooks 'cal-tex-year-hook))
   (run-hooks 'cal-tex-hook))
 
+;;;###cal-autoload
 (defun cal-tex-cursor-filofax-year (&optional arg)
   "Make a Filofax one page yearly calendar of year indicated by cursor.
 Optional prefix argument ARG specifies number of years."
@@ -409,6 +417,7 @@ Optional prefix argument ARG specifies number of years."
 ;;;  Monthly calendars
 ;;;
 
+;;;###cal-autoload
 (defun cal-tex-cursor-month-landscape (&optional arg)
   "Make a LaTeX calendar buffer for the month the cursor is on.
 Optional prefix argument ARG specifies number of months to be
@@ -427,56 +436,56 @@ month to a page.  It shows holiday and diary entries if
          (d2 (calendar-absolute-from-gregorian
               (list end-month
                     (calendar-last-day-of-month end-month end-year)
-                    end-year))))
-    (increment-calendar-month end-month end-year (1- n))
-    (let ((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 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)
-      (dotimes (i n)
-        (setq other-month month
-              other-year year)
-        (increment-calendar-month other-month other-year -1)
-        (insert (cal-tex-mini-calendar other-month other-year "lastmonth"
-                                       "\\cellwidth" "\\cellheight"))
-        (increment-calendar-month other-month other-year 2)
-        (insert (cal-tex-mini-calendar other-month other-year "nextmonth"
-                                       "\\cellwidth" "\\cellheight"))
-        (cal-tex-insert-month-header 1 month year month year)
-        (cal-tex-insert-day-names)
-        (cal-tex-nl ".2cm")
-        (if (setq small-months-at-start
-                  (< 1 (mod (- (calendar-day-of-week (list month 1 year))
+                    end-year)))
+         (diary-list (progn
+                       (increment-calendar-month end-month end-year (1- n))
+                       (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 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)
+    (dotimes (i n)
+      (setq other-month month
+            other-year year)
+      (increment-calendar-month other-month other-year -1)
+      (insert (cal-tex-mini-calendar other-month other-year "lastmonth"
+                                     "\\cellwidth" "\\cellheight"))
+      (increment-calendar-month other-month other-year 2)
+      (insert (cal-tex-mini-calendar other-month other-year "nextmonth"
+                                     "\\cellwidth" "\\cellheight"))
+      (cal-tex-insert-month-header 1 month year month year)
+      (cal-tex-insert-day-names)
+      (cal-tex-nl ".2cm")
+      (if (setq small-months-at-start
+                (< 1 (mod (- (calendar-day-of-week (list month 1 year))
                                calendar-week-start-day)
-                            7)))
-            (insert "\\lastmonth\\nextmonth\\hspace*{-2\\cellwidth}"))
-        (cal-tex-insert-blank-days month year cal-tex-day-prefix)
-        (cal-tex-insert-days month year diary-list holidays
-                             cal-tex-day-prefix)
-        (cal-tex-insert-blank-days-at-end month year cal-tex-day-prefix)
-        (if (and (not small-months-at-start)
-                 (< 1 (mod (- (1- calendar-week-start-day)
-                              (calendar-day-of-week
-                               (list month
-                                     (calendar-last-day-of-month month year)
-                                     year)))
-                           7)))
-            (insert "\\vspace*{-\\cellwidth}\\hspace*{-2\\cellwidth}"
-                    "\\lastmonth\\nextmonth%
+                          7)))
+          (insert "\\lastmonth\\nextmonth\\hspace*{-2\\cellwidth}"))
+      (cal-tex-insert-blank-days month year cal-tex-day-prefix)
+      (cal-tex-insert-days month year diary-list holidays
+                           cal-tex-day-prefix)
+      (cal-tex-insert-blank-days-at-end month year cal-tex-day-prefix)
+      (if (and (not small-months-at-start)
+               (< 1 (mod (- (1- calendar-week-start-day)
+                            (calendar-day-of-week
+                             (list month
+                                   (calendar-last-day-of-month month year)
+                                   year)))
+                         7)))
+          (insert "\\vspace*{-\\cellwidth}\\hspace*{-2\\cellwidth}"
+                  "\\lastmonth\\nextmonth%
 "))
-        (unless (= i (1- n))
-          (run-hooks 'cal-tex-month-hook)
-          (cal-tex-newpage)
-          (increment-calendar-month month year 1)
-          (cal-tex-vspace "-2cm")
-          (cal-tex-insert-preamble
-           (cal-tex-number-weeks month year 1) t "12pt" t)))
-      (cal-tex-end-document)
-      (run-hooks 'cal-tex-hook))))
+      (unless (= i (1- n))
+        (run-hooks 'cal-tex-month-hook)
+        (cal-tex-newpage)
+        (increment-calendar-month month year 1)
+        (cal-tex-vspace "-2cm")
+        (cal-tex-insert-preamble
+         (cal-tex-number-weeks month year 1) t "12pt" t))))
+  (cal-tex-end-document)
+  (run-hooks 'cal-tex-hook))
 
+;;;###cal-autoload
 (defun cal-tex-cursor-month (arg)
   "Make a LaTeX calendar buffer for the month the cursor is on.
 Optional prefix argument ARG specifies number of months to be
@@ -484,46 +493,44 @@ produced (default 1).  The calendar is condensed onto one page.
 It shows holiday and diary entries if `cal-tex-holidays' and
 `cal-tex-diary', respectively, are non-nil."
   (interactive "p")
-  (let* ((date (calendar-cursor-to-date t))
+  (let* ((n (or arg 1))
+         (date (calendar-cursor-to-date t))
          (month (extract-calendar-month date))
          (year (extract-calendar-year date))
          (end-month month)
          (end-year year)
-         (n (or arg 1))
          (d1 (calendar-absolute-from-gregorian (list month 1 year)))
          (d2 (calendar-absolute-from-gregorian
               (list end-month
                     (calendar-last-day-of-month end-month end-year)
-                    end-year))))
-    (increment-calendar-month end-month end-year (1- n))
-    (let ((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)
-      (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-cmd cal-tex-cal-one-month))
-      (cal-tex-insert-month-header n month year end-month end-year)
-      (cal-tex-insert-day-names)
-      (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 (= (mod (calendar-absolute-from-gregorian
+                    end-year)))
+         (diary-list (progn
+                       (increment-calendar-month end-month end-year (1- n))
+                       (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)
+    (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-cmd cal-tex-cal-one-month))
+    (cal-tex-insert-month-header n month year end-month end-year)
+    (cal-tex-insert-day-names)
+    (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)
-                 6)                   ; last day of month was Saturday
-          (cal-tex-hfill)
-          (cal-tex-nl))
-        (increment-calendar-month month year 1))
-      (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix)
-      (cal-tex-end-document)))
+                      7))           ; last day of month was Saturday
+        (cal-tex-hfill)
+        (cal-tex-nl))
+      (increment-calendar-month month year 1))
+    (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix))
+  (cal-tex-end-document)
   (run-hooks 'cal-tex-hook))
 
 (defun cal-tex-insert-days (month year diary-list holidays day-format)
@@ -601,10 +608,11 @@ The entry is formatted using DAY-FORMAT."
               (mod
                (- (calendar-day-of-week (list month last-day year))
                   calendar-week-start-day)
-               7)))
-        (calendar-for-loop i from (1+ blank-days) to 6 do
-           (if (memq i cal-tex-which-days)
-               (insert (format day-format "" "") "{}{}{}{}%\n"))))))
+               7))
+             (i blank-days))
+        (while (<= (setq i (1+ i)) 6)
+          (if (memq i 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.
@@ -624,15 +632,16 @@ in the calendar starting in 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))
-        any-days the-sunday)          ; the day of week of last Sunday
-    (calendar-for-loop i from (- last-day 6) to last-day do
-       (if (= 0 (calendar-day-of-week (list month i year)))
-           (setq the-sunday i)))
-    (calendar-for-loop i from the-sunday to last-day do
-       (if (memq (calendar-day-of-week (list month i year))
-                 cal-tex-which-days)
-           (setq any-days t)))
+  (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))
 
 (defun cal-tex-number-weeks (month year n)
@@ -662,6 +671,7 @@ this is only an upper bound."
 
 ;; TODO cal-tex-diary-support.
 ;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
+;;;###cal-autoload
 (defun cal-tex-cursor-week (&optional arg)
   "Make a LaTeX calendar buffer for a two-page one-week calendar.
 It applies to the week that point is in.  The optional prefix
@@ -714,6 +724,7 @@ entries are not shown).  The calendar shows the hours 8-12am, 1-5pm."
 
 ;; TODO cal-tex-diary support.
 ;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
+;;;###cal-autoload
 (defun cal-tex-cursor-week2 (&optional arg)
   "Make a LaTeX calendar buffer for a two-page one-week calendar.
 It applies to the week that point is in.  Optional prefix
@@ -793,6 +804,9 @@ entries are not shown).  The calendar shows the hours 8-12am, 1-5pm"
     (cal-tex-end-document)
     (run-hooks 'cal-tex-hook)))
 
+(autoload 'calendar-iso-from-absolute "cal-iso")
+
+;;;###cal-autoload
 (defun cal-tex-cursor-week-iso (&optional arg)
   "Make a LaTeX calendar buffer for a one page ISO-style weekly calendar.
 Optional prefix argument ARG specifies number of weeks (default 1).
@@ -924,6 +938,7 @@ shown are hard-coded to 8-12, 13-17."
 
 ;; TODO cal-tex-diary support.
 ;; TODO respect cal-tex-daily-start,end (see cal-tex-weekly4-box).
+;;;###cal-autoload
 (defun cal-tex-cursor-week-monday (&optional arg)
   "Make a LaTeX calendar buffer for a two-page one-week calendar.
 It applies to the week that point is in, and starts on Monday.
@@ -1004,6 +1019,7 @@ shown are hard-coded to 8-12, 13-17."
      (cal-tex-e-framebox)
      (cal-tex-hspace "1cm")))
 
+;;;###cal-autoload
 (defun cal-tex-cursor-filofax-2week (&optional arg)
   "Two-weeks-at-a-glance Filofax style calendar for week cursor is in.
 Optional prefix argument ARG specifies number of weeks (default 1).
@@ -1098,6 +1114,7 @@ The calendar shows holiday and diary entries if
     (cal-tex-end-document)
     (run-hooks 'cal-tex-hook)))
 
+;;;###cal-autoload
 (defun cal-tex-cursor-filofax-week (&optional arg)
   "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
 Optional prefix argument ARG specifies number of weeks (default 1),
@@ -1237,6 +1254,7 @@ if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil."
     (cal-tex-end-document)
     (run-hooks 'cal-tex-hook)))
 
+;;;###cal-autoload
 (defun cal-tex-cursor-filofax-daily (&optional arg)
   "Day-per-page Filofax style calendar for week indicated by cursor.
 Optional prefix argument ARG specifies number of weeks (default 1),
@@ -1261,7 +1279,7 @@ are non-nil.  Pages are ruled if `cal-tex-rules' is non-nil."
                          (cal-tex-list-diary-entries
                           ;; FIXME d1?
                           (calendar-absolute-from-gregorian (list month 1 year))
-                         d2))))
+                          d2))))
     (cal-tex-preamble "twoside")
     (cal-tex-cmd "\\textwidth 3.25in")
     (cal-tex-cmd "\\textheight 6.5in")
@@ -1350,6 +1368,7 @@ are non-nil.  Pages are ruled if `cal-tex-rules' is non-nil."
 ;;;  Daily calendars
 ;;;
 
+;;;###cal-autoload
 (defun cal-tex-cursor-day (&optional arg)
   "Make a buffer with LaTeX commands for the day cursor is on.
 Optional prefix argument ARG specifies number of days.  The calendar shows
@@ -1379,6 +1398,7 @@ Uses the 24-hour clock if `cal-tex-24' is non-nil.  Produces
 hourly sections for the period specified by `cal-tex-daily-start'
 and `cal-tex-daily-end'."
   (let ((month-name (cal-tex-month-name (extract-calendar-month date)))
+        (i (1- cal-tex-daily-start))
         hour)
     (cal-tex-banner "cal-tex-daily-page")
     (cal-tex-b-makebox "4cm" "l")
@@ -1400,22 +1420,22 @@ and `cal-tex-daily-end'."
     (cal-tex-hspace ".4cm")
     (cal-tex-rule "0mm" "16.1cm" "1mm")
     (cal-tex-nl ".1cm")
-    (calendar-for-loop i from cal-tex-daily-start to cal-tex-daily-end do
-       (cal-tex-cmd "\\noindent")
-       (setq hour (if cal-tex-24
-                      i
-                    (mod i 12)))
-       (if (zerop hour) (setq hour 12))
-       (cal-tex-b-makebox "1cm" "c")
-       (cal-tex-arg (number-to-string hour))
-       (cal-tex-e-makebox)
-       (cal-tex-rule "0mm" "15.5cm" ".2mm")
-       (cal-tex-nl ".2cm")
-       (cal-tex-b-makebox "1cm" "c")
-       (cal-tex-arg "$\\diamond$" )
-       (cal-tex-e-makebox)
-       (cal-tex-rule "0mm" "15.5cm" ".2mm")
-       (cal-tex-nl ".2cm"))
+    (while (<= (setq i (1+ i)) cal-tex-daily-end)
+      (cal-tex-cmd "\\noindent")
+      (setq hour (if cal-tex-24
+                     i
+                   (mod i 12)))
+      (if (zerop hour) (setq hour 12))
+      (cal-tex-b-makebox "1cm" "c")
+      (cal-tex-arg (number-to-string hour))
+      (cal-tex-e-makebox)
+      (cal-tex-rule "0mm" "15.5cm" ".2mm")
+      (cal-tex-nl ".2cm")
+      (cal-tex-b-makebox "1cm" "c")
+      (cal-tex-arg "$\\diamond$" )
+      (cal-tex-e-makebox)
+      (cal-tex-rule "0mm" "15.5cm" ".2mm")
+      (cal-tex-nl ".2cm"))
     (cal-tex-hfill)
     (insert (cal-tex-mini-calendar
              (extract-calendar-month (cal-tex-previous-month date))
@@ -1559,7 +1579,7 @@ informative header, and run HOOK."
   "Initialize the output LaTeX calendar buffer, `cal-tex-buffer'.
 Select the output buffer, and insert the preamble for a calendar
 of WEEKS weeks.  Insert code for landscape mode if LANDSCAPE is
-non-nil.  Use pointsize SIZE.  Optional argument APPEND, if
+non-nil.  Use point-size SIZE.  Optional argument APPEND, if
 non-nil, means add to end of buffer without erasing current contents."
   (let ((width "18cm")
         (height "24cm"))
@@ -1614,18 +1634,19 @@ non-nil, means add to end of buffer without erasing current contents."
       ""
     (let ((head "")
           (tail string)
-          (list cal-tex-LaTeX-subst-list))
+          (list cal-tex-LaTeX-subst-list)
+          ch pair)
       (while (not (string-equal tail ""))
-        (let* ((ch (substring-no-properties tail 0 1))
-               (pair (assoc ch list)))
-          (if (and pair (string-equal ch "\""))
-              (setq list (reverse list))) ; quote changes meaning each time
-          (setq tail (substring-no-properties tail 1)
-                head (concat head (if pair (cdr pair) ch)))))
+        (setq ch (substring-no-properties tail 0 1)
+              pair (assoc ch list))
+        (if (and pair (string-equal ch "\""))
+            (setq list (reverse list))) ; quote changes meaning each time
+        (setq tail (substring-no-properties tail 1)
+              head (concat head (if pair (cdr pair) ch))))
       head)))
 
 (defun cal-tex-month-name (month)
-  "The name of MONTH, LaTeXified."
+  "The name of MONTH, LaTeX-ified."
   (cal-tex-LaTeXify-string (calendar-month-name month)))
 
 (defun cal-tex-hfill ()
@@ -1788,5 +1809,5 @@ Add trailing COMMENT if present."
 
 (provide 'cal-tex)
 
-;;; arch-tag: ca8168a4-5a00-4508-a565-17e3bccce6d0
+;; arch-tag: ca8168a4-5a00-4508-a565-17e3bccce6d0
 ;;; cal-tex.el ends here