1 ;;; cal-tex.el --- calendar functions for printing calendars with LaTeX
3 ;; Copyright (C) 1995, 2001-2011 Free Software Foundation, Inc.
5 ;; Author: Steve Fisk <fisk@bowdoin.edu>
6 ;; Edward M. Reingold <reingold@cs.uiuc.edu>
7 ;; Maintainer: Glenn Morris <rgm@gnu.org>
9 ;; 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 of the License, or
17 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
29 ;; This collection of functions implements the creation of LaTeX calendars
30 ;; based on the user's holiday choices and diary file.
32 ;; The user commands are:
33 ;; cal-tex-cursor-year
34 ;; cal-tex-cursor-year-landscape
35 ;; cal-tex-cursor-filofax-year
36 ;; cal-tex-cursor-month-landscape
37 ;; cal-tex-cursor-month
38 ;; cal-tex-cursor-week
39 ;; cal-tex-cursor-week2
40 ;; cal-tex-cursor-week-iso
41 ;; cal-tex-cursor-week-monday
42 ;; cal-tex-cursor-filofax-2week
43 ;; cal-tex-cursor-filofax-week
44 ;; cal-tex-cursor-filofax-daily
49 ;; (*) Add holidays and diary entries to daily calendar.
51 ;; (*) Add diary entries to weekly calendar functions.
53 ;; (*) Make calendar styles for A4 paper.
55 ;; (*) Make monthly styles Filofax paper.
62 ;;; Customizable variables
65 (defgroup calendar-tex nil
66 "Options for printing calendar with LaTeX."
70 (defcustom cal-tex-which-days
'(0 1 2 3 4 5 6)
71 "The days of the week that are displayed on the portrait monthly calendar.
72 Sunday is 0, Monday is 1, and so on. The default is to print from Sunday to
73 Saturday. For example, use '(1 3 5) to only print Monday, Wednesday, Friday."
74 :type
'(repeat integer
)
77 (defcustom cal-tex-holidays t
78 "Non-nil means holidays are printed in the LaTeX calendars that support it.
79 Setting this to nil may speed up calendar generation."
83 (defcustom cal-tex-diary nil
84 "Non-nil means diary entries are printed in LaTeX calendars that support it.
85 At present, this only affects the monthly, filofax, and iso-week
86 calendars (i.e. not the yearly, plain weekly, or daily calendars).
87 Setting this to nil may speed up calendar generation."
91 (defcustom cal-tex-rules nil
92 "Non-nil means pages will be ruled in some LaTeX calendar styles.
93 At present, this only affects the daily filofax calendar."
97 (defcustom cal-tex-daily-string
98 '(let* ((year (calendar-extract-year date
))
99 (day (calendar-day-number date
))
100 (days-remaining (- (calendar-day-number (list 12 31 year
)) day
)))
101 (format "%d/%d" day days-remaining
))
102 "Lisp expression giving the date format to use in the LaTeX calendars.
103 This should be an expression involving the variable `date'. When
104 this expression is called, `date' is a list of the form '(MONTH DAY YEAR)'.
106 The string resulting from evaluating this expression is placed at
107 the bottom center of each date in monthly calendars, next to the
108 date in the weekly calendars, and in the top center of daily calendars.
110 The default is ordinal day number of the year and the number of
111 days remaining. As an example, setting this to
113 '(calendar-hebrew-date-string date)
115 will put the Hebrew date at the bottom of each day."
117 :group
'calendar-tex
)
119 (defcustom cal-tex-buffer
"calendar.tex"
120 "The name for the output LaTeX calendar buffer."
122 :group
'calendar-tex
)
124 (defcustom cal-tex-24 nil
125 "Non-nil means use a 24 hour clock in the daily calendar."
127 :group
'calendar-tex
)
129 (defcustom cal-tex-daily-start
8
130 "The first hour of the daily LaTeX calendar page.
131 At present, this only affects `cal-tex-cursor-day'."
133 :group
'calendar-tex
)
135 (defcustom cal-tex-daily-end
20
136 "The last hour of the daily LaTeX calendar page.
137 At present, this only affects `cal-tex-cursor-day'."
139 :group
'calendar-tex
)
141 (defcustom cal-tex-preamble-extra nil
142 "A string giving extra LaTeX commands to insert in the calendar preamble.
143 For example, to include extra packages:
144 \"\\\\usepackage{foo}\\n\\\\usepackage{bar}\\n\"."
145 :type
'(choice (const nil
)
146 ;; An example to help people format things in custom.
147 (string :value
"\\usepackage{foo}\n\\usepackage{bar}\n"))
151 (defcustom cal-tex-hook nil
152 "List of functions called after any LaTeX calendar buffer is generated.
153 You can use this to do post-processing on the buffer. For example, to change
154 characters with diacritical marks to their LaTeX equivalents, use
155 (add-hook 'cal-tex-hook
156 (lambda () (iso-iso2tex (point-min) (point-max))))"
158 :group
'calendar-tex
)
160 (defcustom cal-tex-year-hook nil
161 "List of functions called after a LaTeX year calendar buffer is generated."
163 :group
'calendar-tex
)
165 (defcustom cal-tex-month-hook nil
166 "List of functions called after a LaTeX month calendar buffer is generated."
168 :group
'calendar-tex
)
170 (defcustom cal-tex-week-hook nil
171 "List of functions called after a LaTeX week calendar buffer is generated."
173 :group
'calendar-tex
)
175 (defcustom cal-tex-daily-hook nil
176 "List of functions called after a LaTeX daily calendar buffer is generated."
178 :group
'calendar-tex
)
181 ;;; Definitions for LaTeX code
184 (defconst cal-tex-day-prefix
"\\caldate{%s}{%s}"
185 "The initial LaTeX code for a day.
186 The holidays, diary entries, bottom string, and the text follow.")
188 (defconst cal-tex-day-name-format
"\\myday{%s}%%"
189 "The format for LaTeX code for a day name.
190 The names are taken from `calendar-day-name-array'.")
192 (defconst cal-tex-cal-one-month
193 "\\def\\calmonth#1#2%
195 \\Huge\\bf\\uppercase{#1} #2 \\\\[1cm]%
200 "LaTeX code for the month header, for a single month calendar.")
202 (defconst cal-tex-cal-multi-month
203 "\\def\\calmonth#1#2#3#4%
205 \\Huge\\bf #1 #2---#3 #4\\\\[1cm]%
210 "LaTeX code for the month header, for a multi-month calendar.")
212 (defconst cal-tex-myday
213 "\\renewcommand{\\myday}[1]%
214 {\\makebox[\\cellwidth]{\\hfill\\large\\bf#1\\hfill}}
217 "LaTeX code for a day heading.")
219 (defconst cal-tex-caldate
221 \\long\\def\\caldate#1#2#3#4#5#6{%
222 \\fbox{\\hbox to\\cellwidth{%
223 \\vbox to\\cellheight{%
224 \\hbox to\\cellwidth{%
225 {\\hspace*{1mm}\\Large \\bf \\strut #2}\\hspace{.05\\cellwidth}%
226 \\raisebox{\\holidaymult\\cellheight}%
227 {\\parbox[t]{.75\\cellwidth}{\\tiny \\raggedright #4}}}
228 \\hbox to\\cellwidth{%
229 \\hspace*{1mm}\\parbox{.95\\cellwidth}{\\tiny \\raggedright #3}}
231 \\hbox to\\cellwidth{#6}%
233 \\hbox to\\cellwidth{\\hfill \\tiny #5 \\hfill}%
237 "LaTeX code to insert one box with date info in calendar.
238 This definition is the heart of the calendar!")
240 (autoload 'calendar-holiday-list
"holidays")
242 (defun cal-tex-list-holidays (d1 d2
)
243 "Generate a list of all holidays from absolute date D1 to D2."
244 (let* ((start (calendar-gregorian-from-absolute d1
))
245 (displayed-month (calendar-extract-month start
))
246 (displayed-year (calendar-extract-year start
))
247 (end (calendar-gregorian-from-absolute d2
))
248 (end-month (calendar-extract-month end
))
249 (end-year (calendar-extract-year end
))
251 (1+ (/ (calendar-interval displayed-month displayed-year
255 (calendar-increment-month displayed-month displayed-year
1)
256 (dotimes (_idummy number-of-intervals
)
257 (setq holidays
(append holidays
(calendar-holiday-list)))
258 (calendar-increment-month displayed-month displayed-year
3))
259 (dolist (hol holidays
)
261 (setq a
(calendar-absolute-from-gregorian (car hol
)))
262 (and (<= d1 a
) (<= a d2
))
263 (setq in-range
(append (list hol
) in-range
))))
266 (autoload 'diary-list-entries
"diary-lib")
268 (defun cal-tex-list-diary-entries (d1 d2
)
269 "Generate a list of all diary-entries from absolute date D1 to D2."
270 (let (diary-list-include-blanks)
271 (diary-list-entries (calendar-gregorian-from-absolute d1
)
274 (defun cal-tex-preamble (&optional args
)
275 "Insert the LaTeX calendar preamble into `cal-tex-buffer'.
276 Preamble includes initial definitions for various LaTeX commands.
277 Optional string ARGS are included as options for the article document class."
278 ;; FIXME use generate-new-buffer, and adjust cal-tex-end-document.
279 (set-buffer (get-buffer-create cal-tex-buffer
))
280 (insert (format "\\documentclass%s{article}\n"
284 (if (stringp cal-tex-preamble-extra
)
285 (insert cal-tex-preamble-extra
"\n"))
286 (insert "\\hbadness 20000
292 \\evensidemargin -2cm
297 \\newlength{\\cellwidth}
298 \\newlength{\\cellheight}
299 \\newlength{\\boxwidth}
300 \\newlength{\\boxheight}
301 \\newlength{\\cellsize}
302 \\newcommand{\\myday}[1]{}
303 \\newcommand{\\caldate}[6]{}
304 \\newcommand{\\nocaldate}[6]{}
305 \\newcommand{\\calsmall}[6]{}
314 (defun cal-tex-cursor-year (&optional n event
)
315 "Make a buffer with LaTeX commands for the year cursor is on.
316 Optional prefix argument N specifies number of years.
317 Optional EVENT indicates a buffer position to use instead of point."
318 (interactive (list (prefix-numeric-value current-prefix-arg
)
320 (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t event
))
324 (defun cal-tex-cursor-year-landscape (&optional n event
)
325 "Make a buffer with LaTeX commands for the year cursor is on.
326 Optional prefix argument N specifies number of years.
327 Optional EVENT indicates a buffer position to use instead of point."
328 (interactive (list (prefix-numeric-value current-prefix-arg
)
330 (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t event
))
333 (defun cal-tex-year (year n
&optional landscape
)
334 "Make a one page yearly calendar of YEAR; do this for N years.
335 There are four rows of three months each, unless optional
336 LANDSCAPE is non-nil, in which case the calendar is printed in
337 landscape mode with three rows of four months each."
338 (cal-tex-insert-preamble 1 landscape
"12pt")
340 (cal-tex-vspace "-.6cm")
341 (cal-tex-vspace "-3.1cm"))
343 (insert "\\vfill%\n")
345 (cal-tex-Huge (number-to-string year
))
347 (cal-tex-vspace "1cm")
349 (cal-tex-b-parbox "l" (if landscape
"5.9in" "4.3in"))
354 (insert (cal-tex-mini-calendar (1+ i
) year
"month" "1.1in" "1in"))
356 (cal-tex-hspace "0.5in")
357 (if (zerop (mod (1+ i
) (if landscape
4 3)))
358 (cal-tex-nl "0.5in")))
361 (insert "\\vfill%\n")
362 (setq year
(1+ year
))
364 (cal-tex-end-document)
366 (run-hooks 'cal-tex-year-hook
))
367 (run-hooks 'cal-tex-hook
))
370 (defun cal-tex-cursor-filofax-year (&optional n event
)
371 "Make a Filofax one page yearly calendar of year indicated by cursor.
372 Optional prefix argument N specifies number of years.
373 Optional EVENT indicates a buffer position to use instead of point."
374 (interactive (list (prefix-numeric-value current-prefix-arg
)
377 (let ((year (calendar-extract-year (calendar-cursor-to-date t event
))))
378 (cal-tex-preamble "twoside")
379 (cal-tex-cmd "\\textwidth 3.25in")
380 (cal-tex-cmd "\\textheight 6.5in")
381 (cal-tex-cmd "\\oddsidemargin 1.675in")
382 (cal-tex-cmd "\\evensidemargin 1.675in")
383 (cal-tex-cmd "\\topmargin 0pt")
384 (cal-tex-cmd "\\headheight -0.875in")
385 (cal-tex-cmd "\\fboxsep 0.5mm")
386 (cal-tex-cmd "\\pagestyle{empty}")
388 (cal-tex-cmd "\\vspace*{0.25in}")
390 (insert (format "\\hfil \\textbf{\\Large %s} \\hfil\\\\\n" year
))
392 (cal-tex-b-parbox "l" "\\textwidth")
396 (let ((month-names; don't use default in case user changed it
397 ;; These are only used to define the command names, not
398 ;; the names of the months they insert.
399 ["January" "February" "March" "April" "May" "June"
400 "July" "August" "September" "October" "November" "December"]))
402 (insert (cal-tex-mini-calendar (1+ i
) year
(aref month-names i
)
403 "1in" ".9in" "tiny" "0.6mm"))))
405 "\\noindent\\fbox{\\January}\\fbox{\\February}\\fbox{\\March}\\\\
406 \\noindent\\fbox{\\April}\\fbox{\\May}\\fbox{\\June}\\\\
407 \\noindent\\fbox{\\July}\\fbox{\\August}\\fbox{\\September}\\\\
408 \\noindent\\fbox{\\October}\\fbox{\\November}\\fbox{\\December}
412 (setq year
(1+ year
))
414 (cal-tex-end-document)
416 (cal-tex-cmd "\\vspace*{0.25in}"))
417 (run-hooks 'cal-tex-year-hook
))
418 (run-hooks 'cal-tex-hook
)))
421 ;;; Monthly calendars
425 (defun cal-tex-cursor-month-landscape (&optional n event
)
426 "Make a LaTeX calendar buffer for the month the cursor is on.
427 Optional prefix argument N specifies number of months to be
428 produced (default 1). The output is in landscape format, one
429 month to a page. It shows holiday and diary entries if
430 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
431 Optional EVENT indicates a buffer position to use instead of point."
432 (interactive (list (prefix-numeric-value current-prefix-arg
)
435 (let* ((date (calendar-cursor-to-date t event
))
436 (month (calendar-extract-month date
))
437 (year (calendar-extract-year date
))
440 (cal-tex-which-days '(0 1 2 3 4 5 6))
441 (d1 (calendar-absolute-from-gregorian (list month
1 year
)))
443 (calendar-increment-month end-month end-year
(1- n
))
444 (calendar-absolute-from-gregorian
446 (calendar-last-day-of-month end-month end-year
)
448 (diary-list (if cal-tex-diary
(cal-tex-list-diary-entries d1 d2
)))
449 (holidays (if cal-tex-holidays
(cal-tex-list-holidays d1 d2
)))
450 other-month other-year small-months-at-start
)
451 (cal-tex-insert-preamble (cal-tex-number-weeks month year
1) t
"12pt")
452 (cal-tex-cmd cal-tex-cal-one-month
)
454 (setq other-month month
456 (calendar-increment-month other-month other-year -
1)
457 (insert (cal-tex-mini-calendar other-month other-year
"lastmonth"
458 "\\cellwidth" "\\cellheight"))
459 (calendar-increment-month other-month other-year
2)
460 (insert (cal-tex-mini-calendar other-month other-year
"nextmonth"
461 "\\cellwidth" "\\cellheight"))
462 (cal-tex-insert-month-header 1 month year month year
)
463 (cal-tex-insert-day-names)
465 (if (setq small-months-at-start
466 (< 1 (mod (- (calendar-day-of-week (list month
1 year
))
467 calendar-week-start-day
)
469 (insert "\\lastmonth\\nextmonth\\hspace*{-2\\cellwidth}"))
470 (cal-tex-insert-blank-days month year cal-tex-day-prefix
)
471 (cal-tex-insert-days month year diary-list holidays
473 (cal-tex-insert-blank-days-at-end month year cal-tex-day-prefix
)
474 (if (and (not small-months-at-start
)
475 (< 1 (mod (- (1- calendar-week-start-day
)
476 (calendar-day-of-week
478 (calendar-last-day-of-month month year
)
481 (insert "\\vspace*{-\\cellwidth}\\hspace*{-2\\cellwidth}"
482 "\\lastmonth\\nextmonth%
485 (run-hooks 'cal-tex-month-hook
)
487 (calendar-increment-month month year
1)
488 (cal-tex-vspace "-2cm")
489 (cal-tex-insert-preamble
490 (cal-tex-number-weeks month year
1) t
"12pt" t
))))
491 (cal-tex-end-document)
492 (run-hooks 'cal-tex-hook
))
495 (defun cal-tex-cursor-month (&optional n event
)
496 "Make a LaTeX calendar buffer for the month the cursor is on.
497 Optional prefix argument N specifies number of months to be
498 produced (default 1). The calendar is condensed onto one page.
499 It shows holiday and diary entries if `cal-tex-holidays' and
500 `cal-tex-diary', respectively, are non-nil. Optional EVENT
501 indicates a buffer position to use instead of point."
502 (interactive (list (prefix-numeric-value current-prefix-arg
)
505 (let* ((date (calendar-cursor-to-date t event
))
506 (month (calendar-extract-month date
))
507 (year (calendar-extract-year date
))
510 ;; FIXME -landscape sets cal-tex-which-days?
511 (d1 (calendar-absolute-from-gregorian (list month
1 year
)))
513 (calendar-increment-month end-month end-year
(1- n
))
514 (calendar-absolute-from-gregorian
516 (calendar-last-day-of-month end-month end-year
)
518 (diary-list (if cal-tex-diary
(cal-tex-list-diary-entries d1 d2
)))
519 (holidays (if cal-tex-holidays
(cal-tex-list-holidays d1 d2
))))
520 (cal-tex-insert-preamble (cal-tex-number-weeks month year n
) nil
"12pt")
522 (cal-tex-cmd cal-tex-cal-multi-month
)
523 (cal-tex-cmd cal-tex-cal-one-month
))
524 (cal-tex-insert-month-header n month year end-month end-year
)
525 (cal-tex-insert-day-names)
527 (cal-tex-insert-blank-days month year cal-tex-day-prefix
)
529 (cal-tex-insert-days month year diary-list holidays cal-tex-day-prefix
)
530 (when (= (calendar-week-end-day)
531 (calendar-day-of-week
533 (calendar-last-day-of-month month year
)
534 year
))) ; last day of month was last day of week
537 (calendar-increment-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
)
552 (last (calendar-last-day-of-month month year
))
555 (setq j
(1+ i
) ; 1-last, incl
556 date
(list month j year
))
557 (when (memq (calendar-day-of-week date
) cal-tex-which-days
)
558 (insert (format day-format
(cal-tex-month-name month
) j
))
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 (when (and (zerop (mod (+ j blank-days
) 7))
569 (defun cal-tex-insert-day-names ()
570 "Insert the names of the days at top of a monthly calendar."
573 (if (memq (setq j
(mod (+ calendar-week-start-day i
) 7))
575 (insert (format cal-tex-day-name-format
576 (cal-tex-LaTeXify-string
577 (aref calendar-day-name-array j
)))))
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 (dotimes (i blank-days
)
605 (if (memq (mod (+ calendar-week-start-day i
) 7) 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
)
620 (while (<= (setq i
(1+ i
)) 6)
621 (if (memq (mod (+ calendar-week-start-day i
) 7) cal-tex-which-days
)
622 (insert (format day-format
"" "") "{}{}{}{}%\n"))))))
624 (defun cal-tex-first-blank-p (month year
)
625 "Determine if any days of the first week will be printed.
626 Return t if there will there be any days of the first week printed
627 in the calendar starting in MONTH YEAR."
628 ;; Check days 1-7 of the month, until we find the last day of the week.
632 (if (memq (setq dow
(calendar-day-of-week (list month
(1+ i
) year
)))
635 (if (= dow
(calendar-week-end-day)) (throw 'found nil
)))))))
637 (defun cal-tex-last-blank-p (month year
)
638 "Determine if any days of the last week will be printed.
639 Return t if there will there be any days of the last week printed
640 in the calendar starting in MONTH YEAR."
641 ;; Check backwards from the last day of the month, until we find the
642 ;; start of the last week in the month.
644 (let ((last-day (calendar-last-day-of-month month year
))
647 (if (memq (setq dow
(calendar-day-of-week
648 (list month
(- last-day i
) year
)))
651 (if (= dow calendar-week-start-day
) (throw 'found nil
)))))))
653 (defun cal-tex-number-weeks (month year n
)
654 "Determine the number of weeks in a range of dates.
655 Compute the number of weeks in the calendar starting with MONTH and YEAR,
656 and lasting N months, including only the days in WHICH-DAYS. As it stands,
657 this is only an upper bound."
658 (let ((d (list month
1 year
)))
659 (calendar-increment-month month year
(1- n
))
660 (/ (- (calendar-dayname-on-or-before
661 calendar-week-start-day
662 (+ 7 (calendar-absolute-from-gregorian
663 (list month
(calendar-last-day-of-month month year
) year
))))
664 (calendar-dayname-on-or-before
665 calendar-week-start-day
666 (calendar-absolute-from-gregorian d
)))
673 (defconst cal-tex-LaTeX-hourbox
674 "\\newcommand{\\hourbox}[2]%
675 {\\makebox[2em]{\\rule{0cm}{#2ex}#1}\\rule{3in}{.15mm}}\n"
676 "One hour and a line on the right.")
678 ;; TODO cal-tex-diary-support.
679 ;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
681 (defun cal-tex-cursor-week (&optional n event
)
682 "Make a LaTeX calendar buffer for a two-page one-week calendar.
683 It applies to the week that point is in. The optional prefix
684 argument N specifies number of weeks (default 1). The calendar
685 shows holidays if `cal-tex-holidays' is non-nil (note that diary
686 entries are not shown). The calendar shows the hours 8-12am, 1-5pm."
687 (interactive (list (prefix-numeric-value current-prefix-arg
)
690 (let* ((date (calendar-gregorian-from-absolute
691 (calendar-dayname-on-or-before
692 calendar-week-start-day
693 (calendar-absolute-from-gregorian
694 (calendar-cursor-to-date t event
)))))
695 (month (calendar-extract-month date
))
696 (year (calendar-extract-year date
))
697 (d1 (calendar-absolute-from-gregorian date
))
699 (holidays (if cal-tex-holidays
700 (cal-tex-list-holidays d1 d2
))))
701 (cal-tex-preamble "11pt")
702 (cal-tex-cmd "\\textwidth 6.5in")
703 (cal-tex-cmd "\\textheight 10.5in")
704 (cal-tex-cmd "\\oddsidemargin 0in")
705 (cal-tex-cmd "\\evensidemargin 0in")
706 (insert cal-tex-LaTeX-hourbox
)
708 (cal-tex-cmd "\\pagestyle{empty}")
710 (cal-tex-vspace "-1.5in")
712 (cal-tex-Huge-bf (format "\\uppercase{%s}"
713 (cal-tex-month-name month
)))
714 (cal-tex-hspace "2em")
715 (cal-tex-Huge-bf (number-to-string year
))
718 (cal-tex-hspace "-.2in")
719 (cal-tex-b-parbox "l" "7in")
721 (cal-tex-week-hours date holidays
"3.1")
722 (setq date
(cal-tex-incr-date date
)))
724 (setq month
(calendar-extract-month date
)
725 year
(calendar-extract-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 ;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
735 (defun cal-tex-cursor-week2 (&optional n event
)
736 "Make a LaTeX calendar buffer for a two-page one-week calendar.
737 It applies to the week that point is in. Optional prefix
738 argument N specifies number of weeks (default 1). The calendar
739 shows holidays if `cal-tex-holidays' is non-nil (note that diary
740 entries are not shown). The calendar shows the hours 8-12am, 1-5pm.
741 Optional EVENT indicates a buffer position to use instead of point."
742 (interactive (list (prefix-numeric-value current-prefix-arg
)
745 (let* ((date (calendar-gregorian-from-absolute
746 (calendar-dayname-on-or-before
747 calendar-week-start-day
748 (calendar-absolute-from-gregorian
749 (calendar-cursor-to-date t event
)))))
750 (month (calendar-extract-month date
))
751 (year (calendar-extract-year date
))
752 (d1 (calendar-absolute-from-gregorian date
))
754 (holidays (if cal-tex-holidays
755 (cal-tex-list-holidays d1 d2
))))
756 (cal-tex-preamble "12pt")
757 (cal-tex-cmd "\\textwidth 6.5in")
758 (cal-tex-cmd "\\textheight 10.5in")
759 (cal-tex-cmd "\\oddsidemargin 0in")
760 (cal-tex-cmd "\\evensidemargin 0in")
761 (insert cal-tex-LaTeX-hourbox
)
763 (cal-tex-cmd "\\pagestyle{empty}")
765 (cal-tex-vspace "-1.5in")
767 (cal-tex-Huge-bf (format "\\uppercase{%s}"
768 (cal-tex-month-name month
)))
769 (cal-tex-hspace "2em")
770 (cal-tex-Huge-bf (number-to-string year
))
773 (cal-tex-hspace "-.2in")
774 (cal-tex-b-parbox "l" "\\textwidth")
776 (cal-tex-week-hours date holidays
"5")
777 (setq date
(cal-tex-incr-date date
)))
780 (insert (cal-tex-mini-calendar
781 (calendar-extract-month (cal-tex-previous-month date
))
782 (calendar-extract-year (cal-tex-previous-month date
))
783 "lastmonth" "1.1in" "1in"))
784 (insert (cal-tex-mini-calendar
785 (calendar-extract-month date
)
786 (calendar-extract-year date
)
787 "thismonth" "1.1in" "1in"))
788 (insert (cal-tex-mini-calendar
789 (calendar-extract-month (cal-tex-next-month date
))
790 (calendar-extract-year (cal-tex-next-month date
))
791 "nextmonth" "1.1in" "1in"))
792 (insert "\\hbox to \\textwidth{")
794 (insert "\\lastmonth")
796 (insert "\\thismonth")
798 (insert "\\nextmonth")
802 (cal-tex-b-parbox "l" "\\textwidth")
804 (cal-tex-week-hours date holidays
"5")
805 (setq date
(cal-tex-incr-date date
)))
807 (setq month
(calendar-extract-month date
)
808 year
(calendar-extract-year date
))
810 (run-hooks 'cal-tex-week-hook
)
812 (cal-tex-end-document)
813 (run-hooks 'cal-tex-hook
)))
815 (autoload 'calendar-iso-from-absolute
"cal-iso")
818 (defun cal-tex-cursor-week-iso (&optional n event
)
819 "Make a LaTeX calendar buffer for a one page ISO-style weekly calendar.
820 Optional prefix argument N specifies number of weeks (default 1).
821 The calendar shows holiday and diary entries if
822 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
823 It does not show hours of the day. Optional EVENT indicates a buffer
824 position to use instead of point."
825 (interactive (list (prefix-numeric-value current-prefix-arg
)
828 (let* ((date (calendar-gregorian-from-absolute
829 (calendar-dayname-on-or-before
831 (calendar-absolute-from-gregorian
832 (calendar-cursor-to-date t event
)))))
833 (month (calendar-extract-month date
))
834 (year (calendar-extract-year date
))
835 (day (calendar-extract-day date
))
836 (d1 (calendar-absolute-from-gregorian date
))
838 (holidays (if cal-tex-holidays
839 (cal-tex-list-holidays d1 d2
)))
840 (diary-list (if cal-tex-diary
841 (cal-tex-list-diary-entries
843 (calendar-absolute-from-gregorian (list month
1 year
))
846 (cal-tex-preamble "11pt")
847 (cal-tex-cmd "\\textwidth 6.5in")
848 (cal-tex-cmd "\\textheight 10.5in")
849 (cal-tex-cmd "\\oddsidemargin 0in")
850 (cal-tex-cmd "\\evensidemargin 0in")
852 (cal-tex-cmd "\\pagestyle{empty}")
854 (cal-tex-vspace "-1.5in")
857 (let ((d (calendar-iso-from-absolute
858 (calendar-absolute-from-gregorian date
))))
859 (format "Week %d of %d"
860 (calendar-extract-month d
)
861 (calendar-extract-year d
))))
864 (cal-tex-b-parbox "l" "\\textwidth")
866 (cal-tex-b-parbox "t" "\\textwidth")
867 (cal-tex-b-parbox "t" "\\textwidth")
868 (cal-tex-rule "0pt" "\\textwidth" ".2mm")
870 (cal-tex-b-parbox "t" "\\textwidth")
871 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
873 (cal-tex-large-bf (cal-tex-month-name month
))
875 (cal-tex-large-bf (number-to-string day
))
876 (unless (string-equal "" (setq s
(cal-tex-latexify-list
877 holidays date
"; ")))
879 (cal-tex-large-bf s
))
881 (insert " " (eval cal-tex-daily-string
))
885 (cal-tex-b-parbox "t" "\\textwidth")
886 (unless (string-equal "" (setq s
(cal-tex-latexify-list
888 (insert "\\vbox to 0pt{")
893 (setq date
(cal-tex-incr-date date
)
894 month
(calendar-extract-month date
)
895 day
(calendar-extract-day date
))
897 (cal-tex-e-parbox "2cm")
899 (setq month
(calendar-extract-month date
)
900 year
(calendar-extract-year date
)))
903 (run-hooks 'cal-tex-week-hook
)
905 (cal-tex-end-document)
906 (run-hooks 'cal-tex-hook
)))
908 ;; TODO respect cal-tex-daily-start,end?
909 ;; Using different numbers of hours will probably break some layouts.
910 (defun cal-tex-week-hours (date holidays height
)
911 "Insert hourly entries for DATE with HOLIDAYS, with line height HEIGHT.
912 Uses the 24-hour clock if `cal-tex-24' is non-nil. Note that the hours
913 shown are hard-coded to 8-12, 13-17."
914 (let ((month (calendar-extract-month date
))
915 (day (calendar-extract-day date
))
916 (year (calendar-extract-year date
))
918 (cal-tex-comment "begin cal-tex-week-hours")
919 (cal-tex-cmd "\\ \\\\[-.2cm]")
920 (cal-tex-cmd "\\noindent")
921 (cal-tex-b-parbox "l" "6.8in")
922 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
924 (cal-tex-large-bf (cal-tex-month-name month
))
926 (cal-tex-large-bf (number-to-string day
))
927 (unless (string-equal "" (setq s
(cal-tex-latexify-list
928 holidays date
"; ")))
930 (cal-tex-large-bf s
))
932 (insert " " (eval cal-tex-daily-string
))
935 (cal-tex-rule "0pt" "6.8in" ".2mm")
938 (setq morning
(+ i
8) ; 8-12 incl
939 afternoon
(if cal-tex-24
940 (+ i
13) ; 13-17 incl
942 (cal-tex-cmd "\\hourbox" (number-to-string morning
))
944 (cal-tex-hspace ".4cm")
945 (cal-tex-cmd "\\hourbox" (number-to-string afternoon
))
949 ;; TODO cal-tex-diary support.
950 ;; TODO respect cal-tex-daily-start,end (see cal-tex-weekly4-box).
952 (defun cal-tex-cursor-week-monday (&optional n event
)
953 "Make a LaTeX calendar buffer for a two-page one-week calendar.
954 It applies to the week that point is in, and starts on Monday.
955 Optional prefix argument N specifies number of weeks (default 1).
956 The calendar shows holidays if `cal-tex-holidays' is
957 non-nil (note that diary entries are not shown). The calendar shows
958 the hours 8-12am, 1-5pm. Optional EVENT indicates a buffer position
959 to use instead of point."
960 (interactive (list (prefix-numeric-value current-prefix-arg
)
963 (let ((date (calendar-gregorian-from-absolute
964 (calendar-dayname-on-or-before
966 (calendar-absolute-from-gregorian
967 (calendar-cursor-to-date t event
))))))
968 (cal-tex-preamble "11pt")
969 (cal-tex-cmd "\\textwidth 6.5in")
970 (cal-tex-cmd "\\textheight 10.5in")
971 (cal-tex-cmd "\\oddsidemargin 0in")
972 (cal-tex-cmd "\\evensidemargin 0in")
975 (cal-tex-vspace "-1cm")
976 (insert "\\noindent ")
977 (cal-tex-weekly4-box (cal-tex-incr-date date
) nil
)
978 (cal-tex-weekly4-box (cal-tex-incr-date date
4) nil
)
980 (cal-tex-weekly4-box (cal-tex-incr-date date
2) nil
)
981 (cal-tex-weekly4-box (cal-tex-incr-date date
5) nil
)
983 (cal-tex-weekly4-box (cal-tex-incr-date date
3) nil
)
984 (cal-tex-weekly4-box (cal-tex-incr-date date
6) t
)
986 (run-hooks 'cal-tex-week-hook
)
987 (setq date
(cal-tex-incr-date date
7))
989 (cal-tex-end-document)
990 (run-hooks 'cal-tex-hook
)))
992 ;; TODO respect cal-tex-daily-start,end?
993 ;; Using different numbers of hours will probably break some layouts.
994 (defun cal-tex-weekly4-box (date weekend
)
995 "Make one box for DATE, different if WEEKEND.
996 Uses the 24-hour clock if `cal-tex-24' is non-nil. Note that the hours
997 shown are hard-coded to 8-12, 13-17."
998 (let* ((day (calendar-extract-day date
))
999 (month (calendar-extract-month date
))
1000 (year (calendar-extract-year date
))
1001 (dayname (cal-tex-LaTeXify-string (calendar-day-name date
)))
1002 (date1 (cal-tex-incr-date date
))
1003 (day1 (calendar-extract-day date1
))
1004 (month1 (calendar-extract-month date1
))
1005 (year1 (calendar-extract-year date1
))
1006 (dayname1 (cal-tex-LaTeXify-string (calendar-day-name date1
))))
1007 (cal-tex-b-framebox "8cm" "l")
1008 (cal-tex-b-parbox "b" "7.5cm")
1009 (insert (format "\\textbf{\\Large %s,} %s/%s/%s\\\\\n"
1010 dayname month day year
))
1011 (cal-tex-rule "0pt" "7.5cm" ".5mm")
1015 (insert (format "\\textsf{\\large %d}\\\\\n" (+ i
8))))
1017 (insert (format "\\textsf{\\large %d}\\\\\n"
1019 (+ i
13) ; 13-17 incl
1020 (1+ i
)))))) ; 1-5 incl
1023 (cal-tex-vspace "1cm")
1024 (insert "\\ \\vfill")
1025 (insert (format "\\textbf{\\Large %s,} %s/%s/%s\\\\\n"
1026 dayname1 month1 day1 year1
))
1027 (cal-tex-rule "0pt" "7.5cm" ".5mm")
1028 (cal-tex-nl "1.5cm")
1029 (cal-tex-vspace "1cm"))
1031 (cal-tex-e-framebox)
1032 (cal-tex-hspace "1cm")))
1035 (defun cal-tex-cursor-filofax-2week (&optional n event
)
1036 "Two-weeks-at-a-glance Filofax style calendar for week cursor is in.
1037 Optional prefix argument N specifies number of weeks (default 1).
1038 The calendar shows holiday and diary entries if
1039 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
1040 Optional EVENT indicates a buffer position to use instead of point."
1041 (interactive (list (prefix-numeric-value current-prefix-arg
)
1042 last-nonmenu-event
))
1044 (let* ((date (calendar-gregorian-from-absolute
1045 (calendar-dayname-on-or-before
1046 calendar-week-start-day
1047 (calendar-absolute-from-gregorian
1048 (calendar-cursor-to-date t event
)))))
1049 (month (calendar-extract-month date
))
1050 (year (calendar-extract-year date
))
1051 (day (calendar-extract-day date
))
1052 (d1 (calendar-absolute-from-gregorian date
))
1054 (holidays (if cal-tex-holidays
1055 (cal-tex-list-holidays d1 d2
)))
1056 (diary-list (if cal-tex-diary
1057 (cal-tex-list-diary-entries
1059 (calendar-absolute-from-gregorian (list month
1 year
))
1061 (cal-tex-preamble "twoside")
1062 (cal-tex-cmd "\\textwidth 3.25in")
1063 (cal-tex-cmd "\\textheight 6.5in")
1064 (cal-tex-cmd "\\oddsidemargin 1.75in")
1065 (cal-tex-cmd "\\evensidemargin 1.5in")
1066 (cal-tex-cmd "\\topmargin 0pt")
1067 (cal-tex-cmd "\\headheight -0.875in")
1068 (cal-tex-cmd "\\headsep 0.125in")
1069 (cal-tex-cmd "\\footskip .125in")
1070 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1071 \\long\\def\\rightday#1#2#3#4#5{%
1072 \\rule{\\textwidth}{0.3pt}\\\\%
1073 \\hbox to \\textwidth{%
1076 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1077 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1078 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1079 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1080 \\long\\def\\leftday#1#2#3#4#5{%
1081 \\rule{\\textwidth}{0.3pt}\\\\%
1082 \\hbox to \\textwidth{%
1085 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1086 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1087 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1089 (cal-tex-b-document)
1090 (cal-tex-cmd "\\pagestyle{empty}")
1092 (if (zerop (mod i
2))
1093 (insert "\\righthead")
1094 (insert "\\lefthead"))
1096 (let ((d (cal-tex-incr-date date
6)))
1097 (if (= (calendar-extract-month date
)
1098 (calendar-extract-month d
))
1100 (cal-tex-month-name (calendar-extract-month date
))
1101 (calendar-extract-year date
))
1102 (if (= (calendar-extract-year date
)
1103 (calendar-extract-year d
))
1104 (format "%s---%s %s"
1105 (cal-tex-month-name (calendar-extract-month date
))
1106 (cal-tex-month-name (calendar-extract-month d
))
1107 (calendar-extract-year date
))
1108 (format "%s %s---%s %s"
1109 (cal-tex-month-name (calendar-extract-month date
))
1110 (calendar-extract-year date
)
1111 (cal-tex-month-name (calendar-extract-month d
))
1112 (calendar-extract-year d
))))))
1114 (dotimes (_jdummy 7)
1115 (if (zerop (mod i
2))
1116 (insert "\\rightday")
1117 (insert "\\leftday"))
1118 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1119 (cal-tex-arg (number-to-string (calendar-extract-day date
)))
1120 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1121 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1122 (cal-tex-arg (eval cal-tex-daily-string
))
1124 (setq date
(cal-tex-incr-date date
)))
1125 (unless (= i
(1- n
))
1126 (run-hooks 'cal-tex-week-hook
)
1128 (cal-tex-end-document)
1129 (run-hooks 'cal-tex-hook
)))
1132 (defun cal-tex-cursor-filofax-week (&optional n event
)
1133 "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
1134 Optional prefix argument N specifies number of weeks (default 1),
1135 starting on Mondays. The calendar shows holiday and diary entries
1136 if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
1137 Optional EVENT indicates a buffer position to use instead of point."
1138 (interactive (list (prefix-numeric-value current-prefix-arg
)
1139 last-nonmenu-event
))
1141 (let* ((date (calendar-gregorian-from-absolute
1142 (calendar-dayname-on-or-before
1144 (calendar-absolute-from-gregorian
1145 (calendar-cursor-to-date t event
)))))
1146 (month (calendar-extract-month date
))
1147 (year (calendar-extract-year date
))
1148 (day (calendar-extract-day date
))
1149 (d1 (calendar-absolute-from-gregorian date
))
1151 (holidays (if cal-tex-holidays
1152 (cal-tex-list-holidays d1 d2
)))
1153 (diary-list (if cal-tex-diary
1154 (cal-tex-list-diary-entries
1156 (calendar-absolute-from-gregorian (list month
1 year
))
1158 (cal-tex-preamble "twoside")
1159 (cal-tex-cmd "\\textwidth 3.25in")
1160 (cal-tex-cmd "\\textheight 6.5in")
1161 (cal-tex-cmd "\\oddsidemargin 1.75in")
1162 (cal-tex-cmd "\\evensidemargin 1.5in")
1163 (cal-tex-cmd "\\topmargin 0pt")
1164 (cal-tex-cmd "\\headheight -0.875in")
1165 (cal-tex-cmd "\\headsep 0.125in")
1166 (cal-tex-cmd "\\footskip .125in")
1167 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1168 \\long\\def\\rightday#1#2#3#4#5{%
1169 \\rule{\\textwidth}{0.3pt}\\\\%
1170 \\hbox to \\textwidth{%
1173 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1174 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1175 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1176 \\long\\def\\weekend#1#2#3#4#5{%
1177 \\rule{\\textwidth}{0.3pt}\\\\%
1178 \\hbox to \\textwidth{%
1181 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1182 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1183 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1184 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1185 \\long\\def\\leftday#1#2#3#4#5{%
1186 \\rule{\\textwidth}{0.3pt}\\\\%
1187 \\hbox to \\textwidth{%
1190 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1191 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1192 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1194 (cal-tex-b-document)
1195 (cal-tex-cmd "\\pagestyle{empty}\\ ")
1198 (insert "\\lefthead")
1200 (let ((d (cal-tex-incr-date date
2)))
1201 (if (= (calendar-extract-month date
)
1202 (calendar-extract-month d
))
1204 (cal-tex-month-name (calendar-extract-month date
))
1205 (calendar-extract-year date
))
1206 (if (= (calendar-extract-year date
)
1207 (calendar-extract-year d
))
1208 (format "%s---%s %s"
1209 (cal-tex-month-name (calendar-extract-month date
))
1210 (cal-tex-month-name (calendar-extract-month d
))
1211 (calendar-extract-year date
))
1212 (format "%s %s---%s %s"
1213 (cal-tex-month-name (calendar-extract-month date
))
1214 (calendar-extract-year date
)
1215 (cal-tex-month-name (calendar-extract-month d
))
1216 (calendar-extract-year d
))))))
1218 (dotimes (_jdummy 3)
1219 (insert "\\leftday")
1220 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1221 (cal-tex-arg (number-to-string (calendar-extract-day date
)))
1222 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1223 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1224 (cal-tex-arg (eval cal-tex-daily-string
))
1226 (setq date
(cal-tex-incr-date date
)))
1227 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1229 (insert "\\righthead")
1231 (let ((d (cal-tex-incr-date date
3)))
1232 (if (= (calendar-extract-month date
)
1233 (calendar-extract-month d
))
1235 (cal-tex-month-name (calendar-extract-month date
))
1236 (calendar-extract-year date
))
1237 (if (= (calendar-extract-year date
)
1238 (calendar-extract-year d
))
1239 (format "%s---%s %s"
1240 (cal-tex-month-name (calendar-extract-month date
))
1241 (cal-tex-month-name (calendar-extract-month d
))
1242 (calendar-extract-year date
))
1243 (format "%s %s---%s %s"
1244 (cal-tex-month-name (calendar-extract-month date
))
1245 (calendar-extract-year date
)
1246 (cal-tex-month-name (calendar-extract-month d
))
1247 (calendar-extract-year d
))))))
1249 (dotimes (_jdummy 2)
1250 (insert "\\rightday")
1251 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1252 (cal-tex-arg (number-to-string (calendar-extract-day date
)))
1253 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1254 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1255 (cal-tex-arg (eval cal-tex-daily-string
))
1257 (setq date
(cal-tex-incr-date date
)))
1258 (dotimes (_jdummy 2)
1259 (insert "\\weekend")
1260 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1261 (cal-tex-arg (number-to-string (calendar-extract-day date
)))
1262 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1263 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1264 (cal-tex-arg (eval cal-tex-daily-string
))
1266 (setq date
(cal-tex-incr-date date
)))
1267 (unless (= i
(1- n
))
1268 (run-hooks 'cal-tex-week-hook
)
1270 (cal-tex-end-document)
1271 (run-hooks 'cal-tex-hook
)))
1274 (defun cal-tex-cursor-filofax-daily (&optional n event
)
1275 "Day-per-page Filofax style calendar for week indicated by cursor.
1276 Optional prefix argument N specifies number of weeks (default 1),
1277 starting on Mondays. The calendar shows holiday and diary
1278 entries if `cal-tex-holidays' and `cal-tex-diary', respectively,
1279 are non-nil. Pages are ruled if `cal-tex-rules' is non-nil.
1280 Optional EVENT indicates a buffer position to use instead of point."
1281 (interactive (list (prefix-numeric-value current-prefix-arg
)
1282 last-nonmenu-event
))
1284 (let* ((date (calendar-gregorian-from-absolute
1285 (calendar-dayname-on-or-before
1287 (calendar-absolute-from-gregorian
1288 (calendar-cursor-to-date t event
)))))
1289 (month (calendar-extract-month date
))
1290 (year (calendar-extract-year date
))
1291 (day (calendar-extract-day date
))
1292 (d1 (calendar-absolute-from-gregorian date
))
1294 (holidays (if cal-tex-holidays
1295 (cal-tex-list-holidays d1 d2
)))
1296 (diary-list (if cal-tex-diary
1297 (cal-tex-list-diary-entries
1299 (calendar-absolute-from-gregorian (list month
1 year
))
1301 (cal-tex-preamble "twoside")
1302 (cal-tex-cmd "\\textwidth 3.25in")
1303 (cal-tex-cmd "\\textheight 6.5in")
1304 (cal-tex-cmd "\\oddsidemargin 1.75in")
1305 (cal-tex-cmd "\\evensidemargin 1.5in")
1306 (cal-tex-cmd "\\topmargin 0pt")
1307 (cal-tex-cmd "\\headheight -0.875in")
1308 (cal-tex-cmd "\\headsep 0.125in")
1309 (cal-tex-cmd "\\footskip .125in")
1310 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1311 \\long\\def\\rightday#1#2#3{%
1312 \\rule{\\textwidth}{0.3pt}\\\\%
1313 \\hbox to \\textwidth{%
1316 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1317 \\hbox to \\textwidth{\\vbox {\\raggedleft \\em #2}}%
1318 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1319 \\long\\def\\weekend#1#2#3{%
1320 \\rule{\\textwidth}{0.3pt}\\\\%
1321 \\hbox to \\textwidth{%
1324 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1325 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1326 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1327 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1328 \\long\\def\\leftday#1#2#3{%
1329 \\rule{\\textwidth}{0.3pt}\\\\%
1330 \\hbox to \\textwidth{%
1333 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1334 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1335 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1337 \\setbox\\LineBox=\\hbox to\\textwidth{%
1338 \\vrule height.2in width0pt\\leaders\\hrule\\hfill}
1339 \\def\\linesfill{\\par\\leaders\\copy\\LineBox\\vfill}
1341 (cal-tex-b-document)
1342 (cal-tex-cmd "\\pagestyle{empty}")
1345 (let ((even (zerop (% j
2))))
1349 (cal-tex-arg (calendar-date-string date
))
1354 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1355 (cal-tex-arg (cal-tex-latexify-list holidays date
"\\\\" t
))
1356 (cal-tex-arg (eval cal-tex-daily-string
))
1359 (insert "\\linesfill\n")
1360 (insert "\\vfill\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1362 (setq date
(cal-tex-incr-date date
)))
1364 (dotimes (_jdummy 2)
1365 (insert "\\lefthead")
1366 (cal-tex-arg (calendar-date-string date
))
1367 (insert "\\weekend")
1368 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1369 (cal-tex-arg (cal-tex-latexify-list holidays date
"\\\\" t
))
1370 (cal-tex-arg (eval cal-tex-daily-string
))
1373 (insert "\\linesfill\n")
1375 (setq date
(cal-tex-incr-date date
)))
1377 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1378 (unless (= i
(1- n
))
1379 (run-hooks 'cal-tex-week-hook
)
1381 (cal-tex-end-document)
1382 (run-hooks 'cal-tex-hook
)))
1390 (defun cal-tex-cursor-day (&optional n event
)
1391 "Make a buffer with LaTeX commands for the day cursor is on.
1392 Optional prefix argument N specifies number of days. The calendar shows
1393 the hours between `cal-tex-daily-start' and `cal-tex-daily-end', using
1394 the 24-hour clock if `cal-tex-24' is non-nil. Optional EVENT indicates
1395 a buffer position to use instead of point."
1396 (interactive (list (prefix-numeric-value current-prefix-arg
)
1397 last-nonmenu-event
))
1399 (let ((date (calendar-absolute-from-gregorian
1400 (calendar-cursor-to-date t event
))))
1401 (cal-tex-preamble "12pt")
1402 (cal-tex-cmd "\\textwidth 6.5in")
1403 (cal-tex-cmd "\\textheight 10.5in")
1404 (cal-tex-b-document)
1405 (cal-tex-cmd "\\pagestyle{empty}")
1407 (cal-tex-vspace "-1.7in")
1408 (cal-tex-daily-page (calendar-gregorian-from-absolute date
))
1409 (setq date
(1+ date
))
1410 (unless (= i
(1- n
))
1412 (run-hooks 'cal-tex-daily-hook
)))
1413 (cal-tex-end-document)
1414 (run-hooks 'cal-tex-hook
)))
1416 (defun cal-tex-daily-page (date)
1417 "Make a calendar page for Gregorian DATE on 8.5 by 11 paper.
1418 Uses the 24-hour clock if `cal-tex-24' is non-nil. Produces
1419 hourly sections for the period specified by `cal-tex-daily-start'
1420 and `cal-tex-daily-end'."
1421 (let ((month-name (cal-tex-month-name (calendar-extract-month date
)))
1422 (i (1- cal-tex-daily-start
))
1424 (cal-tex-banner "cal-tex-daily-page")
1425 (cal-tex-b-makebox "4cm" "l")
1426 (cal-tex-b-parbox "b" "3.8cm")
1427 (cal-tex-rule "0mm" "0mm" "2cm")
1428 (cal-tex-Huge (number-to-string (calendar-extract-day date
)))
1430 (cal-tex-bf month-name
)
1432 (cal-tex-hspace "1cm")
1433 (cal-tex-scriptsize (eval cal-tex-daily-string
))
1434 (cal-tex-hspace "3.5cm")
1437 (cal-tex-b-makebox "4cm" "r")
1438 (cal-tex-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
1441 (cal-tex-hspace ".4cm")
1442 (cal-tex-rule "0mm" "16.1cm" "1mm")
1444 (while (<= (setq i
(1+ i
)) cal-tex-daily-end
)
1445 (cal-tex-cmd "\\noindent")
1446 (setq hour
(if cal-tex-24
1449 (if (zerop hour
) (setq hour
12))
1450 (cal-tex-b-makebox "1cm" "c")
1451 (cal-tex-arg (number-to-string hour
))
1453 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1455 (cal-tex-b-makebox "1cm" "c")
1456 (cal-tex-arg "$\\diamond$" )
1458 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1459 (cal-tex-nl ".2cm"))
1461 (insert (cal-tex-mini-calendar
1462 (calendar-extract-month (cal-tex-previous-month date
))
1463 (calendar-extract-year (cal-tex-previous-month date
))
1464 "lastmonth" "1.1in" "1in"))
1465 (insert (cal-tex-mini-calendar
1466 (calendar-extract-month date
)
1467 (calendar-extract-year date
)
1468 "thismonth" "1.1in" "1in"))
1469 (insert (cal-tex-mini-calendar
1470 (calendar-extract-month (cal-tex-next-month date
))
1471 (calendar-extract-year (cal-tex-next-month date
))
1472 "nextmonth" "1.1in" "1in"))
1473 (insert "\\hbox to \\textwidth{")
1475 (insert "\\lastmonth")
1477 (insert "\\thismonth")
1479 (insert "\\nextmonth")
1482 (cal-tex-banner "end of cal-tex-daily-page")))
1488 (defun cal-tex-mini-calendar (month year name width height
&optional ptsize colsep
)
1489 "Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT.
1490 Optional string PTSIZE gives the point size (default \"scriptsize\").
1491 Optional string COLSEP gives the column separation (default \"1mm\")."
1492 (or colsep
(setq colsep
"1mm"))
1493 (or ptsize
(setq ptsize
"scriptsize"))
1494 (let ((blank-days ; at start of month
1496 (- (calendar-day-of-week (list month
1 year
))
1497 calendar-week-start-day
)
1499 (last( calendar-last-day-of-month month year
))
1500 (str (concat "\\def\\" name
"{\\hbox to" width
"{%\n"
1501 "\\vbox to" height
"{%\n"
1502 "\\vfil \\hbox to" width
"{%\n"
1505 "{@{\\hspace{0mm}}r@{\\hspace{" colsep
1506 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{" colsep
1507 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{" colsep
1508 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{0mm}}}%\n"
1509 "\\multicolumn{7}{c}{"
1510 (cal-tex-month-name month
)
1512 (number-to-string year
)
1517 (cal-tex-LaTeXify-string
1518 (substring (aref calendar-day-name-array
1519 (mod (+ calendar-week-start-day i
) 7))
1525 (dotimes (_idummy blank-days
)
1526 (setq str
(concat str
" & ")))
1528 (setq str
(concat str
(number-to-string (1+ i
)))
1529 str
(concat str
(if (zerop (mod (+ i
1 blank-days
) 7))
1534 (setq str
(concat str
"\n\\end{tabular}\\hfil}\\vfil}}}%\n"))
1538 ;;; Various calendar functions
1541 (defun cal-tex-incr-date (date &optional n
)
1542 "The date of the day following DATE.
1543 If optional N is given, the date of N days after DATE."
1544 (calendar-gregorian-from-absolute
1545 (+ (or n
1) (calendar-absolute-from-gregorian date
))))
1547 (defun cal-tex-latexify-list (date-list date
&optional separator final-separator
)
1548 "Return string with concatenated, LaTeX-ified entries in DATE-LIST for DATE.
1549 Use double backslash as a separator unless optional SEPARATOR is given.
1550 If resulting string is not empty, put separator at end if optional
1551 FINAL-SEPARATOR is non-nil."
1552 (or separator
(setq separator
"\\\\"))
1555 (mapconcat (lambda (x) (cal-tex-LaTeXify-string x
))
1556 (dolist (d date-list
(reverse result
))
1558 (calendar-date-equal date
(car d
))
1559 (setq result
(cons (cadr d
) result
))))
1561 (if (and final-separator
1562 (not (string-equal result
"")))
1563 (concat result separator
)
1566 (defun cal-tex-previous-month (date)
1567 "Return the date of the first day in the month previous to DATE."
1568 (let ((month (calendar-extract-month date
))
1569 (year (calendar-extract-year date
)))
1570 (calendar-increment-month month year -
1)
1571 (list month
1 year
)))
1573 (defun cal-tex-next-month (date)
1574 "Return the date of the first day in the month following DATE."
1575 (let ((month (calendar-extract-month date
))
1576 (year (calendar-extract-year date
)))
1577 (calendar-increment-month month year
1)
1578 (list month
1 year
)))
1584 (defun cal-tex-end-document ()
1585 "Finish the LaTeX document.
1586 Insert the trailer to LaTeX document, pop to LaTeX buffer, add
1587 informative header, and run HOOK."
1588 (cal-tex-e-document)
1589 (or (and cal-tex-preamble-extra
1590 (string-match "inputenc" cal-tex-preamble-extra
))
1591 (not (re-search-backward "[^[:ascii:]]" nil
'move
))
1593 (goto-char (point-min))
1594 (when (search-forward "documentclass" nil t
)
1596 ;; Eg for some Bahai holidays.
1597 ;; FIXME latin1 might not always be right.
1598 (insert "\\usepackage[latin1]{inputenc}\n"))))
1600 (pop-to-buffer cal-tex-buffer
)
1601 (goto-char (point-min))
1602 ;; FIXME auctex equivalents?
1604 (format "\tThis buffer was produced by cal-tex.el.
1605 \tTo print a calendar, type
1606 \t\tM-x tex-buffer RET
1607 \t\tM-x tex-print RET")))
1609 (defun cal-tex-insert-preamble (weeks landscape size
&optional append
)
1610 "Initialize the output LaTeX calendar buffer, `cal-tex-buffer'.
1611 Select the output buffer, and insert the preamble for a calendar
1612 of WEEKS weeks. Insert code for landscape mode if LANDSCAPE is
1613 non-nil. Use point-size SIZE. Optional argument APPEND, if
1614 non-nil, means add to end of buffer without erasing current contents."
1615 (let ((width "18cm")
1621 (cal-tex-preamble size
)
1624 (cal-tex-cmd "\\oddsidemargin -1.75cm")
1625 (cal-tex-cmd "\\def\\holidaymult{.06}"))
1626 (cal-tex-cmd "\\special{landscape}")
1627 (cal-tex-cmd "\\textwidth 9.5in")
1628 (cal-tex-cmd "\\textheight 7in")
1630 (cal-tex-cmd "\\def\\holidaymult{.08}"))
1631 (cal-tex-cmd cal-tex-caldate
)
1632 (cal-tex-cmd cal-tex-myday
)
1633 (cal-tex-b-document)
1634 (cal-tex-cmd "\\pagestyle{empty}"))
1635 (cal-tex-cmd "\\setlength{\\cellwidth}" width
)
1636 (insert (format "\\setlength{\\cellwidth}{%f\\cellwidth}\n"
1637 (/ 1.1 (length cal-tex-which-days
))))
1638 (cal-tex-cmd "\\setlength{\\cellheight}" height
)
1639 (insert (format "\\setlength{\\cellheight}{%f\\cellheight}\n"
1641 (cal-tex-cmd "\\ \\par")
1642 (cal-tex-vspace "-3cm")))
1644 (defconst cal-tex-LaTeX-subst-list
1646 ("\"".
"''") ; quote changes meaning when list is reversed
1647 ;; Don't think this is necessary, and in any case, does not work:
1648 ;; "LaTeX Error: \verb illegal in command argument".
1649 ;;; ("@" . "\\verb|@|")
1659 ("\n" .
"\\ \\\\")) ; \\ needed for e.g \begin{center}\n AA\end{center}
1660 "Alist of symbols and their LaTeX replacements.")
1662 (defun cal-tex-LaTeXify-string (string)
1663 "Protect special characters in STRING from LaTeX."
1668 (list cal-tex-LaTeX-subst-list
)
1670 (while (not (string-equal tail
""))
1671 (setq ch
(substring-no-properties tail
0 1)
1672 pair
(assoc ch list
))
1673 (if (and pair
(string-equal ch
"\""))
1674 (setq list
(reverse list
))) ; quote changes meaning each time
1675 (setq tail
(substring-no-properties tail
1)
1676 head
(concat head
(if pair
(cdr pair
) ch
))))
1679 (defun cal-tex-month-name (month)
1680 "The name of MONTH, LaTeX-ified."
1681 (cal-tex-LaTeXify-string (calendar-month-name month
)))
1683 (defun cal-tex-hfill ()
1687 (defun cal-tex-newpage ()
1689 (insert "\\newpage%\n"))
1691 (defun cal-tex-noindent ()
1693 (insert "\\noindent"))
1695 (defun cal-tex-vspace (space)
1696 "Insert vspace command to move SPACE vertically."
1697 (insert "\\vspace*{" space
"}")
1700 (defun cal-tex-hspace (space)
1701 "Insert hspace command to move SPACE horizontally."
1702 (insert "\\hspace*{" space
"}")
1705 (defun cal-tex-comment (&optional comment
)
1706 "Insert `% ', followed by optional string COMMENT, followed by newline.
1707 COMMENT may contain newlines, which are prefixed by `% ' in the output."
1708 (insert (format "%% %s\n"
1710 (replace-regexp-in-string "\n" "\n% " comment
)
1713 (defun cal-tex-banner (comment)
1714 "Insert string COMMENT, separated by blank lines."
1715 (cal-tex-comment (format "\n\n\n\t\t\t%s\n" comment
)))
1717 (defun cal-tex-nl (&optional skip comment
)
1718 "End a line with \\. If SKIP, then add that much spacing.
1719 Add trailing COMMENT if present."
1720 (insert (format "\\\\%s"
1722 (format "[%s]" skip
)
1724 (cal-tex-comment comment
))
1726 (defun cal-tex-arg (&optional text
)
1727 "Insert a brace {} pair containing the optional string TEXT."
1728 (insert (format "{%s}" (or text
""))))
1730 (defun cal-tex-cmd (cmd &optional arg
)
1731 "Insert LaTeX CMD, with optional argument ARG, and end with %."
1740 (defun cal-tex-b-document ()
1741 "Insert beginning of document."
1742 (cal-tex-cmd "\\begin{document}"))
1744 (defun cal-tex-e-document ()
1745 "Insert end of document."
1746 (cal-tex-cmd "\\end{document}"))
1748 (defun cal-tex-b-center ()
1749 "Insert beginning of centered block."
1750 (cal-tex-cmd "\\begin{center}"))
1752 (defun cal-tex-e-center ()
1753 "Insert end of centered block."
1755 (cal-tex-cmd "\\end{center}"))
1763 (defun cal-tex-b-parbox (position width
)
1764 "Insert parbox with parameters POSITION and WIDTH."
1765 (insert "\\parbox[" position
"]{" width
"}{")
1768 (defun cal-tex-e-parbox (&optional height
)
1769 "Insert end of parbox. Optionally, force it to be a given HEIGHT."
1772 (cal-tex-rule "0mm" "0mm" height
))
1774 (cal-tex-comment "end parbox"))
1776 (defun cal-tex-b-framebox (width position
)
1777 "Insert framebox with parameters WIDTH and POSITION (clr)."
1778 (insert "\\framebox[" width
"][" position
"]{" )
1781 (defun cal-tex-e-framebox ()
1782 "Insert end of framebox."
1785 (cal-tex-comment "end framebox"))
1788 (defun cal-tex-b-makebox (width position
)
1789 "Insert makebox with parameters WIDTH and POSITION (clr)."
1790 (insert "\\makebox[" width
"][" position
"]{" )
1793 (defun cal-tex-e-makebox ()
1794 "Insert end of makebox."
1797 (cal-tex-comment "end makebox"))
1800 (defun cal-tex-rule (lower width height
)
1801 "Insert a rule with parameters LOWER WIDTH HEIGHT."
1802 (insert "\\rule[" lower
"]{" width
"}{" height
"}"))
1808 (defun cal-tex-em (string)
1809 "Insert STRING in italic font."
1810 (insert "\\textit{" string
"}"))
1812 (defun cal-tex-bf (string)
1813 "Insert STRING in bf font."
1814 (insert "\\textbf{ " string
"}"))
1816 (defun cal-tex-scriptsize (string)
1817 "Insert STRING in scriptsize font."
1818 (insert "{\\scriptsize " string
"}"))
1820 (defun cal-tex-huge (string)
1821 "Insert STRING in huge font."
1822 (insert "{\\huge " string
"}"))
1824 (defun cal-tex-Huge (string)
1825 "Insert STRING in Huge font."
1826 (insert "{\\Huge " string
"}"))
1828 (defun cal-tex-Huge-bf (string)
1829 "Insert STRING in Huge bf font."
1830 (insert "\\textbf{\\Huge " string
"}"))
1832 (defun cal-tex-large (string)
1833 "Insert STRING in large font."
1834 (insert "{\\large " string
"}"))
1836 (defun cal-tex-large-bf (string)
1837 "Insert STRING in large bf font."
1838 (insert "\\textbf{\\large " string
"}"))
1843 ;;; cal-tex.el ends here