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-rules nil
77 "*If t, pages will be ruled in some styles."
81 (defcustom cal-tex-daily-string
82 '(let* ((year (extract-calendar-year date
))
83 (day (calendar-day-number date
))
84 (days-remaining (- (calendar-day-number (list 12 31 year
)) day
)))
85 (format "%d/%d" day days-remaining
))
86 "*An expression in the variable `date' whose value is placed on date.
87 The string resulting from evaluating this expression is placed at the bottom
88 center of `date' on the monthly calendar, next to the date in the weekly
89 calendars, and in the top center of daily calendars.
91 Default is ordinal day number of the year and the number of days remaining.
92 As an example of what you do, setting this to
96 (calendar-hebrew-date-string date))
98 will put the Hebrew date at the bottom of each day."
100 :group
'calendar-tex
)
102 (defcustom cal-tex-buffer
"calendar.tex"
103 "*The name for the tex-ed calendar."
105 :group
'calendar-tex
)
107 (defcustom cal-tex-24 nil
108 "*If t, use a 24 hour clock in the daily calendar."
110 :group
'calendar-tex
)
112 (defcustom cal-tex-daily-start
8
113 "*The first hour of the daily calendar page."
115 :group
'calendar-tex
)
117 (defcustom cal-tex-daily-end
20
118 "*The last hour of the daily calendar page."
120 :group
'calendar-tex
)
122 (defcustom cal-tex-hook nil
123 "*List of functions called after any LaTeX calendar buffer is generated.
124 You can use this to do postprocessing on the buffer. For example, to change
125 characters with diacritical marks to their LaTeX equivalents, use
126 (add-hook 'cal-tex-hook
127 '(lambda () (iso-iso2tex (point-min) (point-max))))"
129 :group
'calendar-tex
)
131 (defcustom cal-tex-year-hook nil
132 "*List of functions called after a LaTeX year calendar buffer is generated."
134 :group
'calendar-tex
)
136 (defcustom cal-tex-month-hook nil
137 "*List of functions called after a LaTeX month calendar buffer is generated."
139 :group
'calendar-tex
)
141 (defcustom cal-tex-week-hook nil
142 "*List of functions called after a LaTeX week calendar buffer is generated."
144 :group
'calendar-tex
)
146 (defcustom cal-tex-daily-hook nil
147 "*List of functions called after a LaTeX daily calendar buffer is generated."
149 :group
'calendar-tex
)
152 ;;; Definitions for LaTeX code
155 (defvar cal-tex-day-prefix
"\\caldate{%s}{%s}"
156 "The initial LaTeX code for a day.
157 The holidays, diary entries, bottom string, and the text follow.")
159 (defvar cal-tex-day-name-format
"\\myday{%s}%%"
160 "The format for LaTeX code for a day name. The names are taken from
161 calendar-day-name-array.")
163 (defvar cal-tex-cal-one-month
164 "\\def\\calmonth#1#2%
166 \\Huge\\bf\\uppercase{#1} #2 \\\\[1cm]%
171 "LaTeX code for the month header")
173 (defvar cal-tex-cal-multi-month
174 "\\def\\calmonth#1#2#3#4%
176 \\Huge\\bf #1 #2---#3 #4\\\\[1cm]%
181 "LaTeX code for the month header")
183 (defvar cal-tex-myday
184 "\\renewcommand{\\myday}[1]%
185 {\\makebox[\\cellwidth]{\\hfill\\large\\bf#1\\hfill}}
188 "LaTeX code for a day heading")
190 (defvar cal-tex-caldate
192 \\long\\def\\caldate#1#2#3#4#5#6{%
193 \\fbox{\\hbox to\\cellwidth{%
194 \\vbox to\\cellheight{%
195 \\hbox to\\cellwidth{%
196 {\\hspace*{1mm}\\Large \\bf \\strut #2}\\hspace{.05\\cellwidth}%
197 \\raisebox{\\holidaymult\\cellheight}%
198 {\\parbox[t]{.75\\cellwidth}{\\tiny \\raggedright #4}}}
199 \\hbox to\\cellwidth{%
200 \\hspace*{1mm}\\parbox{.95\\cellwidth}{\\tiny \\raggedright #3}}
202 \\hbox to\\cellwidth{#6}%
204 \\hbox to\\cellwidth{\\hfill \\tiny #5 \\hfill}%
208 "LaTeX code to insert one box with date info in calendar.
209 This definition is the heart of the calendar!")
211 (defun cal-tex-list-holidays (d1 d2
)
212 "Generate a list of all holidays from absolute date D1 to D2."
213 (let* ((start (calendar-gregorian-from-absolute d1
))
214 (displayed-month (extract-calendar-month start
))
215 (displayed-year (extract-calendar-year start
))
216 (end (calendar-gregorian-from-absolute d2
))
217 (end-month (extract-calendar-month end
))
218 (end-year (extract-calendar-year end
))
220 (1+ (/ (calendar-interval displayed-month displayed-year
225 (increment-calendar-month displayed-month displayed-year
1)
226 (calendar-for-loop i from
1 to number-of-intervals do
227 (setq holidays
(append holidays
(calendar-holiday-list)))
228 (increment-calendar-month displayed-month displayed-year
3))
230 (and (car (car holidays
))
231 (let ((a (calendar-absolute-from-gregorian (car (car holidays
)))))
232 (and (<= d1 a
) (<= a d2
)))
233 (setq in-range
(append (list (car holidays
)) in-range
)))
234 (setq holidays
(cdr holidays
)))
237 (defun cal-tex-list-diary-entries (d1 d2
)
238 "Generate a list of all diary-entries from absolute date D1 to D2."
239 (let ((diary-list-include-blanks nil
)
240 (diary-display-hook 'ignore
))
242 (calendar-gregorian-from-absolute d1
)
245 (defun cal-tex-preamble (&optional args
)
246 "Insert the LaTeX preamble.
247 Preamble Includes initial definitions for various LaTeX commands.
248 Optional ARGS are included."
249 (set-buffer (get-buffer-create cal-tex-buffer
))
251 (insert "\\documentclass")
253 (insert "[" args
"]"))
254 (insert "{article}\n"
261 \\evensidemargin -2cm
266 \\newlength{\\cellwidth}
267 \\newlength{\\cellheight}
268 \\newlength{\\boxwidth}
269 \\newlength{\\boxheight}
270 \\newlength{\\cellsize}
271 \\newcommand{\\myday}[1]{}
272 \\newcommand{\\caldate}[6]{}
273 \\newcommand{\\nocaldate}[6]{}
274 \\newcommand{\\calsmall}[6]{}
282 (defun cal-tex-cursor-year (&optional arg
)
283 "Make a buffer with LaTeX commands for the year cursor is on.
284 Optional prefix argument specifies number of years."
286 (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t
))
289 (defun cal-tex-cursor-year-landscape (&optional arg
)
290 "Make a buffer with LaTeX commands for the year cursor is on.
291 Optional prefix argument specifies number of years."
293 (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t
))
297 (defun cal-tex-year (year n
&optional landscape
)
298 "Make a one page yearly calendar of YEAR; do this for N years.
299 There are four rows of three months each, unless optional LANDSCAPE is t,
300 in which case the calendar isprinted in landscape mode with three rows of
302 (cal-tex-insert-preamble 1 landscape
"12pt")
304 (cal-tex-vspace "-.6cm")
305 (cal-tex-vspace "-3.1cm"))
306 (calendar-for-loop j from
1 to n do
307 (insert "\\vfill%\n")
309 (cal-tex-Huge (number-to-string year
))
311 (cal-tex-vspace "1cm")
313 (cal-tex-b-parbox "l" (if landscape
"5.9in" "4.3in"))
317 (calendar-for-loop i from
1 to
12 do
318 (insert (cal-tex-mini-calendar i year
"month" "1.1in" "1in"))
320 (cal-tex-hspace "0.5in")
321 (if (zerop (mod i
(if landscape
4 3)))
322 (cal-tex-nl "0.5in")))
325 (insert "\\vfill%\n")
326 (setq year
(1+ year
))
329 (cal-tex-end-document))
330 (run-hooks 'cal-tex-year-hook
))
331 (run-hooks 'cal-tex-hook
))
333 (defun cal-tex-cursor-filofax-year (&optional arg
)
334 "Make a Filofax one page yearly calendar of year indicated by cursor.
335 Optional parameter specifies number of years."
337 (let* ((n (if arg arg
1))
338 (year (extract-calendar-year (calendar-cursor-to-date t
))))
339 (cal-tex-preamble "twoside")
340 (cal-tex-cmd "\\textwidth 3.25in")
341 (cal-tex-cmd "\\textheight 6.5in")
342 (cal-tex-cmd "\\oddsidemargin 1.675in")
343 (cal-tex-cmd "\\evensidemargin 1.675in")
344 (cal-tex-cmd "\\topmargin 0pt")
345 (cal-tex-cmd "\\headheight -0.875in")
346 (cal-tex-cmd "\\fboxsep 0.5mm")
347 (cal-tex-cmd "\\pagestyle{empty}")
349 (cal-tex-cmd "\\vspace*{0.25in}")
350 (calendar-for-loop j from
1 to n do
351 (insert (format "\\hfil {\\Large \\bf %s} \\hfil\\\\\n" year
))
353 (cal-tex-b-parbox "l" "\\textwidth")
357 (let ((month-names; don't use default in case user changed it
358 ["January" "February" "March" "April" "May" "June"
359 "July" "August" "September" "October" "November" "December"]))
360 (calendar-for-loop i from
1 to
12 do
361 (insert (cal-tex-mini-calendar i year
362 (aref month-names
(1- i
))
363 "1in" ".9in" "tiny" "0.6mm"))))
365 "\\noindent\\fbox{\\January}\\fbox{\\February}\\fbox{\\March}\\\\
366 \\noindent\\fbox{\\April}\\fbox{\\May}\\fbox{\\June}\\\\
367 \\noindent\\fbox{\\July}\\fbox{\\August}\\fbox{\\September}\\\\
368 \\noindent\\fbox{\\October}\\fbox{\\November}\\fbox{\\December}
372 (setq year
(1+ year
))
374 (cal-tex-end-document)
376 (cal-tex-cmd "\\vspace*{0.25in}"))
377 (run-hooks 'cal-tex-year-hook
))
378 (run-hooks 'cal-tex-hook
)))
381 ;;; Monthly calendars
384 (defun cal-tex-cursor-month-landscape (&optional arg
)
385 "Make a buffer with LaTeX commands for the month cursor is on.
386 Optional prefix argument specifies number of months to be produced.
387 The output is in landscape format, one month to a page."
389 (let* ((n (if arg arg
1))
390 (date (calendar-cursor-to-date t
))
391 (month (extract-calendar-month date
))
392 (year (extract-calendar-year date
))
395 (cal-tex-which-days '(0 1 2 3 4 5 6)))
396 (increment-calendar-month end-month end-year
(1- n
))
397 (let ((diary-list (if cal-tex-diary
398 (cal-tex-list-diary-entries
399 (calendar-absolute-from-gregorian
401 (calendar-absolute-from-gregorian
403 (calendar-last-day-of-month
406 (holidays (if cal-tex-holidays
407 (cal-tex-list-holidays
408 (calendar-absolute-from-gregorian
410 (calendar-absolute-from-gregorian
412 (calendar-last-day-of-month end-month end-year
)
416 (small-months-at-start))
417 (cal-tex-insert-preamble (cal-tex-number-weeks month year
1) t
"12pt")
418 (cal-tex-cmd cal-tex-cal-one-month
)
419 (calendar-for-loop i from
1 to n do
420 (setq other-month month
)
421 (setq other-year year
)
422 (increment-calendar-month other-month other-year -
1)
423 (insert (cal-tex-mini-calendar other-month other-year
"lastmonth"
424 "\\cellwidth" "\\cellheight"))
425 (increment-calendar-month other-month other-year
2)
426 (insert (cal-tex-mini-calendar other-month other-year
"nextmonth"
427 "\\cellwidth" "\\cellheight"))
428 (cal-tex-insert-month-header 1 month year month year
)
429 (cal-tex-insert-day-names)
431 (setq small-months-at-start
432 (< 1 (mod (- (calendar-day-of-week (list month
1 year
))
433 calendar-week-start-day
)
435 (if small-months-at-start
436 (insert "\\lastmonth\\nextmonth\\hspace*{-2\\cellwidth}"))
437 (cal-tex-insert-blank-days month year cal-tex-day-prefix
)
438 (cal-tex-insert-days month year diary-list holidays
440 (cal-tex-insert-blank-days-at-end month year cal-tex-day-prefix
)
441 (if (and (not small-months-at-start
)
442 (< 1 (mod (- (1- calendar-week-start-day
)
443 (calendar-day-of-week
445 (calendar-last-day-of-month month year
)
448 (insert "\\vspace*{-\\cellwidth}\\hspace*{-2\\cellwidth}"
449 "\\lastmonth\\nextmonth%
453 (run-hooks 'cal-tex-month-hook
)
455 (increment-calendar-month month year
1)
456 (cal-tex-vspace "-2cm")
457 (cal-tex-insert-preamble
458 (cal-tex-number-weeks month year
1) t
"12pt" t
))))
459 (cal-tex-end-document)
460 (run-hooks 'cal-tex-hook
))))
462 (defun cal-tex-cursor-month (arg)
463 "Make a buffer with LaTeX commands for the month cursor is on.
464 Optional prefix argument specifies number of months to be produced.
465 Calendar is condensed onto one page."
467 (let* ((date (calendar-cursor-to-date t
))
468 (month (extract-calendar-month date
))
469 (year (extract-calendar-year date
))
473 (increment-calendar-month end-month end-year
(1- n
))
474 (let ((diary-list (if cal-tex-diary
475 (cal-tex-list-diary-entries
476 (calendar-absolute-from-gregorian
478 (calendar-absolute-from-gregorian
480 (calendar-last-day-of-month
483 (holidays (if cal-tex-holidays
484 (cal-tex-list-holidays
485 (calendar-absolute-from-gregorian
487 (calendar-absolute-from-gregorian
489 (calendar-last-day-of-month end-month end-year
)
493 (cal-tex-insert-preamble (cal-tex-number-weeks month year n
) nil
"12pt")
495 (cal-tex-cmd cal-tex-cal-multi-month
)
496 (cal-tex-cmd cal-tex-cal-one-month
))
497 (cal-tex-insert-month-header n month year end-month end-year
)
498 (cal-tex-insert-day-names)
500 (cal-tex-insert-blank-days month year cal-tex-day-prefix
)
501 (calendar-for-loop i from
1 to n do
502 (setq other-month month
)
503 (setq other-year year
)
504 (cal-tex-insert-days month year diary-list holidays
506 (if (= (mod (calendar-absolute-from-gregorian
508 (calendar-last-day-of-month month year
)
511 6); last day of month was Saturday
515 (increment-calendar-month month year
1))
516 (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix
)
517 (cal-tex-end-document)))
518 (run-hooks 'cal-tex-hook
))
520 (defun cal-tex-insert-days (month year diary-list holidays day-format
)
521 "Insert LaTeX commands for a range of days in monthly calendars.
522 LaTeX commands are inserted for the days of the MONTH in YEAR.
523 Diary entries on DIARY-LIST are included. Holidays on HOLIDAYS are included.
524 Each day is formatted using format DAY-FORMAT."
525 (let* ((blank-days;; at start of month
527 (- (calendar-day-of-week (list month
1 year
))
528 calendar-week-start-day
)
531 (last (calendar-last-day-of-month month year
)))
532 (calendar-for-loop i from
1 to last do
533 (setq date
(list month i year
))
534 (if (memq (calendar-day-of-week date
) cal-tex-which-days
)
536 (insert (format day-format
(cal-tex-month-name month
) i
))
537 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
538 (cal-tex-arg (cal-tex-latexify-list holidays date
))
539 (cal-tex-arg (eval cal-tex-daily-string
))
542 (if (and (zerop (mod (+ i blank-days
) 7))
548 (defun cal-tex-insert-day-names ()
549 "Insert the names of the days at top of a monthly calendar."
550 (calendar-for-loop i from
0 to
6 do
551 (if (memq i cal-tex-which-days
)
552 (insert (format cal-tex-day-name-format
553 (cal-tex-LaTeXify-string
554 (aref calendar-day-name-array
555 (mod (+ calendar-week-start-day i
) 7))))))
558 (defun cal-tex-insert-month-header (n month year end-month end-year
)
559 "Create a title for a calendar.
560 A title is inserted for a calendar with N months starting with
561 MONTH YEAR and ending with END-MONTH END-YEAR."
562 (let ((month-name (cal-tex-month-name month
))
563 (end-month-name (cal-tex-month-name end-month
)))
565 (insert (format "\\calmonth{%s}{%s}\n\\vspace*{-0.5cm}"
567 (insert (format "\\calmonth{%s}{%s}{%s}{%s}\n\\vspace*{-0.5cm}"
568 month-name year end-month-name end-year
))))
571 (defun cal-tex-insert-blank-days (month year day-format
)
572 "Insert code for initial days not in calendar.
573 Insert LaTeX code for the blank days at the beginning of the MONTH in
574 YEAR. The entry is formatted using DAY-FORMAT. If the entire week is
575 blank, no days are inserted."
576 (if (cal-tex-first-blank-p month year
)
577 (let* ((blank-days;; at start of month
579 (- (calendar-day-of-week (list month
1 year
))
580 calendar-week-start-day
)
582 (calendar-for-loop i from
0 to
(1- blank-days
) do
583 (if (memq i cal-tex-which-days
)
584 (insert (format day-format
" " " ") "{}{}{}{}%\n"))))))
586 (defun cal-tex-insert-blank-days-at-end (month year day-format
)
587 "Insert code for final days not in calendar.
588 Insert LaTeX code for the blank days at the end of the MONTH in YEAR.
589 The entry is formatted using DAY-FORMAT."
590 (if (cal-tex-last-blank-p month year
)
591 (let* ((last-day (calendar-last-day-of-month month year
))
592 (blank-days;; at end of month
594 (- (calendar-day-of-week (list month last-day year
))
595 calendar-week-start-day
)
597 (calendar-for-loop i from
(1+ blank-days
) to
6 do
598 (if (memq i cal-tex-which-days
)
599 (insert (format day-format
"" "") "{}{}{}{}%\n"))))))
601 (defun cal-tex-first-blank-p (month year
)
602 "Determine if any days of the first week will be printed.
603 Return t if there will there be any days of the first week printed
604 in the calendar starting in MONTH YEAR."
606 (the-saturday)) ;the day of week of 1st Saturday
607 (calendar-for-loop i from
1 to
7 do
608 (if (= 6 (calendar-day-of-week (list month i year
)))
609 (setq the-saturday i
)))
610 (calendar-for-loop i from
1 to the-saturday do
611 (if (memq (calendar-day-of-week (list month i year
))
616 (defun cal-tex-last-blank-p (month year
)
617 "Determine if any days of the last week will be printed.
618 Return t if there will there be any days of the last week printed
619 in the calendar starting in MONTH YEAR."
621 (last-day (calendar-last-day-of-month month year
))
622 (the-sunday)) ;the day of week of last Sunday
623 (calendar-for-loop i from
(- last-day
6) to last-day do
624 (if (= 0 (calendar-day-of-week (list month i year
)))
625 (setq the-sunday i
)))
626 (calendar-for-loop i from the-sunday to last-day do
627 (if (memq (calendar-day-of-week (list month i year
))
632 (defun cal-tex-number-weeks (month year n
)
633 "Determine the number of weeks in a range of dates.
634 Compute the number of weeks in the calendar starting with MONTH and YEAR,
635 and lasting N months, including only the days in WHICH-DAYS. As it stands,
636 this is only an upper bound."
637 (let ((d (list month
1 year
)))
638 (increment-calendar-month month year
(1- n
))
639 (/ (- (calendar-dayname-on-or-before
640 calendar-week-start-day
641 (+ 7 (calendar-absolute-from-gregorian
642 (list month
(calendar-last-day-of-month month year
) year
))))
643 (calendar-dayname-on-or-before
644 calendar-week-start-day
645 (calendar-absolute-from-gregorian d
)))
652 (defun cal-tex-cursor-week (&optional arg
)
653 "Make a buffer with LaTeX commands for a two-page one-week calendar.
654 It applies to the week that point is in.
655 Optional prefix argument specifies number of weeks.
656 Holidays are included if `cal-tex-holidays' is t."
658 (let* ((n (if arg arg
1))
659 (date (calendar-gregorian-from-absolute
660 (calendar-dayname-on-or-before
661 calendar-week-start-day
662 (calendar-absolute-from-gregorian
663 (calendar-cursor-to-date t
)))))
664 (month (extract-calendar-month date
))
665 (year (extract-calendar-year date
))
666 (holidays (if cal-tex-holidays
667 (cal-tex-list-holidays
668 (calendar-absolute-from-gregorian date
)
670 (calendar-absolute-from-gregorian date
))))))
671 (cal-tex-preamble "11pt")
672 (cal-tex-cmd "\\textwidth 6.5in")
673 (cal-tex-cmd "\\textheight 10.5in")
674 (cal-tex-cmd "\\oddsidemargin 0in")
675 (cal-tex-cmd "\\evensidemargin 0in")
676 (insert cal-tex-LaTeX-hourbox
)
678 (cal-tex-cmd "\\pagestyle{empty}")
679 (calendar-for-loop i from
1 to n do
680 (cal-tex-vspace "-1.5in")
682 (cal-tex-Huge-bf (format "\\uppercase{%s}"
683 (cal-tex-month-name month
)))
684 (cal-tex-hspace "2em")
685 (cal-tex-Huge-bf (number-to-string year
))
688 (cal-tex-hspace "-.2in")
689 (cal-tex-b-parbox "l" "7in")
690 (calendar-for-loop j from
1 to
7 do
691 (cal-tex-week-hours date holidays
"3.1")
692 (setq date
(cal-tex-incr-date date
)))
694 (setq month
(extract-calendar-month date
))
695 (setq year
(extract-calendar-year date
))
698 (run-hooks 'cal-tex-week-hook
)
700 (cal-tex-end-document)
701 (run-hooks 'cal-tex-hook
)))
703 (defun cal-tex-cursor-week2 (&optional arg
)
704 "Make a buffer with LaTeX commands for a two-page one-week calendar.
705 It applies to the week that point is in.
706 Optional prefix argument specifies number of weeks.
707 Holidays are included if `cal-tex-holidays' is t."
709 (let* ((n (if arg arg
1))
710 (date (calendar-gregorian-from-absolute
711 (calendar-dayname-on-or-before
712 calendar-week-start-day
713 (calendar-absolute-from-gregorian
714 (calendar-cursor-to-date t
)))))
715 (month (extract-calendar-month date
))
716 (year (extract-calendar-year date
))
718 (holidays (if cal-tex-holidays
719 (cal-tex-list-holidays
720 (calendar-absolute-from-gregorian date
)
722 (calendar-absolute-from-gregorian date
))))))
723 (cal-tex-preamble "12pt")
724 (cal-tex-cmd "\\textwidth 6.5in")
725 (cal-tex-cmd "\\textheight 10.5in")
726 (cal-tex-cmd "\\oddsidemargin 0in")
727 (cal-tex-cmd "\\evensidemargin 0in")
728 (insert cal-tex-LaTeX-hourbox
)
730 (cal-tex-cmd "\\pagestyle{empty}")
731 (calendar-for-loop i from
1 to n do
732 (cal-tex-vspace "-1.5in")
734 (cal-tex-Huge-bf (format "\\uppercase{%s}"
735 (cal-tex-month-name month
)))
736 (cal-tex-hspace "2em")
737 (cal-tex-Huge-bf (number-to-string year
))
740 (cal-tex-hspace "-.2in")
741 (cal-tex-b-parbox "l" "\\textwidth")
742 (calendar-for-loop j from
1 to
3 do
743 (cal-tex-week-hours date holidays
"5")
744 (setq date
(cal-tex-incr-date date
)))
747 (insert (cal-tex-mini-calendar
748 (extract-calendar-month (cal-tex-previous-month date
))
749 (extract-calendar-year (cal-tex-previous-month date
))
750 "lastmonth" "1.1in" "1in"))
751 (insert (cal-tex-mini-calendar
752 (extract-calendar-month date
)
753 (extract-calendar-year date
)
754 "thismonth" "1.1in" "1in"))
755 (insert (cal-tex-mini-calendar
756 (extract-calendar-month (cal-tex-next-month date
))
757 (extract-calendar-year (cal-tex-next-month date
))
758 "nextmonth" "1.1in" "1in"))
759 (insert "\\hbox to \\textwidth{")
761 (insert "\\lastmonth")
763 (insert "\\thismonth")
765 (insert "\\nextmonth")
769 (cal-tex-b-parbox "l" "\\textwidth")
770 (calendar-for-loop j from
4 to
7 do
771 (cal-tex-week-hours date holidays
"5")
772 (setq date
(cal-tex-incr-date date
)))
774 (setq month
(extract-calendar-month date
))
775 (setq year
(extract-calendar-year date
))
778 (run-hooks 'cal-tex-week-hook
)
780 (cal-tex-end-document)
781 (run-hooks 'cal-tex-hook
)))
783 (defun cal-tex-cursor-week-iso (&optional arg
)
784 "Make a buffer with LaTeX commands for a one page ISO-style weekly calendar.
785 Optional prefix argument specifies number of weeks.
786 Diary entries are included if `cal-tex-diary' is t.
787 Holidays are included if `cal-tex-holidays' is t."
789 (let* ((n (if arg arg
1))
790 (date (calendar-gregorian-from-absolute
791 (calendar-dayname-on-or-before
793 (calendar-absolute-from-gregorian
794 (calendar-cursor-to-date t
)))))
795 (month (extract-calendar-month date
))
796 (year (extract-calendar-year date
))
797 (day (extract-calendar-day date
))
798 (holidays (if cal-tex-holidays
799 (cal-tex-list-holidays
800 (calendar-absolute-from-gregorian date
)
802 (calendar-absolute-from-gregorian date
)))))
803 (diary-list (if cal-tex-diary
804 (cal-tex-list-diary-entries
805 (calendar-absolute-from-gregorian
808 (calendar-absolute-from-gregorian date
))))))
809 (cal-tex-preamble "11pt")
810 (cal-tex-cmd "\\textwidth 6.5in")
811 (cal-tex-cmd "\\textheight 10.5in")
812 (cal-tex-cmd "\\oddsidemargin 0in")
813 (cal-tex-cmd "\\evensidemargin 0in")
815 (cal-tex-cmd "\\pagestyle{empty}")
816 (calendar-for-loop i from
1 to n do
817 (cal-tex-vspace "-1.5in")
820 (let* ((d (calendar-iso-from-absolute
821 (calendar-absolute-from-gregorian date
))))
822 (format "Week %d of %d"
823 (extract-calendar-month d
)
824 (extract-calendar-year d
))))
827 (cal-tex-b-parbox "l" "\\textwidth")
828 (calendar-for-loop j from
1 to
7 do
829 (cal-tex-b-parbox "t" "\\textwidth")
830 (cal-tex-b-parbox "t" "\\textwidth")
831 (cal-tex-rule "0pt" "\\textwidth" ".2mm")
833 (cal-tex-b-parbox "t" "\\textwidth")
834 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
836 (cal-tex-large-bf (cal-tex-month-name month
))
838 (cal-tex-large-bf (number-to-string day
))
839 (if (not (string= "" (cal-tex-latexify-list holidays date
)))
842 (cal-tex-large-bf (cal-tex-latexify-list holidays date
"; "))))
844 (insert " " (eval cal-tex-daily-string
))
848 (cal-tex-b-parbox "t" "\\textwidth")
849 (if (not (string= "" (cal-tex-latexify-list diary-list date
)))
851 (insert "\\vbox to 0pt{")
853 (cal-tex-latexify-list diary-list date
))
857 (setq date
(cal-tex-incr-date date
))
858 (setq month
(extract-calendar-month date
))
859 (setq day
(extract-calendar-day date
))
861 (cal-tex-e-parbox "2cm")
863 (setq month
(extract-calendar-month date
))
864 (setq year
(extract-calendar-year date
)))
868 (run-hooks 'cal-tex-week-hook
)
870 (cal-tex-end-document)
871 (run-hooks 'cal-tex-hook
)))
873 (defvar cal-tex-LaTeX-hourbox
874 "\\newcommand{\\hourbox}[2]%
875 {\\makebox[2em]{\\rule{0cm}{#2ex}#1}\\rule{3in}{.15mm}}\n"
876 "One hour and a line on the right.")
878 (defun cal-tex-week-hours (date holidays height
)
879 "Insert hourly entries for DATE with HOLIDAYS, with line height HEIGHT."
880 (let ((month (extract-calendar-month date
))
881 (day (extract-calendar-day date
))
882 (year (extract-calendar-year date
))
884 (cal-tex-comment "begin cal-tex-week-hours")
885 (cal-tex-cmd "\\ \\\\[-.2cm]")
886 (cal-tex-cmd "\\noindent")
887 (cal-tex-b-parbox "l" "6.8in")
888 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
890 (cal-tex-large-bf (cal-tex-month-name month
))
892 (cal-tex-large-bf (number-to-string day
))
893 (if (not (string= "" (cal-tex-latexify-list holidays date
)))
896 (cal-tex-large-bf (cal-tex-latexify-list holidays date
"; "))))
898 (insert " " (eval cal-tex-daily-string
))
901 (cal-tex-rule "0pt" "6.8in" ".2mm")
903 (calendar-for-loop i from
8 to
12 do
905 (setq afternoon
(+ i
5))
906 (setq afternoon
(- i
7)))
907 (cal-tex-cmd "\\hourbox" (number-to-string i
))
909 (cal-tex-hspace ".4cm")
910 (cal-tex-cmd "\\hourbox" (number-to-string afternoon
))
914 (defun cal-tex-cursor-week-monday (&optional arg
)
915 "Make a buffer with LaTeX commands for a two-page one-week calendar.
916 It applies to the week that point is in, and starts on Monday.
917 Optional prefix argument specifies number of weeks.
918 Holidays are included if `cal-tex-holidays' is t."
920 (let* ((n (if arg arg
1))
921 (date (calendar-gregorian-from-absolute
922 (calendar-dayname-on-or-before
924 (calendar-absolute-from-gregorian
925 (calendar-cursor-to-date t
))))))
926 (cal-tex-preamble "11pt")
927 (cal-tex-cmd "\\textwidth 6.5in")
928 (cal-tex-cmd "\\textheight 10.5in")
929 (cal-tex-cmd "\\oddsidemargin 0in")
930 (cal-tex-cmd "\\evensidemargin 0in")
932 (calendar-for-loop i from
1 to n do
933 (cal-tex-vspace "-1cm")
934 (insert "\\noindent ")
935 (cal-tex-weekly4-box (cal-tex-incr-date date
) nil
)
936 (cal-tex-weekly4-box (cal-tex-incr-date date
4) nil
)
938 (cal-tex-weekly4-box (cal-tex-incr-date date
2) nil
)
939 (cal-tex-weekly4-box (cal-tex-incr-date date
5) nil
)
941 (cal-tex-weekly4-box (cal-tex-incr-date date
3) nil
)
942 (cal-tex-weekly4-box (cal-tex-incr-date date
6) t
)
945 (run-hooks 'cal-tex-week-hook
)
946 (setq date
(cal-tex-incr-date date
7))
948 (cal-tex-end-document)
949 (run-hooks 'cal-tex-hook
)))
951 (defun cal-tex-weekly4-box (date weekend
)
952 "Make one box for DATE, different if WEEKEND."
954 (day (extract-calendar-day date
))
955 (month (extract-calendar-month date
))
956 (year (extract-calendar-year date
))
957 (dayname (cal-tex-LaTeXify-string (calendar-day-name date
)))
958 (date1 (cal-tex-incr-date date
))
959 (day1 (extract-calendar-day date1
))
960 (month1 (extract-calendar-month date1
))
961 (year1 (extract-calendar-year date1
))
962 (dayname1 (cal-tex-LaTeXify-string (calendar-day-name date1
)))
964 (cal-tex-b-framebox "8cm" "l")
965 (cal-tex-b-parbox "b" "7.5cm")
966 (insert (format "{\\Large\\bf %s,} %s/%s/%s\\\\\n" dayname month day year
))
967 (cal-tex-rule "0pt" "7.5cm" ".5mm")
971 (calendar-for-loop i from
8 to
12 do
972 (insert (format "{\\large\\sf %d}\\\\\n" i
)))
973 (calendar-for-loop i from
1 to
5 do
974 (insert (format "{\\large\\sf %d}\\\\\n"
975 (if cal-tex-24
(+ i
12) i
))))))
979 (cal-tex-vspace "1cm")
980 (insert "\\ \\vfill")
981 (insert (format "{\\Large\\bf %s,} %s/%s/%s\\\\\n"
982 dayname1 month1 day1 year1
))
983 (cal-tex-rule "0pt" "7.5cm" ".5mm")
985 (cal-tex-vspace "1cm")))
988 (cal-tex-hspace "1cm")))
990 (defun cal-tex-cursor-filofax-2week (&optional arg
)
991 "Two-weeks-at-a-glance Filofax style calendar for week indicated by cursor.
992 Optional prefix argument specifies number of weeks.
993 Diary entries are included if `cal-tex-diary' is t.
994 Holidays are included if `cal-tex-holidays' is t."
996 (let* ((n (if arg arg
1))
997 (date (calendar-gregorian-from-absolute
998 (calendar-dayname-on-or-before
999 calendar-week-start-day
1000 (calendar-absolute-from-gregorian
1001 (calendar-cursor-to-date t
)))))
1002 (month (extract-calendar-month date
))
1003 (year (extract-calendar-year date
))
1004 (day (extract-calendar-day date
))
1005 (holidays (if cal-tex-holidays
1006 (cal-tex-list-holidays
1007 (calendar-absolute-from-gregorian date
)
1009 (calendar-absolute-from-gregorian date
)))))
1010 (diary-list (if cal-tex-diary
1011 (cal-tex-list-diary-entries
1012 (calendar-absolute-from-gregorian
1013 (list month
1 year
))
1015 (calendar-absolute-from-gregorian date
))))))
1016 (cal-tex-preamble "twoside")
1017 (cal-tex-cmd "\\textwidth 3.25in")
1018 (cal-tex-cmd "\\textheight 6.5in")
1019 (cal-tex-cmd "\\oddsidemargin 1.75in")
1020 (cal-tex-cmd "\\evensidemargin 1.5in")
1021 (cal-tex-cmd "\\topmargin 0pt")
1022 (cal-tex-cmd "\\headheight -0.875in")
1023 (cal-tex-cmd "\\headsep 0.125in")
1024 (cal-tex-cmd "\\footskip .125in")
1025 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1026 \\long\\def\\rightday#1#2#3#4#5{%
1027 \\rule{\\textwidth}{0.3pt}\\\\%
1028 \\hbox to \\textwidth{%
1031 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1032 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1033 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1034 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1035 \\long\\def\\leftday#1#2#3#4#5{%
1036 \\rule{\\textwidth}{0.3pt}\\\\%
1037 \\hbox to \\textwidth{%
1040 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1041 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1042 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1044 (cal-tex-b-document)
1045 (cal-tex-cmd "\\pagestyle{empty}")
1046 (calendar-for-loop i from
1 to n do
1048 (insert "\\righthead")
1049 (insert "\\lefthead"))
1051 (let ((d (cal-tex-incr-date date
6)))
1052 (if (= (extract-calendar-month date
)
1053 (extract-calendar-month d
))
1056 (extract-calendar-month date
))
1057 (extract-calendar-year date
))
1058 (if (= (extract-calendar-year date
)
1059 (extract-calendar-year d
))
1060 (format "%s---%s %s"
1062 (extract-calendar-month date
))
1064 (extract-calendar-month d
))
1065 (extract-calendar-year date
))
1066 (format "%s %s---%s %s"
1068 (extract-calendar-month date
))
1069 (extract-calendar-year date
)
1070 (cal-tex-month-name (extract-calendar-month d
))
1071 (extract-calendar-year d
))))))
1073 (calendar-for-loop j from
1 to
7 do
1075 (insert "\\rightday")
1076 (insert "\\leftday"))
1077 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1078 (cal-tex-arg (int-to-string (extract-calendar-day date
)))
1079 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1080 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1081 (cal-tex-arg (eval cal-tex-daily-string
))
1083 (setq date
(cal-tex-incr-date date
)))
1086 (run-hooks 'cal-tex-week-hook
)
1087 (cal-tex-newpage))))
1088 (cal-tex-end-document)
1089 (run-hooks 'cal-tex-hook
)))
1091 (defun cal-tex-cursor-filofax-week (&optional arg
)
1092 "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
1093 Optional prefix argument specifies number of weeks.
1094 Weeks start on Monday.
1095 Diary entries are included if `cal-tex-diary' is t.
1096 Holidays are included if `cal-tex-holidays' is t."
1098 (let* ((n (if arg arg
1))
1099 (date (calendar-gregorian-from-absolute
1100 (calendar-dayname-on-or-before
1102 (calendar-absolute-from-gregorian
1103 (calendar-cursor-to-date t
)))))
1104 (month (extract-calendar-month date
))
1105 (year (extract-calendar-year date
))
1106 (day (extract-calendar-day date
))
1107 (holidays (if cal-tex-holidays
1108 (cal-tex-list-holidays
1109 (calendar-absolute-from-gregorian date
)
1111 (calendar-absolute-from-gregorian date
)))))
1112 (diary-list (if cal-tex-diary
1113 (cal-tex-list-diary-entries
1114 (calendar-absolute-from-gregorian
1115 (list month
1 year
))
1117 (calendar-absolute-from-gregorian date
))))))
1118 (cal-tex-preamble "twoside")
1119 (cal-tex-cmd "\\textwidth 3.25in")
1120 (cal-tex-cmd "\\textheight 6.5in")
1121 (cal-tex-cmd "\\oddsidemargin 1.75in")
1122 (cal-tex-cmd "\\evensidemargin 1.5in")
1123 (cal-tex-cmd "\\topmargin 0pt")
1124 (cal-tex-cmd "\\headheight -0.875in")
1125 (cal-tex-cmd "\\headsep 0.125in")
1126 (cal-tex-cmd "\\footskip .125in")
1127 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1128 \\long\\def\\rightday#1#2#3#4#5{%
1129 \\rule{\\textwidth}{0.3pt}\\\\%
1130 \\hbox to \\textwidth{%
1133 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1134 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1135 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1136 \\long\\def\\weekend#1#2#3#4#5{%
1137 \\rule{\\textwidth}{0.3pt}\\\\%
1138 \\hbox to \\textwidth{%
1141 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1142 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1143 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1144 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1145 \\long\\def\\leftday#1#2#3#4#5{%
1146 \\rule{\\textwidth}{0.3pt}\\\\%
1147 \\hbox to \\textwidth{%
1150 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1151 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1152 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1154 (cal-tex-b-document)
1155 (cal-tex-cmd "\\pagestyle{empty}\\ ")
1157 (calendar-for-loop i from
1 to n do
1158 (insert "\\lefthead")
1160 (let ((d (cal-tex-incr-date date
2)))
1161 (if (= (extract-calendar-month date
)
1162 (extract-calendar-month d
))
1165 (extract-calendar-month date
))
1166 (extract-calendar-year date
))
1167 (if (= (extract-calendar-year date
)
1168 (extract-calendar-year d
))
1169 (format "%s---%s %s"
1171 (extract-calendar-month date
))
1173 (extract-calendar-month d
))
1174 (extract-calendar-year date
))
1175 (format "%s %s---%s %s"
1177 (extract-calendar-month date
))
1178 (extract-calendar-year date
)
1179 (cal-tex-month-name (extract-calendar-month d
))
1180 (extract-calendar-year d
))))))
1182 (calendar-for-loop j from
1 to
3 do
1183 (insert "\\leftday")
1184 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1185 (cal-tex-arg (int-to-string (extract-calendar-day date
)))
1186 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1187 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1188 (cal-tex-arg (eval cal-tex-daily-string
))
1190 (setq date
(cal-tex-incr-date date
)))
1191 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1193 (insert "\\righthead")
1195 (let ((d (cal-tex-incr-date date
3)))
1196 (if (= (extract-calendar-month date
)
1197 (extract-calendar-month d
))
1200 (extract-calendar-month date
))
1201 (extract-calendar-year date
))
1202 (if (= (extract-calendar-year date
)
1203 (extract-calendar-year d
))
1204 (format "%s---%s %s"
1206 (extract-calendar-month date
))
1208 (extract-calendar-month d
))
1209 (extract-calendar-year date
))
1210 (format "%s %s---%s %s"
1212 (extract-calendar-month date
))
1213 (extract-calendar-year date
)
1214 (cal-tex-month-name (extract-calendar-month d
))
1215 (extract-calendar-year d
))))))
1217 (calendar-for-loop j from
1 to
2 do
1218 (insert "\\rightday")
1219 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1220 (cal-tex-arg (int-to-string (extract-calendar-day date
)))
1221 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1222 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1223 (cal-tex-arg (eval cal-tex-daily-string
))
1225 (setq date
(cal-tex-incr-date date
)))
1226 (calendar-for-loop j from
1 to
2 do
1227 (insert "\\weekend")
1228 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1229 (cal-tex-arg (int-to-string (extract-calendar-day date
)))
1230 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1231 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1232 (cal-tex-arg (eval cal-tex-daily-string
))
1234 (setq date
(cal-tex-incr-date date
)))
1237 (run-hooks 'cal-tex-week-hook
)
1238 (cal-tex-newpage))))
1239 (cal-tex-end-document)
1240 (run-hooks 'cal-tex-hook
)))
1242 (defun cal-tex-cursor-filofax-daily (&optional arg
)
1243 "Day-per-page Filofax style calendar for week indicated by cursor.
1244 Optional prefix argument specifies number of weeks. Weeks start on Monday.
1245 Diary entries are included if `cal-tex-diary' is t.
1246 Holidays are included if `cal-tex-holidays' is t.
1247 Pages are ruled if `cal-tex-rules' is t."
1249 (let* ((n (if arg arg
1))
1250 (date (calendar-gregorian-from-absolute
1251 (calendar-dayname-on-or-before
1253 (calendar-absolute-from-gregorian
1254 (calendar-cursor-to-date t
)))))
1255 (month (extract-calendar-month date
))
1256 (year (extract-calendar-year date
))
1257 (day (extract-calendar-day date
))
1258 (holidays (if cal-tex-holidays
1259 (cal-tex-list-holidays
1260 (calendar-absolute-from-gregorian date
)
1262 (calendar-absolute-from-gregorian date
)))))
1263 (diary-list (if cal-tex-diary
1264 (cal-tex-list-diary-entries
1265 (calendar-absolute-from-gregorian
1266 (list month
1 year
))
1268 (calendar-absolute-from-gregorian date
))))))
1269 (cal-tex-preamble "twoside")
1270 (cal-tex-cmd "\\textwidth 3.25in")
1271 (cal-tex-cmd "\\textheight 6.5in")
1272 (cal-tex-cmd "\\oddsidemargin 1.75in")
1273 (cal-tex-cmd "\\evensidemargin 1.5in")
1274 (cal-tex-cmd "\\topmargin 0pt")
1275 (cal-tex-cmd "\\headheight -0.875in")
1276 (cal-tex-cmd "\\headsep 0.125in")
1277 (cal-tex-cmd "\\footskip .125in")
1278 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1279 \\long\\def\\rightday#1#2#3{%
1280 \\rule{\\textwidth}{0.3pt}\\\\%
1281 \\hbox to \\textwidth{%
1284 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1285 \\hbox to \\textwidth{\\vbox {\\raggedleft \\em #2}}%
1286 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1287 \\long\\def\\weekend#1#2#3{%
1288 \\rule{\\textwidth}{0.3pt}\\\\%
1289 \\hbox to \\textwidth{%
1292 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1293 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1294 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1295 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1296 \\long\\def\\leftday#1#2#3{%
1297 \\rule{\\textwidth}{0.3pt}\\\\%
1298 \\hbox to \\textwidth{%
1301 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1302 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1303 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1305 \\setbox\\LineBox=\\hbox to\\textwidth{%
1306 \\vrule height.2in width0pt\\leaders\\hrule\\hfill}
1307 \\def\\linesfill{\\par\\leaders\\copy\\LineBox\\vfill}
1309 (cal-tex-b-document)
1310 (cal-tex-cmd "\\pagestyle{empty}")
1311 (calendar-for-loop i from
1 to n do
1312 (calendar-for-loop j from
1 to
5 do
1313 (let ((odd (/= 0 (% j
2))))
1314 (insert (if odd
"\\righthead" "\\lefthead"))
1315 (cal-tex-arg (calendar-date-string date
))
1317 (insert (if odd
"\\rightday" "\\leftday")))
1318 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1319 (cal-tex-arg (cal-tex-latexify-list holidays date
"\\\\" t
))
1320 (cal-tex-arg (eval cal-tex-daily-string
))
1323 (insert "\\linesfill\n")
1324 (insert "\\vfill\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1326 (setq date
(cal-tex-incr-date date
)))
1328 (calendar-for-loop j from
1 to
2 do
1329 (insert "\\lefthead")
1330 (cal-tex-arg (calendar-date-string date
))
1331 (insert "\\weekend")
1332 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1333 (cal-tex-arg (cal-tex-latexify-list holidays date
"\\\\" t
))
1334 (cal-tex-arg (eval cal-tex-daily-string
))
1337 (insert "\\linesfill\n")
1339 (setq date
(cal-tex-incr-date date
)))
1340 (if (not cal-tex-rules
)
1341 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1344 (run-hooks 'cal-tex-week-hook
)
1345 (cal-tex-newpage))))
1346 (cal-tex-end-document)
1347 (run-hooks 'cal-tex-hook
)))
1354 (defun cal-tex-cursor-day (&optional arg
)
1355 "Make a buffer with LaTeX commands for the day cursor is on.
1356 Optional prefix argument specifies number of days."
1358 (let ((n (if arg arg
1))
1359 (date (calendar-absolute-from-gregorian (calendar-cursor-to-date t
))))
1360 (cal-tex-preamble "12pt")
1361 (cal-tex-cmd "\\textwidth 6.5in")
1362 (cal-tex-cmd "\\textheight 10.5in")
1363 (cal-tex-b-document)
1364 (cal-tex-cmd "\\pagestyle{empty}")
1365 (calendar-for-loop i from
1 to n do
1366 (cal-tex-vspace "-1.7in")
1367 (cal-tex-daily-page (calendar-gregorian-from-absolute date
))
1368 (setq date
(1+ date
))
1372 (run-hooks 'cal-tex-daily-hook
))))
1373 (cal-tex-end-document)
1374 (run-hooks 'cal-tex-hook
)))
1376 (defun cal-tex-daily-page (date)
1377 "Make a calendar page for Gregorian DATE on 8.5 by 11 paper."
1379 (month-name (cal-tex-month-name (extract-calendar-month date
))))
1380 (cal-tex-banner "cal-tex-daily-page")
1381 (cal-tex-b-makebox "4cm" "l")
1382 (cal-tex-b-parbox "b" "3.8cm")
1383 (cal-tex-rule "0mm" "0mm" "2cm")
1384 (cal-tex-Huge (number-to-string (extract-calendar-day date
)))
1386 (cal-tex-bf month-name
)
1388 (cal-tex-hspace "1cm")
1389 (cal-tex-scriptsize (eval cal-tex-daily-string
))
1390 (cal-tex-hspace "3.5cm")
1393 (cal-tex-b-makebox "4cm" "r")
1394 (cal-tex-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
1397 (cal-tex-hspace ".4cm")
1398 (cal-tex-rule "0mm" "16.1cm" "1mm")
1400 (calendar-for-loop i from cal-tex-daily-start to cal-tex-daily-end do
1401 (cal-tex-cmd "\\noindent")
1402 (setq hour
(if cal-tex-24
1405 (if (= 0 hour
) (setq hour
12))
1406 (cal-tex-b-makebox "1cm" "c")
1407 (cal-tex-arg (number-to-string hour
))
1409 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1411 (cal-tex-b-makebox "1cm" "c")
1412 (cal-tex-arg "$\\diamond$" )
1414 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1415 (cal-tex-nl ".2cm"))
1417 (insert (cal-tex-mini-calendar
1418 (extract-calendar-month (cal-tex-previous-month date
))
1419 (extract-calendar-year (cal-tex-previous-month date
))
1420 "lastmonth" "1.1in" "1in"))
1421 (insert (cal-tex-mini-calendar
1422 (extract-calendar-month date
)
1423 (extract-calendar-year date
)
1424 "thismonth" "1.1in" "1in"))
1425 (insert (cal-tex-mini-calendar
1426 (extract-calendar-month (cal-tex-next-month date
))
1427 (extract-calendar-year (cal-tex-next-month date
))
1428 "nextmonth" "1.1in" "1in"))
1429 (insert "\\hbox to \\textwidth{")
1431 (insert "\\lastmonth")
1433 (insert "\\thismonth")
1435 (insert "\\nextmonth")
1438 (cal-tex-banner "end of cal-tex-daily-page")))
1444 (defun cal-tex-mini-calendar (month year name width height
&optional ptsize colsep
)
1445 "Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT.
1446 Optional PTSIZE gives the point ptsize; scriptsize is the default. Optional
1447 COLSEP gives the column separation; 1mm is the default."
1448 (let* ((blank-days;; at start of month
1450 (- (calendar-day-of-week (list month
1 year
))
1451 calendar-week-start-day
)
1453 (last (calendar-last-day-of-month month year
))
1454 (colsep (if colsep colsep
"1mm"))
1455 (str (concat "\\def\\" name
"{\\hbox to" width
"{%\n"
1456 "\\vbox to" height
"{%\n"
1457 "\\vfil \\hbox to" width
"{%\n"
1459 (if ptsize ptsize
"scriptsize")
1461 "{@{\\hspace{0mm}}r@{\\hspace{" colsep
1462 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{" colsep
1463 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{" colsep
1464 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{0mm}}}%\n"
1465 "\\multicolumn{7}{c}{"
1466 (cal-tex-month-name month
)
1468 (int-to-string year
)
1470 (calendar-for-loop i from
0 to
6 do
1473 (cal-tex-LaTeXify-string
1474 (substring (aref calendar-day-name-array
1475 (mod (+ calendar-week-start-day i
) 7))
1480 (calendar-for-loop i from
1 to blank-days do
1481 (setq str
(concat str
" & ")))
1482 (calendar-for-loop i from
1 to last do
1483 (setq str
(concat str
(int-to-string i
)))
1484 (setq str
(concat str
(if (zerop (mod (+ i blank-days
) 7))
1485 (if (/= i last
) "\\\\[0.5mm]\n" "")
1487 (setq str
(concat str
"\n\\end{tabular}\\hfil}\\vfil}}}%\n"))
1491 ;;; Various calendar functions
1494 (defun cal-tex-incr-date (date &optional n
)
1495 "The date of the day following DATE.
1496 If optional N is given, the date of N days after DATE."
1497 (calendar-gregorian-from-absolute
1498 (+ (if n n
1) (calendar-absolute-from-gregorian date
))))
1500 (defun cal-tex-latexify-list (date-list date
&optional separator final-separator
)
1501 "Return string with concatenated, LaTeXified entries in DATE-LIST for DATE.
1502 Use double backslash as a separator unless optional SEPARATOR is given.
1503 If resulting string is not empty, put separator at end if optional
1504 FINAL-SEPARATOR is t."
1505 (let* ((sep (if separator separator
"\\\\"))
1507 (mapconcat '(lambda (x) (cal-tex-LaTeXify-string x
))
1512 (calendar-date-equal date
(car (car p
)))
1513 (setq result
(cons (car (cdr (car p
))) result
)))
1517 (if (and final-separator
(not (string-equal result
"")))
1521 (defun cal-tex-previous-month (date)
1522 "Return the date of the first day in the month previous to DATE."
1523 (let* ((month (extract-calendar-month date
))
1524 (year (extract-calendar-year date
)))
1525 (increment-calendar-month month year -
1)
1526 (list month
1 year
)))
1528 (defun cal-tex-next-month (date)
1529 "Return the date of the first day in the month following DATE."
1530 (let* ((month (extract-calendar-month date
))
1531 (year (extract-calendar-year date
)))
1532 (increment-calendar-month month year
1)
1533 (list month
1 year
)))
1539 (defun cal-tex-end-document ()
1540 "Finish the LaTeX document.
1541 Insert the trailer to LaTeX document, pop to LaTeX buffer, add
1542 informative header, and run HOOK."
1543 (cal-tex-e-document)
1545 (pop-to-buffer cal-tex-buffer
)
1546 (goto-char (point-min))
1547 (cal-tex-comment " This buffer was produced by cal-tex.el.")
1548 (cal-tex-comment " To print a calendar, type")
1549 (cal-tex-comment " M-x tex-buffer RET")
1550 (cal-tex-comment " M-x tex-print RET")
1551 (goto-char (point-min)))
1553 (defun cal-tex-insert-preamble (weeks landscape size
&optional append
)
1554 "Initialize the output buffer.
1555 Select the output buffer, and insert the preamble for a calendar of
1556 WEEKS weeks. Insert code for landscape mode if LANDSCAPE is true.
1557 Use pointsize SIZE. Optional argument APPEND, if t, means add to end of
1558 without erasing current contents."
1559 (let ((width "18cm")
1564 (setq height
"18cm")))
1567 (cal-tex-preamble size
)
1570 (cal-tex-cmd "\\oddsidemargin -1.75cm")
1571 (cal-tex-cmd "\\def\\holidaymult{.06}"))
1572 (cal-tex-cmd "\\special{landscape}")
1573 (cal-tex-cmd "\\textwidth 9.5in")
1574 (cal-tex-cmd "\\textheight 7in")
1576 (cal-tex-cmd "\\def\\holidaymult{.08}"))
1577 (cal-tex-cmd cal-tex-caldate
)
1578 (cal-tex-cmd cal-tex-myday
)
1579 (cal-tex-b-document)
1580 (cal-tex-cmd "\\pagestyle{empty}")))
1581 (cal-tex-cmd "\\setlength{\\cellwidth}" width
)
1582 (insert (format "\\setlength{\\cellwidth}{%f\\cellwidth}\n"
1583 (/ 1.1 (length cal-tex-which-days
))))
1584 (cal-tex-cmd "\\setlength{\\cellheight}" height
)
1585 (insert (format "\\setlength{\\cellheight}{%f\\cellheight}\n"
1587 (cal-tex-cmd "\\ \\par")
1588 (cal-tex-vspace "-3cm")))
1590 (defvar cal-tex-LaTeX-subst-list
1592 ("\"".
"''");; Quote changes meaning when list is reversed.
1603 ("\n" .
"\\ \\\\")) ;\\ needed for e.g \begin{center}\n AA\end{center}
1604 "List of symbols and their replacements.")
1606 (defun cal-tex-LaTeXify-string (string)
1607 "Protect special characters in STRING from LaTeX."
1612 (list cal-tex-LaTeX-subst-list
))
1613 (while (not (string-equal tail
""))
1614 (let* ((ch (substring tail
0 1))
1615 (pair (assoc ch list
)))
1616 (if (and pair
(string-equal ch
"\""))
1617 (setq list
(reverse list
)));; Quote changes meaning each time.
1618 (setq tail
(substring tail
1))
1619 (setq head
(concat head
(if pair
(cdr pair
) ch
)))))
1622 (defun cal-tex-month-name (month)
1623 "The name of MONTH, LaTeXified."
1624 (cal-tex-LaTeXify-string (calendar-month-name month
)))
1626 (defun cal-tex-hfill () "Insert hfill." (insert "\\hfill"))
1628 (defun cal-tex-newpage () "Insert newpage." (insert "\\newpage%\n"))
1630 (defun cal-tex-noindent () "Insert noindent." (insert "\\noindent"))
1632 (defun cal-tex-vspace (space)
1633 "Insert vspace command to move SPACE vertically."
1634 (insert "\\vspace*{" space
"}")
1637 (defun cal-tex-hspace (space)
1638 "Insert hspace command to move SPACE horizontally."
1639 (insert "\\hspace*{" space
"}")
1642 (defun cal-tex-comment (&optional comment
)
1643 "Insert % at end of line, include COMMENT if present, and move
1650 (defun cal-tex-banner (comment)
1651 "Insert the COMMENT separated by blank lines."
1654 (cal-tex-comment (concat "\t\t\t" comment
))
1658 (defun cal-tex-nl (&optional skip comment
)
1659 "End a line with \\. If SKIP, then add that much spacing.
1660 Add COMMENT if present"
1663 (insert "[" skip
"]"))
1664 (cal-tex-comment comment
))
1666 (defun cal-tex-arg (&optional text
)
1667 "Insert optional TEXT surrounded by braces."
1669 (if text
(insert text
))
1672 (defun cal-tex-cmd (cmd &optional arg
)
1673 "Insert LaTeX CMD, with optional ARG, and end with %"
1682 (defun cal-tex-b-document ()
1683 "Insert beginning of document."
1684 (cal-tex-cmd "\\begin{document}"))
1686 (defun cal-tex-e-document ()
1687 "Insert end of document."
1688 (cal-tex-cmd "\\end{document}"))
1690 (defun cal-tex-b-center ()
1691 "Insert beginning of centered block."
1692 (cal-tex-cmd "\\begin{center}"))
1694 (defun cal-tex-e-center ()
1695 "Insert end of centered block."
1697 (cal-tex-cmd "\\end{center}"))
1705 (defun cal-tex-b-parbox (position width
)
1706 "Insert parbox with parameters POSITION and WIDTH."
1707 (insert "\\parbox[" position
"]{" width
"}{")
1710 (defun cal-tex-e-parbox (&optional height
)
1711 "Insert end of parbox. Force it to be a given HEIGHT."
1714 (cal-tex-rule "0mm" "0mm" height
))
1716 (cal-tex-comment "end parbox"))
1718 (defun cal-tex-b-framebox ( width position
)
1719 "Insert framebox with parameters WIDTH and POSITION (clr)."
1720 (insert "\\framebox[" width
"][" position
"]{" )
1723 (defun cal-tex-e-framebox ()
1724 "Insert end of framebox."
1727 (cal-tex-comment "end framebox"))
1730 (defun cal-tex-b-makebox ( width position
)
1731 "Insert makebox with parameters WIDTH and POSITION (clr)."
1732 (insert "\\makebox[" width
"][" position
"]{" )
1735 (defun cal-tex-e-makebox ()
1736 "Insert end of makebox."
1739 (cal-tex-comment "end makebox"))
1742 (defun cal-tex-rule (lower width height
)
1743 "Insert a rule with parameters LOWER WIDTH HEIGHT."
1744 (insert "\\rule[" lower
"]{" width
"}{" height
"}"))
1750 (defun cal-tex-em (string)
1751 "Insert STRING in bf font."
1752 (insert "{\\em " string
"}"))
1754 (defun cal-tex-bf (string)
1755 "Insert STRING in bf font."
1756 (insert "{\\bf " string
"}"))
1758 (defun cal-tex-scriptsize (string)
1759 "Insert STRING in scriptsize font."
1760 (insert "{\\scriptsize " string
"}"))
1762 (defun cal-tex-huge (string)
1763 "Insert STRING in huge size."
1764 (insert "{\\huge " string
"}"))
1766 (defun cal-tex-Huge (string)
1767 "Insert STRING in Huge size."
1768 (insert "{\\Huge " string
"}"))
1770 (defun cal-tex-Huge-bf (string)
1771 "Insert STRING in Huge bf size."
1772 (insert "{\\Huge\\bf " string
"}"))
1774 (defun cal-tex-large (string)
1775 "Insert STRING in large size."
1776 (insert "{\\large " string
"}"))
1778 (defun cal-tex-large-bf (string)
1779 "Insert STRING in large bf size."
1780 (insert "{\\large\\bf " string
"}"))
1784 ;;; cal-tex.el ends here