]> code.delx.au - gnu-emacs/blobdiff - lisp/calendar/cal-tex.el
Fix todo-mode category movement
[gnu-emacs] / lisp / calendar / cal-tex.el
index 326deef69ba383a793fd8e48cf26376310b971e4..4f2eb9890105b83a142c62db5307d65cbc446569 100644 (file)
@@ -1,6 +1,6 @@
 ;;; cal-tex.el --- calendar functions for printing calendars with LaTeX
 
-;; Copyright (C) 1995, 2001-2012 Free Software Foundation, Inc.
+;; Copyright (C) 1995, 2001-2016 Free Software Foundation, Inc.
 
 ;; Author: Steve Fisk <fisk@bowdoin.edu>
 ;;         Edward M. Reingold <reingold@cs.uiuc.edu>
@@ -37,6 +37,7 @@
 ;; cal-tex-cursor-month
 ;; cal-tex-cursor-week
 ;; cal-tex-cursor-week2
+;; cal-tex-cursor-week2-summary
 ;; cal-tex-cursor-week-iso
 ;; cal-tex-cursor-week-monday
 ;; cal-tex-cursor-filofax-2week
@@ -82,8 +83,6 @@ Setting this to nil may speed up calendar generation."
 
 (defcustom cal-tex-diary nil
   "Non-nil means diary entries are printed in LaTeX calendars that support it.
-At present, this only affects the monthly, filofax, and iso-week
-calendars (i.e. not the yearly, plain weekly, or daily calendars).
 Setting this to nil may speed up calendar generation."
   :type 'boolean
   :group 'calendar-tex)
@@ -101,7 +100,7 @@ At present, this only affects the daily filofax calendar."
      (format "%d/%d" day days-remaining))
   "Lisp expression giving the date format to use in the LaTeX calendars.
 This should be an expression involving the variable `date'.  When
-this expression is called, `date' is a list of the form '(MONTH DAY YEAR)'.
+this expression is called, `date' is a list of the form `(MONTH DAY YEAR)'.
 
 The string resulting from evaluating this expression is placed at
 the bottom center of each date in monthly calendars, next to the
@@ -152,7 +151,7 @@ For example, to include extra packages:
   "List of functions called after any LaTeX calendar buffer is generated.
 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
+    (add-hook \\='cal-tex-hook
               (lambda () (iso-iso2tex (point-min) (point-max))))"
   :type 'hook
   :group 'calendar-tex)
@@ -237,6 +236,14 @@ 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!")
 
+(defconst cal-tex-lefthead
+  "\\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}\n"
+  "LaTeX code for left header.")
+
+(defconst cal-tex-righthead
+  "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}\n"
+  "LaTeX code for right header.")
+
 (autoload 'holiday-in-range "holidays")
 
 (define-obsolete-function-alias 'cal-tex-list-holidays 'holiday-in-range "24.3")
@@ -253,14 +260,14 @@ This definition is the heart of the calendar!")
   "Insert the LaTeX calendar preamble into `cal-tex-buffer'.
 Preamble includes initial definitions for various LaTeX commands.
 Optional string ARGS are included as options for the article document class."
-  ;; FIXME use generate-new-buffer, and adjust cal-tex-end-document.
-  (set-buffer (get-buffer-create cal-tex-buffer))
+  (set-buffer (generate-new-buffer cal-tex-buffer))
   (insert (format "\\documentclass%s{article}\n"
                   (if (stringp args)
                       (format "[%s]" args)
                     "")))
   (if (stringp cal-tex-preamble-extra)
       (insert cal-tex-preamble-extra "\n"))
+  ;; FIXME boxwidth and boxheight unused?
   (insert "\\hbadness 20000
 \\hfuzz=1000pt
 \\vbadness 20000
@@ -363,6 +370,35 @@ landscape mode with three rows of four months each."
 \\footskip 0.125in
 ")))
 
+(defun cal-tex-longday (funcname height)
+  "Insert LaTeX code for a long day function."
+  (insert "\\long\\def\\" funcname "#1#2#3#4#5{%
+   \\rule{\\textwidth}{0.3pt}\\\\%
+   \\hbox to \\textwidth{%
+     \\vbox to " height "{%
+       \\vspace*{2pt}%
+       \\hbox to \\textwidth{"
+     (if (string-equal funcname "leftday")
+         "\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%\n"
+       "\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%\n")
+     "       \\hbox to \\textwidth{\\vbox {\\"
+     (if (string-equal funcname "leftday") "noindent" "raggedleft")
+     " \\footnotesize \\em #4}}%
+       \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}\n"))
+
+(defun cal-tex-shortday (funcname)
+  "Insert LaTeX code for a short day function."
+  (insert "\\long\\def\\" funcname "#1#2#3{%
+   \\rule{\\textwidth}{0.3pt}\\\\%
+   \\hbox to \\textwidth{%
+     \\vbox {%
+          \\vspace*{2pt}%
+          \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
+          \\hbox to \\textwidth{\\vbox {\\"
+          (if (string-equal funcname "rightday") "raggedleft" "noindent")
+          " \\em #2}}%
+          \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}\n"))
+
 ;;;###cal-autoload
 (defun cal-tex-cursor-filofax-year (&optional n event)
   "Make a Filofax one page yearly calendar of year indicated by cursor.
@@ -680,11 +716,15 @@ this is only an upper bound."
 ;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
 ;;;###cal-autoload
 (defun cal-tex-cursor-week (&optional n event)
-  "Make a LaTeX calendar buffer for a two-page one-week calendar.
-It applies to the week that point is in.  The optional prefix
-argument N specifies number of weeks (default 1).  The calendar
-shows holidays if `cal-tex-holidays' is non-nil (note that diary
-entries are not shown).  The calendar shows the hours 8-12am, 1-5pm."
+  "Make a one page LaTeX calendar for one week, showing hours of the day.
+There are two columns; with 8-12am in the first and 1-5pm in the second.
+It shows holidays if `cal-tex-holidays' is non-nil.
+It does not show diary entries.
+
+The optional prefix argument N specifies a number of weeks (default 1).
+
+By default, the calendar is for the week at point; the optional
+argument EVENT specifies a different buffer position."
   (interactive (list (prefix-numeric-value current-prefix-arg)
                      last-nonmenu-event))
   (or n (setq n 1))
@@ -731,12 +771,15 @@ entries are not shown).  The calendar shows the hours 8-12am, 1-5pm."
 ;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
 ;;;###cal-autoload
 (defun cal-tex-cursor-week2 (&optional n event)
-  "Make a LaTeX calendar buffer for a two-page one-week calendar.
-It applies to the week that point is in.  Optional prefix
-argument N specifies number of weeks (default 1).  The calendar
-shows holidays if `cal-tex-holidays' is non-nil (note that diary
-entries are not shown).  The calendar shows the hours 8-12am, 1-5pm.
-Optional EVENT indicates a buffer position to use instead of point."
+  "Make a two page LaTeX calendar for one week, showing hours of the day.
+There are two columns; with 8-12am in the first and 1-5pm in the second.
+It shows holidays if `cal-tex-holidays' is non-nil.
+It does not show diary entries.
+
+The optional prefix argument N specifies a number of weeks (default 1).
+
+By default, the calendar is for the week at point; the optional
+argument EVENT specifies a different buffer position."
   (interactive (list (prefix-numeric-value current-prefix-arg)
                      last-nonmenu-event))
   (or n (setq n 1))
@@ -811,12 +854,15 @@ Optional EVENT indicates a buffer position to use instead of point."
 
 ;;;###cal-autoload
 (defun cal-tex-cursor-week-iso (&optional n event)
-  "Make a LaTeX calendar buffer for a one page ISO-style weekly calendar.
-Optional prefix argument N specifies number of weeks (default 1).
-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."
+  "Make a one page LaTeX calendar for one week, in the ISO-style.
+It does not show hours of the day.
+It shows holidays if `cal-tex-holidays' is non-nil.
+It shows diary entries if `cal-tex-diary' is non-nil.
+
+The optional prefix argument N specifies a number of weeks (default 1).
+
+By default, the calendar is for the week at point; the optional
+argument EVENT specifies a different buffer position."
   (interactive (list (prefix-numeric-value current-prefix-arg)
                      last-nonmenu-event))
   (or n (setq n 1))
@@ -939,13 +985,16 @@ shown are hard-coded to 8-12, 13-17."
 ;; TODO respect cal-tex-daily-start,end (see cal-tex-weekly4-box).
 ;;;###cal-autoload
 (defun cal-tex-cursor-week-monday (&optional n event)
-  "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.
-Optional prefix argument N specifies number of weeks (default 1).
-The calendar shows holidays if `cal-tex-holidays' is
-non-nil (note that diary entries are not shown).   The calendar shows
-the hours 8-12am, 1-5pm.  Optional EVENT indicates a buffer position
-to use instead of point."
+  "Make a one page LaTeX calendar for one week, showing hours of the day.
+There are two columns; with M-W in the first and T-S in the second.
+It shows the hours 8-12am and 1-5pm.
+It shows holidays if `cal-tex-holidays' is non-nil.
+It does not show diary entries.
+
+The optional prefix argument N specifies a number of weeks (default 1).
+
+By default, the calendar is for the week at point; the optional
+argument EVENT specifies a different buffer position."
   (interactive (list (prefix-numeric-value current-prefix-arg)
                      last-nonmenu-event))
   (or n (setq n 1))
@@ -1017,16 +1066,8 @@ shown are hard-coded to 8-12, 13-17."
      (cal-tex-e-framebox)
      (cal-tex-hspace "1cm")))
 
-;;;###cal-autoload
-(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))
+(defun cal-tex-weekly-common (n event &optional filofax)
+  "Common code for weekly calendars."
   (or n (setq n 1))
   (let* ((date (calendar-gregorian-from-absolute
                 (calendar-dayname-on-or-before
@@ -1042,8 +1083,17 @@ position to use instead of point."
                        (holiday-in-range d1 d2)))
          (diary-list (if cal-tex-diary
                          (cal-tex-list-diary-entries d1 d2))))
-    (cal-tex-preamble "twoside,12pt")
-    (insert "\\textwidth 7in
+    (if filofax
+        (progn
+          (cal-tex-preamble "twoside")
+          (cal-tex-filofax-paper)
+          (insert cal-tex-righthead)
+          (cal-tex-longday "rightday" "1.85in")
+          (cal-tex-longday "weekend" "0.8in")
+          (insert cal-tex-lefthead)
+          (cal-tex-longday "leftday" "1.85in"))
+      (cal-tex-preamble "twoside,12pt")
+      (insert "\\textwidth 7in
 \\textheight 10.5in
 \\oddsidemargin 0in
 \\evensidemargin 0in
@@ -1052,35 +1102,19 @@ position to use instead of point."
 \\headsep 0.125in
 \\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 #4}}%
-          \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #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 #4}}%
-          \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #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 #4}}%
-          \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
-")
+      (insert cal-tex-righthead)
+      (cal-tex-longday "rightday" "2.75in")
+      (cal-tex-longday "weekend" "1.8in")
+      (insert cal-tex-lefthead)
+      (cal-tex-longday "leftday" "2.75in"))
     (cal-tex-b-document)
     (cal-tex-cmd "\\pagestyle" "empty")
+    ;; Let's assume this is something to do with twopage documents.
+    ;; It has the downside that we start with a blank page.
+    ;; It doesn't make obvious sense when oddside and evenside margins
+    ;; are the same (non-filofax), but consider the left and right
+    ;; versions of various functions as applicable to even and odd pages.
+    (cal-tex-newpage)
     (dotimes (i n)
       (insert "\\lefthead")
       (cal-tex-arg
@@ -1112,34 +1146,35 @@ position to use instead of point."
         (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 "}")
+      (unless filofax
+        (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))
+                (calendar-extract-month d))
              (format "%s %s"
                      (cal-tex-month-name (calendar-extract-month date))
                      (calendar-extract-year date))
@@ -1179,6 +1214,21 @@ position to use instead of point."
     (cal-tex-end-document)
     (run-hooks 'cal-tex-hook)))
 
+;;;###cal-autoload
+(defun cal-tex-cursor-week2-summary (&optional n event)
+  "Make a two page LaTeX calendar for one week, with optional diary entries.
+It does not show hours of the day.
+It shows holidays if `cal-tex-holidays' is non-nil.
+It shows diary entries if `cal-tex-diary' is non-nil.
+
+The optional prefix argument N specifies a number of weeks (default 1).
+
+By default, the calendar is for the week at point; the optional
+argument EVENT specifies a different buffer position."
+  (interactive (list (prefix-numeric-value current-prefix-arg)
+                     last-nonmenu-event))
+  (cal-tex-weekly-common n event))
+
 ;;;###cal-autoload
 (defun cal-tex-cursor-filofax-2week (&optional n event)
   "Two-weeks-at-a-glance Filofax style calendar for week cursor is in.
@@ -1205,25 +1255,10 @@ Optional EVENT indicates a buffer position to use instead of point."
                          (cal-tex-list-diary-entries d1 d2))))
     (cal-tex-preamble "twoside")
     (cal-tex-filofax-paper)
-    (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 0.7in{%
-          \\vspace*{2pt}%
-          \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
-          \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
-          \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #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 0.7in{%
-          \\vspace*{2pt}%
-          \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
-          \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
-          \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
-")
+    (insert cal-tex-righthead)
+    (cal-tex-longday "rightday" "0.7in")
+    (insert cal-tex-lefthead)
+    (cal-tex-longday "leftday" "0.7in")
     (cal-tex-b-document)
     (cal-tex-cmd "\\pagestyle" "empty")
     (dotimes (i n)
@@ -1275,127 +1310,7 @@ if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
 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")
-    (cal-tex-filofax-paper)
-    (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 1.85in{%
-          \\vspace*{2pt}%
-          \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
-          \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
-          \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
-\\long\\def\\weekend#1#2#3#4#5{%
-   \\rule{\\textwidth}{0.3pt}\\\\%
-   \\hbox to \\textwidth{%
-     \\vbox to .8in{%
-          \\vspace*{2pt}%
-          \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
-          \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
-          \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #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 1.85in{%
-          \\vspace*{2pt}%
-          \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
-          \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
-          \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
-")
-    (cal-tex-b-document)
-    (cal-tex-cmd "\\pagestyle" "empty")
-    (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-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-tex-weekly-common n event t))
 
 ;;;###cal-autoload
 (defun cal-tex-cursor-filofax-daily (&optional n event)
@@ -1424,33 +1339,12 @@ Optional EVENT indicates a buffer position to use instead of point."
                          (cal-tex-list-diary-entries d1 d2))))
     (cal-tex-preamble "twoside")
     (cal-tex-filofax-paper)
-    (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
+    (insert cal-tex-righthead)
+    (cal-tex-shortday "rightday")
+    (cal-tex-shortday "weekend")
+    (insert cal-tex-lefthead)
+    (cal-tex-shortday "leftday")
+    (insert "\\newbox\\LineBox
 \\setbox\\LineBox=\\hbox to\\textwidth{%
 \\vrule height.2in width0pt\\leaders\\hrule\\hfill}
 \\def\\linesfill{\\par\\leaders\\copy\\LineBox\\vfill}
@@ -1708,11 +1602,11 @@ informative header, and run HOOK."
         (goto-char (point-min))
         (when (search-forward "documentclass" nil t)
           (forward-line 1)
-          ;; Eg for some Bahai holidays.
+          ;; E.g., for some Bahá’í holidays.
           ;; FIXME latin1 might not always be right.
           (insert "\\usepackage[latin1]{inputenc}\n"))))
   (latex-mode)
-  (pop-to-buffer cal-tex-buffer)
+  (pop-to-buffer (current-buffer))
   (goto-char (point-min))
   ;; FIXME auctex equivalents?
   (cal-tex-comment
@@ -1928,15 +1822,15 @@ Add trailing COMMENT if present."
 
 (defun cal-tex-scriptsize (string)
   "Insert STRING in scriptsize font."
-  (insert "{\\scriptsize " string "}"))
+  (cal-tex-arg (concat "\\scriptsize " string)))
 
 (defun cal-tex-huge (string)
   "Insert STRING in huge font."
-  (insert "{\\huge " string "}"))
+  (cal-tex-arg (concat "\\huge " string)))
 
 (defun cal-tex-Huge (string)
   "Insert STRING in Huge font."
-  (insert "{\\Huge " string "}"))
+  (cal-tex-arg (concat "\\Huge " string)))
 
 (defun cal-tex-Huge-bf (string)
   "Insert STRING in Huge bf font."
@@ -1944,7 +1838,7 @@ Add trailing COMMENT if present."
 
 (defun cal-tex-large (string)
   "Insert STRING in large font."
-  (insert "{\\large " string "}"))
+  (cal-tex-arg (concat "\\large " string)))
 
 (defun cal-tex-large-bf (string)
   "Insert STRING in large bf font."