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."
180 (start (calendar-gregorian-from-absolute d1))
181 (start-month (extract-calendar-month start))
182 (start-year (extract-calendar-year start)))
183 (increment-calendar-month start-month start-year 1)
184 (let* ((end (calendar-gregorian-from-absolute d2))
185 (end-month (extract-calendar-month end))
186 (end-year (extract-calendar-year end)))
187 (if (= (extract-calendar-day end) 1)
188 (increment-calendar-month end-month end-year -1))
189 (let* ((s (calendar-absolute-from-gregorian
190 (list start-month 1 start-year)))
191 (e (calendar-absolute-from-gregorian
192 (list end-month 1 end-year)))
195 (displayed-month start-month)
196 (displayed-year start-year))
197 (while (or never (<= d e))
198 (setq result (append result (calendar-holiday-list)))
200 (increment-calendar-month displayed-month displayed-year 3)
201 (setq d (calendar-absolute-from-gregorian
202 (list displayed-month 1 displayed-year))))))
207 (let ((a (calendar-absolute-from-gregorian (car (car p)))))
208 (and (<= d1 a) (<= a d2)))
209 (setq in-range (append (list (car p)) in-range)))
213 (defun cal-tex-list-diary-entries (d1 d2)
214 "Generate a list of all diary-entries from absolute date D1 to D2."
215 (let ((diary-list-include-blanks nil)
216 (diary-display-hook nil))
218 (calendar-gregorian-from-absolute d1)
221 (defun cal-tex-preamble (&optional args)
222 "Insert the LaTeX preamble.
223 Preamble Includes initial definitions for various LaTeX commands.
224 Optional ARGS are included."
225 (set-buffer (get-buffer-create cal-tex-buffer))
227 (insert "\\documentstyle")
229 (insert "[" args "]"))
230 (insert "{article}\n"
237 \\evensidemargin -2cm
242 \\newlength{\\cellwidth}
243 \\newlength{\\cellheight}
244 \\newlength{\\boxwidth}
245 \\newlength{\\boxheight}
246 \\newlength{\\cellsize}
247 \\newcommand{\\myday}[1]{}
248 \\newcommand{\\caldate}[6]{}
249 \\newcommand{\\nocaldate}[6]{}
250 \\newcommand{\\calsmall}[6]{}
258 (defun cal-tex-cursor-year (&optional arg)
259 "Make a buffer with LaTeX commands for the year cursor is on.
260 Optional prefix argument specifies number of years."
262 (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
265 (defun cal-tex-cursor-year-landscape (&optional arg)
266 "Make a buffer with LaTeX commands for the year cursor is on.
267 Optional prefix argument specifies number of years."
269 (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
273 (defun cal-tex-year (year n &optional landscape)
274 "Make a one page yearly calendar of YEAR; do this for N years.
275 There are four rows of three months each, unless optional LANDSCAPE is t,
276 in which case the calendar isprinted in landscape mode with three rows of
278 (cal-tex-insert-preamble 1 landscape "12pt")
280 (cal-tex-vspace "-.6cm")
281 (cal-tex-vspace "-3.1cm"))
282 (calendar-for-loop j from 1 to n do
283 (insert "\\vfill%\n")
285 (cal-tex-Huge (number-to-string year))
287 (cal-tex-vspace "1cm")
289 (cal-tex-b-parbox "l" (if landscape "5.9in" "4.3in"))
293 (calendar-for-loop i from 1 to 12 do
294 (insert (cal-tex-mini-calendar i year "month" "1.1in" "1in"))
296 (cal-tex-hspace "0.5in")
297 (if (zerop (mod i (if landscape 4 3)))
298 (cal-tex-nl "0.5in")))
301 (insert "\\vfill%\n")
302 (setq year (1+ year))
305 (cal-tex-end-document))
306 (run-hooks 'cal-tex-year-hook))
307 (run-hooks 'cal-tex-hook))
309 (defun cal-tex-cursor-filofax-year (&optional arg)
310 "Make a Filofax one page yearly calendar of year indicated by cursor.
311 Optional parameter specifies number of years."
313 (let* ((n (if arg arg 1))
314 (year (extract-calendar-year (calendar-cursor-to-date t))))
315 (cal-tex-preamble "twoside")
316 (cal-tex-cmd "\\textwidth 3.25in")
317 (cal-tex-cmd "\\textheight 6.5in")
318 (cal-tex-cmd "\\oddsidemargin 1.675in")
319 (cal-tex-cmd "\\evensidemargin 1.675in")
320 (cal-tex-cmd "\\topmargin 0pt")
321 (cal-tex-cmd "\\headheight -0.875in")
322 (cal-tex-cmd "\\fboxsep 0.5mm")
323 (cal-tex-cmd "\\pagestyle{empty}")
325 (cal-tex-cmd "\\vspace*{0.25in}")
326 (calendar-for-loop j from 1 to n do
327 (insert (format "\\hfil {\\Large \\bf %s} \\hfil\\\\\n" year))
329 (cal-tex-b-parbox "l" "\\textwidth")
333 (calendar-for-loop i from 1 to 12 do
334 (insert (cal-tex-mini-calendar i year
335 (calendar-month-name i)
336 "1in" ".9in" "tiny" "0.6mm")))
338 "\\noindent\\fbox{\\January}\\fbox{\\February}\\fbox{\\March}\\\\
339 \\noindent\\fbox{\\April}\\fbox{\\May}\\fbox{\\June}\\\\
340 \\noindent\\fbox{\\July}\\fbox{\\August}\\fbox{\\September}\\\\
341 \\noindent\\fbox{\\October}\\fbox{\\November}\\fbox{\\December}
345 (setq year (1+ year))
347 (cal-tex-end-document)
349 (cal-tex-cmd "\\vspace*{0.25in}"))
350 (run-hooks 'cal-tex-year-hook))
351 (run-hooks 'cal-tex-hook)))
354 ;;; Monthly calendars
357 (defun cal-tex-cursor-month-landscape (&optional arg)
358 "Make a buffer with LaTeX commands for the month cursor is on.
359 Optional prefix argument specifies number of months to be produced.
360 The output is in landscape format, one month to a page."
362 (let* ((n (if arg arg 1))
363 (date (calendar-cursor-to-date t))
364 (month (extract-calendar-month date))
365 (year (extract-calendar-year date))
368 (cal-tex-which-days '(0 1 2 3 4 5 6)))
369 (increment-calendar-month end-month end-year (1- n))
370 (let ((diary-list (if cal-tex-diary
371 (cal-tex-list-diary-entries
372 (calendar-absolute-from-gregorian
374 (calendar-absolute-from-gregorian
376 (calendar-last-day-of-month
379 (holidays (if cal-tex-holidays
380 (cal-tex-list-holidays
381 (calendar-absolute-from-gregorian
383 (calendar-absolute-from-gregorian
385 (calendar-last-day-of-month end-month end-year)
389 (small-months-at-start))
390 (cal-tex-insert-preamble (cal-tex-number-weeks month year 1) t "12pt")
391 (cal-tex-cmd cal-tex-cal-one-month)
392 (calendar-for-loop i from 1 to n do
393 (setq other-month month)
394 (setq other-year year)
395 (increment-calendar-month other-month other-year -1)
396 (insert (cal-tex-mini-calendar other-month other-year "lastmonth"
397 "\\cellwidth" "\\cellheight"))
398 (increment-calendar-month other-month other-year 2)
399 (insert (cal-tex-mini-calendar other-month other-year "nextmonth"
400 "\\cellwidth" "\\cellheight"))
401 (cal-tex-insert-month-header 1 month year month year)
402 (cal-tex-insert-day-names)
404 (setq small-months-at-start
405 (< 1 (mod (- (calendar-day-of-week (list month 1 year))
406 calendar-week-start-day)
408 (if small-months-at-start
409 (insert "\\lastmonth\\nextmonth\\hspace*{-2\\cellwidth}"))
410 (cal-tex-insert-blank-days month year cal-tex-day-prefix)
411 (cal-tex-insert-days month year diary-list holidays
413 (cal-tex-insert-blank-days-at-end month year cal-tex-day-prefix)
414 (if (and (not small-months-at-start)
415 (< 1 (mod (- (1- calendar-week-start-day)
416 (calendar-day-of-week
418 (calendar-last-day-of-month month year)
421 (insert "\\vspace*{-\\cellwidth}\\hspace*{-2\\cellwidth}"
422 "\\lastmonth\\nextmonth"))
425 (run-hooks 'cal-tex-month-hook)
427 (increment-calendar-month month year 1)
428 (cal-tex-vspace "-2cm")
429 (cal-tex-insert-preamble
430 (cal-tex-number-weeks month year 1) t "12pt" t))))
431 (cal-tex-end-document)
432 (run-hooks 'cal-tex-hook))))
434 (defun cal-tex-cursor-month (arg)
435 "Make a buffer with LaTeX commands for the month cursor is on.
436 Optional prefix argument specifies number of months to be produced.
437 Calendar is condensed onto one page."
439 (let* ((date (calendar-cursor-to-date t))
440 (month (extract-calendar-month date))
441 (year (extract-calendar-year date))
445 (increment-calendar-month end-month end-year (1- n))
446 (let ((diary-list (if cal-tex-diary
447 (cal-tex-list-diary-entries
448 (calendar-absolute-from-gregorian
450 (calendar-absolute-from-gregorian
452 (calendar-last-day-of-month
455 (holidays (if cal-tex-holidays
456 (cal-tex-list-holidays
457 (calendar-absolute-from-gregorian
459 (calendar-absolute-from-gregorian
461 (calendar-last-day-of-month end-month end-year)
465 (cal-tex-insert-preamble (cal-tex-number-weeks month year n) nil"12pt")
467 (cal-tex-cmd cal-tex-cal-multi-month)
468 (cal-tex-cmd cal-tex-cal-one-month))
469 (cal-tex-insert-month-header n month year end-month end-year)
470 (cal-tex-insert-day-names)
472 (cal-tex-insert-blank-days month year cal-tex-day-prefix)
473 (calendar-for-loop i from 1 to n do
474 (setq other-month month)
475 (setq other-year year)
476 (cal-tex-insert-days month year diary-list holidays
478 (increment-calendar-month month year 1))
479 (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix)
480 (cal-tex-end-document)))
481 (run-hooks 'cal-tex-hook))
483 (defun cal-tex-insert-days (month year diary-list holidays day-format)
484 "Insert LaTeX commands for a range of days in monthly calendars.
485 LaTeX commands are inserted for the days of the MONTH in YEAR.
486 Diary entries on DIARY-LIST are included. Holidays on HOLIDAYS are included.
487 Each day is formatted using format DAY-FORMAT."
488 (let* ((blank-days;; at start of month
490 (- (calendar-day-of-week (list month 1 year))
491 calendar-week-start-day)
494 (last (calendar-last-day-of-month month year)))
495 (calendar-for-loop i from 1 to last do
496 (setq date (list month i year))
497 (if (memq (calendar-day-of-week date) cal-tex-which-days)
499 (insert (format day-format (calendar-month-name month) i))
500 (cal-tex-arg (cal-tex-latexify-list diary-list date))
501 (cal-tex-arg (cal-tex-latexify-list holidays date))
502 (cal-tex-arg (eval cal-tex-daily-string))
505 (if (and (zerop (mod (+ i blank-days) 7))
511 (defun cal-tex-insert-day-names ()
512 "Insert the names of the days at top of a monthly calendar."
513 (calendar-for-loop i from 0 to 6 do
514 (if (memq i cal-tex-which-days)
515 (insert (format cal-tex-day-name-format
516 (aref calendar-day-name-array
517 (mod (+ calendar-week-start-day i) 7)))))
520 (defun cal-tex-insert-month-header (n month year end-month end-year)
521 "Create a title for a calendar.
522 A title is inserted for a calendar with N months starting with
523 MONTH YEAR and ending with END-MONTH END-YEAR."
524 (let ( (month-name (calendar-month-name month))
525 (end-month-name (calendar-month-name end-month)))
527 (insert (format "\\calmonth{%s}{%s}\n\\vspace*{-0.5cm}"
529 (insert (format "\\calmonth{%s}{%s}{%s}{%s}\n\\vspace*{-0.5cm}"
530 month-name year end-month-name end-year))))
533 (defun cal-tex-insert-blank-days (month year day-format)
534 "Insert code for initial days not in calendar.
535 Insert LaTeX code for the blank days at the beginning of the MONTH in
536 YEAR. The entry is formatted using DAY-FORMAT. If the entire week is
537 blank, no days are inserted."
538 (if (cal-tex-first-blank-p month year)
539 (let* ((blank-days;; at start of month
541 (- (calendar-day-of-week (list month 1 year))
542 calendar-week-start-day)
544 (calendar-for-loop i from 0 to (1- blank-days) do
545 (if (memq i cal-tex-which-days)
546 (insert (format day-format " " " ") "{}{}{}{}%\n"))))))
548 (defun cal-tex-insert-blank-days-at-end (month year day-format)
549 "Insert code for final days not in calendar.
550 Insert LaTeX code for the blank days at the end of the MONTH in YEAR.
551 The entry is formatted using DAY-FORMAT."
552 (if (cal-tex-last-blank-p month year)
553 (let* ((last-day (calendar-last-day-of-month month year))
554 (blank-days;; at end of month
556 (- (calendar-day-of-week (list month last-day year))
557 calendar-week-start-day)
559 (calendar-for-loop i from (1+ blank-days) to 6 do
560 (if (memq i cal-tex-which-days)
561 (insert (format day-format "" "") "{}{}{}{}%\n"))))))
563 (defun cal-tex-first-blank-p (month year)
564 "Determine if any days of the first week will be printed.
565 Return t if there will there be any days of the first week printed
566 in the calendar starting in MONTH YEAR."
568 (the-saturday)) ;the day of week of 1st Saturday
569 (calendar-for-loop i from 1 to 7 do
570 (if (= 6 (calendar-day-of-week (list month i year)))
571 (setq the-saturday i)))
572 (calendar-for-loop i from 1 to the-saturday do
573 (if (memq (calendar-day-of-week (list month i year))
578 (defun cal-tex-last-blank-p (month year)
579 "Determine if any days of the last week will be printed.
580 Return t if there will there be any days of the last week printed
581 in the calendar starting in MONTH YEAR."
583 (last-day (calendar-last-day-of-month month year))
584 (the-sunday)) ;the day of week of last Sunday
585 (calendar-for-loop i from (- last-day 6) to last-day do
586 (if (= 0 (calendar-day-of-week (list month i year)))
587 (setq the-sunday i)))
588 (calendar-for-loop i from the-sunday to last-day do
589 (if (memq (calendar-day-of-week (list month i year))
594 (defun cal-tex-number-weeks (month year n)
595 "Determine the number of weeks in a range of dates.
596 Compute the number of weeks in the calendar starting with MONTH and YEAR,
597 and lasting N months, including only the days in WHICH-DAYS. As it stands,
598 this is only an upper bound."
599 (let ((d (list month 1 year)))
600 (increment-calendar-month month year (1- n))
601 (/ (- (calendar-dayname-on-or-before
602 calendar-week-start-day
603 (+ 7 (calendar-absolute-from-gregorian
604 (list month (calendar-last-day-of-month month year) year))))
605 (calendar-dayname-on-or-before
606 calendar-week-start-day
607 (calendar-absolute-from-gregorian d)))
614 (defun cal-tex-cursor-week (&optional arg)
615 "Make a buffer with LaTeX commands for a two-page one-week calendar.
616 It applies to the week that point is in.
617 Optional prefix argument specifies number of weeks.
618 Holidays are included if `cal-tex-holidays' is t."
620 (let* ((n (if arg arg 1))
621 (date (calendar-gregorian-from-absolute
622 (calendar-dayname-on-or-before
623 calendar-week-start-day
624 (calendar-absolute-from-gregorian
625 (calendar-cursor-to-date t)))))
626 (month (extract-calendar-month date))
627 (year (extract-calendar-year date))
628 (holidays (if cal-tex-holidays
629 (cal-tex-list-holidays
630 (calendar-absolute-from-gregorian date)
632 (calendar-absolute-from-gregorian date))))))
633 (cal-tex-preamble "11pt")
634 (cal-tex-cmd "\\textwidth 6.5in")
635 (cal-tex-cmd "\\textheight 10.5in")
636 (cal-tex-cmd "\\oddsidemargin 0in")
637 (cal-tex-cmd "\\evensidemargin 0in")
638 (insert cal-tex-LaTeX-hourbox)
640 (cal-tex-cmd "\\pagestyle{empty}")
641 (calendar-for-loop i from 1 to n do
642 (cal-tex-vspace "-1.5in")
644 (cal-tex-Huge-bf (format "\\uppercase{%s}"
645 (calendar-month-name month)))
646 (cal-tex-hspace "2em")
647 (cal-tex-Huge-bf (number-to-string year))
650 (cal-tex-hspace "-.2in")
651 (cal-tex-b-parbox "l" "7in")
652 (calendar-for-loop j from 1 to 7 do
653 (cal-tex-week-hours date holidays "3.1")
654 (setq date (cal-tex-incr-date date)))
656 (setq month (extract-calendar-month date))
657 (setq year (extract-calendar-year date))
660 (run-hooks 'cal-tex-week-hook)
662 (cal-tex-end-document)
663 (run-hooks 'cal-tex-hook)))
665 (defun cal-tex-cursor-week2 (&optional arg)
666 "Make a buffer with LaTeX commands for a two-page one-week calendar.
667 It applies to the week that point is in.
668 Optional prefix argument specifies number of weeks.
669 Holidays are included if `cal-tex-holidays' is t."
671 (let* ((n (if arg arg 1))
672 (date (calendar-gregorian-from-absolute
673 (calendar-dayname-on-or-before
674 calendar-week-start-day
675 (calendar-absolute-from-gregorian
676 (calendar-cursor-to-date t)))))
677 (month (extract-calendar-month date))
678 (year (extract-calendar-year date))
680 (holidays (if cal-tex-holidays
681 (cal-tex-list-holidays
682 (calendar-absolute-from-gregorian date)
684 (calendar-absolute-from-gregorian date))))))
685 (cal-tex-preamble "12pt")
686 (cal-tex-cmd "\\textwidth 6.5in")
687 (cal-tex-cmd "\\textheight 10.5in")
688 (cal-tex-cmd "\\oddsidemargin 0in")
689 (cal-tex-cmd "\\evensidemargin 0in")
690 (insert cal-tex-LaTeX-hourbox)
692 (cal-tex-cmd "\\pagestyle{empty}")
693 (calendar-for-loop i from 1 to n do
694 (cal-tex-vspace "-1.5in")
696 (cal-tex-Huge-bf (format "\\uppercase{%s}"
697 (calendar-month-name month)))
698 (cal-tex-hspace "2em")
699 (cal-tex-Huge-bf (number-to-string year))
702 (cal-tex-hspace "-.2in")
703 (cal-tex-b-parbox "l" "\\textwidth")
704 (calendar-for-loop j from 1 to 3 do
705 (cal-tex-week-hours date holidays "5")
706 (setq date (cal-tex-incr-date date)))
709 (insert (cal-tex-mini-calendar
710 (extract-calendar-month (cal-tex-previous-month date))
711 (extract-calendar-year (cal-tex-previous-month date))
712 "lastmonth" "1.1in" "1in"))
713 (insert (cal-tex-mini-calendar
714 (extract-calendar-month date)
715 (extract-calendar-year date)
716 "thismonth" "1.1in" "1in"))
717 (insert (cal-tex-mini-calendar
718 (extract-calendar-month (cal-tex-next-month date))
719 (extract-calendar-year (cal-tex-next-month date))
720 "nextmonth" "1.1in" "1in"))
721 (insert "\\hbox to \\textwidth{")
723 (insert "\\lastmonth")
725 (insert "\\thismonth")
727 (insert "\\nextmonth")
731 (cal-tex-b-parbox "l" "\\textwidth")
732 (calendar-for-loop j from 4 to 7 do
733 (cal-tex-week-hours date holidays "5")
734 (setq date (cal-tex-incr-date date)))
736 (setq month (extract-calendar-month date))
737 (setq year (extract-calendar-year date))
740 (run-hooks 'cal-tex-week-hook)
742 (cal-tex-end-document)
743 (run-hooks 'cal-tex-hook)))
745 (defun cal-tex-cursor-week-iso (&optional arg)
746 "Make a buffer with LaTeX commands for a one page ISO-style weekly calendar.
747 Optional prefix argument specifies number of weeks.
748 Diary entries are included if `cal-tex-diary' is t.
749 Holidays are included if `cal-tex-holidays' is t."
751 (let* ((n (if arg arg 1))
752 (date (calendar-gregorian-from-absolute
753 (calendar-dayname-on-or-before
755 (calendar-absolute-from-gregorian
756 (calendar-cursor-to-date t)))))
757 (month (extract-calendar-month date))
758 (year (extract-calendar-year date))
759 (day (extract-calendar-day date))
760 (holidays (if cal-tex-holidays
761 (cal-tex-list-holidays
762 (calendar-absolute-from-gregorian date)
764 (calendar-absolute-from-gregorian date)))))
765 (diary-list (if cal-tex-diary
766 (cal-tex-list-diary-entries
767 (calendar-absolute-from-gregorian
770 (calendar-absolute-from-gregorian date))))))
771 (cal-tex-preamble "11pt")
772 (cal-tex-cmd "\\textwidth 6.5in")
773 (cal-tex-cmd "\\textheight 10.5in")
774 (cal-tex-cmd "\\oddsidemargin 0in")
775 (cal-tex-cmd "\\evensidemargin 0in")
777 (cal-tex-cmd "\\pagestyle{empty}")
778 (calendar-for-loop i from 1 to n do
779 (cal-tex-vspace "-1.5in")
782 (let* ((d (calendar-iso-from-absolute
783 (calendar-absolute-from-gregorian date))))
784 (format "Week %d of %d"
785 (extract-calendar-month d)
786 (extract-calendar-year d))))
789 (cal-tex-b-parbox "l" "\\textwidth")
790 (calendar-for-loop j from 1 to 7 do
791 (cal-tex-b-parbox "t" "\\textwidth")
792 (cal-tex-b-parbox "t" "\\textwidth")
793 (cal-tex-rule "0pt" "\\textwidth" ".2mm")
795 (cal-tex-b-parbox "t" "\\textwidth")
796 (cal-tex-large-bf (calendar-day-name date))
798 (cal-tex-large-bf (calendar-month-name month))
800 (cal-tex-large-bf (number-to-string day))
801 (if (not (string= "" (cal-tex-latexify-list holidays date)))
804 (cal-tex-large-bf (cal-tex-latexify-list holidays date "; "))))
806 (insert " " (eval cal-tex-daily-string))
810 (cal-tex-b-parbox "t" "\\textwidth")
811 (if (not (string= "" (cal-tex-latexify-list diary-list date)))
813 (insert "\\vbox to 0pt{")
815 (cal-tex-latexify-list diary-list date))
819 (setq date (cal-tex-incr-date date))
820 (setq month (extract-calendar-month date))
821 (setq day (extract-calendar-day date))
823 (cal-tex-e-parbox "2cm")
825 (setq month (extract-calendar-month date))
826 (setq year (extract-calendar-year date)))
830 (run-hooks 'cal-tex-week-hook)
832 (cal-tex-end-document)
833 (run-hooks 'cal-tex-hook)))
835 (defvar cal-tex-LaTeX-hourbox
836 "\\newcommand{\\hourbox}[2]%
837 {\\makebox[2em]{\\rule{0cm}{#2ex}#1}\\rule{3in}{.15mm}}\n"
838 "One hour and a line on the right.")
840 (defun cal-tex-week-hours (date holidays height)
841 "Insert hourly entries for DATE with HOLIDAYS, with line height HEIGHT."
842 (let ((month (extract-calendar-month date))
843 (day (extract-calendar-day date))
844 (year (extract-calendar-year date))
846 (cal-tex-comment "begin cal-tex-week-hours")
847 (cal-tex-cmd "\\ \\\\[-.2cm]")
848 (cal-tex-cmd "\\noindent")
849 (cal-tex-b-parbox "l" "6.8in")
850 (cal-tex-large-bf (calendar-day-name date))
852 (cal-tex-large-bf (calendar-month-name month))
854 (cal-tex-large-bf (number-to-string day))
855 (if (not (string= "" (cal-tex-latexify-list holidays date)))
858 (cal-tex-large-bf (cal-tex-latexify-list holidays date "; "))))
860 (insert " " (eval cal-tex-daily-string))
863 (cal-tex-rule "0pt" "6.8in" ".2mm")
865 (calendar-for-loop i from 8 to 12 do
867 (setq afternoon (+ i 5))
868 (setq afternoon (- i 7)))
869 (cal-tex-cmd "\\hourbox" (number-to-string i))
871 (cal-tex-hspace ".4cm")
872 (cal-tex-cmd "\\hourbox" (number-to-string afternoon))
876 (defun cal-tex-cursor-week-monday (&optional arg)
877 "Make a buffer with LaTeX commands for a two-page one-week calendar.
878 It applies to the week that point is in, and starts on Monday.
879 Optional prefix argument specifies number of weeks.
880 Holidays are included if `cal-tex-holidays' is t."
882 (let* ((n (if arg arg 1))
883 (date (calendar-gregorian-from-absolute
884 (calendar-dayname-on-or-before
886 (calendar-absolute-from-gregorian
887 (calendar-cursor-to-date t))))))
888 (cal-tex-preamble "11pt")
889 (cal-tex-cmd "\\textwidth 6.5in")
890 (cal-tex-cmd "\\textheight 10.5in")
891 (cal-tex-cmd "\\oddsidemargin 0in")
892 (cal-tex-cmd "\\evensidemargin 0in")
894 (calendar-for-loop i from 1 to n do
895 (cal-tex-vspace "-1cm")
896 (insert "\\noindent ")
897 (cal-tex-weekly4-box (cal-tex-incr-date date) nil)
898 (cal-tex-weekly4-box (cal-tex-incr-date date 4) nil)
900 (cal-tex-weekly4-box (cal-tex-incr-date date 2) nil)
901 (cal-tex-weekly4-box (cal-tex-incr-date date 5) nil)
903 (cal-tex-weekly4-box (cal-tex-incr-date date 3) nil)
904 (cal-tex-weekly4-box (cal-tex-incr-date date 6) t)
907 (run-hooks 'cal-tex-week-hook)
908 (setq date (cal-tex-incr-date date 7))
910 (cal-tex-end-document)
911 (run-hooks 'cal-tex-hook)))
913 (defun cal-tex-weekly4-box (date weekend)
914 "Make one box for DATE, different if WEEKEND."
916 (day (extract-calendar-day date))
917 (month (extract-calendar-month date))
918 (year (extract-calendar-year date))
919 (dayname (calendar-day-name date))
920 (date1 (cal-tex-incr-date date))
921 (day1 (extract-calendar-day date1))
922 (month1 (extract-calendar-month date1))
923 (year1 (extract-calendar-year date1))
924 (dayname1 (calendar-day-name date1))
926 (cal-tex-b-framebox "8cm" "l")
927 (cal-tex-b-parbox "b" "7.5cm")
928 (insert (format "{\\Large\\bf %s,} %s/%s/%s\\\\\n" dayname month day year))
929 (cal-tex-rule "0pt" "7.5cm" ".5mm")
933 (calendar-for-loop i from 8 to 12 do
934 (insert (format "{\\large\\sf %d}\\\\\n" i)))
935 (calendar-for-loop i from 1 to 5 do
936 (insert (format "{\\large\\sf %d}\\\\\n" i)))))
940 (cal-tex-vspace "1cm")
941 (insert "\\ \\vfill")
942 (insert (format "{\\Large\\bf %s,} %s/%s/%s\\\\\n"
943 dayname1 month1 day1 year1))
944 (cal-tex-rule "0pt" "7.5cm" ".5mm")
946 (cal-tex-vspace "1cm")))
949 (cal-tex-hspace "1cm")))
951 (defun cal-tex-cursor-filofax-2week (&optional arg)
952 "Two-weeks-at-a-glance Filofax style calendar for week indicated by cursor.
953 Optional prefix argument specifies number of weeks.
954 Diary entries are included if `cal-tex-diary' is t.
955 Holidays are included if `cal-tex-holidays' is t."
957 (let* ((n (if arg arg 1))
958 (date (calendar-gregorian-from-absolute
959 (calendar-dayname-on-or-before
960 calendar-week-start-day
961 (calendar-absolute-from-gregorian
962 (calendar-cursor-to-date t)))))
963 (month (extract-calendar-month date))
964 (year (extract-calendar-year date))
965 (day (extract-calendar-day date))
966 (holidays (if cal-tex-holidays
967 (cal-tex-list-holidays
968 (calendar-absolute-from-gregorian date)
970 (calendar-absolute-from-gregorian date)))))
971 (diary-list (if cal-tex-diary
972 (cal-tex-list-diary-entries
973 (calendar-absolute-from-gregorian
976 (calendar-absolute-from-gregorian date))))))
977 (cal-tex-preamble "twoside")
978 (cal-tex-cmd "\\textwidth 3.25in")
979 (cal-tex-cmd "\\textheight 6.5in")
980 (cal-tex-cmd "\\oddsidemargin 1.75in")
981 (cal-tex-cmd "\\evensidemargin 1.5in")
982 (cal-tex-cmd "\\topmargin 0pt")
983 (cal-tex-cmd "\\headheight -0.875in")
984 (cal-tex-cmd "\\headsep 0.125in")
985 (cal-tex-cmd "\\footskip .125in")
986 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
987 \\long\\def\\rightday#1#2#3#4#5{%
988 \\rule{\\textwidth}{0.3pt}\\\\%
989 \\hbox to \\textwidth{%
992 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
993 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
994 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
995 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
996 \\long\\def\\leftday#1#2#3#4#5{%
997 \\rule{\\textwidth}{0.3pt}\\\\%
998 \\hbox to \\textwidth{%
1001 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1002 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1003 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1005 (cal-tex-b-document)
1006 (cal-tex-cmd "\\pagestyle{empty}")
1007 (calendar-for-loop i from 1 to n do
1009 (insert "\\righthead")
1010 (insert "\\lefthead"))
1012 (let ((d (cal-tex-incr-date date 6)))
1013 (if (= (extract-calendar-month date)
1014 (extract-calendar-month d))
1016 (calendar-month-name
1017 (extract-calendar-month date))
1018 (extract-calendar-year date))
1019 (if (= (extract-calendar-year date)
1020 (extract-calendar-year d))
1021 (format "%s---%s %s"
1022 (calendar-month-name
1023 (extract-calendar-month date))
1024 (calendar-month-name
1025 (extract-calendar-month d))
1026 (extract-calendar-year date))
1027 (format "%s %s---%s %s"
1028 (calendar-month-name
1029 (extract-calendar-month date))
1030 (extract-calendar-year date)
1031 (calendar-month-name (extract-calendar-month d))
1032 (extract-calendar-year d))))))
1034 (calendar-for-loop j from 1 to 7 do
1036 (insert "\\rightday")
1037 (insert "\\leftday"))
1038 (cal-tex-arg (calendar-day-name date))
1039 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1040 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1041 (cal-tex-arg (cal-tex-latexify-list holidays date))
1042 (cal-tex-arg (eval cal-tex-daily-string))
1044 (setq date (cal-tex-incr-date date)))
1047 (run-hooks 'cal-tex-week-hook)
1048 (cal-tex-newpage))))
1049 (cal-tex-end-document)
1050 (run-hooks 'cal-tex-hook)))
1052 (defun cal-tex-cursor-filofax-week (&optional arg)
1053 "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
1054 Optional prefix argument specifies number of weeks.
1055 Weeks start on Monday.
1056 Diary entries are included if `cal-tex-diary' is t.
1057 Holidays are included if `cal-tex-holidays' is t."
1059 (let* ((n (if arg arg 1))
1060 (date (calendar-gregorian-from-absolute
1061 (calendar-dayname-on-or-before
1063 (calendar-absolute-from-gregorian
1064 (calendar-cursor-to-date t)))))
1065 (month (extract-calendar-month date))
1066 (year (extract-calendar-year date))
1067 (day (extract-calendar-day date))
1068 (holidays (if cal-tex-holidays
1069 (cal-tex-list-holidays
1070 (calendar-absolute-from-gregorian date)
1072 (calendar-absolute-from-gregorian date)))))
1073 (diary-list (if cal-tex-diary
1074 (cal-tex-list-diary-entries
1075 (calendar-absolute-from-gregorian
1076 (list month 1 year))
1078 (calendar-absolute-from-gregorian date))))))
1079 (cal-tex-preamble "twoside")
1080 (cal-tex-cmd "\\textwidth 3.25in")
1081 (cal-tex-cmd "\\textheight 6.5in")
1082 (cal-tex-cmd "\\oddsidemargin 1.75in")
1083 (cal-tex-cmd "\\evensidemargin 1.5in")
1084 (cal-tex-cmd "\\topmargin 0pt")
1085 (cal-tex-cmd "\\headheight -0.875in")
1086 (cal-tex-cmd "\\headsep 0.125in")
1087 (cal-tex-cmd "\\footskip .125in")
1088 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1089 \\long\\def\\rightday#1#2#3#4#5{%
1090 \\rule{\\textwidth}{0.3pt}\\\\%
1091 \\hbox to \\textwidth{%
1094 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1095 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1096 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1097 \\long\\def\\weekend#1#2#3#4#5{%
1098 \\rule{\\textwidth}{0.3pt}\\\\%
1099 \\hbox to \\textwidth{%
1102 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1103 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1104 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1105 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1106 \\long\\def\\leftday#1#2#3#4#5{%
1107 \\rule{\\textwidth}{0.3pt}\\\\%
1108 \\hbox to \\textwidth{%
1111 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1112 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1113 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1115 (cal-tex-b-document)
1116 (cal-tex-cmd "\\pagestyle{empty}\\ ")
1118 (calendar-for-loop i from 1 to n do
1119 (insert "\\lefthead")
1121 (let ((d (cal-tex-incr-date date 2)))
1122 (if (= (extract-calendar-month date)
1123 (extract-calendar-month d))
1125 (calendar-month-name
1126 (extract-calendar-month date))
1127 (extract-calendar-year date))
1128 (if (= (extract-calendar-year date)
1129 (extract-calendar-year d))
1130 (format "%s---%s %s"
1131 (calendar-month-name
1132 (extract-calendar-month date))
1133 (calendar-month-name
1134 (extract-calendar-month d))
1135 (extract-calendar-year date))
1136 (format "%s %s---%s %s"
1137 (calendar-month-name
1138 (extract-calendar-month date))
1139 (extract-calendar-year date)
1140 (calendar-month-name (extract-calendar-month d))
1141 (extract-calendar-year d))))))
1143 (calendar-for-loop j from 1 to 3 do
1144 (insert "\\leftday")
1145 (cal-tex-arg (calendar-day-name date))
1146 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1147 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1148 (cal-tex-arg (cal-tex-latexify-list holidays date))
1149 (cal-tex-arg (eval cal-tex-daily-string))
1151 (setq date (cal-tex-incr-date date)))
1152 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1154 (insert "\\righthead")
1156 (let ((d (cal-tex-incr-date date 3)))
1157 (if (= (extract-calendar-month date)
1158 (extract-calendar-month d))
1160 (calendar-month-name
1161 (extract-calendar-month date))
1162 (extract-calendar-year date))
1163 (if (= (extract-calendar-year date)
1164 (extract-calendar-year d))
1165 (format "%s---%s %s"
1166 (calendar-month-name
1167 (extract-calendar-month date))
1168 (calendar-month-name
1169 (extract-calendar-month d))
1170 (extract-calendar-year date))
1171 (format "%s %s---%s %s"
1172 (calendar-month-name
1173 (extract-calendar-month date))
1174 (extract-calendar-year date)
1175 (calendar-month-name (extract-calendar-month d))
1176 (extract-calendar-year d))))))
1178 (calendar-for-loop j from 1 to 2 do
1179 (insert "\\rightday")
1180 (cal-tex-arg (calendar-day-name date))
1181 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1182 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1183 (cal-tex-arg (cal-tex-latexify-list holidays date))
1184 (cal-tex-arg (eval cal-tex-daily-string))
1186 (setq date (cal-tex-incr-date date)))
1187 (calendar-for-loop j from 1 to 2 do
1188 (insert "\\weekend")
1189 (cal-tex-arg (calendar-day-name date))
1190 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1191 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1192 (cal-tex-arg (cal-tex-latexify-list holidays date))
1193 (cal-tex-arg (eval cal-tex-daily-string))
1195 (setq date (cal-tex-incr-date date)))
1198 (run-hooks 'cal-tex-week-hook)
1199 (cal-tex-newpage))))
1200 (cal-tex-end-document)
1201 (run-hooks 'cal-tex-hook)))
1203 (defun cal-tex-cursor-filofax-daily (&optional arg)
1204 "Day-per-page Filofax style calendar for week indicated by cursor.
1205 Optional prefix argument specifies number of weeks. Weeks start on Monday.
1206 Diary entries are included if `cal-tex-diary' is t.
1207 Holidays are included if `cal-tex-holidays' is t."
1209 (let* ((n (if arg arg 1))
1210 (date (calendar-gregorian-from-absolute
1211 (calendar-dayname-on-or-before
1213 (calendar-absolute-from-gregorian
1214 (calendar-cursor-to-date t)))))
1215 (month (extract-calendar-month date))
1216 (year (extract-calendar-year date))
1217 (day (extract-calendar-day date))
1218 (holidays (if cal-tex-holidays
1219 (cal-tex-list-holidays
1220 (calendar-absolute-from-gregorian date)
1222 (calendar-absolute-from-gregorian date)))))
1223 (diary-list (if cal-tex-diary
1224 (cal-tex-list-diary-entries
1225 (calendar-absolute-from-gregorian
1226 (list month 1 year))
1228 (calendar-absolute-from-gregorian date))))))
1229 (cal-tex-preamble "twoside")
1230 (cal-tex-cmd "\\textwidth 3.25in")
1231 (cal-tex-cmd "\\textheight 6.5in")
1232 (cal-tex-cmd "\\oddsidemargin 1.75in")
1233 (cal-tex-cmd "\\evensidemargin 1.5in")
1234 (cal-tex-cmd "\\topmargin 0pt")
1235 (cal-tex-cmd "\\headheight -0.875in")
1236 (cal-tex-cmd "\\headsep 0.125in")
1237 (cal-tex-cmd "\\footskip .125in")
1238 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1239 \\long\\def\\rightday#1#2#3{%
1240 \\rule{\\textwidth}{0.3pt}\\\\%
1241 \\hbox to \\textwidth{%
1244 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1245 \\hbox to \\textwidth{\\vbox {\\raggedleft \\em #2}}%
1246 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #1}}}}}
1247 \\long\\def\\weekend#1#2#3{%
1248 \\rule{\\textwidth}{0.3pt}\\\\%
1249 \\hbox to \\textwidth{%
1252 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1253 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1254 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #1}}}}}
1255 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1256 \\long\\def\\leftday#1#2#3{%
1257 \\rule{\\textwidth}{0.3pt}\\\\%
1258 \\hbox to \\textwidth{%
1261 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1262 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1263 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #1}}}}}
1265 (cal-tex-b-document)
1266 (cal-tex-cmd "\\pagestyle{empty}")
1267 (calendar-for-loop i from 1 to n do
1268 (calendar-for-loop j from 1 to 5 do
1269 (insert (if (oddp j) "\\righthead" "\\lefthead"))
1270 (cal-tex-arg (calendar-date-string date))
1272 (insert (if (oddp j) "\\rightday" "\\leftday"))
1273 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1274 (cal-tex-arg (cal-tex-latexify-list holidays date))
1275 (cal-tex-arg (eval cal-tex-daily-string))
1277 (insert "\\vfill\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1279 (setq date (cal-tex-incr-date date)))
1281 (calendar-for-loop j from 1 to 2 do
1282 (insert "\\lefthead")
1283 (cal-tex-arg (calendar-date-string date))
1284 (insert "\\weekend")
1285 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1286 (cal-tex-arg (cal-tex-latexify-list holidays date))
1287 (cal-tex-arg (eval cal-tex-daily-string))
1290 (setq date (cal-tex-incr-date date)))
1291 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1294 (run-hooks 'cal-tex-week-hook)
1295 (cal-tex-newpage))))
1296 (cal-tex-end-document)
1297 (run-hooks 'cal-tex-hook)))
1304 (defun cal-tex-cursor-day (&optional arg)
1305 "Make a buffer with LaTeX commands for the day cursor is on.
1306 Optional prefix argument specifies number of days."
1308 (let ((n (if arg arg 1))
1309 (date (calendar-absolute-from-gregorian (calendar-cursor-to-date t))))
1310 (cal-tex-preamble "12pt")
1311 (cal-tex-cmd "\\textwidth 6.5in")
1312 (cal-tex-cmd "\\textheight 10.5in")
1313 (cal-tex-b-document)
1314 (cal-tex-cmd "\\pagestyle{empty}")
1315 (calendar-for-loop i from 1 to n do
1316 (cal-tex-vspace "-1.7in")
1317 (cal-tex-daily-page (calendar-gregorian-from-absolute date))
1318 (setq date (1+ date))
1322 (run-hooks 'cal-tex-daily-hook))))
1323 (cal-tex-end-document)
1324 (run-hooks 'cal-tex-hook)))
1326 (defun cal-tex-daily-page (date)
1327 "Make a calendar page for Gregorian DATE on 8.5 by 11 paper."
1329 (month-name (calendar-month-name (extract-calendar-month date))))
1330 (cal-tex-banner "cal-tex-daily-page")
1331 (cal-tex-b-makebox "4cm" "l")
1332 (cal-tex-b-parbox "b" "3.8cm")
1333 (cal-tex-rule "0mm" "0mm" "2cm")
1334 (cal-tex-Huge (number-to-string (extract-calendar-day date)))
1336 (cal-tex-bf month-name )
1338 (cal-tex-hspace "1cm")
1339 (cal-tex-scriptsize (eval cal-tex-daily-string))
1340 (cal-tex-hspace "3.5cm")
1343 (cal-tex-b-makebox "4cm" "r")
1344 (cal-tex-bf (calendar-day-name date))
1347 (cal-tex-hspace ".4cm")
1348 (cal-tex-rule "0mm" "16.1cm" "1mm")
1350 (calendar-for-loop i from cal-tex-daily-start to cal-tex-daily-end do
1351 (cal-tex-cmd "\\noindent")
1352 (setq hour (if cal-tex-24
1355 (if (= 0 hour) (setq hour 12))
1356 (cal-tex-b-makebox "1cm" "c")
1357 (cal-tex-arg (number-to-string hour))
1359 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1361 (cal-tex-b-makebox "1cm" "c")
1362 (cal-tex-arg "$\\diamond$" )
1364 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1365 (cal-tex-nl ".2cm"))
1367 (insert (cal-tex-mini-calendar
1368 (extract-calendar-month (cal-tex-previous-month date))
1369 (extract-calendar-year (cal-tex-previous-month date))
1370 "lastmonth" "1.1in" "1in"))
1371 (insert (cal-tex-mini-calendar
1372 (extract-calendar-month date)
1373 (extract-calendar-year date)
1374 "thismonth" "1.1in" "1in"))
1375 (insert (cal-tex-mini-calendar
1376 (extract-calendar-month (cal-tex-next-month date))
1377 (extract-calendar-year (cal-tex-next-month date))
1378 "nextmonth" "1.1in" "1in"))
1379 (insert "\\hbox to \\textwidth{")
1381 (insert "\\lastmonth")
1383 (insert "\\thismonth")
1385 (insert "\\nextmonth")
1388 (cal-tex-banner "end of cal-tex-daily-page")))
1394 (defun cal-tex-mini-calendar (month year name width height &optional ptsize colsep)
1395 "Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT.
1396 Optional PTSIZE gives the point ptsize; scriptsize is the default. Optional
1397 COLSEP gives the column separation; 1mm is the default."
1398 (let* ((blank-days;; at start of month
1400 (- (calendar-day-of-week (list month 1 year))
1401 calendar-week-start-day)
1403 (last (calendar-last-day-of-month month year))
1404 (colsep (if colsep colsep "1mm"))
1405 (str (concat "\\def\\" name "{\\hbox to" width "{%\n"
1406 "\\vbox to" height "{%\n"
1407 "\\vfil \\hbox to" width "{%\n"
1409 (if ptsize ptsize "scriptsize")
1411 "{@{\\hspace{0mm}}r@{\\hspace{" colsep
1412 "}}r@{\\hspace{" colsep "}}r@{\\hspace{" colsep
1413 "}}r@{\\hspace{" colsep "}}r@{\\hspace{" colsep
1414 "}}r@{\\hspace{" colsep "}}r@{\\hspace{0mm}}}%\n"
1415 "\\multicolumn{7}{c}{"
1416 (calendar-month-name month)
1418 (int-to-string year)
1420 (calendar-for-loop i from 0 to 6 do
1421 (setq str (concat str
1422 (substring (aref calendar-day-name-array
1423 (mod (+ calendar-week-start-day i) 7))
1428 (calendar-for-loop i from 1 to blank-days do
1429 (setq str (concat str " & ")))
1430 (calendar-for-loop i from 1 to last do
1431 (setq str (concat str (int-to-string i)))
1432 (setq str (concat str (if (zerop (mod (+ i blank-days) 7))
1433 (if (/= i last) "\\\\[0.5mm]\n" "")
1435 (setq str (concat str "\n\\end{tabular}\\hfil}\\vfil}}}%\n"))
1439 ;;; Various calendar functions
1442 (defun cal-tex-incr-date (date &optional n)
1443 "The date of the day following DATE.
1444 If optional N is given, the date of N days after DATE."
1445 (calendar-gregorian-from-absolute
1446 (+ (if n n 1) (calendar-absolute-from-gregorian date))))
1448 (defun cal-tex-latexify-list (date-list date &optional separator)
1449 "Return string with concatenated, LaTeXified entries in DATE_LIST for DATE.
1450 Use double backslash as a separator unless optional SEPARATOR is given."
1451 (mapconcat '(lambda (x) (cal-tex-LaTeXify-string x))
1456 (calendar-date-equal date (car (car p)))
1457 (setq result (append result (cdr (car p)))))
1460 (if separator separator "\\\\")))
1462 (defun cal-tex-previous-month (date)
1463 "Return the date of the first day in the month previous to DATE."
1464 (let* ((month (extract-calendar-month date))
1465 (year (extract-calendar-year date)))
1466 (increment-calendar-month month year -1)
1467 (list month 1 year)))
1469 (defun cal-tex-next-month (date)
1470 "Return the date of the first day in the month following DATE."
1471 (let* ((month (extract-calendar-month date))
1472 (year (extract-calendar-year date)))
1473 (increment-calendar-month month year 1)
1474 (list month 1 year)))
1480 (defun cal-tex-end-document ()
1481 "Finish the LaTeX document.
1482 Insert the trailer to LaTeX document, pop to LaTeX buffer, add
1483 informative header, and run HOOK."
1484 (cal-tex-e-document)
1486 (pop-to-buffer cal-tex-buffer)
1487 (goto-char (point-min))
1488 (cal-tex-comment " This buffer was produced by cal-tex.el.")
1489 (cal-tex-comment " To print a calendar, type")
1490 (cal-tex-comment " M-x tex-buffer RET")
1491 (cal-tex-comment " M-x tex-print RET")
1492 (goto-char (point-min)))
1494 (defun cal-tex-insert-preamble (weeks landscape size &optional append)
1495 "Initialize the output buffer.
1496 Select the output buffer, and insert the preamble for a calendar of
1497 WEEKS weeks. Insert code for landscape mode if LANDSCAPE is true.
1498 Use pointsize SIZE. Optional argument APPEND, if t, means add to end of
1499 without erasing current contents."
1500 (let ((width "18cm")
1505 (setq height "18cm")))
1508 (cal-tex-preamble size)
1511 (cal-tex-cmd "\\oddsidemargin -1.75cm")
1512 (cal-tex-cmd "\\def\\holidaymult{.06}"))
1513 (cal-tex-cmd "\\special{landscape}")
1514 (cal-tex-cmd "\\textwidth 9.5in")
1515 (cal-tex-cmd "\\textheight 7in")
1517 (cal-tex-cmd "\\def\\holidaymult{.08}"))
1518 (cal-tex-cmd cal-tex-caldate)
1519 (cal-tex-cmd cal-tex-myday)
1520 (cal-tex-b-document)
1521 (cal-tex-cmd "\\pagestyle{empty}")))
1522 (cal-tex-cmd "\\setlength{\\cellwidth}" width)
1523 (insert (format "\\setlength{\\cellwidth}{%f\\cellwidth}\n"
1524 (/ 1.1 (length cal-tex-which-days))))
1525 (cal-tex-cmd "\\setlength{\\cellheight}" height)
1526 (insert (format "\\setlength{\\cellheight}{%f\\cellheight}\n"
1528 (cal-tex-cmd "\\ \\par")
1529 (cal-tex-vspace "-3cm")))
1531 (defvar cal-tex-LaTeX-subst-list
1533 ("\"". "''");; Quote changes meaning when list is reversed.
1544 ("\n" . "\\ \\\\")) ;\\ needed for e.g \begin{center}\n AA\end{center}
1545 "List of symbols and their replacements.")
1547 (defun cal-tex-LaTeXify-string (string)
1548 "Protect special characters in STRING from LaTeX."
1553 (list cal-tex-LaTeX-subst-list))
1554 (while (not (string-equal tail ""))
1555 (let* ((ch (substring tail 0 1))
1556 (pair (assoc ch list)))
1557 (if (and pair (string-equal ch "\""))
1558 (setq list (reverse list)));; Quote changes meaning each time.
1559 (setq tail (substring tail 1))
1560 (setq head (concat head (if pair (cdr pair) ch)))))
1563 (defun cal-tex-hfill () "Insert hfill." (insert "\\hfill"))
1565 (defun cal-tex-newpage () "Insert newpage." (insert "\\newpage%\n"))
1567 (defun cal-tex-noindent () "Insert noindent." (insert "\\noindent"))
1569 (defun cal-tex-vspace (space)
1570 "Insert vspace command to move SPACE vertically."
1571 (insert "\\vspace*{" space "}")
1574 (defun cal-tex-hspace (space)
1575 "Insert hspace command to move SPACE horizontally."
1576 (insert "\\hspace*{" space "}")
1579 (defun cal-tex-comment (&optional comment)
1580 "Insert % at end of line, include COMMENT if present, and move
1587 (defun cal-tex-banner (comment)
1588 "Insert the COMMENT separated by blank lines."
1591 (cal-tex-comment (concat "\t\t\t" comment))
1595 (defun cal-tex-nl (&optional skip comment)
1596 "End a line with \\. If SKIP, then add that much spacing.
1597 Add COMMENT if present"
1600 (insert "[" skip "]"))
1601 (cal-tex-comment comment))
1603 (defun cal-tex-arg (&optional text)
1604 "Insert optional TEXT surrounded by braces."
1606 (if text (insert text))
1609 (defun cal-tex-cmd (cmd &optional arg)
1610 "Insert LaTeX CMD, with optional ARG, and end with %"
1619 (defun cal-tex-b-document ()
1620 "Insert beginning of document."
1621 (cal-tex-cmd "\\begin{document}"))
1623 (defun cal-tex-e-document ()
1624 "Insert end of document."
1625 (cal-tex-cmd "\\end{document}"))
1627 (defun cal-tex-b-center ()
1628 "Insert beginning of centered block."
1629 (cal-tex-cmd "\\begin{center}"))
1631 (defun cal-tex-e-center ()
1632 "Insert end of centered block."
1634 (cal-tex-cmd "\\end{center}"))
1642 (defun cal-tex-b-parbox (position width)
1643 "Insert parbox with parameters POSITION and WIDTH."
1644 (insert "\\parbox[" position "]{" width "}{")
1647 (defun cal-tex-e-parbox (&optional height)
1648 "Insert end of parbox. Force it to be a given HEIGHT."
1651 (cal-tex-rule "0mm" "0mm" height))
1653 (cal-tex-comment "end parbox"))
1655 (defun cal-tex-b-framebox ( width position )
1656 "Insert framebox with parameters WIDTH and POSITION (clr)."
1657 (insert "\\framebox[" width "][" position "]{" )
1660 (defun cal-tex-e-framebox ()
1661 "Insert end of framebox."
1664 (cal-tex-comment "end framebox"))
1667 (defun cal-tex-b-makebox ( width position )
1668 "Insert makebox with parameters WIDTH and POSITION (clr)."
1669 (insert "\\makebox[" width "][" position "]{" )
1672 (defun cal-tex-e-makebox ()
1673 "Insert end of makebox."
1676 (cal-tex-comment "end makebox"))
1679 (defun cal-tex-rule (lower width height)
1680 "Insert a rule with parameters LOWER WIDTH HEIGHT."
1681 (insert "\\rule[" lower "]{" width "}{" height "}"))
1687 (defun cal-tex-em (string)
1688 "Insert STRING in bf font."
1689 (insert "{\\em " string "}"))
1691 (defun cal-tex-bf (string)
1692 "Insert STRING in bf font."
1693 (insert "{\\bf " string "}"))
1695 (defun cal-tex-scriptsize (string)
1696 "Insert STRING in scriptsize font."
1697 (insert "{\\scriptsize " string "}"))
1699 (defun cal-tex-huge (string)
1700 "Insert STRING in huge size."
1701 (insert "{\\huge " string "}"))
1703 (defun cal-tex-Huge (string)
1704 "Insert STRING in Huge size."
1705 (insert "{\\Huge " string "}"))
1707 (defun cal-tex-Huge-bf (string)
1708 "Insert STRING in Huge bf size."
1709 (insert "{\\Huge\\bf " string "}"))
1711 (defun cal-tex-large (string)
1712 "Insert STRING in large size."
1713 (insert "{\\large " string "}"))
1715 (defun cal-tex-large-bf (string)
1716 "Insert STRING in large bf size."
1717 (insert "{\\large\\bf " string "}"))
1721 ;;; cal-tex.el ends here