]> code.delx.au - gnu-emacs/blobdiff - lisp/calendar/cal-tex.el
*** empty log message ***
[gnu-emacs] / lisp / calendar / cal-tex.el
index 638fb232866c6c4f4ff4bb7e558077b84b3fa8b0..75c630f981ce763c75f597182187b612c04832b9 100644 (file)
 ;;
 ;;     (*)  Make calendar styles for A4 paper.
 ;;
-;;     (*)  Make daily and monthly styles Filofax paper.
-;;
-;;     (*)  Improve the LaTeX command that produces the boxes in the monthly
-;;          calendar to eliminate slight gap--what causes it?!
+;;     (*)  Make monthly styles Filofax paper.
 
 ;;; Code:
 
 ;;; Customizable variables 
 ;;;
 
-(defvar cal-tex-which-days '(0 1 2 3 4 5 6)
+(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
 Saturday.  For example, use
 
                     (setq cal-tex-which-days '(1 3 5))
 
-to only print Monday, Wednesday, Friday.")
+to only print Monday, Wednesday, Friday."
+  :type '(repeat integer)
+  :group 'calendar-tex)
 
-(defvar cal-tex-holidays t
+(defcustom cal-tex-holidays t
   "*If t (default), then the holidays are also printed.
-If finding the holidays is too slow, set this to nil.")
+If finding the holidays is too slow, set this to nil."
+  :type 'boolean
+  :group 'calendar-tex)
+
+(defcustom cal-tex-diary nil
+  "*If t, the diary entries are printed in the calendar."
+  :type 'boolean
+  :group 'calendar-tex)
 
-(defvar cal-tex-diary nil
-  "*If t, the diary entries are printed in the calendar.")
+(defcustom cal-tex-rules nil
+  "*If t, pages will be ruled in some styles."
+  :type 'boolean
+  :group 'calendar-tex)
 
-(defvar cal-tex-daily-string
+(defcustom cal-tex-daily-string
   '(let* ((year (extract-calendar-year date))
           (day  (calendar-day-number date))
           (days-remaining (- (calendar-day-number (list 12 31 year)) day)))
@@ -87,19 +95,29 @@ As an example of what you do, setting this to
        (require 'cal-hebrew)
        (calendar-hebrew-date-string date))
 
-will put the Hebrew date at the bottom of each day.")
+will put the Hebrew date at the bottom of each day."
+  :type 'sexp
+  :group 'calendar-tex)
 
-(defvar cal-tex-buffer "calendar.tex"
-  "*The name for the tex-ed calendar.")
+(defcustom cal-tex-buffer "calendar.tex"
+  "*The name for the tex-ed calendar."
+  :type 'string
+  :group 'calendar-tex)
 
-(defvar cal-tex-24 nil
-  "*If t, use a 24 hour clock in the daily calendar.")
+(defcustom cal-tex-24 nil
+  "*If t, use a 24 hour clock in the daily calendar."
+  :type 'boolean
+  :group 'calendar-tex)
 
-(defvar cal-tex-daily-start 8
-  "*The first hour of the daily calendar page.")
+(defcustom cal-tex-daily-start 8
+  "*The first hour of the daily calendar page."
+  :type 'integer
+  :group 'calendar-tex)
 
-(defvar cal-tex-daily-end 20
-  "*The last hour of the daily calendar page.")
+(defcustom cal-tex-daily-end 20
+  "*The last hour of the daily calendar page."
+  :type 'integer
+  :group 'calendar-tex)
 
 ;;;
 ;;; Definitions for LaTeX code
@@ -163,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)))))
@@ -215,7 +224,9 @@ Optional ARGS are included."
       (insert "[" args "]"))
   (insert "{article}\n"
           "\\hbadness 20000
+\\hfuzz=1000pt
 \\vbadness 20000
+\\lineskip 0pt
 \\marginparwidth 0pt
 \\oddsidemargin  -2cm
 \\evensidemargin -2cm
@@ -299,12 +310,14 @@ Optional parameter specifies number of years."
     (cal-tex-preamble "twoside")
     (cal-tex-cmd "\\textwidth 3.25in")
     (cal-tex-cmd "\\textheight 6.5in")
-    (cal-tex-cmd "\\oddsidemargin 1.6in")
-    (cal-tex-cmd "\\evensidemargin 1.55in")
+    (cal-tex-cmd "\\oddsidemargin 1.675in")
+    (cal-tex-cmd "\\evensidemargin 1.675in")
     (cal-tex-cmd "\\topmargin 0pt")
     (cal-tex-cmd "\\headheight -0.875in")
+    (cal-tex-cmd "\\fboxsep 0.5mm")
     (cal-tex-cmd "\\pagestyle{empty}")
     (cal-tex-b-document)
+    (cal-tex-cmd "\\vspace*{0.25in}")
     (calendar-for-loop j from 1 to n do
        (insert (format "\\hfil {\\Large \\bf %s} \\hfil\\\\\n" year))
        (cal-tex-b-center)
@@ -315,7 +328,7 @@ Optional parameter specifies number of years."
        (calendar-for-loop i from 1 to 12 do
           (insert (cal-tex-mini-calendar i year
                                          (calendar-month-name i)
-                                         "1.05in" ".8in" "tiny")))
+                                         "1in" ".9in" "tiny" "0.6mm")))
        (insert
 "\\noindent\\fbox{\\January}\\fbox{\\February}\\fbox{\\March}\\\\
 \\noindent\\fbox{\\April}\\fbox{\\May}\\fbox{\\June}\\\\
@@ -325,9 +338,10 @@ Optional parameter specifies number of years."
        (cal-tex-e-parbox)
        (cal-tex-e-center)
        (setq year (1+ year))
-       (if (/= j n)
-           (cal-tex-newpage)
-         (cal-tex-end-document))
+       (if (= j n)
+           (cal-tex-end-document)
+         (cal-tex-newpage)
+         (cal-tex-cmd "\\vspace*{0.25in}"))
        (run-hooks 'cal-tex-year-hook))
     (run-hooks 'cal-tex-hook)))
 
@@ -805,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)
@@ -1180,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
 ;;;
@@ -1274,28 +1397,32 @@ Optional prefix argument specifies number of days."
 ;;;  Mini calendars
 ;;;
 
-(defun cal-tex-mini-calendar (month year name width height &optional size)
+(defun cal-tex-mini-calendar (month year name width height &optional ptsize colsep)
   "Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT.
-Optional SIZE gives the point size; scriptsize is the default,"
+Optional PTSIZE gives the point ptsize; scriptsize is the default.  Optional
+COLSEP gives the column separation; 1mm is the default."
   (let* ((blank-days;; at start of month
           (mod
            (- (calendar-day-of-week (list month 1 year))
               calendar-week-start-day)
            7))
-        (last (calendar-last-day-of-month month year))
+          (last (calendar-last-day-of-month month year))
+         (colsep (if colsep colsep "1mm"))
          (str (concat "\\def\\" name "{\\hbox to" width "{%\n"
                       "\\vbox to" height "{%\n"
                       "\\vfil  \\hbox to" width "{%\n"
                       "\\hfil\\"
-                      (if size size "scriptsize")
+                      (if ptsize ptsize "scriptsize")
                       "\\begin{tabular}"
-                      "{@{\\hspace{1mm}}r@{\\hspace{1mm}}r@{\\hspace{1mm}}r@{\\hspace{1mm}}"
-                      "r@{\\hspace{1mm}}r@{\\hspace{1mm}}r@{\\hspace{1mm}}r@{\\hspace{1mm}}}%\n"
+                      "{@{\\hspace{0mm}}r@{\\hspace{" colsep
+                      "}}r@{\\hspace{" colsep "}}r@{\\hspace{" colsep
+                      "}}r@{\\hspace{" colsep "}}r@{\\hspace{" colsep
+                      "}}r@{\\hspace{" colsep "}}r@{\\hspace{0mm}}}%\n"
                       "\\multicolumn{7}{c}{"
                       (calendar-month-name month)
                       " "
                       (int-to-string year)
-                      "}\\\\[0.5mm]\n")))
+                      "}\\\\[1mm]\n")))
     (calendar-for-loop i from 0 to 6 do
       (setq str (concat str
                         (substring (aref calendar-day-name-array 
@@ -1303,7 +1430,7 @@ Optional SIZE gives the point size; scriptsize is the default,"
                                    0 2)
                         (if (/= i 6)
                             " & "
-                          "\\\\[0.5mm]\n"))))
+                          "\\\\[0.7mm]\n"))))
     (calendar-for-loop i from 1 to blank-days do
       (setq str (concat str " & ")))
     (calendar-for-loop i from 1 to last do
@@ -1324,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 (cdr (car p)) result)))
-                 (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."