1 ;;; cal-tex.el --- calendar functions for printing calendars with LaTeX
3 ;; Copyright (C) 1995, 2001-2012 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 (defconst cal-tex-lefthead
241 "\\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}\n"
242 "LaTeX code for left header.")
244 (defconst cal-tex-righthead
245 "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}\n"
246 "LaTeX code for right header.")
248 (autoload 'holiday-in-range
"holidays")
250 (define-obsolete-function-alias 'cal-tex-list-holidays
'holiday-in-range
"24.3")
252 (autoload 'diary-list-entries
"diary-lib")
254 (defun cal-tex-list-diary-entries (d1 d2
)
255 "Generate a list of all diary-entries from absolute date D1 to D2."
256 (let (diary-list-include-blanks)
257 (diary-list-entries (calendar-gregorian-from-absolute d1
)
260 (defun cal-tex-preamble (&optional args
)
261 "Insert the LaTeX calendar preamble into `cal-tex-buffer'.
262 Preamble includes initial definitions for various LaTeX commands.
263 Optional string ARGS are included as options for the article document class."
264 (set-buffer (generate-new-buffer cal-tex-buffer
))
265 (insert (format "\\documentclass%s{article}\n"
269 (if (stringp cal-tex-preamble-extra
)
270 (insert cal-tex-preamble-extra
"\n"))
271 ;; FIXME boxwidth and boxheight unused?
272 (insert "\\hbadness 20000
278 \\evensidemargin -2cm
283 \\newlength{\\cellwidth}
284 \\newlength{\\cellheight}
285 \\newlength{\\boxwidth}
286 \\newlength{\\boxheight}
287 \\newlength{\\cellsize}
288 \\newcommand{\\myday}[1]{}
289 \\newcommand{\\caldate}[6]{}
290 \\newcommand{\\nocaldate}[6]{}
291 \\newcommand{\\calsmall}[6]{}
300 (defun cal-tex-cursor-year (&optional n event
)
301 "Make a buffer with LaTeX commands for the year cursor is on.
302 Optional prefix argument N specifies number of years.
303 Optional EVENT indicates a buffer position to use instead of point."
304 (interactive (list (prefix-numeric-value current-prefix-arg
)
306 (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t event
))
310 (defun cal-tex-cursor-year-landscape (&optional n event
)
311 "Make a buffer with LaTeX commands for the year cursor is on.
312 Optional prefix argument N specifies number of years.
313 Optional EVENT indicates a buffer position to use instead of point."
314 (interactive (list (prefix-numeric-value current-prefix-arg
)
316 (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t event
))
319 (defun cal-tex-year (year n
&optional landscape
)
320 "Make a one page yearly calendar of YEAR; do this for N years.
321 There are four rows of three months each, unless optional
322 LANDSCAPE is non-nil, in which case the calendar is printed in
323 landscape mode with three rows of four months each."
324 (cal-tex-insert-preamble 1 landscape
"12pt")
326 (cal-tex-vspace "-.6cm")
327 (cal-tex-vspace "-3.1cm"))
329 (insert "\\vfill%\n")
331 (cal-tex-Huge (number-to-string year
))
333 (cal-tex-vspace "1cm")
335 (cal-tex-b-parbox "l" (if landscape
"5.9in" "4.3in"))
340 (insert (cal-tex-mini-calendar (1+ i
) year
"month" "1.1in" "1in"))
342 (cal-tex-hspace "0.5in")
343 (if (zerop (mod (1+ i
) (if landscape
4 3)))
344 (cal-tex-nl "0.5in")))
347 (insert "\\vfill%\n")
348 (setq year
(1+ year
))
350 (cal-tex-end-document)
352 (run-hooks 'cal-tex-year-hook
))
353 (run-hooks 'cal-tex-hook
))
356 (defun cal-tex-filofax-paper (&optional year
)
357 "Insert some page size settings for filofax layouts."
358 (insert "\\textwidth 3.25in
360 \\headheight -0.875in
364 ;; Why is this one subtly different? Who knows...
365 (if year
"\\oddsidemargin 1.675in
366 \\evensidemargin 1.675in
368 "\\oddsidemargin 1.75in
369 \\evensidemargin 1.5in
374 (defun cal-tex-longday (funcname height
)
375 "Insert LaTeX code for a long day function."
376 (insert "\\long\\def\\" funcname
"#1#2#3#4#5{%
377 \\rule{\\textwidth}{0.3pt}\\\\%
378 \\hbox to \\textwidth{%
379 \\vbox to " height
"{%
381 \\hbox to \\textwidth{"
382 (if (string-equal funcname
"leftday")
383 "\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%\n"
384 "\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%\n")
385 " \\hbox to \\textwidth{\\vbox {\\"
386 (if (string-equal funcname
"leftday") "noindent" "raggedleft")
387 " \\footnotesize \\em #4}}%
388 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}\n"))
390 (defun cal-tex-shortday (funcname)
391 "Insert LaTeX code for a short day function."
392 (insert "\\long\\def\\" funcname
"#1#2#3{%
393 \\rule{\\textwidth}{0.3pt}\\\\%
394 \\hbox to \\textwidth{%
397 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
398 \\hbox to \\textwidth{\\vbox {\\"
399 (if (string-equal funcname
"rightday") "raggedleft" "noindent")
401 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}\n"))
404 (defun cal-tex-cursor-filofax-year (&optional n event
)
405 "Make a Filofax one page yearly calendar of year indicated by cursor.
406 Optional prefix argument N specifies number of years.
407 Optional EVENT indicates a buffer position to use instead of point."
408 (interactive (list (prefix-numeric-value current-prefix-arg
)
411 (let ((year (calendar-extract-year (calendar-cursor-to-date t event
))))
412 (cal-tex-preamble "twoside")
413 (cal-tex-filofax-paper 'year
)
414 (cal-tex-cmd "\\fboxsep 0.5mm")
415 (cal-tex-cmd "\\pagestyle" "empty")
417 (cal-tex-vspace "0.25in")
419 (insert (format "\\hfil \\textbf{\\Large %s} \\hfil\\\\\n" year
))
421 (cal-tex-b-parbox "l" "\\textwidth")
425 (let ((month-names; don't use default in case user changed it
426 ;; These are only used to define the command names, not
427 ;; the names of the months they insert.
428 ["January" "February" "March" "April" "May" "June"
429 "July" "August" "September" "October" "November" "December"]))
431 (insert (cal-tex-mini-calendar (1+ i
) year
(aref month-names i
)
432 "1in" ".9in" "tiny" "0.6mm"))))
434 "\\noindent\\fbox{\\January}\\fbox{\\February}\\fbox{\\March}\\\\
435 \\noindent\\fbox{\\April}\\fbox{\\May}\\fbox{\\June}\\\\
436 \\noindent\\fbox{\\July}\\fbox{\\August}\\fbox{\\September}\\\\
437 \\noindent\\fbox{\\October}\\fbox{\\November}\\fbox{\\December}
441 (setq year
(1+ year
))
443 (cal-tex-end-document)
445 (cal-tex-vspace "0.25in"))
446 (run-hooks 'cal-tex-year-hook
))
447 (run-hooks 'cal-tex-hook
)))
450 ;;; Monthly calendars
454 (defun cal-tex-cursor-month-landscape (&optional n event
)
455 "Make a LaTeX calendar buffer for the month the cursor is on.
456 Optional prefix argument N specifies number of months to be
457 produced (default 1). The output is in landscape format, one
458 month to a page. It shows holiday and diary entries if
459 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
460 Optional EVENT indicates a buffer position to use instead of point."
461 (interactive (list (prefix-numeric-value current-prefix-arg
)
464 (let* ((date (calendar-cursor-to-date t event
))
465 (month (calendar-extract-month date
))
466 (year (calendar-extract-year date
))
469 (cal-tex-which-days '(0 1 2 3 4 5 6))
470 (d1 (calendar-absolute-from-gregorian (list month
1 year
)))
472 (calendar-increment-month end-month end-year
(1- n
))
473 (calendar-absolute-from-gregorian
475 (calendar-last-day-of-month end-month end-year
)
477 (diary-list (if cal-tex-diary
(cal-tex-list-diary-entries d1 d2
)))
478 (holidays (if cal-tex-holidays
(holiday-in-range d1 d2
)))
479 other-month other-year small-months-at-start
)
480 (cal-tex-insert-preamble (cal-tex-number-weeks month year
1) t
"12pt")
481 (cal-tex-cmd cal-tex-cal-one-month
)
483 (setq other-month month
485 (calendar-increment-month other-month other-year -
1)
486 (insert (cal-tex-mini-calendar other-month other-year
"lastmonth"
487 "\\cellwidth" "\\cellheight"))
488 (calendar-increment-month other-month other-year
2)
489 (insert (cal-tex-mini-calendar other-month other-year
"nextmonth"
490 "\\cellwidth" "\\cellheight"))
491 (cal-tex-insert-month-header 1 month year month year
)
492 (cal-tex-insert-day-names)
494 (if (setq small-months-at-start
495 (< 1 (mod (- (calendar-day-of-week (list month
1 year
))
496 calendar-week-start-day
)
498 (insert "\\lastmonth\\nextmonth\\hspace*{-2\\cellwidth}"))
499 (cal-tex-insert-blank-days month year cal-tex-day-prefix
)
500 (cal-tex-insert-days month year diary-list holidays
502 (cal-tex-insert-blank-days-at-end month year cal-tex-day-prefix
)
503 (if (and (not small-months-at-start
)
504 (< 1 (mod (- (1- calendar-week-start-day
)
505 (calendar-day-of-week
507 (calendar-last-day-of-month month year
)
510 (insert "\\vspace*{-\\cellwidth}\\hspace*{-2\\cellwidth}"
511 "\\lastmonth\\nextmonth%
514 (run-hooks 'cal-tex-month-hook
)
516 (calendar-increment-month month year
1)
517 (cal-tex-vspace "-2cm")
518 (cal-tex-insert-preamble
519 (cal-tex-number-weeks month year
1) t
"12pt" t
))))
520 (cal-tex-end-document)
521 (run-hooks 'cal-tex-hook
))
524 (defun cal-tex-cursor-month (&optional n event
)
525 "Make a LaTeX calendar buffer for the month the cursor is on.
526 Optional prefix argument N specifies number of months to be
527 produced (default 1). The calendar is condensed onto one page.
528 It shows holiday and diary entries if `cal-tex-holidays' and
529 `cal-tex-diary', respectively, are non-nil. Optional EVENT
530 indicates a buffer position to use instead of point."
531 (interactive (list (prefix-numeric-value current-prefix-arg
)
534 (let* ((date (calendar-cursor-to-date t event
))
535 (month (calendar-extract-month date
))
536 (year (calendar-extract-year date
))
539 ;; FIXME -landscape sets cal-tex-which-days?
540 (d1 (calendar-absolute-from-gregorian (list month
1 year
)))
542 (calendar-increment-month end-month end-year
(1- n
))
543 (calendar-absolute-from-gregorian
545 (calendar-last-day-of-month end-month end-year
)
547 (diary-list (if cal-tex-diary
(cal-tex-list-diary-entries d1 d2
)))
548 (holidays (if cal-tex-holidays
(holiday-in-range d1 d2
))))
549 (cal-tex-insert-preamble (cal-tex-number-weeks month year n
) nil
"12pt")
551 (cal-tex-cmd cal-tex-cal-multi-month
)
552 (cal-tex-cmd cal-tex-cal-one-month
))
553 (cal-tex-insert-month-header n month year end-month end-year
)
554 (cal-tex-insert-day-names)
556 (cal-tex-insert-blank-days month year cal-tex-day-prefix
)
558 (cal-tex-insert-days month year diary-list holidays cal-tex-day-prefix
)
559 (when (= (calendar-week-end-day)
560 (calendar-day-of-week
562 (calendar-last-day-of-month month year
)
563 year
))) ; last day of month was last day of week
566 (calendar-increment-month month year
1))
567 (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix
))
568 (cal-tex-end-document)
569 (run-hooks 'cal-tex-hook
))
571 (defun cal-tex-insert-days (month year diary-list holidays day-format
)
572 "Insert LaTeX commands for a range of days in monthly calendars.
573 LaTeX commands are inserted for the days of the MONTH in YEAR.
574 Diary entries on DIARY-LIST are included. Holidays on HOLIDAYS
575 are included. Each day is formatted using format DAY-FORMAT."
576 (let ((blank-days ; at start of month
578 (- (calendar-day-of-week (list month
1 year
))
579 calendar-week-start-day
)
581 (last (calendar-last-day-of-month month year
))
584 (setq j
(1+ i
) ; 1-last, incl
585 date
(list month j year
))
586 (when (memq (calendar-day-of-week date
) cal-tex-which-days
)
587 (insert (format day-format
(cal-tex-month-name month
) j
))
588 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
589 (cal-tex-arg (cal-tex-latexify-list holidays date
))
590 (cal-tex-arg (eval cal-tex-daily-string
))
593 (when (and (zerop (mod (+ j blank-days
) 7))
598 (defun cal-tex-insert-day-names ()
599 "Insert the names of the days at top of a monthly calendar."
602 (if (memq (setq j
(mod (+ calendar-week-start-day i
) 7))
604 (insert (format cal-tex-day-name-format
605 (cal-tex-LaTeXify-string
606 (aref calendar-day-name-array j
)))))
609 (defun cal-tex-insert-month-header (n month year end-month end-year
)
610 "Create a title for a calendar.
611 A title is inserted for a calendar with N months starting with
612 MONTH YEAR and ending with END-MONTH END-YEAR."
613 (let ((month-name (cal-tex-month-name month
))
614 (end-month-name (cal-tex-month-name end-month
)))
616 (insert (format "\\calmonth{%s}{%s}\n\\vspace*{-0.5cm}"
618 (insert (format "\\calmonth{%s}{%s}{%s}{%s}\n\\vspace*{-0.5cm}"
619 month-name year end-month-name end-year
))))
622 (defun cal-tex-insert-blank-days (month year day-format
)
623 "Insert code for initial days not in calendar.
624 Insert LaTeX code for the blank days at the beginning of the MONTH in
625 YEAR. The entry is formatted using DAY-FORMAT. If the entire week is
626 blank, no days are inserted."
627 (if (cal-tex-first-blank-p month year
)
628 (let ((blank-days ; at start of month
630 (- (calendar-day-of-week (list month
1 year
))
631 calendar-week-start-day
)
633 (dotimes (i blank-days
)
634 (if (memq (mod (+ calendar-week-start-day i
) 7) cal-tex-which-days
)
635 (insert (format day-format
" " " ") "{}{}{}{}%\n"))))))
637 (defun cal-tex-insert-blank-days-at-end (month year day-format
)
638 "Insert code for final days not in calendar.
639 Insert LaTeX code for the blank days at the end of the MONTH in YEAR.
640 The entry is formatted using DAY-FORMAT."
641 (if (cal-tex-last-blank-p month year
)
642 (let* ((last-day (calendar-last-day-of-month month year
))
643 (blank-days ; at end of month
645 (- (calendar-day-of-week (list month last-day year
))
646 calendar-week-start-day
)
649 (while (<= (setq i
(1+ i
)) 6)
650 (if (memq (mod (+ calendar-week-start-day i
) 7) cal-tex-which-days
)
651 (insert (format day-format
"" "") "{}{}{}{}%\n"))))))
653 (defun cal-tex-first-blank-p (month year
)
654 "Determine if any days of the first week will be printed.
655 Return t if there will there be any days of the first week printed
656 in the calendar starting in MONTH YEAR."
657 ;; Check days 1-7 of the month, until we find the last day of the week.
661 (if (memq (setq dow
(calendar-day-of-week (list month
(1+ i
) year
)))
664 (if (= dow
(calendar-week-end-day)) (throw 'found nil
)))))))
666 (defun cal-tex-last-blank-p (month year
)
667 "Determine if any days of the last week will be printed.
668 Return t if there will there be any days of the last week printed
669 in the calendar starting in MONTH YEAR."
670 ;; Check backwards from the last day of the month, until we find the
671 ;; start of the last week in the month.
673 (let ((last-day (calendar-last-day-of-month month year
))
676 (if (memq (setq dow
(calendar-day-of-week
677 (list month
(- last-day i
) year
)))
680 (if (= dow calendar-week-start-day
) (throw 'found nil
)))))))
682 (defun cal-tex-number-weeks (month year n
)
683 "Determine the number of weeks in a range of dates.
684 Compute the number of weeks in the calendar starting with MONTH and YEAR,
685 and lasting N months, including only the days in WHICH-DAYS. As it stands,
686 this is only an upper bound."
687 (let ((d (list month
1 year
)))
688 (calendar-increment-month month year
(1- n
))
689 (/ (- (calendar-dayname-on-or-before
690 calendar-week-start-day
691 (+ 7 (calendar-absolute-from-gregorian
692 (list month
(calendar-last-day-of-month month year
) year
))))
693 (calendar-dayname-on-or-before
694 calendar-week-start-day
695 (calendar-absolute-from-gregorian d
)))
702 (defconst cal-tex-LaTeX-hourbox
703 "\\newcommand{\\hourbox}[2]%
704 {\\makebox[2em]{\\rule{0cm}{#2ex}#1}\\rule{3in}{.15mm}}\n"
705 "One hour and a line on the right.")
707 (defun cal-tex-weekly-paper (&optional nomargins
)
708 "Insert some page size settings for weekly layouts."
709 (insert "\\textwidth 6.5in
712 (or nomargins
(insert "\\oddsidemargin 0in
716 ;; TODO cal-tex-diary-support.
717 ;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
719 (defun cal-tex-cursor-week (&optional n event
)
720 "Make a LaTeX calendar buffer for a two-page one-week calendar.
721 It applies to the week that point is in. The optional prefix
722 argument N specifies number of weeks (default 1). The calendar
723 shows holidays if `cal-tex-holidays' is non-nil (note that diary
724 entries are not shown). The calendar shows the hours 8-12am, 1-5pm."
725 (interactive (list (prefix-numeric-value current-prefix-arg
)
728 (let* ((date (calendar-gregorian-from-absolute
729 (calendar-dayname-on-or-before
730 calendar-week-start-day
731 (calendar-absolute-from-gregorian
732 (calendar-cursor-to-date t event
)))))
733 (month (calendar-extract-month date
))
734 (year (calendar-extract-year date
))
735 (d1 (calendar-absolute-from-gregorian date
))
737 (holidays (if cal-tex-holidays
738 (holiday-in-range d1 d2
))))
739 (cal-tex-preamble "11pt")
740 (cal-tex-weekly-paper)
741 (insert cal-tex-LaTeX-hourbox
)
743 (cal-tex-cmd "\\pagestyle" "empty")
745 (cal-tex-vspace "-1.5in")
747 (cal-tex-Huge-bf (format "\\uppercase{%s}"
748 (cal-tex-month-name month
)))
749 (cal-tex-hspace "2em")
750 (cal-tex-Huge-bf (number-to-string year
))
753 (cal-tex-hspace "-.2in")
754 (cal-tex-b-parbox "l" "7in")
756 (cal-tex-week-hours date holidays
"3.1")
757 (setq date
(cal-tex-incr-date date
)))
759 (setq month
(calendar-extract-month date
)
760 year
(calendar-extract-year date
))
762 (run-hooks 'cal-tex-week-hook
)
764 (cal-tex-end-document)
765 (run-hooks 'cal-tex-hook
)))
767 ;; TODO cal-tex-diary support.
768 ;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
770 (defun cal-tex-cursor-week2 (&optional n event
)
771 "Make a LaTeX calendar buffer for a two-page one-week calendar.
772 It applies to the week that point is in. Optional prefix
773 argument N specifies number of weeks (default 1). The calendar
774 shows holidays if `cal-tex-holidays' is non-nil (note that diary
775 entries are not shown). The calendar shows the hours 8-12am, 1-5pm.
776 Optional EVENT indicates a buffer position to use instead of point."
777 (interactive (list (prefix-numeric-value current-prefix-arg
)
780 (let* ((date (calendar-gregorian-from-absolute
781 (calendar-dayname-on-or-before
782 calendar-week-start-day
783 (calendar-absolute-from-gregorian
784 (calendar-cursor-to-date t event
)))))
785 (month (calendar-extract-month date
))
786 (year (calendar-extract-year date
))
787 (d1 (calendar-absolute-from-gregorian date
))
789 (holidays (if cal-tex-holidays
790 (holiday-in-range d1 d2
))))
791 (cal-tex-preamble "12pt")
792 (cal-tex-weekly-paper)
793 (insert cal-tex-LaTeX-hourbox
)
795 (cal-tex-cmd "\\pagestyle" "empty")
797 (cal-tex-vspace "-1.5in")
799 (cal-tex-Huge-bf (format "\\uppercase{%s}"
800 (cal-tex-month-name month
)))
801 (cal-tex-hspace "2em")
802 (cal-tex-Huge-bf (number-to-string year
))
805 (cal-tex-hspace "-.2in")
806 (cal-tex-b-parbox "l" "\\textwidth")
808 (cal-tex-week-hours date holidays
"5")
809 (setq date
(cal-tex-incr-date date
)))
812 (insert (cal-tex-mini-calendar
813 (calendar-extract-month (cal-tex-previous-month date
))
814 (calendar-extract-year (cal-tex-previous-month date
))
815 "lastmonth" "1.1in" "1in"))
816 (insert (cal-tex-mini-calendar
817 (calendar-extract-month date
)
818 (calendar-extract-year date
)
819 "thismonth" "1.1in" "1in"))
820 (insert (cal-tex-mini-calendar
821 (calendar-extract-month (cal-tex-next-month date
))
822 (calendar-extract-year (cal-tex-next-month date
))
823 "nextmonth" "1.1in" "1in"))
824 (insert "\\hbox to \\textwidth{")
826 (insert "\\lastmonth")
828 (insert "\\thismonth")
830 (insert "\\nextmonth")
834 (cal-tex-b-parbox "l" "\\textwidth")
836 (cal-tex-week-hours date holidays
"5")
837 (setq date
(cal-tex-incr-date date
)))
839 (setq month
(calendar-extract-month date
)
840 year
(calendar-extract-year date
))
842 (run-hooks 'cal-tex-week-hook
)
844 (cal-tex-end-document)
845 (run-hooks 'cal-tex-hook
)))
847 (autoload 'calendar-iso-from-absolute
"cal-iso")
850 (defun cal-tex-cursor-week-iso (&optional n event
)
851 "Make a LaTeX calendar buffer for a one page ISO-style weekly calendar.
852 Optional prefix argument N specifies number of weeks (default 1).
853 The calendar shows holiday and diary entries if
854 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
855 It does not show hours of the day. Optional EVENT indicates a buffer
856 position to use instead of point."
857 (interactive (list (prefix-numeric-value current-prefix-arg
)
860 (let* ((date (calendar-gregorian-from-absolute
861 (calendar-dayname-on-or-before
863 (calendar-absolute-from-gregorian
864 (calendar-cursor-to-date t event
)))))
865 (month (calendar-extract-month date
))
866 (year (calendar-extract-year date
))
867 (day (calendar-extract-day date
))
868 (d1 (calendar-absolute-from-gregorian date
))
870 (holidays (if cal-tex-holidays
871 (holiday-in-range d1 d2
)))
872 (diary-list (if cal-tex-diary
873 (cal-tex-list-diary-entries d1 d2
)))
875 (cal-tex-preamble "11pt")
876 (cal-tex-weekly-paper)
878 (cal-tex-cmd "\\pagestyle" "empty")
880 (cal-tex-vspace "-1.5in")
883 (let ((d (calendar-iso-from-absolute
884 (calendar-absolute-from-gregorian date
))))
885 (format "Week %d of %d"
886 (calendar-extract-month d
)
887 (calendar-extract-year d
))))
890 (cal-tex-b-parbox "l" "\\textwidth")
892 (cal-tex-b-parbox "t" "\\textwidth")
893 (cal-tex-b-parbox "t" "\\textwidth")
894 (cal-tex-rule "0pt" "\\textwidth" ".2mm")
896 (cal-tex-b-parbox "t" "\\textwidth")
897 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
899 (cal-tex-large-bf (cal-tex-month-name month
))
901 (cal-tex-large-bf (number-to-string day
))
902 (unless (string-equal "" (setq s
(cal-tex-latexify-list
903 holidays date
"; ")))
905 (cal-tex-large-bf s
))
907 (insert " " (eval cal-tex-daily-string
))
911 (cal-tex-b-parbox "t" "\\textwidth")
912 (unless (string-equal "" (setq s
(cal-tex-latexify-list
914 (insert "\\vbox to 0pt{")
919 (setq date
(cal-tex-incr-date date
)
920 month
(calendar-extract-month date
)
921 day
(calendar-extract-day date
))
923 (cal-tex-e-parbox "2cm")
925 (setq month
(calendar-extract-month date
)
926 year
(calendar-extract-year date
)))
929 (run-hooks 'cal-tex-week-hook
)
931 (cal-tex-end-document)
932 (run-hooks 'cal-tex-hook
)))
934 ;; TODO respect cal-tex-daily-start,end?
935 ;; Using different numbers of hours will probably break some layouts.
936 (defun cal-tex-week-hours (date holidays height
)
937 "Insert hourly entries for DATE with HOLIDAYS, with line height HEIGHT.
938 Uses the 24-hour clock if `cal-tex-24' is non-nil. Note that the hours
939 shown are hard-coded to 8-12, 13-17."
940 (let ((month (calendar-extract-month date
))
941 (day (calendar-extract-day date
))
942 (year (calendar-extract-year date
))
944 (cal-tex-comment "begin cal-tex-week-hours")
945 (cal-tex-cmd "\\ \\\\[-.2cm]")
946 (cal-tex-cmd "\\noindent")
947 (cal-tex-b-parbox "l" "6.8in")
948 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
950 (cal-tex-large-bf (cal-tex-month-name month
))
952 (cal-tex-large-bf (number-to-string day
))
953 (unless (string-equal "" (setq s
(cal-tex-latexify-list
954 holidays date
"; ")))
956 (cal-tex-large-bf s
))
958 (insert " " (eval cal-tex-daily-string
))
961 (cal-tex-rule "0pt" "6.8in" ".2mm")
964 (setq morning
(+ i
8) ; 8-12 incl
965 afternoon
(if cal-tex-24
966 (+ i
13) ; 13-17 incl
968 (cal-tex-cmd "\\hourbox" (number-to-string morning
))
970 (cal-tex-hspace ".4cm")
971 (cal-tex-cmd "\\hourbox" (number-to-string afternoon
))
975 ;; TODO cal-tex-diary support.
976 ;; TODO respect cal-tex-daily-start,end (see cal-tex-weekly4-box).
978 (defun cal-tex-cursor-week-monday (&optional n event
)
979 "Make a LaTeX calendar buffer for a two-page one-week calendar.
980 It applies to the week that point is in, and starts on Monday.
981 Optional prefix argument N specifies number of weeks (default 1).
982 The calendar shows holidays if `cal-tex-holidays' is
983 non-nil (note that diary entries are not shown). The calendar shows
984 the hours 8-12am, 1-5pm. Optional EVENT indicates a buffer position
985 to use instead of point."
986 (interactive (list (prefix-numeric-value current-prefix-arg
)
989 (let ((date (calendar-gregorian-from-absolute
990 (calendar-dayname-on-or-before
992 (calendar-absolute-from-gregorian
993 (calendar-cursor-to-date t event
))))))
994 (cal-tex-preamble "11pt")
995 (cal-tex-weekly-paper)
998 (cal-tex-vspace "-1cm")
999 (insert "\\noindent ")
1000 (cal-tex-weekly4-box (cal-tex-incr-date date
) nil
)
1001 (cal-tex-weekly4-box (cal-tex-incr-date date
4) nil
)
1003 (cal-tex-weekly4-box (cal-tex-incr-date date
2) nil
)
1004 (cal-tex-weekly4-box (cal-tex-incr-date date
5) nil
)
1006 (cal-tex-weekly4-box (cal-tex-incr-date date
3) nil
)
1007 (cal-tex-weekly4-box (cal-tex-incr-date date
6) t
)
1008 (unless (= i
(1- n
))
1009 (run-hooks 'cal-tex-week-hook
)
1010 (setq date
(cal-tex-incr-date date
7))
1012 (cal-tex-end-document)
1013 (run-hooks 'cal-tex-hook
)))
1015 ;; TODO respect cal-tex-daily-start,end?
1016 ;; Using different numbers of hours will probably break some layouts.
1017 (defun cal-tex-weekly4-box (date weekend
)
1018 "Make one box for DATE, different if WEEKEND.
1019 Uses the 24-hour clock if `cal-tex-24' is non-nil. Note that the hours
1020 shown are hard-coded to 8-12, 13-17."
1021 (let* ((day (calendar-extract-day date
))
1022 (month (calendar-extract-month date
))
1023 (year (calendar-extract-year date
))
1024 (dayname (cal-tex-LaTeXify-string (calendar-day-name date
)))
1025 (date1 (cal-tex-incr-date date
))
1026 (day1 (calendar-extract-day date1
))
1027 (month1 (calendar-extract-month date1
))
1028 (year1 (calendar-extract-year date1
))
1029 (dayname1 (cal-tex-LaTeXify-string (calendar-day-name date1
))))
1030 (cal-tex-b-framebox "8cm" "l")
1031 (cal-tex-b-parbox "b" "7.5cm")
1032 (insert (format "\\textbf{\\Large %s,} %s/%s/%s\\\\\n"
1033 dayname month day year
))
1034 (cal-tex-rule "0pt" "7.5cm" ".5mm")
1038 (insert (format "\\textsf{\\large %d}\\\\\n" (+ i
8))))
1040 (insert (format "\\textsf{\\large %d}\\\\\n"
1042 (+ i
13) ; 13-17 incl
1043 (1+ i
)))))) ; 1-5 incl
1046 (cal-tex-vspace "1cm")
1047 (insert "\\ \\vfill")
1048 (insert (format "\\textbf{\\Large %s,} %s/%s/%s\\\\\n"
1049 dayname1 month1 day1 year1
))
1050 (cal-tex-rule "0pt" "7.5cm" ".5mm")
1051 (cal-tex-nl "1.5cm")
1052 (cal-tex-vspace "1cm"))
1054 (cal-tex-e-framebox)
1055 (cal-tex-hspace "1cm")))
1057 (defun cal-tex-weekly-common (n event
&optional filofax
)
1058 "Common code for weekly calendars."
1060 (let* ((date (calendar-gregorian-from-absolute
1061 (calendar-dayname-on-or-before
1063 (calendar-absolute-from-gregorian
1064 (calendar-cursor-to-date t event
)))))
1065 (month (calendar-extract-month date
))
1066 (year (calendar-extract-year date
))
1067 (day (calendar-extract-day date
))
1068 (d1 (calendar-absolute-from-gregorian date
))
1070 (holidays (if cal-tex-holidays
1071 (holiday-in-range d1 d2
)))
1072 (diary-list (if cal-tex-diary
1073 (cal-tex-list-diary-entries d1 d2
))))
1076 (cal-tex-preamble "twoside")
1077 (cal-tex-filofax-paper)
1078 (insert cal-tex-righthead
)
1079 (cal-tex-longday "rightday" "1.85in")
1080 (cal-tex-longday "weekend" "0.8in")
1081 (insert cal-tex-lefthead
)
1082 (cal-tex-longday "leftday" "1.85in"))
1083 (cal-tex-preamble "twoside,12pt")
1084 (insert "\\textwidth 7in
1087 \\evensidemargin 0in
1089 \\headheight -0.875in
1093 (insert cal-tex-righthead
)
1094 (cal-tex-longday "rightday" "2.75in")
1095 (cal-tex-longday "weekend" "1.8in")
1096 (insert cal-tex-lefthead
)
1097 (cal-tex-longday "leftday" "2.75in"))
1098 (cal-tex-b-document)
1099 (cal-tex-cmd "\\pagestyle" "empty")
1100 ;; Let's assume this is something to with twopage documents.
1101 ;; It has the downside that we start with a blank page.
1102 ;; It doesn't make obvious sense when oddside and evenside margins
1103 ;; are the same (non-filofax), but consider the left and right
1104 ;; versions of various functions as applicable to even and odd pages.
1107 (insert "\\lefthead")
1109 (let ((d (cal-tex-incr-date date
2)))
1110 (if (= (calendar-extract-month date
)
1111 (calendar-extract-month d
))
1113 (cal-tex-month-name (calendar-extract-month date
))
1114 (calendar-extract-year date
))
1115 (if (= (calendar-extract-year date
)
1116 (calendar-extract-year d
))
1117 (format "%s---%s %s"
1118 (cal-tex-month-name (calendar-extract-month date
))
1119 (cal-tex-month-name (calendar-extract-month d
))
1120 (calendar-extract-year date
))
1121 (format "%s %s---%s %s"
1122 (cal-tex-month-name (calendar-extract-month date
))
1123 (calendar-extract-year date
)
1124 (cal-tex-month-name (calendar-extract-month d
))
1125 (calendar-extract-year d
))))))
1127 (dotimes (_jdummy 3)
1128 (insert "\\leftday")
1129 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1130 (cal-tex-arg (number-to-string (calendar-extract-day date
)))
1131 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1132 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1133 (cal-tex-arg (eval cal-tex-daily-string
))
1135 (setq date
(cal-tex-incr-date date
)))
1136 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1139 (insert (cal-tex-mini-calendar
1140 (calendar-extract-month (cal-tex-previous-month date
))
1141 (calendar-extract-year (cal-tex-previous-month date
))
1142 "lastmonth" "1.1in" "1in"))
1143 (insert (cal-tex-mini-calendar
1144 (calendar-extract-month date
)
1145 (calendar-extract-year date
)
1146 "thismonth" "1.1in" "1in"))
1147 (insert (cal-tex-mini-calendar
1148 (calendar-extract-month (cal-tex-next-month date
))
1149 (calendar-extract-year (cal-tex-next-month date
))
1150 "nextmonth" "1.1in" "1in"))
1151 (insert "\\hbox to \\textwidth{")
1153 (insert "\\lastmonth")
1155 (insert "\\thismonth")
1157 (insert "\\nextmonth")
1161 (insert "\\righthead")
1163 (let ((d (cal-tex-incr-date date
3)))
1164 (if (= (calendar-extract-month date
)
1165 (calendar-extract-month d
))
1167 (cal-tex-month-name (calendar-extract-month date
))
1168 (calendar-extract-year date
))
1169 (if (= (calendar-extract-year date
)
1170 (calendar-extract-year d
))
1171 (format "%s---%s %s"
1172 (cal-tex-month-name (calendar-extract-month date
))
1173 (cal-tex-month-name (calendar-extract-month d
))
1174 (calendar-extract-year date
))
1175 (format "%s %s---%s %s"
1176 (cal-tex-month-name (calendar-extract-month date
))
1177 (calendar-extract-year date
)
1178 (cal-tex-month-name (calendar-extract-month d
))
1179 (calendar-extract-year d
))))))
1181 (dotimes (_jdummy 2)
1182 (insert "\\rightday")
1183 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1184 (cal-tex-arg (number-to-string (calendar-extract-day date
)))
1185 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1186 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1187 (cal-tex-arg (eval cal-tex-daily-string
))
1189 (setq date
(cal-tex-incr-date date
)))
1190 (dotimes (_jdummy 2)
1191 (insert "\\weekend")
1192 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1193 (cal-tex-arg (number-to-string (calendar-extract-day date
)))
1194 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1195 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1196 (cal-tex-arg (eval cal-tex-daily-string
))
1198 (setq date
(cal-tex-incr-date date
)))
1199 (unless (= i
(1- n
))
1200 (run-hooks 'cal-tex-week-hook
)
1202 (cal-tex-end-document)
1203 (run-hooks 'cal-tex-hook
)))
1206 (defun cal-tex-cursor-week-at-a-glance (&optional n event
)
1207 "One-week-at-a-glance full page calendar for week indicated by cursor.
1208 Optional prefix argument N specifies number of weeks (default 1),
1209 starting on Mondays. The calendar shows holiday and diary entries
1210 if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
1211 It does not show hours of the day. Optional EVENT indicates a buffer
1212 position to use instead of point."
1213 (interactive (list (prefix-numeric-value current-prefix-arg
)
1214 last-nonmenu-event
))
1215 (cal-tex-weekly-common n event
))
1218 (defun cal-tex-cursor-filofax-2week (&optional n event
)
1219 "Two-weeks-at-a-glance Filofax style calendar for week cursor is in.
1220 Optional prefix argument N specifies number of weeks (default 1).
1221 The calendar shows holiday and diary entries if
1222 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
1223 Optional EVENT indicates a buffer position to use instead of point."
1224 (interactive (list (prefix-numeric-value current-prefix-arg
)
1225 last-nonmenu-event
))
1227 (let* ((date (calendar-gregorian-from-absolute
1228 (calendar-dayname-on-or-before
1229 calendar-week-start-day
1230 (calendar-absolute-from-gregorian
1231 (calendar-cursor-to-date t event
)))))
1232 (month (calendar-extract-month date
))
1233 (year (calendar-extract-year date
))
1234 (day (calendar-extract-day date
))
1235 (d1 (calendar-absolute-from-gregorian date
))
1237 (holidays (if cal-tex-holidays
1238 (holiday-in-range d1 d2
)))
1239 (diary-list (if cal-tex-diary
1240 (cal-tex-list-diary-entries d1 d2
))))
1241 (cal-tex-preamble "twoside")
1242 (cal-tex-filofax-paper)
1243 (insert cal-tex-righthead
)
1244 (cal-tex-longday "rightday" "0.7in")
1245 (insert cal-tex-lefthead
)
1246 (cal-tex-longday "leftday" "0.7in")
1247 (cal-tex-b-document)
1248 (cal-tex-cmd "\\pagestyle" "empty")
1250 (if (zerop (mod i
2))
1251 (insert "\\righthead")
1252 (insert "\\lefthead"))
1254 (let ((d (cal-tex-incr-date date
6)))
1255 (if (= (calendar-extract-month date
)
1256 (calendar-extract-month d
))
1258 (cal-tex-month-name (calendar-extract-month date
))
1259 (calendar-extract-year date
))
1260 (if (= (calendar-extract-year date
)
1261 (calendar-extract-year d
))
1262 (format "%s---%s %s"
1263 (cal-tex-month-name (calendar-extract-month date
))
1264 (cal-tex-month-name (calendar-extract-month d
))
1265 (calendar-extract-year date
))
1266 (format "%s %s---%s %s"
1267 (cal-tex-month-name (calendar-extract-month date
))
1268 (calendar-extract-year date
)
1269 (cal-tex-month-name (calendar-extract-month d
))
1270 (calendar-extract-year d
))))))
1272 (dotimes (_jdummy 7)
1273 (if (zerop (mod i
2))
1274 (insert "\\rightday")
1275 (insert "\\leftday"))
1276 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1277 (cal-tex-arg (number-to-string (calendar-extract-day date
)))
1278 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1279 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1280 (cal-tex-arg (eval cal-tex-daily-string
))
1282 (setq date
(cal-tex-incr-date date
)))
1283 (unless (= i
(1- n
))
1284 (run-hooks 'cal-tex-week-hook
)
1286 (cal-tex-end-document)
1287 (run-hooks 'cal-tex-hook
)))
1290 (defun cal-tex-cursor-filofax-week (&optional n event
)
1291 "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
1292 Optional prefix argument N specifies number of weeks (default 1),
1293 starting on Mondays. The calendar shows holiday and diary entries
1294 if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
1295 Optional EVENT indicates a buffer position to use instead of point."
1296 (interactive (list (prefix-numeric-value current-prefix-arg
)
1297 last-nonmenu-event
))
1298 (cal-tex-weekly-common n event t
))
1301 (defun cal-tex-cursor-filofax-daily (&optional n event
)
1302 "Day-per-page Filofax style calendar for week indicated by cursor.
1303 Optional prefix argument N specifies number of weeks (default 1),
1304 starting on Mondays. The calendar shows holiday and diary
1305 entries if `cal-tex-holidays' and `cal-tex-diary', respectively,
1306 are non-nil. Pages are ruled if `cal-tex-rules' is non-nil.
1307 Optional EVENT indicates a buffer position to use instead of point."
1308 (interactive (list (prefix-numeric-value current-prefix-arg
)
1309 last-nonmenu-event
))
1311 (let* ((date (calendar-gregorian-from-absolute
1312 (calendar-dayname-on-or-before
1314 (calendar-absolute-from-gregorian
1315 (calendar-cursor-to-date t event
)))))
1316 (month (calendar-extract-month date
))
1317 (year (calendar-extract-year date
))
1318 (day (calendar-extract-day date
))
1319 (d1 (calendar-absolute-from-gregorian date
))
1321 (holidays (if cal-tex-holidays
1322 (holiday-in-range d1 d2
)))
1323 (diary-list (if cal-tex-diary
1324 (cal-tex-list-diary-entries d1 d2
))))
1325 (cal-tex-preamble "twoside")
1326 (cal-tex-filofax-paper)
1327 (insert cal-tex-righthead
)
1328 (cal-tex-shortday "rightday")
1329 (cal-tex-shortday "weekend")
1330 (insert cal-tex-lefthead
)
1331 (cal-tex-shortday "leftday")
1332 (insert "\\newbox\\LineBox
1333 \\setbox\\LineBox=\\hbox to\\textwidth{%
1334 \\vrule height.2in width0pt\\leaders\\hrule\\hfill}
1335 \\def\\linesfill{\\par\\leaders\\copy\\LineBox\\vfill}
1337 (cal-tex-b-document)
1338 (cal-tex-cmd "\\pagestyle" "empty")
1341 (let ((even (zerop (% j
2))))
1345 (cal-tex-arg (calendar-date-string date
))
1350 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1351 (cal-tex-arg (cal-tex-latexify-list holidays date
"\\\\" t
))
1352 (cal-tex-arg (eval cal-tex-daily-string
))
1355 (insert "\\linesfill\n")
1356 (insert "\\vfill\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1358 (setq date
(cal-tex-incr-date date
)))
1360 (dotimes (_jdummy 2)
1361 (insert "\\lefthead")
1362 (cal-tex-arg (calendar-date-string date
))
1363 (insert "\\weekend")
1364 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1365 (cal-tex-arg (cal-tex-latexify-list holidays date
"\\\\" t
))
1366 (cal-tex-arg (eval cal-tex-daily-string
))
1369 (insert "\\linesfill\n")
1371 (setq date
(cal-tex-incr-date date
)))
1373 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1374 (unless (= i
(1- n
))
1375 (run-hooks 'cal-tex-week-hook
)
1377 (cal-tex-end-document)
1378 (run-hooks 'cal-tex-hook
)))
1386 (defun cal-tex-cursor-day (&optional n event
)
1387 "Make a buffer with LaTeX commands for the day cursor is on.
1388 Optional prefix argument N specifies number of days. The calendar shows
1389 the hours between `cal-tex-daily-start' and `cal-tex-daily-end', using
1390 the 24-hour clock if `cal-tex-24' is non-nil. Optional EVENT indicates
1391 a buffer position to use instead of point."
1392 (interactive (list (prefix-numeric-value current-prefix-arg
)
1393 last-nonmenu-event
))
1395 (let ((date (calendar-absolute-from-gregorian
1396 (calendar-cursor-to-date t event
))))
1397 (cal-tex-preamble "12pt")
1398 (cal-tex-weekly-paper 'nomargins
)
1399 (cal-tex-b-document)
1400 (cal-tex-cmd "\\pagestyle" "empty")
1402 (cal-tex-vspace "-1.7in")
1403 (cal-tex-daily-page (calendar-gregorian-from-absolute date
))
1404 (setq date
(1+ date
))
1405 (unless (= i
(1- n
))
1407 (run-hooks 'cal-tex-daily-hook
)))
1408 (cal-tex-end-document)
1409 (run-hooks 'cal-tex-hook
)))
1411 (defun cal-tex-daily-page (date)
1412 "Make a calendar page for Gregorian DATE on 8.5 by 11 paper.
1413 Uses the 24-hour clock if `cal-tex-24' is non-nil. Produces
1414 hourly sections for the period specified by `cal-tex-daily-start'
1415 and `cal-tex-daily-end'."
1416 (let ((month-name (cal-tex-month-name (calendar-extract-month date
)))
1417 (i (1- cal-tex-daily-start
))
1419 (cal-tex-banner "cal-tex-daily-page")
1420 (cal-tex-b-makebox "4cm" "l")
1421 (cal-tex-b-parbox "b" "3.8cm")
1422 (cal-tex-rule "0mm" "0mm" "2cm")
1423 (cal-tex-Huge (number-to-string (calendar-extract-day date
)))
1425 (cal-tex-bf month-name
)
1427 (cal-tex-hspace "1cm")
1428 (cal-tex-scriptsize (eval cal-tex-daily-string
))
1429 (cal-tex-hspace "3.5cm")
1432 (cal-tex-b-makebox "4cm" "r")
1433 (cal-tex-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
1436 (cal-tex-hspace ".4cm")
1437 (cal-tex-rule "0mm" "16.1cm" "1mm")
1439 (while (<= (setq i
(1+ i
)) cal-tex-daily-end
)
1440 (cal-tex-cmd "\\noindent")
1441 (setq hour
(if cal-tex-24
1444 (if (zerop hour
) (setq hour
12))
1445 (cal-tex-b-makebox "1cm" "c")
1446 (cal-tex-arg (number-to-string hour
))
1448 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1450 (cal-tex-b-makebox "1cm" "c")
1451 (cal-tex-arg "$\\diamond$" )
1453 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1454 (cal-tex-nl ".2cm"))
1456 (insert (cal-tex-mini-calendar
1457 (calendar-extract-month (cal-tex-previous-month date
))
1458 (calendar-extract-year (cal-tex-previous-month date
))
1459 "lastmonth" "1.1in" "1in"))
1460 (insert (cal-tex-mini-calendar
1461 (calendar-extract-month date
)
1462 (calendar-extract-year date
)
1463 "thismonth" "1.1in" "1in"))
1464 (insert (cal-tex-mini-calendar
1465 (calendar-extract-month (cal-tex-next-month date
))
1466 (calendar-extract-year (cal-tex-next-month date
))
1467 "nextmonth" "1.1in" "1in"))
1468 (insert "\\hbox to \\textwidth{")
1470 (insert "\\lastmonth")
1472 (insert "\\thismonth")
1474 (insert "\\nextmonth")
1477 (cal-tex-banner "end of cal-tex-daily-page")))
1483 (defun cal-tex-mini-calendar (month year name width height
&optional ptsize colsep
)
1484 "Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT.
1485 Optional string PTSIZE gives the point size (default \"scriptsize\").
1486 Optional string COLSEP gives the column separation (default \"1mm\")."
1487 (or colsep
(setq colsep
"1mm"))
1488 (or ptsize
(setq ptsize
"scriptsize"))
1489 (let ((blank-days ; at start of month
1491 (- (calendar-day-of-week (list month
1 year
))
1492 calendar-week-start-day
)
1494 (last( calendar-last-day-of-month month year
))
1495 (str (concat "\\def\\" name
"{\\hbox to" width
"{%\n"
1496 "\\vbox to" height
"{%\n"
1497 "\\vfil \\hbox to" width
"{%\n"
1500 "{@{\\hspace{0mm}}r@{\\hspace{" colsep
1501 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{" colsep
1502 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{" colsep
1503 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{0mm}}}%\n"
1504 "\\multicolumn{7}{c}{"
1505 (cal-tex-month-name month
)
1507 (number-to-string year
)
1512 (cal-tex-LaTeXify-string
1513 (substring (aref calendar-day-name-array
1514 (mod (+ calendar-week-start-day i
) 7))
1520 (dotimes (_idummy blank-days
)
1521 (setq str
(concat str
" & ")))
1523 (setq str
(concat str
(number-to-string (1+ i
)))
1524 str
(concat str
(if (zerop (mod (+ i
1 blank-days
) 7))
1529 (setq str
(concat str
"\n\\end{tabular}\\hfil}\\vfil}}}%\n"))
1533 ;;; Various calendar functions
1536 (defun cal-tex-incr-date (date &optional n
)
1537 "The date of the day following DATE.
1538 If optional N is given, the date of N days after DATE."
1539 (calendar-gregorian-from-absolute
1540 (+ (or n
1) (calendar-absolute-from-gregorian date
))))
1542 (defun cal-tex-latexify-list (date-list date
&optional separator final-separator
)
1543 "Return string with concatenated, LaTeX-ified entries in DATE-LIST for DATE.
1544 Use double backslash as a separator unless optional SEPARATOR is given.
1545 If resulting string is not empty, put separator at end if optional
1546 FINAL-SEPARATOR is non-nil."
1547 (or separator
(setq separator
"\\\\"))
1550 (mapconcat (lambda (x) (cal-tex-LaTeXify-string x
))
1551 (dolist (d date-list
(reverse result
))
1553 (calendar-date-equal date
(car d
))
1554 (setq result
(cons (cadr d
) result
))))
1556 (if (and final-separator
1557 (not (string-equal result
"")))
1558 (concat result separator
)
1561 (defun cal-tex-previous-month (date)
1562 "Return the date of the first day in the month previous to DATE."
1563 (let ((month (calendar-extract-month date
))
1564 (year (calendar-extract-year date
)))
1565 (calendar-increment-month month year -
1)
1566 (list month
1 year
)))
1568 (defun cal-tex-next-month (date)
1569 "Return the date of the first day in the month following DATE."
1570 (let ((month (calendar-extract-month date
))
1571 (year (calendar-extract-year date
)))
1572 (calendar-increment-month month year
1)
1573 (list month
1 year
)))
1579 (defun cal-tex-end-document ()
1580 "Finish the LaTeX document.
1581 Insert the trailer to LaTeX document, pop to LaTeX buffer, add
1582 informative header, and run HOOK."
1583 (cal-tex-e-document)
1584 (or (and cal-tex-preamble-extra
1585 (string-match "inputenc" cal-tex-preamble-extra
))
1586 (when (re-search-backward "[^[:ascii:]]" nil
'move
)
1587 (goto-char (point-min))
1588 (when (search-forward "documentclass" nil t
)
1590 ;; Eg for some Bahai holidays.
1591 ;; FIXME latin1 might not always be right.
1592 (insert "\\usepackage[latin1]{inputenc}\n"))))
1594 (pop-to-buffer (current-buffer))
1595 (goto-char (point-min))
1596 ;; FIXME auctex equivalents?
1598 (format "\tThis buffer was produced by cal-tex.el.
1599 \tTo print a calendar, type
1600 \t\tM-x tex-buffer RET
1601 \t\tM-x tex-print RET")))
1603 (defun cal-tex-insert-preamble (weeks landscape size
&optional append
)
1604 "Initialize the output LaTeX calendar buffer, `cal-tex-buffer'.
1605 Select the output buffer, and insert the preamble for a calendar
1606 of WEEKS weeks. Insert code for landscape mode if LANDSCAPE is
1607 non-nil. Use point-size SIZE. Optional argument APPEND, if
1608 non-nil, means add to end of buffer without erasing current contents."
1609 (let ((width "18cm")
1615 (cal-tex-preamble size
)
1618 (cal-tex-cmd "\\oddsidemargin -1.75cm")
1619 (cal-tex-cmd "\\def\\holidaymult" ".06"))
1620 (cal-tex-cmd "\\special" "landscape")
1621 (cal-tex-cmd "\\textwidth 9.5in")
1622 (cal-tex-cmd "\\textheight 7in")
1624 (cal-tex-cmd "\\def\\holidaymult" ".08"))
1625 (cal-tex-cmd cal-tex-caldate
)
1626 (cal-tex-cmd cal-tex-myday
)
1627 (cal-tex-b-document)
1628 (cal-tex-cmd "\\pagestyle" "empty"))
1629 (cal-tex-cmd "\\setlength{\\cellwidth}" width
)
1630 (insert (format "\\setlength{\\cellwidth}{%f\\cellwidth}\n"
1631 (/ 1.1 (length cal-tex-which-days
))))
1632 (cal-tex-cmd "\\setlength{\\cellheight}" height
)
1633 (insert (format "\\setlength{\\cellheight}{%f\\cellheight}\n"
1635 (cal-tex-cmd "\\ \\par")
1636 (cal-tex-vspace "-3cm")))
1638 (defconst cal-tex-LaTeX-subst-list
1640 ("\"".
"''") ; quote changes meaning when list is reversed
1641 ;; Don't think this is necessary, and in any case, does not work:
1642 ;; "LaTeX Error: \verb illegal in command argument".
1643 ;;; ("@" . "\\verb|@|")
1653 ("\n" .
"\\ \\\\")) ; \\ needed for e.g \begin{center}\n AA\end{center}
1654 "Alist of symbols and their LaTeX replacements.")
1656 (defun cal-tex-LaTeXify-string (string)
1657 "Protect special characters in STRING from LaTeX."
1662 (list cal-tex-LaTeX-subst-list
)
1664 (while (not (string-equal tail
""))
1665 (setq ch
(substring-no-properties tail
0 1)
1666 pair
(assoc ch list
))
1667 (if (and pair
(string-equal ch
"\""))
1668 (setq list
(reverse list
))) ; quote changes meaning each time
1669 (setq tail
(substring-no-properties tail
1)
1670 head
(concat head
(if pair
(cdr pair
) ch
))))
1673 (defun cal-tex-month-name (month)
1674 "The name of MONTH, LaTeX-ified."
1675 (cal-tex-LaTeXify-string (calendar-month-name month
)))
1677 (defun cal-tex-hfill ()
1681 (defun cal-tex-newpage ()
1683 (insert "\\newpage%\n"))
1685 (defun cal-tex-noindent ()
1687 (insert "\\noindent"))
1689 (defun cal-tex-vspace (space)
1690 "Insert vspace command to move SPACE vertically."
1691 (cal-tex-cmd "\\vspace*" space
))
1693 (defun cal-tex-hspace (space)
1694 "Insert hspace command to move SPACE horizontally."
1695 (cal-tex-cmd "\\hspace*" space
))
1697 (defun cal-tex-comment (&optional comment
)
1698 "Insert `% ', followed by optional string COMMENT, followed by newline.
1699 COMMENT may contain newlines, which are prefixed by `% ' in the output."
1700 (insert (format "%% %s\n"
1702 (replace-regexp-in-string "\n" "\n% " comment
)
1705 (defun cal-tex-banner (comment)
1706 "Insert string COMMENT, separated by blank lines."
1707 (cal-tex-comment (format "\n\n\n\t\t\t%s\n" comment
)))
1709 (defun cal-tex-nl (&optional skip comment
)
1710 "End a line with \\. If SKIP, then add that much spacing.
1711 Add trailing COMMENT if present."
1712 (insert (format "\\\\%s"
1714 (format "[%s]" skip
)
1716 (cal-tex-comment comment
))
1718 (defun cal-tex-arg (&optional text
)
1719 "Insert a brace {} pair containing the optional string TEXT."
1720 (insert (format "{%s}" (or text
""))))
1722 (defun cal-tex-cmd (cmd &optional arg
)
1723 "Insert LaTeX CMD, with optional argument ARG, and end with %."
1732 (defun cal-tex-b-document ()
1733 "Insert beginning of document."
1734 (cal-tex-cmd "\\begin" "document"))
1736 (defun cal-tex-e-document ()
1737 "Insert end of document."
1738 (cal-tex-cmd "\\end" "document"))
1740 (defun cal-tex-b-center ()
1741 "Insert beginning of centered block."
1742 (cal-tex-cmd "\\begin" "center"))
1744 (defun cal-tex-e-center ()
1745 "Insert end of centered block."
1747 (cal-tex-cmd "\\end" "center"))
1755 (defun cal-tex-b-parbox (position width
)
1756 "Insert parbox with parameters POSITION and WIDTH."
1757 (insert "\\parbox[" position
"]{" width
"}{")
1760 (defun cal-tex-e-parbox (&optional height
)
1761 "Insert end of parbox. Optionally, force it to be a given HEIGHT."
1764 (cal-tex-rule "0mm" "0mm" height
))
1766 (cal-tex-comment "end parbox"))
1768 (defun cal-tex-b-framebox (width position
)
1769 "Insert framebox with parameters WIDTH and POSITION (clr)."
1770 (insert "\\framebox[" width
"][" position
"]{" )
1773 (defun cal-tex-e-framebox ()
1774 "Insert end of framebox."
1777 (cal-tex-comment "end framebox"))
1780 (defun cal-tex-b-makebox (width position
)
1781 "Insert makebox with parameters WIDTH and POSITION (clr)."
1782 (insert "\\makebox[" width
"][" position
"]{" )
1785 (defun cal-tex-e-makebox ()
1786 "Insert end of makebox."
1789 (cal-tex-comment "end makebox"))
1792 (defun cal-tex-rule (lower width height
)
1793 "Insert a rule with parameters LOWER WIDTH HEIGHT."
1794 (insert "\\rule[" lower
"]{" width
"}{" height
"}"))
1800 (defun cal-tex-em (string)
1801 "Insert STRING in italic font."
1802 (cal-tex-cmd "\\textit" string
))
1804 (defun cal-tex-bf (string)
1805 "Insert STRING in bf font."
1806 (cal-tex-cmd "\\textbf" string
))
1808 (defun cal-tex-scriptsize (string)
1809 "Insert STRING in scriptsize font."
1810 (cal-tex-arg (concat "\\scriptsize " string
)))
1812 (defun cal-tex-huge (string)
1813 "Insert STRING in huge font."
1814 (cal-tex-arg (concat "\\huge " string
)))
1816 (defun cal-tex-Huge (string)
1817 "Insert STRING in Huge font."
1818 (cal-tex-arg (concat "\\Huge " string
)))
1820 (defun cal-tex-Huge-bf (string)
1821 "Insert STRING in Huge bf font."
1822 (cal-tex-cmd "\\textbf" (concat "\\Huge " string
)))
1824 (defun cal-tex-large (string)
1825 "Insert STRING in large font."
1826 (cal-tex-arg (concat "\\large " string
)))
1828 (defun cal-tex-large-bf (string)
1829 "Insert STRING in large bf font."
1830 (cal-tex-cmd "\\textbf" (concat "\\large " string
)))
1835 ;;; cal-tex.el ends here