1 ;;; cal-tex.el --- calendar functions for printing calendars with LaTeX
3 ;; Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005, 2006
4 ;; Free Software Foundation, Inc.
6 ;; Author: Steve Fisk <fisk@bowdoin.edu>
7 ;; Edward M. Reingold <reingold@cs.uiuc.edu>
8 ;; Maintainer: Glenn Morris <rgm@gnu.org>
10 ;; Human-Keywords: Calendar, LaTeX
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
31 ;; This collection of functions implements the creation of LaTeX calendars
32 ;; based on the user's holiday choices and diary file.
36 ;; (*) Add holidays and diary entries to daily calendar.
38 ;; (*) Add diary entries to weekly calendar functions.
40 ;; (*) Make calendar styles for A4 paper.
42 ;; (*) Make monthly styles Filofax paper.
48 (autoload 'diary-list-entries "diary-lib" nil t)
49 (autoload 'calendar-holiday-list "holidays" nil t)
50 (autoload 'calendar-iso-from-absolute "cal-iso" nil t)
53 ;;; Customizable variables
56 (defcustom cal-tex-which-days '(0 1 2 3 4 5 6)
57 "*The days of the week that are displayed on the portrait monthly calendar.
58 Sunday is 0, Monday is 1, and so on. The default is to print from Sunday to
59 Saturday. For example, use
61 (setq cal-tex-which-days '(1 3 5))
63 to only print Monday, Wednesday, Friday."
64 :type '(repeat integer)
67 (defcustom cal-tex-holidays t
68 "*If t (default), then the holidays are also printed.
69 If finding the holidays is too slow, set this to nil."
73 (defcustom cal-tex-diary nil
74 "*If t, the diary entries are printed in the calendar."
78 (defcustom cal-tex-rules nil
79 "*If t, pages will be ruled in some styles."
83 (defcustom cal-tex-daily-string
84 '(let* ((year (extract-calendar-year date))
85 (day (calendar-day-number date))
86 (days-remaining (- (calendar-day-number (list 12 31 year)) day)))
87 (format "%d/%d" day days-remaining))
88 "*An expression in the variable `date' whose value is placed on date.
89 The string resulting from evaluating this expression is placed at the bottom
90 center of `date' on the monthly calendar, next to the date in the weekly
91 calendars, and in the top center of daily calendars.
93 Default is ordinal day number of the year and the number of days remaining.
94 As an example of what you do, setting this to
98 (calendar-hebrew-date-string date))
100 will put the Hebrew date at the bottom of each day."
102 :group 'calendar-tex)
104 (defcustom cal-tex-buffer "calendar.tex"
105 "*The name for the tex-ed calendar."
107 :group 'calendar-tex)
109 (defcustom cal-tex-24 nil
110 "*If t, use a 24 hour clock in the daily calendar."
112 :group 'calendar-tex)
114 (defcustom cal-tex-daily-start 8
115 "*The first hour of the daily calendar page."
117 :group 'calendar-tex)
119 (defcustom cal-tex-daily-end 20
120 "*The last hour of the daily calendar page."
122 :group 'calendar-tex)
124 (defcustom cal-tex-preamble-extra nil
125 "A string giving extra LaTeX commands to insert in the calendar preamble.
126 For example, to include extra packages:
127 \"\\\\usepackage{foo}\\n\\\\usepackage{bar}\\n\"."
132 (defcustom cal-tex-hook nil
133 "*List of functions called after any LaTeX calendar buffer is generated.
134 You can use this to do postprocessing on the buffer. For example, to change
135 characters with diacritical marks to their LaTeX equivalents, use
136 (add-hook 'cal-tex-hook
137 '(lambda () (iso-iso2tex (point-min) (point-max))))"
139 :group 'calendar-tex)
141 (defcustom cal-tex-year-hook nil
142 "*List of functions called after a LaTeX year calendar buffer is generated."
144 :group 'calendar-tex)
146 (defcustom cal-tex-month-hook nil
147 "*List of functions called after a LaTeX month calendar buffer is generated."
149 :group 'calendar-tex)
151 (defcustom cal-tex-week-hook nil
152 "*List of functions called after a LaTeX week calendar buffer is generated."
154 :group 'calendar-tex)
156 (defcustom cal-tex-daily-hook nil
157 "*List of functions called after a LaTeX daily calendar buffer is generated."
159 :group 'calendar-tex)
162 ;;; Definitions for LaTeX code
165 (defvar cal-tex-day-prefix "\\caldate{%s}{%s}"
166 "The initial LaTeX code for a day.
167 The holidays, diary entries, bottom string, and the text follow.")
169 (defvar cal-tex-day-name-format "\\myday{%s}%%"
170 "The format for LaTeX code for a day name. The names are taken from
171 `calendar-day-name-array'.")
173 (defvar cal-tex-cal-one-month
174 "\\def\\calmonth#1#2%
176 \\Huge\\bf\\uppercase{#1} #2 \\\\[1cm]%
181 "LaTeX code for the month header")
183 (defvar cal-tex-cal-multi-month
184 "\\def\\calmonth#1#2#3#4%
186 \\Huge\\bf #1 #2---#3 #4\\\\[1cm]%
191 "LaTeX code for the month header")
193 (defvar cal-tex-myday
194 "\\renewcommand{\\myday}[1]%
195 {\\makebox[\\cellwidth]{\\hfill\\large\\bf#1\\hfill}}
198 "LaTeX code for a day heading")
200 (defvar cal-tex-caldate
202 \\long\\def\\caldate#1#2#3#4#5#6{%
203 \\fbox{\\hbox to\\cellwidth{%
204 \\vbox to\\cellheight{%
205 \\hbox to\\cellwidth{%
206 {\\hspace*{1mm}\\Large \\bf \\strut #2}\\hspace{.05\\cellwidth}%
207 \\raisebox{\\holidaymult\\cellheight}%
208 {\\parbox[t]{.75\\cellwidth}{\\tiny \\raggedright #4}}}
209 \\hbox to\\cellwidth{%
210 \\hspace*{1mm}\\parbox{.95\\cellwidth}{\\tiny \\raggedright #3}}
212 \\hbox to\\cellwidth{#6}%
214 \\hbox to\\cellwidth{\\hfill \\tiny #5 \\hfill}%
218 "LaTeX code to insert one box with date info in calendar.
219 This definition is the heart of the calendar!")
221 (defun cal-tex-list-holidays (d1 d2)
222 "Generate a list of all holidays from absolute date D1 to D2."
223 (let* ((start (calendar-gregorian-from-absolute d1))
224 (displayed-month (extract-calendar-month start))
225 (displayed-year (extract-calendar-year start))
226 (end (calendar-gregorian-from-absolute d2))
227 (end-month (extract-calendar-month end))
228 (end-year (extract-calendar-year end))
230 (1+ (/ (calendar-interval displayed-month displayed-year
235 (increment-calendar-month displayed-month displayed-year 1)
236 (calendar-for-loop i from 1 to number-of-intervals do
237 (setq holidays (append holidays (calendar-holiday-list)))
238 (increment-calendar-month displayed-month displayed-year 3))
240 (and (car (car holidays))
241 (let ((a (calendar-absolute-from-gregorian (car (car holidays)))))
242 (and (<= d1 a) (<= a d2)))
243 (setq in-range (append (list (car holidays)) in-range)))
244 (setq holidays (cdr holidays)))
247 (defun cal-tex-list-diary-entries (d1 d2)
248 "Generate a list of all diary-entries from absolute date D1 to D2."
249 (let ((diary-list-include-blanks nil)
250 (diary-display-hook 'ignore))
252 (calendar-gregorian-from-absolute d1)
255 (defun cal-tex-preamble (&optional args)
256 "Insert the LaTeX preamble.
257 Preamble Includes initial definitions for various LaTeX commands.
258 Optional ARGS are included."
259 (set-buffer (get-buffer-create cal-tex-buffer))
261 (insert "\\documentclass")
263 (insert "[" args "]"))
264 (insert "{article}\n")
265 (if (stringp cal-tex-preamble-extra)
266 (insert cal-tex-preamble-extra "\n"))
267 (insert "\\hbadness 20000
273 \\evensidemargin -2cm
278 \\newlength{\\cellwidth}
279 \\newlength{\\cellheight}
280 \\newlength{\\boxwidth}
281 \\newlength{\\boxheight}
282 \\newlength{\\cellsize}
283 \\newcommand{\\myday}[1]{}
284 \\newcommand{\\caldate}[6]{}
285 \\newcommand{\\nocaldate}[6]{}
286 \\newcommand{\\calsmall}[6]{}
294 (defun cal-tex-cursor-year (&optional arg)
295 "Make a buffer with LaTeX commands for the year cursor is on.
296 Optional prefix argument specifies number of years."
298 (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
301 (defun cal-tex-cursor-year-landscape (&optional arg)
302 "Make a buffer with LaTeX commands for the year cursor is on.
303 Optional prefix argument specifies number of years."
305 (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
309 (defun cal-tex-year (year n &optional landscape)
310 "Make a one page yearly calendar of YEAR; do this for N years.
311 There are four rows of three months each, unless optional LANDSCAPE is t,
312 in which case the calendar isprinted in landscape mode with three rows of
314 (cal-tex-insert-preamble 1 landscape "12pt")
316 (cal-tex-vspace "-.6cm")
317 (cal-tex-vspace "-3.1cm"))
318 (calendar-for-loop j from 1 to n do
319 (insert "\\vfill%\n")
321 (cal-tex-Huge (number-to-string year))
323 (cal-tex-vspace "1cm")
325 (cal-tex-b-parbox "l" (if landscape "5.9in" "4.3in"))
329 (calendar-for-loop i from 1 to 12 do
330 (insert (cal-tex-mini-calendar i year "month" "1.1in" "1in"))
332 (cal-tex-hspace "0.5in")
333 (if (zerop (mod i (if landscape 4 3)))
334 (cal-tex-nl "0.5in")))
337 (insert "\\vfill%\n")
338 (setq year (1+ year))
341 (cal-tex-end-document))
342 (run-hooks 'cal-tex-year-hook))
343 (run-hooks 'cal-tex-hook))
345 (defun cal-tex-cursor-filofax-year (&optional arg)
346 "Make a Filofax one page yearly calendar of year indicated by cursor.
347 Optional parameter specifies number of years."
349 (let* ((n (if arg arg 1))
350 (year (extract-calendar-year (calendar-cursor-to-date t))))
351 (cal-tex-preamble "twoside")
352 (cal-tex-cmd "\\textwidth 3.25in")
353 (cal-tex-cmd "\\textheight 6.5in")
354 (cal-tex-cmd "\\oddsidemargin 1.675in")
355 (cal-tex-cmd "\\evensidemargin 1.675in")
356 (cal-tex-cmd "\\topmargin 0pt")
357 (cal-tex-cmd "\\headheight -0.875in")
358 (cal-tex-cmd "\\fboxsep 0.5mm")
359 (cal-tex-cmd "\\pagestyle{empty}")
361 (cal-tex-cmd "\\vspace*{0.25in}")
362 (calendar-for-loop j from 1 to n do
363 (insert (format "\\hfil {\\Large \\bf %s} \\hfil\\\\\n" year))
365 (cal-tex-b-parbox "l" "\\textwidth")
369 (let ((month-names; don't use default in case user changed it
370 ;; These are only used to define the command names, not
371 ;; the names of the months they insert.
372 ["January" "February" "March" "April" "May" "June"
373 "July" "August" "September" "October" "November" "December"]))
374 (calendar-for-loop i from 1 to 12 do
375 (insert (cal-tex-mini-calendar i year
376 (aref month-names (1- i))
377 "1in" ".9in" "tiny" "0.6mm"))))
379 "\\noindent\\fbox{\\January}\\fbox{\\February}\\fbox{\\March}\\\\
380 \\noindent\\fbox{\\April}\\fbox{\\May}\\fbox{\\June}\\\\
381 \\noindent\\fbox{\\July}\\fbox{\\August}\\fbox{\\September}\\\\
382 \\noindent\\fbox{\\October}\\fbox{\\November}\\fbox{\\December}
386 (setq year (1+ year))
388 (cal-tex-end-document)
390 (cal-tex-cmd "\\vspace*{0.25in}"))
391 (run-hooks 'cal-tex-year-hook))
392 (run-hooks 'cal-tex-hook)))
395 ;;; Monthly calendars
398 (defun cal-tex-cursor-month-landscape (&optional arg)
399 "Make a buffer with LaTeX commands for the month cursor is on.
400 Optional prefix argument specifies number of months to be produced.
401 The output is in landscape format, one month to a page."
403 (let* ((n (if arg arg 1))
404 (date (calendar-cursor-to-date t))
405 (month (extract-calendar-month date))
406 (year (extract-calendar-year date))
409 (cal-tex-which-days '(0 1 2 3 4 5 6)))
410 (increment-calendar-month end-month end-year (1- n))
411 (let ((diary-list (if cal-tex-diary
412 (cal-tex-list-diary-entries
413 (calendar-absolute-from-gregorian
415 (calendar-absolute-from-gregorian
417 (calendar-last-day-of-month
420 (holidays (if cal-tex-holidays
421 (cal-tex-list-holidays
422 (calendar-absolute-from-gregorian
424 (calendar-absolute-from-gregorian
426 (calendar-last-day-of-month end-month end-year)
430 (small-months-at-start))
431 (cal-tex-insert-preamble (cal-tex-number-weeks month year 1) t "12pt")
432 (cal-tex-cmd cal-tex-cal-one-month)
433 (calendar-for-loop i from 1 to n do
434 (setq other-month month)
435 (setq other-year year)
436 (increment-calendar-month other-month other-year -1)
437 (insert (cal-tex-mini-calendar other-month other-year "lastmonth"
438 "\\cellwidth" "\\cellheight"))
439 (increment-calendar-month other-month other-year 2)
440 (insert (cal-tex-mini-calendar other-month other-year "nextmonth"
441 "\\cellwidth" "\\cellheight"))
442 (cal-tex-insert-month-header 1 month year month year)
443 (cal-tex-insert-day-names)
445 (setq small-months-at-start
446 (< 1 (mod (- (calendar-day-of-week (list month 1 year))
447 calendar-week-start-day)
449 (if small-months-at-start
450 (insert "\\lastmonth\\nextmonth\\hspace*{-2\\cellwidth}"))
451 (cal-tex-insert-blank-days month year cal-tex-day-prefix)
452 (cal-tex-insert-days month year diary-list holidays
454 (cal-tex-insert-blank-days-at-end month year cal-tex-day-prefix)
455 (if (and (not small-months-at-start)
456 (< 1 (mod (- (1- calendar-week-start-day)
457 (calendar-day-of-week
459 (calendar-last-day-of-month month year)
462 (insert "\\vspace*{-\\cellwidth}\\hspace*{-2\\cellwidth}"
463 "\\lastmonth\\nextmonth%
467 (run-hooks 'cal-tex-month-hook)
469 (increment-calendar-month month year 1)
470 (cal-tex-vspace "-2cm")
471 (cal-tex-insert-preamble
472 (cal-tex-number-weeks month year 1) t "12pt" t))))
473 (cal-tex-end-document)
474 (run-hooks 'cal-tex-hook))))
476 (defun cal-tex-cursor-month (arg)
477 "Make a buffer with LaTeX commands for the month cursor is on.
478 Optional prefix argument specifies number of months to be produced.
479 Calendar is condensed onto one page."
481 (let* ((date (calendar-cursor-to-date t))
482 (month (extract-calendar-month date))
483 (year (extract-calendar-year date))
487 (increment-calendar-month end-month end-year (1- n))
488 (let ((diary-list (if cal-tex-diary
489 (cal-tex-list-diary-entries
490 (calendar-absolute-from-gregorian
492 (calendar-absolute-from-gregorian
494 (calendar-last-day-of-month
497 (holidays (if cal-tex-holidays
498 (cal-tex-list-holidays
499 (calendar-absolute-from-gregorian
501 (calendar-absolute-from-gregorian
503 (calendar-last-day-of-month end-month end-year)
507 (cal-tex-insert-preamble (cal-tex-number-weeks month year n) nil"12pt")
509 (cal-tex-cmd cal-tex-cal-multi-month)
510 (cal-tex-cmd cal-tex-cal-one-month))
511 (cal-tex-insert-month-header n month year end-month end-year)
512 (cal-tex-insert-day-names)
514 (cal-tex-insert-blank-days month year cal-tex-day-prefix)
515 (calendar-for-loop i from 1 to n do
516 (setq other-month month)
517 (setq other-year year)
518 (cal-tex-insert-days month year diary-list holidays
520 (if (= (mod (calendar-absolute-from-gregorian
522 (calendar-last-day-of-month month year)
525 6); last day of month was Saturday
529 (increment-calendar-month month year 1))
530 (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix)
531 (cal-tex-end-document)))
532 (run-hooks 'cal-tex-hook))
534 (defun cal-tex-insert-days (month year diary-list holidays day-format)
535 "Insert LaTeX commands for a range of days in monthly calendars.
536 LaTeX commands are inserted for the days of the MONTH in YEAR.
537 Diary entries on DIARY-LIST are included. Holidays on HOLIDAYS are included.
538 Each day is formatted using format DAY-FORMAT."
539 (let* ((blank-days;; at start of month
541 (- (calendar-day-of-week (list month 1 year))
542 calendar-week-start-day)
545 (last (calendar-last-day-of-month month year)))
546 (calendar-for-loop i from 1 to last do
547 (setq date (list month i year))
548 (if (memq (calendar-day-of-week date) cal-tex-which-days)
550 (insert (format day-format (cal-tex-month-name month) i))
551 (cal-tex-arg (cal-tex-latexify-list diary-list date))
552 (cal-tex-arg (cal-tex-latexify-list holidays date))
553 (cal-tex-arg (eval cal-tex-daily-string))
556 (if (and (zerop (mod (+ i blank-days) 7))
562 (defun cal-tex-insert-day-names ()
563 "Insert the names of the days at top of a monthly calendar."
564 (calendar-for-loop i from 0 to 6 do
565 (if (memq i cal-tex-which-days)
566 (insert (format cal-tex-day-name-format
567 (cal-tex-LaTeXify-string
568 (aref calendar-day-name-array
569 (mod (+ calendar-week-start-day i) 7))))))
572 (defun cal-tex-insert-month-header (n month year end-month end-year)
573 "Create a title for a calendar.
574 A title is inserted for a calendar with N months starting with
575 MONTH YEAR and ending with END-MONTH END-YEAR."
576 (let ((month-name (cal-tex-month-name month))
577 (end-month-name (cal-tex-month-name end-month)))
579 (insert (format "\\calmonth{%s}{%s}\n\\vspace*{-0.5cm}"
581 (insert (format "\\calmonth{%s}{%s}{%s}{%s}\n\\vspace*{-0.5cm}"
582 month-name year end-month-name end-year))))
585 (defun cal-tex-insert-blank-days (month year day-format)
586 "Insert code for initial days not in calendar.
587 Insert LaTeX code for the blank days at the beginning of the MONTH in
588 YEAR. The entry is formatted using DAY-FORMAT. If the entire week is
589 blank, no days are inserted."
590 (if (cal-tex-first-blank-p month year)
591 (let* ((blank-days;; at start of month
593 (- (calendar-day-of-week (list month 1 year))
594 calendar-week-start-day)
596 (calendar-for-loop i from 0 to (1- blank-days) do
597 (if (memq i cal-tex-which-days)
598 (insert (format day-format " " " ") "{}{}{}{}%\n"))))))
600 (defun cal-tex-insert-blank-days-at-end (month year day-format)
601 "Insert code for final days not in calendar.
602 Insert LaTeX code for the blank days at the end of the MONTH in YEAR.
603 The entry is formatted using DAY-FORMAT."
604 (if (cal-tex-last-blank-p month year)
605 (let* ((last-day (calendar-last-day-of-month month year))
606 (blank-days;; at end of month
608 (- (calendar-day-of-week (list month last-day year))
609 calendar-week-start-day)
611 (calendar-for-loop i from (1+ blank-days) to 6 do
612 (if (memq i cal-tex-which-days)
613 (insert (format day-format "" "") "{}{}{}{}%\n"))))))
615 (defun cal-tex-first-blank-p (month year)
616 "Determine if any days of the first week will be printed.
617 Return t if there will there be any days of the first week printed
618 in the calendar starting in MONTH YEAR."
620 (the-saturday)) ;the day of week of 1st Saturday
621 (calendar-for-loop i from 1 to 7 do
622 (if (= 6 (calendar-day-of-week (list month i year)))
623 (setq the-saturday i)))
624 (calendar-for-loop i from 1 to the-saturday do
625 (if (memq (calendar-day-of-week (list month i year))
630 (defun cal-tex-last-blank-p (month year)
631 "Determine if any days of the last week will be printed.
632 Return t if there will there be any days of the last week printed
633 in the calendar starting in MONTH YEAR."
635 (last-day (calendar-last-day-of-month month year))
636 (the-sunday)) ;the day of week of last Sunday
637 (calendar-for-loop i from (- last-day 6) to last-day do
638 (if (= 0 (calendar-day-of-week (list month i year)))
639 (setq the-sunday i)))
640 (calendar-for-loop i from the-sunday to last-day do
641 (if (memq (calendar-day-of-week (list month i year))
646 (defun cal-tex-number-weeks (month year n)
647 "Determine the number of weeks in a range of dates.
648 Compute the number of weeks in the calendar starting with MONTH and YEAR,
649 and lasting N months, including only the days in WHICH-DAYS. As it stands,
650 this is only an upper bound."
651 (let ((d (list month 1 year)))
652 (increment-calendar-month month year (1- n))
653 (/ (- (calendar-dayname-on-or-before
654 calendar-week-start-day
655 (+ 7 (calendar-absolute-from-gregorian
656 (list month (calendar-last-day-of-month month year) year))))
657 (calendar-dayname-on-or-before
658 calendar-week-start-day
659 (calendar-absolute-from-gregorian d)))
666 (defvar cal-tex-LaTeX-hourbox
667 "\\newcommand{\\hourbox}[2]%
668 {\\makebox[2em]{\\rule{0cm}{#2ex}#1}\\rule{3in}{.15mm}}\n"
669 "One hour and a line on the right.")
671 (defun cal-tex-cursor-week (&optional arg)
672 "Make a buffer with LaTeX commands for a two-page one-week calendar.
673 It applies to the week that point is in.
674 Optional prefix argument specifies number of weeks.
675 Holidays are included if `cal-tex-holidays' is t."
677 (let* ((n (if arg arg 1))
678 (date (calendar-gregorian-from-absolute
679 (calendar-dayname-on-or-before
680 calendar-week-start-day
681 (calendar-absolute-from-gregorian
682 (calendar-cursor-to-date t)))))
683 (month (extract-calendar-month date))
684 (year (extract-calendar-year date))
685 (holidays (if cal-tex-holidays
686 (cal-tex-list-holidays
687 (calendar-absolute-from-gregorian date)
689 (calendar-absolute-from-gregorian date))))))
690 (cal-tex-preamble "11pt")
691 (cal-tex-cmd "\\textwidth 6.5in")
692 (cal-tex-cmd "\\textheight 10.5in")
693 (cal-tex-cmd "\\oddsidemargin 0in")
694 (cal-tex-cmd "\\evensidemargin 0in")
695 (insert cal-tex-LaTeX-hourbox)
697 (cal-tex-cmd "\\pagestyle{empty}")
698 (calendar-for-loop i from 1 to n do
699 (cal-tex-vspace "-1.5in")
701 (cal-tex-Huge-bf (format "\\uppercase{%s}"
702 (cal-tex-month-name month)))
703 (cal-tex-hspace "2em")
704 (cal-tex-Huge-bf (number-to-string year))
707 (cal-tex-hspace "-.2in")
708 (cal-tex-b-parbox "l" "7in")
709 (calendar-for-loop j from 1 to 7 do
710 (cal-tex-week-hours date holidays "3.1")
711 (setq date (cal-tex-incr-date date)))
713 (setq month (extract-calendar-month date))
714 (setq year (extract-calendar-year date))
717 (run-hooks 'cal-tex-week-hook)
719 (cal-tex-end-document)
720 (run-hooks 'cal-tex-hook)))
722 (defun cal-tex-cursor-week2 (&optional arg)
723 "Make a buffer with LaTeX commands for a two-page one-week calendar.
724 It applies to the week that point is in.
725 Optional prefix argument specifies number of weeks.
726 Holidays are included if `cal-tex-holidays' is t."
728 (let* ((n (if arg arg 1))
729 (date (calendar-gregorian-from-absolute
730 (calendar-dayname-on-or-before
731 calendar-week-start-day
732 (calendar-absolute-from-gregorian
733 (calendar-cursor-to-date t)))))
734 (month (extract-calendar-month date))
735 (year (extract-calendar-year date))
737 (holidays (if cal-tex-holidays
738 (cal-tex-list-holidays
739 (calendar-absolute-from-gregorian date)
741 (calendar-absolute-from-gregorian date))))))
742 (cal-tex-preamble "12pt")
743 (cal-tex-cmd "\\textwidth 6.5in")
744 (cal-tex-cmd "\\textheight 10.5in")
745 (cal-tex-cmd "\\oddsidemargin 0in")
746 (cal-tex-cmd "\\evensidemargin 0in")
747 (insert cal-tex-LaTeX-hourbox)
749 (cal-tex-cmd "\\pagestyle{empty}")
750 (calendar-for-loop i from 1 to n do
751 (cal-tex-vspace "-1.5in")
753 (cal-tex-Huge-bf (format "\\uppercase{%s}"
754 (cal-tex-month-name month)))
755 (cal-tex-hspace "2em")
756 (cal-tex-Huge-bf (number-to-string year))
759 (cal-tex-hspace "-.2in")
760 (cal-tex-b-parbox "l" "\\textwidth")
761 (calendar-for-loop j from 1 to 3 do
762 (cal-tex-week-hours date holidays "5")
763 (setq date (cal-tex-incr-date date)))
766 (insert (cal-tex-mini-calendar
767 (extract-calendar-month (cal-tex-previous-month date))
768 (extract-calendar-year (cal-tex-previous-month date))
769 "lastmonth" "1.1in" "1in"))
770 (insert (cal-tex-mini-calendar
771 (extract-calendar-month date)
772 (extract-calendar-year date)
773 "thismonth" "1.1in" "1in"))
774 (insert (cal-tex-mini-calendar
775 (extract-calendar-month (cal-tex-next-month date))
776 (extract-calendar-year (cal-tex-next-month date))
777 "nextmonth" "1.1in" "1in"))
778 (insert "\\hbox to \\textwidth{")
780 (insert "\\lastmonth")
782 (insert "\\thismonth")
784 (insert "\\nextmonth")
788 (cal-tex-b-parbox "l" "\\textwidth")
789 (calendar-for-loop j from 4 to 7 do
790 (cal-tex-week-hours date holidays "5")
791 (setq date (cal-tex-incr-date date)))
793 (setq month (extract-calendar-month date))
794 (setq year (extract-calendar-year date))
797 (run-hooks 'cal-tex-week-hook)
799 (cal-tex-end-document)
800 (run-hooks 'cal-tex-hook)))
802 (defun cal-tex-cursor-week-iso (&optional arg)
803 "Make a buffer with LaTeX commands for a one page ISO-style weekly calendar.
804 Optional prefix argument specifies number of weeks.
805 Diary entries are included if `cal-tex-diary' is t.
806 Holidays are included if `cal-tex-holidays' is t."
808 (let* ((n (if arg arg 1))
809 (date (calendar-gregorian-from-absolute
810 (calendar-dayname-on-or-before
812 (calendar-absolute-from-gregorian
813 (calendar-cursor-to-date t)))))
814 (month (extract-calendar-month date))
815 (year (extract-calendar-year date))
816 (day (extract-calendar-day date))
817 (holidays (if cal-tex-holidays
818 (cal-tex-list-holidays
819 (calendar-absolute-from-gregorian date)
821 (calendar-absolute-from-gregorian date)))))
822 (diary-list (if cal-tex-diary
823 (cal-tex-list-diary-entries
824 (calendar-absolute-from-gregorian
827 (calendar-absolute-from-gregorian date))))))
828 (cal-tex-preamble "11pt")
829 (cal-tex-cmd "\\textwidth 6.5in")
830 (cal-tex-cmd "\\textheight 10.5in")
831 (cal-tex-cmd "\\oddsidemargin 0in")
832 (cal-tex-cmd "\\evensidemargin 0in")
834 (cal-tex-cmd "\\pagestyle{empty}")
835 (calendar-for-loop i from 1 to n do
836 (cal-tex-vspace "-1.5in")
839 (let* ((d (calendar-iso-from-absolute
840 (calendar-absolute-from-gregorian date))))
841 (format "Week %d of %d"
842 (extract-calendar-month d)
843 (extract-calendar-year d))))
846 (cal-tex-b-parbox "l" "\\textwidth")
847 (calendar-for-loop j from 1 to 7 do
848 (cal-tex-b-parbox "t" "\\textwidth")
849 (cal-tex-b-parbox "t" "\\textwidth")
850 (cal-tex-rule "0pt" "\\textwidth" ".2mm")
852 (cal-tex-b-parbox "t" "\\textwidth")
853 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date)))
855 (cal-tex-large-bf (cal-tex-month-name month))
857 (cal-tex-large-bf (number-to-string day))
858 (if (not (string= "" (cal-tex-latexify-list holidays date)))
861 (cal-tex-large-bf (cal-tex-latexify-list holidays date "; "))))
863 (insert " " (eval cal-tex-daily-string))
867 (cal-tex-b-parbox "t" "\\textwidth")
868 (if (not (string= "" (cal-tex-latexify-list diary-list date)))
870 (insert "\\vbox to 0pt{")
872 (cal-tex-latexify-list diary-list date))
876 (setq date (cal-tex-incr-date date))
877 (setq month (extract-calendar-month date))
878 (setq day (extract-calendar-day date))
880 (cal-tex-e-parbox "2cm")
882 (setq month (extract-calendar-month date))
883 (setq year (extract-calendar-year date)))
887 (run-hooks 'cal-tex-week-hook)
889 (cal-tex-end-document)
890 (run-hooks 'cal-tex-hook)))
892 (defun cal-tex-week-hours (date holidays height)
893 "Insert hourly entries for DATE with HOLIDAYS, with line height HEIGHT."
894 (let ((month (extract-calendar-month date))
895 (day (extract-calendar-day date))
896 (year (extract-calendar-year date))
898 (cal-tex-comment "begin cal-tex-week-hours")
899 (cal-tex-cmd "\\ \\\\[-.2cm]")
900 (cal-tex-cmd "\\noindent")
901 (cal-tex-b-parbox "l" "6.8in")
902 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date)))
904 (cal-tex-large-bf (cal-tex-month-name month))
906 (cal-tex-large-bf (number-to-string day))
907 (if (not (string= "" (cal-tex-latexify-list holidays date)))
910 (cal-tex-large-bf (cal-tex-latexify-list holidays date "; "))))
912 (insert " " (eval cal-tex-daily-string))
915 (cal-tex-rule "0pt" "6.8in" ".2mm")
917 (calendar-for-loop i from 8 to 12 do
919 (setq afternoon (+ i 5))
920 (setq afternoon (- i 7)))
921 (cal-tex-cmd "\\hourbox" (number-to-string i))
923 (cal-tex-hspace ".4cm")
924 (cal-tex-cmd "\\hourbox" (number-to-string afternoon))
928 (defun cal-tex-cursor-week-monday (&optional arg)
929 "Make a buffer with LaTeX commands for a two-page one-week calendar.
930 It applies to the week that point is in, and starts on Monday.
931 Optional prefix argument specifies number of weeks.
932 Holidays are included if `cal-tex-holidays' is t."
934 (let* ((n (if arg arg 1))
935 (date (calendar-gregorian-from-absolute
936 (calendar-dayname-on-or-before
938 (calendar-absolute-from-gregorian
939 (calendar-cursor-to-date t))))))
940 (cal-tex-preamble "11pt")
941 (cal-tex-cmd "\\textwidth 6.5in")
942 (cal-tex-cmd "\\textheight 10.5in")
943 (cal-tex-cmd "\\oddsidemargin 0in")
944 (cal-tex-cmd "\\evensidemargin 0in")
946 (calendar-for-loop i from 1 to n do
947 (cal-tex-vspace "-1cm")
948 (insert "\\noindent ")
949 (cal-tex-weekly4-box (cal-tex-incr-date date) nil)
950 (cal-tex-weekly4-box (cal-tex-incr-date date 4) nil)
952 (cal-tex-weekly4-box (cal-tex-incr-date date 2) nil)
953 (cal-tex-weekly4-box (cal-tex-incr-date date 5) nil)
955 (cal-tex-weekly4-box (cal-tex-incr-date date 3) nil)
956 (cal-tex-weekly4-box (cal-tex-incr-date date 6) t)
959 (run-hooks 'cal-tex-week-hook)
960 (setq date (cal-tex-incr-date date 7))
962 (cal-tex-end-document)
963 (run-hooks 'cal-tex-hook)))
965 (defun cal-tex-weekly4-box (date weekend)
966 "Make one box for DATE, different if WEEKEND."
968 (day (extract-calendar-day date))
969 (month (extract-calendar-month date))
970 (year (extract-calendar-year date))
971 (dayname (cal-tex-LaTeXify-string (calendar-day-name date)))
972 (date1 (cal-tex-incr-date date))
973 (day1 (extract-calendar-day date1))
974 (month1 (extract-calendar-month date1))
975 (year1 (extract-calendar-year date1))
976 (dayname1 (cal-tex-LaTeXify-string (calendar-day-name date1)))
978 (cal-tex-b-framebox "8cm" "l")
979 (cal-tex-b-parbox "b" "7.5cm")
980 (insert (format "{\\Large\\bf %s,} %s/%s/%s\\\\\n" dayname month day year))
981 (cal-tex-rule "0pt" "7.5cm" ".5mm")
985 (calendar-for-loop i from 8 to 12 do
986 (insert (format "{\\large\\sf %d}\\\\\n" i)))
987 (calendar-for-loop i from 1 to 5 do
988 (insert (format "{\\large\\sf %d}\\\\\n"
989 (if cal-tex-24 (+ i 12) i))))))
993 (cal-tex-vspace "1cm")
994 (insert "\\ \\vfill")
995 (insert (format "{\\Large\\bf %s,} %s/%s/%s\\\\\n"
996 dayname1 month1 day1 year1))
997 (cal-tex-rule "0pt" "7.5cm" ".5mm")
999 (cal-tex-vspace "1cm")))
1001 (cal-tex-e-framebox)
1002 (cal-tex-hspace "1cm")))
1004 (defun cal-tex-cursor-filofax-2week (&optional arg)
1005 "Two-weeks-at-a-glance Filofax style calendar for week indicated by cursor.
1006 Optional prefix argument specifies number of weeks.
1007 Diary entries are included if `cal-tex-diary' is t.
1008 Holidays are included if `cal-tex-holidays' is t."
1010 (let* ((n (if arg arg 1))
1011 (date (calendar-gregorian-from-absolute
1012 (calendar-dayname-on-or-before
1013 calendar-week-start-day
1014 (calendar-absolute-from-gregorian
1015 (calendar-cursor-to-date t)))))
1016 (month (extract-calendar-month date))
1017 (year (extract-calendar-year date))
1018 (day (extract-calendar-day date))
1019 (holidays (if cal-tex-holidays
1020 (cal-tex-list-holidays
1021 (calendar-absolute-from-gregorian date)
1023 (calendar-absolute-from-gregorian date)))))
1024 (diary-list (if cal-tex-diary
1025 (cal-tex-list-diary-entries
1026 (calendar-absolute-from-gregorian
1027 (list month 1 year))
1029 (calendar-absolute-from-gregorian date))))))
1030 (cal-tex-preamble "twoside")
1031 (cal-tex-cmd "\\textwidth 3.25in")
1032 (cal-tex-cmd "\\textheight 6.5in")
1033 (cal-tex-cmd "\\oddsidemargin 1.75in")
1034 (cal-tex-cmd "\\evensidemargin 1.5in")
1035 (cal-tex-cmd "\\topmargin 0pt")
1036 (cal-tex-cmd "\\headheight -0.875in")
1037 (cal-tex-cmd "\\headsep 0.125in")
1038 (cal-tex-cmd "\\footskip .125in")
1039 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1040 \\long\\def\\rightday#1#2#3#4#5{%
1041 \\rule{\\textwidth}{0.3pt}\\\\%
1042 \\hbox to \\textwidth{%
1045 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1046 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1047 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1048 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1049 \\long\\def\\leftday#1#2#3#4#5{%
1050 \\rule{\\textwidth}{0.3pt}\\\\%
1051 \\hbox to \\textwidth{%
1054 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1055 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1056 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1058 (cal-tex-b-document)
1059 (cal-tex-cmd "\\pagestyle{empty}")
1060 (calendar-for-loop i from 1 to n do
1062 (insert "\\righthead")
1063 (insert "\\lefthead"))
1065 (let ((d (cal-tex-incr-date date 6)))
1066 (if (= (extract-calendar-month date)
1067 (extract-calendar-month d))
1070 (extract-calendar-month date))
1071 (extract-calendar-year date))
1072 (if (= (extract-calendar-year date)
1073 (extract-calendar-year d))
1074 (format "%s---%s %s"
1076 (extract-calendar-month date))
1078 (extract-calendar-month d))
1079 (extract-calendar-year date))
1080 (format "%s %s---%s %s"
1082 (extract-calendar-month date))
1083 (extract-calendar-year date)
1084 (cal-tex-month-name (extract-calendar-month d))
1085 (extract-calendar-year d))))))
1087 (calendar-for-loop j from 1 to 7 do
1089 (insert "\\rightday")
1090 (insert "\\leftday"))
1091 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1092 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1093 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1094 (cal-tex-arg (cal-tex-latexify-list holidays date))
1095 (cal-tex-arg (eval cal-tex-daily-string))
1097 (setq date (cal-tex-incr-date date)))
1100 (run-hooks 'cal-tex-week-hook)
1101 (cal-tex-newpage))))
1102 (cal-tex-end-document)
1103 (run-hooks 'cal-tex-hook)))
1105 (defun cal-tex-cursor-filofax-week (&optional arg)
1106 "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
1107 Optional prefix argument specifies number of weeks.
1108 Weeks start on Monday.
1109 Diary entries are included if `cal-tex-diary' is t.
1110 Holidays are included if `cal-tex-holidays' is t."
1112 (let* ((n (if arg arg 1))
1113 (date (calendar-gregorian-from-absolute
1114 (calendar-dayname-on-or-before
1116 (calendar-absolute-from-gregorian
1117 (calendar-cursor-to-date t)))))
1118 (month (extract-calendar-month date))
1119 (year (extract-calendar-year date))
1120 (day (extract-calendar-day date))
1121 (holidays (if cal-tex-holidays
1122 (cal-tex-list-holidays
1123 (calendar-absolute-from-gregorian date)
1125 (calendar-absolute-from-gregorian date)))))
1126 (diary-list (if cal-tex-diary
1127 (cal-tex-list-diary-entries
1128 (calendar-absolute-from-gregorian
1129 (list month 1 year))
1131 (calendar-absolute-from-gregorian date))))))
1132 (cal-tex-preamble "twoside")
1133 (cal-tex-cmd "\\textwidth 3.25in")
1134 (cal-tex-cmd "\\textheight 6.5in")
1135 (cal-tex-cmd "\\oddsidemargin 1.75in")
1136 (cal-tex-cmd "\\evensidemargin 1.5in")
1137 (cal-tex-cmd "\\topmargin 0pt")
1138 (cal-tex-cmd "\\headheight -0.875in")
1139 (cal-tex-cmd "\\headsep 0.125in")
1140 (cal-tex-cmd "\\footskip .125in")
1141 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1142 \\long\\def\\rightday#1#2#3#4#5{%
1143 \\rule{\\textwidth}{0.3pt}\\\\%
1144 \\hbox to \\textwidth{%
1147 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1148 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1149 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1150 \\long\\def\\weekend#1#2#3#4#5{%
1151 \\rule{\\textwidth}{0.3pt}\\\\%
1152 \\hbox to \\textwidth{%
1155 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1156 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1157 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1158 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1159 \\long\\def\\leftday#1#2#3#4#5{%
1160 \\rule{\\textwidth}{0.3pt}\\\\%
1161 \\hbox to \\textwidth{%
1164 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1165 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1166 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1168 (cal-tex-b-document)
1169 (cal-tex-cmd "\\pagestyle{empty}\\ ")
1171 (calendar-for-loop i from 1 to n do
1172 (insert "\\lefthead")
1174 (let ((d (cal-tex-incr-date date 2)))
1175 (if (= (extract-calendar-month date)
1176 (extract-calendar-month d))
1179 (extract-calendar-month date))
1180 (extract-calendar-year date))
1181 (if (= (extract-calendar-year date)
1182 (extract-calendar-year d))
1183 (format "%s---%s %s"
1185 (extract-calendar-month date))
1187 (extract-calendar-month d))
1188 (extract-calendar-year date))
1189 (format "%s %s---%s %s"
1191 (extract-calendar-month date))
1192 (extract-calendar-year date)
1193 (cal-tex-month-name (extract-calendar-month d))
1194 (extract-calendar-year d))))))
1196 (calendar-for-loop j from 1 to 3 do
1197 (insert "\\leftday")
1198 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1199 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1200 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1201 (cal-tex-arg (cal-tex-latexify-list holidays date))
1202 (cal-tex-arg (eval cal-tex-daily-string))
1204 (setq date (cal-tex-incr-date date)))
1205 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1207 (insert "\\righthead")
1209 (let ((d (cal-tex-incr-date date 3)))
1210 (if (= (extract-calendar-month date)
1211 (extract-calendar-month d))
1214 (extract-calendar-month date))
1215 (extract-calendar-year date))
1216 (if (= (extract-calendar-year date)
1217 (extract-calendar-year d))
1218 (format "%s---%s %s"
1220 (extract-calendar-month date))
1222 (extract-calendar-month d))
1223 (extract-calendar-year date))
1224 (format "%s %s---%s %s"
1226 (extract-calendar-month date))
1227 (extract-calendar-year date)
1228 (cal-tex-month-name (extract-calendar-month d))
1229 (extract-calendar-year d))))))
1231 (calendar-for-loop j from 1 to 2 do
1232 (insert "\\rightday")
1233 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1234 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1235 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1236 (cal-tex-arg (cal-tex-latexify-list holidays date))
1237 (cal-tex-arg (eval cal-tex-daily-string))
1239 (setq date (cal-tex-incr-date date)))
1240 (calendar-for-loop j from 1 to 2 do
1241 (insert "\\weekend")
1242 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1243 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1244 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1245 (cal-tex-arg (cal-tex-latexify-list holidays date))
1246 (cal-tex-arg (eval cal-tex-daily-string))
1248 (setq date (cal-tex-incr-date date)))
1251 (run-hooks 'cal-tex-week-hook)
1252 (cal-tex-newpage))))
1253 (cal-tex-end-document)
1254 (run-hooks 'cal-tex-hook)))
1256 (defun cal-tex-cursor-filofax-daily (&optional arg)
1257 "Day-per-page Filofax style calendar for week indicated by cursor.
1258 Optional prefix argument specifies number of weeks. Weeks start on Monday.
1259 Diary entries are included if `cal-tex-diary' is t.
1260 Holidays are included if `cal-tex-holidays' is t.
1261 Pages are ruled if `cal-tex-rules' is t."
1263 (let* ((n (if arg arg 1))
1264 (date (calendar-gregorian-from-absolute
1265 (calendar-dayname-on-or-before
1267 (calendar-absolute-from-gregorian
1268 (calendar-cursor-to-date t)))))
1269 (month (extract-calendar-month date))
1270 (year (extract-calendar-year date))
1271 (day (extract-calendar-day date))
1272 (holidays (if cal-tex-holidays
1273 (cal-tex-list-holidays
1274 (calendar-absolute-from-gregorian date)
1276 (calendar-absolute-from-gregorian date)))))
1277 (diary-list (if cal-tex-diary
1278 (cal-tex-list-diary-entries
1279 (calendar-absolute-from-gregorian
1280 (list month 1 year))
1282 (calendar-absolute-from-gregorian date))))))
1283 (cal-tex-preamble "twoside")
1284 (cal-tex-cmd "\\textwidth 3.25in")
1285 (cal-tex-cmd "\\textheight 6.5in")
1286 (cal-tex-cmd "\\oddsidemargin 1.75in")
1287 (cal-tex-cmd "\\evensidemargin 1.5in")
1288 (cal-tex-cmd "\\topmargin 0pt")
1289 (cal-tex-cmd "\\headheight -0.875in")
1290 (cal-tex-cmd "\\headsep 0.125in")
1291 (cal-tex-cmd "\\footskip .125in")
1292 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1293 \\long\\def\\rightday#1#2#3{%
1294 \\rule{\\textwidth}{0.3pt}\\\\%
1295 \\hbox to \\textwidth{%
1298 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1299 \\hbox to \\textwidth{\\vbox {\\raggedleft \\em #2}}%
1300 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1301 \\long\\def\\weekend#1#2#3{%
1302 \\rule{\\textwidth}{0.3pt}\\\\%
1303 \\hbox to \\textwidth{%
1306 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1307 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1308 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1309 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1310 \\long\\def\\leftday#1#2#3{%
1311 \\rule{\\textwidth}{0.3pt}\\\\%
1312 \\hbox to \\textwidth{%
1315 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1316 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1317 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1319 \\setbox\\LineBox=\\hbox to\\textwidth{%
1320 \\vrule height.2in width0pt\\leaders\\hrule\\hfill}
1321 \\def\\linesfill{\\par\\leaders\\copy\\LineBox\\vfill}
1323 (cal-tex-b-document)
1324 (cal-tex-cmd "\\pagestyle{empty}")
1325 (calendar-for-loop i from 1 to n do
1326 (calendar-for-loop j from 1 to 5 do
1327 (let ((odd (/= 0 (% j 2))))
1328 (insert (if odd "\\righthead" "\\lefthead"))
1329 (cal-tex-arg (calendar-date-string date))
1331 (insert (if odd "\\rightday" "\\leftday")))
1332 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1333 (cal-tex-arg (cal-tex-latexify-list holidays date "\\\\" t))
1334 (cal-tex-arg (eval cal-tex-daily-string))
1337 (insert "\\linesfill\n")
1338 (insert "\\vfill\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1340 (setq date (cal-tex-incr-date date)))
1342 (calendar-for-loop j from 1 to 2 do
1343 (insert "\\lefthead")
1344 (cal-tex-arg (calendar-date-string date))
1345 (insert "\\weekend")
1346 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1347 (cal-tex-arg (cal-tex-latexify-list holidays date "\\\\" t))
1348 (cal-tex-arg (eval cal-tex-daily-string))
1351 (insert "\\linesfill\n")
1353 (setq date (cal-tex-incr-date date)))
1354 (if (not cal-tex-rules)
1355 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1358 (run-hooks 'cal-tex-week-hook)
1359 (cal-tex-newpage))))
1360 (cal-tex-end-document)
1361 (run-hooks 'cal-tex-hook)))
1368 (defun cal-tex-cursor-day (&optional arg)
1369 "Make a buffer with LaTeX commands for the day cursor is on.
1370 Optional prefix argument specifies number of days."
1372 (let ((n (if arg arg 1))
1373 (date (calendar-absolute-from-gregorian (calendar-cursor-to-date t))))
1374 (cal-tex-preamble "12pt")
1375 (cal-tex-cmd "\\textwidth 6.5in")
1376 (cal-tex-cmd "\\textheight 10.5in")
1377 (cal-tex-b-document)
1378 (cal-tex-cmd "\\pagestyle{empty}")
1379 (calendar-for-loop i from 1 to n do
1380 (cal-tex-vspace "-1.7in")
1381 (cal-tex-daily-page (calendar-gregorian-from-absolute date))
1382 (setq date (1+ date))
1386 (run-hooks 'cal-tex-daily-hook))))
1387 (cal-tex-end-document)
1388 (run-hooks 'cal-tex-hook)))
1390 (defun cal-tex-daily-page (date)
1391 "Make a calendar page for Gregorian DATE on 8.5 by 11 paper."
1393 (month-name (cal-tex-month-name (extract-calendar-month date))))
1394 (cal-tex-banner "cal-tex-daily-page")
1395 (cal-tex-b-makebox "4cm" "l")
1396 (cal-tex-b-parbox "b" "3.8cm")
1397 (cal-tex-rule "0mm" "0mm" "2cm")
1398 (cal-tex-Huge (number-to-string (extract-calendar-day date)))
1400 (cal-tex-bf month-name )
1402 (cal-tex-hspace "1cm")
1403 (cal-tex-scriptsize (eval cal-tex-daily-string))
1404 (cal-tex-hspace "3.5cm")
1407 (cal-tex-b-makebox "4cm" "r")
1408 (cal-tex-bf (cal-tex-LaTeXify-string (calendar-day-name date)))
1411 (cal-tex-hspace ".4cm")
1412 (cal-tex-rule "0mm" "16.1cm" "1mm")
1414 (calendar-for-loop i from cal-tex-daily-start to cal-tex-daily-end do
1415 (cal-tex-cmd "\\noindent")
1416 (setq hour (if cal-tex-24
1419 (if (= 0 hour) (setq hour 12))
1420 (cal-tex-b-makebox "1cm" "c")
1421 (cal-tex-arg (number-to-string hour))
1423 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1425 (cal-tex-b-makebox "1cm" "c")
1426 (cal-tex-arg "$\\diamond$" )
1428 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1429 (cal-tex-nl ".2cm"))
1431 (insert (cal-tex-mini-calendar
1432 (extract-calendar-month (cal-tex-previous-month date))
1433 (extract-calendar-year (cal-tex-previous-month date))
1434 "lastmonth" "1.1in" "1in"))
1435 (insert (cal-tex-mini-calendar
1436 (extract-calendar-month date)
1437 (extract-calendar-year date)
1438 "thismonth" "1.1in" "1in"))
1439 (insert (cal-tex-mini-calendar
1440 (extract-calendar-month (cal-tex-next-month date))
1441 (extract-calendar-year (cal-tex-next-month date))
1442 "nextmonth" "1.1in" "1in"))
1443 (insert "\\hbox to \\textwidth{")
1445 (insert "\\lastmonth")
1447 (insert "\\thismonth")
1449 (insert "\\nextmonth")
1452 (cal-tex-banner "end of cal-tex-daily-page")))
1458 (defun cal-tex-mini-calendar (month year name width height &optional ptsize colsep)
1459 "Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT.
1460 Optional PTSIZE gives the point ptsize; scriptsize is the default. Optional
1461 COLSEP gives the column separation; 1mm is the default."
1462 (let* ((blank-days;; at start of month
1464 (- (calendar-day-of-week (list month 1 year))
1465 calendar-week-start-day)
1467 (last (calendar-last-day-of-month month year))
1468 (colsep (if colsep colsep "1mm"))
1469 (str (concat "\\def\\" name "{\\hbox to" width "{%\n"
1470 "\\vbox to" height "{%\n"
1471 "\\vfil \\hbox to" width "{%\n"
1473 (if ptsize ptsize "scriptsize")
1475 "{@{\\hspace{0mm}}r@{\\hspace{" colsep
1476 "}}r@{\\hspace{" colsep "}}r@{\\hspace{" colsep
1477 "}}r@{\\hspace{" colsep "}}r@{\\hspace{" colsep
1478 "}}r@{\\hspace{" colsep "}}r@{\\hspace{0mm}}}%\n"
1479 "\\multicolumn{7}{c}{"
1480 (cal-tex-month-name month)
1482 (int-to-string year)
1484 (calendar-for-loop i from 0 to 6 do
1487 (cal-tex-LaTeXify-string
1488 (substring (aref calendar-day-name-array
1489 (mod (+ calendar-week-start-day i) 7))
1494 (calendar-for-loop i from 1 to blank-days do
1495 (setq str (concat str " & ")))
1496 (calendar-for-loop i from 1 to last do
1497 (setq str (concat str (int-to-string i)))
1498 (setq str (concat str (if (zerop (mod (+ i blank-days) 7))
1499 (if (/= i last) "\\\\[0.5mm]\n" "")
1501 (setq str (concat str "\n\\end{tabular}\\hfil}\\vfil}}}%\n"))
1505 ;;; Various calendar functions
1508 (defun cal-tex-incr-date (date &optional n)
1509 "The date of the day following DATE.
1510 If optional N is given, the date of N days after DATE."
1511 (calendar-gregorian-from-absolute
1512 (+ (if n n 1) (calendar-absolute-from-gregorian date))))
1514 (defun cal-tex-latexify-list (date-list date &optional separator final-separator)
1515 "Return string with concatenated, LaTeXified entries in DATE-LIST for DATE.
1516 Use double backslash as a separator unless optional SEPARATOR is given.
1517 If resulting string is not empty, put separator at end if optional
1518 FINAL-SEPARATOR is t."
1519 (let* ((sep (if separator separator "\\\\"))
1521 (mapconcat '(lambda (x) (cal-tex-LaTeXify-string x))
1526 (calendar-date-equal date (car (car p)))
1527 (setq result (cons (car (cdr (car p))) result)))
1531 (if (and final-separator (not (string-equal result "")))
1535 (defun cal-tex-previous-month (date)
1536 "Return the date of the first day in the month previous to DATE."
1537 (let* ((month (extract-calendar-month date))
1538 (year (extract-calendar-year date)))
1539 (increment-calendar-month month year -1)
1540 (list month 1 year)))
1542 (defun cal-tex-next-month (date)
1543 "Return the date of the first day in the month following DATE."
1544 (let* ((month (extract-calendar-month date))
1545 (year (extract-calendar-year date)))
1546 (increment-calendar-month month year 1)
1547 (list month 1 year)))
1553 (defun cal-tex-end-document ()
1554 "Finish the LaTeX document.
1555 Insert the trailer to LaTeX document, pop to LaTeX buffer, add
1556 informative header, and run HOOK."
1557 (cal-tex-e-document)
1559 (pop-to-buffer cal-tex-buffer)
1560 (goto-char (point-min))
1561 (cal-tex-comment " This buffer was produced by cal-tex.el.")
1562 (cal-tex-comment " To print a calendar, type")
1563 (cal-tex-comment " M-x tex-buffer RET")
1564 (cal-tex-comment " M-x tex-print RET")
1565 (goto-char (point-min)))
1567 (defun cal-tex-insert-preamble (weeks landscape size &optional append)
1568 "Initialize the output buffer.
1569 Select the output buffer, and insert the preamble for a calendar of
1570 WEEKS weeks. Insert code for landscape mode if LANDSCAPE is true.
1571 Use pointsize SIZE. Optional argument APPEND, if t, means add to end of
1572 without erasing current contents."
1573 (let ((width "18cm")
1578 (setq height "18cm")))
1581 (cal-tex-preamble size)
1584 (cal-tex-cmd "\\oddsidemargin -1.75cm")
1585 (cal-tex-cmd "\\def\\holidaymult{.06}"))
1586 (cal-tex-cmd "\\special{landscape}")
1587 (cal-tex-cmd "\\textwidth 9.5in")
1588 (cal-tex-cmd "\\textheight 7in")
1590 (cal-tex-cmd "\\def\\holidaymult{.08}"))
1591 (cal-tex-cmd cal-tex-caldate)
1592 (cal-tex-cmd cal-tex-myday)
1593 (cal-tex-b-document)
1594 (cal-tex-cmd "\\pagestyle{empty}")))
1595 (cal-tex-cmd "\\setlength{\\cellwidth}" width)
1596 (insert (format "\\setlength{\\cellwidth}{%f\\cellwidth}\n"
1597 (/ 1.1 (length cal-tex-which-days))))
1598 (cal-tex-cmd "\\setlength{\\cellheight}" height)
1599 (insert (format "\\setlength{\\cellheight}{%f\\cellheight}\n"
1601 (cal-tex-cmd "\\ \\par")
1602 (cal-tex-vspace "-3cm")))
1604 (defvar cal-tex-LaTeX-subst-list
1606 ("\"". "''");; Quote changes meaning when list is reversed.
1617 ("\n" . "\\ \\\\")) ;\\ needed for e.g \begin{center}\n AA\end{center}
1618 "List of symbols and their replacements.")
1620 (defun cal-tex-LaTeXify-string (string)
1621 "Protect special characters in STRING from LaTeX."
1626 (list cal-tex-LaTeX-subst-list))
1627 (while (not (string-equal tail ""))
1628 (let* ((ch (substring tail 0 1))
1629 (pair (assoc ch list)))
1630 (if (and pair (string-equal ch "\""))
1631 (setq list (reverse list)));; Quote changes meaning each time.
1632 (setq tail (substring tail 1))
1633 (setq head (concat head (if pair (cdr pair) ch)))))
1636 (defun cal-tex-month-name (month)
1637 "The name of MONTH, LaTeXified."
1638 (cal-tex-LaTeXify-string (calendar-month-name month)))
1640 (defun cal-tex-hfill () "Insert hfill." (insert "\\hfill"))
1642 (defun cal-tex-newpage () "Insert newpage." (insert "\\newpage%\n"))
1644 (defun cal-tex-noindent () "Insert noindent." (insert "\\noindent"))
1646 (defun cal-tex-vspace (space)
1647 "Insert vspace command to move SPACE vertically."
1648 (insert "\\vspace*{" space "}")
1651 (defun cal-tex-hspace (space)
1652 "Insert hspace command to move SPACE horizontally."
1653 (insert "\\hspace*{" space "}")
1656 (defun cal-tex-comment (&optional comment)
1657 "Insert % at end of line, include COMMENT if present, and move
1664 (defun cal-tex-banner (comment)
1665 "Insert the COMMENT separated by blank lines."
1668 (cal-tex-comment (concat "\t\t\t" comment))
1672 (defun cal-tex-nl (&optional skip comment)
1673 "End a line with \\. If SKIP, then add that much spacing.
1674 Add COMMENT if present"
1677 (insert "[" skip "]"))
1678 (cal-tex-comment comment))
1680 (defun cal-tex-arg (&optional text)
1681 "Insert optional TEXT surrounded by braces."
1683 (if text (insert text))
1686 (defun cal-tex-cmd (cmd &optional arg)
1687 "Insert LaTeX CMD, with optional ARG, and end with %"
1696 (defun cal-tex-b-document ()
1697 "Insert beginning of document."
1698 (cal-tex-cmd "\\begin{document}"))
1700 (defun cal-tex-e-document ()
1701 "Insert end of document."
1702 (cal-tex-cmd "\\end{document}"))
1704 (defun cal-tex-b-center ()
1705 "Insert beginning of centered block."
1706 (cal-tex-cmd "\\begin{center}"))
1708 (defun cal-tex-e-center ()
1709 "Insert end of centered block."
1711 (cal-tex-cmd "\\end{center}"))
1719 (defun cal-tex-b-parbox (position width)
1720 "Insert parbox with parameters POSITION and WIDTH."
1721 (insert "\\parbox[" position "]{" width "}{")
1724 (defun cal-tex-e-parbox (&optional height)
1725 "Insert end of parbox. Force it to be a given HEIGHT."
1728 (cal-tex-rule "0mm" "0mm" height))
1730 (cal-tex-comment "end parbox"))
1732 (defun cal-tex-b-framebox ( width position )
1733 "Insert framebox with parameters WIDTH and POSITION (clr)."
1734 (insert "\\framebox[" width "][" position "]{" )
1737 (defun cal-tex-e-framebox ()
1738 "Insert end of framebox."
1741 (cal-tex-comment "end framebox"))
1744 (defun cal-tex-b-makebox ( width position )
1745 "Insert makebox with parameters WIDTH and POSITION (clr)."
1746 (insert "\\makebox[" width "][" position "]{" )
1749 (defun cal-tex-e-makebox ()
1750 "Insert end of makebox."
1753 (cal-tex-comment "end makebox"))
1756 (defun cal-tex-rule (lower width height)
1757 "Insert a rule with parameters LOWER WIDTH HEIGHT."
1758 (insert "\\rule[" lower "]{" width "}{" height "}"))
1764 (defun cal-tex-em (string)
1765 "Insert STRING in bf font."
1766 (insert "{\\em " string "}"))
1768 (defun cal-tex-bf (string)
1769 "Insert STRING in bf font."
1770 (insert "{\\bf " string "}"))
1772 (defun cal-tex-scriptsize (string)
1773 "Insert STRING in scriptsize font."
1774 (insert "{\\scriptsize " string "}"))
1776 (defun cal-tex-huge (string)
1777 "Insert STRING in huge size."
1778 (insert "{\\huge " string "}"))
1780 (defun cal-tex-Huge (string)
1781 "Insert STRING in Huge size."
1782 (insert "{\\Huge " string "}"))
1784 (defun cal-tex-Huge-bf (string)
1785 "Insert STRING in Huge bf size."
1786 (insert "{\\Huge\\bf " string "}"))
1788 (defun cal-tex-large (string)
1789 "Insert STRING in large size."
1790 (insert "{\\large " string "}"))
1792 (defun cal-tex-large-bf (string)
1793 "Insert STRING in large bf size."
1794 (insert "{\\large\\bf " string "}"))
1798 ;;; arch-tag: ca8168a4-5a00-4508-a565-17e3bccce6d0
1799 ;;; cal-tex.el ends here