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 daily and monthly styles Filofax paper.
42 ;; (*) Improve the LaTeX command that produces the boxes in the monthly
43 ;; calendar to eliminate slight gap--what causes it?!
49 (autoload 'list-diary-entries "diary-lib" nil t)
50 (autoload 'calendar-holiday-list "holidays" nil t)
51 (autoload 'calendar-iso-from-absolute "cal-iso" nil t)
54 ;;; Customizable variables
57 (defvar cal-tex-which-days '(0 1 2 3 4 5 6)
58 "*The days of the week that are displayed on the portrait monthly calendar.
59 Sunday is 0, Monday is 1, and so on. The default is to print from Sunday to
60 Saturday. For example, use
62 (setq cal-tex-which-days '(1 3 5))
64 to only print Monday, Wednesday, Friday.")
66 (defvar cal-tex-holidays t
67 "*If t (default), then the holidays are also printed.
68 If finding the holidays is too slow, set this to nil.")
70 (defvar cal-tex-diary nil
71 "*If t, the diary entries are printed in the calendar.")
73 (defvar cal-tex-daily-string
74 '(let* ((year (extract-calendar-year date))
75 (day (calendar-day-number date))
76 (days-remaining (- (calendar-day-number (list 12 31 year)) day)))
77 (format "%d/%d" day days-remaining))
78 "*An expression in the variable `date' whose value is placed on date.
79 The string resulting from evaluating this expression is placed at the bottom
80 center of `date' on the monthly calendar, next to the date in the weekly
81 calendars, and in the top center of daily calendars.
83 Default is ordinal day number of the year and the number of days remaining.
84 As an example of what you do, setting this to
88 (calendar-hebrew-date-string date))
90 will put the Hebrew date at the bottom of each day.")
92 (defvar cal-tex-buffer "calendar.tex"
93 "*The name for the tex-ed calendar.")
95 (defvar cal-tex-24 nil
96 "*If t, use a 24 hour clock in the daily calendar.")
98 (defvar cal-tex-daily-start 8
99 "*The first hour of the daily calendar page.")
101 (defvar cal-tex-daily-end 20
102 "*The last hour of the daily calendar page.")
105 ;;; Definitions for LaTeX code
108 (defvar cal-tex-day-prefix "\\caldate{%s}{%s}"
109 "The initial LaTeX code for a day.
110 The holidays, diary entries, bottom string, and the text follow.")
112 (defvar cal-tex-day-name-format "\\myday{%s}%%"
113 "The format for LaTeX code for a day name. The names are taken from
114 calendar-day-name-array.")
116 (defvar cal-tex-cal-one-month
117 "\\def\\calmonth#1#2%
119 \\Huge\\bf\\uppercase{#1} #2 \\\\[1cm]%
124 "LaTeX code for the month header")
126 (defvar cal-tex-cal-multi-month
127 "\\def\\calmonth#1#2#3#4%
129 \\Huge\\bf #1 #2---#3 #4\\\\[1cm]%
134 "LaTeX code for the month header")
136 (defvar cal-tex-myday
137 "\\renewcommand{\\myday}[1]%
138 {\\makebox[\\cellwidth]{\\hfill\\large\\bf#1\\hfill}}
141 "LaTeX code for a day heading")
143 (defvar cal-tex-caldate
145 \\long\\def\\caldate#1#2#3#4#5#6{%
146 \\fbox{\\hbox to\\cellwidth{%
147 \\vbox to\\cellheight{%
148 \\hbox to\\cellwidth{%
149 {\\hspace*{1mm}\\Large \\bf \\strut #2}\\hspace{.05\\cellwidth}%
150 \\raisebox{\\holidaymult\\cellheight}%
151 {\\parbox[t]{.75\\cellwidth}{\\tiny \\raggedright #4}}}
152 \\hbox to\\cellwidth{%
153 \\hspace*{1mm}\\parbox{.95\\cellwidth}{\\tiny \\raggedright #3}}
155 \\hbox to\\cellwidth{#6}%
157 \\hbox to\\cellwidth{\\hfill \\tiny #5 \\hfill}%
161 "LaTeX code to insert one box with date info in calendar.
162 This definition is the heart of the calendar!")
164 (defun cal-tex-list-holidays (d1 d2)
165 "Generate a list of all holidays from absolute date D1 to D2."
167 (start (calendar-gregorian-from-absolute d1))
168 (start-month (extract-calendar-month start))
169 (start-year (extract-calendar-year start)))
170 (increment-calendar-month start-month start-year 1)
171 (let* ((end (calendar-gregorian-from-absolute d2))
172 (end-month (extract-calendar-month end))
173 (end-year (extract-calendar-year end)))
174 (if (= (extract-calendar-day end) 1)
175 (increment-calendar-month end-month end-year -1))
176 (let* ((s (calendar-absolute-from-gregorian
177 (list start-month 1 start-year)))
178 (e (calendar-absolute-from-gregorian
179 (list end-month 1 end-year)))
182 (displayed-month start-month)
183 (displayed-year start-year))
184 (while (or never (<= d e))
185 (setq result (append result (calendar-holiday-list)))
187 (increment-calendar-month displayed-month displayed-year 3)
188 (setq d (calendar-absolute-from-gregorian
189 (list displayed-month 1 displayed-year))))))
194 (let ((a (calendar-absolute-from-gregorian (car (car p)))))
195 (and (<= d1 a) (<= a d2)))
196 (setq in-range (append (list (car p)) in-range)))
200 (defun cal-tex-list-diary-entries (d1 d2)
201 "Generate a list of all diary-entries from absolute date D1 to D2."
202 (let ((diary-display-hook nil))
204 (calendar-gregorian-from-absolute d1)
207 (defun cal-tex-preamble (&optional args)
208 "Insert the LaTeX preamble.
209 Preamble Includes initial definitions for various LaTeX commands.
210 Optional ARGS are included."
211 (set-buffer (get-buffer-create cal-tex-buffer))
213 (insert "\\documentstyle")
215 (insert "[" args "]"))
216 (insert "{article}\n"
221 \\evensidemargin -2cm
226 \\newlength{\\cellwidth}
227 \\newlength{\\cellheight}
228 \\newlength{\\boxwidth}
229 \\newlength{\\boxheight}
230 \\newlength{\\cellsize}
231 \\newcommand{\\myday}[1]{}
232 \\newcommand{\\caldate}[6]{}
233 \\newcommand{\\nocaldate}[6]{}
234 \\newcommand{\\calsmall}[6]{}
242 (defun cal-tex-cursor-year (&optional arg)
243 "Make a buffer with LaTeX commands for the year cursor is on.
244 Optional prefix argument specifies number of years."
246 (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
249 (defun cal-tex-cursor-year-landscape (&optional arg)
250 "Make a buffer with LaTeX commands for the year cursor is on.
251 Optional prefix argument specifies number of years."
253 (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
257 (defun cal-tex-year (year n &optional landscape)
258 "Make a one page yearly calendar of YEAR; do this for N years.
259 There are four rows of three months each, unless optional LANDSCAPE is t,
260 in which case the calendar isprinted in landscape mode with three rows of
262 (cal-tex-insert-preamble 1 landscape "12pt")
264 (cal-tex-vspace "-.6cm")
265 (cal-tex-vspace "-3.1cm"))
266 (calendar-for-loop j from 1 to n do
267 (insert "\\vfill%\n")
269 (cal-tex-Huge (number-to-string year))
271 (cal-tex-vspace "1cm")
273 (cal-tex-b-parbox "l" (if landscape "5.9in" "4.3in"))
277 (calendar-for-loop i from 1 to 12 do
278 (insert (cal-tex-mini-calendar i year "month" "1.1in" "1in"))
280 (cal-tex-hspace "0.5in")
281 (if (zerop (mod i (if landscape 4 3)))
282 (cal-tex-nl "0.5in")))
285 (insert "\\vfill%\n")
286 (setq year (1+ year))
289 (cal-tex-end-document))
290 (run-hooks 'cal-tex-year-hook))
291 (run-hooks 'cal-tex-hook))
293 (defun cal-tex-cursor-filofax-year (&optional arg)
294 "Make a Filofax one page yearly calendar of year indicated by cursor.
295 Optional parameter specifies number of years."
297 (let* ((n (if arg arg 1))
298 (year (extract-calendar-year (calendar-cursor-to-date t))))
299 (cal-tex-preamble "twoside")
300 (cal-tex-cmd "\\textwidth 3.25in")
301 (cal-tex-cmd "\\textheight 6.5in")
302 (cal-tex-cmd "\\oddsidemargin 1.6in")
303 (cal-tex-cmd "\\evensidemargin 1.55in")
304 (cal-tex-cmd "\\topmargin 0pt")
305 (cal-tex-cmd "\\headheight -0.875in")
306 (cal-tex-cmd "\\pagestyle{empty}")
308 (calendar-for-loop j from 1 to n do
309 (insert (format "\\hfil {\\Large \\bf %s} \\hfil\\\\\n" year))
311 (cal-tex-b-parbox "l" "\\textwidth")
315 (calendar-for-loop i from 1 to 12 do
316 (insert (cal-tex-mini-calendar i year
317 (calendar-month-name i)
318 "1.05in" ".8in" "tiny")))
320 "\\noindent\\fbox{\\January}\\fbox{\\February}\\fbox{\\March}\\\\
321 \\noindent\\fbox{\\April}\\fbox{\\May}\\fbox{\\June}\\\\
322 \\noindent\\fbox{\\July}\\fbox{\\August}\\fbox{\\September}\\\\
323 \\noindent\\fbox{\\October}\\fbox{\\November}\\fbox{\\December}
327 (setq year (1+ year))
330 (cal-tex-end-document))
331 (run-hooks 'cal-tex-year-hook))
332 (run-hooks 'cal-tex-hook)))
335 ;;; Monthly calendars
338 (defun cal-tex-cursor-month-landscape (&optional arg)
339 "Make a buffer with LaTeX commands for the month cursor is on.
340 Optional prefix argument specifies number of months to be produced.
341 The output is in landscape format, one month to a page."
343 (let* ((n (if arg arg 1))
344 (date (calendar-cursor-to-date t))
345 (month (extract-calendar-month date))
346 (year (extract-calendar-year date))
349 (cal-tex-which-days '(0 1 2 3 4 5 6)))
350 (increment-calendar-month end-month end-year (1- n))
351 (let ((diary-list (if cal-tex-diary
352 (cal-tex-list-diary-entries
353 (calendar-absolute-from-gregorian
355 (calendar-absolute-from-gregorian
357 (calendar-last-day-of-month
360 (holidays (if cal-tex-holidays
361 (cal-tex-list-holidays
362 (calendar-absolute-from-gregorian
364 (calendar-absolute-from-gregorian
366 (calendar-last-day-of-month end-month end-year)
370 (small-months-at-start))
371 (cal-tex-insert-preamble (cal-tex-number-weeks month year 1) t "12pt")
372 (cal-tex-cmd cal-tex-cal-one-month)
373 (calendar-for-loop i from 1 to n do
374 (setq other-month month)
375 (setq other-year year)
376 (increment-calendar-month other-month other-year -1)
377 (insert (cal-tex-mini-calendar other-month other-year "lastmonth"
378 "\\cellwidth" "\\cellheight"))
379 (increment-calendar-month other-month other-year 2)
380 (insert (cal-tex-mini-calendar other-month other-year "nextmonth"
381 "\\cellwidth" "\\cellheight"))
382 (cal-tex-insert-month-header 1 month year month year)
383 (cal-tex-insert-day-names)
385 (setq small-months-at-start
386 (< 1 (mod (- (calendar-day-of-week (list month 1 year))
387 calendar-week-start-day)
389 (if small-months-at-start
390 (insert "\\lastmonth\\nextmonth\\hspace*{-2\\cellwidth}"))
391 (cal-tex-insert-blank-days month year cal-tex-day-prefix)
392 (cal-tex-insert-days month year diary-list holidays
394 (cal-tex-insert-blank-days-at-end month year cal-tex-day-prefix)
395 (if (and (not small-months-at-start)
396 (< 1 (mod (- (1- calendar-week-start-day)
397 (calendar-day-of-week
399 (calendar-last-day-of-month month year)
402 (insert "\\vspace*{-\\cellwidth}\\hspace*{-2\\cellwidth}"
403 "\\lastmonth\\nextmonth"))
406 (run-hooks 'cal-tex-month-hook)
408 (increment-calendar-month month year 1)
409 (cal-tex-vspace "-2cm")
410 (cal-tex-insert-preamble
411 (cal-tex-number-weeks month year 1) t "12pt" t))))
412 (cal-tex-end-document)
413 (run-hooks 'cal-tex-hook))))
415 (defun cal-tex-cursor-month (arg)
416 "Make a buffer with LaTeX commands for the month cursor is on.
417 Optional prefix argument specifies number of months to be produced.
418 Calendar is condensed onto one page."
420 (let* ((date (calendar-cursor-to-date t))
421 (month (extract-calendar-month date))
422 (year (extract-calendar-year date))
426 (increment-calendar-month end-month end-year (1- n))
427 (let ((diary-list (if cal-tex-diary
428 (cal-tex-list-diary-entries
429 (calendar-absolute-from-gregorian
431 (calendar-absolute-from-gregorian
433 (calendar-last-day-of-month
436 (holidays (if cal-tex-holidays
437 (cal-tex-list-holidays
438 (calendar-absolute-from-gregorian
440 (calendar-absolute-from-gregorian
442 (calendar-last-day-of-month end-month end-year)
446 (cal-tex-insert-preamble (cal-tex-number-weeks month year n) nil"12pt")
448 (cal-tex-cmd cal-tex-cal-multi-month)
449 (cal-tex-cmd cal-tex-cal-one-month))
450 (cal-tex-insert-month-header n month year end-month end-year)
451 (cal-tex-insert-day-names)
453 (cal-tex-insert-blank-days month year cal-tex-day-prefix)
454 (calendar-for-loop i from 1 to n do
455 (setq other-month month)
456 (setq other-year year)
457 (cal-tex-insert-days month year diary-list holidays
459 (increment-calendar-month month year 1))
460 (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix)
461 (cal-tex-end-document)))
462 (run-hooks 'cal-tex-hook))
464 (defun cal-tex-insert-days (month year diary-list holidays day-format)
465 "Insert LaTeX commands for a range of days in monthly calendars.
466 LaTeX commands are inserted for the days of the MONTH in YEAR.
467 Diary entries on DIARY-LIST are included. Holidays on HOLIDAYS are included.
468 Each day is formatted using format DAY-FORMAT."
469 (let* ((blank-days;; at start of month
471 (- (calendar-day-of-week (list month 1 year))
472 calendar-week-start-day)
475 (last (calendar-last-day-of-month month year)))
476 (calendar-for-loop i from 1 to last do
477 (setq date (list month i year))
478 (if (memq (calendar-day-of-week date) cal-tex-which-days)
480 (insert (format day-format (calendar-month-name month) i))
481 (cal-tex-arg (cal-tex-latexify-list diary-list date))
482 (cal-tex-arg (cal-tex-latexify-list holidays date))
483 (cal-tex-arg (eval cal-tex-daily-string))
486 (if (and (zerop (mod (+ i blank-days) 7))
492 (defun cal-tex-insert-day-names ()
493 "Insert the names of the days at top of a monthly calendar."
494 (calendar-for-loop i from 0 to 6 do
495 (if (memq i cal-tex-which-days)
496 (insert (format cal-tex-day-name-format
497 (aref calendar-day-name-array
498 (mod (+ calendar-week-start-day i) 7)))))
501 (defun cal-tex-insert-month-header (n month year end-month end-year)
502 "Create a title for a calendar.
503 A title is inserted for a calendar with N months starting with
504 MONTH YEAR and ending with END-MONTH END-YEAR."
505 (let ( (month-name (calendar-month-name month))
506 (end-month-name (calendar-month-name end-month)))
508 (insert (format "\\calmonth{%s}{%s}\n\\vspace*{-0.5cm}"
510 (insert (format "\\calmonth{%s}{%s}{%s}{%s}\n\\vspace*{-0.5cm}"
511 month-name year end-month-name end-year))))
514 (defun cal-tex-insert-blank-days (month year day-format)
515 "Insert code for initial days not in calendar.
516 Insert LaTeX code for the blank days at the beginning of the MONTH in
517 YEAR. The entry is formatted using DAY-FORMAT. If the entire week is
518 blank, no days are inserted."
519 (if (cal-tex-first-blank-p month year)
520 (let* ((blank-days;; at start of month
522 (- (calendar-day-of-week (list month 1 year))
523 calendar-week-start-day)
525 (calendar-for-loop i from 0 to (1- blank-days) do
526 (if (memq i cal-tex-which-days)
527 (insert (format day-format " " " ") "{}{}{}{}%\n"))))))
529 (defun cal-tex-insert-blank-days-at-end (month year day-format)
530 "Insert code for final days not in calendar.
531 Insert LaTeX code for the blank days at the end of the MONTH in YEAR.
532 The entry is formatted using DAY-FORMAT."
533 (if (cal-tex-last-blank-p month year)
534 (let* ((last-day (calendar-last-day-of-month month year))
535 (blank-days;; at end of month
537 (- (calendar-day-of-week (list month last-day year))
538 calendar-week-start-day)
540 (calendar-for-loop i from (1+ blank-days) to 6 do
541 (if (memq i cal-tex-which-days)
542 (insert (format day-format "" "") "{}{}{}{}%\n"))))))
544 (defun cal-tex-first-blank-p (month year)
545 "Determine if any days of the first week will be printed.
546 Return t if there will there be any days of the first week printed
547 in the calendar starting in MONTH YEAR."
549 (the-saturday)) ;the day of week of 1st Saturday
550 (calendar-for-loop i from 1 to 7 do
551 (if (= 6 (calendar-day-of-week (list month i year)))
552 (setq the-saturday i)))
553 (calendar-for-loop i from 1 to the-saturday do
554 (if (memq (calendar-day-of-week (list month i year))
559 (defun cal-tex-last-blank-p (month year)
560 "Determine if any days of the last week will be printed.
561 Return t if there will there be any days of the last week printed
562 in the calendar starting in MONTH YEAR."
564 (last-day (calendar-last-day-of-month month year))
565 (the-sunday)) ;the day of week of last Sunday
566 (calendar-for-loop i from (- last-day 6) to last-day do
567 (if (= 0 (calendar-day-of-week (list month i year)))
568 (setq the-sunday i)))
569 (calendar-for-loop i from the-sunday to last-day do
570 (if (memq (calendar-day-of-week (list month i year))
575 (defun cal-tex-number-weeks (month year n)
576 "Determine the number of weeks in a range of dates.
577 Compute the number of weeks in the calendar starting with MONTH and YEAR,
578 and lasting N months, including only the days in WHICH-DAYS. As it stands,
579 this is only an upper bound."
580 (let ((d (list month 1 year)))
581 (increment-calendar-month month year (1- n))
582 (/ (- (calendar-dayname-on-or-before
583 calendar-week-start-day
584 (+ 7 (calendar-absolute-from-gregorian
585 (list month (calendar-last-day-of-month month year) year))))
586 (calendar-dayname-on-or-before
587 calendar-week-start-day
588 (calendar-absolute-from-gregorian d)))
595 (defun cal-tex-cursor-week (&optional arg)
596 "Make a buffer with LaTeX commands for a two-page one-week calendar.
597 It applies to the week that point is in.
598 Optional prefix argument specifies number of weeks.
599 Holidays are included if `cal-tex-holidays' is t."
601 (let* ((n (if arg arg 1))
602 (date (calendar-gregorian-from-absolute
603 (calendar-dayname-on-or-before
604 calendar-week-start-day
605 (calendar-absolute-from-gregorian
606 (calendar-cursor-to-date t)))))
607 (month (extract-calendar-month date))
608 (year (extract-calendar-year date))
609 (holidays (if cal-tex-holidays
610 (cal-tex-list-holidays
611 (calendar-absolute-from-gregorian date)
613 (calendar-absolute-from-gregorian date))))))
614 (cal-tex-preamble "11pt")
615 (cal-tex-cmd "\\textwidth 6.5in")
616 (cal-tex-cmd "\\textheight 10.5in")
617 (cal-tex-cmd "\\oddsidemargin 0in")
618 (cal-tex-cmd "\\evensidemargin 0in")
619 (insert cal-tex-LaTeX-hourbox)
621 (cal-tex-cmd "\\pagestyle{empty}")
622 (calendar-for-loop i from 1 to n do
623 (cal-tex-vspace "-1.5in")
625 (cal-tex-Huge-bf (format "\\uppercase{%s}"
626 (calendar-month-name month)))
627 (cal-tex-hspace "2em")
628 (cal-tex-Huge-bf (number-to-string year))
631 (cal-tex-hspace "-.2in")
632 (cal-tex-b-parbox "l" "7in")
633 (calendar-for-loop j from 1 to 7 do
634 (cal-tex-week-hours date holidays "3.1")
635 (setq date (cal-tex-incr-date date)))
637 (setq month (extract-calendar-month date))
638 (setq year (extract-calendar-year date))
641 (run-hooks 'cal-tex-week-hook)
643 (cal-tex-end-document)
644 (run-hooks 'cal-tex-hook)))
646 (defun cal-tex-cursor-week2 (&optional arg)
647 "Make a buffer with LaTeX commands for a two-page one-week calendar.
648 It applies to the week that point is in.
649 Optional prefix argument specifies number of weeks.
650 Holidays are included if `cal-tex-holidays' is t."
652 (let* ((n (if arg arg 1))
653 (date (calendar-gregorian-from-absolute
654 (calendar-dayname-on-or-before
655 calendar-week-start-day
656 (calendar-absolute-from-gregorian
657 (calendar-cursor-to-date t)))))
658 (month (extract-calendar-month date))
659 (year (extract-calendar-year date))
661 (holidays (if cal-tex-holidays
662 (cal-tex-list-holidays
663 (calendar-absolute-from-gregorian date)
665 (calendar-absolute-from-gregorian date))))))
666 (cal-tex-preamble "12pt")
667 (cal-tex-cmd "\\textwidth 6.5in")
668 (cal-tex-cmd "\\textheight 10.5in")
669 (cal-tex-cmd "\\oddsidemargin 0in")
670 (cal-tex-cmd "\\evensidemargin 0in")
671 (insert cal-tex-LaTeX-hourbox)
673 (cal-tex-cmd "\\pagestyle{empty}")
674 (calendar-for-loop i from 1 to n do
675 (cal-tex-vspace "-1.5in")
677 (cal-tex-Huge-bf (format "\\uppercase{%s}"
678 (calendar-month-name month)))
679 (cal-tex-hspace "2em")
680 (cal-tex-Huge-bf (number-to-string year))
683 (cal-tex-hspace "-.2in")
684 (cal-tex-b-parbox "l" "\\textwidth")
685 (calendar-for-loop j from 1 to 3 do
686 (cal-tex-week-hours date holidays "5")
687 (setq date (cal-tex-incr-date date)))
690 (insert (cal-tex-mini-calendar
691 (extract-calendar-month (cal-tex-previous-month date))
692 (extract-calendar-year (cal-tex-previous-month date))
693 "lastmonth" "1.1in" "1in"))
694 (insert (cal-tex-mini-calendar
695 (extract-calendar-month date)
696 (extract-calendar-year date)
697 "thismonth" "1.1in" "1in"))
698 (insert (cal-tex-mini-calendar
699 (extract-calendar-month (cal-tex-next-month date))
700 (extract-calendar-year (cal-tex-next-month date))
701 "nextmonth" "1.1in" "1in"))
702 (insert "\\hbox to \\textwidth{")
704 (insert "\\lastmonth")
706 (insert "\\thismonth")
708 (insert "\\nextmonth")
712 (cal-tex-b-parbox "l" "\\textwidth")
713 (calendar-for-loop j from 4 to 7 do
714 (cal-tex-week-hours date holidays "5")
715 (setq date (cal-tex-incr-date date)))
717 (setq month (extract-calendar-month date))
718 (setq year (extract-calendar-year date))
721 (run-hooks 'cal-tex-week-hook)
723 (cal-tex-end-document)
724 (run-hooks 'cal-tex-hook)))
726 (defun cal-tex-cursor-week-iso (&optional arg)
727 "Make a buffer with LaTeX commands for a one page ISO-style weekly calendar.
728 Optional prefix argument specifies number of weeks.
729 Diary entries are included if `cal-tex-diary' is t.
730 Holidays are included if `cal-tex-holidays' is t."
732 (let* ((n (if arg arg 1))
733 (date (calendar-gregorian-from-absolute
734 (calendar-dayname-on-or-before
736 (calendar-absolute-from-gregorian
737 (calendar-cursor-to-date t)))))
738 (month (extract-calendar-month date))
739 (year (extract-calendar-year date))
740 (day (extract-calendar-day date))
741 (holidays (if cal-tex-holidays
742 (cal-tex-list-holidays
743 (calendar-absolute-from-gregorian date)
745 (calendar-absolute-from-gregorian date)))))
746 (diary-list (if cal-tex-diary
747 (cal-tex-list-diary-entries
748 (calendar-absolute-from-gregorian
751 (calendar-absolute-from-gregorian date))))))
752 (cal-tex-preamble "11pt")
753 (cal-tex-cmd "\\textwidth 6.5in")
754 (cal-tex-cmd "\\textheight 10.5in")
755 (cal-tex-cmd "\\oddsidemargin 0in")
756 (cal-tex-cmd "\\evensidemargin 0in")
758 (cal-tex-cmd "\\pagestyle{empty}")
759 (calendar-for-loop i from 1 to n do
760 (cal-tex-vspace "-1.5in")
763 (let* ((d (calendar-iso-from-absolute
764 (calendar-absolute-from-gregorian date))))
765 (format "Week %d of %d"
766 (extract-calendar-month d)
767 (extract-calendar-year d))))
770 (cal-tex-b-parbox "l" "\\textwidth")
771 (calendar-for-loop j from 1 to 7 do
772 (cal-tex-b-parbox "t" "\\textwidth")
773 (cal-tex-b-parbox "t" "\\textwidth")
774 (cal-tex-rule "0pt" "\\textwidth" ".2mm")
776 (cal-tex-b-parbox "t" "\\textwidth")
777 (cal-tex-large-bf (calendar-day-name date))
779 (cal-tex-large-bf (calendar-month-name month))
781 (cal-tex-large-bf (number-to-string day))
782 (if (not (string= "" (cal-tex-latexify-list holidays date)))
785 (cal-tex-large-bf (cal-tex-latexify-list holidays date "; "))))
787 (insert " " (eval cal-tex-daily-string))
791 (cal-tex-b-parbox "t" "\\textwidth")
792 (if (not (string= "" (cal-tex-latexify-list diary-list date)))
794 (insert "\\vbox to 0pt{")
796 (cal-tex-latexify-list diary-list date))
800 (setq date (cal-tex-incr-date date))
801 (setq month (extract-calendar-month date))
802 (setq day (extract-calendar-day date))
804 (cal-tex-e-parbox "2cm")
806 (setq month (extract-calendar-month date))
807 (setq year (extract-calendar-year date)))
811 (run-hooks 'cal-tex-week-hook)
813 (cal-tex-end-document)
814 (run-hooks 'cal-tex-hook)))
816 (defvar cal-tex-LaTeX-hourbox
817 "\\newcommand{\\hourbox}[2]%
818 {\\makebox[2em]{\\rule{0cm}{#2ex}#1}\\rule{3in}{.15mm}}\n"
819 "One hour and a line on the right.")
821 (defun cal-tex-week-hours (date holidays height)
822 "Insert hourly entries for DATE with HOLIDAYS, with line height HEIGHT."
823 (let ((month (extract-calendar-month date))
824 (day (extract-calendar-day date))
825 (year (extract-calendar-year date))
827 (cal-tex-comment "begin cal-tex-week-hours")
828 (cal-tex-cmd "\\ \\\\[-.2cm]")
829 (cal-tex-cmd "\\noindent")
830 (cal-tex-b-parbox "l" "6.8in")
831 (cal-tex-large-bf (calendar-day-name date))
833 (cal-tex-large-bf (calendar-month-name month))
835 (cal-tex-large-bf (number-to-string day))
836 (if (not (string= "" (cal-tex-latexify-list holidays date)))
839 (cal-tex-large-bf (cal-tex-latexify-list holidays date "; "))))
841 (insert " " (eval cal-tex-daily-string))
844 (cal-tex-rule "0pt" "6.8in" ".2mm")
846 (calendar-for-loop i from 8 to 12 do
848 (setq afternoon (+ i 5))
849 (setq afternoon (- i 7)))
850 (cal-tex-cmd "\\hourbox" (number-to-string i))
852 (cal-tex-hspace ".4cm")
853 (cal-tex-cmd "\\hourbox" (number-to-string afternoon))
857 (defun cal-tex-cursor-week-monday (&optional arg)
858 "Make a buffer with LaTeX commands for a two-page one-week calendar.
859 It applies to the week that point is in, and starts on Monday.
860 Optional prefix argument specifies number of weeks.
861 Holidays are included if `cal-tex-holidays' is t."
863 (let* ((n (if arg arg 1))
864 (date (calendar-gregorian-from-absolute
865 (calendar-dayname-on-or-before
867 (calendar-absolute-from-gregorian
868 (calendar-cursor-to-date t))))))
869 (cal-tex-preamble "11pt")
870 (cal-tex-cmd "\\textwidth 6.5in")
871 (cal-tex-cmd "\\textheight 10.5in")
872 (cal-tex-cmd "\\oddsidemargin 0in")
873 (cal-tex-cmd "\\evensidemargin 0in")
875 (calendar-for-loop i from 1 to n do
876 (cal-tex-vspace "-1cm")
877 (insert "\\noindent ")
878 (cal-tex-weekly4-box (cal-tex-incr-date date) nil)
879 (cal-tex-weekly4-box (cal-tex-incr-date date 4) nil)
881 (cal-tex-weekly4-box (cal-tex-incr-date date 2) nil)
882 (cal-tex-weekly4-box (cal-tex-incr-date date 5) nil)
884 (cal-tex-weekly4-box (cal-tex-incr-date date 3) nil)
885 (cal-tex-weekly4-box (cal-tex-incr-date date 6) t)
888 (run-hooks 'cal-tex-week-hook)
889 (setq date (cal-tex-incr-date date 7))
891 (cal-tex-end-document)
892 (run-hooks 'cal-tex-hook)))
894 (defun cal-tex-weekly4-box (date weekend)
895 "Make one box for DATE, different if WEEKEND."
897 (day (extract-calendar-day date))
898 (month (extract-calendar-month date))
899 (year (extract-calendar-year date))
900 (dayname (calendar-day-name date))
901 (date1 (cal-tex-incr-date date))
902 (day1 (extract-calendar-day date1))
903 (month1 (extract-calendar-month date1))
904 (year1 (extract-calendar-year date1))
905 (dayname1 (calendar-day-name date1))
907 (cal-tex-b-framebox "8cm" "l")
908 (cal-tex-b-parbox "b" "7.5cm")
909 (insert (format "{\\Large\\bf %s,} %s/%s/%s\\\\\n" dayname month day year))
910 (cal-tex-rule "0pt" "7.5cm" ".5mm")
914 (calendar-for-loop i from 8 to 12 do
915 (insert (format "{\\large\\sf %d}\\\\\n" i)))
916 (calendar-for-loop i from 1 to 5 do
917 (insert (format "{\\large\\sf %d}\\\\\n" i)))))
921 (cal-tex-vspace "1cm")
922 (insert "\\ \\vfill")
923 (insert (format "{\\Large\\bf %s,} %s/%s/%s\\\\\n"
924 dayname1 month1 day1 year1))
925 (cal-tex-rule "0pt" "7.5cm" ".5mm")
927 (cal-tex-vspace "1cm")))
930 (cal-tex-hspace "1cm")))
932 (defun cal-tex-cursor-filofax-2week (&optional arg)
933 "Two-weeks-at-a-glance Filofax style calendar for week indicated by cursor.
934 Optional prefix argument specifies number of weeks.
935 Diary entries are included if `cal-tex-diary' is t.
936 Holidays are included if `cal-tex-holidays' is t."
938 (let* ((n (if arg arg 1))
939 (date (calendar-gregorian-from-absolute
940 (calendar-dayname-on-or-before
941 calendar-week-start-day
942 (calendar-absolute-from-gregorian
943 (calendar-cursor-to-date t)))))
944 (month (extract-calendar-month date))
945 (year (extract-calendar-year date))
946 (day (extract-calendar-day date))
947 (holidays (if cal-tex-holidays
948 (cal-tex-list-holidays
949 (calendar-absolute-from-gregorian date)
951 (calendar-absolute-from-gregorian date)))))
952 (diary-list (if cal-tex-diary
953 (cal-tex-list-diary-entries
954 (calendar-absolute-from-gregorian
957 (calendar-absolute-from-gregorian date))))))
958 (cal-tex-preamble "twoside")
959 (cal-tex-cmd "\\textwidth 3.25in")
960 (cal-tex-cmd "\\textheight 6.5in")
961 (cal-tex-cmd "\\oddsidemargin 1.75in")
962 (cal-tex-cmd "\\evensidemargin 1.5in")
963 (cal-tex-cmd "\\topmargin 0pt")
964 (cal-tex-cmd "\\headheight -0.875in")
965 (cal-tex-cmd "\\headsep 0.125in")
966 (cal-tex-cmd "\\footskip .125in")
967 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
968 \\long\\def\\rightday#1#2#3#4#5{%
969 \\rule{\\textwidth}{0.3pt}\\\\%
970 \\hbox to \\textwidth{%
973 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
974 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
975 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
976 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
977 \\long\\def\\leftday#1#2#3#4#5{%
978 \\rule{\\textwidth}{0.3pt}\\\\%
979 \\hbox to \\textwidth{%
982 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
983 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
984 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
987 (cal-tex-cmd "\\pagestyle{empty}")
988 (calendar-for-loop i from 1 to n do
990 (insert "\\righthead")
991 (insert "\\lefthead"))
993 (let ((d (cal-tex-incr-date date 6)))
994 (if (= (extract-calendar-month date)
995 (extract-calendar-month d))
998 (extract-calendar-month date))
999 (extract-calendar-year date))
1000 (if (= (extract-calendar-year date)
1001 (extract-calendar-year d))
1002 (format "%s---%s %s"
1003 (calendar-month-name
1004 (extract-calendar-month date))
1005 (calendar-month-name
1006 (extract-calendar-month d))
1007 (extract-calendar-year date))
1008 (format "%s %s---%s %s"
1009 (calendar-month-name
1010 (extract-calendar-month date))
1011 (extract-calendar-year date)
1012 (calendar-month-name (extract-calendar-month d))
1013 (extract-calendar-year d))))))
1015 (calendar-for-loop j from 1 to 7 do
1017 (insert "\\rightday")
1018 (insert "\\leftday"))
1019 (cal-tex-arg (calendar-day-name date))
1020 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1021 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1022 (cal-tex-arg (cal-tex-latexify-list holidays date))
1023 (cal-tex-arg (eval cal-tex-daily-string))
1025 (setq date (cal-tex-incr-date date)))
1028 (run-hooks 'cal-tex-week-hook)
1029 (cal-tex-newpage))))
1030 (cal-tex-end-document)
1031 (run-hooks 'cal-tex-hook)))
1033 (defun cal-tex-cursor-filofax-week (&optional arg)
1034 "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
1035 Optional prefix argument specifies number of weeks.
1036 Weeks start on Monday.
1037 Diary entries are included if `cal-tex-diary' is t.
1038 Holidays are included if `cal-tex-holidays' is t."
1040 (let* ((n (if arg arg 1))
1041 (date (calendar-gregorian-from-absolute
1042 (calendar-dayname-on-or-before
1044 (calendar-absolute-from-gregorian
1045 (calendar-cursor-to-date t)))))
1046 (month (extract-calendar-month date))
1047 (year (extract-calendar-year date))
1048 (day (extract-calendar-day date))
1049 (holidays (if cal-tex-holidays
1050 (cal-tex-list-holidays
1051 (calendar-absolute-from-gregorian date)
1053 (calendar-absolute-from-gregorian date)))))
1054 (diary-list (if cal-tex-diary
1055 (cal-tex-list-diary-entries
1056 (calendar-absolute-from-gregorian
1057 (list month 1 year))
1059 (calendar-absolute-from-gregorian date))))))
1060 (cal-tex-preamble "twoside")
1061 (cal-tex-cmd "\\textwidth 3.25in")
1062 (cal-tex-cmd "\\textheight 6.5in")
1063 (cal-tex-cmd "\\oddsidemargin 1.75in")
1064 (cal-tex-cmd "\\evensidemargin 1.5in")
1065 (cal-tex-cmd "\\topmargin 0pt")
1066 (cal-tex-cmd "\\headheight -0.875in")
1067 (cal-tex-cmd "\\headsep 0.125in")
1068 (cal-tex-cmd "\\footskip .125in")
1069 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1070 \\long\\def\\rightday#1#2#3#4#5{%
1071 \\rule{\\textwidth}{0.3pt}\\\\%
1072 \\hbox to \\textwidth{%
1075 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1076 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1077 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1078 \\long\\def\\weekend#1#2#3#4#5{%
1079 \\rule{\\textwidth}{0.3pt}\\\\%
1080 \\hbox to \\textwidth{%
1083 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1084 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1085 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1086 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1087 \\long\\def\\leftday#1#2#3#4#5{%
1088 \\rule{\\textwidth}{0.3pt}\\\\%
1089 \\hbox to \\textwidth{%
1092 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1093 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1094 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1096 (cal-tex-b-document)
1097 (cal-tex-cmd "\\pagestyle{empty}\\ ")
1099 (calendar-for-loop i from 1 to n do
1100 (insert "\\lefthead")
1102 (let ((d (cal-tex-incr-date date 2)))
1103 (if (= (extract-calendar-month date)
1104 (extract-calendar-month d))
1106 (calendar-month-name
1107 (extract-calendar-month date))
1108 (extract-calendar-year date))
1109 (if (= (extract-calendar-year date)
1110 (extract-calendar-year d))
1111 (format "%s---%s %s"
1112 (calendar-month-name
1113 (extract-calendar-month date))
1114 (calendar-month-name
1115 (extract-calendar-month d))
1116 (extract-calendar-year date))
1117 (format "%s %s---%s %s"
1118 (calendar-month-name
1119 (extract-calendar-month date))
1120 (extract-calendar-year date)
1121 (calendar-month-name (extract-calendar-month d))
1122 (extract-calendar-year d))))))
1124 (calendar-for-loop j from 1 to 3 do
1125 (insert "\\leftday")
1126 (cal-tex-arg (calendar-day-name date))
1127 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1128 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1129 (cal-tex-arg (cal-tex-latexify-list holidays date))
1130 (cal-tex-arg (eval cal-tex-daily-string))
1132 (setq date (cal-tex-incr-date date)))
1133 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1135 (insert "\\righthead")
1137 (let ((d (cal-tex-incr-date date 3)))
1138 (if (= (extract-calendar-month date)
1139 (extract-calendar-month d))
1141 (calendar-month-name
1142 (extract-calendar-month date))
1143 (extract-calendar-year date))
1144 (if (= (extract-calendar-year date)
1145 (extract-calendar-year d))
1146 (format "%s---%s %s"
1147 (calendar-month-name
1148 (extract-calendar-month date))
1149 (calendar-month-name
1150 (extract-calendar-month d))
1151 (extract-calendar-year date))
1152 (format "%s %s---%s %s"
1153 (calendar-month-name
1154 (extract-calendar-month date))
1155 (extract-calendar-year date)
1156 (calendar-month-name (extract-calendar-month d))
1157 (extract-calendar-year d))))))
1159 (calendar-for-loop j from 1 to 2 do
1160 (insert "\\rightday")
1161 (cal-tex-arg (calendar-day-name date))
1162 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1163 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1164 (cal-tex-arg (cal-tex-latexify-list holidays date))
1165 (cal-tex-arg (eval cal-tex-daily-string))
1167 (setq date (cal-tex-incr-date date)))
1168 (calendar-for-loop j from 1 to 2 do
1169 (insert "\\weekend")
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)))
1179 (run-hooks 'cal-tex-week-hook)
1180 (cal-tex-newpage))))
1181 (cal-tex-end-document)
1182 (run-hooks 'cal-tex-hook)))
1187 (defun cal-tex-cursor-day (&optional arg)
1188 "Make a buffer with LaTeX commands for the day cursor is on.
1189 Optional prefix argument specifies number of days."
1191 (let ((n (if arg arg 1))
1192 (date (calendar-absolute-from-gregorian (calendar-cursor-to-date t))))
1193 (cal-tex-preamble "12pt")
1194 (cal-tex-cmd "\\textwidth 6.5in")
1195 (cal-tex-cmd "\\textheight 10.5in")
1196 (cal-tex-b-document)
1197 (cal-tex-cmd "\\pagestyle{empty}")
1198 (calendar-for-loop i from 1 to n do
1199 (cal-tex-vspace "-1.7in")
1200 (cal-tex-daily-page (calendar-gregorian-from-absolute date))
1201 (setq date (1+ date))
1205 (run-hooks 'cal-tex-daily-hook))))
1206 (cal-tex-end-document)
1207 (run-hooks 'cal-tex-hook)))
1209 (defun cal-tex-daily-page (date)
1210 "Make a calendar page for Gregorian DATE on 8.5 by 11 paper."
1212 (month-name (calendar-month-name (extract-calendar-month date))))
1213 (cal-tex-banner "cal-tex-daily-page")
1214 (cal-tex-b-makebox "4cm" "l")
1215 (cal-tex-b-parbox "b" "3.8cm")
1216 (cal-tex-rule "0mm" "0mm" "2cm")
1217 (cal-tex-Huge (number-to-string (extract-calendar-day date)))
1219 (cal-tex-bf month-name )
1221 (cal-tex-hspace "1cm")
1222 (cal-tex-scriptsize (eval cal-tex-daily-string))
1223 (cal-tex-hspace "3.5cm")
1226 (cal-tex-b-makebox "4cm" "r")
1227 (cal-tex-bf (calendar-day-name date))
1230 (cal-tex-hspace ".4cm")
1231 (cal-tex-rule "0mm" "16.1cm" "1mm")
1233 (calendar-for-loop i from cal-tex-daily-start to cal-tex-daily-end do
1234 (cal-tex-cmd "\\noindent")
1235 (setq hour (if cal-tex-24
1238 (if (= 0 hour) (setq hour 12))
1239 (cal-tex-b-makebox "1cm" "c")
1240 (cal-tex-arg (number-to-string hour))
1242 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1244 (cal-tex-b-makebox "1cm" "c")
1245 (cal-tex-arg "$\\diamond$" )
1247 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1248 (cal-tex-nl ".2cm"))
1250 (insert (cal-tex-mini-calendar
1251 (extract-calendar-month (cal-tex-previous-month date))
1252 (extract-calendar-year (cal-tex-previous-month date))
1253 "lastmonth" "1.1in" "1in"))
1254 (insert (cal-tex-mini-calendar
1255 (extract-calendar-month date)
1256 (extract-calendar-year date)
1257 "thismonth" "1.1in" "1in"))
1258 (insert (cal-tex-mini-calendar
1259 (extract-calendar-month (cal-tex-next-month date))
1260 (extract-calendar-year (cal-tex-next-month date))
1261 "nextmonth" "1.1in" "1in"))
1262 (insert "\\hbox to \\textwidth{")
1264 (insert "\\lastmonth")
1266 (insert "\\thismonth")
1268 (insert "\\nextmonth")
1271 (cal-tex-banner "end of cal-tex-daily-page")))
1277 (defun cal-tex-mini-calendar (month year name width height &optional size)
1278 "Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT.
1279 Optional SIZE gives the point size; scriptsize is the default,"
1280 (let* ((blank-days;; at start of month
1282 (- (calendar-day-of-week (list month 1 year))
1283 calendar-week-start-day)
1285 (last (calendar-last-day-of-month month year))
1286 (str (concat "\\def\\" name "{\\hbox to" width "{%\n"
1287 "\\vbox to" height "{%\n"
1288 "\\vfil \\hbox to" width "{%\n"
1290 (if size size "scriptsize")
1292 "{@{\\hspace{1mm}}r@{\\hspace{1mm}}r@{\\hspace{1mm}}r@{\\hspace{1mm}}"
1293 "r@{\\hspace{1mm}}r@{\\hspace{1mm}}r@{\\hspace{1mm}}r@{\\hspace{1mm}}}%\n"
1294 "\\multicolumn{7}{c}{"
1295 (calendar-month-name month)
1297 (int-to-string year)
1299 (calendar-for-loop i from 0 to 6 do
1300 (setq str (concat str
1301 (substring (aref calendar-day-name-array
1302 (mod (+ calendar-week-start-day i) 7))
1307 (calendar-for-loop i from 1 to blank-days do
1308 (setq str (concat str " & ")))
1309 (calendar-for-loop i from 1 to last do
1310 (setq str (concat str (int-to-string i)))
1311 (setq str (concat str (if (zerop (mod (+ i blank-days) 7))
1312 (if (/= i last) "\\\\[0.5mm]\n" "")
1314 (setq str (concat str "\n\\end{tabular}\\hfil}\\vfil}}}%\n"))
1318 ;;; Various calendar functions
1321 (defun cal-tex-incr-date (date &optional n)
1322 "The date of the day following DATE.
1323 If optional N is given, the date of N days after DATE."
1324 (calendar-gregorian-from-absolute
1325 (+ (if n n 1) (calendar-absolute-from-gregorian date))))
1327 (defun cal-tex-latexify-list (date-list date &optional separator)
1328 "Return string with concatenated, LaTeXified entries in DATE_LIST for DATE.
1329 Use double backslash as a separator unless optional SEPARATOR is given."
1330 (mapconcat '(lambda (x) (cal-tex-LaTeXify-string x))
1335 (calendar-date-equal date (car (car p)))
1336 (setq result (append (cdr (car p)) result)))
1339 (if separator separator "\\\\")))
1341 (defun cal-tex-previous-month (date)
1342 "Return the date of the first day in the month previous to DATE."
1343 (let* ((month (extract-calendar-month date))
1344 (year (extract-calendar-year date)))
1345 (increment-calendar-month month year -1)
1346 (list month 1 year)))
1348 (defun cal-tex-next-month (date)
1349 "Return the date of the first day in the month following DATE."
1350 (let* ((month (extract-calendar-month date))
1351 (year (extract-calendar-year date)))
1352 (increment-calendar-month month year 1)
1353 (list month 1 year)))
1359 (defun cal-tex-end-document ()
1360 "Finish the LaTeX document.
1361 Insert the trailer to LaTeX document, pop to LaTeX buffer, add
1362 informative header, and run HOOK."
1363 (cal-tex-e-document)
1365 (pop-to-buffer cal-tex-buffer)
1366 (goto-char (point-min))
1367 (cal-tex-comment " This buffer was produced by cal-tex.el.")
1368 (cal-tex-comment " To print a calendar, type")
1369 (cal-tex-comment " M-x tex-buffer RET")
1370 (cal-tex-comment " M-x tex-print RET")
1371 (goto-char (point-min)))
1373 (defun cal-tex-insert-preamble (weeks landscape size &optional append)
1374 "Initialize the output buffer.
1375 Select the output buffer, and insert the preamble for a calendar of
1376 WEEKS weeks. Insert code for landscape mode if LANDSCAPE is true.
1377 Use pointsize SIZE. Optional argument APPEND, if t, means add to end of
1378 without erasing current contents."
1379 (let ((width "18cm")
1384 (setq height "18cm")))
1387 (cal-tex-preamble size)
1390 (cal-tex-cmd "\\oddsidemargin -1.75cm")
1391 (cal-tex-cmd "\\def\\holidaymult{.06}"))
1392 (cal-tex-cmd "\\special{landscape}")
1393 (cal-tex-cmd "\\textwidth 9.5in")
1394 (cal-tex-cmd "\\textheight 7in")
1396 (cal-tex-cmd "\\def\\holidaymult{.08}"))
1397 (cal-tex-cmd cal-tex-caldate)
1398 (cal-tex-cmd cal-tex-myday)
1399 (cal-tex-b-document)
1400 (cal-tex-cmd "\\pagestyle{empty}")))
1401 (cal-tex-cmd "\\setlength{\\cellwidth}" width)
1402 (insert (format "\\setlength{\\cellwidth}{%f\\cellwidth}\n"
1403 (/ 1.1 (length cal-tex-which-days))))
1404 (cal-tex-cmd "\\setlength{\\cellheight}" height)
1405 (insert (format "\\setlength{\\cellheight}{%f\\cellheight}\n"
1407 (cal-tex-cmd "\\ \\par")
1408 (cal-tex-vspace "-3cm")))
1410 (defvar cal-tex-LaTeX-subst-list
1412 ("\"". "''");; Quote changes meaning when list is reversed.
1423 ("\n" . "\\ \\\\")) ;\\ needed for e.g \begin{center}\n AA\end{center}
1424 "List of symbols and their replacements.")
1426 (defun cal-tex-LaTeXify-string (string)
1427 "Protect special characters in STRING from LaTeX."
1432 (list cal-tex-LaTeX-subst-list))
1433 (while (not (string-equal tail ""))
1434 (let* ((ch (substring tail 0 1))
1435 (pair (assoc ch list)))
1436 (if (and pair (string-equal ch "\""))
1437 (setq list (reverse list)));; Quote changes meaning each time.
1438 (setq tail (substring tail 1))
1439 (setq head (concat head (if pair (cdr pair) ch)))))
1442 (defun cal-tex-hfill () "Insert hfill." (insert "\\hfill"))
1444 (defun cal-tex-newpage () "Insert newpage." (insert "\\newpage%\n"))
1446 (defun cal-tex-noindent () "Insert noindent." (insert "\\noindent"))
1448 (defun cal-tex-vspace (space)
1449 "Insert vspace command to move SPACE vertically."
1450 (insert "\\vspace*{" space "}")
1453 (defun cal-tex-hspace (space)
1454 "Insert hspace command to move SPACE horizontally."
1455 (insert "\\hspace*{" space "}")
1458 (defun cal-tex-comment (&optional comment)
1459 "Insert % at end of line, include COMMENT if present, and move
1466 (defun cal-tex-banner (comment)
1467 "Insert the COMMENT separated by blank lines."
1470 (cal-tex-comment (concat "\t\t\t" comment))
1474 (defun cal-tex-nl (&optional skip comment)
1475 "End a line with \\. If SKIP, then add that much spacing.
1476 Add COMMENT if present"
1479 (insert "[" skip "]"))
1480 (cal-tex-comment comment))
1482 (defun cal-tex-arg (&optional text)
1483 "Insert optional TEXT surrounded by braces."
1485 (if text (insert text))
1488 (defun cal-tex-cmd (cmd &optional arg)
1489 "Insert LaTeX CMD, with optional ARG, and end with %"
1498 (defun cal-tex-b-document ()
1499 "Insert beginning of document."
1500 (cal-tex-cmd "\\begin{document}"))
1502 (defun cal-tex-e-document ()
1503 "Insert end of document."
1504 (cal-tex-cmd "\\end{document}"))
1506 (defun cal-tex-b-center ()
1507 "Insert beginning of centered block."
1508 (cal-tex-cmd "\\begin{center}"))
1510 (defun cal-tex-e-center ()
1511 "Insert end of centered block."
1513 (cal-tex-cmd "\\end{center}"))
1521 (defun cal-tex-b-parbox (position width)
1522 "Insert parbox with parameters POSITION and WIDTH."
1523 (insert "\\parbox[" position "]{" width "}{")
1526 (defun cal-tex-e-parbox (&optional height)
1527 "Insert end of parbox. Force it to be a given HEIGHT."
1530 (cal-tex-rule "0mm" "0mm" height))
1532 (cal-tex-comment "end parbox"))
1534 (defun cal-tex-b-framebox ( width position )
1535 "Insert framebox with parameters WIDTH and POSITION (clr)."
1536 (insert "\\framebox[" width "][" position "]{" )
1539 (defun cal-tex-e-framebox ()
1540 "Insert end of framebox."
1543 (cal-tex-comment "end framebox"))
1546 (defun cal-tex-b-makebox ( width position )
1547 "Insert makebox with parameters WIDTH and POSITION (clr)."
1548 (insert "\\makebox[" width "][" position "]{" )
1551 (defun cal-tex-e-makebox ()
1552 "Insert end of makebox."
1555 (cal-tex-comment "end makebox"))
1558 (defun cal-tex-rule (lower width height)
1559 "Insert a rule with parameters LOWER WIDTH HEIGHT."
1560 (insert "\\rule[" lower "]{" width "}{" height "}"))
1566 (defun cal-tex-em (string)
1567 "Insert STRING in bf font."
1568 (insert "{\\em " string "}"))
1570 (defun cal-tex-bf (string)
1571 "Insert STRING in bf font."
1572 (insert "{\\bf " string "}"))
1574 (defun cal-tex-scriptsize (string)
1575 "Insert STRING in scriptsize font."
1576 (insert "{\\scriptsize " string "}"))
1578 (defun cal-tex-huge (string)
1579 "Insert STRING in huge size."
1580 (insert "{\\huge " string "}"))
1582 (defun cal-tex-Huge (string)
1583 "Insert STRING in Huge size."
1584 (insert "{\\Huge " string "}"))
1586 (defun cal-tex-Huge-bf (string)
1587 "Insert STRING in Huge bf size."
1588 (insert "{\\Huge\\bf " string "}"))
1590 (defun cal-tex-large (string)
1591 "Insert STRING in large size."
1592 (insert "{\\large " string "}"))
1594 (defun cal-tex-large-bf (string)
1595 "Insert STRING in large bf size."
1596 (insert "{\\large\\bf " string "}"))
1600 ;;; cal-tex.el ends here