1 ;;; cal-tex.el --- calendar functions for printing calendars with LaTeX
3 ;; Copyright (C) 1995, 2001-2012 Free Software Foundation, Inc.
5 ;; Author: Steve Fisk <fisk@bowdoin.edu>
6 ;; Edward M. Reingold <reingold@cs.uiuc.edu>
7 ;; Maintainer: Glenn Morris <rgm@gnu.org>
9 ;; Human-Keywords: Calendar, LaTeX
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 ;; This collection of functions implements the creation of LaTeX calendars
30 ;; based on the user's holiday choices and diary file.
32 ;; The user commands are:
33 ;; cal-tex-cursor-year
34 ;; cal-tex-cursor-year-landscape
35 ;; cal-tex-cursor-filofax-year
36 ;; cal-tex-cursor-month-landscape
37 ;; cal-tex-cursor-month
38 ;; cal-tex-cursor-week
39 ;; cal-tex-cursor-week2
40 ;; cal-tex-cursor-week-iso
41 ;; cal-tex-cursor-week-monday
42 ;; cal-tex-cursor-filofax-2week
43 ;; cal-tex-cursor-filofax-week
44 ;; cal-tex-cursor-filofax-daily
49 ;; (*) Add holidays and diary entries to daily calendar.
51 ;; (*) Add diary entries to weekly calendar functions.
53 ;; (*) Make calendar styles for A4 paper.
55 ;; (*) Make monthly styles Filofax paper.
62 ;;; Customizable variables
65 (defgroup calendar-tex nil
66 "Options for printing calendar with LaTeX."
70 (defcustom cal-tex-which-days '(0 1 2 3 4 5 6)
71 "The days of the week that are displayed on the portrait monthly calendar.
72 Sunday is 0, Monday is 1, and so on. The default is to print from Sunday to
73 Saturday. For example, use '(1 3 5) to only print Monday, Wednesday, Friday."
74 :type '(repeat integer)
77 (defcustom cal-tex-holidays t
78 "Non-nil means holidays are printed in the LaTeX calendars that support it.
79 Setting this to nil may speed up calendar generation."
83 (defcustom cal-tex-diary nil
84 "Non-nil means diary entries are printed in LaTeX calendars that support it.
85 At present, this only affects the monthly, filofax, and iso-week
86 calendars (i.e. not the yearly, plain weekly, or daily calendars).
87 Setting this to nil may speed up calendar generation."
91 (defcustom cal-tex-rules nil
92 "Non-nil means pages will be ruled in some LaTeX calendar styles.
93 At present, this only affects the daily filofax calendar."
97 (defcustom cal-tex-daily-string
98 '(let* ((year (calendar-extract-year date))
99 (day (calendar-day-number date))
100 (days-remaining (- (calendar-day-number (list 12 31 year)) day)))
101 (format "%d/%d" day days-remaining))
102 "Lisp expression giving the date format to use in the LaTeX calendars.
103 This should be an expression involving the variable `date'. When
104 this expression is called, `date' is a list of the form '(MONTH DAY YEAR)'.
106 The string resulting from evaluating this expression is placed at
107 the bottom center of each date in monthly calendars, next to the
108 date in the weekly calendars, and in the top center of daily calendars.
110 The default is ordinal day number of the year and the number of
111 days remaining. As an example, setting this to
113 '(calendar-hebrew-date-string date)
115 will put the Hebrew date at the bottom of each day."
117 :group 'calendar-tex)
119 (defcustom cal-tex-buffer "calendar.tex"
120 "The name for the output LaTeX calendar buffer."
122 :group 'calendar-tex)
124 (defcustom cal-tex-24 nil
125 "Non-nil means use a 24 hour clock in the daily calendar."
127 :group 'calendar-tex)
129 (defcustom cal-tex-daily-start 8
130 "The first hour of the daily LaTeX calendar page.
131 At present, this only affects `cal-tex-cursor-day'."
133 :group 'calendar-tex)
135 (defcustom cal-tex-daily-end 20
136 "The last hour of the daily LaTeX calendar page.
137 At present, this only affects `cal-tex-cursor-day'."
139 :group 'calendar-tex)
141 (defcustom cal-tex-preamble-extra nil
142 "A string giving extra LaTeX commands to insert in the calendar preamble.
143 For example, to include extra packages:
144 \"\\\\usepackage{foo}\\n\\\\usepackage{bar}\\n\"."
145 :type '(choice (const nil)
146 ;; An example to help people format things in custom.
147 (string :value "\\usepackage{foo}\n\\usepackage{bar}\n"))
151 (defcustom cal-tex-hook nil
152 "List of functions called after any LaTeX calendar buffer is generated.
153 You can use this to do post-processing on the buffer. For example, to change
154 characters with diacritical marks to their LaTeX equivalents, use
155 (add-hook 'cal-tex-hook
156 (lambda () (iso-iso2tex (point-min) (point-max))))"
158 :group 'calendar-tex)
160 (defcustom cal-tex-year-hook nil
161 "List of functions called after a LaTeX year calendar buffer is generated."
163 :group 'calendar-tex)
165 (defcustom cal-tex-month-hook nil
166 "List of functions called after a LaTeX month calendar buffer is generated."
168 :group 'calendar-tex)
170 (defcustom cal-tex-week-hook nil
171 "List of functions called after a LaTeX week calendar buffer is generated."
173 :group 'calendar-tex)
175 (defcustom cal-tex-daily-hook nil
176 "List of functions called after a LaTeX daily calendar buffer is generated."
178 :group 'calendar-tex)
181 ;;; Definitions for LaTeX code
184 (defconst cal-tex-day-prefix "\\caldate{%s}{%s}"
185 "The initial LaTeX code for a day.
186 The holidays, diary entries, bottom string, and the text follow.")
188 (defconst cal-tex-day-name-format "\\myday{%s}%%"
189 "The format for LaTeX code for a day name.
190 The names are taken from `calendar-day-name-array'.")
192 (defconst cal-tex-cal-one-month
193 "\\def\\calmonth#1#2%
195 \\Huge\\bf\\uppercase{#1} #2 \\\\[1cm]%
200 "LaTeX code for the month header, for a single month calendar.")
202 (defconst cal-tex-cal-multi-month
203 "\\def\\calmonth#1#2#3#4%
205 \\Huge\\bf #1 #2---#3 #4\\\\[1cm]%
210 "LaTeX code for the month header, for a multi-month calendar.")
212 (defconst cal-tex-myday
213 "\\renewcommand{\\myday}[1]%
214 {\\makebox[\\cellwidth]{\\hfill\\large\\bf#1\\hfill}}
217 "LaTeX code for a day heading.")
219 (defconst cal-tex-caldate
221 \\long\\def\\caldate#1#2#3#4#5#6{%
222 \\fbox{\\hbox to\\cellwidth{%
223 \\vbox to\\cellheight{%
224 \\hbox to\\cellwidth{%
225 {\\hspace*{1mm}\\Large \\bf \\strut #2}\\hspace{.05\\cellwidth}%
226 \\raisebox{\\holidaymult\\cellheight}%
227 {\\parbox[t]{.75\\cellwidth}{\\tiny \\raggedright #4}}}
228 \\hbox to\\cellwidth{%
229 \\hspace*{1mm}\\parbox{.95\\cellwidth}{\\tiny \\raggedright #3}}
231 \\hbox to\\cellwidth{#6}%
233 \\hbox to\\cellwidth{\\hfill \\tiny #5 \\hfill}%
237 "LaTeX code to insert one box with date info in calendar.
238 This definition is the heart of the calendar!")
240 (autoload 'holiday-in-range "holidays")
242 (define-obsolete-function-alias 'cal-tex-list-holidays 'holiday-in-range "24.2")
244 (autoload 'diary-list-entries "diary-lib")
246 (defun cal-tex-list-diary-entries (d1 d2)
247 "Generate a list of all diary-entries from absolute date D1 to D2."
248 (let (diary-list-include-blanks)
249 (diary-list-entries (calendar-gregorian-from-absolute d1)
252 (defun cal-tex-preamble (&optional args)
253 "Insert the LaTeX calendar preamble into `cal-tex-buffer'.
254 Preamble includes initial definitions for various LaTeX commands.
255 Optional string ARGS are included as options for the article document class."
256 ;; FIXME use generate-new-buffer, and adjust cal-tex-end-document.
257 (set-buffer (get-buffer-create cal-tex-buffer))
258 (insert (format "\\documentclass%s{article}\n"
262 (if (stringp cal-tex-preamble-extra)
263 (insert cal-tex-preamble-extra "\n"))
264 (insert "\\hbadness 20000
270 \\evensidemargin -2cm
275 \\newlength{\\cellwidth}
276 \\newlength{\\cellheight}
277 \\newlength{\\boxwidth}
278 \\newlength{\\boxheight}
279 \\newlength{\\cellsize}
280 \\newcommand{\\myday}[1]{}
281 \\newcommand{\\caldate}[6]{}
282 \\newcommand{\\nocaldate}[6]{}
283 \\newcommand{\\calsmall}[6]{}
292 (defun cal-tex-cursor-year (&optional n event)
293 "Make a buffer with LaTeX commands for the year cursor is on.
294 Optional prefix argument N specifies number of years.
295 Optional EVENT indicates a buffer position to use instead of point."
296 (interactive (list (prefix-numeric-value current-prefix-arg)
298 (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t event))
302 (defun cal-tex-cursor-year-landscape (&optional n event)
303 "Make a buffer with LaTeX commands for the year cursor is on.
304 Optional prefix argument N specifies number of years.
305 Optional EVENT indicates a buffer position to use instead of point."
306 (interactive (list (prefix-numeric-value current-prefix-arg)
308 (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t event))
311 (defun cal-tex-year (year n &optional landscape)
312 "Make a one page yearly calendar of YEAR; do this for N years.
313 There are four rows of three months each, unless optional
314 LANDSCAPE is non-nil, in which case the calendar is printed in
315 landscape mode with three rows of four months each."
316 (cal-tex-insert-preamble 1 landscape "12pt")
318 (cal-tex-vspace "-.6cm")
319 (cal-tex-vspace "-3.1cm"))
321 (insert "\\vfill%\n")
323 (cal-tex-Huge (number-to-string year))
325 (cal-tex-vspace "1cm")
327 (cal-tex-b-parbox "l" (if landscape "5.9in" "4.3in"))
332 (insert (cal-tex-mini-calendar (1+ i) year "month" "1.1in" "1in"))
334 (cal-tex-hspace "0.5in")
335 (if (zerop (mod (1+ i) (if landscape 4 3)))
336 (cal-tex-nl "0.5in")))
339 (insert "\\vfill%\n")
340 (setq year (1+ year))
342 (cal-tex-end-document)
344 (run-hooks 'cal-tex-year-hook))
345 (run-hooks 'cal-tex-hook))
348 (defun cal-tex-cursor-filofax-year (&optional n event)
349 "Make a Filofax one page yearly calendar of year indicated by cursor.
350 Optional prefix argument N specifies number of years.
351 Optional EVENT indicates a buffer position to use instead of point."
352 (interactive (list (prefix-numeric-value current-prefix-arg)
355 (let ((year (calendar-extract-year (calendar-cursor-to-date t event))))
356 (cal-tex-preamble "twoside")
357 (cal-tex-cmd "\\textwidth 3.25in")
358 (cal-tex-cmd "\\textheight 6.5in")
359 (cal-tex-cmd "\\oddsidemargin 1.675in")
360 (cal-tex-cmd "\\evensidemargin 1.675in")
361 (cal-tex-cmd "\\topmargin 0pt")
362 (cal-tex-cmd "\\headheight -0.875in")
363 (cal-tex-cmd "\\fboxsep 0.5mm")
364 (cal-tex-cmd "\\pagestyle{empty}")
366 (cal-tex-cmd "\\vspace*{0.25in}")
368 (insert (format "\\hfil \\textbf{\\Large %s} \\hfil\\\\\n" year))
370 (cal-tex-b-parbox "l" "\\textwidth")
374 (let ((month-names; don't use default in case user changed it
375 ;; These are only used to define the command names, not
376 ;; the names of the months they insert.
377 ["January" "February" "March" "April" "May" "June"
378 "July" "August" "September" "October" "November" "December"]))
380 (insert (cal-tex-mini-calendar (1+ i) year (aref month-names i)
381 "1in" ".9in" "tiny" "0.6mm"))))
383 "\\noindent\\fbox{\\January}\\fbox{\\February}\\fbox{\\March}\\\\
384 \\noindent\\fbox{\\April}\\fbox{\\May}\\fbox{\\June}\\\\
385 \\noindent\\fbox{\\July}\\fbox{\\August}\\fbox{\\September}\\\\
386 \\noindent\\fbox{\\October}\\fbox{\\November}\\fbox{\\December}
390 (setq year (1+ year))
392 (cal-tex-end-document)
394 (cal-tex-cmd "\\vspace*{0.25in}"))
395 (run-hooks 'cal-tex-year-hook))
396 (run-hooks 'cal-tex-hook)))
399 ;;; Monthly calendars
403 (defun cal-tex-cursor-month-landscape (&optional n event)
404 "Make a LaTeX calendar buffer for the month the cursor is on.
405 Optional prefix argument N specifies number of months to be
406 produced (default 1). The output is in landscape format, one
407 month to a page. It shows holiday and diary entries if
408 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
409 Optional EVENT indicates a buffer position to use instead of point."
410 (interactive (list (prefix-numeric-value current-prefix-arg)
413 (let* ((date (calendar-cursor-to-date t event))
414 (month (calendar-extract-month date))
415 (year (calendar-extract-year date))
418 (cal-tex-which-days '(0 1 2 3 4 5 6))
419 (d1 (calendar-absolute-from-gregorian (list month 1 year)))
421 (calendar-increment-month end-month end-year (1- n))
422 (calendar-absolute-from-gregorian
424 (calendar-last-day-of-month end-month end-year)
426 (diary-list (if cal-tex-diary (cal-tex-list-diary-entries d1 d2)))
427 (holidays (if cal-tex-holidays (holiday-in-range d1 d2)))
428 other-month other-year small-months-at-start)
429 (cal-tex-insert-preamble (cal-tex-number-weeks month year 1) t "12pt")
430 (cal-tex-cmd cal-tex-cal-one-month)
432 (setq other-month month
434 (calendar-increment-month other-month other-year -1)
435 (insert (cal-tex-mini-calendar other-month other-year "lastmonth"
436 "\\cellwidth" "\\cellheight"))
437 (calendar-increment-month other-month other-year 2)
438 (insert (cal-tex-mini-calendar other-month other-year "nextmonth"
439 "\\cellwidth" "\\cellheight"))
440 (cal-tex-insert-month-header 1 month year month year)
441 (cal-tex-insert-day-names)
443 (if (setq small-months-at-start
444 (< 1 (mod (- (calendar-day-of-week (list month 1 year))
445 calendar-week-start-day)
447 (insert "\\lastmonth\\nextmonth\\hspace*{-2\\cellwidth}"))
448 (cal-tex-insert-blank-days month year cal-tex-day-prefix)
449 (cal-tex-insert-days month year diary-list holidays
451 (cal-tex-insert-blank-days-at-end month year cal-tex-day-prefix)
452 (if (and (not small-months-at-start)
453 (< 1 (mod (- (1- calendar-week-start-day)
454 (calendar-day-of-week
456 (calendar-last-day-of-month month year)
459 (insert "\\vspace*{-\\cellwidth}\\hspace*{-2\\cellwidth}"
460 "\\lastmonth\\nextmonth%
463 (run-hooks 'cal-tex-month-hook)
465 (calendar-increment-month month year 1)
466 (cal-tex-vspace "-2cm")
467 (cal-tex-insert-preamble
468 (cal-tex-number-weeks month year 1) t "12pt" t))))
469 (cal-tex-end-document)
470 (run-hooks 'cal-tex-hook))
473 (defun cal-tex-cursor-month (&optional n event)
474 "Make a LaTeX calendar buffer for the month the cursor is on.
475 Optional prefix argument N specifies number of months to be
476 produced (default 1). The calendar is condensed onto one page.
477 It shows holiday and diary entries if `cal-tex-holidays' and
478 `cal-tex-diary', respectively, are non-nil. Optional EVENT
479 indicates a buffer position to use instead of point."
480 (interactive (list (prefix-numeric-value current-prefix-arg)
483 (let* ((date (calendar-cursor-to-date t event))
484 (month (calendar-extract-month date))
485 (year (calendar-extract-year date))
488 ;; FIXME -landscape sets cal-tex-which-days?
489 (d1 (calendar-absolute-from-gregorian (list month 1 year)))
491 (calendar-increment-month end-month end-year (1- n))
492 (calendar-absolute-from-gregorian
494 (calendar-last-day-of-month end-month end-year)
496 (diary-list (if cal-tex-diary (cal-tex-list-diary-entries d1 d2)))
497 (holidays (if cal-tex-holidays (holiday-in-range d1 d2))))
498 (cal-tex-insert-preamble (cal-tex-number-weeks month year n) nil "12pt")
500 (cal-tex-cmd cal-tex-cal-multi-month)
501 (cal-tex-cmd cal-tex-cal-one-month))
502 (cal-tex-insert-month-header n month year end-month end-year)
503 (cal-tex-insert-day-names)
505 (cal-tex-insert-blank-days month year cal-tex-day-prefix)
507 (cal-tex-insert-days month year diary-list holidays cal-tex-day-prefix)
508 (when (= (calendar-week-end-day)
509 (calendar-day-of-week
511 (calendar-last-day-of-month month year)
512 year))) ; last day of month was last day of week
515 (calendar-increment-month month year 1))
516 (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix))
517 (cal-tex-end-document)
518 (run-hooks 'cal-tex-hook))
520 (defun cal-tex-insert-days (month year diary-list holidays day-format)
521 "Insert LaTeX commands for a range of days in monthly calendars.
522 LaTeX commands are inserted for the days of the MONTH in YEAR.
523 Diary entries on DIARY-LIST are included. Holidays on HOLIDAYS
524 are included. Each day is formatted using format DAY-FORMAT."
525 (let ((blank-days ; at start of month
527 (- (calendar-day-of-week (list month 1 year))
528 calendar-week-start-day)
530 (last (calendar-last-day-of-month month year))
533 (setq j (1+ i) ; 1-last, incl
534 date (list month j year))
535 (when (memq (calendar-day-of-week date) cal-tex-which-days)
536 (insert (format day-format (cal-tex-month-name month) j))
537 (cal-tex-arg (cal-tex-latexify-list diary-list date))
538 (cal-tex-arg (cal-tex-latexify-list holidays date))
539 (cal-tex-arg (eval cal-tex-daily-string))
542 (when (and (zerop (mod (+ j blank-days) 7))
547 (defun cal-tex-insert-day-names ()
548 "Insert the names of the days at top of a monthly calendar."
551 (if (memq (setq j (mod (+ calendar-week-start-day i) 7))
553 (insert (format cal-tex-day-name-format
554 (cal-tex-LaTeXify-string
555 (aref calendar-day-name-array j)))))
558 (defun cal-tex-insert-month-header (n month year end-month end-year)
559 "Create a title for a calendar.
560 A title is inserted for a calendar with N months starting with
561 MONTH YEAR and ending with END-MONTH END-YEAR."
562 (let ((month-name (cal-tex-month-name month))
563 (end-month-name (cal-tex-month-name end-month)))
565 (insert (format "\\calmonth{%s}{%s}\n\\vspace*{-0.5cm}"
567 (insert (format "\\calmonth{%s}{%s}{%s}{%s}\n\\vspace*{-0.5cm}"
568 month-name year end-month-name end-year))))
571 (defun cal-tex-insert-blank-days (month year day-format)
572 "Insert code for initial days not in calendar.
573 Insert LaTeX code for the blank days at the beginning of the MONTH in
574 YEAR. The entry is formatted using DAY-FORMAT. If the entire week is
575 blank, no days are inserted."
576 (if (cal-tex-first-blank-p month year)
577 (let ((blank-days ; at start of month
579 (- (calendar-day-of-week (list month 1 year))
580 calendar-week-start-day)
582 (dotimes (i blank-days)
583 (if (memq (mod (+ calendar-week-start-day i) 7) cal-tex-which-days)
584 (insert (format day-format " " " ") "{}{}{}{}%\n"))))))
586 (defun cal-tex-insert-blank-days-at-end (month year day-format)
587 "Insert code for final days not in calendar.
588 Insert LaTeX code for the blank days at the end of the MONTH in YEAR.
589 The entry is formatted using DAY-FORMAT."
590 (if (cal-tex-last-blank-p month year)
591 (let* ((last-day (calendar-last-day-of-month month year))
592 (blank-days ; at end of month
594 (- (calendar-day-of-week (list month last-day year))
595 calendar-week-start-day)
598 (while (<= (setq i (1+ i)) 6)
599 (if (memq (mod (+ calendar-week-start-day i) 7) cal-tex-which-days)
600 (insert (format day-format "" "") "{}{}{}{}%\n"))))))
602 (defun cal-tex-first-blank-p (month year)
603 "Determine if any days of the first week will be printed.
604 Return t if there will there be any days of the first week printed
605 in the calendar starting in MONTH YEAR."
606 ;; Check days 1-7 of the month, until we find the last day of the week.
610 (if (memq (setq dow (calendar-day-of-week (list month (1+ i) year)))
613 (if (= dow (calendar-week-end-day)) (throw 'found nil)))))))
615 (defun cal-tex-last-blank-p (month year)
616 "Determine if any days of the last week will be printed.
617 Return t if there will there be any days of the last week printed
618 in the calendar starting in MONTH YEAR."
619 ;; Check backwards from the last day of the month, until we find the
620 ;; start of the last week in the month.
622 (let ((last-day (calendar-last-day-of-month month year))
625 (if (memq (setq dow (calendar-day-of-week
626 (list month (- last-day i) year)))
629 (if (= dow calendar-week-start-day) (throw 'found nil)))))))
631 (defun cal-tex-number-weeks (month year n)
632 "Determine the number of weeks in a range of dates.
633 Compute the number of weeks in the calendar starting with MONTH and YEAR,
634 and lasting N months, including only the days in WHICH-DAYS. As it stands,
635 this is only an upper bound."
636 (let ((d (list month 1 year)))
637 (calendar-increment-month month year (1- n))
638 (/ (- (calendar-dayname-on-or-before
639 calendar-week-start-day
640 (+ 7 (calendar-absolute-from-gregorian
641 (list month (calendar-last-day-of-month month year) year))))
642 (calendar-dayname-on-or-before
643 calendar-week-start-day
644 (calendar-absolute-from-gregorian d)))
651 (defconst cal-tex-LaTeX-hourbox
652 "\\newcommand{\\hourbox}[2]%
653 {\\makebox[2em]{\\rule{0cm}{#2ex}#1}\\rule{3in}{.15mm}}\n"
654 "One hour and a line on the right.")
656 ;; TODO cal-tex-diary-support.
657 ;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
659 (defun cal-tex-cursor-week (&optional n event)
660 "Make a LaTeX calendar buffer for a two-page one-week calendar.
661 It applies to the week that point is in. The optional prefix
662 argument N specifies number of weeks (default 1). The calendar
663 shows holidays if `cal-tex-holidays' is non-nil (note that diary
664 entries are not shown). The calendar shows the hours 8-12am, 1-5pm."
665 (interactive (list (prefix-numeric-value current-prefix-arg)
668 (let* ((date (calendar-gregorian-from-absolute
669 (calendar-dayname-on-or-before
670 calendar-week-start-day
671 (calendar-absolute-from-gregorian
672 (calendar-cursor-to-date t event)))))
673 (month (calendar-extract-month date))
674 (year (calendar-extract-year date))
675 (d1 (calendar-absolute-from-gregorian date))
677 (holidays (if cal-tex-holidays
678 (holiday-in-range d1 d2))))
679 (cal-tex-preamble "11pt")
680 (cal-tex-cmd "\\textwidth 6.5in")
681 (cal-tex-cmd "\\textheight 10.5in")
682 (cal-tex-cmd "\\oddsidemargin 0in")
683 (cal-tex-cmd "\\evensidemargin 0in")
684 (insert cal-tex-LaTeX-hourbox)
686 (cal-tex-cmd "\\pagestyle{empty}")
688 (cal-tex-vspace "-1.5in")
690 (cal-tex-Huge-bf (format "\\uppercase{%s}"
691 (cal-tex-month-name month)))
692 (cal-tex-hspace "2em")
693 (cal-tex-Huge-bf (number-to-string year))
696 (cal-tex-hspace "-.2in")
697 (cal-tex-b-parbox "l" "7in")
699 (cal-tex-week-hours date holidays "3.1")
700 (setq date (cal-tex-incr-date date)))
702 (setq month (calendar-extract-month date)
703 year (calendar-extract-year date))
705 (run-hooks 'cal-tex-week-hook)
707 (cal-tex-end-document)
708 (run-hooks 'cal-tex-hook)))
710 ;; TODO cal-tex-diary support.
711 ;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
713 (defun cal-tex-cursor-week2 (&optional n event)
714 "Make a LaTeX calendar buffer for a two-page one-week calendar.
715 It applies to the week that point is in. Optional prefix
716 argument N specifies number of weeks (default 1). The calendar
717 shows holidays if `cal-tex-holidays' is non-nil (note that diary
718 entries are not shown). The calendar shows the hours 8-12am, 1-5pm.
719 Optional EVENT indicates a buffer position to use instead of point."
720 (interactive (list (prefix-numeric-value current-prefix-arg)
723 (let* ((date (calendar-gregorian-from-absolute
724 (calendar-dayname-on-or-before
725 calendar-week-start-day
726 (calendar-absolute-from-gregorian
727 (calendar-cursor-to-date t event)))))
728 (month (calendar-extract-month date))
729 (year (calendar-extract-year date))
730 (d1 (calendar-absolute-from-gregorian date))
732 (holidays (if cal-tex-holidays
733 (holiday-in-range d1 d2))))
734 (cal-tex-preamble "12pt")
735 (cal-tex-cmd "\\textwidth 6.5in")
736 (cal-tex-cmd "\\textheight 10.5in")
737 (cal-tex-cmd "\\oddsidemargin 0in")
738 (cal-tex-cmd "\\evensidemargin 0in")
739 (insert cal-tex-LaTeX-hourbox)
741 (cal-tex-cmd "\\pagestyle{empty}")
743 (cal-tex-vspace "-1.5in")
745 (cal-tex-Huge-bf (format "\\uppercase{%s}"
746 (cal-tex-month-name month)))
747 (cal-tex-hspace "2em")
748 (cal-tex-Huge-bf (number-to-string year))
751 (cal-tex-hspace "-.2in")
752 (cal-tex-b-parbox "l" "\\textwidth")
754 (cal-tex-week-hours date holidays "5")
755 (setq date (cal-tex-incr-date date)))
758 (insert (cal-tex-mini-calendar
759 (calendar-extract-month (cal-tex-previous-month date))
760 (calendar-extract-year (cal-tex-previous-month date))
761 "lastmonth" "1.1in" "1in"))
762 (insert (cal-tex-mini-calendar
763 (calendar-extract-month date)
764 (calendar-extract-year date)
765 "thismonth" "1.1in" "1in"))
766 (insert (cal-tex-mini-calendar
767 (calendar-extract-month (cal-tex-next-month date))
768 (calendar-extract-year (cal-tex-next-month date))
769 "nextmonth" "1.1in" "1in"))
770 (insert "\\hbox to \\textwidth{")
772 (insert "\\lastmonth")
774 (insert "\\thismonth")
776 (insert "\\nextmonth")
780 (cal-tex-b-parbox "l" "\\textwidth")
782 (cal-tex-week-hours date holidays "5")
783 (setq date (cal-tex-incr-date date)))
785 (setq month (calendar-extract-month date)
786 year (calendar-extract-year date))
788 (run-hooks 'cal-tex-week-hook)
790 (cal-tex-end-document)
791 (run-hooks 'cal-tex-hook)))
793 (autoload 'calendar-iso-from-absolute "cal-iso")
796 (defun cal-tex-cursor-week-iso (&optional n event)
797 "Make a LaTeX calendar buffer for a one page ISO-style weekly calendar.
798 Optional prefix argument N specifies number of weeks (default 1).
799 The calendar shows holiday and diary entries if
800 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
801 It does not show hours of the day. Optional EVENT indicates a buffer
802 position to use instead of point."
803 (interactive (list (prefix-numeric-value current-prefix-arg)
806 (let* ((date (calendar-gregorian-from-absolute
807 (calendar-dayname-on-or-before
809 (calendar-absolute-from-gregorian
810 (calendar-cursor-to-date t event)))))
811 (month (calendar-extract-month date))
812 (year (calendar-extract-year date))
813 (day (calendar-extract-day date))
814 (d1 (calendar-absolute-from-gregorian date))
816 (holidays (if cal-tex-holidays
817 (holiday-in-range d1 d2)))
818 (diary-list (if cal-tex-diary
819 (cal-tex-list-diary-entries
821 (calendar-absolute-from-gregorian (list month 1 year))
824 (cal-tex-preamble "11pt")
825 (cal-tex-cmd "\\textwidth 6.5in")
826 (cal-tex-cmd "\\textheight 10.5in")
827 (cal-tex-cmd "\\oddsidemargin 0in")
828 (cal-tex-cmd "\\evensidemargin 0in")
830 (cal-tex-cmd "\\pagestyle{empty}")
832 (cal-tex-vspace "-1.5in")
835 (let ((d (calendar-iso-from-absolute
836 (calendar-absolute-from-gregorian date))))
837 (format "Week %d of %d"
838 (calendar-extract-month d)
839 (calendar-extract-year d))))
842 (cal-tex-b-parbox "l" "\\textwidth")
844 (cal-tex-b-parbox "t" "\\textwidth")
845 (cal-tex-b-parbox "t" "\\textwidth")
846 (cal-tex-rule "0pt" "\\textwidth" ".2mm")
848 (cal-tex-b-parbox "t" "\\textwidth")
849 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date)))
851 (cal-tex-large-bf (cal-tex-month-name month))
853 (cal-tex-large-bf (number-to-string day))
854 (unless (string-equal "" (setq s (cal-tex-latexify-list
855 holidays date "; ")))
857 (cal-tex-large-bf s))
859 (insert " " (eval cal-tex-daily-string))
863 (cal-tex-b-parbox "t" "\\textwidth")
864 (unless (string-equal "" (setq s (cal-tex-latexify-list
866 (insert "\\vbox to 0pt{")
871 (setq date (cal-tex-incr-date date)
872 month (calendar-extract-month date)
873 day (calendar-extract-day date))
875 (cal-tex-e-parbox "2cm")
877 (setq month (calendar-extract-month date)
878 year (calendar-extract-year date)))
881 (run-hooks 'cal-tex-week-hook)
883 (cal-tex-end-document)
884 (run-hooks 'cal-tex-hook)))
886 ;; TODO respect cal-tex-daily-start,end?
887 ;; Using different numbers of hours will probably break some layouts.
888 (defun cal-tex-week-hours (date holidays height)
889 "Insert hourly entries for DATE with HOLIDAYS, with line height HEIGHT.
890 Uses the 24-hour clock if `cal-tex-24' is non-nil. Note that the hours
891 shown are hard-coded to 8-12, 13-17."
892 (let ((month (calendar-extract-month date))
893 (day (calendar-extract-day date))
894 (year (calendar-extract-year date))
896 (cal-tex-comment "begin cal-tex-week-hours")
897 (cal-tex-cmd "\\ \\\\[-.2cm]")
898 (cal-tex-cmd "\\noindent")
899 (cal-tex-b-parbox "l" "6.8in")
900 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date)))
902 (cal-tex-large-bf (cal-tex-month-name month))
904 (cal-tex-large-bf (number-to-string day))
905 (unless (string-equal "" (setq s (cal-tex-latexify-list
906 holidays date "; ")))
908 (cal-tex-large-bf s))
910 (insert " " (eval cal-tex-daily-string))
913 (cal-tex-rule "0pt" "6.8in" ".2mm")
916 (setq morning (+ i 8) ; 8-12 incl
917 afternoon (if cal-tex-24
918 (+ i 13) ; 13-17 incl
920 (cal-tex-cmd "\\hourbox" (number-to-string morning))
922 (cal-tex-hspace ".4cm")
923 (cal-tex-cmd "\\hourbox" (number-to-string afternoon))
927 ;; TODO cal-tex-diary support.
928 ;; TODO respect cal-tex-daily-start,end (see cal-tex-weekly4-box).
930 (defun cal-tex-cursor-week-monday (&optional n event)
931 "Make a LaTeX calendar buffer for a two-page one-week calendar.
932 It applies to the week that point is in, and starts on Monday.
933 Optional prefix argument N specifies number of weeks (default 1).
934 The calendar shows holidays if `cal-tex-holidays' is
935 non-nil (note that diary entries are not shown). The calendar shows
936 the hours 8-12am, 1-5pm. Optional EVENT indicates a buffer position
937 to use instead of point."
938 (interactive (list (prefix-numeric-value current-prefix-arg)
941 (let ((date (calendar-gregorian-from-absolute
942 (calendar-dayname-on-or-before
944 (calendar-absolute-from-gregorian
945 (calendar-cursor-to-date t event))))))
946 (cal-tex-preamble "11pt")
947 (cal-tex-cmd "\\textwidth 6.5in")
948 (cal-tex-cmd "\\textheight 10.5in")
949 (cal-tex-cmd "\\oddsidemargin 0in")
950 (cal-tex-cmd "\\evensidemargin 0in")
953 (cal-tex-vspace "-1cm")
954 (insert "\\noindent ")
955 (cal-tex-weekly4-box (cal-tex-incr-date date) nil)
956 (cal-tex-weekly4-box (cal-tex-incr-date date 4) nil)
958 (cal-tex-weekly4-box (cal-tex-incr-date date 2) nil)
959 (cal-tex-weekly4-box (cal-tex-incr-date date 5) nil)
961 (cal-tex-weekly4-box (cal-tex-incr-date date 3) nil)
962 (cal-tex-weekly4-box (cal-tex-incr-date date 6) t)
964 (run-hooks 'cal-tex-week-hook)
965 (setq date (cal-tex-incr-date date 7))
967 (cal-tex-end-document)
968 (run-hooks 'cal-tex-hook)))
970 ;; TODO respect cal-tex-daily-start,end?
971 ;; Using different numbers of hours will probably break some layouts.
972 (defun cal-tex-weekly4-box (date weekend)
973 "Make one box for DATE, different if WEEKEND.
974 Uses the 24-hour clock if `cal-tex-24' is non-nil. Note that the hours
975 shown are hard-coded to 8-12, 13-17."
976 (let* ((day (calendar-extract-day date))
977 (month (calendar-extract-month date))
978 (year (calendar-extract-year date))
979 (dayname (cal-tex-LaTeXify-string (calendar-day-name date)))
980 (date1 (cal-tex-incr-date date))
981 (day1 (calendar-extract-day date1))
982 (month1 (calendar-extract-month date1))
983 (year1 (calendar-extract-year date1))
984 (dayname1 (cal-tex-LaTeXify-string (calendar-day-name date1))))
985 (cal-tex-b-framebox "8cm" "l")
986 (cal-tex-b-parbox "b" "7.5cm")
987 (insert (format "\\textbf{\\Large %s,} %s/%s/%s\\\\\n"
988 dayname month day year))
989 (cal-tex-rule "0pt" "7.5cm" ".5mm")
993 (insert (format "\\textsf{\\large %d}\\\\\n" (+ i 8))))
995 (insert (format "\\textsf{\\large %d}\\\\\n"
997 (+ i 13) ; 13-17 incl
998 (1+ i)))))) ; 1-5 incl
1001 (cal-tex-vspace "1cm")
1002 (insert "\\ \\vfill")
1003 (insert (format "\\textbf{\\Large %s,} %s/%s/%s\\\\\n"
1004 dayname1 month1 day1 year1))
1005 (cal-tex-rule "0pt" "7.5cm" ".5mm")
1006 (cal-tex-nl "1.5cm")
1007 (cal-tex-vspace "1cm"))
1009 (cal-tex-e-framebox)
1010 (cal-tex-hspace "1cm")))
1013 (defun cal-tex-cursor-filofax-2week (&optional n event)
1014 "Two-weeks-at-a-glance Filofax style calendar for week cursor is in.
1015 Optional prefix argument N specifies number of weeks (default 1).
1016 The calendar shows holiday and diary entries if
1017 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
1018 Optional EVENT indicates a buffer position to use instead of point."
1019 (interactive (list (prefix-numeric-value current-prefix-arg)
1020 last-nonmenu-event))
1022 (let* ((date (calendar-gregorian-from-absolute
1023 (calendar-dayname-on-or-before
1024 calendar-week-start-day
1025 (calendar-absolute-from-gregorian
1026 (calendar-cursor-to-date t event)))))
1027 (month (calendar-extract-month date))
1028 (year (calendar-extract-year date))
1029 (day (calendar-extract-day date))
1030 (d1 (calendar-absolute-from-gregorian date))
1032 (holidays (if cal-tex-holidays
1033 (holiday-in-range d1 d2)))
1034 (diary-list (if cal-tex-diary
1035 (cal-tex-list-diary-entries
1037 (calendar-absolute-from-gregorian (list month 1 year))
1039 (cal-tex-preamble "twoside")
1040 (cal-tex-cmd "\\textwidth 3.25in")
1041 (cal-tex-cmd "\\textheight 6.5in")
1042 (cal-tex-cmd "\\oddsidemargin 1.75in")
1043 (cal-tex-cmd "\\evensidemargin 1.5in")
1044 (cal-tex-cmd "\\topmargin 0pt")
1045 (cal-tex-cmd "\\headheight -0.875in")
1046 (cal-tex-cmd "\\headsep 0.125in")
1047 (cal-tex-cmd "\\footskip .125in")
1048 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1049 \\long\\def\\rightday#1#2#3#4#5{%
1050 \\rule{\\textwidth}{0.3pt}\\\\%
1051 \\hbox to \\textwidth{%
1054 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1055 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1056 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1057 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1058 \\long\\def\\leftday#1#2#3#4#5{%
1059 \\rule{\\textwidth}{0.3pt}\\\\%
1060 \\hbox to \\textwidth{%
1063 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1064 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1065 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1067 (cal-tex-b-document)
1068 (cal-tex-cmd "\\pagestyle{empty}")
1070 (if (zerop (mod i 2))
1071 (insert "\\righthead")
1072 (insert "\\lefthead"))
1074 (let ((d (cal-tex-incr-date date 6)))
1075 (if (= (calendar-extract-month date)
1076 (calendar-extract-month d))
1078 (cal-tex-month-name (calendar-extract-month date))
1079 (calendar-extract-year date))
1080 (if (= (calendar-extract-year date)
1081 (calendar-extract-year d))
1082 (format "%s---%s %s"
1083 (cal-tex-month-name (calendar-extract-month date))
1084 (cal-tex-month-name (calendar-extract-month d))
1085 (calendar-extract-year date))
1086 (format "%s %s---%s %s"
1087 (cal-tex-month-name (calendar-extract-month date))
1088 (calendar-extract-year date)
1089 (cal-tex-month-name (calendar-extract-month d))
1090 (calendar-extract-year d))))))
1092 (dotimes (_jdummy 7)
1093 (if (zerop (mod i 2))
1094 (insert "\\rightday")
1095 (insert "\\leftday"))
1096 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1097 (cal-tex-arg (number-to-string (calendar-extract-day date)))
1098 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1099 (cal-tex-arg (cal-tex-latexify-list holidays date))
1100 (cal-tex-arg (eval cal-tex-daily-string))
1102 (setq date (cal-tex-incr-date date)))
1103 (unless (= i (1- n))
1104 (run-hooks 'cal-tex-week-hook)
1106 (cal-tex-end-document)
1107 (run-hooks 'cal-tex-hook)))
1110 (defun cal-tex-cursor-filofax-week (&optional n event)
1111 "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
1112 Optional prefix argument N specifies number of weeks (default 1),
1113 starting on Mondays. The calendar shows holiday and diary entries
1114 if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
1115 Optional EVENT indicates a buffer position to use instead of point."
1116 (interactive (list (prefix-numeric-value current-prefix-arg)
1117 last-nonmenu-event))
1119 (let* ((date (calendar-gregorian-from-absolute
1120 (calendar-dayname-on-or-before
1122 (calendar-absolute-from-gregorian
1123 (calendar-cursor-to-date t event)))))
1124 (month (calendar-extract-month date))
1125 (year (calendar-extract-year date))
1126 (day (calendar-extract-day date))
1127 (d1 (calendar-absolute-from-gregorian date))
1129 (holidays (if cal-tex-holidays
1130 (holiday-in-range d1 d2)))
1131 (diary-list (if cal-tex-diary
1132 (cal-tex-list-diary-entries
1134 (calendar-absolute-from-gregorian (list month 1 year))
1136 (cal-tex-preamble "twoside")
1137 (cal-tex-cmd "\\textwidth 3.25in")
1138 (cal-tex-cmd "\\textheight 6.5in")
1139 (cal-tex-cmd "\\oddsidemargin 1.75in")
1140 (cal-tex-cmd "\\evensidemargin 1.5in")
1141 (cal-tex-cmd "\\topmargin 0pt")
1142 (cal-tex-cmd "\\headheight -0.875in")
1143 (cal-tex-cmd "\\headsep 0.125in")
1144 (cal-tex-cmd "\\footskip .125in")
1145 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1146 \\long\\def\\rightday#1#2#3#4#5{%
1147 \\rule{\\textwidth}{0.3pt}\\\\%
1148 \\hbox to \\textwidth{%
1151 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1152 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1153 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1154 \\long\\def\\weekend#1#2#3#4#5{%
1155 \\rule{\\textwidth}{0.3pt}\\\\%
1156 \\hbox to \\textwidth{%
1159 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1160 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1161 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1162 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1163 \\long\\def\\leftday#1#2#3#4#5{%
1164 \\rule{\\textwidth}{0.3pt}\\\\%
1165 \\hbox to \\textwidth{%
1168 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1169 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1170 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1172 (cal-tex-b-document)
1173 (cal-tex-cmd "\\pagestyle{empty}\\ ")
1176 (insert "\\lefthead")
1178 (let ((d (cal-tex-incr-date date 2)))
1179 (if (= (calendar-extract-month date)
1180 (calendar-extract-month d))
1182 (cal-tex-month-name (calendar-extract-month date))
1183 (calendar-extract-year date))
1184 (if (= (calendar-extract-year date)
1185 (calendar-extract-year d))
1186 (format "%s---%s %s"
1187 (cal-tex-month-name (calendar-extract-month date))
1188 (cal-tex-month-name (calendar-extract-month d))
1189 (calendar-extract-year date))
1190 (format "%s %s---%s %s"
1191 (cal-tex-month-name (calendar-extract-month date))
1192 (calendar-extract-year date)
1193 (cal-tex-month-name (calendar-extract-month d))
1194 (calendar-extract-year d))))))
1196 (dotimes (_jdummy 3)
1197 (insert "\\leftday")
1198 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1199 (cal-tex-arg (number-to-string (calendar-extract-day date)))
1200 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1201 (cal-tex-arg (cal-tex-latexify-list holidays date))
1202 (cal-tex-arg (eval cal-tex-daily-string))
1204 (setq date (cal-tex-incr-date date)))
1205 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1207 (insert "\\righthead")
1209 (let ((d (cal-tex-incr-date date 3)))
1210 (if (= (calendar-extract-month date)
1211 (calendar-extract-month d))
1213 (cal-tex-month-name (calendar-extract-month date))
1214 (calendar-extract-year date))
1215 (if (= (calendar-extract-year date)
1216 (calendar-extract-year d))
1217 (format "%s---%s %s"
1218 (cal-tex-month-name (calendar-extract-month date))
1219 (cal-tex-month-name (calendar-extract-month d))
1220 (calendar-extract-year date))
1221 (format "%s %s---%s %s"
1222 (cal-tex-month-name (calendar-extract-month date))
1223 (calendar-extract-year date)
1224 (cal-tex-month-name (calendar-extract-month d))
1225 (calendar-extract-year d))))))
1227 (dotimes (_jdummy 2)
1228 (insert "\\rightday")
1229 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1230 (cal-tex-arg (number-to-string (calendar-extract-day date)))
1231 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1232 (cal-tex-arg (cal-tex-latexify-list holidays date))
1233 (cal-tex-arg (eval cal-tex-daily-string))
1235 (setq date (cal-tex-incr-date date)))
1236 (dotimes (_jdummy 2)
1237 (insert "\\weekend")
1238 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1239 (cal-tex-arg (number-to-string (calendar-extract-day date)))
1240 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1241 (cal-tex-arg (cal-tex-latexify-list holidays date))
1242 (cal-tex-arg (eval cal-tex-daily-string))
1244 (setq date (cal-tex-incr-date date)))
1245 (unless (= i (1- n))
1246 (run-hooks 'cal-tex-week-hook)
1248 (cal-tex-end-document)
1249 (run-hooks 'cal-tex-hook)))
1252 (defun cal-tex-cursor-filofax-daily (&optional n event)
1253 "Day-per-page Filofax style calendar for week indicated by cursor.
1254 Optional prefix argument N specifies number of weeks (default 1),
1255 starting on Mondays. The calendar shows holiday and diary
1256 entries if `cal-tex-holidays' and `cal-tex-diary', respectively,
1257 are non-nil. Pages are ruled if `cal-tex-rules' is non-nil.
1258 Optional EVENT indicates a buffer position to use instead of point."
1259 (interactive (list (prefix-numeric-value current-prefix-arg)
1260 last-nonmenu-event))
1262 (let* ((date (calendar-gregorian-from-absolute
1263 (calendar-dayname-on-or-before
1265 (calendar-absolute-from-gregorian
1266 (calendar-cursor-to-date t event)))))
1267 (month (calendar-extract-month date))
1268 (year (calendar-extract-year date))
1269 (day (calendar-extract-day date))
1270 (d1 (calendar-absolute-from-gregorian date))
1272 (holidays (if cal-tex-holidays
1273 (holiday-in-range d1 d2)))
1274 (diary-list (if cal-tex-diary
1275 (cal-tex-list-diary-entries
1277 (calendar-absolute-from-gregorian (list month 1 year))
1279 (cal-tex-preamble "twoside")
1280 (cal-tex-cmd "\\textwidth 3.25in")
1281 (cal-tex-cmd "\\textheight 6.5in")
1282 (cal-tex-cmd "\\oddsidemargin 1.75in")
1283 (cal-tex-cmd "\\evensidemargin 1.5in")
1284 (cal-tex-cmd "\\topmargin 0pt")
1285 (cal-tex-cmd "\\headheight -0.875in")
1286 (cal-tex-cmd "\\headsep 0.125in")
1287 (cal-tex-cmd "\\footskip .125in")
1288 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1289 \\long\\def\\rightday#1#2#3{%
1290 \\rule{\\textwidth}{0.3pt}\\\\%
1291 \\hbox to \\textwidth{%
1294 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1295 \\hbox to \\textwidth{\\vbox {\\raggedleft \\em #2}}%
1296 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1297 \\long\\def\\weekend#1#2#3{%
1298 \\rule{\\textwidth}{0.3pt}\\\\%
1299 \\hbox to \\textwidth{%
1302 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1303 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1304 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1305 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1306 \\long\\def\\leftday#1#2#3{%
1307 \\rule{\\textwidth}{0.3pt}\\\\%
1308 \\hbox to \\textwidth{%
1311 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1312 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1313 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1315 \\setbox\\LineBox=\\hbox to\\textwidth{%
1316 \\vrule height.2in width0pt\\leaders\\hrule\\hfill}
1317 \\def\\linesfill{\\par\\leaders\\copy\\LineBox\\vfill}
1319 (cal-tex-b-document)
1320 (cal-tex-cmd "\\pagestyle{empty}")
1323 (let ((even (zerop (% j 2))))
1327 (cal-tex-arg (calendar-date-string date))
1332 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1333 (cal-tex-arg (cal-tex-latexify-list holidays date "\\\\" t))
1334 (cal-tex-arg (eval cal-tex-daily-string))
1337 (insert "\\linesfill\n")
1338 (insert "\\vfill\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1340 (setq date (cal-tex-incr-date date)))
1342 (dotimes (_jdummy 2)
1343 (insert "\\lefthead")
1344 (cal-tex-arg (calendar-date-string date))
1345 (insert "\\weekend")
1346 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1347 (cal-tex-arg (cal-tex-latexify-list holidays date "\\\\" t))
1348 (cal-tex-arg (eval cal-tex-daily-string))
1351 (insert "\\linesfill\n")
1353 (setq date (cal-tex-incr-date date)))
1355 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1356 (unless (= i (1- n))
1357 (run-hooks 'cal-tex-week-hook)
1359 (cal-tex-end-document)
1360 (run-hooks 'cal-tex-hook)))
1368 (defun cal-tex-cursor-day (&optional n event)
1369 "Make a buffer with LaTeX commands for the day cursor is on.
1370 Optional prefix argument N specifies number of days. The calendar shows
1371 the hours between `cal-tex-daily-start' and `cal-tex-daily-end', using
1372 the 24-hour clock if `cal-tex-24' is non-nil. Optional EVENT indicates
1373 a buffer position to use instead of point."
1374 (interactive (list (prefix-numeric-value current-prefix-arg)
1375 last-nonmenu-event))
1377 (let ((date (calendar-absolute-from-gregorian
1378 (calendar-cursor-to-date t event))))
1379 (cal-tex-preamble "12pt")
1380 (cal-tex-cmd "\\textwidth 6.5in")
1381 (cal-tex-cmd "\\textheight 10.5in")
1382 (cal-tex-b-document)
1383 (cal-tex-cmd "\\pagestyle{empty}")
1385 (cal-tex-vspace "-1.7in")
1386 (cal-tex-daily-page (calendar-gregorian-from-absolute date))
1387 (setq date (1+ date))
1388 (unless (= i (1- n))
1390 (run-hooks 'cal-tex-daily-hook)))
1391 (cal-tex-end-document)
1392 (run-hooks 'cal-tex-hook)))
1394 (defun cal-tex-daily-page (date)
1395 "Make a calendar page for Gregorian DATE on 8.5 by 11 paper.
1396 Uses the 24-hour clock if `cal-tex-24' is non-nil. Produces
1397 hourly sections for the period specified by `cal-tex-daily-start'
1398 and `cal-tex-daily-end'."
1399 (let ((month-name (cal-tex-month-name (calendar-extract-month date)))
1400 (i (1- cal-tex-daily-start))
1402 (cal-tex-banner "cal-tex-daily-page")
1403 (cal-tex-b-makebox "4cm" "l")
1404 (cal-tex-b-parbox "b" "3.8cm")
1405 (cal-tex-rule "0mm" "0mm" "2cm")
1406 (cal-tex-Huge (number-to-string (calendar-extract-day date)))
1408 (cal-tex-bf month-name )
1410 (cal-tex-hspace "1cm")
1411 (cal-tex-scriptsize (eval cal-tex-daily-string))
1412 (cal-tex-hspace "3.5cm")
1415 (cal-tex-b-makebox "4cm" "r")
1416 (cal-tex-bf (cal-tex-LaTeXify-string (calendar-day-name date)))
1419 (cal-tex-hspace ".4cm")
1420 (cal-tex-rule "0mm" "16.1cm" "1mm")
1422 (while (<= (setq i (1+ i)) cal-tex-daily-end)
1423 (cal-tex-cmd "\\noindent")
1424 (setq hour (if cal-tex-24
1427 (if (zerop hour) (setq hour 12))
1428 (cal-tex-b-makebox "1cm" "c")
1429 (cal-tex-arg (number-to-string hour))
1431 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1433 (cal-tex-b-makebox "1cm" "c")
1434 (cal-tex-arg "$\\diamond$" )
1436 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1437 (cal-tex-nl ".2cm"))
1439 (insert (cal-tex-mini-calendar
1440 (calendar-extract-month (cal-tex-previous-month date))
1441 (calendar-extract-year (cal-tex-previous-month date))
1442 "lastmonth" "1.1in" "1in"))
1443 (insert (cal-tex-mini-calendar
1444 (calendar-extract-month date)
1445 (calendar-extract-year date)
1446 "thismonth" "1.1in" "1in"))
1447 (insert (cal-tex-mini-calendar
1448 (calendar-extract-month (cal-tex-next-month date))
1449 (calendar-extract-year (cal-tex-next-month date))
1450 "nextmonth" "1.1in" "1in"))
1451 (insert "\\hbox to \\textwidth{")
1453 (insert "\\lastmonth")
1455 (insert "\\thismonth")
1457 (insert "\\nextmonth")
1460 (cal-tex-banner "end of cal-tex-daily-page")))
1466 (defun cal-tex-mini-calendar (month year name width height &optional ptsize colsep)
1467 "Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT.
1468 Optional string PTSIZE gives the point size (default \"scriptsize\").
1469 Optional string COLSEP gives the column separation (default \"1mm\")."
1470 (or colsep (setq colsep "1mm"))
1471 (or ptsize (setq ptsize "scriptsize"))
1472 (let ((blank-days ; at start of month
1474 (- (calendar-day-of-week (list month 1 year))
1475 calendar-week-start-day)
1477 (last( calendar-last-day-of-month month year))
1478 (str (concat "\\def\\" name "{\\hbox to" width "{%\n"
1479 "\\vbox to" height "{%\n"
1480 "\\vfil \\hbox to" width "{%\n"
1483 "{@{\\hspace{0mm}}r@{\\hspace{" colsep
1484 "}}r@{\\hspace{" colsep "}}r@{\\hspace{" colsep
1485 "}}r@{\\hspace{" colsep "}}r@{\\hspace{" colsep
1486 "}}r@{\\hspace{" colsep "}}r@{\\hspace{0mm}}}%\n"
1487 "\\multicolumn{7}{c}{"
1488 (cal-tex-month-name month)
1490 (number-to-string year)
1495 (cal-tex-LaTeXify-string
1496 (substring (aref calendar-day-name-array
1497 (mod (+ calendar-week-start-day i) 7))
1503 (dotimes (_idummy blank-days)
1504 (setq str (concat str " & ")))
1506 (setq str (concat str (number-to-string (1+ i)))
1507 str (concat str (if (zerop (mod (+ i 1 blank-days) 7))
1512 (setq str (concat str "\n\\end{tabular}\\hfil}\\vfil}}}%\n"))
1516 ;;; Various calendar functions
1519 (defun cal-tex-incr-date (date &optional n)
1520 "The date of the day following DATE.
1521 If optional N is given, the date of N days after DATE."
1522 (calendar-gregorian-from-absolute
1523 (+ (or n 1) (calendar-absolute-from-gregorian date))))
1525 (defun cal-tex-latexify-list (date-list date &optional separator final-separator)
1526 "Return string with concatenated, LaTeX-ified entries in DATE-LIST for DATE.
1527 Use double backslash as a separator unless optional SEPARATOR is given.
1528 If resulting string is not empty, put separator at end if optional
1529 FINAL-SEPARATOR is non-nil."
1530 (or separator (setq separator "\\\\"))
1533 (mapconcat (lambda (x) (cal-tex-LaTeXify-string x))
1534 (dolist (d date-list (reverse result))
1536 (calendar-date-equal date (car d))
1537 (setq result (cons (cadr d) result))))
1539 (if (and final-separator
1540 (not (string-equal result "")))
1541 (concat result separator)
1544 (defun cal-tex-previous-month (date)
1545 "Return the date of the first day in the month previous to DATE."
1546 (let ((month (calendar-extract-month date))
1547 (year (calendar-extract-year date)))
1548 (calendar-increment-month month year -1)
1549 (list month 1 year)))
1551 (defun cal-tex-next-month (date)
1552 "Return the date of the first day in the month following DATE."
1553 (let ((month (calendar-extract-month date))
1554 (year (calendar-extract-year date)))
1555 (calendar-increment-month month year 1)
1556 (list month 1 year)))
1562 (defun cal-tex-end-document ()
1563 "Finish the LaTeX document.
1564 Insert the trailer to LaTeX document, pop to LaTeX buffer, add
1565 informative header, and run HOOK."
1566 (cal-tex-e-document)
1567 (or (and cal-tex-preamble-extra
1568 (string-match "inputenc" cal-tex-preamble-extra))
1569 (when (re-search-backward "[^[:ascii:]]" nil 'move)
1570 (goto-char (point-min))
1571 (when (search-forward "documentclass" nil t)
1573 ;; Eg for some Bahai holidays.
1574 ;; FIXME latin1 might not always be right.
1575 (insert "\\usepackage[latin1]{inputenc}\n"))))
1577 (pop-to-buffer cal-tex-buffer)
1578 (goto-char (point-min))
1579 ;; FIXME auctex equivalents?
1581 (format "\tThis buffer was produced by cal-tex.el.
1582 \tTo print a calendar, type
1583 \t\tM-x tex-buffer RET
1584 \t\tM-x tex-print RET")))
1586 (defun cal-tex-insert-preamble (weeks landscape size &optional append)
1587 "Initialize the output LaTeX calendar buffer, `cal-tex-buffer'.
1588 Select the output buffer, and insert the preamble for a calendar
1589 of WEEKS weeks. Insert code for landscape mode if LANDSCAPE is
1590 non-nil. Use point-size SIZE. Optional argument APPEND, if
1591 non-nil, means add to end of buffer without erasing current contents."
1592 (let ((width "18cm")
1598 (cal-tex-preamble size)
1601 (cal-tex-cmd "\\oddsidemargin -1.75cm")
1602 (cal-tex-cmd "\\def\\holidaymult{.06}"))
1603 (cal-tex-cmd "\\special{landscape}")
1604 (cal-tex-cmd "\\textwidth 9.5in")
1605 (cal-tex-cmd "\\textheight 7in")
1607 (cal-tex-cmd "\\def\\holidaymult{.08}"))
1608 (cal-tex-cmd cal-tex-caldate)
1609 (cal-tex-cmd cal-tex-myday)
1610 (cal-tex-b-document)
1611 (cal-tex-cmd "\\pagestyle{empty}"))
1612 (cal-tex-cmd "\\setlength{\\cellwidth}" width)
1613 (insert (format "\\setlength{\\cellwidth}{%f\\cellwidth}\n"
1614 (/ 1.1 (length cal-tex-which-days))))
1615 (cal-tex-cmd "\\setlength{\\cellheight}" height)
1616 (insert (format "\\setlength{\\cellheight}{%f\\cellheight}\n"
1618 (cal-tex-cmd "\\ \\par")
1619 (cal-tex-vspace "-3cm")))
1621 (defconst cal-tex-LaTeX-subst-list
1623 ("\"". "''") ; quote changes meaning when list is reversed
1624 ;; Don't think this is necessary, and in any case, does not work:
1625 ;; "LaTeX Error: \verb illegal in command argument".
1626 ;;; ("@" . "\\verb|@|")
1636 ("\n" . "\\ \\\\")) ; \\ needed for e.g \begin{center}\n AA\end{center}
1637 "Alist of symbols and their LaTeX replacements.")
1639 (defun cal-tex-LaTeXify-string (string)
1640 "Protect special characters in STRING from LaTeX."
1645 (list cal-tex-LaTeX-subst-list)
1647 (while (not (string-equal tail ""))
1648 (setq ch (substring-no-properties tail 0 1)
1649 pair (assoc ch list))
1650 (if (and pair (string-equal ch "\""))
1651 (setq list (reverse list))) ; quote changes meaning each time
1652 (setq tail (substring-no-properties tail 1)
1653 head (concat head (if pair (cdr pair) ch))))
1656 (defun cal-tex-month-name (month)
1657 "The name of MONTH, LaTeX-ified."
1658 (cal-tex-LaTeXify-string (calendar-month-name month)))
1660 (defun cal-tex-hfill ()
1664 (defun cal-tex-newpage ()
1666 (insert "\\newpage%\n"))
1668 (defun cal-tex-noindent ()
1670 (insert "\\noindent"))
1672 (defun cal-tex-vspace (space)
1673 "Insert vspace command to move SPACE vertically."
1674 (insert "\\vspace*{" space "}")
1677 (defun cal-tex-hspace (space)
1678 "Insert hspace command to move SPACE horizontally."
1679 (insert "\\hspace*{" space "}")
1682 (defun cal-tex-comment (&optional comment)
1683 "Insert `% ', followed by optional string COMMENT, followed by newline.
1684 COMMENT may contain newlines, which are prefixed by `% ' in the output."
1685 (insert (format "%% %s\n"
1687 (replace-regexp-in-string "\n" "\n% " comment)
1690 (defun cal-tex-banner (comment)
1691 "Insert string COMMENT, separated by blank lines."
1692 (cal-tex-comment (format "\n\n\n\t\t\t%s\n" comment)))
1694 (defun cal-tex-nl (&optional skip comment)
1695 "End a line with \\. If SKIP, then add that much spacing.
1696 Add trailing COMMENT if present."
1697 (insert (format "\\\\%s"
1699 (format "[%s]" skip)
1701 (cal-tex-comment comment))
1703 (defun cal-tex-arg (&optional text)
1704 "Insert a brace {} pair containing the optional string TEXT."
1705 (insert (format "{%s}" (or text ""))))
1707 (defun cal-tex-cmd (cmd &optional arg)
1708 "Insert LaTeX CMD, with optional argument ARG, and end with %."
1717 (defun cal-tex-b-document ()
1718 "Insert beginning of document."
1719 (cal-tex-cmd "\\begin{document}"))
1721 (defun cal-tex-e-document ()
1722 "Insert end of document."
1723 (cal-tex-cmd "\\end{document}"))
1725 (defun cal-tex-b-center ()
1726 "Insert beginning of centered block."
1727 (cal-tex-cmd "\\begin{center}"))
1729 (defun cal-tex-e-center ()
1730 "Insert end of centered block."
1732 (cal-tex-cmd "\\end{center}"))
1740 (defun cal-tex-b-parbox (position width)
1741 "Insert parbox with parameters POSITION and WIDTH."
1742 (insert "\\parbox[" position "]{" width "}{")
1745 (defun cal-tex-e-parbox (&optional height)
1746 "Insert end of parbox. Optionally, force it to be a given HEIGHT."
1749 (cal-tex-rule "0mm" "0mm" height))
1751 (cal-tex-comment "end parbox"))
1753 (defun cal-tex-b-framebox (width position)
1754 "Insert framebox with parameters WIDTH and POSITION (clr)."
1755 (insert "\\framebox[" width "][" position "]{" )
1758 (defun cal-tex-e-framebox ()
1759 "Insert end of framebox."
1762 (cal-tex-comment "end framebox"))
1765 (defun cal-tex-b-makebox (width position)
1766 "Insert makebox with parameters WIDTH and POSITION (clr)."
1767 (insert "\\makebox[" width "][" position "]{" )
1770 (defun cal-tex-e-makebox ()
1771 "Insert end of makebox."
1774 (cal-tex-comment "end makebox"))
1777 (defun cal-tex-rule (lower width height)
1778 "Insert a rule with parameters LOWER WIDTH HEIGHT."
1779 (insert "\\rule[" lower "]{" width "}{" height "}"))
1785 (defun cal-tex-em (string)
1786 "Insert STRING in italic font."
1787 (insert "\\textit{" string "}"))
1789 (defun cal-tex-bf (string)
1790 "Insert STRING in bf font."
1791 (insert "\\textbf{ " string "}"))
1793 (defun cal-tex-scriptsize (string)
1794 "Insert STRING in scriptsize font."
1795 (insert "{\\scriptsize " string "}"))
1797 (defun cal-tex-huge (string)
1798 "Insert STRING in huge font."
1799 (insert "{\\huge " string "}"))
1801 (defun cal-tex-Huge (string)
1802 "Insert STRING in Huge font."
1803 (insert "{\\Huge " string "}"))
1805 (defun cal-tex-Huge-bf (string)
1806 "Insert STRING in Huge bf font."
1807 (insert "\\textbf{\\Huge " string "}"))
1809 (defun cal-tex-large (string)
1810 "Insert STRING in large font."
1811 (insert "{\\large " string "}"))
1813 (defun cal-tex-large-bf (string)
1814 "Insert STRING in large bf font."
1815 (insert "\\textbf{\\large " string "}"))
1820 ;;; cal-tex.el ends here