1 ;;; cal-tex.el --- calendar functions for printing calendars with LaTeX.
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;; Author: Steve Fisk <fisk@bowdoin.edu>
6 ;; Edward M. Reingold <reingold@cs.uiuc.edu>
8 ;; Human-Keywords: Calendar, LaTeX
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; This collection of functions implements the creation of LaTeX calendars
30 ;; based on the user's holiday choices and diary file.
34 ;; (*) Add holidays and diary entries to daily calendar.
36 ;; (*) Add diary entries to weekly calendar functions.
38 ;; (*) Make calendar styles for A4 paper.
40 ;; (*) Make monthly styles Filofax paper.
46 (autoload 'list-diary-entries "diary-lib" nil t)
47 (autoload 'calendar-holiday-list "holidays" nil t)
48 (autoload 'calendar-iso-from-absolute "cal-iso" nil t)
51 ;;; Customizable variables
54 (defcustom cal-tex-which-days '(0 1 2 3 4 5 6)
55 "*The days of the week that are displayed on the portrait monthly calendar.
56 Sunday is 0, Monday is 1, and so on. The default is to print from Sunday to
57 Saturday. For example, use
59 (setq cal-tex-which-days '(1 3 5))
61 to only print Monday, Wednesday, Friday."
62 :type '(repeat integer)
65 (defcustom cal-tex-holidays t
66 "*If t (default), then the holidays are also printed.
67 If finding the holidays is too slow, set this to nil."
71 (defcustom cal-tex-diary nil
72 "*If t, the diary entries are printed in the calendar."
76 (defcustom cal-tex-daily-string
77 '(let* ((year (extract-calendar-year date))
78 (day (calendar-day-number date))
79 (days-remaining (- (calendar-day-number (list 12 31 year)) day)))
80 (format "%d/%d" day days-remaining))
81 "*An expression in the variable `date' whose value is placed on date.
82 The string resulting from evaluating this expression is placed at the bottom
83 center of `date' on the monthly calendar, next to the date in the weekly
84 calendars, and in the top center of daily calendars.
86 Default is ordinal day number of the year and the number of days remaining.
87 As an example of what you do, setting this to
91 (calendar-hebrew-date-string date))
93 will put the Hebrew date at the bottom of each day."
97 (defcustom cal-tex-buffer "calendar.tex"
98 "*The name for the tex-ed calendar."
100 :group 'calendar-tex)
102 (defcustom cal-tex-24 nil
103 "*If t, use a 24 hour clock in the daily calendar."
105 :group 'calendar-tex)
107 (defcustom cal-tex-daily-start 8
108 "*The first hour of the daily calendar page."
110 :group 'calendar-tex)
112 (defcustom cal-tex-daily-end 20
113 "*The last hour of the daily calendar page."
115 :group 'calendar-tex)
118 ;;; Definitions for LaTeX code
121 (defvar cal-tex-day-prefix "\\caldate{%s}{%s}"
122 "The initial LaTeX code for a day.
123 The holidays, diary entries, bottom string, and the text follow.")
125 (defvar cal-tex-day-name-format "\\myday{%s}%%"
126 "The format for LaTeX code for a day name. The names are taken from
127 calendar-day-name-array.")
129 (defvar cal-tex-cal-one-month
130 "\\def\\calmonth#1#2%
132 \\Huge\\bf\\uppercase{#1} #2 \\\\[1cm]%
137 "LaTeX code for the month header")
139 (defvar cal-tex-cal-multi-month
140 "\\def\\calmonth#1#2#3#4%
142 \\Huge\\bf #1 #2---#3 #4\\\\[1cm]%
147 "LaTeX code for the month header")
149 (defvar cal-tex-myday
150 "\\renewcommand{\\myday}[1]%
151 {\\makebox[\\cellwidth]{\\hfill\\large\\bf#1\\hfill}}
154 "LaTeX code for a day heading")
156 (defvar cal-tex-caldate
158 \\long\\def\\caldate#1#2#3#4#5#6{%
159 \\fbox{\\hbox to\\cellwidth{%
160 \\vbox to\\cellheight{%
161 \\hbox to\\cellwidth{%
162 {\\hspace*{1mm}\\Large \\bf \\strut #2}\\hspace{.05\\cellwidth}%
163 \\raisebox{\\holidaymult\\cellheight}%
164 {\\parbox[t]{.75\\cellwidth}{\\tiny \\raggedright #4}}}
165 \\hbox to\\cellwidth{%
166 \\hspace*{1mm}\\parbox{.95\\cellwidth}{\\tiny \\raggedright #3}}
168 \\hbox to\\cellwidth{#6}%
170 \\hbox to\\cellwidth{\\hfill \\tiny #5 \\hfill}%
174 "LaTeX code to insert one box with date info in calendar.
175 This definition is the heart of the calendar!")
177 (defun cal-tex-list-holidays (d1 d2)
178 "Generate a list of all holidays from absolute date D1 to D2."
179 (let* ((start (calendar-gregorian-from-absolute d1))
180 (displayed-month (extract-calendar-month start))
181 (displayed-year (extract-calendar-year start))
182 (end (calendar-gregorian-from-absolute d2))
183 (end-month (extract-calendar-month end))
184 (end-year (extract-calendar-year end))
186 (1+ (/ (calendar-interval displayed-month displayed-year
191 (increment-calendar-month displayed-month displayed-year 1)
192 (calendar-for-loop i from 1 to number-of-intervals do
193 (setq holidays (append holidays (calendar-holiday-list)))
194 (increment-calendar-month displayed-month displayed-year 3))
196 (and (car (car holidays))
197 (let ((a (calendar-absolute-from-gregorian (car (car holidays)))))
198 (and (<= d1 a) (<= a d2)))
199 (setq in-range (append (list (car holidays)) in-range)))
200 (setq holidays (cdr holidays)))
203 (defun cal-tex-list-diary-entries (d1 d2)
204 "Generate a list of all diary-entries from absolute date D1 to D2."
205 (let ((diary-list-include-blanks nil)
206 (diary-display-hook nil))
208 (calendar-gregorian-from-absolute d1)
211 (defun cal-tex-preamble (&optional args)
212 "Insert the LaTeX preamble.
213 Preamble Includes initial definitions for various LaTeX commands.
214 Optional ARGS are included."
215 (set-buffer (get-buffer-create cal-tex-buffer))
217 (insert "\\documentstyle")
219 (insert "[" args "]"))
220 (insert "{article}\n"
227 \\evensidemargin -2cm
232 \\newlength{\\cellwidth}
233 \\newlength{\\cellheight}
234 \\newlength{\\boxwidth}
235 \\newlength{\\boxheight}
236 \\newlength{\\cellsize}
237 \\newcommand{\\myday}[1]{}
238 \\newcommand{\\caldate}[6]{}
239 \\newcommand{\\nocaldate}[6]{}
240 \\newcommand{\\calsmall}[6]{}
248 (defun cal-tex-cursor-year (&optional arg)
249 "Make a buffer with LaTeX commands for the year cursor is on.
250 Optional prefix argument specifies number of years."
252 (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
255 (defun cal-tex-cursor-year-landscape (&optional arg)
256 "Make a buffer with LaTeX commands for the year cursor is on.
257 Optional prefix argument specifies number of years."
259 (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
263 (defun cal-tex-year (year n &optional landscape)
264 "Make a one page yearly calendar of YEAR; do this for N years.
265 There are four rows of three months each, unless optional LANDSCAPE is t,
266 in which case the calendar isprinted in landscape mode with three rows of
268 (cal-tex-insert-preamble 1 landscape "12pt")
270 (cal-tex-vspace "-.6cm")
271 (cal-tex-vspace "-3.1cm"))
272 (calendar-for-loop j from 1 to n do
273 (insert "\\vfill%\n")
275 (cal-tex-Huge (number-to-string year))
277 (cal-tex-vspace "1cm")
279 (cal-tex-b-parbox "l" (if landscape "5.9in" "4.3in"))
283 (calendar-for-loop i from 1 to 12 do
284 (insert (cal-tex-mini-calendar i year "month" "1.1in" "1in"))
286 (cal-tex-hspace "0.5in")
287 (if (zerop (mod i (if landscape 4 3)))
288 (cal-tex-nl "0.5in")))
291 (insert "\\vfill%\n")
292 (setq year (1+ year))
295 (cal-tex-end-document))
296 (run-hooks 'cal-tex-year-hook))
297 (run-hooks 'cal-tex-hook))
299 (defun cal-tex-cursor-filofax-year (&optional arg)
300 "Make a Filofax one page yearly calendar of year indicated by cursor.
301 Optional parameter specifies number of years."
303 (let* ((n (if arg arg 1))
304 (year (extract-calendar-year (calendar-cursor-to-date t))))
305 (cal-tex-preamble "twoside")
306 (cal-tex-cmd "\\textwidth 3.25in")
307 (cal-tex-cmd "\\textheight 6.5in")
308 (cal-tex-cmd "\\oddsidemargin 1.675in")
309 (cal-tex-cmd "\\evensidemargin 1.675in")
310 (cal-tex-cmd "\\topmargin 0pt")
311 (cal-tex-cmd "\\headheight -0.875in")
312 (cal-tex-cmd "\\fboxsep 0.5mm")
313 (cal-tex-cmd "\\pagestyle{empty}")
315 (cal-tex-cmd "\\vspace*{0.25in}")
316 (calendar-for-loop j from 1 to n do
317 (insert (format "\\hfil {\\Large \\bf %s} \\hfil\\\\\n" year))
319 (cal-tex-b-parbox "l" "\\textwidth")
323 (calendar-for-loop i from 1 to 12 do
324 (insert (cal-tex-mini-calendar i year
325 (calendar-month-name i)
326 "1in" ".9in" "tiny" "0.6mm")))
328 "\\noindent\\fbox{\\January}\\fbox{\\February}\\fbox{\\March}\\\\
329 \\noindent\\fbox{\\April}\\fbox{\\May}\\fbox{\\June}\\\\
330 \\noindent\\fbox{\\July}\\fbox{\\August}\\fbox{\\September}\\\\
331 \\noindent\\fbox{\\October}\\fbox{\\November}\\fbox{\\December}
335 (setq year (1+ year))
337 (cal-tex-end-document)
339 (cal-tex-cmd "\\vspace*{0.25in}"))
340 (run-hooks 'cal-tex-year-hook))
341 (run-hooks 'cal-tex-hook)))
344 ;;; Monthly calendars
347 (defun cal-tex-cursor-month-landscape (&optional arg)
348 "Make a buffer with LaTeX commands for the month cursor is on.
349 Optional prefix argument specifies number of months to be produced.
350 The output is in landscape format, one month to a page."
352 (let* ((n (if arg arg 1))
353 (date (calendar-cursor-to-date t))
354 (month (extract-calendar-month date))
355 (year (extract-calendar-year date))
358 (cal-tex-which-days '(0 1 2 3 4 5 6)))
359 (increment-calendar-month end-month end-year (1- n))
360 (let ((diary-list (if cal-tex-diary
361 (cal-tex-list-diary-entries
362 (calendar-absolute-from-gregorian
364 (calendar-absolute-from-gregorian
366 (calendar-last-day-of-month
369 (holidays (if cal-tex-holidays
370 (cal-tex-list-holidays
371 (calendar-absolute-from-gregorian
373 (calendar-absolute-from-gregorian
375 (calendar-last-day-of-month end-month end-year)
379 (small-months-at-start))
380 (cal-tex-insert-preamble (cal-tex-number-weeks month year 1) t "12pt")
381 (cal-tex-cmd cal-tex-cal-one-month)
382 (calendar-for-loop i from 1 to n do
383 (setq other-month month)
384 (setq other-year year)
385 (increment-calendar-month other-month other-year -1)
386 (insert (cal-tex-mini-calendar other-month other-year "lastmonth"
387 "\\cellwidth" "\\cellheight"))
388 (increment-calendar-month other-month other-year 2)
389 (insert (cal-tex-mini-calendar other-month other-year "nextmonth"
390 "\\cellwidth" "\\cellheight"))
391 (cal-tex-insert-month-header 1 month year month year)
392 (cal-tex-insert-day-names)
394 (setq small-months-at-start
395 (< 1 (mod (- (calendar-day-of-week (list month 1 year))
396 calendar-week-start-day)
398 (if small-months-at-start
399 (insert "\\lastmonth\\nextmonth\\hspace*{-2\\cellwidth}"))
400 (cal-tex-insert-blank-days month year cal-tex-day-prefix)
401 (cal-tex-insert-days month year diary-list holidays
403 (cal-tex-insert-blank-days-at-end month year cal-tex-day-prefix)
404 (if (and (not small-months-at-start)
405 (< 1 (mod (- (1- calendar-week-start-day)
406 (calendar-day-of-week
408 (calendar-last-day-of-month month year)
411 (insert "\\vspace*{-\\cellwidth}\\hspace*{-2\\cellwidth}"
412 "\\lastmonth\\nextmonth"))
415 (run-hooks 'cal-tex-month-hook)
417 (increment-calendar-month month year 1)
418 (cal-tex-vspace "-2cm")
419 (cal-tex-insert-preamble
420 (cal-tex-number-weeks month year 1) t "12pt" t))))
421 (cal-tex-end-document)
422 (run-hooks 'cal-tex-hook))))
424 (defun cal-tex-cursor-month (arg)
425 "Make a buffer with LaTeX commands for the month cursor is on.
426 Optional prefix argument specifies number of months to be produced.
427 Calendar is condensed onto one page."
429 (let* ((date (calendar-cursor-to-date t))
430 (month (extract-calendar-month date))
431 (year (extract-calendar-year date))
435 (increment-calendar-month end-month end-year (1- n))
436 (let ((diary-list (if cal-tex-diary
437 (cal-tex-list-diary-entries
438 (calendar-absolute-from-gregorian
440 (calendar-absolute-from-gregorian
442 (calendar-last-day-of-month
445 (holidays (if cal-tex-holidays
446 (cal-tex-list-holidays
447 (calendar-absolute-from-gregorian
449 (calendar-absolute-from-gregorian
451 (calendar-last-day-of-month end-month end-year)
455 (cal-tex-insert-preamble (cal-tex-number-weeks month year n) nil"12pt")
457 (cal-tex-cmd cal-tex-cal-multi-month)
458 (cal-tex-cmd cal-tex-cal-one-month))
459 (cal-tex-insert-month-header n month year end-month end-year)
460 (cal-tex-insert-day-names)
462 (cal-tex-insert-blank-days month year cal-tex-day-prefix)
463 (calendar-for-loop i from 1 to n do
464 (setq other-month month)
465 (setq other-year year)
466 (cal-tex-insert-days month year diary-list holidays
468 (increment-calendar-month month year 1))
469 (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix)
470 (cal-tex-end-document)))
471 (run-hooks 'cal-tex-hook))
473 (defun cal-tex-insert-days (month year diary-list holidays day-format)
474 "Insert LaTeX commands for a range of days in monthly calendars.
475 LaTeX commands are inserted for the days of the MONTH in YEAR.
476 Diary entries on DIARY-LIST are included. Holidays on HOLIDAYS are included.
477 Each day is formatted using format DAY-FORMAT."
478 (let* ((blank-days;; at start of month
480 (- (calendar-day-of-week (list month 1 year))
481 calendar-week-start-day)
484 (last (calendar-last-day-of-month month year)))
485 (calendar-for-loop i from 1 to last do
486 (setq date (list month i year))
487 (if (memq (calendar-day-of-week date) cal-tex-which-days)
489 (insert (format day-format (calendar-month-name month) i))
490 (cal-tex-arg (cal-tex-latexify-list diary-list date))
491 (cal-tex-arg (cal-tex-latexify-list holidays date))
492 (cal-tex-arg (eval cal-tex-daily-string))
495 (if (and (zerop (mod (+ i blank-days) 7))
501 (defun cal-tex-insert-day-names ()
502 "Insert the names of the days at top of a monthly calendar."
503 (calendar-for-loop i from 0 to 6 do
504 (if (memq i cal-tex-which-days)
505 (insert (format cal-tex-day-name-format
506 (aref calendar-day-name-array
507 (mod (+ calendar-week-start-day i) 7)))))
510 (defun cal-tex-insert-month-header (n month year end-month end-year)
511 "Create a title for a calendar.
512 A title is inserted for a calendar with N months starting with
513 MONTH YEAR and ending with END-MONTH END-YEAR."
514 (let ( (month-name (calendar-month-name month))
515 (end-month-name (calendar-month-name end-month)))
517 (insert (format "\\calmonth{%s}{%s}\n\\vspace*{-0.5cm}"
519 (insert (format "\\calmonth{%s}{%s}{%s}{%s}\n\\vspace*{-0.5cm}"
520 month-name year end-month-name end-year))))
523 (defun cal-tex-insert-blank-days (month year day-format)
524 "Insert code for initial days not in calendar.
525 Insert LaTeX code for the blank days at the beginning of the MONTH in
526 YEAR. The entry is formatted using DAY-FORMAT. If the entire week is
527 blank, no days are inserted."
528 (if (cal-tex-first-blank-p month year)
529 (let* ((blank-days;; at start of month
531 (- (calendar-day-of-week (list month 1 year))
532 calendar-week-start-day)
534 (calendar-for-loop i from 0 to (1- blank-days) do
535 (if (memq i cal-tex-which-days)
536 (insert (format day-format " " " ") "{}{}{}{}%\n"))))))
538 (defun cal-tex-insert-blank-days-at-end (month year day-format)
539 "Insert code for final days not in calendar.
540 Insert LaTeX code for the blank days at the end of the MONTH in YEAR.
541 The entry is formatted using DAY-FORMAT."
542 (if (cal-tex-last-blank-p month year)
543 (let* ((last-day (calendar-last-day-of-month month year))
544 (blank-days;; at end of month
546 (- (calendar-day-of-week (list month last-day year))
547 calendar-week-start-day)
549 (calendar-for-loop i from (1+ blank-days) to 6 do
550 (if (memq i cal-tex-which-days)
551 (insert (format day-format "" "") "{}{}{}{}%\n"))))))
553 (defun cal-tex-first-blank-p (month year)
554 "Determine if any days of the first week will be printed.
555 Return t if there will there be any days of the first week printed
556 in the calendar starting in MONTH YEAR."
558 (the-saturday)) ;the day of week of 1st Saturday
559 (calendar-for-loop i from 1 to 7 do
560 (if (= 6 (calendar-day-of-week (list month i year)))
561 (setq the-saturday i)))
562 (calendar-for-loop i from 1 to the-saturday do
563 (if (memq (calendar-day-of-week (list month i year))
568 (defun cal-tex-last-blank-p (month year)
569 "Determine if any days of the last week will be printed.
570 Return t if there will there be any days of the last week printed
571 in the calendar starting in MONTH YEAR."
573 (last-day (calendar-last-day-of-month month year))
574 (the-sunday)) ;the day of week of last Sunday
575 (calendar-for-loop i from (- last-day 6) to last-day do
576 (if (= 0 (calendar-day-of-week (list month i year)))
577 (setq the-sunday i)))
578 (calendar-for-loop i from the-sunday to last-day do
579 (if (memq (calendar-day-of-week (list month i year))
584 (defun cal-tex-number-weeks (month year n)
585 "Determine the number of weeks in a range of dates.
586 Compute the number of weeks in the calendar starting with MONTH and YEAR,
587 and lasting N months, including only the days in WHICH-DAYS. As it stands,
588 this is only an upper bound."
589 (let ((d (list month 1 year)))
590 (increment-calendar-month month year (1- n))
591 (/ (- (calendar-dayname-on-or-before
592 calendar-week-start-day
593 (+ 7 (calendar-absolute-from-gregorian
594 (list month (calendar-last-day-of-month month year) year))))
595 (calendar-dayname-on-or-before
596 calendar-week-start-day
597 (calendar-absolute-from-gregorian d)))
604 (defun cal-tex-cursor-week (&optional arg)
605 "Make a buffer with LaTeX commands for a two-page one-week calendar.
606 It applies to the week that point is in.
607 Optional prefix argument specifies number of weeks.
608 Holidays are included if `cal-tex-holidays' is t."
610 (let* ((n (if arg arg 1))
611 (date (calendar-gregorian-from-absolute
612 (calendar-dayname-on-or-before
613 calendar-week-start-day
614 (calendar-absolute-from-gregorian
615 (calendar-cursor-to-date t)))))
616 (month (extract-calendar-month date))
617 (year (extract-calendar-year date))
618 (holidays (if cal-tex-holidays
619 (cal-tex-list-holidays
620 (calendar-absolute-from-gregorian date)
622 (calendar-absolute-from-gregorian date))))))
623 (cal-tex-preamble "11pt")
624 (cal-tex-cmd "\\textwidth 6.5in")
625 (cal-tex-cmd "\\textheight 10.5in")
626 (cal-tex-cmd "\\oddsidemargin 0in")
627 (cal-tex-cmd "\\evensidemargin 0in")
628 (insert cal-tex-LaTeX-hourbox)
630 (cal-tex-cmd "\\pagestyle{empty}")
631 (calendar-for-loop i from 1 to n do
632 (cal-tex-vspace "-1.5in")
634 (cal-tex-Huge-bf (format "\\uppercase{%s}"
635 (calendar-month-name month)))
636 (cal-tex-hspace "2em")
637 (cal-tex-Huge-bf (number-to-string year))
640 (cal-tex-hspace "-.2in")
641 (cal-tex-b-parbox "l" "7in")
642 (calendar-for-loop j from 1 to 7 do
643 (cal-tex-week-hours date holidays "3.1")
644 (setq date (cal-tex-incr-date date)))
646 (setq month (extract-calendar-month date))
647 (setq year (extract-calendar-year date))
650 (run-hooks 'cal-tex-week-hook)
652 (cal-tex-end-document)
653 (run-hooks 'cal-tex-hook)))
655 (defun cal-tex-cursor-week2 (&optional arg)
656 "Make a buffer with LaTeX commands for a two-page one-week calendar.
657 It applies to the week that point is in.
658 Optional prefix argument specifies number of weeks.
659 Holidays are included if `cal-tex-holidays' is t."
661 (let* ((n (if arg arg 1))
662 (date (calendar-gregorian-from-absolute
663 (calendar-dayname-on-or-before
664 calendar-week-start-day
665 (calendar-absolute-from-gregorian
666 (calendar-cursor-to-date t)))))
667 (month (extract-calendar-month date))
668 (year (extract-calendar-year date))
670 (holidays (if cal-tex-holidays
671 (cal-tex-list-holidays
672 (calendar-absolute-from-gregorian date)
674 (calendar-absolute-from-gregorian date))))))
675 (cal-tex-preamble "12pt")
676 (cal-tex-cmd "\\textwidth 6.5in")
677 (cal-tex-cmd "\\textheight 10.5in")
678 (cal-tex-cmd "\\oddsidemargin 0in")
679 (cal-tex-cmd "\\evensidemargin 0in")
680 (insert cal-tex-LaTeX-hourbox)
682 (cal-tex-cmd "\\pagestyle{empty}")
683 (calendar-for-loop i from 1 to n do
684 (cal-tex-vspace "-1.5in")
686 (cal-tex-Huge-bf (format "\\uppercase{%s}"
687 (calendar-month-name month)))
688 (cal-tex-hspace "2em")
689 (cal-tex-Huge-bf (number-to-string year))
692 (cal-tex-hspace "-.2in")
693 (cal-tex-b-parbox "l" "\\textwidth")
694 (calendar-for-loop j from 1 to 3 do
695 (cal-tex-week-hours date holidays "5")
696 (setq date (cal-tex-incr-date date)))
699 (insert (cal-tex-mini-calendar
700 (extract-calendar-month (cal-tex-previous-month date))
701 (extract-calendar-year (cal-tex-previous-month date))
702 "lastmonth" "1.1in" "1in"))
703 (insert (cal-tex-mini-calendar
704 (extract-calendar-month date)
705 (extract-calendar-year date)
706 "thismonth" "1.1in" "1in"))
707 (insert (cal-tex-mini-calendar
708 (extract-calendar-month (cal-tex-next-month date))
709 (extract-calendar-year (cal-tex-next-month date))
710 "nextmonth" "1.1in" "1in"))
711 (insert "\\hbox to \\textwidth{")
713 (insert "\\lastmonth")
715 (insert "\\thismonth")
717 (insert "\\nextmonth")
721 (cal-tex-b-parbox "l" "\\textwidth")
722 (calendar-for-loop j from 4 to 7 do
723 (cal-tex-week-hours date holidays "5")
724 (setq date (cal-tex-incr-date date)))
726 (setq month (extract-calendar-month date))
727 (setq year (extract-calendar-year date))
730 (run-hooks 'cal-tex-week-hook)
732 (cal-tex-end-document)
733 (run-hooks 'cal-tex-hook)))
735 (defun cal-tex-cursor-week-iso (&optional arg)
736 "Make a buffer with LaTeX commands for a one page ISO-style weekly calendar.
737 Optional prefix argument specifies number of weeks.
738 Diary entries are included if `cal-tex-diary' is t.
739 Holidays are included if `cal-tex-holidays' is t."
741 (let* ((n (if arg arg 1))
742 (date (calendar-gregorian-from-absolute
743 (calendar-dayname-on-or-before
745 (calendar-absolute-from-gregorian
746 (calendar-cursor-to-date t)))))
747 (month (extract-calendar-month date))
748 (year (extract-calendar-year date))
749 (day (extract-calendar-day date))
750 (holidays (if cal-tex-holidays
751 (cal-tex-list-holidays
752 (calendar-absolute-from-gregorian date)
754 (calendar-absolute-from-gregorian date)))))
755 (diary-list (if cal-tex-diary
756 (cal-tex-list-diary-entries
757 (calendar-absolute-from-gregorian
760 (calendar-absolute-from-gregorian date))))))
761 (cal-tex-preamble "11pt")
762 (cal-tex-cmd "\\textwidth 6.5in")
763 (cal-tex-cmd "\\textheight 10.5in")
764 (cal-tex-cmd "\\oddsidemargin 0in")
765 (cal-tex-cmd "\\evensidemargin 0in")
767 (cal-tex-cmd "\\pagestyle{empty}")
768 (calendar-for-loop i from 1 to n do
769 (cal-tex-vspace "-1.5in")
772 (let* ((d (calendar-iso-from-absolute
773 (calendar-absolute-from-gregorian date))))
774 (format "Week %d of %d"
775 (extract-calendar-month d)
776 (extract-calendar-year d))))
779 (cal-tex-b-parbox "l" "\\textwidth")
780 (calendar-for-loop j from 1 to 7 do
781 (cal-tex-b-parbox "t" "\\textwidth")
782 (cal-tex-b-parbox "t" "\\textwidth")
783 (cal-tex-rule "0pt" "\\textwidth" ".2mm")
785 (cal-tex-b-parbox "t" "\\textwidth")
786 (cal-tex-large-bf (calendar-day-name date))
788 (cal-tex-large-bf (calendar-month-name month))
790 (cal-tex-large-bf (number-to-string day))
791 (if (not (string= "" (cal-tex-latexify-list holidays date)))
794 (cal-tex-large-bf (cal-tex-latexify-list holidays date "; "))))
796 (insert " " (eval cal-tex-daily-string))
800 (cal-tex-b-parbox "t" "\\textwidth")
801 (if (not (string= "" (cal-tex-latexify-list diary-list date)))
803 (insert "\\vbox to 0pt{")
805 (cal-tex-latexify-list diary-list date))
809 (setq date (cal-tex-incr-date date))
810 (setq month (extract-calendar-month date))
811 (setq day (extract-calendar-day date))
813 (cal-tex-e-parbox "2cm")
815 (setq month (extract-calendar-month date))
816 (setq year (extract-calendar-year date)))
820 (run-hooks 'cal-tex-week-hook)
822 (cal-tex-end-document)
823 (run-hooks 'cal-tex-hook)))
825 (defvar cal-tex-LaTeX-hourbox
826 "\\newcommand{\\hourbox}[2]%
827 {\\makebox[2em]{\\rule{0cm}{#2ex}#1}\\rule{3in}{.15mm}}\n"
828 "One hour and a line on the right.")
830 (defun cal-tex-week-hours (date holidays height)
831 "Insert hourly entries for DATE with HOLIDAYS, with line height HEIGHT."
832 (let ((month (extract-calendar-month date))
833 (day (extract-calendar-day date))
834 (year (extract-calendar-year date))
836 (cal-tex-comment "begin cal-tex-week-hours")
837 (cal-tex-cmd "\\ \\\\[-.2cm]")
838 (cal-tex-cmd "\\noindent")
839 (cal-tex-b-parbox "l" "6.8in")
840 (cal-tex-large-bf (calendar-day-name date))
842 (cal-tex-large-bf (calendar-month-name month))
844 (cal-tex-large-bf (number-to-string day))
845 (if (not (string= "" (cal-tex-latexify-list holidays date)))
848 (cal-tex-large-bf (cal-tex-latexify-list holidays date "; "))))
850 (insert " " (eval cal-tex-daily-string))
853 (cal-tex-rule "0pt" "6.8in" ".2mm")
855 (calendar-for-loop i from 8 to 12 do
857 (setq afternoon (+ i 5))
858 (setq afternoon (- i 7)))
859 (cal-tex-cmd "\\hourbox" (number-to-string i))
861 (cal-tex-hspace ".4cm")
862 (cal-tex-cmd "\\hourbox" (number-to-string afternoon))
866 (defun cal-tex-cursor-week-monday (&optional arg)
867 "Make a buffer with LaTeX commands for a two-page one-week calendar.
868 It applies to the week that point is in, and starts on Monday.
869 Optional prefix argument specifies number of weeks.
870 Holidays are included if `cal-tex-holidays' is t."
872 (let* ((n (if arg arg 1))
873 (date (calendar-gregorian-from-absolute
874 (calendar-dayname-on-or-before
876 (calendar-absolute-from-gregorian
877 (calendar-cursor-to-date t))))))
878 (cal-tex-preamble "11pt")
879 (cal-tex-cmd "\\textwidth 6.5in")
880 (cal-tex-cmd "\\textheight 10.5in")
881 (cal-tex-cmd "\\oddsidemargin 0in")
882 (cal-tex-cmd "\\evensidemargin 0in")
884 (calendar-for-loop i from 1 to n do
885 (cal-tex-vspace "-1cm")
886 (insert "\\noindent ")
887 (cal-tex-weekly4-box (cal-tex-incr-date date) nil)
888 (cal-tex-weekly4-box (cal-tex-incr-date date 4) nil)
890 (cal-tex-weekly4-box (cal-tex-incr-date date 2) nil)
891 (cal-tex-weekly4-box (cal-tex-incr-date date 5) nil)
893 (cal-tex-weekly4-box (cal-tex-incr-date date 3) nil)
894 (cal-tex-weekly4-box (cal-tex-incr-date date 6) t)
897 (run-hooks 'cal-tex-week-hook)
898 (setq date (cal-tex-incr-date date 7))
900 (cal-tex-end-document)
901 (run-hooks 'cal-tex-hook)))
903 (defun cal-tex-weekly4-box (date weekend)
904 "Make one box for DATE, different if WEEKEND."
906 (day (extract-calendar-day date))
907 (month (extract-calendar-month date))
908 (year (extract-calendar-year date))
909 (dayname (calendar-day-name date))
910 (date1 (cal-tex-incr-date date))
911 (day1 (extract-calendar-day date1))
912 (month1 (extract-calendar-month date1))
913 (year1 (extract-calendar-year date1))
914 (dayname1 (calendar-day-name date1))
916 (cal-tex-b-framebox "8cm" "l")
917 (cal-tex-b-parbox "b" "7.5cm")
918 (insert (format "{\\Large\\bf %s,} %s/%s/%s\\\\\n" dayname month day year))
919 (cal-tex-rule "0pt" "7.5cm" ".5mm")
923 (calendar-for-loop i from 8 to 12 do
924 (insert (format "{\\large\\sf %d}\\\\\n" i)))
925 (calendar-for-loop i from 1 to 5 do
926 (insert (format "{\\large\\sf %d}\\\\\n" i)))))
930 (cal-tex-vspace "1cm")
931 (insert "\\ \\vfill")
932 (insert (format "{\\Large\\bf %s,} %s/%s/%s\\\\\n"
933 dayname1 month1 day1 year1))
934 (cal-tex-rule "0pt" "7.5cm" ".5mm")
936 (cal-tex-vspace "1cm")))
939 (cal-tex-hspace "1cm")))
941 (defun cal-tex-cursor-filofax-2week (&optional arg)
942 "Two-weeks-at-a-glance Filofax style calendar for week indicated by cursor.
943 Optional prefix argument specifies number of weeks.
944 Diary entries are included if `cal-tex-diary' is t.
945 Holidays are included if `cal-tex-holidays' is t."
947 (let* ((n (if arg arg 1))
948 (date (calendar-gregorian-from-absolute
949 (calendar-dayname-on-or-before
950 calendar-week-start-day
951 (calendar-absolute-from-gregorian
952 (calendar-cursor-to-date t)))))
953 (month (extract-calendar-month date))
954 (year (extract-calendar-year date))
955 (day (extract-calendar-day date))
956 (holidays (if cal-tex-holidays
957 (cal-tex-list-holidays
958 (calendar-absolute-from-gregorian date)
960 (calendar-absolute-from-gregorian date)))))
961 (diary-list (if cal-tex-diary
962 (cal-tex-list-diary-entries
963 (calendar-absolute-from-gregorian
966 (calendar-absolute-from-gregorian date))))))
967 (cal-tex-preamble "twoside")
968 (cal-tex-cmd "\\textwidth 3.25in")
969 (cal-tex-cmd "\\textheight 6.5in")
970 (cal-tex-cmd "\\oddsidemargin 1.75in")
971 (cal-tex-cmd "\\evensidemargin 1.5in")
972 (cal-tex-cmd "\\topmargin 0pt")
973 (cal-tex-cmd "\\headheight -0.875in")
974 (cal-tex-cmd "\\headsep 0.125in")
975 (cal-tex-cmd "\\footskip .125in")
976 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
977 \\long\\def\\rightday#1#2#3#4#5{%
978 \\rule{\\textwidth}{0.3pt}\\\\%
979 \\hbox to \\textwidth{%
982 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
983 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
984 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
985 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
986 \\long\\def\\leftday#1#2#3#4#5{%
987 \\rule{\\textwidth}{0.3pt}\\\\%
988 \\hbox to \\textwidth{%
991 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
992 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
993 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
996 (cal-tex-cmd "\\pagestyle{empty}")
997 (calendar-for-loop i from 1 to n do
999 (insert "\\righthead")
1000 (insert "\\lefthead"))
1002 (let ((d (cal-tex-incr-date date 6)))
1003 (if (= (extract-calendar-month date)
1004 (extract-calendar-month d))
1006 (calendar-month-name
1007 (extract-calendar-month date))
1008 (extract-calendar-year date))
1009 (if (= (extract-calendar-year date)
1010 (extract-calendar-year d))
1011 (format "%s---%s %s"
1012 (calendar-month-name
1013 (extract-calendar-month date))
1014 (calendar-month-name
1015 (extract-calendar-month d))
1016 (extract-calendar-year date))
1017 (format "%s %s---%s %s"
1018 (calendar-month-name
1019 (extract-calendar-month date))
1020 (extract-calendar-year date)
1021 (calendar-month-name (extract-calendar-month d))
1022 (extract-calendar-year d))))))
1024 (calendar-for-loop j from 1 to 7 do
1026 (insert "\\rightday")
1027 (insert "\\leftday"))
1028 (cal-tex-arg (calendar-day-name date))
1029 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1030 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1031 (cal-tex-arg (cal-tex-latexify-list holidays date))
1032 (cal-tex-arg (eval cal-tex-daily-string))
1034 (setq date (cal-tex-incr-date date)))
1037 (run-hooks 'cal-tex-week-hook)
1038 (cal-tex-newpage))))
1039 (cal-tex-end-document)
1040 (run-hooks 'cal-tex-hook)))
1042 (defun cal-tex-cursor-filofax-week (&optional arg)
1043 "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
1044 Optional prefix argument specifies number of weeks.
1045 Weeks start on Monday.
1046 Diary entries are included if `cal-tex-diary' is t.
1047 Holidays are included if `cal-tex-holidays' is t."
1049 (let* ((n (if arg arg 1))
1050 (date (calendar-gregorian-from-absolute
1051 (calendar-dayname-on-or-before
1053 (calendar-absolute-from-gregorian
1054 (calendar-cursor-to-date t)))))
1055 (month (extract-calendar-month date))
1056 (year (extract-calendar-year date))
1057 (day (extract-calendar-day date))
1058 (holidays (if cal-tex-holidays
1059 (cal-tex-list-holidays
1060 (calendar-absolute-from-gregorian date)
1062 (calendar-absolute-from-gregorian date)))))
1063 (diary-list (if cal-tex-diary
1064 (cal-tex-list-diary-entries
1065 (calendar-absolute-from-gregorian
1066 (list month 1 year))
1068 (calendar-absolute-from-gregorian date))))))
1069 (cal-tex-preamble "twoside")
1070 (cal-tex-cmd "\\textwidth 3.25in")
1071 (cal-tex-cmd "\\textheight 6.5in")
1072 (cal-tex-cmd "\\oddsidemargin 1.75in")
1073 (cal-tex-cmd "\\evensidemargin 1.5in")
1074 (cal-tex-cmd "\\topmargin 0pt")
1075 (cal-tex-cmd "\\headheight -0.875in")
1076 (cal-tex-cmd "\\headsep 0.125in")
1077 (cal-tex-cmd "\\footskip .125in")
1078 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1079 \\long\\def\\rightday#1#2#3#4#5{%
1080 \\rule{\\textwidth}{0.3pt}\\\\%
1081 \\hbox to \\textwidth{%
1084 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1085 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1086 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1087 \\long\\def\\weekend#1#2#3#4#5{%
1088 \\rule{\\textwidth}{0.3pt}\\\\%
1089 \\hbox to \\textwidth{%
1092 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1093 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1094 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1095 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1096 \\long\\def\\leftday#1#2#3#4#5{%
1097 \\rule{\\textwidth}{0.3pt}\\\\%
1098 \\hbox to \\textwidth{%
1101 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1102 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1103 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1105 (cal-tex-b-document)
1106 (cal-tex-cmd "\\pagestyle{empty}\\ ")
1108 (calendar-for-loop i from 1 to n do
1109 (insert "\\lefthead")
1111 (let ((d (cal-tex-incr-date date 2)))
1112 (if (= (extract-calendar-month date)
1113 (extract-calendar-month d))
1115 (calendar-month-name
1116 (extract-calendar-month date))
1117 (extract-calendar-year date))
1118 (if (= (extract-calendar-year date)
1119 (extract-calendar-year d))
1120 (format "%s---%s %s"
1121 (calendar-month-name
1122 (extract-calendar-month date))
1123 (calendar-month-name
1124 (extract-calendar-month d))
1125 (extract-calendar-year date))
1126 (format "%s %s---%s %s"
1127 (calendar-month-name
1128 (extract-calendar-month date))
1129 (extract-calendar-year date)
1130 (calendar-month-name (extract-calendar-month d))
1131 (extract-calendar-year d))))))
1133 (calendar-for-loop j from 1 to 3 do
1134 (insert "\\leftday")
1135 (cal-tex-arg (calendar-day-name date))
1136 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1137 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1138 (cal-tex-arg (cal-tex-latexify-list holidays date))
1139 (cal-tex-arg (eval cal-tex-daily-string))
1141 (setq date (cal-tex-incr-date date)))
1142 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1144 (insert "\\righthead")
1146 (let ((d (cal-tex-incr-date date 3)))
1147 (if (= (extract-calendar-month date)
1148 (extract-calendar-month d))
1150 (calendar-month-name
1151 (extract-calendar-month date))
1152 (extract-calendar-year date))
1153 (if (= (extract-calendar-year date)
1154 (extract-calendar-year d))
1155 (format "%s---%s %s"
1156 (calendar-month-name
1157 (extract-calendar-month date))
1158 (calendar-month-name
1159 (extract-calendar-month d))
1160 (extract-calendar-year date))
1161 (format "%s %s---%s %s"
1162 (calendar-month-name
1163 (extract-calendar-month date))
1164 (extract-calendar-year date)
1165 (calendar-month-name (extract-calendar-month d))
1166 (extract-calendar-year d))))))
1168 (calendar-for-loop j from 1 to 2 do
1169 (insert "\\rightday")
1170 (cal-tex-arg (calendar-day-name date))
1171 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1172 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1173 (cal-tex-arg (cal-tex-latexify-list holidays date))
1174 (cal-tex-arg (eval cal-tex-daily-string))
1176 (setq date (cal-tex-incr-date date)))
1177 (calendar-for-loop j from 1 to 2 do
1178 (insert "\\weekend")
1179 (cal-tex-arg (calendar-day-name date))
1180 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1181 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1182 (cal-tex-arg (cal-tex-latexify-list holidays date))
1183 (cal-tex-arg (eval cal-tex-daily-string))
1185 (setq date (cal-tex-incr-date date)))
1188 (run-hooks 'cal-tex-week-hook)
1189 (cal-tex-newpage))))
1190 (cal-tex-end-document)
1191 (run-hooks 'cal-tex-hook)))
1193 (defun cal-tex-cursor-filofax-daily (&optional arg)
1194 "Day-per-page Filofax style calendar for week indicated by cursor.
1195 Optional prefix argument specifies number of weeks. Weeks start on Monday.
1196 Diary entries are included if `cal-tex-diary' is t.
1197 Holidays are included if `cal-tex-holidays' is t."
1199 (let* ((n (if arg arg 1))
1200 (date (calendar-gregorian-from-absolute
1201 (calendar-dayname-on-or-before
1203 (calendar-absolute-from-gregorian
1204 (calendar-cursor-to-date t)))))
1205 (month (extract-calendar-month date))
1206 (year (extract-calendar-year date))
1207 (day (extract-calendar-day date))
1208 (holidays (if cal-tex-holidays
1209 (cal-tex-list-holidays
1210 (calendar-absolute-from-gregorian date)
1212 (calendar-absolute-from-gregorian date)))))
1213 (diary-list (if cal-tex-diary
1214 (cal-tex-list-diary-entries
1215 (calendar-absolute-from-gregorian
1216 (list month 1 year))
1218 (calendar-absolute-from-gregorian date))))))
1219 (cal-tex-preamble "twoside")
1220 (cal-tex-cmd "\\textwidth 3.25in")
1221 (cal-tex-cmd "\\textheight 6.5in")
1222 (cal-tex-cmd "\\oddsidemargin 1.75in")
1223 (cal-tex-cmd "\\evensidemargin 1.5in")
1224 (cal-tex-cmd "\\topmargin 0pt")
1225 (cal-tex-cmd "\\headheight -0.875in")
1226 (cal-tex-cmd "\\headsep 0.125in")
1227 (cal-tex-cmd "\\footskip .125in")
1228 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1229 \\long\\def\\rightday#1#2#3{%
1230 \\rule{\\textwidth}{0.3pt}\\\\%
1231 \\hbox to \\textwidth{%
1234 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1235 \\hbox to \\textwidth{\\vbox {\\raggedleft \\em #2}}%
1236 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #1}}}}}
1237 \\long\\def\\weekend#1#2#3{%
1238 \\rule{\\textwidth}{0.3pt}\\\\%
1239 \\hbox to \\textwidth{%
1242 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1243 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1244 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #1}}}}}
1245 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1246 \\long\\def\\leftday#1#2#3{%
1247 \\rule{\\textwidth}{0.3pt}\\\\%
1248 \\hbox to \\textwidth{%
1251 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1252 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1253 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #1}}}}}
1255 (cal-tex-b-document)
1256 (cal-tex-cmd "\\pagestyle{empty}")
1257 (calendar-for-loop i from 1 to n do
1258 (calendar-for-loop j from 1 to 5 do
1259 (insert (if (oddp j) "\\righthead" "\\lefthead"))
1260 (cal-tex-arg (calendar-date-string date))
1262 (insert (if (oddp j) "\\rightday" "\\leftday"))
1263 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1264 (cal-tex-arg (cal-tex-latexify-list holidays date))
1265 (cal-tex-arg (eval cal-tex-daily-string))
1267 (insert "\\vfill\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1269 (setq date (cal-tex-incr-date date)))
1271 (calendar-for-loop j from 1 to 2 do
1272 (insert "\\lefthead")
1273 (cal-tex-arg (calendar-date-string date))
1274 (insert "\\weekend")
1275 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1276 (cal-tex-arg (cal-tex-latexify-list holidays date))
1277 (cal-tex-arg (eval cal-tex-daily-string))
1280 (setq date (cal-tex-incr-date date)))
1281 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1284 (run-hooks 'cal-tex-week-hook)
1285 (cal-tex-newpage))))
1286 (cal-tex-end-document)
1287 (run-hooks 'cal-tex-hook)))
1294 (defun cal-tex-cursor-day (&optional arg)
1295 "Make a buffer with LaTeX commands for the day cursor is on.
1296 Optional prefix argument specifies number of days."
1298 (let ((n (if arg arg 1))
1299 (date (calendar-absolute-from-gregorian (calendar-cursor-to-date t))))
1300 (cal-tex-preamble "12pt")
1301 (cal-tex-cmd "\\textwidth 6.5in")
1302 (cal-tex-cmd "\\textheight 10.5in")
1303 (cal-tex-b-document)
1304 (cal-tex-cmd "\\pagestyle{empty}")
1305 (calendar-for-loop i from 1 to n do
1306 (cal-tex-vspace "-1.7in")
1307 (cal-tex-daily-page (calendar-gregorian-from-absolute date))
1308 (setq date (1+ date))
1312 (run-hooks 'cal-tex-daily-hook))))
1313 (cal-tex-end-document)
1314 (run-hooks 'cal-tex-hook)))
1316 (defun cal-tex-daily-page (date)
1317 "Make a calendar page for Gregorian DATE on 8.5 by 11 paper."
1319 (month-name (calendar-month-name (extract-calendar-month date))))
1320 (cal-tex-banner "cal-tex-daily-page")
1321 (cal-tex-b-makebox "4cm" "l")
1322 (cal-tex-b-parbox "b" "3.8cm")
1323 (cal-tex-rule "0mm" "0mm" "2cm")
1324 (cal-tex-Huge (number-to-string (extract-calendar-day date)))
1326 (cal-tex-bf month-name )
1328 (cal-tex-hspace "1cm")
1329 (cal-tex-scriptsize (eval cal-tex-daily-string))
1330 (cal-tex-hspace "3.5cm")
1333 (cal-tex-b-makebox "4cm" "r")
1334 (cal-tex-bf (calendar-day-name date))
1337 (cal-tex-hspace ".4cm")
1338 (cal-tex-rule "0mm" "16.1cm" "1mm")
1340 (calendar-for-loop i from cal-tex-daily-start to cal-tex-daily-end do
1341 (cal-tex-cmd "\\noindent")
1342 (setq hour (if cal-tex-24
1345 (if (= 0 hour) (setq hour 12))
1346 (cal-tex-b-makebox "1cm" "c")
1347 (cal-tex-arg (number-to-string hour))
1349 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1351 (cal-tex-b-makebox "1cm" "c")
1352 (cal-tex-arg "$\\diamond$" )
1354 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1355 (cal-tex-nl ".2cm"))
1357 (insert (cal-tex-mini-calendar
1358 (extract-calendar-month (cal-tex-previous-month date))
1359 (extract-calendar-year (cal-tex-previous-month date))
1360 "lastmonth" "1.1in" "1in"))
1361 (insert (cal-tex-mini-calendar
1362 (extract-calendar-month date)
1363 (extract-calendar-year date)
1364 "thismonth" "1.1in" "1in"))
1365 (insert (cal-tex-mini-calendar
1366 (extract-calendar-month (cal-tex-next-month date))
1367 (extract-calendar-year (cal-tex-next-month date))
1368 "nextmonth" "1.1in" "1in"))
1369 (insert "\\hbox to \\textwidth{")
1371 (insert "\\lastmonth")
1373 (insert "\\thismonth")
1375 (insert "\\nextmonth")
1378 (cal-tex-banner "end of cal-tex-daily-page")))
1384 (defun cal-tex-mini-calendar (month year name width height &optional ptsize colsep)
1385 "Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT.
1386 Optional PTSIZE gives the point ptsize; scriptsize is the default. Optional
1387 COLSEP gives the column separation; 1mm is the default."
1388 (let* ((blank-days;; at start of month
1390 (- (calendar-day-of-week (list month 1 year))
1391 calendar-week-start-day)
1393 (last (calendar-last-day-of-month month year))
1394 (colsep (if colsep colsep "1mm"))
1395 (str (concat "\\def\\" name "{\\hbox to" width "{%\n"
1396 "\\vbox to" height "{%\n"
1397 "\\vfil \\hbox to" width "{%\n"
1399 (if ptsize ptsize "scriptsize")
1401 "{@{\\hspace{0mm}}r@{\\hspace{" colsep
1402 "}}r@{\\hspace{" colsep "}}r@{\\hspace{" colsep
1403 "}}r@{\\hspace{" colsep "}}r@{\\hspace{" colsep
1404 "}}r@{\\hspace{" colsep "}}r@{\\hspace{0mm}}}%\n"
1405 "\\multicolumn{7}{c}{"
1406 (calendar-month-name month)
1408 (int-to-string year)
1410 (calendar-for-loop i from 0 to 6 do
1411 (setq str (concat str
1412 (substring (aref calendar-day-name-array
1413 (mod (+ calendar-week-start-day i) 7))
1418 (calendar-for-loop i from 1 to blank-days do
1419 (setq str (concat str " & ")))
1420 (calendar-for-loop i from 1 to last do
1421 (setq str (concat str (int-to-string i)))
1422 (setq str (concat str (if (zerop (mod (+ i blank-days) 7))
1423 (if (/= i last) "\\\\[0.5mm]\n" "")
1425 (setq str (concat str "\n\\end{tabular}\\hfil}\\vfil}}}%\n"))
1429 ;;; Various calendar functions
1432 (defun cal-tex-incr-date (date &optional n)
1433 "The date of the day following DATE.
1434 If optional N is given, the date of N days after DATE."
1435 (calendar-gregorian-from-absolute
1436 (+ (if n n 1) (calendar-absolute-from-gregorian date))))
1438 (defun cal-tex-latexify-list (date-list date &optional separator)
1439 "Return string with concatenated, LaTeXified entries in DATE_LIST for DATE.
1440 Use double backslash as a separator unless optional SEPARATOR is given."
1441 (mapconcat '(lambda (x) (cal-tex-LaTeXify-string x))
1446 (calendar-date-equal date (car (car p)))
1447 (setq result (append result (cdr (car p)))))
1450 (if separator separator "\\\\")))
1452 (defun cal-tex-previous-month (date)
1453 "Return the date of the first day in the month previous to DATE."
1454 (let* ((month (extract-calendar-month date))
1455 (year (extract-calendar-year date)))
1456 (increment-calendar-month month year -1)
1457 (list month 1 year)))
1459 (defun cal-tex-next-month (date)
1460 "Return the date of the first day in the month following DATE."
1461 (let* ((month (extract-calendar-month date))
1462 (year (extract-calendar-year date)))
1463 (increment-calendar-month month year 1)
1464 (list month 1 year)))
1470 (defun cal-tex-end-document ()
1471 "Finish the LaTeX document.
1472 Insert the trailer to LaTeX document, pop to LaTeX buffer, add
1473 informative header, and run HOOK."
1474 (cal-tex-e-document)
1476 (pop-to-buffer cal-tex-buffer)
1477 (goto-char (point-min))
1478 (cal-tex-comment " This buffer was produced by cal-tex.el.")
1479 (cal-tex-comment " To print a calendar, type")
1480 (cal-tex-comment " M-x tex-buffer RET")
1481 (cal-tex-comment " M-x tex-print RET")
1482 (goto-char (point-min)))
1484 (defun cal-tex-insert-preamble (weeks landscape size &optional append)
1485 "Initialize the output buffer.
1486 Select the output buffer, and insert the preamble for a calendar of
1487 WEEKS weeks. Insert code for landscape mode if LANDSCAPE is true.
1488 Use pointsize SIZE. Optional argument APPEND, if t, means add to end of
1489 without erasing current contents."
1490 (let ((width "18cm")
1495 (setq height "18cm")))
1498 (cal-tex-preamble size)
1501 (cal-tex-cmd "\\oddsidemargin -1.75cm")
1502 (cal-tex-cmd "\\def\\holidaymult{.06}"))
1503 (cal-tex-cmd "\\special{landscape}")
1504 (cal-tex-cmd "\\textwidth 9.5in")
1505 (cal-tex-cmd "\\textheight 7in")
1507 (cal-tex-cmd "\\def\\holidaymult{.08}"))
1508 (cal-tex-cmd cal-tex-caldate)
1509 (cal-tex-cmd cal-tex-myday)
1510 (cal-tex-b-document)
1511 (cal-tex-cmd "\\pagestyle{empty}")))
1512 (cal-tex-cmd "\\setlength{\\cellwidth}" width)
1513 (insert (format "\\setlength{\\cellwidth}{%f\\cellwidth}\n"
1514 (/ 1.1 (length cal-tex-which-days))))
1515 (cal-tex-cmd "\\setlength{\\cellheight}" height)
1516 (insert (format "\\setlength{\\cellheight}{%f\\cellheight}\n"
1518 (cal-tex-cmd "\\ \\par")
1519 (cal-tex-vspace "-3cm")))
1521 (defvar cal-tex-LaTeX-subst-list
1523 ("\"". "''");; Quote changes meaning when list is reversed.
1534 ("\n" . "\\ \\\\")) ;\\ needed for e.g \begin{center}\n AA\end{center}
1535 "List of symbols and their replacements.")
1537 (defun cal-tex-LaTeXify-string (string)
1538 "Protect special characters in STRING from LaTeX."
1543 (list cal-tex-LaTeX-subst-list))
1544 (while (not (string-equal tail ""))
1545 (let* ((ch (substring tail 0 1))
1546 (pair (assoc ch list)))
1547 (if (and pair (string-equal ch "\""))
1548 (setq list (reverse list)));; Quote changes meaning each time.
1549 (setq tail (substring tail 1))
1550 (setq head (concat head (if pair (cdr pair) ch)))))
1553 (defun cal-tex-hfill () "Insert hfill." (insert "\\hfill"))
1555 (defun cal-tex-newpage () "Insert newpage." (insert "\\newpage%\n"))
1557 (defun cal-tex-noindent () "Insert noindent." (insert "\\noindent"))
1559 (defun cal-tex-vspace (space)
1560 "Insert vspace command to move SPACE vertically."
1561 (insert "\\vspace*{" space "}")
1564 (defun cal-tex-hspace (space)
1565 "Insert hspace command to move SPACE horizontally."
1566 (insert "\\hspace*{" space "}")
1569 (defun cal-tex-comment (&optional comment)
1570 "Insert % at end of line, include COMMENT if present, and move
1577 (defun cal-tex-banner (comment)
1578 "Insert the COMMENT separated by blank lines."
1581 (cal-tex-comment (concat "\t\t\t" comment))
1585 (defun cal-tex-nl (&optional skip comment)
1586 "End a line with \\. If SKIP, then add that much spacing.
1587 Add COMMENT if present"
1590 (insert "[" skip "]"))
1591 (cal-tex-comment comment))
1593 (defun cal-tex-arg (&optional text)
1594 "Insert optional TEXT surrounded by braces."
1596 (if text (insert text))
1599 (defun cal-tex-cmd (cmd &optional arg)
1600 "Insert LaTeX CMD, with optional ARG, and end with %"
1609 (defun cal-tex-b-document ()
1610 "Insert beginning of document."
1611 (cal-tex-cmd "\\begin{document}"))
1613 (defun cal-tex-e-document ()
1614 "Insert end of document."
1615 (cal-tex-cmd "\\end{document}"))
1617 (defun cal-tex-b-center ()
1618 "Insert beginning of centered block."
1619 (cal-tex-cmd "\\begin{center}"))
1621 (defun cal-tex-e-center ()
1622 "Insert end of centered block."
1624 (cal-tex-cmd "\\end{center}"))
1632 (defun cal-tex-b-parbox (position width)
1633 "Insert parbox with parameters POSITION and WIDTH."
1634 (insert "\\parbox[" position "]{" width "}{")
1637 (defun cal-tex-e-parbox (&optional height)
1638 "Insert end of parbox. Force it to be a given HEIGHT."
1641 (cal-tex-rule "0mm" "0mm" height))
1643 (cal-tex-comment "end parbox"))
1645 (defun cal-tex-b-framebox ( width position )
1646 "Insert framebox with parameters WIDTH and POSITION (clr)."
1647 (insert "\\framebox[" width "][" position "]{" )
1650 (defun cal-tex-e-framebox ()
1651 "Insert end of framebox."
1654 (cal-tex-comment "end framebox"))
1657 (defun cal-tex-b-makebox ( width position )
1658 "Insert makebox with parameters WIDTH and POSITION (clr)."
1659 (insert "\\makebox[" width "][" position "]{" )
1662 (defun cal-tex-e-makebox ()
1663 "Insert end of makebox."
1666 (cal-tex-comment "end makebox"))
1669 (defun cal-tex-rule (lower width height)
1670 "Insert a rule with parameters LOWER WIDTH HEIGHT."
1671 (insert "\\rule[" lower "]{" width "}{" height "}"))
1677 (defun cal-tex-em (string)
1678 "Insert STRING in bf font."
1679 (insert "{\\em " string "}"))
1681 (defun cal-tex-bf (string)
1682 "Insert STRING in bf font."
1683 (insert "{\\bf " string "}"))
1685 (defun cal-tex-scriptsize (string)
1686 "Insert STRING in scriptsize font."
1687 (insert "{\\scriptsize " string "}"))
1689 (defun cal-tex-huge (string)
1690 "Insert STRING in huge size."
1691 (insert "{\\huge " string "}"))
1693 (defun cal-tex-Huge (string)
1694 "Insert STRING in Huge size."
1695 (insert "{\\Huge " string "}"))
1697 (defun cal-tex-Huge-bf (string)
1698 "Insert STRING in Huge bf size."
1699 (insert "{\\Huge\\bf " string "}"))
1701 (defun cal-tex-large (string)
1702 "Insert STRING in large size."
1703 (insert "{\\large " string "}"))
1705 (defun cal-tex-large-bf (string)
1706 "Insert STRING in large bf size."
1707 (insert "{\\large\\bf " string "}"))
1711 ;;; cal-tex.el ends here