]> code.delx.au - gnu-emacs/blobdiff - lisp/calendar/cal-tex.el
*** empty log message ***
[gnu-emacs] / lisp / calendar / cal-tex.el
index 4caa6839115bd3df322533bf8e117c83bcdd7f7f..75c630f981ce763c75f597182187b612c04832b9 100644 (file)
@@ -37,7 +37,7 @@
 ;;
 ;;     (*)  Make calendar styles for A4 paper.
 ;;
-;;     (*)  Make daily and monthly styles Filofax paper.
+;;     (*)  Make monthly styles Filofax paper.
 
 ;;; Code:
 
@@ -73,6 +73,11 @@ If finding the holidays is too slow, set this to nil."
   :type 'boolean
   :group 'calendar-tex)
 
+(defcustom cal-tex-rules nil
+  "*If t, pages will be ruled in some styles."
+  :type 'boolean
+  :group 'calendar-tex)
+
 (defcustom cal-tex-daily-string
   '(let* ((year (extract-calendar-year date))
           (day  (calendar-day-number date))
@@ -176,43 +181,34 @@ This definition is the heart of the calendar!")
 
 (defun cal-tex-list-holidays (d1 d2)
   "Generate a list of all holidays from absolute date D1 to D2."
-  (let* ((result nil)
-         (start (calendar-gregorian-from-absolute d1))
-         (start-month (extract-calendar-month start))
-         (start-year (extract-calendar-year start)))
-    (increment-calendar-month start-month start-year 1)
-    (let* ((end (calendar-gregorian-from-absolute d2))
-           (end-month (extract-calendar-month end))
-           (end-year (extract-calendar-year end)))
-      (if (= (extract-calendar-day end) 1)
-          (increment-calendar-month end-month end-year -1))
-      (let* ((s (calendar-absolute-from-gregorian
-                 (list start-month 1 start-year)))
-             (e (calendar-absolute-from-gregorian
-                 (list end-month 1 end-year)))
-             (d s)
-             (never t)
-             (displayed-month start-month)
-             (displayed-year start-year))
-        (while (or never (<= d e))
-          (setq result (append result (calendar-holiday-list)))
-          (setq never nil)
-          (increment-calendar-month displayed-month displayed-year 3)
-          (setq d (calendar-absolute-from-gregorian
-                   (list displayed-month 1 displayed-year))))))
-    (let ((in-range)
-          (p result))
-      (while p
-        (and (car (car p))
-             (let ((a (calendar-absolute-from-gregorian (car (car p)))))
-               (and (<= d1 a) (<= a d2)))
-             (setq in-range (append (list (car p)) in-range)))
-        (setq p (cdr p)))
-      in-range)))
+  (let* ((start (calendar-gregorian-from-absolute d1))
+         (displayed-month (extract-calendar-month start))
+         (displayed-year (extract-calendar-year start))
+         (end (calendar-gregorian-from-absolute d2))
+         (end-month (extract-calendar-month end))
+         (end-year (extract-calendar-year end))
+         (number-of-intervals
+          (1+ (/ (calendar-interval displayed-month displayed-year
+                                    end-month end-year)
+                 3)))
+         (holidays nil)
+         (in-range))
+    (increment-calendar-month displayed-month displayed-year 1)
+    (calendar-for-loop i from 1 to number-of-intervals do
+      (setq holidays (append holidays (calendar-holiday-list)))
+      (increment-calendar-month displayed-month displayed-year 3))
+    (while holidays
+      (and (car (car holidays))
+           (let ((a (calendar-absolute-from-gregorian (car (car holidays)))))
+             (and (<= d1 a) (<= a d2)))
+           (setq in-range (append (list (car holidays)) in-range)))
+      (setq holidays (cdr holidays)))
+    in-range))
 
 (defun cal-tex-list-diary-entries (d1 d2)
   "Generate a list of all diary-entries from absolute date D1 to D2."
-  (let ((diary-display-hook nil))
+  (let ((diary-list-include-blanks nil)
+        (diary-display-hook 'ignore))
     (list-diary-entries
      (calendar-gregorian-from-absolute d1)
      (1+ (- d2 d1)))))
@@ -823,7 +819,7 @@ Holidays are included if `cal-tex-holidays' is t."
           (cal-tex-nl)
           (setq month (extract-calendar-month date))
           (setq year (extract-calendar-year date)))
-       (cal-tex-e-parbox)
+       (cal-tex-e-parbox)
        (if (/= i n)
            (progn
              (run-hooks 'cal-tex-week-hook)
@@ -1198,6 +1194,115 @@ Holidays are included if `cal-tex-holidays' is t."
              (cal-tex-newpage))))
     (cal-tex-end-document)
     (run-hooks 'cal-tex-hook)))
+
+(defun cal-tex-cursor-filofax-daily (&optional arg)
+  "Day-per-page Filofax style calendar for week indicated by cursor.
+Optional prefix argument specifies number of weeks.  Weeks start on Monday. 
+Diary entries are included if `cal-tex-diary' is t.
+Holidays are included if `cal-tex-holidays' is t.
+Pages are ruled if `cal-tex-rules' is t."
+  (interactive "P")
+  (let* ((n (if arg arg 1))
+         (date (calendar-gregorian-from-absolute
+                (calendar-dayname-on-or-before
+                 1
+                 (calendar-absolute-from-gregorian
+                  (calendar-cursor-to-date t)))))
+         (month (extract-calendar-month date))
+         (year (extract-calendar-year date))
+         (day (extract-calendar-day date))
+         (holidays (if cal-tex-holidays
+                       (cal-tex-list-holidays
+                        (calendar-absolute-from-gregorian date)
+                        (+ (* 7 n)
+                           (calendar-absolute-from-gregorian date)))))
+         (diary-list (if cal-tex-diary
+                         (cal-tex-list-diary-entries
+                          (calendar-absolute-from-gregorian
+                           (list month 1 year))
+                         (+ (* 7 n)
+                            (calendar-absolute-from-gregorian date))))))
+    (cal-tex-preamble "twoside")
+    (cal-tex-cmd "\\textwidth 3.25in")
+    (cal-tex-cmd "\\textheight 6.5in")
+    (cal-tex-cmd "\\oddsidemargin 1.75in")
+    (cal-tex-cmd "\\evensidemargin 1.5in")
+    (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{%
+   \\rule{\\textwidth}{0.3pt}\\\\%
+   \\hbox to \\textwidth{%
+     \\vbox {%
+          \\vspace*{2pt}%
+          \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
+          \\hbox to \\textwidth{\\vbox {\\raggedleft \\em #2}}%
+          \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
+\\long\\def\\weekend#1#2#3{%
+   \\rule{\\textwidth}{0.3pt}\\\\%
+   \\hbox to \\textwidth{%
+     \\vbox {%
+          \\vspace*{2pt}%
+          \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
+          \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
+          \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
+\\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
+\\long\\def\\leftday#1#2#3{%
+   \\rule{\\textwidth}{0.3pt}\\\\%
+   \\hbox to \\textwidth{%
+     \\vbox {%
+          \\vspace*{2pt}%
+          \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
+          \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
+          \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
+\\newbox\\LineBox
+\\setbox\\LineBox=\\hbox to\\textwidth{%
+\\vrule height.2in width0pt\\leaders\\hrule\\hfill}
+\\def\\linesfill{\\par\\leaders\\copy\\LineBox\\vfill}
+")
+    (cal-tex-b-document)
+    (cal-tex-cmd "\\pagestyle{empty}")
+    (calendar-for-loop i from 1 to n do
+       (calendar-for-loop j from 1 to 5 do 
+         (let ((odd (/= 0 (% j 2))))
+           (insert (if odd "\\righthead" "\\lefthead"))
+           (cal-tex-arg (calendar-date-string date))
+           (insert "%\n")
+           (insert (if odd "\\rightday"  "\\leftday")))
+         (cal-tex-arg (cal-tex-latexify-list diary-list date))
+         (cal-tex-arg (cal-tex-latexify-list holidays date "\\\\" t))
+         (cal-tex-arg (eval cal-tex-daily-string))
+         (insert "%\n")
+         (if cal-tex-rules
+             (insert "\\linesfill\n")
+           (insert "\\vfill\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
+         (cal-tex-newpage)
+         (setq date (cal-tex-incr-date date)))
+       (insert "%\n")
+       (calendar-for-loop j from 1 to 2 do 
+         (insert "\\lefthead")
+          (cal-tex-arg (calendar-date-string date))
+          (insert "\\weekend")
+          (cal-tex-arg (cal-tex-latexify-list diary-list date))
+          (cal-tex-arg (cal-tex-latexify-list holidays date "\\\\" t))
+          (cal-tex-arg (eval cal-tex-daily-string))
+          (insert "%\n")
+          (if cal-tex-rules
+              (insert "\\linesfill\n")
+            (insert "\\vfill"))
+          (setq date (cal-tex-incr-date date)))
+       (if (not cal-tex-rules)
+          (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
+       (if (/= i n)
+           (progn
+             (run-hooks 'cal-tex-week-hook)
+             (cal-tex-newpage))))
+    (cal-tex-end-document)
+    (run-hooks 'cal-tex-hook)))
+
+
 ;;;
 ;;;  Daily calendars
 ;;;
@@ -1346,19 +1451,26 @@ If optional N is given, the date of N days after DATE."
   (calendar-gregorian-from-absolute
    (+ (if n n 1) (calendar-absolute-from-gregorian date))))
 
-(defun cal-tex-latexify-list (date-list date &optional separator)
+(defun cal-tex-latexify-list (date-list date &optional separator final-separator)
   "Return string with concatenated, LaTeXified entries in DATE_LIST for DATE.
-Use double backslash as a separator unless optional SEPARATOR is given."
-  (mapconcat '(lambda (x) (cal-tex-LaTeXify-string  x))
-             (let ((result)
-                   (p date-list))
-               (while p
-                 (and (car (car p))
-                      (calendar-date-equal date (car (car p)))
-                      (setq result (append result (cdr (car p)))))
-                 (setq p (cdr p)))
-               result)
-             (if separator separator "\\\\")))
+Use double backslash as a separator unless optional SEPARATOR is given.
+If resulting string is not empty, put separator at end if optional
+FINAL-SEPARATOR is t."
+  (let* ((sep (if separator separator "\\\\"))
+         (result
+          (mapconcat '(lambda (x) (cal-tex-LaTeXify-string  x))
+                     (let ((result)
+                           (p date-list))
+                       (while p
+                         (and (car (car p))
+                              (calendar-date-equal date (car (car p)))
+                              (setq result (cons (car (cdr (car p))) result)))
+                         (setq p (cdr p)))
+                       (reverse result))
+                     sep)))
+    (if (and final-separator (not (string-equal result "")))
+          (concat result sep)
+        result)))
 
 (defun cal-tex-previous-month (date)
   "Return the date of the first day in the month previous to DATE."