1 ;;; cal-tex.el --- calendar functions for printing calendars with LaTeX
3 ;; Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 ;; Free Software Foundation, Inc.
6 ;; Author: Steve Fisk <fisk@bowdoin.edu>
7 ;; Edward M. Reingold <reingold@cs.uiuc.edu>
8 ;; Maintainer: Glenn Morris <rgm@gnu.org>
10 ;; Human-Keywords: Calendar, LaTeX
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 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
) string
)
149 (defcustom cal-tex-hook nil
150 "List of functions called after any LaTeX calendar buffer is generated.
151 You can use this to do post-processing on the buffer. For example, to change
152 characters with diacritical marks to their LaTeX equivalents, use
153 (add-hook 'cal-tex-hook
154 (lambda () (iso-iso2tex (point-min) (point-max))))"
156 :group
'calendar-tex
)
158 (defcustom cal-tex-year-hook nil
159 "List of functions called after a LaTeX year calendar buffer is generated."
161 :group
'calendar-tex
)
163 (defcustom cal-tex-month-hook nil
164 "List of functions called after a LaTeX month calendar buffer is generated."
166 :group
'calendar-tex
)
168 (defcustom cal-tex-week-hook nil
169 "List of functions called after a LaTeX week calendar buffer is generated."
171 :group
'calendar-tex
)
173 (defcustom cal-tex-daily-hook nil
174 "List of functions called after a LaTeX daily calendar buffer is generated."
176 :group
'calendar-tex
)
179 ;;; Definitions for LaTeX code
182 (defconst cal-tex-day-prefix
"\\caldate{%s}{%s}"
183 "The initial LaTeX code for a day.
184 The holidays, diary entries, bottom string, and the text follow.")
186 (defconst cal-tex-day-name-format
"\\myday{%s}%%"
187 "The format for LaTeX code for a day name.
188 The names are taken from `calendar-day-name-array'.")
190 (defconst cal-tex-cal-one-month
191 "\\def\\calmonth#1#2%
193 \\Huge\\bf\\uppercase{#1} #2 \\\\[1cm]%
198 "LaTeX code for the month header, for a single month calendar.")
200 (defconst cal-tex-cal-multi-month
201 "\\def\\calmonth#1#2#3#4%
203 \\Huge\\bf #1 #2---#3 #4\\\\[1cm]%
208 "LaTeX code for the month header, for a multi-month calendar.")
210 (defconst cal-tex-myday
211 "\\renewcommand{\\myday}[1]%
212 {\\makebox[\\cellwidth]{\\hfill\\large\\bf#1\\hfill}}
215 "LaTeX code for a day heading.")
217 (defconst cal-tex-caldate
219 \\long\\def\\caldate#1#2#3#4#5#6{%
220 \\fbox{\\hbox to\\cellwidth{%
221 \\vbox to\\cellheight{%
222 \\hbox to\\cellwidth{%
223 {\\hspace*{1mm}\\Large \\bf \\strut #2}\\hspace{.05\\cellwidth}%
224 \\raisebox{\\holidaymult\\cellheight}%
225 {\\parbox[t]{.75\\cellwidth}{\\tiny \\raggedright #4}}}
226 \\hbox to\\cellwidth{%
227 \\hspace*{1mm}\\parbox{.95\\cellwidth}{\\tiny \\raggedright #3}}
229 \\hbox to\\cellwidth{#6}%
231 \\hbox to\\cellwidth{\\hfill \\tiny #5 \\hfill}%
235 "LaTeX code to insert one box with date info in calendar.
236 This definition is the heart of the calendar!")
238 (autoload 'calendar-holiday-list
"holidays")
240 (defun cal-tex-list-holidays (d1 d2
)
241 "Generate a list of all holidays from absolute date D1 to D2."
242 (let* ((start (calendar-gregorian-from-absolute d1
))
243 (displayed-month (calendar-extract-month start
))
244 (displayed-year (calendar-extract-year start
))
245 (end (calendar-gregorian-from-absolute d2
))
246 (end-month (calendar-extract-month end
))
247 (end-year (calendar-extract-year end
))
249 (1+ (/ (calendar-interval displayed-month displayed-year
253 (calendar-increment-month displayed-month displayed-year
1)
254 (dotimes (idummy number-of-intervals
)
255 (setq holidays
(append holidays
(calendar-holiday-list)))
256 (calendar-increment-month displayed-month displayed-year
3))
257 (dolist (hol holidays
)
259 (setq a
(calendar-absolute-from-gregorian (car hol
)))
260 (and (<= d1 a
) (<= a d2
))
261 (setq in-range
(append (list hol
) in-range
))))
264 (autoload 'diary-list-entries
"diary-lib")
266 (defun cal-tex-list-diary-entries (d1 d2
)
267 "Generate a list of all diary-entries from absolute date D1 to D2."
268 (let ((diary-list-include-blanks nil
)
269 (diary-display-hook 'ignore
))
271 (calendar-gregorian-from-absolute d1
)
274 (defun cal-tex-preamble (&optional args
)
275 "Insert the LaTeX calendar preamble into `cal-tex-buffer'.
276 Preamble includes initial definitions for various LaTeX commands.
277 Optional string ARGS are included as options for the article document class."
278 ;; FIXME use generate-new-buffer, and adjust cal-tex-end-document.
279 (set-buffer (get-buffer-create cal-tex-buffer
))
280 (insert (format "\\documentclass%s{article}\n"
284 (if (stringp cal-tex-preamble-extra
)
285 (insert cal-tex-preamble-extra
"\n"))
286 (insert "\\hbadness 20000
292 \\evensidemargin -2cm
297 \\newlength{\\cellwidth}
298 \\newlength{\\cellheight}
299 \\newlength{\\boxwidth}
300 \\newlength{\\boxheight}
301 \\newlength{\\cellsize}
302 \\newcommand{\\myday}[1]{}
303 \\newcommand{\\caldate}[6]{}
304 \\newcommand{\\nocaldate}[6]{}
305 \\newcommand{\\calsmall}[6]{}
314 (defun cal-tex-cursor-year (&optional arg
)
315 "Make a buffer with LaTeX commands for the year cursor is on.
316 Optional prefix argument ARG specifies number of years."
318 (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t
))
322 (defun cal-tex-cursor-year-landscape (&optional arg
)
323 "Make a buffer with LaTeX commands for the year cursor is on.
324 Optional prefix argument ARG specifies number of years."
326 (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t
))
329 (defun cal-tex-year (year n
&optional landscape
)
330 "Make a one page yearly calendar of YEAR; do this for N years.
331 There are four rows of three months each, unless optional
332 LANDSCAPE is non-nil, in which case the calendar is printed in
333 landscape mode with three rows of four months each."
334 (cal-tex-insert-preamble 1 landscape
"12pt")
336 (cal-tex-vspace "-.6cm")
337 (cal-tex-vspace "-3.1cm"))
339 (insert "\\vfill%\n")
341 (cal-tex-Huge (number-to-string year
))
343 (cal-tex-vspace "1cm")
345 (cal-tex-b-parbox "l" (if landscape
"5.9in" "4.3in"))
350 (insert (cal-tex-mini-calendar (1+ i
) year
"month" "1.1in" "1in"))
352 (cal-tex-hspace "0.5in")
353 (if (zerop (mod (1+ i
) (if landscape
4 3)))
354 (cal-tex-nl "0.5in")))
357 (insert "\\vfill%\n")
358 (setq year
(1+ year
))
360 (cal-tex-end-document)
362 (run-hooks 'cal-tex-year-hook
))
363 (run-hooks 'cal-tex-hook
))
366 (defun cal-tex-cursor-filofax-year (&optional arg
)
367 "Make a Filofax one page yearly calendar of year indicated by cursor.
368 Optional prefix argument ARG specifies number of years."
371 (year (calendar-extract-year (calendar-cursor-to-date t
))))
372 (cal-tex-preamble "twoside")
373 (cal-tex-cmd "\\textwidth 3.25in")
374 (cal-tex-cmd "\\textheight 6.5in")
375 (cal-tex-cmd "\\oddsidemargin 1.675in")
376 (cal-tex-cmd "\\evensidemargin 1.675in")
377 (cal-tex-cmd "\\topmargin 0pt")
378 (cal-tex-cmd "\\headheight -0.875in")
379 (cal-tex-cmd "\\fboxsep 0.5mm")
380 (cal-tex-cmd "\\pagestyle{empty}")
382 (cal-tex-cmd "\\vspace*{0.25in}")
384 (insert (format "\\hfil \\textbf{\\Large %s} \\hfil\\\\\n" year
))
386 (cal-tex-b-parbox "l" "\\textwidth")
390 (let ((month-names; don't use default in case user changed it
391 ;; These are only used to define the command names, not
392 ;; the names of the months they insert.
393 ["January" "February" "March" "April" "May" "June"
394 "July" "August" "September" "October" "November" "December"]))
396 (insert (cal-tex-mini-calendar (1+ i
) year
(aref month-names i
)
397 "1in" ".9in" "tiny" "0.6mm"))))
399 "\\noindent\\fbox{\\January}\\fbox{\\February}\\fbox{\\March}\\\\
400 \\noindent\\fbox{\\April}\\fbox{\\May}\\fbox{\\June}\\\\
401 \\noindent\\fbox{\\July}\\fbox{\\August}\\fbox{\\September}\\\\
402 \\noindent\\fbox{\\October}\\fbox{\\November}\\fbox{\\December}
406 (setq year
(1+ year
))
408 (cal-tex-end-document)
410 (cal-tex-cmd "\\vspace*{0.25in}"))
411 (run-hooks 'cal-tex-year-hook
))
412 (run-hooks 'cal-tex-hook
)))
415 ;;; Monthly calendars
419 (defun cal-tex-cursor-month-landscape (&optional arg
)
420 "Make a LaTeX calendar buffer for the month the cursor is on.
421 Optional prefix argument ARG specifies number of months to be
422 produced (default 1). The output is in landscape format, one
423 month to a page. It shows holiday and diary entries if
424 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil."
426 (let* ((n (or arg
1))
427 (date (calendar-cursor-to-date t
))
428 (month (calendar-extract-month date
))
429 (year (calendar-extract-year date
))
432 (cal-tex-which-days '(0 1 2 3 4 5 6))
433 (d1 (calendar-absolute-from-gregorian (list month
1 year
)))
434 (d2 (calendar-absolute-from-gregorian
436 (calendar-last-day-of-month end-month end-year
)
439 (calendar-increment-month end-month end-year
(1- n
))
440 (if cal-tex-diary
(cal-tex-list-diary-entries d1 d2
))))
441 (holidays (if cal-tex-holidays
(cal-tex-list-holidays d1 d2
)))
442 other-month other-year small-months-at-start
)
443 (cal-tex-insert-preamble (cal-tex-number-weeks month year
1) t
"12pt")
444 (cal-tex-cmd cal-tex-cal-one-month
)
446 (setq other-month month
448 (calendar-increment-month other-month other-year -
1)
449 (insert (cal-tex-mini-calendar other-month other-year
"lastmonth"
450 "\\cellwidth" "\\cellheight"))
451 (calendar-increment-month other-month other-year
2)
452 (insert (cal-tex-mini-calendar other-month other-year
"nextmonth"
453 "\\cellwidth" "\\cellheight"))
454 (cal-tex-insert-month-header 1 month year month year
)
455 (cal-tex-insert-day-names)
457 (if (setq small-months-at-start
458 (< 1 (mod (- (calendar-day-of-week (list month
1 year
))
459 calendar-week-start-day
)
461 (insert "\\lastmonth\\nextmonth\\hspace*{-2\\cellwidth}"))
462 (cal-tex-insert-blank-days month year cal-tex-day-prefix
)
463 (cal-tex-insert-days month year diary-list holidays
465 (cal-tex-insert-blank-days-at-end month year cal-tex-day-prefix
)
466 (if (and (not small-months-at-start
)
467 (< 1 (mod (- (1- calendar-week-start-day
)
468 (calendar-day-of-week
470 (calendar-last-day-of-month month year
)
473 (insert "\\vspace*{-\\cellwidth}\\hspace*{-2\\cellwidth}"
474 "\\lastmonth\\nextmonth%
477 (run-hooks 'cal-tex-month-hook
)
479 (calendar-increment-month month year
1)
480 (cal-tex-vspace "-2cm")
481 (cal-tex-insert-preamble
482 (cal-tex-number-weeks month year
1) t
"12pt" t
))))
483 (cal-tex-end-document)
484 (run-hooks 'cal-tex-hook
))
487 (defun cal-tex-cursor-month (arg)
488 "Make a LaTeX calendar buffer for the month the cursor is on.
489 Optional prefix argument ARG specifies number of months to be
490 produced (default 1). The calendar is condensed onto one page.
491 It shows holiday and diary entries if `cal-tex-holidays' and
492 `cal-tex-diary', respectively, are non-nil."
494 (let* ((n (or arg
1))
495 (date (calendar-cursor-to-date t
))
496 (month (calendar-extract-month date
))
497 (year (calendar-extract-year date
))
500 (d1 (calendar-absolute-from-gregorian (list month
1 year
)))
501 (d2 (calendar-absolute-from-gregorian
503 (calendar-last-day-of-month end-month end-year
)
506 (calendar-increment-month end-month end-year
(1- n
))
507 (if cal-tex-diary
(cal-tex-list-diary-entries d1 d2
))))
508 (holidays (if cal-tex-holidays
(cal-tex-list-holidays d1 d2
)))
509 other-month other-year
)
510 (cal-tex-insert-preamble (cal-tex-number-weeks month year n
) nil
"12pt")
512 (cal-tex-cmd cal-tex-cal-multi-month
)
513 (cal-tex-cmd cal-tex-cal-one-month
))
514 (cal-tex-insert-month-header n month year end-month end-year
)
515 (cal-tex-insert-day-names)
517 (cal-tex-insert-blank-days month year cal-tex-day-prefix
)
519 (setq other-month month
521 (cal-tex-insert-days month year diary-list holidays cal-tex-day-prefix
)
522 (when (= 6 (mod (calendar-absolute-from-gregorian
524 (calendar-last-day-of-month month year
)
526 7)) ; last day of month was Saturday
529 (calendar-increment-month month year
1))
530 (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix
))
531 (cal-tex-end-document)
532 (run-hooks 'cal-tex-hook
))
534 (defun cal-tex-insert-days (month year diary-list holidays day-format
)
535 "Insert LaTeX commands for a range of days in monthly calendars.
536 LaTeX commands are inserted for the days of the MONTH in YEAR.
537 Diary entries on DIARY-LIST are included. Holidays on HOLIDAYS
538 are included. Each day is formatted using format DAY-FORMAT."
539 (let ((blank-days ; at start of month
541 (- (calendar-day-of-week (list month
1 year
))
542 calendar-week-start-day
)
544 (last (calendar-last-day-of-month month year
))
547 (setq j
(1+ i
) ; 1-last, incl
548 date
(list month j year
))
549 (when (memq (calendar-day-of-week date
) cal-tex-which-days
)
550 (insert (format day-format
(cal-tex-month-name month
) j
))
551 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
552 (cal-tex-arg (cal-tex-latexify-list holidays date
))
553 (cal-tex-arg (eval cal-tex-daily-string
))
556 (when (and (zerop (mod (+ j blank-days
) 7))
561 (defun cal-tex-insert-day-names ()
562 "Insert the names of the days at top of a monthly calendar."
564 (if (memq i cal-tex-which-days
)
565 (insert (format cal-tex-day-name-format
566 (cal-tex-LaTeXify-string
567 (aref calendar-day-name-array
568 (mod (+ calendar-week-start-day i
) 7))))))
571 (defun cal-tex-insert-month-header (n month year end-month end-year
)
572 "Create a title for a calendar.
573 A title is inserted for a calendar with N months starting with
574 MONTH YEAR and ending with END-MONTH END-YEAR."
575 (let ((month-name (cal-tex-month-name month
))
576 (end-month-name (cal-tex-month-name end-month
)))
578 (insert (format "\\calmonth{%s}{%s}\n\\vspace*{-0.5cm}"
580 (insert (format "\\calmonth{%s}{%s}{%s}{%s}\n\\vspace*{-0.5cm}"
581 month-name year end-month-name end-year
))))
584 (defun cal-tex-insert-blank-days (month year day-format
)
585 "Insert code for initial days not in calendar.
586 Insert LaTeX code for the blank days at the beginning of the MONTH in
587 YEAR. The entry is formatted using DAY-FORMAT. If the entire week is
588 blank, no days are inserted."
589 (if (cal-tex-first-blank-p month year
)
590 (let ((blank-days ; at start of month
592 (- (calendar-day-of-week (list month
1 year
))
593 calendar-week-start-day
)
595 (dotimes (i blank-days
)
596 (if (memq i cal-tex-which-days
)
597 (insert (format day-format
" " " ") "{}{}{}{}%\n"))))))
599 (defun cal-tex-insert-blank-days-at-end (month year day-format
)
600 "Insert code for final days not in calendar.
601 Insert LaTeX code for the blank days at the end of the MONTH in YEAR.
602 The entry is formatted using DAY-FORMAT."
603 (if (cal-tex-last-blank-p month year
)
604 (let* ((last-day (calendar-last-day-of-month month year
))
605 (blank-days ; at end of month
607 (- (calendar-day-of-week (list month last-day year
))
608 calendar-week-start-day
)
611 (while (<= (setq i
(1+ i
)) 6)
612 (if (memq i cal-tex-which-days
)
613 (insert (format day-format
"" "") "{}{}{}{}%\n"))))))
615 (defun cal-tex-first-blank-p (month year
)
616 "Determine if any days of the first week will be printed.
617 Return t if there will there be any days of the first week printed
618 in the calendar starting in MONTH YEAR."
619 (let (any-days the-saturday
) ; the day of week of 1st Saturday
621 (if (= 6 (calendar-day-of-week (list month
(1+ i
) year
)))
622 (setq the-saturday
(1+ i
))))
623 (dotimes (i the-saturday
)
624 (if (memq (calendar-day-of-week (list month
(1+ i
) year
))
629 (defun cal-tex-last-blank-p (month year
)
630 "Determine if any days of the last week will be printed.
631 Return t if there will there be any days of the last week printed
632 in the calendar starting in MONTH YEAR."
633 (let* ((last-day (calendar-last-day-of-month month year
))
635 any-days the-sunday
) ; the day of week of last Sunday
636 (while (<= (setq i
(1+ i
)) last-day
)
637 (if (zerop (calendar-day-of-week (list month i year
)))
638 (setq the-sunday i
)))
639 (setq i
(1- the-sunday
))
640 (while (<= (setq i
(1+ i
)) last-day
)
641 (if (memq (calendar-day-of-week (list month i year
)) cal-tex-which-days
)
645 (defun cal-tex-number-weeks (month year n
)
646 "Determine the number of weeks in a range of dates.
647 Compute the number of weeks in the calendar starting with MONTH and YEAR,
648 and lasting N months, including only the days in WHICH-DAYS. As it stands,
649 this is only an upper bound."
650 (let ((d (list month
1 year
)))
651 (calendar-increment-month month year
(1- n
))
652 (/ (- (calendar-dayname-on-or-before
653 calendar-week-start-day
654 (+ 7 (calendar-absolute-from-gregorian
655 (list month
(calendar-last-day-of-month month year
) year
))))
656 (calendar-dayname-on-or-before
657 calendar-week-start-day
658 (calendar-absolute-from-gregorian d
)))
665 (defconst cal-tex-LaTeX-hourbox
666 "\\newcommand{\\hourbox}[2]%
667 {\\makebox[2em]{\\rule{0cm}{#2ex}#1}\\rule{3in}{.15mm}}\n"
668 "One hour and a line on the right.")
670 ;; TODO cal-tex-diary-support.
671 ;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
673 (defun cal-tex-cursor-week (&optional arg
)
674 "Make a LaTeX calendar buffer for a two-page one-week calendar.
675 It applies to the week that point is in. The optional prefix
676 argument ARG specifies the number of weeks (default 1). The calendar
677 shows holidays if `cal-tex-holidays' is non-nil (note that diary
678 entries are not shown). The calendar shows the hours 8-12am, 1-5pm."
680 (let* ((n (or arg
1))
681 (date (calendar-gregorian-from-absolute
682 (calendar-dayname-on-or-before
683 calendar-week-start-day
684 (calendar-absolute-from-gregorian
685 (calendar-cursor-to-date t
)))))
686 (month (calendar-extract-month date
))
687 (year (calendar-extract-year date
))
688 (d1 (calendar-absolute-from-gregorian date
))
690 (holidays (if cal-tex-holidays
691 (cal-tex-list-holidays d1 d2
))))
692 (cal-tex-preamble "11pt")
693 (cal-tex-cmd "\\textwidth 6.5in")
694 (cal-tex-cmd "\\textheight 10.5in")
695 (cal-tex-cmd "\\oddsidemargin 0in")
696 (cal-tex-cmd "\\evensidemargin 0in")
697 (insert cal-tex-LaTeX-hourbox
)
699 (cal-tex-cmd "\\pagestyle{empty}")
701 (cal-tex-vspace "-1.5in")
703 (cal-tex-Huge-bf (format "\\uppercase{%s}"
704 (cal-tex-month-name month
)))
705 (cal-tex-hspace "2em")
706 (cal-tex-Huge-bf (number-to-string year
))
709 (cal-tex-hspace "-.2in")
710 (cal-tex-b-parbox "l" "7in")
712 (cal-tex-week-hours date holidays
"3.1")
713 (setq date
(cal-tex-incr-date date
)))
715 (setq month
(calendar-extract-month date
)
716 year
(calendar-extract-year date
))
718 (run-hooks 'cal-tex-week-hook
)
720 (cal-tex-end-document)
721 (run-hooks 'cal-tex-hook
)))
723 ;; TODO cal-tex-diary support.
724 ;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
726 (defun cal-tex-cursor-week2 (&optional arg
)
727 "Make a LaTeX calendar buffer for a two-page one-week calendar.
728 It applies to the week that point is in. Optional prefix
729 argument ARG specifies number of weeks (default 1). The calendar
730 shows holidays if `cal-tex-holidays' is non-nil (note that diary
731 entries are not shown). The calendar shows the hours 8-12am, 1-5pm"
733 (let* ((n (or arg
1))
734 (date (calendar-gregorian-from-absolute
735 (calendar-dayname-on-or-before
736 calendar-week-start-day
737 (calendar-absolute-from-gregorian
738 (calendar-cursor-to-date t
)))))
739 (month (calendar-extract-month date
))
740 (year (calendar-extract-year date
))
742 (d1 (calendar-absolute-from-gregorian date
))
744 (holidays (if cal-tex-holidays
745 (cal-tex-list-holidays d1 d2
))))
746 (cal-tex-preamble "12pt")
747 (cal-tex-cmd "\\textwidth 6.5in")
748 (cal-tex-cmd "\\textheight 10.5in")
749 (cal-tex-cmd "\\oddsidemargin 0in")
750 (cal-tex-cmd "\\evensidemargin 0in")
751 (insert cal-tex-LaTeX-hourbox
)
753 (cal-tex-cmd "\\pagestyle{empty}")
755 (cal-tex-vspace "-1.5in")
757 (cal-tex-Huge-bf (format "\\uppercase{%s}"
758 (cal-tex-month-name month
)))
759 (cal-tex-hspace "2em")
760 (cal-tex-Huge-bf (number-to-string year
))
763 (cal-tex-hspace "-.2in")
764 (cal-tex-b-parbox "l" "\\textwidth")
766 (cal-tex-week-hours date holidays
"5")
767 (setq date
(cal-tex-incr-date date
)))
770 (insert (cal-tex-mini-calendar
771 (calendar-extract-month (cal-tex-previous-month date
))
772 (calendar-extract-year (cal-tex-previous-month date
))
773 "lastmonth" "1.1in" "1in"))
774 (insert (cal-tex-mini-calendar
775 (calendar-extract-month date
)
776 (calendar-extract-year date
)
777 "thismonth" "1.1in" "1in"))
778 (insert (cal-tex-mini-calendar
779 (calendar-extract-month (cal-tex-next-month date
))
780 (calendar-extract-year (cal-tex-next-month date
))
781 "nextmonth" "1.1in" "1in"))
782 (insert "\\hbox to \\textwidth{")
784 (insert "\\lastmonth")
786 (insert "\\thismonth")
788 (insert "\\nextmonth")
792 (cal-tex-b-parbox "l" "\\textwidth")
794 (cal-tex-week-hours date holidays
"5")
795 (setq date
(cal-tex-incr-date date
)))
797 (setq month
(calendar-extract-month date
)
798 year
(calendar-extract-year date
))
800 (run-hooks 'cal-tex-week-hook
)
802 (cal-tex-end-document)
803 (run-hooks 'cal-tex-hook
)))
805 (autoload 'calendar-iso-from-absolute
"cal-iso")
808 (defun cal-tex-cursor-week-iso (&optional arg
)
809 "Make a LaTeX calendar buffer for a one page ISO-style weekly calendar.
810 Optional prefix argument ARG specifies number of weeks (default 1).
811 The calendar shows holiday and diary entries if
812 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
813 It does not show hours of the day."
815 (let* ((n (or arg
1))
816 (date (calendar-gregorian-from-absolute
817 (calendar-dayname-on-or-before
819 (calendar-absolute-from-gregorian
820 (calendar-cursor-to-date t
)))))
821 (month (calendar-extract-month date
))
822 (year (calendar-extract-year date
))
823 (day (calendar-extract-day date
))
824 (d1 (calendar-absolute-from-gregorian date
))
826 (holidays (if cal-tex-holidays
827 (cal-tex-list-holidays d1 d2
)))
828 (diary-list (if cal-tex-diary
829 (cal-tex-list-diary-entries
831 (calendar-absolute-from-gregorian (list month
1 year
))
834 (cal-tex-preamble "11pt")
835 (cal-tex-cmd "\\textwidth 6.5in")
836 (cal-tex-cmd "\\textheight 10.5in")
837 (cal-tex-cmd "\\oddsidemargin 0in")
838 (cal-tex-cmd "\\evensidemargin 0in")
840 (cal-tex-cmd "\\pagestyle{empty}")
842 (cal-tex-vspace "-1.5in")
845 (let ((d (calendar-iso-from-absolute
846 (calendar-absolute-from-gregorian date
))))
847 (format "Week %d of %d"
848 (calendar-extract-month d
)
849 (calendar-extract-year d
))))
852 (cal-tex-b-parbox "l" "\\textwidth")
854 (cal-tex-b-parbox "t" "\\textwidth")
855 (cal-tex-b-parbox "t" "\\textwidth")
856 (cal-tex-rule "0pt" "\\textwidth" ".2mm")
858 (cal-tex-b-parbox "t" "\\textwidth")
859 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
861 (cal-tex-large-bf (cal-tex-month-name month
))
863 (cal-tex-large-bf (number-to-string day
))
864 (unless (string-equal "" (setq s
(cal-tex-latexify-list
865 holidays date
"; ")))
867 (cal-tex-large-bf s
))
869 (insert " " (eval cal-tex-daily-string
))
873 (cal-tex-b-parbox "t" "\\textwidth")
874 (unless (string-equal "" (setq s
(cal-tex-latexify-list
876 (insert "\\vbox to 0pt{")
881 (setq date
(cal-tex-incr-date date
)
882 month
(calendar-extract-month date
)
883 day
(calendar-extract-day date
))
885 (cal-tex-e-parbox "2cm")
887 (setq month
(calendar-extract-month date
)
888 year
(calendar-extract-year date
)))
891 (run-hooks 'cal-tex-week-hook
)
893 (cal-tex-end-document)
894 (run-hooks 'cal-tex-hook
)))
896 ;; TODO respect cal-tex-daily-start,end?
897 ;; Using different numbers of hours will probably break some layouts.
898 (defun cal-tex-week-hours (date holidays height
)
899 "Insert hourly entries for DATE with HOLIDAYS, with line height HEIGHT.
900 Uses the 24-hour clock if `cal-tex-24' is non-nil. Note that the hours
901 shown are hard-coded to 8-12, 13-17."
902 (let ((month (calendar-extract-month date
))
903 (day (calendar-extract-day date
))
904 (year (calendar-extract-year date
))
906 (cal-tex-comment "begin cal-tex-week-hours")
907 (cal-tex-cmd "\\ \\\\[-.2cm]")
908 (cal-tex-cmd "\\noindent")
909 (cal-tex-b-parbox "l" "6.8in")
910 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
912 (cal-tex-large-bf (cal-tex-month-name month
))
914 (cal-tex-large-bf (number-to-string day
))
915 (unless (string-equal "" (setq s
(cal-tex-latexify-list
916 holidays date
"; ")))
918 (cal-tex-large-bf s
))
920 (insert " " (eval cal-tex-daily-string
))
923 (cal-tex-rule "0pt" "6.8in" ".2mm")
926 (setq morning
(+ i
8) ; 8-12 incl
927 afternoon
(if cal-tex-24
928 (+ i
13) ; 13-17 incl
930 (cal-tex-cmd "\\hourbox" (number-to-string morning
))
932 (cal-tex-hspace ".4cm")
933 (cal-tex-cmd "\\hourbox" (number-to-string afternoon
))
937 ;; TODO cal-tex-diary support.
938 ;; TODO respect cal-tex-daily-start,end (see cal-tex-weekly4-box).
940 (defun cal-tex-cursor-week-monday (&optional arg
)
941 "Make a LaTeX calendar buffer for a two-page one-week calendar.
942 It applies to the week that point is in, and starts on Monday.
943 Optional prefix argument ARG specifies number of weeks (default 1).
944 The calendar shows holidays if `cal-tex-holidays' is
945 non-nil (note that diary entries are not shown). The calendar shows
946 the hours 8-12am, 1-5pm."
949 (date (calendar-gregorian-from-absolute
950 (calendar-dayname-on-or-before
952 (calendar-absolute-from-gregorian
953 (calendar-cursor-to-date t
))))))
954 (cal-tex-preamble "11pt")
955 (cal-tex-cmd "\\textwidth 6.5in")
956 (cal-tex-cmd "\\textheight 10.5in")
957 (cal-tex-cmd "\\oddsidemargin 0in")
958 (cal-tex-cmd "\\evensidemargin 0in")
961 (cal-tex-vspace "-1cm")
962 (insert "\\noindent ")
963 (cal-tex-weekly4-box (cal-tex-incr-date date
) nil
)
964 (cal-tex-weekly4-box (cal-tex-incr-date date
4) nil
)
966 (cal-tex-weekly4-box (cal-tex-incr-date date
2) nil
)
967 (cal-tex-weekly4-box (cal-tex-incr-date date
5) nil
)
969 (cal-tex-weekly4-box (cal-tex-incr-date date
3) nil
)
970 (cal-tex-weekly4-box (cal-tex-incr-date date
6) t
)
972 (run-hooks 'cal-tex-week-hook
)
973 (setq date
(cal-tex-incr-date date
7))
975 (cal-tex-end-document)
976 (run-hooks 'cal-tex-hook
)))
978 ;; TODO respect cal-tex-daily-start,end?
979 ;; Using different numbers of hours will probably break some layouts.
980 (defun cal-tex-weekly4-box (date weekend
)
981 "Make one box for DATE, different if WEEKEND.
982 Uses the 24-hour clock if `cal-tex-24' is non-nil. Note that the hours
983 shown are hard-coded to 8-12, 13-17."
984 (let* ((day (calendar-extract-day date
))
985 (month (calendar-extract-month date
))
986 (year (calendar-extract-year date
))
987 (dayname (cal-tex-LaTeXify-string (calendar-day-name date
)))
988 (date1 (cal-tex-incr-date date
))
989 (day1 (calendar-extract-day date1
))
990 (month1 (calendar-extract-month date1
))
991 (year1 (calendar-extract-year date1
))
992 (dayname1 (cal-tex-LaTeXify-string (calendar-day-name date1
))))
993 (cal-tex-b-framebox "8cm" "l")
994 (cal-tex-b-parbox "b" "7.5cm")
995 (insert (format "\\textbf{\\Large %s,} %s/%s/%s\\\\\n"
996 dayname month day year
))
997 (cal-tex-rule "0pt" "7.5cm" ".5mm")
1001 (insert (format "\\textsf{\\large %d}\\\\\n" (+ i
8))))
1003 (insert (format "\\textsf{\\large %d}\\\\\n"
1005 (+ i
13) ; 13-17 incl
1006 (1+ i
)))))) ; 1-5 incl
1009 (cal-tex-vspace "1cm")
1010 (insert "\\ \\vfill")
1011 (insert (format "\\textbf{\\Large %s,} %s/%s/%s\\\\\n"
1012 dayname1 month1 day1 year1
))
1013 (cal-tex-rule "0pt" "7.5cm" ".5mm")
1014 (cal-tex-nl "1.5cm")
1015 (cal-tex-vspace "1cm"))
1017 (cal-tex-e-framebox)
1018 (cal-tex-hspace "1cm")))
1021 (defun cal-tex-cursor-filofax-2week (&optional arg
)
1022 "Two-weeks-at-a-glance Filofax style calendar for week cursor is in.
1023 Optional prefix argument ARG specifies number of weeks (default 1).
1024 The calendar shows holiday and diary entries if
1025 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil."
1027 (let* ((n (or arg
1))
1028 (date (calendar-gregorian-from-absolute
1029 (calendar-dayname-on-or-before
1030 calendar-week-start-day
1031 (calendar-absolute-from-gregorian
1032 (calendar-cursor-to-date t
)))))
1033 (month (calendar-extract-month date
))
1034 (year (calendar-extract-year date
))
1035 (day (calendar-extract-day date
))
1036 (d1 (calendar-absolute-from-gregorian date
))
1038 (holidays (if cal-tex-holidays
1039 (cal-tex-list-holidays d1 d2
)))
1040 (diary-list (if cal-tex-diary
1041 (cal-tex-list-diary-entries
1043 (calendar-absolute-from-gregorian (list month
1 year
))
1045 (cal-tex-preamble "twoside")
1046 (cal-tex-cmd "\\textwidth 3.25in")
1047 (cal-tex-cmd "\\textheight 6.5in")
1048 (cal-tex-cmd "\\oddsidemargin 1.75in")
1049 (cal-tex-cmd "\\evensidemargin 1.5in")
1050 (cal-tex-cmd "\\topmargin 0pt")
1051 (cal-tex-cmd "\\headheight -0.875in")
1052 (cal-tex-cmd "\\headsep 0.125in")
1053 (cal-tex-cmd "\\footskip .125in")
1054 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1055 \\long\\def\\rightday#1#2#3#4#5{%
1056 \\rule{\\textwidth}{0.3pt}\\\\%
1057 \\hbox to \\textwidth{%
1060 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1061 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1062 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1063 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1064 \\long\\def\\leftday#1#2#3#4#5{%
1065 \\rule{\\textwidth}{0.3pt}\\\\%
1066 \\hbox to \\textwidth{%
1069 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1070 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1071 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1073 (cal-tex-b-document)
1074 (cal-tex-cmd "\\pagestyle{empty}")
1076 (if (zerop (mod i
2))
1077 (insert "\\righthead")
1078 (insert "\\lefthead"))
1080 (let ((d (cal-tex-incr-date date
6)))
1081 (if (= (calendar-extract-month date
)
1082 (calendar-extract-month d
))
1084 (cal-tex-month-name (calendar-extract-month date
))
1085 (calendar-extract-year date
))
1086 (if (= (calendar-extract-year date
)
1087 (calendar-extract-year d
))
1088 (format "%s---%s %s"
1089 (cal-tex-month-name (calendar-extract-month date
))
1090 (cal-tex-month-name (calendar-extract-month d
))
1091 (calendar-extract-year date
))
1092 (format "%s %s---%s %s"
1093 (cal-tex-month-name (calendar-extract-month date
))
1094 (calendar-extract-year date
)
1095 (cal-tex-month-name (calendar-extract-month d
))
1096 (calendar-extract-year d
))))))
1099 (if (zerop (mod i
2))
1100 (insert "\\rightday")
1101 (insert "\\leftday"))
1102 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1103 (cal-tex-arg (number-to-string (calendar-extract-day date
)))
1104 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1105 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1106 (cal-tex-arg (eval cal-tex-daily-string
))
1108 (setq date
(cal-tex-incr-date date
)))
1109 (unless (= i
(1- n
))
1110 (run-hooks 'cal-tex-week-hook
)
1112 (cal-tex-end-document)
1113 (run-hooks 'cal-tex-hook
)))
1116 (defun cal-tex-cursor-filofax-week (&optional arg
)
1117 "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
1118 Optional prefix argument ARG specifies number of weeks (default 1),
1119 starting on Mondays. The calendar shows holiday and diary entries
1120 if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil."
1122 (let* ((n (or arg
1))
1123 (date (calendar-gregorian-from-absolute
1124 (calendar-dayname-on-or-before
1126 (calendar-absolute-from-gregorian
1127 (calendar-cursor-to-date t
)))))
1128 (month (calendar-extract-month date
))
1129 (year (calendar-extract-year date
))
1130 (day (calendar-extract-day date
))
1131 (d1 (calendar-absolute-from-gregorian date
))
1133 (holidays (if cal-tex-holidays
1134 (cal-tex-list-holidays d1 d2
)))
1135 (diary-list (if cal-tex-diary
1136 (cal-tex-list-diary-entries
1138 (calendar-absolute-from-gregorian (list month
1 year
))
1140 (cal-tex-preamble "twoside")
1141 (cal-tex-cmd "\\textwidth 3.25in")
1142 (cal-tex-cmd "\\textheight 6.5in")
1143 (cal-tex-cmd "\\oddsidemargin 1.75in")
1144 (cal-tex-cmd "\\evensidemargin 1.5in")
1145 (cal-tex-cmd "\\topmargin 0pt")
1146 (cal-tex-cmd "\\headheight -0.875in")
1147 (cal-tex-cmd "\\headsep 0.125in")
1148 (cal-tex-cmd "\\footskip .125in")
1149 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1150 \\long\\def\\rightday#1#2#3#4#5{%
1151 \\rule{\\textwidth}{0.3pt}\\\\%
1152 \\hbox to \\textwidth{%
1155 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1156 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1157 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1158 \\long\\def\\weekend#1#2#3#4#5{%
1159 \\rule{\\textwidth}{0.3pt}\\\\%
1160 \\hbox to \\textwidth{%
1163 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1164 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1165 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1166 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1167 \\long\\def\\leftday#1#2#3#4#5{%
1168 \\rule{\\textwidth}{0.3pt}\\\\%
1169 \\hbox to \\textwidth{%
1172 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1173 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1174 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1176 (cal-tex-b-document)
1177 (cal-tex-cmd "\\pagestyle{empty}\\ ")
1180 (insert "\\lefthead")
1182 (let ((d (cal-tex-incr-date date
2)))
1183 (if (= (calendar-extract-month date
)
1184 (calendar-extract-month d
))
1186 (cal-tex-month-name (calendar-extract-month date
))
1187 (calendar-extract-year date
))
1188 (if (= (calendar-extract-year date
)
1189 (calendar-extract-year d
))
1190 (format "%s---%s %s"
1191 (cal-tex-month-name (calendar-extract-month date
))
1192 (cal-tex-month-name (calendar-extract-month d
))
1193 (calendar-extract-year date
))
1194 (format "%s %s---%s %s"
1195 (cal-tex-month-name (calendar-extract-month date
))
1196 (calendar-extract-year date
)
1197 (cal-tex-month-name (calendar-extract-month d
))
1198 (calendar-extract-year d
))))))
1201 (insert "\\leftday")
1202 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1203 (cal-tex-arg (number-to-string (calendar-extract-day date
)))
1204 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1205 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1206 (cal-tex-arg (eval cal-tex-daily-string
))
1208 (setq date
(cal-tex-incr-date date
)))
1209 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1211 (insert "\\righthead")
1213 (let ((d (cal-tex-incr-date date
3)))
1214 (if (= (calendar-extract-month date
)
1215 (calendar-extract-month d
))
1217 (cal-tex-month-name (calendar-extract-month date
))
1218 (calendar-extract-year date
))
1219 (if (= (calendar-extract-year date
)
1220 (calendar-extract-year d
))
1221 (format "%s---%s %s"
1222 (cal-tex-month-name (calendar-extract-month date
))
1223 (cal-tex-month-name (calendar-extract-month d
))
1224 (calendar-extract-year date
))
1225 (format "%s %s---%s %s"
1226 (cal-tex-month-name (calendar-extract-month date
))
1227 (calendar-extract-year date
)
1228 (cal-tex-month-name (calendar-extract-month d
))
1229 (calendar-extract-year d
))))))
1232 (insert "\\rightday")
1233 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1234 (cal-tex-arg (number-to-string (calendar-extract-day date
)))
1235 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1236 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1237 (cal-tex-arg (eval cal-tex-daily-string
))
1239 (setq date
(cal-tex-incr-date date
)))
1241 (insert "\\weekend")
1242 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1243 (cal-tex-arg (number-to-string (calendar-extract-day date
)))
1244 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1245 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1246 (cal-tex-arg (eval cal-tex-daily-string
))
1248 (setq date
(cal-tex-incr-date date
)))
1249 (unless (= i
(1- n
))
1250 (run-hooks 'cal-tex-week-hook
)
1252 (cal-tex-end-document)
1253 (run-hooks 'cal-tex-hook
)))
1256 (defun cal-tex-cursor-filofax-daily (&optional arg
)
1257 "Day-per-page Filofax style calendar for week indicated by cursor.
1258 Optional prefix argument ARG specifies number of weeks (default 1),
1259 starting on Mondays. The calendar shows holiday and diary
1260 entries if `cal-tex-holidays' and `cal-tex-diary', respectively,
1261 are non-nil. Pages are ruled if `cal-tex-rules' is non-nil."
1263 (let* ((n (or arg
1))
1264 (date (calendar-gregorian-from-absolute
1265 (calendar-dayname-on-or-before
1267 (calendar-absolute-from-gregorian
1268 (calendar-cursor-to-date t
)))))
1269 (month (calendar-extract-month date
))
1270 (year (calendar-extract-year date
))
1271 (day (calendar-extract-day date
))
1272 (d1 (calendar-absolute-from-gregorian date
))
1274 (holidays (if cal-tex-holidays
1275 (cal-tex-list-holidays d1 d2
)))
1276 (diary-list (if cal-tex-diary
1277 (cal-tex-list-diary-entries
1279 (calendar-absolute-from-gregorian (list month
1 year
))
1281 (cal-tex-preamble "twoside")
1282 (cal-tex-cmd "\\textwidth 3.25in")
1283 (cal-tex-cmd "\\textheight 6.5in")
1284 (cal-tex-cmd "\\oddsidemargin 1.75in")
1285 (cal-tex-cmd "\\evensidemargin 1.5in")
1286 (cal-tex-cmd "\\topmargin 0pt")
1287 (cal-tex-cmd "\\headheight -0.875in")
1288 (cal-tex-cmd "\\headsep 0.125in")
1289 (cal-tex-cmd "\\footskip .125in")
1290 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1291 \\long\\def\\rightday#1#2#3{%
1292 \\rule{\\textwidth}{0.3pt}\\\\%
1293 \\hbox to \\textwidth{%
1296 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1297 \\hbox to \\textwidth{\\vbox {\\raggedleft \\em #2}}%
1298 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1299 \\long\\def\\weekend#1#2#3{%
1300 \\rule{\\textwidth}{0.3pt}\\\\%
1301 \\hbox to \\textwidth{%
1304 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1305 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1306 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1307 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1308 \\long\\def\\leftday#1#2#3{%
1309 \\rule{\\textwidth}{0.3pt}\\\\%
1310 \\hbox to \\textwidth{%
1313 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1314 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1315 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1317 \\setbox\\LineBox=\\hbox to\\textwidth{%
1318 \\vrule height.2in width0pt\\leaders\\hrule\\hfill}
1319 \\def\\linesfill{\\par\\leaders\\copy\\LineBox\\vfill}
1321 (cal-tex-b-document)
1322 (cal-tex-cmd "\\pagestyle{empty}")
1325 (let ((even (zerop (% j
2))))
1329 (cal-tex-arg (calendar-date-string date
))
1334 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1335 (cal-tex-arg (cal-tex-latexify-list holidays date
"\\\\" t
))
1336 (cal-tex-arg (eval cal-tex-daily-string
))
1339 (insert "\\linesfill\n")
1340 (insert "\\vfill\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1342 (setq date
(cal-tex-incr-date date
)))
1345 (insert "\\lefthead")
1346 (cal-tex-arg (calendar-date-string date
))
1347 (insert "\\weekend")
1348 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1349 (cal-tex-arg (cal-tex-latexify-list holidays date
"\\\\" t
))
1350 (cal-tex-arg (eval cal-tex-daily-string
))
1353 (insert "\\linesfill\n")
1355 (setq date
(cal-tex-incr-date date
)))
1357 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1358 (unless (= i
(1- n
))
1359 (run-hooks 'cal-tex-week-hook
)
1361 (cal-tex-end-document)
1362 (run-hooks 'cal-tex-hook
)))
1370 (defun cal-tex-cursor-day (&optional arg
)
1371 "Make a buffer with LaTeX commands for the day cursor is on.
1372 Optional prefix argument ARG specifies number of days. The calendar shows
1373 the hours between `cal-tex-daily-start' and `cal-tex-daily-end', using
1374 the 24-hour clock if `cal-tex-24' is non-nil."
1376 (let ((n (or arg
1))
1377 (date (calendar-absolute-from-gregorian (calendar-cursor-to-date t
))))
1378 (cal-tex-preamble "12pt")
1379 (cal-tex-cmd "\\textwidth 6.5in")
1380 (cal-tex-cmd "\\textheight 10.5in")
1381 (cal-tex-b-document)
1382 (cal-tex-cmd "\\pagestyle{empty}")
1384 (cal-tex-vspace "-1.7in")
1385 (cal-tex-daily-page (calendar-gregorian-from-absolute date
))
1386 (setq date
(1+ date
))
1387 (unless (= i
(1- n
))
1389 (run-hooks 'cal-tex-daily-hook
)))
1390 (cal-tex-end-document)
1391 (run-hooks 'cal-tex-hook
)))
1393 (defun cal-tex-daily-page (date)
1394 "Make a calendar page for Gregorian DATE on 8.5 by 11 paper.
1395 Uses the 24-hour clock if `cal-tex-24' is non-nil. Produces
1396 hourly sections for the period specified by `cal-tex-daily-start'
1397 and `cal-tex-daily-end'."
1398 (let ((month-name (cal-tex-month-name (calendar-extract-month date
)))
1399 (i (1- cal-tex-daily-start
))
1401 (cal-tex-banner "cal-tex-daily-page")
1402 (cal-tex-b-makebox "4cm" "l")
1403 (cal-tex-b-parbox "b" "3.8cm")
1404 (cal-tex-rule "0mm" "0mm" "2cm")
1405 (cal-tex-Huge (number-to-string (calendar-extract-day date
)))
1407 (cal-tex-bf month-name
)
1409 (cal-tex-hspace "1cm")
1410 (cal-tex-scriptsize (eval cal-tex-daily-string
))
1411 (cal-tex-hspace "3.5cm")
1414 (cal-tex-b-makebox "4cm" "r")
1415 (cal-tex-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
1418 (cal-tex-hspace ".4cm")
1419 (cal-tex-rule "0mm" "16.1cm" "1mm")
1421 (while (<= (setq i
(1+ i
)) cal-tex-daily-end
)
1422 (cal-tex-cmd "\\noindent")
1423 (setq hour
(if cal-tex-24
1426 (if (zerop hour
) (setq hour
12))
1427 (cal-tex-b-makebox "1cm" "c")
1428 (cal-tex-arg (number-to-string hour
))
1430 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1432 (cal-tex-b-makebox "1cm" "c")
1433 (cal-tex-arg "$\\diamond$" )
1435 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1436 (cal-tex-nl ".2cm"))
1438 (insert (cal-tex-mini-calendar
1439 (calendar-extract-month (cal-tex-previous-month date
))
1440 (calendar-extract-year (cal-tex-previous-month date
))
1441 "lastmonth" "1.1in" "1in"))
1442 (insert (cal-tex-mini-calendar
1443 (calendar-extract-month date
)
1444 (calendar-extract-year date
)
1445 "thismonth" "1.1in" "1in"))
1446 (insert (cal-tex-mini-calendar
1447 (calendar-extract-month (cal-tex-next-month date
))
1448 (calendar-extract-year (cal-tex-next-month date
))
1449 "nextmonth" "1.1in" "1in"))
1450 (insert "\\hbox to \\textwidth{")
1452 (insert "\\lastmonth")
1454 (insert "\\thismonth")
1456 (insert "\\nextmonth")
1459 (cal-tex-banner "end of cal-tex-daily-page")))
1465 (defun cal-tex-mini-calendar (month year name width height
&optional ptsize colsep
)
1466 "Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT.
1467 Optional string PTSIZE gives the point size (default \"scriptsize\").
1468 Optional string COLSEP gives the column separation (default \"1mm\")."
1469 (or colsep
(setq colsep
"1mm"))
1470 (or ptsize
(setq ptsize
"scriptsize"))
1471 (let ((blank-days ; at start of month
1473 (- (calendar-day-of-week (list month
1 year
))
1474 calendar-week-start-day
)
1476 (last (calendar-last-day-of-month month year
))
1477 (str (concat "\\def\\" name
"{\\hbox to" width
"{%\n"
1478 "\\vbox to" height
"{%\n"
1479 "\\vfil \\hbox to" width
"{%\n"
1482 "{@{\\hspace{0mm}}r@{\\hspace{" colsep
1483 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{" colsep
1484 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{" colsep
1485 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{0mm}}}%\n"
1486 "\\multicolumn{7}{c}{"
1487 (cal-tex-month-name month
)
1489 (number-to-string year
)
1494 (cal-tex-LaTeXify-string
1495 (substring (aref calendar-day-name-array
1496 (mod (+ calendar-week-start-day i
) 7))
1502 (dotimes (idummy blank-days
)
1503 (setq str
(concat str
" & ")))
1505 (setq str
(concat str
(number-to-string (1+ i
)))
1506 str
(concat str
(if (zerop (mod (+ i
1 blank-days
) 7))
1511 (setq str
(concat str
"\n\\end{tabular}\\hfil}\\vfil}}}%\n"))
1515 ;;; Various calendar functions
1518 (defun cal-tex-incr-date (date &optional n
)
1519 "The date of the day following DATE.
1520 If optional N is given, the date of N days after DATE."
1521 (calendar-gregorian-from-absolute
1522 (+ (or n
1) (calendar-absolute-from-gregorian date
))))
1524 (defun cal-tex-latexify-list (date-list date
&optional separator final-separator
)
1525 "Return string with concatenated, LaTeX-ified entries in DATE-LIST for DATE.
1526 Use double backslash as a separator unless optional SEPARATOR is given.
1527 If resulting string is not empty, put separator at end if optional
1528 FINAL-SEPARATOR is non-nil."
1529 (or separator
(setq separator
"\\\\"))
1532 (mapconcat (lambda (x) (cal-tex-LaTeXify-string x
))
1533 (dolist (d date-list
(reverse result
))
1535 (calendar-date-equal date
(car d
))
1536 (setq result
(cons (cadr d
) result
))))
1538 (if (and final-separator
1539 (not (string-equal result
"")))
1540 (concat result separator
)
1543 (defun cal-tex-previous-month (date)
1544 "Return the date of the first day in the month previous to DATE."
1545 (let ((month (calendar-extract-month date
))
1546 (year (calendar-extract-year date
)))
1547 (calendar-increment-month month year -
1)
1548 (list month
1 year
)))
1550 (defun cal-tex-next-month (date)
1551 "Return the date of the first day in the month following DATE."
1552 (let ((month (calendar-extract-month date
))
1553 (year (calendar-extract-year date
)))
1554 (calendar-increment-month month year
1)
1555 (list month
1 year
)))
1561 (defun cal-tex-end-document ()
1562 "Finish the LaTeX document.
1563 Insert the trailer to LaTeX document, pop to LaTeX buffer, add
1564 informative header, and run HOOK."
1565 (cal-tex-e-document)
1567 (pop-to-buffer cal-tex-buffer
)
1568 (goto-char (point-min))
1569 ;; FIXME auctex equivalents?
1571 (format "\tThis buffer was produced by cal-tex.el.
1572 \tTo print a calendar, type
1573 \t\tM-x tex-buffer RET
1574 \t\tM-x tex-print RET")))
1576 (defun cal-tex-insert-preamble (weeks landscape size
&optional append
)
1577 "Initialize the output LaTeX calendar buffer, `cal-tex-buffer'.
1578 Select the output buffer, and insert the preamble for a calendar
1579 of WEEKS weeks. Insert code for landscape mode if LANDSCAPE is
1580 non-nil. Use point-size SIZE. Optional argument APPEND, if
1581 non-nil, means add to end of buffer without erasing current contents."
1582 (let ((width "18cm")
1588 (cal-tex-preamble size
)
1591 (cal-tex-cmd "\\oddsidemargin -1.75cm")
1592 (cal-tex-cmd "\\def\\holidaymult{.06}"))
1593 (cal-tex-cmd "\\special{landscape}")
1594 (cal-tex-cmd "\\textwidth 9.5in")
1595 (cal-tex-cmd "\\textheight 7in")
1597 (cal-tex-cmd "\\def\\holidaymult{.08}"))
1598 (cal-tex-cmd cal-tex-caldate
)
1599 (cal-tex-cmd cal-tex-myday
)
1600 (cal-tex-b-document)
1601 (cal-tex-cmd "\\pagestyle{empty}"))
1602 (cal-tex-cmd "\\setlength{\\cellwidth}" width
)
1603 (insert (format "\\setlength{\\cellwidth}{%f\\cellwidth}\n"
1604 (/ 1.1 (length cal-tex-which-days
))))
1605 (cal-tex-cmd "\\setlength{\\cellheight}" height
)
1606 (insert (format "\\setlength{\\cellheight}{%f\\cellheight}\n"
1608 (cal-tex-cmd "\\ \\par")
1609 (cal-tex-vspace "-3cm")))
1611 (defconst cal-tex-LaTeX-subst-list
1613 ("\"".
"''") ; quote changes meaning when list is reversed
1614 ;; Don't think this is necessary, and in any case, does not work:
1615 ;; "LaTeX Error: \verb illegal in command argument".
1616 ;;; ("@" . "\\verb|@|")
1626 ("\n" .
"\\ \\\\")) ; \\ needed for e.g \begin{center}\n AA\end{center}
1627 "Alist of symbols and their LaTeX replacements.")
1629 (defun cal-tex-LaTeXify-string (string)
1630 "Protect special characters in STRING from LaTeX."
1635 (list cal-tex-LaTeX-subst-list
)
1637 (while (not (string-equal tail
""))
1638 (setq ch
(substring-no-properties tail
0 1)
1639 pair
(assoc ch list
))
1640 (if (and pair
(string-equal ch
"\""))
1641 (setq list
(reverse list
))) ; quote changes meaning each time
1642 (setq tail
(substring-no-properties tail
1)
1643 head
(concat head
(if pair
(cdr pair
) ch
))))
1646 (defun cal-tex-month-name (month)
1647 "The name of MONTH, LaTeX-ified."
1648 (cal-tex-LaTeXify-string (calendar-month-name month
)))
1650 (defun cal-tex-hfill ()
1654 (defun cal-tex-newpage ()
1656 (insert "\\newpage%\n"))
1658 (defun cal-tex-noindent ()
1660 (insert "\\noindent"))
1662 (defun cal-tex-vspace (space)
1663 "Insert vspace command to move SPACE vertically."
1664 (insert "\\vspace*{" space
"}")
1667 (defun cal-tex-hspace (space)
1668 "Insert hspace command to move SPACE horizontally."
1669 (insert "\\hspace*{" space
"}")
1672 (defun cal-tex-comment (&optional comment
)
1673 "Insert `% ', followed by optional string COMMENT, followed by newline.
1674 COMMENT may contain newlines, which are prefixed by `% ' in the output."
1675 (insert (format "%% %s\n"
1677 (replace-regexp-in-string "\n" "\n% " comment
)
1680 (defun cal-tex-banner (comment)
1681 "Insert string COMMENT, separated by blank lines."
1682 (cal-tex-comment (format "\n\n\n\t\t\t%s\n" comment
)))
1684 (defun cal-tex-nl (&optional skip comment
)
1685 "End a line with \\. If SKIP, then add that much spacing.
1686 Add trailing COMMENT if present."
1687 (insert (format "\\\\%s"
1689 (format "[%s]" skip
)
1691 (cal-tex-comment comment
))
1693 (defun cal-tex-arg (&optional text
)
1694 "Insert a brace {} pair containing the optional string TEXT."
1695 (insert (format "{%s}" (or text
""))))
1697 (defun cal-tex-cmd (cmd &optional arg
)
1698 "Insert LaTeX CMD, with optional argument ARG, and end with %."
1707 (defun cal-tex-b-document ()
1708 "Insert beginning of document."
1709 (cal-tex-cmd "\\begin{document}"))
1711 (defun cal-tex-e-document ()
1712 "Insert end of document."
1713 (cal-tex-cmd "\\end{document}"))
1715 (defun cal-tex-b-center ()
1716 "Insert beginning of centered block."
1717 (cal-tex-cmd "\\begin{center}"))
1719 (defun cal-tex-e-center ()
1720 "Insert end of centered block."
1722 (cal-tex-cmd "\\end{center}"))
1730 (defun cal-tex-b-parbox (position width
)
1731 "Insert parbox with parameters POSITION and WIDTH."
1732 (insert "\\parbox[" position
"]{" width
"}{")
1735 (defun cal-tex-e-parbox (&optional height
)
1736 "Insert end of parbox. Optionally, force it to be a given HEIGHT."
1739 (cal-tex-rule "0mm" "0mm" height
))
1741 (cal-tex-comment "end parbox"))
1743 (defun cal-tex-b-framebox (width position
)
1744 "Insert framebox with parameters WIDTH and POSITION (clr)."
1745 (insert "\\framebox[" width
"][" position
"]{" )
1748 (defun cal-tex-e-framebox ()
1749 "Insert end of framebox."
1752 (cal-tex-comment "end framebox"))
1755 (defun cal-tex-b-makebox ( width position
)
1756 "Insert makebox with parameters WIDTH and POSITION (clr)."
1757 (insert "\\makebox[" width
"][" position
"]{" )
1760 (defun cal-tex-e-makebox ()
1761 "Insert end of makebox."
1764 (cal-tex-comment "end makebox"))
1767 (defun cal-tex-rule (lower width height
)
1768 "Insert a rule with parameters LOWER WIDTH HEIGHT."
1769 (insert "\\rule[" lower
"]{" width
"}{" height
"}"))
1775 (defun cal-tex-em (string)
1776 "Insert STRING in italic font."
1777 (insert "\\textit{" string
"}"))
1779 (defun cal-tex-bf (string)
1780 "Insert STRING in bf font."
1781 (insert "\\textbf{ " string
"}"))
1783 (defun cal-tex-scriptsize (string)
1784 "Insert STRING in scriptsize font."
1785 (insert "{\\scriptsize " string
"}"))
1787 (defun cal-tex-huge (string)
1788 "Insert STRING in huge font."
1789 (insert "{\\huge " string
"}"))
1791 (defun cal-tex-Huge (string)
1792 "Insert STRING in Huge font."
1793 (insert "{\\Huge " string
"}"))
1795 (defun cal-tex-Huge-bf (string)
1796 "Insert STRING in Huge bf font."
1797 (insert "\\textbf{\\Huge " string
"}"))
1799 (defun cal-tex-large (string)
1800 "Insert STRING in large font."
1801 (insert "{\\large " string
"}"))
1803 (defun cal-tex-large-bf (string)
1804 "Insert STRING in large bf font."
1805 (insert "\\textbf{\\large " string
"}"))
1810 ;; arch-tag: ca8168a4-5a00-4508-a565-17e3bccce6d0
1811 ;;; cal-tex.el ends here