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-week2-summary
41 ;; cal-tex-cursor-week-iso
42 ;; cal-tex-cursor-week-monday
43 ;; cal-tex-cursor-filofax-2week
44 ;; cal-tex-cursor-filofax-week
45 ;; cal-tex-cursor-filofax-daily
50 ;; (*) Add holidays and diary entries to daily calendar.
52 ;; (*) Add diary entries to weekly calendar functions.
54 ;; (*) Make calendar styles for A4 paper.
56 ;; (*) Make monthly styles Filofax paper.
63 ;;; Customizable variables
66 (defgroup calendar-tex nil
67 "Options for printing calendar with LaTeX."
71 (defcustom cal-tex-which-days
'(0 1 2 3 4 5 6)
72 "The days of the week that are displayed on the portrait monthly calendar.
73 Sunday is 0, Monday is 1, and so on. The default is to print from Sunday to
74 Saturday. For example, use '(1 3 5) to only print Monday, Wednesday, Friday."
75 :type
'(repeat integer
)
78 (defcustom cal-tex-holidays t
79 "Non-nil means holidays are printed in the LaTeX calendars that support it.
80 Setting this to nil may speed up calendar generation."
84 (defcustom cal-tex-diary nil
85 "Non-nil means diary entries are printed in LaTeX calendars that support it.
86 Setting this to nil may speed up calendar generation."
90 (defcustom cal-tex-rules nil
91 "Non-nil means pages will be ruled in some LaTeX calendar styles.
92 At present, this only affects the daily filofax calendar."
96 (defcustom cal-tex-daily-string
97 '(let* ((year (calendar-extract-year date
))
98 (day (calendar-day-number date
))
99 (days-remaining (- (calendar-day-number (list 12 31 year
)) day
)))
100 (format "%d/%d" day days-remaining
))
101 "Lisp expression giving the date format to use in the LaTeX calendars.
102 This should be an expression involving the variable `date'. When
103 this expression is called, `date' is a list of the form '(MONTH DAY YEAR)'.
105 The string resulting from evaluating this expression is placed at
106 the bottom center of each date in monthly calendars, next to the
107 date in the weekly calendars, and in the top center of daily calendars.
109 The default is ordinal day number of the year and the number of
110 days remaining. As an example, setting this to
112 '(calendar-hebrew-date-string date)
114 will put the Hebrew date at the bottom of each day."
116 :group
'calendar-tex
)
118 (defcustom cal-tex-buffer
"calendar.tex"
119 "The name for the output LaTeX calendar buffer."
121 :group
'calendar-tex
)
123 (defcustom cal-tex-24 nil
124 "Non-nil means use a 24 hour clock in the daily calendar."
126 :group
'calendar-tex
)
128 (defcustom cal-tex-daily-start
8
129 "The first hour of the daily LaTeX calendar page.
130 At present, this only affects `cal-tex-cursor-day'."
132 :group
'calendar-tex
)
134 (defcustom cal-tex-daily-end
20
135 "The last hour of the daily LaTeX calendar page.
136 At present, this only affects `cal-tex-cursor-day'."
138 :group
'calendar-tex
)
140 (defcustom cal-tex-preamble-extra nil
141 "A string giving extra LaTeX commands to insert in the calendar preamble.
142 For example, to include extra packages:
143 \"\\\\usepackage{foo}\\n\\\\usepackage{bar}\\n\"."
144 :type
'(choice (const nil
)
145 ;; An example to help people format things in custom.
146 (string :value
"\\usepackage{foo}\n\\usepackage{bar}\n"))
150 (defcustom cal-tex-hook nil
151 "List of functions called after any LaTeX calendar buffer is generated.
152 You can use this to do post-processing on the buffer. For example, to change
153 characters with diacritical marks to their LaTeX equivalents, use
154 (add-hook 'cal-tex-hook
155 (lambda () (iso-iso2tex (point-min) (point-max))))"
157 :group
'calendar-tex
)
159 (defcustom cal-tex-year-hook nil
160 "List of functions called after a LaTeX year calendar buffer is generated."
162 :group
'calendar-tex
)
164 (defcustom cal-tex-month-hook nil
165 "List of functions called after a LaTeX month calendar buffer is generated."
167 :group
'calendar-tex
)
169 (defcustom cal-tex-week-hook nil
170 "List of functions called after a LaTeX week calendar buffer is generated."
172 :group
'calendar-tex
)
174 (defcustom cal-tex-daily-hook nil
175 "List of functions called after a LaTeX daily calendar buffer is generated."
177 :group
'calendar-tex
)
180 ;;; Definitions for LaTeX code
183 (defconst cal-tex-day-prefix
"\\caldate{%s}{%s}"
184 "The initial LaTeX code for a day.
185 The holidays, diary entries, bottom string, and the text follow.")
187 (defconst cal-tex-day-name-format
"\\myday{%s}%%"
188 "The format for LaTeX code for a day name.
189 The names are taken from `calendar-day-name-array'.")
191 (defconst cal-tex-cal-one-month
192 "\\def\\calmonth#1#2%
194 \\Huge\\bf\\uppercase{#1} #2 \\\\[1cm]%
199 "LaTeX code for the month header, for a single month calendar.")
201 (defconst cal-tex-cal-multi-month
202 "\\def\\calmonth#1#2#3#4%
204 \\Huge\\bf #1 #2---#3 #4\\\\[1cm]%
209 "LaTeX code for the month header, for a multi-month calendar.")
211 (defconst cal-tex-myday
212 "\\renewcommand{\\myday}[1]%
213 {\\makebox[\\cellwidth]{\\hfill\\large\\bf#1\\hfill}}
216 "LaTeX code for a day heading.")
218 (defconst cal-tex-caldate
220 \\long\\def\\caldate#1#2#3#4#5#6{%
221 \\fbox{\\hbox to\\cellwidth{%
222 \\vbox to\\cellheight{%
223 \\hbox to\\cellwidth{%
224 {\\hspace*{1mm}\\Large \\bf \\strut #2}\\hspace{.05\\cellwidth}%
225 \\raisebox{\\holidaymult\\cellheight}%
226 {\\parbox[t]{.75\\cellwidth}{\\tiny \\raggedright #4}}}
227 \\hbox to\\cellwidth{%
228 \\hspace*{1mm}\\parbox{.95\\cellwidth}{\\tiny \\raggedright #3}}
230 \\hbox to\\cellwidth{#6}%
232 \\hbox to\\cellwidth{\\hfill \\tiny #5 \\hfill}%
236 "LaTeX code to insert one box with date info in calendar.
237 This definition is the heart of the calendar!")
239 (defconst cal-tex-lefthead
240 "\\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}\n"
241 "LaTeX code for left header.")
243 (defconst cal-tex-righthead
244 "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}\n"
245 "LaTeX code for right header.")
247 (autoload 'holiday-in-range
"holidays")
249 (define-obsolete-function-alias 'cal-tex-list-holidays
'holiday-in-range
"24.3")
251 (autoload 'diary-list-entries
"diary-lib")
253 (defun cal-tex-list-diary-entries (d1 d2
)
254 "Generate a list of all diary-entries from absolute date D1 to D2."
255 (let (diary-list-include-blanks)
256 (diary-list-entries (calendar-gregorian-from-absolute d1
)
259 (defun cal-tex-preamble (&optional args
)
260 "Insert the LaTeX calendar preamble into `cal-tex-buffer'.
261 Preamble includes initial definitions for various LaTeX commands.
262 Optional string ARGS are included as options for the article document class."
263 (set-buffer (generate-new-buffer cal-tex-buffer
))
264 (insert (format "\\documentclass%s{article}\n"
268 (if (stringp cal-tex-preamble-extra
)
269 (insert cal-tex-preamble-extra
"\n"))
270 ;; FIXME boxwidth and boxheight unused?
271 (insert "\\hbadness 20000
277 \\evensidemargin -2cm
282 \\newlength{\\cellwidth}
283 \\newlength{\\cellheight}
284 \\newlength{\\boxwidth}
285 \\newlength{\\boxheight}
286 \\newlength{\\cellsize}
287 \\newcommand{\\myday}[1]{}
288 \\newcommand{\\caldate}[6]{}
289 \\newcommand{\\nocaldate}[6]{}
290 \\newcommand{\\calsmall}[6]{}
299 (defun cal-tex-cursor-year (&optional n event
)
300 "Make a buffer with LaTeX commands for the year cursor is on.
301 Optional prefix argument N specifies number of years.
302 Optional EVENT indicates a buffer position to use instead of point."
303 (interactive (list (prefix-numeric-value current-prefix-arg
)
305 (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t event
))
309 (defun cal-tex-cursor-year-landscape (&optional n event
)
310 "Make a buffer with LaTeX commands for the year cursor is on.
311 Optional prefix argument N specifies number of years.
312 Optional EVENT indicates a buffer position to use instead of point."
313 (interactive (list (prefix-numeric-value current-prefix-arg
)
315 (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t event
))
318 (defun cal-tex-year (year n
&optional landscape
)
319 "Make a one page yearly calendar of YEAR; do this for N years.
320 There are four rows of three months each, unless optional
321 LANDSCAPE is non-nil, in which case the calendar is printed in
322 landscape mode with three rows of four months each."
323 (cal-tex-insert-preamble 1 landscape
"12pt")
325 (cal-tex-vspace "-.6cm")
326 (cal-tex-vspace "-3.1cm"))
328 (insert "\\vfill%\n")
330 (cal-tex-Huge (number-to-string year
))
332 (cal-tex-vspace "1cm")
334 (cal-tex-b-parbox "l" (if landscape
"5.9in" "4.3in"))
339 (insert (cal-tex-mini-calendar (1+ i
) year
"month" "1.1in" "1in"))
341 (cal-tex-hspace "0.5in")
342 (if (zerop (mod (1+ i
) (if landscape
4 3)))
343 (cal-tex-nl "0.5in")))
346 (insert "\\vfill%\n")
347 (setq year
(1+ year
))
349 (cal-tex-end-document)
351 (run-hooks 'cal-tex-year-hook
))
352 (run-hooks 'cal-tex-hook
))
355 (defun cal-tex-filofax-paper (&optional year
)
356 "Insert some page size settings for filofax layouts."
357 (insert "\\textwidth 3.25in
359 \\headheight -0.875in
363 ;; Why is this one subtly different? Who knows...
364 (if year
"\\oddsidemargin 1.675in
365 \\evensidemargin 1.675in
367 "\\oddsidemargin 1.75in
368 \\evensidemargin 1.5in
373 (defun cal-tex-longday (funcname height
)
374 "Insert LaTeX code for a long day function."
375 (insert "\\long\\def\\" funcname
"#1#2#3#4#5{%
376 \\rule{\\textwidth}{0.3pt}\\\\%
377 \\hbox to \\textwidth{%
378 \\vbox to " height
"{%
380 \\hbox to \\textwidth{"
381 (if (string-equal funcname
"leftday")
382 "\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%\n"
383 "\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%\n")
384 " \\hbox to \\textwidth{\\vbox {\\"
385 (if (string-equal funcname
"leftday") "noindent" "raggedleft")
386 " \\footnotesize \\em #4}}%
387 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}\n"))
389 (defun cal-tex-shortday (funcname)
390 "Insert LaTeX code for a short day function."
391 (insert "\\long\\def\\" funcname
"#1#2#3{%
392 \\rule{\\textwidth}{0.3pt}\\\\%
393 \\hbox to \\textwidth{%
396 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
397 \\hbox to \\textwidth{\\vbox {\\"
398 (if (string-equal funcname
"rightday") "raggedleft" "noindent")
400 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}\n"))
403 (defun cal-tex-cursor-filofax-year (&optional n event
)
404 "Make a Filofax one page yearly calendar of year indicated by cursor.
405 Optional prefix argument N specifies number of years.
406 Optional EVENT indicates a buffer position to use instead of point."
407 (interactive (list (prefix-numeric-value current-prefix-arg
)
410 (let ((year (calendar-extract-year (calendar-cursor-to-date t event
))))
411 (cal-tex-preamble "twoside")
412 (cal-tex-filofax-paper 'year
)
413 (cal-tex-cmd "\\fboxsep 0.5mm")
414 (cal-tex-cmd "\\pagestyle" "empty")
416 (cal-tex-vspace "0.25in")
418 (insert (format "\\hfil \\textbf{\\Large %s} \\hfil\\\\\n" year
))
420 (cal-tex-b-parbox "l" "\\textwidth")
424 (let ((month-names; don't use default in case user changed it
425 ;; These are only used to define the command names, not
426 ;; the names of the months they insert.
427 ["January" "February" "March" "April" "May" "June"
428 "July" "August" "September" "October" "November" "December"]))
430 (insert (cal-tex-mini-calendar (1+ i
) year
(aref month-names i
)
431 "1in" ".9in" "tiny" "0.6mm"))))
433 "\\noindent\\fbox{\\January}\\fbox{\\February}\\fbox{\\March}\\\\
434 \\noindent\\fbox{\\April}\\fbox{\\May}\\fbox{\\June}\\\\
435 \\noindent\\fbox{\\July}\\fbox{\\August}\\fbox{\\September}\\\\
436 \\noindent\\fbox{\\October}\\fbox{\\November}\\fbox{\\December}
440 (setq year
(1+ year
))
442 (cal-tex-end-document)
444 (cal-tex-vspace "0.25in"))
445 (run-hooks 'cal-tex-year-hook
))
446 (run-hooks 'cal-tex-hook
)))
449 ;;; Monthly calendars
453 (defun cal-tex-cursor-month-landscape (&optional n event
)
454 "Make a LaTeX calendar buffer for the month the cursor is on.
455 Optional prefix argument N specifies number of months to be
456 produced (default 1). The output is in landscape format, one
457 month to a page. It shows holiday and diary entries if
458 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
459 Optional EVENT indicates a buffer position to use instead of point."
460 (interactive (list (prefix-numeric-value current-prefix-arg
)
463 (let* ((date (calendar-cursor-to-date t event
))
464 (month (calendar-extract-month date
))
465 (year (calendar-extract-year date
))
468 (cal-tex-which-days '(0 1 2 3 4 5 6))
469 (d1 (calendar-absolute-from-gregorian (list month
1 year
)))
471 (calendar-increment-month end-month end-year
(1- n
))
472 (calendar-absolute-from-gregorian
474 (calendar-last-day-of-month end-month end-year
)
476 (diary-list (if cal-tex-diary
(cal-tex-list-diary-entries d1 d2
)))
477 (holidays (if cal-tex-holidays
(holiday-in-range d1 d2
)))
478 other-month other-year small-months-at-start
)
479 (cal-tex-insert-preamble (cal-tex-number-weeks month year
1) t
"12pt")
480 (cal-tex-cmd cal-tex-cal-one-month
)
482 (setq other-month month
484 (calendar-increment-month other-month other-year -
1)
485 (insert (cal-tex-mini-calendar other-month other-year
"lastmonth"
486 "\\cellwidth" "\\cellheight"))
487 (calendar-increment-month other-month other-year
2)
488 (insert (cal-tex-mini-calendar other-month other-year
"nextmonth"
489 "\\cellwidth" "\\cellheight"))
490 (cal-tex-insert-month-header 1 month year month year
)
491 (cal-tex-insert-day-names)
493 (if (setq small-months-at-start
494 (< 1 (mod (- (calendar-day-of-week (list month
1 year
))
495 calendar-week-start-day
)
497 (insert "\\lastmonth\\nextmonth\\hspace*{-2\\cellwidth}"))
498 (cal-tex-insert-blank-days month year cal-tex-day-prefix
)
499 (cal-tex-insert-days month year diary-list holidays
501 (cal-tex-insert-blank-days-at-end month year cal-tex-day-prefix
)
502 (if (and (not small-months-at-start
)
503 (< 1 (mod (- (1- calendar-week-start-day
)
504 (calendar-day-of-week
506 (calendar-last-day-of-month month year
)
509 (insert "\\vspace*{-\\cellwidth}\\hspace*{-2\\cellwidth}"
510 "\\lastmonth\\nextmonth%
513 (run-hooks 'cal-tex-month-hook
)
515 (calendar-increment-month month year
1)
516 (cal-tex-vspace "-2cm")
517 (cal-tex-insert-preamble
518 (cal-tex-number-weeks month year
1) t
"12pt" t
))))
519 (cal-tex-end-document)
520 (run-hooks 'cal-tex-hook
))
523 (defun cal-tex-cursor-month (&optional n event
)
524 "Make a LaTeX calendar buffer for the month the cursor is on.
525 Optional prefix argument N specifies number of months to be
526 produced (default 1). The calendar is condensed onto one page.
527 It shows holiday and diary entries if `cal-tex-holidays' and
528 `cal-tex-diary', respectively, are non-nil. Optional EVENT
529 indicates a buffer position to use instead of point."
530 (interactive (list (prefix-numeric-value current-prefix-arg
)
533 (let* ((date (calendar-cursor-to-date t event
))
534 (month (calendar-extract-month date
))
535 (year (calendar-extract-year date
))
538 ;; FIXME -landscape sets cal-tex-which-days?
539 (d1 (calendar-absolute-from-gregorian (list month
1 year
)))
541 (calendar-increment-month end-month end-year
(1- n
))
542 (calendar-absolute-from-gregorian
544 (calendar-last-day-of-month end-month end-year
)
546 (diary-list (if cal-tex-diary
(cal-tex-list-diary-entries d1 d2
)))
547 (holidays (if cal-tex-holidays
(holiday-in-range d1 d2
))))
548 (cal-tex-insert-preamble (cal-tex-number-weeks month year n
) nil
"12pt")
550 (cal-tex-cmd cal-tex-cal-multi-month
)
551 (cal-tex-cmd cal-tex-cal-one-month
))
552 (cal-tex-insert-month-header n month year end-month end-year
)
553 (cal-tex-insert-day-names)
555 (cal-tex-insert-blank-days month year cal-tex-day-prefix
)
557 (cal-tex-insert-days month year diary-list holidays cal-tex-day-prefix
)
558 (when (= (calendar-week-end-day)
559 (calendar-day-of-week
561 (calendar-last-day-of-month month year
)
562 year
))) ; last day of month was last day of week
565 (calendar-increment-month month year
1))
566 (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix
))
567 (cal-tex-end-document)
568 (run-hooks 'cal-tex-hook
))
570 (defun cal-tex-insert-days (month year diary-list holidays day-format
)
571 "Insert LaTeX commands for a range of days in monthly calendars.
572 LaTeX commands are inserted for the days of the MONTH in YEAR.
573 Diary entries on DIARY-LIST are included. Holidays on HOLIDAYS
574 are included. Each day is formatted using format DAY-FORMAT."
575 (let ((blank-days ; at start of month
577 (- (calendar-day-of-week (list month
1 year
))
578 calendar-week-start-day
)
580 (last (calendar-last-day-of-month month year
))
583 (setq j
(1+ i
) ; 1-last, incl
584 date
(list month j year
))
585 (when (memq (calendar-day-of-week date
) cal-tex-which-days
)
586 (insert (format day-format
(cal-tex-month-name month
) j
))
587 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
588 (cal-tex-arg (cal-tex-latexify-list holidays date
))
589 (cal-tex-arg (eval cal-tex-daily-string
))
592 (when (and (zerop (mod (+ j blank-days
) 7))
597 (defun cal-tex-insert-day-names ()
598 "Insert the names of the days at top of a monthly calendar."
601 (if (memq (setq j
(mod (+ calendar-week-start-day i
) 7))
603 (insert (format cal-tex-day-name-format
604 (cal-tex-LaTeXify-string
605 (aref calendar-day-name-array j
)))))
608 (defun cal-tex-insert-month-header (n month year end-month end-year
)
609 "Create a title for a calendar.
610 A title is inserted for a calendar with N months starting with
611 MONTH YEAR and ending with END-MONTH END-YEAR."
612 (let ((month-name (cal-tex-month-name month
))
613 (end-month-name (cal-tex-month-name end-month
)))
615 (insert (format "\\calmonth{%s}{%s}\n\\vspace*{-0.5cm}"
617 (insert (format "\\calmonth{%s}{%s}{%s}{%s}\n\\vspace*{-0.5cm}"
618 month-name year end-month-name end-year
))))
621 (defun cal-tex-insert-blank-days (month year day-format
)
622 "Insert code for initial days not in calendar.
623 Insert LaTeX code for the blank days at the beginning of the MONTH in
624 YEAR. The entry is formatted using DAY-FORMAT. If the entire week is
625 blank, no days are inserted."
626 (if (cal-tex-first-blank-p month year
)
627 (let ((blank-days ; at start of month
629 (- (calendar-day-of-week (list month
1 year
))
630 calendar-week-start-day
)
632 (dotimes (i blank-days
)
633 (if (memq (mod (+ calendar-week-start-day i
) 7) cal-tex-which-days
)
634 (insert (format day-format
" " " ") "{}{}{}{}%\n"))))))
636 (defun cal-tex-insert-blank-days-at-end (month year day-format
)
637 "Insert code for final days not in calendar.
638 Insert LaTeX code for the blank days at the end of the MONTH in YEAR.
639 The entry is formatted using DAY-FORMAT."
640 (if (cal-tex-last-blank-p month year
)
641 (let* ((last-day (calendar-last-day-of-month month year
))
642 (blank-days ; at end of month
644 (- (calendar-day-of-week (list month last-day year
))
645 calendar-week-start-day
)
648 (while (<= (setq i
(1+ i
)) 6)
649 (if (memq (mod (+ calendar-week-start-day i
) 7) cal-tex-which-days
)
650 (insert (format day-format
"" "") "{}{}{}{}%\n"))))))
652 (defun cal-tex-first-blank-p (month year
)
653 "Determine if any days of the first week will be printed.
654 Return t if there will there be any days of the first week printed
655 in the calendar starting in MONTH YEAR."
656 ;; Check days 1-7 of the month, until we find the last day of the week.
660 (if (memq (setq dow
(calendar-day-of-week (list month
(1+ i
) year
)))
663 (if (= dow
(calendar-week-end-day)) (throw 'found nil
)))))))
665 (defun cal-tex-last-blank-p (month year
)
666 "Determine if any days of the last week will be printed.
667 Return t if there will there be any days of the last week printed
668 in the calendar starting in MONTH YEAR."
669 ;; Check backwards from the last day of the month, until we find the
670 ;; start of the last week in the month.
672 (let ((last-day (calendar-last-day-of-month month year
))
675 (if (memq (setq dow
(calendar-day-of-week
676 (list month
(- last-day i
) year
)))
679 (if (= dow calendar-week-start-day
) (throw 'found nil
)))))))
681 (defun cal-tex-number-weeks (month year n
)
682 "Determine the number of weeks in a range of dates.
683 Compute the number of weeks in the calendar starting with MONTH and YEAR,
684 and lasting N months, including only the days in WHICH-DAYS. As it stands,
685 this is only an upper bound."
686 (let ((d (list month
1 year
)))
687 (calendar-increment-month month year
(1- n
))
688 (/ (- (calendar-dayname-on-or-before
689 calendar-week-start-day
690 (+ 7 (calendar-absolute-from-gregorian
691 (list month
(calendar-last-day-of-month month year
) year
))))
692 (calendar-dayname-on-or-before
693 calendar-week-start-day
694 (calendar-absolute-from-gregorian d
)))
701 (defconst cal-tex-LaTeX-hourbox
702 "\\newcommand{\\hourbox}[2]%
703 {\\makebox[2em]{\\rule{0cm}{#2ex}#1}\\rule{3in}{.15mm}}\n"
704 "One hour and a line on the right.")
706 (defun cal-tex-weekly-paper (&optional nomargins
)
707 "Insert some page size settings for weekly layouts."
708 (insert "\\textwidth 6.5in
711 (or nomargins
(insert "\\oddsidemargin 0in
715 ;; TODO cal-tex-diary-support.
716 ;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
718 (defun cal-tex-cursor-week (&optional n event
)
719 "Make a one page LaTeX calendar for one week, showing hours of the day.
720 There are two columns; with 8-12am in the first and 1-5pm in the second.
721 It shows holidays if `cal-tex-holidays' is non-nil.
722 It does not show diary entries.
724 The optional prefix argument N specifies a number of weeks (default 1).
726 By default, the calendar is for the week at point; the optional
727 argument EVENT specifies a different buffer position."
728 (interactive (list (prefix-numeric-value current-prefix-arg
)
731 (let* ((date (calendar-gregorian-from-absolute
732 (calendar-dayname-on-or-before
733 calendar-week-start-day
734 (calendar-absolute-from-gregorian
735 (calendar-cursor-to-date t event
)))))
736 (month (calendar-extract-month date
))
737 (year (calendar-extract-year date
))
738 (d1 (calendar-absolute-from-gregorian date
))
740 (holidays (if cal-tex-holidays
741 (holiday-in-range d1 d2
))))
742 (cal-tex-preamble "11pt")
743 (cal-tex-weekly-paper)
744 (insert cal-tex-LaTeX-hourbox
)
746 (cal-tex-cmd "\\pagestyle" "empty")
748 (cal-tex-vspace "-1.5in")
750 (cal-tex-Huge-bf (format "\\uppercase{%s}"
751 (cal-tex-month-name month
)))
752 (cal-tex-hspace "2em")
753 (cal-tex-Huge-bf (number-to-string year
))
756 (cal-tex-hspace "-.2in")
757 (cal-tex-b-parbox "l" "7in")
759 (cal-tex-week-hours date holidays
"3.1")
760 (setq date
(cal-tex-incr-date date
)))
762 (setq month
(calendar-extract-month date
)
763 year
(calendar-extract-year date
))
765 (run-hooks 'cal-tex-week-hook
)
767 (cal-tex-end-document)
768 (run-hooks 'cal-tex-hook
)))
770 ;; TODO cal-tex-diary support.
771 ;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
773 (defun cal-tex-cursor-week2 (&optional n event
)
774 "Make a two page LaTeX calendar for one week, showing hours of the day.
775 There are two columns; with 8-12am in the first and 1-5pm in the second.
776 It shows holidays if `cal-tex-holidays' is non-nil.
777 It does not show diary entries.
779 The optional prefix argument N specifies a number of weeks (default 1).
781 By default, the calendar is for the week at point; the optional
782 argument EVENT specifies a different buffer position."
783 (interactive (list (prefix-numeric-value current-prefix-arg
)
786 (let* ((date (calendar-gregorian-from-absolute
787 (calendar-dayname-on-or-before
788 calendar-week-start-day
789 (calendar-absolute-from-gregorian
790 (calendar-cursor-to-date t event
)))))
791 (month (calendar-extract-month date
))
792 (year (calendar-extract-year date
))
793 (d1 (calendar-absolute-from-gregorian date
))
795 (holidays (if cal-tex-holidays
796 (holiday-in-range d1 d2
))))
797 (cal-tex-preamble "12pt")
798 (cal-tex-weekly-paper)
799 (insert cal-tex-LaTeX-hourbox
)
801 (cal-tex-cmd "\\pagestyle" "empty")
803 (cal-tex-vspace "-1.5in")
805 (cal-tex-Huge-bf (format "\\uppercase{%s}"
806 (cal-tex-month-name month
)))
807 (cal-tex-hspace "2em")
808 (cal-tex-Huge-bf (number-to-string year
))
811 (cal-tex-hspace "-.2in")
812 (cal-tex-b-parbox "l" "\\textwidth")
814 (cal-tex-week-hours date holidays
"5")
815 (setq date
(cal-tex-incr-date date
)))
818 (insert (cal-tex-mini-calendar
819 (calendar-extract-month (cal-tex-previous-month date
))
820 (calendar-extract-year (cal-tex-previous-month date
))
821 "lastmonth" "1.1in" "1in"))
822 (insert (cal-tex-mini-calendar
823 (calendar-extract-month date
)
824 (calendar-extract-year date
)
825 "thismonth" "1.1in" "1in"))
826 (insert (cal-tex-mini-calendar
827 (calendar-extract-month (cal-tex-next-month date
))
828 (calendar-extract-year (cal-tex-next-month date
))
829 "nextmonth" "1.1in" "1in"))
830 (insert "\\hbox to \\textwidth{")
832 (insert "\\lastmonth")
834 (insert "\\thismonth")
836 (insert "\\nextmonth")
840 (cal-tex-b-parbox "l" "\\textwidth")
842 (cal-tex-week-hours date holidays
"5")
843 (setq date
(cal-tex-incr-date date
)))
845 (setq month
(calendar-extract-month date
)
846 year
(calendar-extract-year date
))
848 (run-hooks 'cal-tex-week-hook
)
850 (cal-tex-end-document)
851 (run-hooks 'cal-tex-hook
)))
853 (autoload 'calendar-iso-from-absolute
"cal-iso")
856 (defun cal-tex-cursor-week-iso (&optional n event
)
857 "Make a one page LaTeX calendar for one week, in the ISO-style.
858 It does not show hours of the day.
859 It shows holidays if `cal-tex-holidays' is non-nil.
860 It shows diary entries if `cal-tex-diary' is non-nil.
862 The optional prefix argument N specifies a number of weeks (default 1).
864 By default, the calendar is for the week at point; the optional
865 argument EVENT specifies a different buffer position."
866 (interactive (list (prefix-numeric-value current-prefix-arg
)
869 (let* ((date (calendar-gregorian-from-absolute
870 (calendar-dayname-on-or-before
872 (calendar-absolute-from-gregorian
873 (calendar-cursor-to-date t event
)))))
874 (month (calendar-extract-month date
))
875 (year (calendar-extract-year date
))
876 (day (calendar-extract-day date
))
877 (d1 (calendar-absolute-from-gregorian date
))
879 (holidays (if cal-tex-holidays
880 (holiday-in-range d1 d2
)))
881 (diary-list (if cal-tex-diary
882 (cal-tex-list-diary-entries d1 d2
)))
884 (cal-tex-preamble "11pt")
885 (cal-tex-weekly-paper)
887 (cal-tex-cmd "\\pagestyle" "empty")
889 (cal-tex-vspace "-1.5in")
892 (let ((d (calendar-iso-from-absolute
893 (calendar-absolute-from-gregorian date
))))
894 (format "Week %d of %d"
895 (calendar-extract-month d
)
896 (calendar-extract-year d
))))
899 (cal-tex-b-parbox "l" "\\textwidth")
901 (cal-tex-b-parbox "t" "\\textwidth")
902 (cal-tex-b-parbox "t" "\\textwidth")
903 (cal-tex-rule "0pt" "\\textwidth" ".2mm")
905 (cal-tex-b-parbox "t" "\\textwidth")
906 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
908 (cal-tex-large-bf (cal-tex-month-name month
))
910 (cal-tex-large-bf (number-to-string day
))
911 (unless (string-equal "" (setq s
(cal-tex-latexify-list
912 holidays date
"; ")))
914 (cal-tex-large-bf s
))
916 (insert " " (eval cal-tex-daily-string
))
920 (cal-tex-b-parbox "t" "\\textwidth")
921 (unless (string-equal "" (setq s
(cal-tex-latexify-list
923 (insert "\\vbox to 0pt{")
928 (setq date
(cal-tex-incr-date date
)
929 month
(calendar-extract-month date
)
930 day
(calendar-extract-day date
))
932 (cal-tex-e-parbox "2cm")
934 (setq month
(calendar-extract-month date
)
935 year
(calendar-extract-year date
)))
938 (run-hooks 'cal-tex-week-hook
)
940 (cal-tex-end-document)
941 (run-hooks 'cal-tex-hook
)))
943 ;; TODO respect cal-tex-daily-start,end?
944 ;; Using different numbers of hours will probably break some layouts.
945 (defun cal-tex-week-hours (date holidays height
)
946 "Insert hourly entries for DATE with HOLIDAYS, with line height HEIGHT.
947 Uses the 24-hour clock if `cal-tex-24' is non-nil. Note that the hours
948 shown are hard-coded to 8-12, 13-17."
949 (let ((month (calendar-extract-month date
))
950 (day (calendar-extract-day date
))
951 (year (calendar-extract-year date
))
953 (cal-tex-comment "begin cal-tex-week-hours")
954 (cal-tex-cmd "\\ \\\\[-.2cm]")
955 (cal-tex-cmd "\\noindent")
956 (cal-tex-b-parbox "l" "6.8in")
957 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
959 (cal-tex-large-bf (cal-tex-month-name month
))
961 (cal-tex-large-bf (number-to-string day
))
962 (unless (string-equal "" (setq s
(cal-tex-latexify-list
963 holidays date
"; ")))
965 (cal-tex-large-bf s
))
967 (insert " " (eval cal-tex-daily-string
))
970 (cal-tex-rule "0pt" "6.8in" ".2mm")
973 (setq morning
(+ i
8) ; 8-12 incl
974 afternoon
(if cal-tex-24
975 (+ i
13) ; 13-17 incl
977 (cal-tex-cmd "\\hourbox" (number-to-string morning
))
979 (cal-tex-hspace ".4cm")
980 (cal-tex-cmd "\\hourbox" (number-to-string afternoon
))
984 ;; TODO cal-tex-diary support.
985 ;; TODO respect cal-tex-daily-start,end (see cal-tex-weekly4-box).
987 (defun cal-tex-cursor-week-monday (&optional n event
)
988 "Make a one page LaTeX calendar for one week, showing hours of the day.
989 There are two columns; with M-W in the first and T-S in the second.
990 It shows the hours 8-12am and 1-5pm.
991 It shows holidays if `cal-tex-holidays' is non-nil.
992 It does not show diary entries.
994 The optional prefix argument N specifies a number of weeks (default 1).
996 By default, the calendar is for the week at point; the optional
997 argument EVENT specifies a different buffer position."
998 (interactive (list (prefix-numeric-value current-prefix-arg
)
1001 (let ((date (calendar-gregorian-from-absolute
1002 (calendar-dayname-on-or-before
1004 (calendar-absolute-from-gregorian
1005 (calendar-cursor-to-date t event
))))))
1006 (cal-tex-preamble "11pt")
1007 (cal-tex-weekly-paper)
1008 (cal-tex-b-document)
1010 (cal-tex-vspace "-1cm")
1011 (insert "\\noindent ")
1012 (cal-tex-weekly4-box (cal-tex-incr-date date
) nil
)
1013 (cal-tex-weekly4-box (cal-tex-incr-date date
4) nil
)
1015 (cal-tex-weekly4-box (cal-tex-incr-date date
2) nil
)
1016 (cal-tex-weekly4-box (cal-tex-incr-date date
5) nil
)
1018 (cal-tex-weekly4-box (cal-tex-incr-date date
3) nil
)
1019 (cal-tex-weekly4-box (cal-tex-incr-date date
6) t
)
1020 (unless (= i
(1- n
))
1021 (run-hooks 'cal-tex-week-hook
)
1022 (setq date
(cal-tex-incr-date date
7))
1024 (cal-tex-end-document)
1025 (run-hooks 'cal-tex-hook
)))
1027 ;; TODO respect cal-tex-daily-start,end?
1028 ;; Using different numbers of hours will probably break some layouts.
1029 (defun cal-tex-weekly4-box (date weekend
)
1030 "Make one box for DATE, different if WEEKEND.
1031 Uses the 24-hour clock if `cal-tex-24' is non-nil. Note that the hours
1032 shown are hard-coded to 8-12, 13-17."
1033 (let* ((day (calendar-extract-day date
))
1034 (month (calendar-extract-month date
))
1035 (year (calendar-extract-year date
))
1036 (dayname (cal-tex-LaTeXify-string (calendar-day-name date
)))
1037 (date1 (cal-tex-incr-date date
))
1038 (day1 (calendar-extract-day date1
))
1039 (month1 (calendar-extract-month date1
))
1040 (year1 (calendar-extract-year date1
))
1041 (dayname1 (cal-tex-LaTeXify-string (calendar-day-name date1
))))
1042 (cal-tex-b-framebox "8cm" "l")
1043 (cal-tex-b-parbox "b" "7.5cm")
1044 (insert (format "\\textbf{\\Large %s,} %s/%s/%s\\\\\n"
1045 dayname month day year
))
1046 (cal-tex-rule "0pt" "7.5cm" ".5mm")
1050 (insert (format "\\textsf{\\large %d}\\\\\n" (+ i
8))))
1052 (insert (format "\\textsf{\\large %d}\\\\\n"
1054 (+ i
13) ; 13-17 incl
1055 (1+ i
)))))) ; 1-5 incl
1058 (cal-tex-vspace "1cm")
1059 (insert "\\ \\vfill")
1060 (insert (format "\\textbf{\\Large %s,} %s/%s/%s\\\\\n"
1061 dayname1 month1 day1 year1
))
1062 (cal-tex-rule "0pt" "7.5cm" ".5mm")
1063 (cal-tex-nl "1.5cm")
1064 (cal-tex-vspace "1cm"))
1066 (cal-tex-e-framebox)
1067 (cal-tex-hspace "1cm")))
1069 (defun cal-tex-weekly-common (n event
&optional filofax
)
1070 "Common code for weekly calendars."
1072 (let* ((date (calendar-gregorian-from-absolute
1073 (calendar-dayname-on-or-before
1075 (calendar-absolute-from-gregorian
1076 (calendar-cursor-to-date t event
)))))
1077 (month (calendar-extract-month date
))
1078 (year (calendar-extract-year date
))
1079 (day (calendar-extract-day date
))
1080 (d1 (calendar-absolute-from-gregorian date
))
1082 (holidays (if cal-tex-holidays
1083 (holiday-in-range d1 d2
)))
1084 (diary-list (if cal-tex-diary
1085 (cal-tex-list-diary-entries d1 d2
))))
1088 (cal-tex-preamble "twoside")
1089 (cal-tex-filofax-paper)
1090 (insert cal-tex-righthead
)
1091 (cal-tex-longday "rightday" "1.85in")
1092 (cal-tex-longday "weekend" "0.8in")
1093 (insert cal-tex-lefthead
)
1094 (cal-tex-longday "leftday" "1.85in"))
1095 (cal-tex-preamble "twoside,12pt")
1096 (insert "\\textwidth 7in
1099 \\evensidemargin 0in
1101 \\headheight -0.875in
1105 (insert cal-tex-righthead
)
1106 (cal-tex-longday "rightday" "2.75in")
1107 (cal-tex-longday "weekend" "1.8in")
1108 (insert cal-tex-lefthead
)
1109 (cal-tex-longday "leftday" "2.75in"))
1110 (cal-tex-b-document)
1111 (cal-tex-cmd "\\pagestyle" "empty")
1112 ;; Let's assume this is something to do with twopage documents.
1113 ;; It has the downside that we start with a blank page.
1114 ;; It doesn't make obvious sense when oddside and evenside margins
1115 ;; are the same (non-filofax), but consider the left and right
1116 ;; versions of various functions as applicable to even and odd pages.
1119 (insert "\\lefthead")
1121 (let ((d (cal-tex-incr-date date
2)))
1122 (if (= (calendar-extract-month date
)
1123 (calendar-extract-month d
))
1125 (cal-tex-month-name (calendar-extract-month date
))
1126 (calendar-extract-year date
))
1127 (if (= (calendar-extract-year date
)
1128 (calendar-extract-year d
))
1129 (format "%s---%s %s"
1130 (cal-tex-month-name (calendar-extract-month date
))
1131 (cal-tex-month-name (calendar-extract-month d
))
1132 (calendar-extract-year date
))
1133 (format "%s %s---%s %s"
1134 (cal-tex-month-name (calendar-extract-month date
))
1135 (calendar-extract-year date
)
1136 (cal-tex-month-name (calendar-extract-month d
))
1137 (calendar-extract-year d
))))))
1139 (dotimes (_jdummy 3)
1140 (insert "\\leftday")
1141 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1142 (cal-tex-arg (number-to-string (calendar-extract-day date
)))
1143 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1144 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1145 (cal-tex-arg (eval cal-tex-daily-string
))
1147 (setq date
(cal-tex-incr-date date
)))
1148 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1151 (insert (cal-tex-mini-calendar
1152 (calendar-extract-month (cal-tex-previous-month date
))
1153 (calendar-extract-year (cal-tex-previous-month date
))
1154 "lastmonth" "1.1in" "1in"))
1155 (insert (cal-tex-mini-calendar
1156 (calendar-extract-month date
)
1157 (calendar-extract-year date
)
1158 "thismonth" "1.1in" "1in"))
1159 (insert (cal-tex-mini-calendar
1160 (calendar-extract-month (cal-tex-next-month date
))
1161 (calendar-extract-year (cal-tex-next-month date
))
1162 "nextmonth" "1.1in" "1in"))
1163 (insert "\\hbox to \\textwidth{")
1165 (insert "\\lastmonth")
1167 (insert "\\thismonth")
1169 (insert "\\nextmonth")
1173 (insert "\\righthead")
1175 (let ((d (cal-tex-incr-date date
3)))
1176 (if (= (calendar-extract-month date
)
1177 (calendar-extract-month d
))
1179 (cal-tex-month-name (calendar-extract-month date
))
1180 (calendar-extract-year date
))
1181 (if (= (calendar-extract-year date
)
1182 (calendar-extract-year d
))
1183 (format "%s---%s %s"
1184 (cal-tex-month-name (calendar-extract-month date
))
1185 (cal-tex-month-name (calendar-extract-month d
))
1186 (calendar-extract-year date
))
1187 (format "%s %s---%s %s"
1188 (cal-tex-month-name (calendar-extract-month date
))
1189 (calendar-extract-year date
)
1190 (cal-tex-month-name (calendar-extract-month d
))
1191 (calendar-extract-year d
))))))
1193 (dotimes (_jdummy 2)
1194 (insert "\\rightday")
1195 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1196 (cal-tex-arg (number-to-string (calendar-extract-day date
)))
1197 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1198 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1199 (cal-tex-arg (eval cal-tex-daily-string
))
1201 (setq date
(cal-tex-incr-date date
)))
1202 (dotimes (_jdummy 2)
1203 (insert "\\weekend")
1204 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1205 (cal-tex-arg (number-to-string (calendar-extract-day date
)))
1206 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1207 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1208 (cal-tex-arg (eval cal-tex-daily-string
))
1210 (setq date
(cal-tex-incr-date date
)))
1211 (unless (= i
(1- n
))
1212 (run-hooks 'cal-tex-week-hook
)
1214 (cal-tex-end-document)
1215 (run-hooks 'cal-tex-hook
)))
1218 (defun cal-tex-cursor-week2-summary (&optional n event
)
1219 "Make a two page LaTeX calendar for one week, with optional diary entries.
1220 It does not show hours of the day.
1221 It shows holidays if `cal-tex-holidays' is non-nil.
1222 It shows diary entries if `cal-tex-diary' is non-nil.
1224 The optional prefix argument N specifies a number of weeks (default 1).
1226 By default, the calendar is for the week at point; the optional
1227 argument EVENT specifies a different buffer position."
1228 (interactive (list (prefix-numeric-value current-prefix-arg
)
1229 last-nonmenu-event
))
1230 (cal-tex-weekly-common n event
))
1233 (defun cal-tex-cursor-filofax-2week (&optional n event
)
1234 "Two-weeks-at-a-glance Filofax style calendar for week cursor is in.
1235 Optional prefix argument N specifies number of weeks (default 1).
1236 The calendar shows holiday and diary entries if
1237 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
1238 Optional EVENT indicates a buffer position to use instead of point."
1239 (interactive (list (prefix-numeric-value current-prefix-arg
)
1240 last-nonmenu-event
))
1242 (let* ((date (calendar-gregorian-from-absolute
1243 (calendar-dayname-on-or-before
1244 calendar-week-start-day
1245 (calendar-absolute-from-gregorian
1246 (calendar-cursor-to-date t event
)))))
1247 (month (calendar-extract-month date
))
1248 (year (calendar-extract-year date
))
1249 (day (calendar-extract-day date
))
1250 (d1 (calendar-absolute-from-gregorian date
))
1252 (holidays (if cal-tex-holidays
1253 (holiday-in-range d1 d2
)))
1254 (diary-list (if cal-tex-diary
1255 (cal-tex-list-diary-entries d1 d2
))))
1256 (cal-tex-preamble "twoside")
1257 (cal-tex-filofax-paper)
1258 (insert cal-tex-righthead
)
1259 (cal-tex-longday "rightday" "0.7in")
1260 (insert cal-tex-lefthead
)
1261 (cal-tex-longday "leftday" "0.7in")
1262 (cal-tex-b-document)
1263 (cal-tex-cmd "\\pagestyle" "empty")
1265 (if (zerop (mod i
2))
1266 (insert "\\righthead")
1267 (insert "\\lefthead"))
1269 (let ((d (cal-tex-incr-date date
6)))
1270 (if (= (calendar-extract-month date
)
1271 (calendar-extract-month d
))
1273 (cal-tex-month-name (calendar-extract-month date
))
1274 (calendar-extract-year date
))
1275 (if (= (calendar-extract-year date
)
1276 (calendar-extract-year d
))
1277 (format "%s---%s %s"
1278 (cal-tex-month-name (calendar-extract-month date
))
1279 (cal-tex-month-name (calendar-extract-month d
))
1280 (calendar-extract-year date
))
1281 (format "%s %s---%s %s"
1282 (cal-tex-month-name (calendar-extract-month date
))
1283 (calendar-extract-year date
)
1284 (cal-tex-month-name (calendar-extract-month d
))
1285 (calendar-extract-year d
))))))
1287 (dotimes (_jdummy 7)
1288 (if (zerop (mod i
2))
1289 (insert "\\rightday")
1290 (insert "\\leftday"))
1291 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1292 (cal-tex-arg (number-to-string (calendar-extract-day date
)))
1293 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1294 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1295 (cal-tex-arg (eval cal-tex-daily-string
))
1297 (setq date
(cal-tex-incr-date date
)))
1298 (unless (= i
(1- n
))
1299 (run-hooks 'cal-tex-week-hook
)
1301 (cal-tex-end-document)
1302 (run-hooks 'cal-tex-hook
)))
1305 (defun cal-tex-cursor-filofax-week (&optional n event
)
1306 "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
1307 Optional prefix argument N specifies number of weeks (default 1),
1308 starting on Mondays. The calendar shows holiday and diary entries
1309 if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
1310 Optional EVENT indicates a buffer position to use instead of point."
1311 (interactive (list (prefix-numeric-value current-prefix-arg
)
1312 last-nonmenu-event
))
1313 (cal-tex-weekly-common n event t
))
1316 (defun cal-tex-cursor-filofax-daily (&optional n event
)
1317 "Day-per-page Filofax style calendar for week indicated by cursor.
1318 Optional prefix argument N specifies number of weeks (default 1),
1319 starting on Mondays. The calendar shows holiday and diary
1320 entries if `cal-tex-holidays' and `cal-tex-diary', respectively,
1321 are non-nil. Pages are ruled if `cal-tex-rules' is non-nil.
1322 Optional EVENT indicates a buffer position to use instead of point."
1323 (interactive (list (prefix-numeric-value current-prefix-arg
)
1324 last-nonmenu-event
))
1326 (let* ((date (calendar-gregorian-from-absolute
1327 (calendar-dayname-on-or-before
1329 (calendar-absolute-from-gregorian
1330 (calendar-cursor-to-date t event
)))))
1331 (month (calendar-extract-month date
))
1332 (year (calendar-extract-year date
))
1333 (day (calendar-extract-day date
))
1334 (d1 (calendar-absolute-from-gregorian date
))
1336 (holidays (if cal-tex-holidays
1337 (holiday-in-range d1 d2
)))
1338 (diary-list (if cal-tex-diary
1339 (cal-tex-list-diary-entries d1 d2
))))
1340 (cal-tex-preamble "twoside")
1341 (cal-tex-filofax-paper)
1342 (insert cal-tex-righthead
)
1343 (cal-tex-shortday "rightday")
1344 (cal-tex-shortday "weekend")
1345 (insert cal-tex-lefthead
)
1346 (cal-tex-shortday "leftday")
1347 (insert "\\newbox\\LineBox
1348 \\setbox\\LineBox=\\hbox to\\textwidth{%
1349 \\vrule height.2in width0pt\\leaders\\hrule\\hfill}
1350 \\def\\linesfill{\\par\\leaders\\copy\\LineBox\\vfill}
1352 (cal-tex-b-document)
1353 (cal-tex-cmd "\\pagestyle" "empty")
1356 (let ((even (zerop (% j
2))))
1360 (cal-tex-arg (calendar-date-string date
))
1365 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1366 (cal-tex-arg (cal-tex-latexify-list holidays date
"\\\\" t
))
1367 (cal-tex-arg (eval cal-tex-daily-string
))
1370 (insert "\\linesfill\n")
1371 (insert "\\vfill\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1373 (setq date
(cal-tex-incr-date date
)))
1375 (dotimes (_jdummy 2)
1376 (insert "\\lefthead")
1377 (cal-tex-arg (calendar-date-string date
))
1378 (insert "\\weekend")
1379 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1380 (cal-tex-arg (cal-tex-latexify-list holidays date
"\\\\" t
))
1381 (cal-tex-arg (eval cal-tex-daily-string
))
1384 (insert "\\linesfill\n")
1386 (setq date
(cal-tex-incr-date date
)))
1388 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1389 (unless (= i
(1- n
))
1390 (run-hooks 'cal-tex-week-hook
)
1392 (cal-tex-end-document)
1393 (run-hooks 'cal-tex-hook
)))
1401 (defun cal-tex-cursor-day (&optional n event
)
1402 "Make a buffer with LaTeX commands for the day cursor is on.
1403 Optional prefix argument N specifies number of days. The calendar shows
1404 the hours between `cal-tex-daily-start' and `cal-tex-daily-end', using
1405 the 24-hour clock if `cal-tex-24' is non-nil. Optional EVENT indicates
1406 a buffer position to use instead of point."
1407 (interactive (list (prefix-numeric-value current-prefix-arg
)
1408 last-nonmenu-event
))
1410 (let ((date (calendar-absolute-from-gregorian
1411 (calendar-cursor-to-date t event
))))
1412 (cal-tex-preamble "12pt")
1413 (cal-tex-weekly-paper 'nomargins
)
1414 (cal-tex-b-document)
1415 (cal-tex-cmd "\\pagestyle" "empty")
1417 (cal-tex-vspace "-1.7in")
1418 (cal-tex-daily-page (calendar-gregorian-from-absolute date
))
1419 (setq date
(1+ date
))
1420 (unless (= i
(1- n
))
1422 (run-hooks 'cal-tex-daily-hook
)))
1423 (cal-tex-end-document)
1424 (run-hooks 'cal-tex-hook
)))
1426 (defun cal-tex-daily-page (date)
1427 "Make a calendar page for Gregorian DATE on 8.5 by 11 paper.
1428 Uses the 24-hour clock if `cal-tex-24' is non-nil. Produces
1429 hourly sections for the period specified by `cal-tex-daily-start'
1430 and `cal-tex-daily-end'."
1431 (let ((month-name (cal-tex-month-name (calendar-extract-month date
)))
1432 (i (1- cal-tex-daily-start
))
1434 (cal-tex-banner "cal-tex-daily-page")
1435 (cal-tex-b-makebox "4cm" "l")
1436 (cal-tex-b-parbox "b" "3.8cm")
1437 (cal-tex-rule "0mm" "0mm" "2cm")
1438 (cal-tex-Huge (number-to-string (calendar-extract-day date
)))
1440 (cal-tex-bf month-name
)
1442 (cal-tex-hspace "1cm")
1443 (cal-tex-scriptsize (eval cal-tex-daily-string
))
1444 (cal-tex-hspace "3.5cm")
1447 (cal-tex-b-makebox "4cm" "r")
1448 (cal-tex-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
1451 (cal-tex-hspace ".4cm")
1452 (cal-tex-rule "0mm" "16.1cm" "1mm")
1454 (while (<= (setq i
(1+ i
)) cal-tex-daily-end
)
1455 (cal-tex-cmd "\\noindent")
1456 (setq hour
(if cal-tex-24
1459 (if (zerop hour
) (setq hour
12))
1460 (cal-tex-b-makebox "1cm" "c")
1461 (cal-tex-arg (number-to-string hour
))
1463 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1465 (cal-tex-b-makebox "1cm" "c")
1466 (cal-tex-arg "$\\diamond$" )
1468 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1469 (cal-tex-nl ".2cm"))
1471 (insert (cal-tex-mini-calendar
1472 (calendar-extract-month (cal-tex-previous-month date
))
1473 (calendar-extract-year (cal-tex-previous-month date
))
1474 "lastmonth" "1.1in" "1in"))
1475 (insert (cal-tex-mini-calendar
1476 (calendar-extract-month date
)
1477 (calendar-extract-year date
)
1478 "thismonth" "1.1in" "1in"))
1479 (insert (cal-tex-mini-calendar
1480 (calendar-extract-month (cal-tex-next-month date
))
1481 (calendar-extract-year (cal-tex-next-month date
))
1482 "nextmonth" "1.1in" "1in"))
1483 (insert "\\hbox to \\textwidth{")
1485 (insert "\\lastmonth")
1487 (insert "\\thismonth")
1489 (insert "\\nextmonth")
1492 (cal-tex-banner "end of cal-tex-daily-page")))
1498 (defun cal-tex-mini-calendar (month year name width height
&optional ptsize colsep
)
1499 "Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT.
1500 Optional string PTSIZE gives the point size (default \"scriptsize\").
1501 Optional string COLSEP gives the column separation (default \"1mm\")."
1502 (or colsep
(setq colsep
"1mm"))
1503 (or ptsize
(setq ptsize
"scriptsize"))
1504 (let ((blank-days ; at start of month
1506 (- (calendar-day-of-week (list month
1 year
))
1507 calendar-week-start-day
)
1509 (last( calendar-last-day-of-month month year
))
1510 (str (concat "\\def\\" name
"{\\hbox to" width
"{%\n"
1511 "\\vbox to" height
"{%\n"
1512 "\\vfil \\hbox to" width
"{%\n"
1515 "{@{\\hspace{0mm}}r@{\\hspace{" colsep
1516 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{" colsep
1517 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{" colsep
1518 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{0mm}}}%\n"
1519 "\\multicolumn{7}{c}{"
1520 (cal-tex-month-name month
)
1522 (number-to-string year
)
1527 (cal-tex-LaTeXify-string
1528 (substring (aref calendar-day-name-array
1529 (mod (+ calendar-week-start-day i
) 7))
1535 (dotimes (_idummy blank-days
)
1536 (setq str
(concat str
" & ")))
1538 (setq str
(concat str
(number-to-string (1+ i
)))
1539 str
(concat str
(if (zerop (mod (+ i
1 blank-days
) 7))
1544 (setq str
(concat str
"\n\\end{tabular}\\hfil}\\vfil}}}%\n"))
1548 ;;; Various calendar functions
1551 (defun cal-tex-incr-date (date &optional n
)
1552 "The date of the day following DATE.
1553 If optional N is given, the date of N days after DATE."
1554 (calendar-gregorian-from-absolute
1555 (+ (or n
1) (calendar-absolute-from-gregorian date
))))
1557 (defun cal-tex-latexify-list (date-list date
&optional separator final-separator
)
1558 "Return string with concatenated, LaTeX-ified entries in DATE-LIST for DATE.
1559 Use double backslash as a separator unless optional SEPARATOR is given.
1560 If resulting string is not empty, put separator at end if optional
1561 FINAL-SEPARATOR is non-nil."
1562 (or separator
(setq separator
"\\\\"))
1565 (mapconcat (lambda (x) (cal-tex-LaTeXify-string x
))
1566 (dolist (d date-list
(reverse result
))
1568 (calendar-date-equal date
(car d
))
1569 (setq result
(cons (cadr d
) result
))))
1571 (if (and final-separator
1572 (not (string-equal result
"")))
1573 (concat result separator
)
1576 (defun cal-tex-previous-month (date)
1577 "Return the date of the first day in the month previous to DATE."
1578 (let ((month (calendar-extract-month date
))
1579 (year (calendar-extract-year date
)))
1580 (calendar-increment-month month year -
1)
1581 (list month
1 year
)))
1583 (defun cal-tex-next-month (date)
1584 "Return the date of the first day in the month following DATE."
1585 (let ((month (calendar-extract-month date
))
1586 (year (calendar-extract-year date
)))
1587 (calendar-increment-month month year
1)
1588 (list month
1 year
)))
1594 (defun cal-tex-end-document ()
1595 "Finish the LaTeX document.
1596 Insert the trailer to LaTeX document, pop to LaTeX buffer, add
1597 informative header, and run HOOK."
1598 (cal-tex-e-document)
1599 (or (and cal-tex-preamble-extra
1600 (string-match "inputenc" cal-tex-preamble-extra
))
1601 (when (re-search-backward "[^[:ascii:]]" nil
'move
)
1602 (goto-char (point-min))
1603 (when (search-forward "documentclass" nil t
)
1605 ;; Eg for some Bahai holidays.
1606 ;; FIXME latin1 might not always be right.
1607 (insert "\\usepackage[latin1]{inputenc}\n"))))
1609 (pop-to-buffer (current-buffer))
1610 (goto-char (point-min))
1611 ;; FIXME auctex equivalents?
1613 (format "\tThis buffer was produced by cal-tex.el.
1614 \tTo print a calendar, type
1615 \t\tM-x tex-buffer RET
1616 \t\tM-x tex-print RET")))
1618 (defun cal-tex-insert-preamble (weeks landscape size
&optional append
)
1619 "Initialize the output LaTeX calendar buffer, `cal-tex-buffer'.
1620 Select the output buffer, and insert the preamble for a calendar
1621 of WEEKS weeks. Insert code for landscape mode if LANDSCAPE is
1622 non-nil. Use point-size SIZE. Optional argument APPEND, if
1623 non-nil, means add to end of buffer without erasing current contents."
1624 (let ((width "18cm")
1630 (cal-tex-preamble size
)
1633 (cal-tex-cmd "\\oddsidemargin -1.75cm")
1634 (cal-tex-cmd "\\def\\holidaymult" ".06"))
1635 (cal-tex-cmd "\\special" "landscape")
1636 (cal-tex-cmd "\\textwidth 9.5in")
1637 (cal-tex-cmd "\\textheight 7in")
1639 (cal-tex-cmd "\\def\\holidaymult" ".08"))
1640 (cal-tex-cmd cal-tex-caldate
)
1641 (cal-tex-cmd cal-tex-myday
)
1642 (cal-tex-b-document)
1643 (cal-tex-cmd "\\pagestyle" "empty"))
1644 (cal-tex-cmd "\\setlength{\\cellwidth}" width
)
1645 (insert (format "\\setlength{\\cellwidth}{%f\\cellwidth}\n"
1646 (/ 1.1 (length cal-tex-which-days
))))
1647 (cal-tex-cmd "\\setlength{\\cellheight}" height
)
1648 (insert (format "\\setlength{\\cellheight}{%f\\cellheight}\n"
1650 (cal-tex-cmd "\\ \\par")
1651 (cal-tex-vspace "-3cm")))
1653 (defconst cal-tex-LaTeX-subst-list
1655 ("\"".
"''") ; quote changes meaning when list is reversed
1656 ;; Don't think this is necessary, and in any case, does not work:
1657 ;; "LaTeX Error: \verb illegal in command argument".
1658 ;;; ("@" . "\\verb|@|")
1668 ("\n" .
"\\ \\\\")) ; \\ needed for e.g \begin{center}\n AA\end{center}
1669 "Alist of symbols and their LaTeX replacements.")
1671 (defun cal-tex-LaTeXify-string (string)
1672 "Protect special characters in STRING from LaTeX."
1677 (list cal-tex-LaTeX-subst-list
)
1679 (while (not (string-equal tail
""))
1680 (setq ch
(substring-no-properties tail
0 1)
1681 pair
(assoc ch list
))
1682 (if (and pair
(string-equal ch
"\""))
1683 (setq list
(reverse list
))) ; quote changes meaning each time
1684 (setq tail
(substring-no-properties tail
1)
1685 head
(concat head
(if pair
(cdr pair
) ch
))))
1688 (defun cal-tex-month-name (month)
1689 "The name of MONTH, LaTeX-ified."
1690 (cal-tex-LaTeXify-string (calendar-month-name month
)))
1692 (defun cal-tex-hfill ()
1696 (defun cal-tex-newpage ()
1698 (insert "\\newpage%\n"))
1700 (defun cal-tex-noindent ()
1702 (insert "\\noindent"))
1704 (defun cal-tex-vspace (space)
1705 "Insert vspace command to move SPACE vertically."
1706 (cal-tex-cmd "\\vspace*" space
))
1708 (defun cal-tex-hspace (space)
1709 "Insert hspace command to move SPACE horizontally."
1710 (cal-tex-cmd "\\hspace*" space
))
1712 (defun cal-tex-comment (&optional comment
)
1713 "Insert `% ', followed by optional string COMMENT, followed by newline.
1714 COMMENT may contain newlines, which are prefixed by `% ' in the output."
1715 (insert (format "%% %s\n"
1717 (replace-regexp-in-string "\n" "\n% " comment
)
1720 (defun cal-tex-banner (comment)
1721 "Insert string COMMENT, separated by blank lines."
1722 (cal-tex-comment (format "\n\n\n\t\t\t%s\n" comment
)))
1724 (defun cal-tex-nl (&optional skip comment
)
1725 "End a line with \\. If SKIP, then add that much spacing.
1726 Add trailing COMMENT if present."
1727 (insert (format "\\\\%s"
1729 (format "[%s]" skip
)
1731 (cal-tex-comment comment
))
1733 (defun cal-tex-arg (&optional text
)
1734 "Insert a brace {} pair containing the optional string TEXT."
1735 (insert (format "{%s}" (or text
""))))
1737 (defun cal-tex-cmd (cmd &optional arg
)
1738 "Insert LaTeX CMD, with optional argument ARG, and end with %."
1747 (defun cal-tex-b-document ()
1748 "Insert beginning of document."
1749 (cal-tex-cmd "\\begin" "document"))
1751 (defun cal-tex-e-document ()
1752 "Insert end of document."
1753 (cal-tex-cmd "\\end" "document"))
1755 (defun cal-tex-b-center ()
1756 "Insert beginning of centered block."
1757 (cal-tex-cmd "\\begin" "center"))
1759 (defun cal-tex-e-center ()
1760 "Insert end of centered block."
1762 (cal-tex-cmd "\\end" "center"))
1770 (defun cal-tex-b-parbox (position width
)
1771 "Insert parbox with parameters POSITION and WIDTH."
1772 (insert "\\parbox[" position
"]{" width
"}{")
1775 (defun cal-tex-e-parbox (&optional height
)
1776 "Insert end of parbox. Optionally, force it to be a given HEIGHT."
1779 (cal-tex-rule "0mm" "0mm" height
))
1781 (cal-tex-comment "end parbox"))
1783 (defun cal-tex-b-framebox (width position
)
1784 "Insert framebox with parameters WIDTH and POSITION (clr)."
1785 (insert "\\framebox[" width
"][" position
"]{" )
1788 (defun cal-tex-e-framebox ()
1789 "Insert end of framebox."
1792 (cal-tex-comment "end framebox"))
1795 (defun cal-tex-b-makebox (width position
)
1796 "Insert makebox with parameters WIDTH and POSITION (clr)."
1797 (insert "\\makebox[" width
"][" position
"]{" )
1800 (defun cal-tex-e-makebox ()
1801 "Insert end of makebox."
1804 (cal-tex-comment "end makebox"))
1807 (defun cal-tex-rule (lower width height
)
1808 "Insert a rule with parameters LOWER WIDTH HEIGHT."
1809 (insert "\\rule[" lower
"]{" width
"}{" height
"}"))
1815 (defun cal-tex-em (string)
1816 "Insert STRING in italic font."
1817 (cal-tex-cmd "\\textit" string
))
1819 (defun cal-tex-bf (string)
1820 "Insert STRING in bf font."
1821 (cal-tex-cmd "\\textbf" string
))
1823 (defun cal-tex-scriptsize (string)
1824 "Insert STRING in scriptsize font."
1825 (cal-tex-arg (concat "\\scriptsize " string
)))
1827 (defun cal-tex-huge (string)
1828 "Insert STRING in huge font."
1829 (cal-tex-arg (concat "\\huge " string
)))
1831 (defun cal-tex-Huge (string)
1832 "Insert STRING in Huge font."
1833 (cal-tex-arg (concat "\\Huge " string
)))
1835 (defun cal-tex-Huge-bf (string)
1836 "Insert STRING in Huge bf font."
1837 (cal-tex-cmd "\\textbf" (concat "\\Huge " string
)))
1839 (defun cal-tex-large (string)
1840 "Insert STRING in large font."
1841 (cal-tex-arg (concat "\\large " string
)))
1843 (defun cal-tex-large-bf (string)
1844 "Insert STRING in large bf font."
1845 (cal-tex-cmd "\\textbf" (concat "\\large " string
)))
1850 ;;; cal-tex.el ends here