1 ;;; cal-tex.el --- calendar functions for printing calendars with LaTeX
3 ;; Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
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 3, 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 "Non-nil means holidays are printed in the LaTeX calendars that support it.
69 If finding the holidays is too slow, set this to nil."
73 (defcustom cal-tex-diary nil
74 "Non-nil means diary entries are printed in LaTeX calendars that support it.
75 At present, this only affects the monthly, filofax, and iso-week
76 calendars (i.e. not the yearly, plain weekly, or daily calendars)."
80 (defcustom cal-tex-rules nil
81 "Non-nil means pages will be ruled in some LaTeX calendar styles.
82 At present, this only affects the daily filofax calendar."
86 (defcustom cal-tex-daily-string
87 '(let* ((year (extract-calendar-year date
))
88 (day (calendar-day-number date
))
89 (days-remaining (- (calendar-day-number (list 12 31 year
)) day
)))
90 (format "%d/%d" day days-remaining
))
91 "*An expression in the variable `date' whose value is placed on date.
92 The string resulting from evaluating this expression is placed at the bottom
93 center of `date' on the monthly calendar, next to the date in the weekly
94 calendars, and in the top center of daily calendars.
96 Default is ordinal day number of the year and the number of days remaining.
97 As an example of what you do, setting this to
100 (require 'cal-hebrew)
101 (calendar-hebrew-date-string date))
103 will put the Hebrew date at the bottom of each day."
105 :group
'calendar-tex
)
107 (defcustom cal-tex-buffer
"calendar.tex"
108 "The name for the output LaTeX calendar buffer."
110 :group
'calendar-tex
)
112 (defcustom cal-tex-24 nil
113 "Non-nil means use a 24 hour clock in the daily calendar."
115 :group
'calendar-tex
)
117 (defcustom cal-tex-daily-start
8
118 "*The first hour of the daily calendar page."
120 :group
'calendar-tex
)
122 (defcustom cal-tex-daily-end
20
123 "*The last hour of the daily calendar page."
125 :group
'calendar-tex
)
127 (defcustom cal-tex-preamble-extra nil
128 "A string giving extra LaTeX commands to insert in the calendar preamble.
129 For example, to include extra packages:
130 \"\\\\usepackage{foo}\\n\\\\usepackage{bar}\\n\"."
135 (defcustom cal-tex-hook nil
136 "*List of functions called after any LaTeX calendar buffer is generated.
137 You can use this to do postprocessing on the buffer. For example, to change
138 characters with diacritical marks to their LaTeX equivalents, use
139 (add-hook 'cal-tex-hook
140 '(lambda () (iso-iso2tex (point-min) (point-max))))"
142 :group
'calendar-tex
)
144 (defcustom cal-tex-year-hook nil
145 "*List of functions called after a LaTeX year calendar buffer is generated."
147 :group
'calendar-tex
)
149 (defcustom cal-tex-month-hook nil
150 "*List of functions called after a LaTeX month calendar buffer is generated."
152 :group
'calendar-tex
)
154 (defcustom cal-tex-week-hook nil
155 "*List of functions called after a LaTeX week calendar buffer is generated."
157 :group
'calendar-tex
)
159 (defcustom cal-tex-daily-hook nil
160 "*List of functions called after a LaTeX daily calendar buffer is generated."
162 :group
'calendar-tex
)
165 ;;; Definitions for LaTeX code
168 (defvar cal-tex-day-prefix
"\\caldate{%s}{%s}"
169 "The initial LaTeX code for a day.
170 The holidays, diary entries, bottom string, and the text follow.")
172 (defvar cal-tex-day-name-format
"\\myday{%s}%%"
173 "The format for LaTeX code for a day name. The names are taken from
174 `calendar-day-name-array'.")
176 (defvar cal-tex-cal-one-month
177 "\\def\\calmonth#1#2%
179 \\Huge\\bf\\uppercase{#1} #2 \\\\[1cm]%
184 "LaTeX code for the month header")
186 (defvar cal-tex-cal-multi-month
187 "\\def\\calmonth#1#2#3#4%
189 \\Huge\\bf #1 #2---#3 #4\\\\[1cm]%
194 "LaTeX code for the month header")
196 (defvar cal-tex-myday
197 "\\renewcommand{\\myday}[1]%
198 {\\makebox[\\cellwidth]{\\hfill\\large\\bf#1\\hfill}}
201 "LaTeX code for a day heading")
203 (defvar cal-tex-caldate
205 \\long\\def\\caldate#1#2#3#4#5#6{%
206 \\fbox{\\hbox to\\cellwidth{%
207 \\vbox to\\cellheight{%
208 \\hbox to\\cellwidth{%
209 {\\hspace*{1mm}\\Large \\bf \\strut #2}\\hspace{.05\\cellwidth}%
210 \\raisebox{\\holidaymult\\cellheight}%
211 {\\parbox[t]{.75\\cellwidth}{\\tiny \\raggedright #4}}}
212 \\hbox to\\cellwidth{%
213 \\hspace*{1mm}\\parbox{.95\\cellwidth}{\\tiny \\raggedright #3}}
215 \\hbox to\\cellwidth{#6}%
217 \\hbox to\\cellwidth{\\hfill \\tiny #5 \\hfill}%
221 "LaTeX code to insert one box with date info in calendar.
222 This definition is the heart of the calendar!")
224 (defun cal-tex-list-holidays (d1 d2
)
225 "Generate a list of all holidays from absolute date D1 to D2."
226 (let* ((start (calendar-gregorian-from-absolute d1
))
227 (displayed-month (extract-calendar-month start
))
228 (displayed-year (extract-calendar-year start
))
229 (end (calendar-gregorian-from-absolute d2
))
230 (end-month (extract-calendar-month end
))
231 (end-year (extract-calendar-year end
))
233 (1+ (/ (calendar-interval displayed-month displayed-year
238 (increment-calendar-month displayed-month displayed-year
1)
239 (calendar-for-loop i from
1 to number-of-intervals do
240 (setq holidays
(append holidays
(calendar-holiday-list)))
241 (increment-calendar-month displayed-month displayed-year
3))
243 (and (car (car holidays
))
244 (let ((a (calendar-absolute-from-gregorian (car (car holidays
)))))
245 (and (<= d1 a
) (<= a d2
)))
246 (setq in-range
(append (list (car holidays
)) in-range
)))
247 (setq holidays
(cdr holidays
)))
250 (defun cal-tex-list-diary-entries (d1 d2
)
251 "Generate a list of all diary-entries from absolute date D1 to D2."
252 (let ((diary-list-include-blanks nil
)
253 (diary-display-hook 'ignore
))
255 (calendar-gregorian-from-absolute d1
)
258 (defun cal-tex-preamble (&optional args
)
259 "Insert the LaTeX preamble.
260 Preamble Includes initial definitions for various LaTeX commands.
261 Optional ARGS are included."
262 (set-buffer (get-buffer-create cal-tex-buffer
))
264 (insert "\\documentclass")
266 (insert "[" args
"]"))
267 (insert "{article}\n")
268 (if (stringp cal-tex-preamble-extra
)
269 (insert cal-tex-preamble-extra
"\n"))
270 (insert "\\hbadness 20000
276 \\evensidemargin -2cm
281 \\newlength{\\cellwidth}
282 \\newlength{\\cellheight}
283 \\newlength{\\boxwidth}
284 \\newlength{\\boxheight}
285 \\newlength{\\cellsize}
286 \\newcommand{\\myday}[1]{}
287 \\newcommand{\\caldate}[6]{}
288 \\newcommand{\\nocaldate}[6]{}
289 \\newcommand{\\calsmall}[6]{}
297 (defun cal-tex-cursor-year (&optional arg
)
298 "Make a buffer with LaTeX commands for the year cursor is on.
299 Optional prefix argument specifies number of years."
301 (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t
))
304 (defun cal-tex-cursor-year-landscape (&optional arg
)
305 "Make a buffer with LaTeX commands for the year cursor is on.
306 Optional prefix argument specifies number of years."
308 (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t
))
312 (defun cal-tex-year (year n
&optional landscape
)
313 "Make a one page yearly calendar of YEAR; do this for N years.
314 There are four rows of three months each, unless optional LANDSCAPE is t,
315 in which case the calendar isprinted in landscape mode with three rows of
317 (cal-tex-insert-preamble 1 landscape
"12pt")
319 (cal-tex-vspace "-.6cm")
320 (cal-tex-vspace "-3.1cm"))
321 (calendar-for-loop j from
1 to n do
322 (insert "\\vfill%\n")
324 (cal-tex-Huge (number-to-string year
))
326 (cal-tex-vspace "1cm")
328 (cal-tex-b-parbox "l" (if landscape
"5.9in" "4.3in"))
332 (calendar-for-loop i from
1 to
12 do
333 (insert (cal-tex-mini-calendar i year
"month" "1.1in" "1in"))
335 (cal-tex-hspace "0.5in")
336 (if (zerop (mod i
(if landscape
4 3)))
337 (cal-tex-nl "0.5in")))
340 (insert "\\vfill%\n")
341 (setq year
(1+ year
))
344 (cal-tex-end-document))
345 (run-hooks 'cal-tex-year-hook
))
346 (run-hooks 'cal-tex-hook
))
348 (defun cal-tex-cursor-filofax-year (&optional arg
)
349 "Make a Filofax one page yearly calendar of year indicated by cursor.
350 Optional parameter specifies number of years."
352 (let* ((n (if arg arg
1))
353 (year (extract-calendar-year (calendar-cursor-to-date t
))))
354 (cal-tex-preamble "twoside")
355 (cal-tex-cmd "\\textwidth 3.25in")
356 (cal-tex-cmd "\\textheight 6.5in")
357 (cal-tex-cmd "\\oddsidemargin 1.675in")
358 (cal-tex-cmd "\\evensidemargin 1.675in")
359 (cal-tex-cmd "\\topmargin 0pt")
360 (cal-tex-cmd "\\headheight -0.875in")
361 (cal-tex-cmd "\\fboxsep 0.5mm")
362 (cal-tex-cmd "\\pagestyle{empty}")
364 (cal-tex-cmd "\\vspace*{0.25in}")
365 (calendar-for-loop j from
1 to n do
366 (insert (format "\\hfil {\\Large \\bf %s} \\hfil\\\\\n" year
))
368 (cal-tex-b-parbox "l" "\\textwidth")
372 (let ((month-names; don't use default in case user changed it
373 ;; These are only used to define the command names, not
374 ;; the names of the months they insert.
375 ["January" "February" "March" "April" "May" "June"
376 "July" "August" "September" "October" "November" "December"]))
377 (calendar-for-loop i from
1 to
12 do
378 (insert (cal-tex-mini-calendar i year
379 (aref month-names
(1- i
))
380 "1in" ".9in" "tiny" "0.6mm"))))
382 "\\noindent\\fbox{\\January}\\fbox{\\February}\\fbox{\\March}\\\\
383 \\noindent\\fbox{\\April}\\fbox{\\May}\\fbox{\\June}\\\\
384 \\noindent\\fbox{\\July}\\fbox{\\August}\\fbox{\\September}\\\\
385 \\noindent\\fbox{\\October}\\fbox{\\November}\\fbox{\\December}
389 (setq year
(1+ year
))
391 (cal-tex-end-document)
393 (cal-tex-cmd "\\vspace*{0.25in}"))
394 (run-hooks 'cal-tex-year-hook
))
395 (run-hooks 'cal-tex-hook
)))
398 ;;; Monthly calendars
401 (defun cal-tex-cursor-month-landscape (&optional arg
)
402 "Make a LaTeX calendar buffer for the month the cursor is on.
403 Optional prefix argument specifies number of months to be
404 produced (default 1). The output is in landscape format, one
405 month to a page. It shows holiday and diary entries if
406 `cal-tex-holidays' and `cal-tex-diary', respectively, are
409 (let* ((n (if arg arg
1))
410 (date (calendar-cursor-to-date t
))
411 (month (extract-calendar-month date
))
412 (year (extract-calendar-year date
))
415 (cal-tex-which-days '(0 1 2 3 4 5 6)))
416 (increment-calendar-month end-month end-year
(1- n
))
417 (let ((diary-list (if cal-tex-diary
418 (cal-tex-list-diary-entries
419 (calendar-absolute-from-gregorian
421 (calendar-absolute-from-gregorian
423 (calendar-last-day-of-month
426 (holidays (if cal-tex-holidays
427 (cal-tex-list-holidays
428 (calendar-absolute-from-gregorian
430 (calendar-absolute-from-gregorian
432 (calendar-last-day-of-month end-month end-year
)
436 (small-months-at-start))
437 (cal-tex-insert-preamble (cal-tex-number-weeks month year
1) t
"12pt")
438 (cal-tex-cmd cal-tex-cal-one-month
)
439 (calendar-for-loop i from
1 to n do
440 (setq other-month month
)
441 (setq other-year year
)
442 (increment-calendar-month other-month other-year -
1)
443 (insert (cal-tex-mini-calendar other-month other-year
"lastmonth"
444 "\\cellwidth" "\\cellheight"))
445 (increment-calendar-month other-month other-year
2)
446 (insert (cal-tex-mini-calendar other-month other-year
"nextmonth"
447 "\\cellwidth" "\\cellheight"))
448 (cal-tex-insert-month-header 1 month year month year
)
449 (cal-tex-insert-day-names)
451 (setq small-months-at-start
452 (< 1 (mod (- (calendar-day-of-week (list month
1 year
))
453 calendar-week-start-day
)
455 (if small-months-at-start
456 (insert "\\lastmonth\\nextmonth\\hspace*{-2\\cellwidth}"))
457 (cal-tex-insert-blank-days month year cal-tex-day-prefix
)
458 (cal-tex-insert-days month year diary-list holidays
460 (cal-tex-insert-blank-days-at-end month year cal-tex-day-prefix
)
461 (if (and (not small-months-at-start
)
462 (< 1 (mod (- (1- calendar-week-start-day
)
463 (calendar-day-of-week
465 (calendar-last-day-of-month month year
)
468 (insert "\\vspace*{-\\cellwidth}\\hspace*{-2\\cellwidth}"
469 "\\lastmonth\\nextmonth%
473 (run-hooks 'cal-tex-month-hook
)
475 (increment-calendar-month month year
1)
476 (cal-tex-vspace "-2cm")
477 (cal-tex-insert-preamble
478 (cal-tex-number-weeks month year
1) t
"12pt" t
))))
479 (cal-tex-end-document)
480 (run-hooks 'cal-tex-hook
))))
482 (defun cal-tex-cursor-month (arg)
483 "Make a LaTeX calendar buffer for the month the cursor is on.
484 Optional prefix argument specifies number of months to be
485 produced (default 1). The calendar is condensed onto one page.
486 It shows holiday and diary entries if `cal-tex-holidays' and
487 `cal-tex-diary', respectively, are non-nil."
489 (let* ((date (calendar-cursor-to-date t
))
490 (month (extract-calendar-month date
))
491 (year (extract-calendar-year date
))
495 (increment-calendar-month end-month end-year
(1- n
))
496 (let ((diary-list (if cal-tex-diary
497 (cal-tex-list-diary-entries
498 (calendar-absolute-from-gregorian
500 (calendar-absolute-from-gregorian
502 (calendar-last-day-of-month
505 (holidays (if cal-tex-holidays
506 (cal-tex-list-holidays
507 (calendar-absolute-from-gregorian
509 (calendar-absolute-from-gregorian
511 (calendar-last-day-of-month end-month end-year
)
515 (cal-tex-insert-preamble (cal-tex-number-weeks month year n
) nil
"12pt")
517 (cal-tex-cmd cal-tex-cal-multi-month
)
518 (cal-tex-cmd cal-tex-cal-one-month
))
519 (cal-tex-insert-month-header n month year end-month end-year
)
520 (cal-tex-insert-day-names)
522 (cal-tex-insert-blank-days month year cal-tex-day-prefix
)
523 (calendar-for-loop i from
1 to n do
524 (setq other-month month
)
525 (setq other-year year
)
526 (cal-tex-insert-days month year diary-list holidays
528 (if (= (mod (calendar-absolute-from-gregorian
530 (calendar-last-day-of-month month year
)
533 6); last day of month was Saturday
537 (increment-calendar-month month year
1))
538 (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix
)
539 (cal-tex-end-document)))
540 (run-hooks 'cal-tex-hook
))
542 (defun cal-tex-insert-days (month year diary-list holidays day-format
)
543 "Insert LaTeX commands for a range of days in monthly calendars.
544 LaTeX commands are inserted for the days of the MONTH in YEAR.
545 Diary entries on DIARY-LIST are included. Holidays on HOLIDAYS
546 are included. Each day is formatted using format DAY-FORMAT."
547 (let* ((blank-days;; at start of month
549 (- (calendar-day-of-week (list month
1 year
))
550 calendar-week-start-day
)
553 (last (calendar-last-day-of-month month year
)))
554 (calendar-for-loop i from
1 to last do
555 (setq date
(list month i year
))
556 (if (memq (calendar-day-of-week date
) cal-tex-which-days
)
558 (insert (format day-format
(cal-tex-month-name month
) i
))
559 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
560 (cal-tex-arg (cal-tex-latexify-list holidays date
))
561 (cal-tex-arg (eval cal-tex-daily-string
))
564 (if (and (zerop (mod (+ i blank-days
) 7))
570 (defun cal-tex-insert-day-names ()
571 "Insert the names of the days at top of a monthly calendar."
572 (calendar-for-loop i from
0 to
6 do
573 (if (memq i cal-tex-which-days
)
574 (insert (format cal-tex-day-name-format
575 (cal-tex-LaTeXify-string
576 (aref calendar-day-name-array
577 (mod (+ calendar-week-start-day i
) 7))))))
580 (defun cal-tex-insert-month-header (n month year end-month end-year
)
581 "Create a title for a calendar.
582 A title is inserted for a calendar with N months starting with
583 MONTH YEAR and ending with END-MONTH END-YEAR."
584 (let ((month-name (cal-tex-month-name month
))
585 (end-month-name (cal-tex-month-name end-month
)))
587 (insert (format "\\calmonth{%s}{%s}\n\\vspace*{-0.5cm}"
589 (insert (format "\\calmonth{%s}{%s}{%s}{%s}\n\\vspace*{-0.5cm}"
590 month-name year end-month-name end-year
))))
593 (defun cal-tex-insert-blank-days (month year day-format
)
594 "Insert code for initial days not in calendar.
595 Insert LaTeX code for the blank days at the beginning of the MONTH in
596 YEAR. The entry is formatted using DAY-FORMAT. If the entire week is
597 blank, no days are inserted."
598 (if (cal-tex-first-blank-p month year
)
599 (let* ((blank-days;; at start of month
601 (- (calendar-day-of-week (list month
1 year
))
602 calendar-week-start-day
)
604 (calendar-for-loop i from
0 to
(1- blank-days
) do
605 (if (memq i cal-tex-which-days
)
606 (insert (format day-format
" " " ") "{}{}{}{}%\n"))))))
608 (defun cal-tex-insert-blank-days-at-end (month year day-format
)
609 "Insert code for final days not in calendar.
610 Insert LaTeX code for the blank days at the end of the MONTH in YEAR.
611 The entry is formatted using DAY-FORMAT."
612 (if (cal-tex-last-blank-p month year
)
613 (let* ((last-day (calendar-last-day-of-month month year
))
614 (blank-days;; at end of month
616 (- (calendar-day-of-week (list month last-day year
))
617 calendar-week-start-day
)
619 (calendar-for-loop i from
(1+ blank-days
) to
6 do
620 (if (memq i cal-tex-which-days
)
621 (insert (format day-format
"" "") "{}{}{}{}%\n"))))))
623 (defun cal-tex-first-blank-p (month year
)
624 "Determine if any days of the first week will be printed.
625 Return t if there will there be any days of the first week printed
626 in the calendar starting in MONTH YEAR."
628 (the-saturday)) ;the day of week of 1st Saturday
629 (calendar-for-loop i from
1 to
7 do
630 (if (= 6 (calendar-day-of-week (list month i year
)))
631 (setq the-saturday i
)))
632 (calendar-for-loop i from
1 to the-saturday do
633 (if (memq (calendar-day-of-week (list month i year
))
638 (defun cal-tex-last-blank-p (month year
)
639 "Determine if any days of the last week will be printed.
640 Return t if there will there be any days of the last week printed
641 in the calendar starting in MONTH YEAR."
643 (last-day (calendar-last-day-of-month month year
))
644 (the-sunday)) ;the day of week of last Sunday
645 (calendar-for-loop i from
(- last-day
6) to last-day do
646 (if (= 0 (calendar-day-of-week (list month i year
)))
647 (setq the-sunday i
)))
648 (calendar-for-loop i from the-sunday to last-day do
649 (if (memq (calendar-day-of-week (list month i year
))
654 (defun cal-tex-number-weeks (month year n
)
655 "Determine the number of weeks in a range of dates.
656 Compute the number of weeks in the calendar starting with MONTH and YEAR,
657 and lasting N months, including only the days in WHICH-DAYS. As it stands,
658 this is only an upper bound."
659 (let ((d (list month
1 year
)))
660 (increment-calendar-month month year
(1- n
))
661 (/ (- (calendar-dayname-on-or-before
662 calendar-week-start-day
663 (+ 7 (calendar-absolute-from-gregorian
664 (list month
(calendar-last-day-of-month month year
) year
))))
665 (calendar-dayname-on-or-before
666 calendar-week-start-day
667 (calendar-absolute-from-gregorian d
)))
674 (defvar cal-tex-LaTeX-hourbox
675 "\\newcommand{\\hourbox}[2]%
676 {\\makebox[2em]{\\rule{0cm}{#2ex}#1}\\rule{3in}{.15mm}}\n"
677 "One hour and a line on the right.")
679 ;; TODO cal-tex-diary-support.
680 (defun cal-tex-cursor-week (&optional arg
)
681 "Make a LaTeX calendar buffer for a two-page one-week calendar.
682 It applies to the week that point is in. The optional prefix
683 argument specifies the number of weeks (default 1). The calendar
684 shows holidays if `cal-tex-holidays' is t (note that diary
685 entries are not shown)."
687 (let* ((n (if arg arg
1))
688 (date (calendar-gregorian-from-absolute
689 (calendar-dayname-on-or-before
690 calendar-week-start-day
691 (calendar-absolute-from-gregorian
692 (calendar-cursor-to-date t
)))))
693 (month (extract-calendar-month date
))
694 (year (extract-calendar-year date
))
695 (holidays (if cal-tex-holidays
696 (cal-tex-list-holidays
697 (calendar-absolute-from-gregorian date
)
699 (calendar-absolute-from-gregorian date
))))))
700 (cal-tex-preamble "11pt")
701 (cal-tex-cmd "\\textwidth 6.5in")
702 (cal-tex-cmd "\\textheight 10.5in")
703 (cal-tex-cmd "\\oddsidemargin 0in")
704 (cal-tex-cmd "\\evensidemargin 0in")
705 (insert cal-tex-LaTeX-hourbox
)
707 (cal-tex-cmd "\\pagestyle{empty}")
708 (calendar-for-loop i from
1 to n do
709 (cal-tex-vspace "-1.5in")
711 (cal-tex-Huge-bf (format "\\uppercase{%s}"
712 (cal-tex-month-name month
)))
713 (cal-tex-hspace "2em")
714 (cal-tex-Huge-bf (number-to-string year
))
717 (cal-tex-hspace "-.2in")
718 (cal-tex-b-parbox "l" "7in")
719 (calendar-for-loop j from
1 to
7 do
720 (cal-tex-week-hours date holidays
"3.1")
721 (setq date
(cal-tex-incr-date date
)))
723 (setq month
(extract-calendar-month date
))
724 (setq year
(extract-calendar-year date
))
727 (run-hooks 'cal-tex-week-hook
)
729 (cal-tex-end-document)
730 (run-hooks 'cal-tex-hook
)))
732 ;; TODO cal-tex-diary support.
733 (defun cal-tex-cursor-week2 (&optional arg
)
734 "Make a LaTeX calendar buffer for a two-page one-week calendar.
735 It applies to the week that point is in. Optional prefix
736 argument specifies number of weeks (default 1). The calendar
737 shows holidays if `cal-tex-holidays' is non-nil (note that diary
738 entries are not shown)."
740 (let* ((n (if arg arg
1))
741 (date (calendar-gregorian-from-absolute
742 (calendar-dayname-on-or-before
743 calendar-week-start-day
744 (calendar-absolute-from-gregorian
745 (calendar-cursor-to-date t
)))))
746 (month (extract-calendar-month date
))
747 (year (extract-calendar-year date
))
749 (holidays (if cal-tex-holidays
750 (cal-tex-list-holidays
751 (calendar-absolute-from-gregorian date
)
753 (calendar-absolute-from-gregorian date
))))))
754 (cal-tex-preamble "12pt")
755 (cal-tex-cmd "\\textwidth 6.5in")
756 (cal-tex-cmd "\\textheight 10.5in")
757 (cal-tex-cmd "\\oddsidemargin 0in")
758 (cal-tex-cmd "\\evensidemargin 0in")
759 (insert cal-tex-LaTeX-hourbox
)
761 (cal-tex-cmd "\\pagestyle{empty}")
762 (calendar-for-loop i from
1 to n do
763 (cal-tex-vspace "-1.5in")
765 (cal-tex-Huge-bf (format "\\uppercase{%s}"
766 (cal-tex-month-name month
)))
767 (cal-tex-hspace "2em")
768 (cal-tex-Huge-bf (number-to-string year
))
771 (cal-tex-hspace "-.2in")
772 (cal-tex-b-parbox "l" "\\textwidth")
773 (calendar-for-loop j from
1 to
3 do
774 (cal-tex-week-hours date holidays
"5")
775 (setq date
(cal-tex-incr-date date
)))
778 (insert (cal-tex-mini-calendar
779 (extract-calendar-month (cal-tex-previous-month date
))
780 (extract-calendar-year (cal-tex-previous-month date
))
781 "lastmonth" "1.1in" "1in"))
782 (insert (cal-tex-mini-calendar
783 (extract-calendar-month date
)
784 (extract-calendar-year date
)
785 "thismonth" "1.1in" "1in"))
786 (insert (cal-tex-mini-calendar
787 (extract-calendar-month (cal-tex-next-month date
))
788 (extract-calendar-year (cal-tex-next-month date
))
789 "nextmonth" "1.1in" "1in"))
790 (insert "\\hbox to \\textwidth{")
792 (insert "\\lastmonth")
794 (insert "\\thismonth")
796 (insert "\\nextmonth")
800 (cal-tex-b-parbox "l" "\\textwidth")
801 (calendar-for-loop j from
4 to
7 do
802 (cal-tex-week-hours date holidays
"5")
803 (setq date
(cal-tex-incr-date date
)))
805 (setq month
(extract-calendar-month date
))
806 (setq year
(extract-calendar-year date
))
809 (run-hooks 'cal-tex-week-hook
)
811 (cal-tex-end-document)
812 (run-hooks 'cal-tex-hook
)))
814 (defun cal-tex-cursor-week-iso (&optional arg
)
815 "Make a LaTeX calendar buffer for a one page ISO-style weekly calendar.
816 Optional prefix argument specifies number of weeks (default 1).
817 The calendar shows holiday and diary entries if
818 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil."
820 (let* ((n (if arg arg
1))
821 (date (calendar-gregorian-from-absolute
822 (calendar-dayname-on-or-before
824 (calendar-absolute-from-gregorian
825 (calendar-cursor-to-date t
)))))
826 (month (extract-calendar-month date
))
827 (year (extract-calendar-year date
))
828 (day (extract-calendar-day date
))
829 (holidays (if cal-tex-holidays
830 (cal-tex-list-holidays
831 (calendar-absolute-from-gregorian date
)
833 (calendar-absolute-from-gregorian date
)))))
834 (diary-list (if cal-tex-diary
835 (cal-tex-list-diary-entries
836 (calendar-absolute-from-gregorian
839 (calendar-absolute-from-gregorian date
))))))
840 (cal-tex-preamble "11pt")
841 (cal-tex-cmd "\\textwidth 6.5in")
842 (cal-tex-cmd "\\textheight 10.5in")
843 (cal-tex-cmd "\\oddsidemargin 0in")
844 (cal-tex-cmd "\\evensidemargin 0in")
846 (cal-tex-cmd "\\pagestyle{empty}")
847 (calendar-for-loop i from
1 to n do
848 (cal-tex-vspace "-1.5in")
851 (let* ((d (calendar-iso-from-absolute
852 (calendar-absolute-from-gregorian date
))))
853 (format "Week %d of %d"
854 (extract-calendar-month d
)
855 (extract-calendar-year d
))))
858 (cal-tex-b-parbox "l" "\\textwidth")
859 (calendar-for-loop j from
1 to
7 do
860 (cal-tex-b-parbox "t" "\\textwidth")
861 (cal-tex-b-parbox "t" "\\textwidth")
862 (cal-tex-rule "0pt" "\\textwidth" ".2mm")
864 (cal-tex-b-parbox "t" "\\textwidth")
865 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
867 (cal-tex-large-bf (cal-tex-month-name month
))
869 (cal-tex-large-bf (number-to-string day
))
870 (if (not (string= "" (cal-tex-latexify-list holidays date
)))
873 (cal-tex-large-bf (cal-tex-latexify-list holidays date
"; "))))
875 (insert " " (eval cal-tex-daily-string
))
879 (cal-tex-b-parbox "t" "\\textwidth")
880 (if (not (string= "" (cal-tex-latexify-list diary-list date
)))
882 (insert "\\vbox to 0pt{")
884 (cal-tex-latexify-list diary-list date
))
888 (setq date
(cal-tex-incr-date date
))
889 (setq month
(extract-calendar-month date
))
890 (setq day
(extract-calendar-day date
))
892 (cal-tex-e-parbox "2cm")
894 (setq month
(extract-calendar-month date
))
895 (setq year
(extract-calendar-year date
)))
899 (run-hooks 'cal-tex-week-hook
)
901 (cal-tex-end-document)
902 (run-hooks 'cal-tex-hook
)))
904 (defun cal-tex-week-hours (date holidays height
)
905 "Insert hourly entries for DATE with HOLIDAYS, with line height HEIGHT.
906 Uses the 24-hour clock if `cal-tex-24' is non-nil."
907 (let ((month (extract-calendar-month date
))
908 (day (extract-calendar-day date
))
909 (year (extract-calendar-year date
))
911 (cal-tex-comment "begin cal-tex-week-hours")
912 (cal-tex-cmd "\\ \\\\[-.2cm]")
913 (cal-tex-cmd "\\noindent")
914 (cal-tex-b-parbox "l" "6.8in")
915 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
917 (cal-tex-large-bf (cal-tex-month-name month
))
919 (cal-tex-large-bf (number-to-string day
))
920 (if (not (string= "" (cal-tex-latexify-list holidays date
)))
923 (cal-tex-large-bf (cal-tex-latexify-list holidays date
"; "))))
925 (insert " " (eval cal-tex-daily-string
))
928 (cal-tex-rule "0pt" "6.8in" ".2mm")
930 (calendar-for-loop i from
8 to
12 do
932 (setq afternoon
(+ i
5))
933 (setq afternoon
(- i
7)))
934 (cal-tex-cmd "\\hourbox" (number-to-string i
))
936 (cal-tex-hspace ".4cm")
937 (cal-tex-cmd "\\hourbox" (number-to-string afternoon
))
941 ;; TODO cal-tex-diary support.
942 (defun cal-tex-cursor-week-monday (&optional arg
)
943 "Make a LaTeX calendar buffer for a two-page one-week calendar.
944 It applies to the week that point is in, and starts on Monday.
945 Optional prefix argument specifies number of weeks (default 1).
946 The calendar shows holidays if `cal-tex-holidays' is
947 non-nil (note that diary entries are not shown)."
949 (let* ((n (if arg arg
1))
950 (date (calendar-gregorian-from-absolute
951 (calendar-dayname-on-or-before
953 (calendar-absolute-from-gregorian
954 (calendar-cursor-to-date t
))))))
955 (cal-tex-preamble "11pt")
956 (cal-tex-cmd "\\textwidth 6.5in")
957 (cal-tex-cmd "\\textheight 10.5in")
958 (cal-tex-cmd "\\oddsidemargin 0in")
959 (cal-tex-cmd "\\evensidemargin 0in")
961 (calendar-for-loop i from
1 to n do
962 (cal-tex-vspace "-1cm")
963 (insert "\\noindent ")
964 (cal-tex-weekly4-box (cal-tex-incr-date date
) nil
)
965 (cal-tex-weekly4-box (cal-tex-incr-date date
4) nil
)
967 (cal-tex-weekly4-box (cal-tex-incr-date date
2) nil
)
968 (cal-tex-weekly4-box (cal-tex-incr-date date
5) nil
)
970 (cal-tex-weekly4-box (cal-tex-incr-date date
3) nil
)
971 (cal-tex-weekly4-box (cal-tex-incr-date date
6) t
)
974 (run-hooks 'cal-tex-week-hook
)
975 (setq date
(cal-tex-incr-date date
7))
977 (cal-tex-end-document)
978 (run-hooks 'cal-tex-hook
)))
980 (defun cal-tex-weekly4-box (date weekend
)
981 "Make one box for DATE, different if WEEKEND.
982 Uses the 24-hour clock if `cal-tex-24' is non-nil."
984 (day (extract-calendar-day date
))
985 (month (extract-calendar-month date
))
986 (year (extract-calendar-year date
))
987 (dayname (cal-tex-LaTeXify-string (calendar-day-name date
)))
988 (date1 (cal-tex-incr-date date
))
989 (day1 (extract-calendar-day date1
))
990 (month1 (extract-calendar-month date1
))
991 (year1 (extract-calendar-year date1
))
992 (dayname1 (cal-tex-LaTeXify-string (calendar-day-name date1
)))
994 (cal-tex-b-framebox "8cm" "l")
995 (cal-tex-b-parbox "b" "7.5cm")
996 (insert (format "{\\Large\\bf %s,} %s/%s/%s\\\\\n" dayname month day year
))
997 (cal-tex-rule "0pt" "7.5cm" ".5mm")
1001 (calendar-for-loop i from
8 to
12 do
1002 (insert (format "{\\large\\sf %d}\\\\\n" i
)))
1003 (calendar-for-loop i from
1 to
5 do
1004 (insert (format "{\\large\\sf %d}\\\\\n"
1005 (if cal-tex-24
(+ i
12) i
))))))
1009 (cal-tex-vspace "1cm")
1010 (insert "\\ \\vfill")
1011 (insert (format "{\\Large\\bf %s,} %s/%s/%s\\\\\n"
1012 dayname1 month1 day1 year1
))
1013 (cal-tex-rule "0pt" "7.5cm" ".5mm")
1014 (cal-tex-nl "1.5cm")
1015 (cal-tex-vspace "1cm")))
1017 (cal-tex-e-framebox)
1018 (cal-tex-hspace "1cm")))
1020 (defun cal-tex-cursor-filofax-2week (&optional arg
)
1021 "Two-weeks-at-a-glance Filofax style calendar for week cursor is in.
1022 Optional prefix argument specifies number of weeks (default 1).
1023 The calendar shows holiday and diary entries if
1024 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil."
1026 (let* ((n (if arg arg
1))
1027 (date (calendar-gregorian-from-absolute
1028 (calendar-dayname-on-or-before
1029 calendar-week-start-day
1030 (calendar-absolute-from-gregorian
1031 (calendar-cursor-to-date t
)))))
1032 (month (extract-calendar-month date
))
1033 (year (extract-calendar-year date
))
1034 (day (extract-calendar-day date
))
1035 (holidays (if cal-tex-holidays
1036 (cal-tex-list-holidays
1037 (calendar-absolute-from-gregorian date
)
1039 (calendar-absolute-from-gregorian date
)))))
1040 (diary-list (if cal-tex-diary
1041 (cal-tex-list-diary-entries
1042 (calendar-absolute-from-gregorian
1043 (list month
1 year
))
1045 (calendar-absolute-from-gregorian date
))))))
1046 (cal-tex-preamble "twoside")
1047 (cal-tex-cmd "\\textwidth 3.25in")
1048 (cal-tex-cmd "\\textheight 6.5in")
1049 (cal-tex-cmd "\\oddsidemargin 1.75in")
1050 (cal-tex-cmd "\\evensidemargin 1.5in")
1051 (cal-tex-cmd "\\topmargin 0pt")
1052 (cal-tex-cmd "\\headheight -0.875in")
1053 (cal-tex-cmd "\\headsep 0.125in")
1054 (cal-tex-cmd "\\footskip .125in")
1055 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1056 \\long\\def\\rightday#1#2#3#4#5{%
1057 \\rule{\\textwidth}{0.3pt}\\\\%
1058 \\hbox to \\textwidth{%
1061 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1062 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1063 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1064 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1065 \\long\\def\\leftday#1#2#3#4#5{%
1066 \\rule{\\textwidth}{0.3pt}\\\\%
1067 \\hbox to \\textwidth{%
1070 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1071 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1072 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1074 (cal-tex-b-document)
1075 (cal-tex-cmd "\\pagestyle{empty}")
1076 (calendar-for-loop i from
1 to n do
1078 (insert "\\righthead")
1079 (insert "\\lefthead"))
1081 (let ((d (cal-tex-incr-date date
6)))
1082 (if (= (extract-calendar-month date
)
1083 (extract-calendar-month d
))
1086 (extract-calendar-month date
))
1087 (extract-calendar-year date
))
1088 (if (= (extract-calendar-year date
)
1089 (extract-calendar-year d
))
1090 (format "%s---%s %s"
1092 (extract-calendar-month date
))
1094 (extract-calendar-month d
))
1095 (extract-calendar-year date
))
1096 (format "%s %s---%s %s"
1098 (extract-calendar-month date
))
1099 (extract-calendar-year date
)
1100 (cal-tex-month-name (extract-calendar-month d
))
1101 (extract-calendar-year d
))))))
1103 (calendar-for-loop j from
1 to
7 do
1105 (insert "\\rightday")
1106 (insert "\\leftday"))
1107 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1108 (cal-tex-arg (int-to-string (extract-calendar-day date
)))
1109 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1110 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1111 (cal-tex-arg (eval cal-tex-daily-string
))
1113 (setq date
(cal-tex-incr-date date
)))
1116 (run-hooks 'cal-tex-week-hook
)
1117 (cal-tex-newpage))))
1118 (cal-tex-end-document)
1119 (run-hooks 'cal-tex-hook
)))
1121 (defun cal-tex-cursor-filofax-week (&optional arg
)
1122 "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
1123 Optional prefix argument specifies number of weeks (default 1),
1124 starting on Mondays. The calendar shows holiday and diary entries
1125 if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil."
1127 (let* ((n (if arg arg
1))
1128 (date (calendar-gregorian-from-absolute
1129 (calendar-dayname-on-or-before
1131 (calendar-absolute-from-gregorian
1132 (calendar-cursor-to-date t
)))))
1133 (month (extract-calendar-month date
))
1134 (year (extract-calendar-year date
))
1135 (day (extract-calendar-day date
))
1136 (holidays (if cal-tex-holidays
1137 (cal-tex-list-holidays
1138 (calendar-absolute-from-gregorian date
)
1140 (calendar-absolute-from-gregorian date
)))))
1141 (diary-list (if cal-tex-diary
1142 (cal-tex-list-diary-entries
1143 (calendar-absolute-from-gregorian
1144 (list month
1 year
))
1146 (calendar-absolute-from-gregorian date
))))))
1147 (cal-tex-preamble "twoside")
1148 (cal-tex-cmd "\\textwidth 3.25in")
1149 (cal-tex-cmd "\\textheight 6.5in")
1150 (cal-tex-cmd "\\oddsidemargin 1.75in")
1151 (cal-tex-cmd "\\evensidemargin 1.5in")
1152 (cal-tex-cmd "\\topmargin 0pt")
1153 (cal-tex-cmd "\\headheight -0.875in")
1154 (cal-tex-cmd "\\headsep 0.125in")
1155 (cal-tex-cmd "\\footskip .125in")
1156 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1157 \\long\\def\\rightday#1#2#3#4#5{%
1158 \\rule{\\textwidth}{0.3pt}\\\\%
1159 \\hbox to \\textwidth{%
1162 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1163 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1164 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1165 \\long\\def\\weekend#1#2#3#4#5{%
1166 \\rule{\\textwidth}{0.3pt}\\\\%
1167 \\hbox to \\textwidth{%
1170 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1171 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1172 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1173 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1174 \\long\\def\\leftday#1#2#3#4#5{%
1175 \\rule{\\textwidth}{0.3pt}\\\\%
1176 \\hbox to \\textwidth{%
1179 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1180 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1181 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1183 (cal-tex-b-document)
1184 (cal-tex-cmd "\\pagestyle{empty}\\ ")
1186 (calendar-for-loop i from
1 to n do
1187 (insert "\\lefthead")
1189 (let ((d (cal-tex-incr-date date
2)))
1190 (if (= (extract-calendar-month date
)
1191 (extract-calendar-month d
))
1194 (extract-calendar-month date
))
1195 (extract-calendar-year date
))
1196 (if (= (extract-calendar-year date
)
1197 (extract-calendar-year d
))
1198 (format "%s---%s %s"
1200 (extract-calendar-month date
))
1202 (extract-calendar-month d
))
1203 (extract-calendar-year date
))
1204 (format "%s %s---%s %s"
1206 (extract-calendar-month date
))
1207 (extract-calendar-year date
)
1208 (cal-tex-month-name (extract-calendar-month d
))
1209 (extract-calendar-year d
))))))
1211 (calendar-for-loop j from
1 to
3 do
1212 (insert "\\leftday")
1213 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1214 (cal-tex-arg (int-to-string (extract-calendar-day date
)))
1215 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1216 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1217 (cal-tex-arg (eval cal-tex-daily-string
))
1219 (setq date
(cal-tex-incr-date date
)))
1220 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1222 (insert "\\righthead")
1224 (let ((d (cal-tex-incr-date date
3)))
1225 (if (= (extract-calendar-month date
)
1226 (extract-calendar-month d
))
1229 (extract-calendar-month date
))
1230 (extract-calendar-year date
))
1231 (if (= (extract-calendar-year date
)
1232 (extract-calendar-year d
))
1233 (format "%s---%s %s"
1235 (extract-calendar-month date
))
1237 (extract-calendar-month d
))
1238 (extract-calendar-year date
))
1239 (format "%s %s---%s %s"
1241 (extract-calendar-month date
))
1242 (extract-calendar-year date
)
1243 (cal-tex-month-name (extract-calendar-month d
))
1244 (extract-calendar-year d
))))))
1246 (calendar-for-loop j from
1 to
2 do
1247 (insert "\\rightday")
1248 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1249 (cal-tex-arg (int-to-string (extract-calendar-day date
)))
1250 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1251 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1252 (cal-tex-arg (eval cal-tex-daily-string
))
1254 (setq date
(cal-tex-incr-date date
)))
1255 (calendar-for-loop j from
1 to
2 do
1256 (insert "\\weekend")
1257 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1258 (cal-tex-arg (int-to-string (extract-calendar-day date
)))
1259 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1260 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1261 (cal-tex-arg (eval cal-tex-daily-string
))
1263 (setq date
(cal-tex-incr-date date
)))
1266 (run-hooks 'cal-tex-week-hook
)
1267 (cal-tex-newpage))))
1268 (cal-tex-end-document)
1269 (run-hooks 'cal-tex-hook
)))
1271 (defun cal-tex-cursor-filofax-daily (&optional arg
)
1272 "Day-per-page Filofax style calendar for week indicated by cursor.
1273 Optional prefix argument specifies number of weeks (default 1),
1274 starting on Mondays. The calendar shows holiday and diary
1275 entries if `cal-tex-holidays' and `cal-tex-diary', respectively,
1276 are non-nil. Pages are ruled if `cal-tex-rules' is non-nil."
1278 (let* ((n (if arg arg
1))
1279 (date (calendar-gregorian-from-absolute
1280 (calendar-dayname-on-or-before
1282 (calendar-absolute-from-gregorian
1283 (calendar-cursor-to-date t
)))))
1284 (month (extract-calendar-month date
))
1285 (year (extract-calendar-year date
))
1286 (day (extract-calendar-day date
))
1287 (holidays (if cal-tex-holidays
1288 (cal-tex-list-holidays
1289 (calendar-absolute-from-gregorian date
)
1291 (calendar-absolute-from-gregorian date
)))))
1292 (diary-list (if cal-tex-diary
1293 (cal-tex-list-diary-entries
1294 (calendar-absolute-from-gregorian
1295 (list month
1 year
))
1297 (calendar-absolute-from-gregorian date
))))))
1298 (cal-tex-preamble "twoside")
1299 (cal-tex-cmd "\\textwidth 3.25in")
1300 (cal-tex-cmd "\\textheight 6.5in")
1301 (cal-tex-cmd "\\oddsidemargin 1.75in")
1302 (cal-tex-cmd "\\evensidemargin 1.5in")
1303 (cal-tex-cmd "\\topmargin 0pt")
1304 (cal-tex-cmd "\\headheight -0.875in")
1305 (cal-tex-cmd "\\headsep 0.125in")
1306 (cal-tex-cmd "\\footskip .125in")
1307 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1308 \\long\\def\\rightday#1#2#3{%
1309 \\rule{\\textwidth}{0.3pt}\\\\%
1310 \\hbox to \\textwidth{%
1313 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1314 \\hbox to \\textwidth{\\vbox {\\raggedleft \\em #2}}%
1315 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1316 \\long\\def\\weekend#1#2#3{%
1317 \\rule{\\textwidth}{0.3pt}\\\\%
1318 \\hbox to \\textwidth{%
1321 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1322 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1323 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1324 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1325 \\long\\def\\leftday#1#2#3{%
1326 \\rule{\\textwidth}{0.3pt}\\\\%
1327 \\hbox to \\textwidth{%
1330 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1331 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1332 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1334 \\setbox\\LineBox=\\hbox to\\textwidth{%
1335 \\vrule height.2in width0pt\\leaders\\hrule\\hfill}
1336 \\def\\linesfill{\\par\\leaders\\copy\\LineBox\\vfill}
1338 (cal-tex-b-document)
1339 (cal-tex-cmd "\\pagestyle{empty}")
1340 (calendar-for-loop i from
1 to n do
1341 (calendar-for-loop j from
1 to
5 do
1342 (let ((odd (/= 0 (% j
2))))
1343 (insert (if odd
"\\righthead" "\\lefthead"))
1344 (cal-tex-arg (calendar-date-string date
))
1346 (insert (if odd
"\\rightday" "\\leftday")))
1347 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1348 (cal-tex-arg (cal-tex-latexify-list holidays date
"\\\\" t
))
1349 (cal-tex-arg (eval cal-tex-daily-string
))
1352 (insert "\\linesfill\n")
1353 (insert "\\vfill\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1355 (setq date
(cal-tex-incr-date date
)))
1357 (calendar-for-loop j from
1 to
2 do
1358 (insert "\\lefthead")
1359 (cal-tex-arg (calendar-date-string date
))
1360 (insert "\\weekend")
1361 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1362 (cal-tex-arg (cal-tex-latexify-list holidays date
"\\\\" t
))
1363 (cal-tex-arg (eval cal-tex-daily-string
))
1366 (insert "\\linesfill\n")
1368 (setq date
(cal-tex-incr-date date
)))
1369 (if (not cal-tex-rules
)
1370 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1373 (run-hooks 'cal-tex-week-hook
)
1374 (cal-tex-newpage))))
1375 (cal-tex-end-document)
1376 (run-hooks 'cal-tex-hook
)))
1383 (defun cal-tex-cursor-day (&optional arg
)
1384 "Make a buffer with LaTeX commands for the day cursor is on.
1385 Optional prefix argument specifies number of days."
1387 (let ((n (if arg arg
1))
1388 (date (calendar-absolute-from-gregorian (calendar-cursor-to-date t
))))
1389 (cal-tex-preamble "12pt")
1390 (cal-tex-cmd "\\textwidth 6.5in")
1391 (cal-tex-cmd "\\textheight 10.5in")
1392 (cal-tex-b-document)
1393 (cal-tex-cmd "\\pagestyle{empty}")
1394 (calendar-for-loop i from
1 to n do
1395 (cal-tex-vspace "-1.7in")
1396 (cal-tex-daily-page (calendar-gregorian-from-absolute date
))
1397 (setq date
(1+ date
))
1401 (run-hooks 'cal-tex-daily-hook
))))
1402 (cal-tex-end-document)
1403 (run-hooks 'cal-tex-hook
)))
1405 (defun cal-tex-daily-page (date)
1406 "Make a calendar page for Gregorian DATE on 8.5 by 11 paper.
1407 Uses the 24-hour clock if `cal-tex-24' is non-nil. Produces
1408 hourly sections for the period specified by `cal-tex-daily-start'
1409 and `cal-tex-daily-end'."
1411 (month-name (cal-tex-month-name (extract-calendar-month date
))))
1412 (cal-tex-banner "cal-tex-daily-page")
1413 (cal-tex-b-makebox "4cm" "l")
1414 (cal-tex-b-parbox "b" "3.8cm")
1415 (cal-tex-rule "0mm" "0mm" "2cm")
1416 (cal-tex-Huge (number-to-string (extract-calendar-day date
)))
1418 (cal-tex-bf month-name
)
1420 (cal-tex-hspace "1cm")
1421 (cal-tex-scriptsize (eval cal-tex-daily-string
))
1422 (cal-tex-hspace "3.5cm")
1425 (cal-tex-b-makebox "4cm" "r")
1426 (cal-tex-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
1429 (cal-tex-hspace ".4cm")
1430 (cal-tex-rule "0mm" "16.1cm" "1mm")
1432 (calendar-for-loop i from cal-tex-daily-start to cal-tex-daily-end do
1433 (cal-tex-cmd "\\noindent")
1434 (setq hour
(if cal-tex-24
1437 (if (= 0 hour
) (setq hour
12))
1438 (cal-tex-b-makebox "1cm" "c")
1439 (cal-tex-arg (number-to-string hour
))
1441 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1443 (cal-tex-b-makebox "1cm" "c")
1444 (cal-tex-arg "$\\diamond$" )
1446 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1447 (cal-tex-nl ".2cm"))
1449 (insert (cal-tex-mini-calendar
1450 (extract-calendar-month (cal-tex-previous-month date
))
1451 (extract-calendar-year (cal-tex-previous-month date
))
1452 "lastmonth" "1.1in" "1in"))
1453 (insert (cal-tex-mini-calendar
1454 (extract-calendar-month date
)
1455 (extract-calendar-year date
)
1456 "thismonth" "1.1in" "1in"))
1457 (insert (cal-tex-mini-calendar
1458 (extract-calendar-month (cal-tex-next-month date
))
1459 (extract-calendar-year (cal-tex-next-month date
))
1460 "nextmonth" "1.1in" "1in"))
1461 (insert "\\hbox to \\textwidth{")
1463 (insert "\\lastmonth")
1465 (insert "\\thismonth")
1467 (insert "\\nextmonth")
1470 (cal-tex-banner "end of cal-tex-daily-page")))
1476 (defun cal-tex-mini-calendar (month year name width height
&optional ptsize colsep
)
1477 "Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT.
1478 Optional PTSIZE gives the point ptsize; scriptsize is the default. Optional
1479 COLSEP gives the column separation; 1mm is the default."
1480 (let* ((blank-days;; at start of month
1482 (- (calendar-day-of-week (list month
1 year
))
1483 calendar-week-start-day
)
1485 (last (calendar-last-day-of-month month year
))
1486 (colsep (if colsep colsep
"1mm"))
1487 (str (concat "\\def\\" name
"{\\hbox to" width
"{%\n"
1488 "\\vbox to" height
"{%\n"
1489 "\\vfil \\hbox to" width
"{%\n"
1491 (if ptsize ptsize
"scriptsize")
1493 "{@{\\hspace{0mm}}r@{\\hspace{" colsep
1494 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{" colsep
1495 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{" colsep
1496 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{0mm}}}%\n"
1497 "\\multicolumn{7}{c}{"
1498 (cal-tex-month-name month
)
1500 (int-to-string year
)
1502 (calendar-for-loop i from
0 to
6 do
1505 (cal-tex-LaTeXify-string
1506 (substring (aref calendar-day-name-array
1507 (mod (+ calendar-week-start-day i
) 7))
1512 (calendar-for-loop i from
1 to blank-days do
1513 (setq str
(concat str
" & ")))
1514 (calendar-for-loop i from
1 to last do
1515 (setq str
(concat str
(int-to-string i
)))
1516 (setq str
(concat str
(if (zerop (mod (+ i blank-days
) 7))
1517 (if (/= i last
) "\\\\[0.5mm]\n" "")
1519 (setq str
(concat str
"\n\\end{tabular}\\hfil}\\vfil}}}%\n"))
1523 ;;; Various calendar functions
1526 (defun cal-tex-incr-date (date &optional n
)
1527 "The date of the day following DATE.
1528 If optional N is given, the date of N days after DATE."
1529 (calendar-gregorian-from-absolute
1530 (+ (if n n
1) (calendar-absolute-from-gregorian date
))))
1532 (defun cal-tex-latexify-list (date-list date
&optional separator final-separator
)
1533 "Return string with concatenated, LaTeXified entries in DATE-LIST for DATE.
1534 Use double backslash as a separator unless optional SEPARATOR is given.
1535 If resulting string is not empty, put separator at end if optional
1536 FINAL-SEPARATOR is t."
1537 (let* ((sep (if separator separator
"\\\\"))
1539 (mapconcat '(lambda (x) (cal-tex-LaTeXify-string x
))
1544 (calendar-date-equal date
(car (car p
)))
1545 (setq result
(cons (car (cdr (car p
))) result
)))
1549 (if (and final-separator
(not (string-equal result
"")))
1553 (defun cal-tex-previous-month (date)
1554 "Return the date of the first day in the month previous to DATE."
1555 (let* ((month (extract-calendar-month date
))
1556 (year (extract-calendar-year date
)))
1557 (increment-calendar-month month year -
1)
1558 (list month
1 year
)))
1560 (defun cal-tex-next-month (date)
1561 "Return the date of the first day in the month following DATE."
1562 (let* ((month (extract-calendar-month date
))
1563 (year (extract-calendar-year date
)))
1564 (increment-calendar-month month year
1)
1565 (list month
1 year
)))
1571 (defun cal-tex-end-document ()
1572 "Finish the LaTeX document.
1573 Insert the trailer to LaTeX document, pop to LaTeX buffer, add
1574 informative header, and run HOOK."
1575 (cal-tex-e-document)
1577 (pop-to-buffer cal-tex-buffer
)
1578 (goto-char (point-min))
1579 (cal-tex-comment " This buffer was produced by cal-tex.el.")
1580 (cal-tex-comment " To print a calendar, type")
1581 (cal-tex-comment " M-x tex-buffer RET")
1582 (cal-tex-comment " M-x tex-print RET")
1583 (goto-char (point-min)))
1585 (defun cal-tex-insert-preamble (weeks landscape size
&optional append
)
1586 "Initialize the output buffer.
1587 Select the output buffer, and insert the preamble for a calendar of
1588 WEEKS weeks. Insert code for landscape mode if LANDSCAPE is true.
1589 Use pointsize SIZE. Optional argument APPEND, if t, means add to end of
1590 without erasing current contents."
1591 (let ((width "18cm")
1596 (setq height
"18cm")))
1599 (cal-tex-preamble size
)
1602 (cal-tex-cmd "\\oddsidemargin -1.75cm")
1603 (cal-tex-cmd "\\def\\holidaymult{.06}"))
1604 (cal-tex-cmd "\\special{landscape}")
1605 (cal-tex-cmd "\\textwidth 9.5in")
1606 (cal-tex-cmd "\\textheight 7in")
1608 (cal-tex-cmd "\\def\\holidaymult{.08}"))
1609 (cal-tex-cmd cal-tex-caldate
)
1610 (cal-tex-cmd cal-tex-myday
)
1611 (cal-tex-b-document)
1612 (cal-tex-cmd "\\pagestyle{empty}")))
1613 (cal-tex-cmd "\\setlength{\\cellwidth}" width
)
1614 (insert (format "\\setlength{\\cellwidth}{%f\\cellwidth}\n"
1615 (/ 1.1 (length cal-tex-which-days
))))
1616 (cal-tex-cmd "\\setlength{\\cellheight}" height
)
1617 (insert (format "\\setlength{\\cellheight}{%f\\cellheight}\n"
1619 (cal-tex-cmd "\\ \\par")
1620 (cal-tex-vspace "-3cm")))
1622 (defvar cal-tex-LaTeX-subst-list
1624 ("\"".
"''");; Quote changes meaning when list is reversed.
1635 ("\n" .
"\\ \\\\")) ;\\ needed for e.g \begin{center}\n AA\end{center}
1636 "List of symbols and their replacements.")
1638 (defun cal-tex-LaTeXify-string (string)
1639 "Protect special characters in STRING from LaTeX."
1644 (list cal-tex-LaTeX-subst-list
))
1645 (while (not (string-equal tail
""))
1646 (let* ((ch (substring tail
0 1))
1647 (pair (assoc ch list
)))
1648 (if (and pair
(string-equal ch
"\""))
1649 (setq list
(reverse list
)));; Quote changes meaning each time.
1650 (setq tail
(substring tail
1))
1651 (setq head
(concat head
(if pair
(cdr pair
) ch
)))))
1654 (defun cal-tex-month-name (month)
1655 "The name of MONTH, LaTeXified."
1656 (cal-tex-LaTeXify-string (calendar-month-name month
)))
1658 (defun cal-tex-hfill () "Insert hfill." (insert "\\hfill"))
1660 (defun cal-tex-newpage () "Insert newpage." (insert "\\newpage%\n"))
1662 (defun cal-tex-noindent () "Insert noindent." (insert "\\noindent"))
1664 (defun cal-tex-vspace (space)
1665 "Insert vspace command to move SPACE vertically."
1666 (insert "\\vspace*{" space
"}")
1669 (defun cal-tex-hspace (space)
1670 "Insert hspace command to move SPACE horizontally."
1671 (insert "\\hspace*{" space
"}")
1674 (defun cal-tex-comment (&optional comment
)
1675 "Insert % at end of line, include COMMENT if present, and move
1682 (defun cal-tex-banner (comment)
1683 "Insert the COMMENT separated by blank lines."
1686 (cal-tex-comment (concat "\t\t\t" comment
))
1690 (defun cal-tex-nl (&optional skip comment
)
1691 "End a line with \\. If SKIP, then add that much spacing.
1692 Add COMMENT if present"
1695 (insert "[" skip
"]"))
1696 (cal-tex-comment comment
))
1698 (defun cal-tex-arg (&optional text
)
1699 "Insert optional TEXT surrounded by braces."
1701 (if text
(insert text
))
1704 (defun cal-tex-cmd (cmd &optional arg
)
1705 "Insert LaTeX CMD, with optional ARG, and end with %"
1714 (defun cal-tex-b-document ()
1715 "Insert beginning of document."
1716 (cal-tex-cmd "\\begin{document}"))
1718 (defun cal-tex-e-document ()
1719 "Insert end of document."
1720 (cal-tex-cmd "\\end{document}"))
1722 (defun cal-tex-b-center ()
1723 "Insert beginning of centered block."
1724 (cal-tex-cmd "\\begin{center}"))
1726 (defun cal-tex-e-center ()
1727 "Insert end of centered block."
1729 (cal-tex-cmd "\\end{center}"))
1737 (defun cal-tex-b-parbox (position width
)
1738 "Insert parbox with parameters POSITION and WIDTH."
1739 (insert "\\parbox[" position
"]{" width
"}{")
1742 (defun cal-tex-e-parbox (&optional height
)
1743 "Insert end of parbox. Force it to be a given HEIGHT."
1746 (cal-tex-rule "0mm" "0mm" height
))
1748 (cal-tex-comment "end parbox"))
1750 (defun cal-tex-b-framebox ( width position
)
1751 "Insert framebox with parameters WIDTH and POSITION (clr)."
1752 (insert "\\framebox[" width
"][" position
"]{" )
1755 (defun cal-tex-e-framebox ()
1756 "Insert end of framebox."
1759 (cal-tex-comment "end framebox"))
1762 (defun cal-tex-b-makebox ( width position
)
1763 "Insert makebox with parameters WIDTH and POSITION (clr)."
1764 (insert "\\makebox[" width
"][" position
"]{" )
1767 (defun cal-tex-e-makebox ()
1768 "Insert end of makebox."
1771 (cal-tex-comment "end makebox"))
1774 (defun cal-tex-rule (lower width height
)
1775 "Insert a rule with parameters LOWER WIDTH HEIGHT."
1776 (insert "\\rule[" lower
"]{" width
"}{" height
"}"))
1782 (defun cal-tex-em (string)
1783 "Insert STRING in bf font."
1784 (insert "{\\em " string
"}"))
1786 (defun cal-tex-bf (string)
1787 "Insert STRING in bf font."
1788 (insert "{\\bf " string
"}"))
1790 (defun cal-tex-scriptsize (string)
1791 "Insert STRING in scriptsize font."
1792 (insert "{\\scriptsize " string
"}"))
1794 (defun cal-tex-huge (string)
1795 "Insert STRING in huge size."
1796 (insert "{\\huge " string
"}"))
1798 (defun cal-tex-Huge (string)
1799 "Insert STRING in Huge size."
1800 (insert "{\\Huge " string
"}"))
1802 (defun cal-tex-Huge-bf (string)
1803 "Insert STRING in Huge bf size."
1804 (insert "{\\Huge\\bf " string
"}"))
1806 (defun cal-tex-large (string)
1807 "Insert STRING in large size."
1808 (insert "{\\large " string
"}"))
1810 (defun cal-tex-large-bf (string)
1811 "Insert STRING in large bf size."
1812 (insert "{\\large\\bf " string
"}"))
1816 ;;; arch-tag: ca8168a4-5a00-4508-a565-17e3bccce6d0
1817 ;;; cal-tex.el ends here