]> code.delx.au - gnu-emacs/blobdiff - lisp/calendar/cal-tex.el
Add "Package:" file headers to denote built-in packages.
[gnu-emacs] / lisp / calendar / cal-tex.el
index ceba455c134de404eb4a82b216cf1d4d22420dcb..e6ba1ad343977d765dd1993116e9f14cf7f23d58 100644 (file)
@@ -1,13 +1,14 @@
 ;;; cal-tex.el --- calendar functions for printing calendars with LaTeX
 
-;; Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
-;;   Free Software Foundation, Inc.
+;; Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+;;   2009, 2010  Free Software Foundation, Inc.
 
 ;; Author: Steve Fisk <fisk@bowdoin.edu>
 ;;         Edward M. Reingold <reingold@cs.uiuc.edu>
 ;; Maintainer: Glenn Morris <rgm@gnu.org>
 ;; Keywords: calendar
 ;; Human-Keywords: Calendar, LaTeX
+;; Package: calendar
 
 ;; This file is part of GNU Emacs.
 
@@ -134,7 +135,7 @@ At present, this only affects `cal-tex-cursor-day'."
 
 (defcustom cal-tex-daily-end 20
   "The last hour of the daily LaTeX calendar page.
-At present, this only affects `cal-tex-cursor-day'"
+At present, this only affects `cal-tex-cursor-day'."
   :type 'integer
   :group 'calendar-tex)
 
@@ -142,7 +143,9 @@ At present, this only affects `cal-tex-cursor-day'"
   "A string giving extra LaTeX commands to insert in the calendar preamble.
 For example, to include extra packages:
 \"\\\\usepackage{foo}\\n\\\\usepackage{bar}\\n\"."
-  :type '(choice (const nil) string)
+  :type '(choice (const nil)
+                 ;; An example to help people format things in custom.
+                 (string :value "\\usepackage{foo}\n\\usepackage{bar}\n"))
   :group 'calendar-tex
   :version "22.1")
 
@@ -309,20 +312,24 @@ Optional string ARGS are included as options for the article document class."
 ;;;
 
 ;;;###cal-autoload
-(defun cal-tex-cursor-year (&optional arg)
+(defun cal-tex-cursor-year (&optional n event)
   "Make a buffer with LaTeX commands for the year cursor is on.
-Optional prefix argument ARG specifies number of years."
-  (interactive "p")
-  (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t))
-                (or arg 1)))
+Optional prefix argument N specifies number of years.
+Optional EVENT indicates a buffer position to use instead of point."
+  (interactive (list (prefix-numeric-value current-prefix-arg)
+                     last-nonmenu-event))
+  (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t event))
+                (or n 1)))
 
 ;;;###cal-autoload
-(defun cal-tex-cursor-year-landscape (&optional arg)
+(defun cal-tex-cursor-year-landscape (&optional n event)
   "Make a buffer with LaTeX commands for the year cursor is on.
-Optional prefix argument ARG specifies number of years."
-  (interactive "p")
-  (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t))
-                (or arg 1) t))
+Optional prefix argument N specifies number of years.
+Optional EVENT indicates a buffer position to use instead of point."
+  (interactive (list (prefix-numeric-value current-prefix-arg)
+                     last-nonmenu-event))
+  (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t event))
+                (or n 1) t))
 
 (defun cal-tex-year (year n &optional landscape)
   "Make a one page yearly calendar of YEAR; do this for N years.
@@ -361,12 +368,14 @@ landscape mode with three rows of four months each."
   (run-hooks 'cal-tex-hook))
 
 ;;;###cal-autoload
-(defun cal-tex-cursor-filofax-year (&optional arg)
+(defun cal-tex-cursor-filofax-year (&optional n event)
   "Make a Filofax one page yearly calendar of year indicated by cursor.
-Optional prefix argument ARG specifies number of years."
-  (interactive "p")
-  (let ((n (or arg 1))
-        (year (calendar-extract-year (calendar-cursor-to-date t))))
+Optional prefix argument N specifies number of years.
+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 ((year (calendar-extract-year (calendar-cursor-to-date t event))))
     (cal-tex-preamble "twoside")
     (cal-tex-cmd "\\textwidth 3.25in")
     (cal-tex-cmd "\\textheight 6.5in")
@@ -414,28 +423,30 @@ Optional prefix argument ARG specifies number of years."
 ;;;
 
 ;;;###cal-autoload
-(defun cal-tex-cursor-month-landscape (&optional arg)
+(defun cal-tex-cursor-month-landscape (&optional n event)
   "Make a LaTeX calendar buffer for the month the cursor is on.
-Optional prefix argument ARG specifies number of months to be
+Optional prefix argument N specifies number of months to be
 produced (default 1).  The output is in landscape format, one
 month to a page.  It shows holiday and diary entries if
-`cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil."
-  (interactive "p")
-  (let* ((n (or arg 1))
-         (date (calendar-cursor-to-date t))
+`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-cursor-to-date t event))
          (month (calendar-extract-month date))
          (year (calendar-extract-year date))
          (end-month month)
          (end-year year)
          (cal-tex-which-days '(0 1 2 3 4 5 6))
          (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)))
-         (diary-list (progn
-                       (calendar-increment-month end-month end-year (1- n))
-                       (if cal-tex-diary (cal-tex-list-diary-entries d1 d2))))
+         (d2 (progn
+               (calendar-increment-month end-month end-year (1- n))
+               (calendar-absolute-from-gregorian
+                (list end-month
+                      (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)))
          other-month other-year small-months-at-start)
     (cal-tex-insert-preamble (cal-tex-number-weeks month year 1) t "12pt")
@@ -482,29 +493,31 @@ month to a page.  It shows holiday and diary entries if
   (run-hooks 'cal-tex-hook))
 
 ;;;###cal-autoload
-(defun cal-tex-cursor-month (arg)
+(defun cal-tex-cursor-month (&optional n event)
   "Make a LaTeX calendar buffer for the month the cursor is on.
-Optional prefix argument ARG specifies number of months to be
+Optional prefix argument N specifies number of months to be
 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* ((n (or arg 1))
-         (date (calendar-cursor-to-date t))
+`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-cursor-to-date t event))
          (month (calendar-extract-month date))
          (year (calendar-extract-year date))
          (end-month month)
          (end-year year)
+         ;; FIXME -landscape sets cal-tex-which-days?
          (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)))
-         (diary-list (progn
-                       (calendar-increment-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)
+         (d2 (progn
+               (calendar-increment-month end-month end-year (1- n))
+               (calendar-absolute-from-gregorian
+                (list end-month
+                      (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))))
     (cal-tex-insert-preamble (cal-tex-number-weeks month year n) nil "12pt")
     (if (> n 1)
         (cal-tex-cmd cal-tex-cal-multi-month)
@@ -514,14 +527,12 @@ It shows holiday and diary entries if `cal-tex-holidays' and
     (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))           ; last day of month was Saturday
+      (when (= (calendar-week-end-day)
+               (calendar-day-of-week
+                (list month
+                      (calendar-last-day-of-month month year)
+                      year))) ; last day of month was last day of week
         (cal-tex-hfill)
         (cal-tex-nl))
       (calendar-increment-month month year 1))
@@ -558,13 +569,14 @@ are included.  Each day is formatted using format DAY-FORMAT."
 
 (defun cal-tex-insert-day-names ()
   "Insert the names of the days at top of a monthly calendar."
-  (dotimes (i 7)
-    (if (memq i cal-tex-which-days)
-        (insert (format cal-tex-day-name-format
-                        (cal-tex-LaTeXify-string
-                         (aref calendar-day-name-array
-                               (mod (+ calendar-week-start-day i) 7))))))
-    (cal-tex-comment)))
+  (let (j)
+    (dotimes (i 7)
+      (if (memq (setq j (mod (+ calendar-week-start-day i) 7))
+                cal-tex-which-days)
+          (insert (format cal-tex-day-name-format
+                          (cal-tex-LaTeXify-string
+                           (aref calendar-day-name-array j)))))
+      (cal-tex-comment))))
 
 (defun cal-tex-insert-month-header (n month year end-month end-year)
   "Create a title for a calendar.
@@ -591,7 +603,7 @@ blank, no days are inserted."
                  calendar-week-start-day)
               7)))
         (dotimes (i blank-days)
-          (if (memq i cal-tex-which-days)
+          (if (memq (mod (+ calendar-week-start-day i) 7) cal-tex-which-days)
               (insert (format day-format " " " ") "{}{}{}{}%\n"))))))
 
 (defun cal-tex-insert-blank-days-at-end (month year day-format)
@@ -607,42 +619,41 @@ The entry is formatted using DAY-FORMAT."
                7))
              (i blank-days))
         (while (<= (setq i (1+ i)) 6)
-          (if (memq i cal-tex-which-days)
+          (if (memq (mod (+ calendar-week-start-day i) 7) 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.
 Return t if there will there be any days of the first week printed
 in the calendar starting in MONTH YEAR."
-  (let (any-days the-saturday)        ; the day of week of 1st Saturday
-    (dotimes (i 7)
-      (if (= 6 (calendar-day-of-week (list month (1+ i) year)))
-          (setq the-saturday (1+ i))))
-    (dotimes (i the-saturday)
-      (if (memq (calendar-day-of-week (list month (1+ i) year))
-                cal-tex-which-days)
-          (setq any-days t)))
-    any-days))
+  ;; Check days 1-7 of the month, until we find the last day of the week.
+  (catch 'found
+    (let (dow)
+      (dotimes (i 7)
+        (if (memq (setq dow (calendar-day-of-week (list month (1+ i) year)))
+                  cal-tex-which-days)
+            (throw 'found t)
+          (if (= dow (calendar-week-end-day)) (throw 'found nil)))))))
 
 (defun cal-tex-last-blank-p (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))
-         (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))
+  ;; Check backwards from the last day of the month, until we find the
+  ;; start of the last week in the month.
+  (catch 'found
+    (let ((last-day (calendar-last-day-of-month month year))
+          day dow)
+      (dotimes (i 7)
+        (if (memq (setq dow (calendar-day-of-week
+                             (list month (- last-day i) year)))
+                  cal-tex-which-days)
+            (throw 'found t)
+          (if (= dow calendar-week-start-day) (throw 'found nil)))))))
 
 (defun cal-tex-number-weeks (month year n)
   "Determine the number of weeks in a range of dates.
-Compute the number of  weeks in the calendar starting with MONTH and YEAR,
+Compute the number of weeks in the calendar starting with MONTH and YEAR,
 and lasting N months, including only the days in WHICH-DAYS.  As it stands,
 this is only an upper bound."
   (let ((d (list month 1 year)))
@@ -668,19 +679,20 @@ 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)
+(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 ARG specifies the number of weeks (default 1).  The calendar
+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."
-  (interactive "p")
-  (let* ((n (or arg 1))
-         (date (calendar-gregorian-from-absolute
+  (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
                  calendar-week-start-day
                  (calendar-absolute-from-gregorian
-                  (calendar-cursor-to-date t)))))
+                  (calendar-cursor-to-date t event)))))
          (month (calendar-extract-month date))
          (year (calendar-extract-year date))
          (d1 (calendar-absolute-from-gregorian date))
@@ -721,19 +733,21 @@ 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)
+(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 ARG specifies number of weeks (default 1).  The calendar
+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"
-  (interactive "p")
-  (let* ((n (or arg 1))
-         (date (calendar-gregorian-from-absolute
+entries are not shown).  The calendar shows the hours 8-12am, 1-5pm.
+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
                  calendar-week-start-day
                  (calendar-absolute-from-gregorian
-                  (calendar-cursor-to-date t)))))
+                  (calendar-cursor-to-date t event)))))
          (month (calendar-extract-month date))
          (year (calendar-extract-year date))
          (d date)
@@ -803,19 +817,21 @@ entries are not shown).  The calendar shows the hours 8-12am, 1-5pm"
 (autoload 'calendar-iso-from-absolute "cal-iso")
 
 ;;;###cal-autoload
-(defun cal-tex-cursor-week-iso (&optional arg)
+(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 ARG specifies number of weeks (default 1).
+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."
-  (interactive "p")
-  (let* ((n (or arg 1))
-         (date (calendar-gregorian-from-absolute
+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)))))
+                  (calendar-cursor-to-date t event)))))
          (month (calendar-extract-month date))
          (year (calendar-extract-year date))
          (day (calendar-extract-day date))
@@ -935,20 +951,22 @@ 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)
+(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 ARG specifies number of weeks (default 1).
+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."
-  (interactive "p")
-  (let ((n (or arg 1))
-        (date (calendar-gregorian-from-absolute
+the hours 8-12am, 1-5pm.  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
                 0
                 (calendar-absolute-from-gregorian
-                 (calendar-cursor-to-date t))))))
+                 (calendar-cursor-to-date t event))))))
     (cal-tex-preamble "11pt")
     (cal-tex-cmd "\\textwidth   6.5in")
     (cal-tex-cmd "\\textheight 10.5in")
@@ -1016,18 +1034,20 @@ shown are hard-coded to 8-12, 13-17."
      (cal-tex-hspace "1cm")))
 
 ;;;###cal-autoload
-(defun cal-tex-cursor-filofax-2week (&optional arg)
+(defun cal-tex-cursor-filofax-2week (&optional n event)
   "Two-weeks-at-a-glance Filofax style calendar for week cursor is in.
-Optional prefix argument ARG specifies number of weeks (default 1).
+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."
-  (interactive "p")
-  (let* ((n (or arg 1))
-         (date (calendar-gregorian-from-absolute
+`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
                  calendar-week-start-day
                  (calendar-absolute-from-gregorian
-                  (calendar-cursor-to-date t)))))
+                  (calendar-cursor-to-date t event)))))
          (month (calendar-extract-month date))
          (year (calendar-extract-year date))
          (day (calendar-extract-day date))
@@ -1111,18 +1131,20 @@ The calendar shows holiday and diary entries if
     (run-hooks 'cal-tex-hook)))
 
 ;;;###cal-autoload
-(defun cal-tex-cursor-filofax-week (&optional arg)
+(defun cal-tex-cursor-filofax-week (&optional n event)
   "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
-Optional prefix argument ARG specifies number of weeks (default 1),
+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."
-  (interactive "p")
-  (let* ((n (or arg 1))
-         (date (calendar-gregorian-from-absolute
+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)))))
+                  (calendar-cursor-to-date t event)))))
          (month (calendar-extract-month date))
          (year (calendar-extract-year date))
          (day (calendar-extract-day date))
@@ -1251,19 +1273,21 @@ if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil."
     (run-hooks 'cal-tex-hook)))
 
 ;;;###cal-autoload
-(defun cal-tex-cursor-filofax-daily (&optional arg)
+(defun cal-tex-cursor-filofax-daily (&optional n event)
   "Day-per-page Filofax style calendar for week indicated by cursor.
-Optional prefix argument ARG specifies number of weeks (default 1),
+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.  Pages are ruled if `cal-tex-rules' is non-nil."
-  (interactive "p")
-  (let* ((n (or arg 1))
-         (date (calendar-gregorian-from-absolute
+are non-nil.  Pages are ruled if `cal-tex-rules' is 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)))))
+                  (calendar-cursor-to-date t event)))))
          (month (calendar-extract-month date))
          (year (calendar-extract-year date))
          (day (calendar-extract-day date))
@@ -1365,14 +1389,17 @@ are non-nil.  Pages are ruled if `cal-tex-rules' is non-nil."
 ;;;
 
 ;;;###cal-autoload
-(defun cal-tex-cursor-day (&optional arg)
+(defun cal-tex-cursor-day (&optional n event)
   "Make a buffer with LaTeX commands for the day cursor is on.
-Optional prefix argument ARG specifies number of days.  The calendar shows
+Optional prefix argument N specifies number of days.  The calendar shows
 the hours between `cal-tex-daily-start' and `cal-tex-daily-end', using
-the 24-hour clock if `cal-tex-24' is non-nil."
-  (interactive "p")
-  (let ((n (or arg 1))
-        (date (calendar-absolute-from-gregorian (calendar-cursor-to-date t))))
+the 24-hour clock if `cal-tex-24' is 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-absolute-from-gregorian
+               (calendar-cursor-to-date t event))))
     (cal-tex-preamble "12pt")
     (cal-tex-cmd "\\textwidth 6.5in")
     (cal-tex-cmd "\\textheight 10.5in")
@@ -1471,7 +1498,7 @@ Optional string COLSEP gives the column separation (default \"1mm\")."
           (- (calendar-day-of-week (list month 1 year))
              calendar-week-start-day)
           7))
-        (last (calendar-last-day-of-month month year))
+        (lastcalendar-last-day-of-month month year))
         (str (concat "\\def\\" name "{\\hbox to" width "{%\n"
                      "\\vbox to" height "{%\n"
                      "\\vfil  \\hbox to" width "{%\n"
@@ -1750,7 +1777,7 @@ Add trailing COMMENT if present."
   (cal-tex-comment "end framebox"))
 
 
-(defun cal-tex-b-makebox ( width position )
+(defun cal-tex-b-makebox (width position)
   "Insert makebox with parameters WIDTH and POSITION (clr)."
   (insert "\\makebox[" width "][" position "]{" )
   (cal-tex-comment))