1 ;;; cal-tex.el --- calendar functions for printing calendars with LaTeX
3 ;; Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 ;; Free Software Foundation, Inc.
6 ;; Author: Steve Fisk <fisk@bowdoin.edu>
7 ;; Edward M. Reingold <reingold@cs.uiuc.edu>
8 ;; Maintainer: Glenn Morris <rgm@gnu.org>
10 ;; Human-Keywords: Calendar, LaTeX
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 3, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
31 ;; This collection of functions implements the creation of LaTeX calendars
32 ;; based on the user's holiday choices and diary file.
34 ;; The user commands are:
35 ;; cal-tex-cursor-year
36 ;; cal-tex-cursor-year-landscape
37 ;; cal-tex-cursor-filofax-year
38 ;; cal-tex-cursor-month-landscape
39 ;; cal-tex-cursor-month
40 ;; cal-tex-cursor-week
41 ;; cal-tex-cursor-week2
42 ;; cal-tex-cursor-week-iso
43 ;; cal-tex-cursor-week-monday
44 ;; cal-tex-cursor-filofax-2week
45 ;; cal-tex-cursor-filofax-week
46 ;; cal-tex-cursor-filofax-daily
51 ;; (*) Add holidays and diary entries to daily calendar.
53 ;; (*) Add diary entries to weekly calendar functions.
55 ;; (*) Make calendar styles for A4 paper.
57 ;; (*) Make monthly styles Filofax paper.
64 ;;; Customizable variables
67 (defgroup calendar-tex nil
68 "Options for printing calendar with LaTeX."
72 (defcustom cal-tex-which-days
'(0 1 2 3 4 5 6)
73 "The days of the week that are displayed on the portrait monthly calendar.
74 Sunday is 0, Monday is 1, and so on. The default is to print from Sunday to
75 Saturday. For example, use '(1 3 5) to only print Monday, Wednesday, Friday."
76 :type
'(repeat integer
)
79 (defcustom cal-tex-holidays t
80 "Non-nil means holidays are printed in the LaTeX calendars that support it.
81 Setting this to nil may speed up calendar generation."
85 (defcustom cal-tex-diary nil
86 "Non-nil means diary entries are printed in LaTeX calendars that support it.
87 At present, this only affects the monthly, filofax, and iso-week
88 calendars (i.e. not the yearly, plain weekly, or daily calendars).
89 Setting this to nil may speed up calendar generation."
93 (defcustom cal-tex-rules nil
94 "Non-nil means pages will be ruled in some LaTeX calendar styles.
95 At present, this only affects the daily filofax calendar."
99 (defcustom cal-tex-daily-string
100 '(let* ((year (calendar-extract-year date
))
101 (day (calendar-day-number date
))
102 (days-remaining (- (calendar-day-number (list 12 31 year
)) day
)))
103 (format "%d/%d" day days-remaining
))
104 "Lisp expression giving the date format to use in the LaTeX calendars.
105 This should be an expression involving the variable `date'. When
106 this expression is called, `date' is a list of the form '(MONTH DAY YEAR)'.
108 The string resulting from evaluating this expression is placed at
109 the bottom center of each date in monthly calendars, next to the
110 date in the weekly calendars, and in the top center of daily calendars.
112 The default is ordinal day number of the year and the number of
113 days remaining. As an example, setting this to
115 '(calendar-hebrew-date-string date)
117 will put the Hebrew date at the bottom of each day."
119 :group
'calendar-tex
)
121 (defcustom cal-tex-buffer
"calendar.tex"
122 "The name for the output LaTeX calendar buffer."
124 :group
'calendar-tex
)
126 (defcustom cal-tex-24 nil
127 "Non-nil means use a 24 hour clock in the daily calendar."
129 :group
'calendar-tex
)
131 (defcustom cal-tex-daily-start
8
132 "The first hour of the daily LaTeX calendar page.
133 At present, this only affects `cal-tex-cursor-day'."
135 :group
'calendar-tex
)
137 (defcustom cal-tex-daily-end
20
138 "The last hour of the daily LaTeX calendar page.
139 At present, this only affects `cal-tex-cursor-day'"
141 :group
'calendar-tex
)
143 (defcustom cal-tex-preamble-extra nil
144 "A string giving extra LaTeX commands to insert in the calendar preamble.
145 For example, to include extra packages:
146 \"\\\\usepackage{foo}\\n\\\\usepackage{bar}\\n\"."
147 :type
'(choice (const nil
) string
)
151 (defcustom cal-tex-hook nil
152 "List of functions called after any LaTeX calendar buffer is generated.
153 You can use this to do post-processing on the buffer. For example, to change
154 characters with diacritical marks to their LaTeX equivalents, use
155 (add-hook 'cal-tex-hook
156 (lambda () (iso-iso2tex (point-min) (point-max))))"
158 :group
'calendar-tex
)
160 (defcustom cal-tex-year-hook nil
161 "List of functions called after a LaTeX year calendar buffer is generated."
163 :group
'calendar-tex
)
165 (defcustom cal-tex-month-hook nil
166 "List of functions called after a LaTeX month calendar buffer is generated."
168 :group
'calendar-tex
)
170 (defcustom cal-tex-week-hook nil
171 "List of functions called after a LaTeX week calendar buffer is generated."
173 :group
'calendar-tex
)
175 (defcustom cal-tex-daily-hook nil
176 "List of functions called after a LaTeX daily calendar buffer is generated."
178 :group
'calendar-tex
)
181 ;;; Definitions for LaTeX code
184 (defconst cal-tex-day-prefix
"\\caldate{%s}{%s}"
185 "The initial LaTeX code for a day.
186 The holidays, diary entries, bottom string, and the text follow.")
188 (defconst cal-tex-day-name-format
"\\myday{%s}%%"
189 "The format for LaTeX code for a day name.
190 The names are taken from `calendar-day-name-array'.")
192 (defconst cal-tex-cal-one-month
193 "\\def\\calmonth#1#2%
195 \\Huge\\bf\\uppercase{#1} #2 \\\\[1cm]%
200 "LaTeX code for the month header, for a single month calendar.")
202 (defconst cal-tex-cal-multi-month
203 "\\def\\calmonth#1#2#3#4%
205 \\Huge\\bf #1 #2---#3 #4\\\\[1cm]%
210 "LaTeX code for the month header, for a multi-month calendar.")
212 (defconst cal-tex-myday
213 "\\renewcommand{\\myday}[1]%
214 {\\makebox[\\cellwidth]{\\hfill\\large\\bf#1\\hfill}}
217 "LaTeX code for a day heading.")
219 (defconst cal-tex-caldate
221 \\long\\def\\caldate#1#2#3#4#5#6{%
222 \\fbox{\\hbox to\\cellwidth{%
223 \\vbox to\\cellheight{%
224 \\hbox to\\cellwidth{%
225 {\\hspace*{1mm}\\Large \\bf \\strut #2}\\hspace{.05\\cellwidth}%
226 \\raisebox{\\holidaymult\\cellheight}%
227 {\\parbox[t]{.75\\cellwidth}{\\tiny \\raggedright #4}}}
228 \\hbox to\\cellwidth{%
229 \\hspace*{1mm}\\parbox{.95\\cellwidth}{\\tiny \\raggedright #3}}
231 \\hbox to\\cellwidth{#6}%
233 \\hbox to\\cellwidth{\\hfill \\tiny #5 \\hfill}%
237 "LaTeX code to insert one box with date info in calendar.
238 This definition is the heart of the calendar!")
240 (autoload 'calendar-holiday-list
"holidays")
242 (defun cal-tex-list-holidays (d1 d2
)
243 "Generate a list of all holidays from absolute date D1 to D2."
244 (let* ((start (calendar-gregorian-from-absolute d1
))
245 (displayed-month (calendar-extract-month start
))
246 (displayed-year (calendar-extract-year start
))
247 (end (calendar-gregorian-from-absolute d2
))
248 (end-month (calendar-extract-month end
))
249 (end-year (calendar-extract-year end
))
251 (1+ (/ (calendar-interval displayed-month displayed-year
255 (calendar-increment-month displayed-month displayed-year
1)
256 (dotimes (idummy number-of-intervals
)
257 (setq holidays
(append holidays
(calendar-holiday-list)))
258 (calendar-increment-month displayed-month displayed-year
3))
259 (dolist (hol holidays
)
261 (setq a
(calendar-absolute-from-gregorian (car hol
)))
262 (and (<= d1 a
) (<= a d2
))
263 (setq in-range
(append (list hol
) in-range
))))
266 (autoload 'diary-list-entries
"diary-lib")
268 (defun cal-tex-list-diary-entries (d1 d2
)
269 "Generate a list of all diary-entries from absolute date D1 to D2."
270 (let ((diary-list-include-blanks nil
)
271 (diary-display-hook 'ignore
))
273 (calendar-gregorian-from-absolute d1
)
276 (defun cal-tex-preamble (&optional args
)
277 "Insert the LaTeX calendar preamble into `cal-tex-buffer'.
278 Preamble includes initial definitions for various LaTeX commands.
279 Optional string ARGS are included as options for the article document class."
280 ;; FIXME use generate-new-buffer, and adjust cal-tex-end-document.
281 (set-buffer (get-buffer-create cal-tex-buffer
))
282 (insert (format "\\documentclass%s{article}\n"
286 (if (stringp cal-tex-preamble-extra
)
287 (insert cal-tex-preamble-extra
"\n"))
288 (insert "\\hbadness 20000
294 \\evensidemargin -2cm
299 \\newlength{\\cellwidth}
300 \\newlength{\\cellheight}
301 \\newlength{\\boxwidth}
302 \\newlength{\\boxheight}
303 \\newlength{\\cellsize}
304 \\newcommand{\\myday}[1]{}
305 \\newcommand{\\caldate}[6]{}
306 \\newcommand{\\nocaldate}[6]{}
307 \\newcommand{\\calsmall}[6]{}
316 (defun cal-tex-cursor-year (&optional arg
)
317 "Make a buffer with LaTeX commands for the year cursor is on.
318 Optional prefix argument ARG specifies number of years."
320 (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t
))
324 (defun cal-tex-cursor-year-landscape (&optional arg
)
325 "Make a buffer with LaTeX commands for the year cursor is on.
326 Optional prefix argument ARG specifies number of years."
328 (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t
))
331 (defun cal-tex-year (year n
&optional landscape
)
332 "Make a one page yearly calendar of YEAR; do this for N years.
333 There are four rows of three months each, unless optional
334 LANDSCAPE is non-nil, in which case the calendar is printed in
335 landscape mode with three rows of four months each."
336 (cal-tex-insert-preamble 1 landscape
"12pt")
338 (cal-tex-vspace "-.6cm")
339 (cal-tex-vspace "-3.1cm"))
341 (insert "\\vfill%\n")
343 (cal-tex-Huge (number-to-string year
))
345 (cal-tex-vspace "1cm")
347 (cal-tex-b-parbox "l" (if landscape
"5.9in" "4.3in"))
352 (insert (cal-tex-mini-calendar (1+ i
) year
"month" "1.1in" "1in"))
354 (cal-tex-hspace "0.5in")
355 (if (zerop (mod (1+ i
) (if landscape
4 3)))
356 (cal-tex-nl "0.5in")))
359 (insert "\\vfill%\n")
360 (setq year
(1+ year
))
362 (cal-tex-end-document)
364 (run-hooks 'cal-tex-year-hook
))
365 (run-hooks 'cal-tex-hook
))
368 (defun cal-tex-cursor-filofax-year (&optional arg
)
369 "Make a Filofax one page yearly calendar of year indicated by cursor.
370 Optional prefix argument ARG specifies number of years."
373 (year (calendar-extract-year (calendar-cursor-to-date t
))))
374 (cal-tex-preamble "twoside")
375 (cal-tex-cmd "\\textwidth 3.25in")
376 (cal-tex-cmd "\\textheight 6.5in")
377 (cal-tex-cmd "\\oddsidemargin 1.675in")
378 (cal-tex-cmd "\\evensidemargin 1.675in")
379 (cal-tex-cmd "\\topmargin 0pt")
380 (cal-tex-cmd "\\headheight -0.875in")
381 (cal-tex-cmd "\\fboxsep 0.5mm")
382 (cal-tex-cmd "\\pagestyle{empty}")
384 (cal-tex-cmd "\\vspace*{0.25in}")
386 (insert (format "\\hfil \\textbf{\\Large %s} \\hfil\\\\\n" year
))
388 (cal-tex-b-parbox "l" "\\textwidth")
392 (let ((month-names; don't use default in case user changed it
393 ;; These are only used to define the command names, not
394 ;; the names of the months they insert.
395 ["January" "February" "March" "April" "May" "June"
396 "July" "August" "September" "October" "November" "December"]))
398 (insert (cal-tex-mini-calendar (1+ i
) year
(aref month-names i
)
399 "1in" ".9in" "tiny" "0.6mm"))))
401 "\\noindent\\fbox{\\January}\\fbox{\\February}\\fbox{\\March}\\\\
402 \\noindent\\fbox{\\April}\\fbox{\\May}\\fbox{\\June}\\\\
403 \\noindent\\fbox{\\July}\\fbox{\\August}\\fbox{\\September}\\\\
404 \\noindent\\fbox{\\October}\\fbox{\\November}\\fbox{\\December}
408 (setq year
(1+ year
))
410 (cal-tex-end-document)
412 (cal-tex-cmd "\\vspace*{0.25in}"))
413 (run-hooks 'cal-tex-year-hook
))
414 (run-hooks 'cal-tex-hook
)))
417 ;;; Monthly calendars
421 (defun cal-tex-cursor-month-landscape (&optional arg
)
422 "Make a LaTeX calendar buffer for the month the cursor is on.
423 Optional prefix argument ARG specifies number of months to be
424 produced (default 1). The output is in landscape format, one
425 month to a page. It shows holiday and diary entries if
426 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil."
428 (let* ((n (or arg
1))
429 (date (calendar-cursor-to-date t
))
430 (month (calendar-extract-month date
))
431 (year (calendar-extract-year date
))
434 (cal-tex-which-days '(0 1 2 3 4 5 6))
435 (d1 (calendar-absolute-from-gregorian (list month
1 year
)))
436 (d2 (calendar-absolute-from-gregorian
438 (calendar-last-day-of-month end-month end-year
)
441 (calendar-increment-month end-month end-year
(1- n
))
442 (if cal-tex-diary
(cal-tex-list-diary-entries d1 d2
))))
443 (holidays (if cal-tex-holidays
(cal-tex-list-holidays d1 d2
)))
444 other-month other-year small-months-at-start
)
445 (cal-tex-insert-preamble (cal-tex-number-weeks month year
1) t
"12pt")
446 (cal-tex-cmd cal-tex-cal-one-month
)
448 (setq other-month month
450 (calendar-increment-month other-month other-year -
1)
451 (insert (cal-tex-mini-calendar other-month other-year
"lastmonth"
452 "\\cellwidth" "\\cellheight"))
453 (calendar-increment-month other-month other-year
2)
454 (insert (cal-tex-mini-calendar other-month other-year
"nextmonth"
455 "\\cellwidth" "\\cellheight"))
456 (cal-tex-insert-month-header 1 month year month year
)
457 (cal-tex-insert-day-names)
459 (if (setq small-months-at-start
460 (< 1 (mod (- (calendar-day-of-week (list month
1 year
))
461 calendar-week-start-day
)
463 (insert "\\lastmonth\\nextmonth\\hspace*{-2\\cellwidth}"))
464 (cal-tex-insert-blank-days month year cal-tex-day-prefix
)
465 (cal-tex-insert-days month year diary-list holidays
467 (cal-tex-insert-blank-days-at-end month year cal-tex-day-prefix
)
468 (if (and (not small-months-at-start
)
469 (< 1 (mod (- (1- calendar-week-start-day
)
470 (calendar-day-of-week
472 (calendar-last-day-of-month month year
)
475 (insert "\\vspace*{-\\cellwidth}\\hspace*{-2\\cellwidth}"
476 "\\lastmonth\\nextmonth%
479 (run-hooks 'cal-tex-month-hook
)
481 (calendar-increment-month month year
1)
482 (cal-tex-vspace "-2cm")
483 (cal-tex-insert-preamble
484 (cal-tex-number-weeks month year
1) t
"12pt" t
))))
485 (cal-tex-end-document)
486 (run-hooks 'cal-tex-hook
))
489 (defun cal-tex-cursor-month (arg)
490 "Make a LaTeX calendar buffer for the month the cursor is on.
491 Optional prefix argument ARG specifies number of months to be
492 produced (default 1). The calendar is condensed onto one page.
493 It shows holiday and diary entries if `cal-tex-holidays' and
494 `cal-tex-diary', respectively, are non-nil."
496 (let* ((n (or arg
1))
497 (date (calendar-cursor-to-date t
))
498 (month (calendar-extract-month date
))
499 (year (calendar-extract-year date
))
502 (d1 (calendar-absolute-from-gregorian (list month
1 year
)))
503 (d2 (calendar-absolute-from-gregorian
505 (calendar-last-day-of-month end-month end-year
)
508 (calendar-increment-month end-month end-year
(1- n
))
509 (if cal-tex-diary
(cal-tex-list-diary-entries d1 d2
))))
510 (holidays (if cal-tex-holidays
(cal-tex-list-holidays d1 d2
)))
511 other-month other-year
)
512 (cal-tex-insert-preamble (cal-tex-number-weeks month year n
) nil
"12pt")
514 (cal-tex-cmd cal-tex-cal-multi-month
)
515 (cal-tex-cmd cal-tex-cal-one-month
))
516 (cal-tex-insert-month-header n month year end-month end-year
)
517 (cal-tex-insert-day-names)
519 (cal-tex-insert-blank-days month year cal-tex-day-prefix
)
521 (setq other-month month
523 (cal-tex-insert-days month year diary-list holidays cal-tex-day-prefix
)
524 (when (= 6 (mod (calendar-absolute-from-gregorian
526 (calendar-last-day-of-month month year
)
528 7)) ; last day of month was Saturday
531 (calendar-increment-month month year
1))
532 (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix
))
533 (cal-tex-end-document)
534 (run-hooks 'cal-tex-hook
))
536 (defun cal-tex-insert-days (month year diary-list holidays day-format
)
537 "Insert LaTeX commands for a range of days in monthly calendars.
538 LaTeX commands are inserted for the days of the MONTH in YEAR.
539 Diary entries on DIARY-LIST are included. Holidays on HOLIDAYS
540 are included. Each day is formatted using format DAY-FORMAT."
541 (let ((blank-days ; at start of month
543 (- (calendar-day-of-week (list month
1 year
))
544 calendar-week-start-day
)
546 (last (calendar-last-day-of-month month year
))
549 (setq j
(1+ i
) ; 1-last, incl
550 date
(list month j year
))
551 (when (memq (calendar-day-of-week date
) cal-tex-which-days
)
552 (insert (format day-format
(cal-tex-month-name month
) j
))
553 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
554 (cal-tex-arg (cal-tex-latexify-list holidays date
))
555 (cal-tex-arg (eval cal-tex-daily-string
))
558 (when (and (zerop (mod (+ j blank-days
) 7))
563 (defun cal-tex-insert-day-names ()
564 "Insert the names of the days at top of a monthly calendar."
566 (if (memq i cal-tex-which-days
)
567 (insert (format cal-tex-day-name-format
568 (cal-tex-LaTeXify-string
569 (aref calendar-day-name-array
570 (mod (+ calendar-week-start-day i
) 7))))))
573 (defun cal-tex-insert-month-header (n month year end-month end-year
)
574 "Create a title for a calendar.
575 A title is inserted for a calendar with N months starting with
576 MONTH YEAR and ending with END-MONTH END-YEAR."
577 (let ((month-name (cal-tex-month-name month
))
578 (end-month-name (cal-tex-month-name end-month
)))
580 (insert (format "\\calmonth{%s}{%s}\n\\vspace*{-0.5cm}"
582 (insert (format "\\calmonth{%s}{%s}{%s}{%s}\n\\vspace*{-0.5cm}"
583 month-name year end-month-name end-year
))))
586 (defun cal-tex-insert-blank-days (month year day-format
)
587 "Insert code for initial days not in calendar.
588 Insert LaTeX code for the blank days at the beginning of the MONTH in
589 YEAR. The entry is formatted using DAY-FORMAT. If the entire week is
590 blank, no days are inserted."
591 (if (cal-tex-first-blank-p month year
)
592 (let ((blank-days ; at start of month
594 (- (calendar-day-of-week (list month
1 year
))
595 calendar-week-start-day
)
597 (dotimes (i blank-days
)
598 (if (memq i cal-tex-which-days
)
599 (insert (format day-format
" " " ") "{}{}{}{}%\n"))))))
601 (defun cal-tex-insert-blank-days-at-end (month year day-format
)
602 "Insert code for final days not in calendar.
603 Insert LaTeX code for the blank days at the end of the MONTH in YEAR.
604 The entry is formatted using DAY-FORMAT."
605 (if (cal-tex-last-blank-p month year
)
606 (let* ((last-day (calendar-last-day-of-month month year
))
607 (blank-days ; at end of month
609 (- (calendar-day-of-week (list month last-day year
))
610 calendar-week-start-day
)
613 (while (<= (setq i
(1+ i
)) 6)
614 (if (memq i cal-tex-which-days
)
615 (insert (format day-format
"" "") "{}{}{}{}%\n"))))))
617 (defun cal-tex-first-blank-p (month year
)
618 "Determine if any days of the first week will be printed.
619 Return t if there will there be any days of the first week printed
620 in the calendar starting in MONTH YEAR."
621 (let (any-days the-saturday
) ; the day of week of 1st Saturday
623 (if (= 6 (calendar-day-of-week (list month
(1+ i
) year
)))
624 (setq the-saturday
(1+ i
))))
625 (dotimes (i the-saturday
)
626 (if (memq (calendar-day-of-week (list month
(1+ i
) year
))
631 (defun cal-tex-last-blank-p (month year
)
632 "Determine if any days of the last week will be printed.
633 Return t if there will there be any days of the last week printed
634 in the calendar starting in MONTH YEAR."
635 (let* ((last-day (calendar-last-day-of-month month year
))
637 any-days the-sunday
) ; the day of week of last Sunday
638 (while (<= (setq i
(1+ i
)) last-day
)
639 (if (zerop (calendar-day-of-week (list month i year
)))
640 (setq the-sunday i
)))
641 (setq i
(1- the-sunday
))
642 (while (<= (setq i
(1+ i
)) last-day
)
643 (if (memq (calendar-day-of-week (list month i year
)) cal-tex-which-days
)
647 (defun cal-tex-number-weeks (month year n
)
648 "Determine the number of weeks in a range of dates.
649 Compute the number of weeks in the calendar starting with MONTH and YEAR,
650 and lasting N months, including only the days in WHICH-DAYS. As it stands,
651 this is only an upper bound."
652 (let ((d (list month
1 year
)))
653 (calendar-increment-month month year
(1- n
))
654 (/ (- (calendar-dayname-on-or-before
655 calendar-week-start-day
656 (+ 7 (calendar-absolute-from-gregorian
657 (list month
(calendar-last-day-of-month month year
) year
))))
658 (calendar-dayname-on-or-before
659 calendar-week-start-day
660 (calendar-absolute-from-gregorian d
)))
667 (defconst cal-tex-LaTeX-hourbox
668 "\\newcommand{\\hourbox}[2]%
669 {\\makebox[2em]{\\rule{0cm}{#2ex}#1}\\rule{3in}{.15mm}}\n"
670 "One hour and a line on the right.")
672 ;; TODO cal-tex-diary-support.
673 ;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
675 (defun cal-tex-cursor-week (&optional arg
)
676 "Make a LaTeX calendar buffer for a two-page one-week calendar.
677 It applies to the week that point is in. The optional prefix
678 argument ARG specifies the number of weeks (default 1). The calendar
679 shows holidays if `cal-tex-holidays' is non-nil (note that diary
680 entries are not shown). The calendar shows the hours 8-12am, 1-5pm."
682 (let* ((n (or arg
1))
683 (date (calendar-gregorian-from-absolute
684 (calendar-dayname-on-or-before
685 calendar-week-start-day
686 (calendar-absolute-from-gregorian
687 (calendar-cursor-to-date t
)))))
688 (month (calendar-extract-month date
))
689 (year (calendar-extract-year date
))
690 (d1 (calendar-absolute-from-gregorian date
))
692 (holidays (if cal-tex-holidays
693 (cal-tex-list-holidays d1 d2
))))
694 (cal-tex-preamble "11pt")
695 (cal-tex-cmd "\\textwidth 6.5in")
696 (cal-tex-cmd "\\textheight 10.5in")
697 (cal-tex-cmd "\\oddsidemargin 0in")
698 (cal-tex-cmd "\\evensidemargin 0in")
699 (insert cal-tex-LaTeX-hourbox
)
701 (cal-tex-cmd "\\pagestyle{empty}")
703 (cal-tex-vspace "-1.5in")
705 (cal-tex-Huge-bf (format "\\uppercase{%s}"
706 (cal-tex-month-name month
)))
707 (cal-tex-hspace "2em")
708 (cal-tex-Huge-bf (number-to-string year
))
711 (cal-tex-hspace "-.2in")
712 (cal-tex-b-parbox "l" "7in")
714 (cal-tex-week-hours date holidays
"3.1")
715 (setq date
(cal-tex-incr-date date
)))
717 (setq month
(calendar-extract-month date
)
718 year
(calendar-extract-year date
))
720 (run-hooks 'cal-tex-week-hook
)
722 (cal-tex-end-document)
723 (run-hooks 'cal-tex-hook
)))
725 ;; TODO cal-tex-diary support.
726 ;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
728 (defun cal-tex-cursor-week2 (&optional arg
)
729 "Make a LaTeX calendar buffer for a two-page one-week calendar.
730 It applies to the week that point is in. Optional prefix
731 argument ARG specifies number of weeks (default 1). The calendar
732 shows holidays if `cal-tex-holidays' is non-nil (note that diary
733 entries are not shown). The calendar shows the hours 8-12am, 1-5pm"
735 (let* ((n (or arg
1))
736 (date (calendar-gregorian-from-absolute
737 (calendar-dayname-on-or-before
738 calendar-week-start-day
739 (calendar-absolute-from-gregorian
740 (calendar-cursor-to-date t
)))))
741 (month (calendar-extract-month date
))
742 (year (calendar-extract-year date
))
744 (d1 (calendar-absolute-from-gregorian date
))
746 (holidays (if cal-tex-holidays
747 (cal-tex-list-holidays d1 d2
))))
748 (cal-tex-preamble "12pt")
749 (cal-tex-cmd "\\textwidth 6.5in")
750 (cal-tex-cmd "\\textheight 10.5in")
751 (cal-tex-cmd "\\oddsidemargin 0in")
752 (cal-tex-cmd "\\evensidemargin 0in")
753 (insert cal-tex-LaTeX-hourbox
)
755 (cal-tex-cmd "\\pagestyle{empty}")
757 (cal-tex-vspace "-1.5in")
759 (cal-tex-Huge-bf (format "\\uppercase{%s}"
760 (cal-tex-month-name month
)))
761 (cal-tex-hspace "2em")
762 (cal-tex-Huge-bf (number-to-string year
))
765 (cal-tex-hspace "-.2in")
766 (cal-tex-b-parbox "l" "\\textwidth")
768 (cal-tex-week-hours date holidays
"5")
769 (setq date
(cal-tex-incr-date date
)))
772 (insert (cal-tex-mini-calendar
773 (calendar-extract-month (cal-tex-previous-month date
))
774 (calendar-extract-year (cal-tex-previous-month date
))
775 "lastmonth" "1.1in" "1in"))
776 (insert (cal-tex-mini-calendar
777 (calendar-extract-month date
)
778 (calendar-extract-year date
)
779 "thismonth" "1.1in" "1in"))
780 (insert (cal-tex-mini-calendar
781 (calendar-extract-month (cal-tex-next-month date
))
782 (calendar-extract-year (cal-tex-next-month date
))
783 "nextmonth" "1.1in" "1in"))
784 (insert "\\hbox to \\textwidth{")
786 (insert "\\lastmonth")
788 (insert "\\thismonth")
790 (insert "\\nextmonth")
794 (cal-tex-b-parbox "l" "\\textwidth")
796 (cal-tex-week-hours date holidays
"5")
797 (setq date
(cal-tex-incr-date date
)))
799 (setq month
(calendar-extract-month date
)
800 year
(calendar-extract-year date
))
802 (run-hooks 'cal-tex-week-hook
)
804 (cal-tex-end-document)
805 (run-hooks 'cal-tex-hook
)))
807 (autoload 'calendar-iso-from-absolute
"cal-iso")
810 (defun cal-tex-cursor-week-iso (&optional arg
)
811 "Make a LaTeX calendar buffer for a one page ISO-style weekly calendar.
812 Optional prefix argument ARG specifies number of weeks (default 1).
813 The calendar shows holiday and diary entries if
814 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
815 It does not show hours of the day."
817 (let* ((n (or arg
1))
818 (date (calendar-gregorian-from-absolute
819 (calendar-dayname-on-or-before
821 (calendar-absolute-from-gregorian
822 (calendar-cursor-to-date t
)))))
823 (month (calendar-extract-month date
))
824 (year (calendar-extract-year date
))
825 (day (calendar-extract-day date
))
826 (d1 (calendar-absolute-from-gregorian date
))
828 (holidays (if cal-tex-holidays
829 (cal-tex-list-holidays d1 d2
)))
830 (diary-list (if cal-tex-diary
831 (cal-tex-list-diary-entries
833 (calendar-absolute-from-gregorian (list month
1 year
))
836 (cal-tex-preamble "11pt")
837 (cal-tex-cmd "\\textwidth 6.5in")
838 (cal-tex-cmd "\\textheight 10.5in")
839 (cal-tex-cmd "\\oddsidemargin 0in")
840 (cal-tex-cmd "\\evensidemargin 0in")
842 (cal-tex-cmd "\\pagestyle{empty}")
844 (cal-tex-vspace "-1.5in")
847 (let ((d (calendar-iso-from-absolute
848 (calendar-absolute-from-gregorian date
))))
849 (format "Week %d of %d"
850 (calendar-extract-month d
)
851 (calendar-extract-year d
))))
854 (cal-tex-b-parbox "l" "\\textwidth")
856 (cal-tex-b-parbox "t" "\\textwidth")
857 (cal-tex-b-parbox "t" "\\textwidth")
858 (cal-tex-rule "0pt" "\\textwidth" ".2mm")
860 (cal-tex-b-parbox "t" "\\textwidth")
861 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
863 (cal-tex-large-bf (cal-tex-month-name month
))
865 (cal-tex-large-bf (number-to-string day
))
866 (unless (string-equal "" (setq s
(cal-tex-latexify-list
867 holidays date
"; ")))
869 (cal-tex-large-bf s
))
871 (insert " " (eval cal-tex-daily-string
))
875 (cal-tex-b-parbox "t" "\\textwidth")
876 (unless (string-equal "" (setq s
(cal-tex-latexify-list
878 (insert "\\vbox to 0pt{")
883 (setq date
(cal-tex-incr-date date
)
884 month
(calendar-extract-month date
)
885 day
(calendar-extract-day date
))
887 (cal-tex-e-parbox "2cm")
889 (setq month
(calendar-extract-month date
)
890 year
(calendar-extract-year date
)))
893 (run-hooks 'cal-tex-week-hook
)
895 (cal-tex-end-document)
896 (run-hooks 'cal-tex-hook
)))
898 ;; TODO respect cal-tex-daily-start,end?
899 ;; Using different numbers of hours will probably break some layouts.
900 (defun cal-tex-week-hours (date holidays height
)
901 "Insert hourly entries for DATE with HOLIDAYS, with line height HEIGHT.
902 Uses the 24-hour clock if `cal-tex-24' is non-nil. Note that the hours
903 shown are hard-coded to 8-12, 13-17."
904 (let ((month (calendar-extract-month date
))
905 (day (calendar-extract-day date
))
906 (year (calendar-extract-year date
))
908 (cal-tex-comment "begin cal-tex-week-hours")
909 (cal-tex-cmd "\\ \\\\[-.2cm]")
910 (cal-tex-cmd "\\noindent")
911 (cal-tex-b-parbox "l" "6.8in")
912 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
914 (cal-tex-large-bf (cal-tex-month-name month
))
916 (cal-tex-large-bf (number-to-string day
))
917 (unless (string-equal "" (setq s
(cal-tex-latexify-list
918 holidays date
"; ")))
920 (cal-tex-large-bf s
))
922 (insert " " (eval cal-tex-daily-string
))
925 (cal-tex-rule "0pt" "6.8in" ".2mm")
928 (setq morning
(+ i
8) ; 8-12 incl
929 afternoon
(if cal-tex-24
930 (+ i
13) ; 13-17 incl
932 (cal-tex-cmd "\\hourbox" (number-to-string morning
))
934 (cal-tex-hspace ".4cm")
935 (cal-tex-cmd "\\hourbox" (number-to-string afternoon
))
939 ;; TODO cal-tex-diary support.
940 ;; TODO respect cal-tex-daily-start,end (see cal-tex-weekly4-box).
942 (defun cal-tex-cursor-week-monday (&optional arg
)
943 "Make a LaTeX calendar buffer for a two-page one-week calendar.
944 It applies to the week that point is in, and starts on Monday.
945 Optional prefix argument ARG specifies number of weeks (default 1).
946 The calendar shows holidays if `cal-tex-holidays' is
947 non-nil (note that diary entries are not shown). The calendar shows
948 the hours 8-12am, 1-5pm."
951 (date (calendar-gregorian-from-absolute
952 (calendar-dayname-on-or-before
954 (calendar-absolute-from-gregorian
955 (calendar-cursor-to-date t
))))))
956 (cal-tex-preamble "11pt")
957 (cal-tex-cmd "\\textwidth 6.5in")
958 (cal-tex-cmd "\\textheight 10.5in")
959 (cal-tex-cmd "\\oddsidemargin 0in")
960 (cal-tex-cmd "\\evensidemargin 0in")
963 (cal-tex-vspace "-1cm")
964 (insert "\\noindent ")
965 (cal-tex-weekly4-box (cal-tex-incr-date date
) nil
)
966 (cal-tex-weekly4-box (cal-tex-incr-date date
4) nil
)
968 (cal-tex-weekly4-box (cal-tex-incr-date date
2) nil
)
969 (cal-tex-weekly4-box (cal-tex-incr-date date
5) nil
)
971 (cal-tex-weekly4-box (cal-tex-incr-date date
3) nil
)
972 (cal-tex-weekly4-box (cal-tex-incr-date date
6) t
)
974 (run-hooks 'cal-tex-week-hook
)
975 (setq date
(cal-tex-incr-date date
7))
977 (cal-tex-end-document)
978 (run-hooks 'cal-tex-hook
)))
980 ;; TODO respect cal-tex-daily-start,end?
981 ;; Using different numbers of hours will probably break some layouts.
982 (defun cal-tex-weekly4-box (date weekend
)
983 "Make one box for DATE, different if WEEKEND.
984 Uses the 24-hour clock if `cal-tex-24' is non-nil. Note that the hours
985 shown are hard-coded to 8-12, 13-17."
986 (let* ((day (calendar-extract-day date
))
987 (month (calendar-extract-month date
))
988 (year (calendar-extract-year date
))
989 (dayname (cal-tex-LaTeXify-string (calendar-day-name date
)))
990 (date1 (cal-tex-incr-date date
))
991 (day1 (calendar-extract-day date1
))
992 (month1 (calendar-extract-month date1
))
993 (year1 (calendar-extract-year date1
))
994 (dayname1 (cal-tex-LaTeXify-string (calendar-day-name date1
))))
995 (cal-tex-b-framebox "8cm" "l")
996 (cal-tex-b-parbox "b" "7.5cm")
997 (insert (format "\\textbf{\\Large %s,} %s/%s/%s\\\\\n"
998 dayname month day year
))
999 (cal-tex-rule "0pt" "7.5cm" ".5mm")
1003 (insert (format "\\textsf{\\large %d}\\\\\n" (+ i
8))))
1005 (insert (format "\\textsf{\\large %d}\\\\\n"
1007 (+ i
13) ; 13-17 incl
1008 (1+ i
)))))) ; 1-5 incl
1011 (cal-tex-vspace "1cm")
1012 (insert "\\ \\vfill")
1013 (insert (format "\\textbf{\\Large %s,} %s/%s/%s\\\\\n"
1014 dayname1 month1 day1 year1
))
1015 (cal-tex-rule "0pt" "7.5cm" ".5mm")
1016 (cal-tex-nl "1.5cm")
1017 (cal-tex-vspace "1cm"))
1019 (cal-tex-e-framebox)
1020 (cal-tex-hspace "1cm")))
1023 (defun cal-tex-cursor-filofax-2week (&optional arg
)
1024 "Two-weeks-at-a-glance Filofax style calendar for week cursor is in.
1025 Optional prefix argument ARG specifies number of weeks (default 1).
1026 The calendar shows holiday and diary entries if
1027 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil."
1029 (let* ((n (or arg
1))
1030 (date (calendar-gregorian-from-absolute
1031 (calendar-dayname-on-or-before
1032 calendar-week-start-day
1033 (calendar-absolute-from-gregorian
1034 (calendar-cursor-to-date t
)))))
1035 (month (calendar-extract-month date
))
1036 (year (calendar-extract-year date
))
1037 (day (calendar-extract-day date
))
1038 (d1 (calendar-absolute-from-gregorian date
))
1040 (holidays (if cal-tex-holidays
1041 (cal-tex-list-holidays d1 d2
)))
1042 (diary-list (if cal-tex-diary
1043 (cal-tex-list-diary-entries
1045 (calendar-absolute-from-gregorian (list month
1 year
))
1047 (cal-tex-preamble "twoside")
1048 (cal-tex-cmd "\\textwidth 3.25in")
1049 (cal-tex-cmd "\\textheight 6.5in")
1050 (cal-tex-cmd "\\oddsidemargin 1.75in")
1051 (cal-tex-cmd "\\evensidemargin 1.5in")
1052 (cal-tex-cmd "\\topmargin 0pt")
1053 (cal-tex-cmd "\\headheight -0.875in")
1054 (cal-tex-cmd "\\headsep 0.125in")
1055 (cal-tex-cmd "\\footskip .125in")
1056 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1057 \\long\\def\\rightday#1#2#3#4#5{%
1058 \\rule{\\textwidth}{0.3pt}\\\\%
1059 \\hbox to \\textwidth{%
1062 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1063 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1064 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1065 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1066 \\long\\def\\leftday#1#2#3#4#5{%
1067 \\rule{\\textwidth}{0.3pt}\\\\%
1068 \\hbox to \\textwidth{%
1071 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1072 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1073 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1075 (cal-tex-b-document)
1076 (cal-tex-cmd "\\pagestyle{empty}")
1078 (if (zerop (mod i
2))
1079 (insert "\\righthead")
1080 (insert "\\lefthead"))
1082 (let ((d (cal-tex-incr-date date
6)))
1083 (if (= (calendar-extract-month date
)
1084 (calendar-extract-month d
))
1086 (cal-tex-month-name (calendar-extract-month date
))
1087 (calendar-extract-year date
))
1088 (if (= (calendar-extract-year date
)
1089 (calendar-extract-year d
))
1090 (format "%s---%s %s"
1091 (cal-tex-month-name (calendar-extract-month date
))
1092 (cal-tex-month-name (calendar-extract-month d
))
1093 (calendar-extract-year date
))
1094 (format "%s %s---%s %s"
1095 (cal-tex-month-name (calendar-extract-month date
))
1096 (calendar-extract-year date
)
1097 (cal-tex-month-name (calendar-extract-month d
))
1098 (calendar-extract-year d
))))))
1101 (if (zerop (mod i
2))
1102 (insert "\\rightday")
1103 (insert "\\leftday"))
1104 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1105 (cal-tex-arg (number-to-string (calendar-extract-day date
)))
1106 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1107 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1108 (cal-tex-arg (eval cal-tex-daily-string
))
1110 (setq date
(cal-tex-incr-date date
)))
1111 (unless (= i
(1- n
))
1112 (run-hooks 'cal-tex-week-hook
)
1114 (cal-tex-end-document)
1115 (run-hooks 'cal-tex-hook
)))
1118 (defun cal-tex-cursor-filofax-week (&optional arg
)
1119 "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
1120 Optional prefix argument ARG specifies number of weeks (default 1),
1121 starting on Mondays. The calendar shows holiday and diary entries
1122 if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil."
1124 (let* ((n (or arg
1))
1125 (date (calendar-gregorian-from-absolute
1126 (calendar-dayname-on-or-before
1128 (calendar-absolute-from-gregorian
1129 (calendar-cursor-to-date t
)))))
1130 (month (calendar-extract-month date
))
1131 (year (calendar-extract-year date
))
1132 (day (calendar-extract-day date
))
1133 (d1 (calendar-absolute-from-gregorian date
))
1135 (holidays (if cal-tex-holidays
1136 (cal-tex-list-holidays d1 d2
)))
1137 (diary-list (if cal-tex-diary
1138 (cal-tex-list-diary-entries
1140 (calendar-absolute-from-gregorian (list month
1 year
))
1142 (cal-tex-preamble "twoside")
1143 (cal-tex-cmd "\\textwidth 3.25in")
1144 (cal-tex-cmd "\\textheight 6.5in")
1145 (cal-tex-cmd "\\oddsidemargin 1.75in")
1146 (cal-tex-cmd "\\evensidemargin 1.5in")
1147 (cal-tex-cmd "\\topmargin 0pt")
1148 (cal-tex-cmd "\\headheight -0.875in")
1149 (cal-tex-cmd "\\headsep 0.125in")
1150 (cal-tex-cmd "\\footskip .125in")
1151 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1152 \\long\\def\\rightday#1#2#3#4#5{%
1153 \\rule{\\textwidth}{0.3pt}\\\\%
1154 \\hbox to \\textwidth{%
1157 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1158 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1159 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1160 \\long\\def\\weekend#1#2#3#4#5{%
1161 \\rule{\\textwidth}{0.3pt}\\\\%
1162 \\hbox to \\textwidth{%
1165 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1166 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1167 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1168 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1169 \\long\\def\\leftday#1#2#3#4#5{%
1170 \\rule{\\textwidth}{0.3pt}\\\\%
1171 \\hbox to \\textwidth{%
1174 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1175 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1176 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1178 (cal-tex-b-document)
1179 (cal-tex-cmd "\\pagestyle{empty}\\ ")
1182 (insert "\\lefthead")
1184 (let ((d (cal-tex-incr-date date
2)))
1185 (if (= (calendar-extract-month date
)
1186 (calendar-extract-month d
))
1188 (cal-tex-month-name (calendar-extract-month date
))
1189 (calendar-extract-year date
))
1190 (if (= (calendar-extract-year date
)
1191 (calendar-extract-year d
))
1192 (format "%s---%s %s"
1193 (cal-tex-month-name (calendar-extract-month date
))
1194 (cal-tex-month-name (calendar-extract-month d
))
1195 (calendar-extract-year date
))
1196 (format "%s %s---%s %s"
1197 (cal-tex-month-name (calendar-extract-month date
))
1198 (calendar-extract-year date
)
1199 (cal-tex-month-name (calendar-extract-month d
))
1200 (calendar-extract-year d
))))))
1203 (insert "\\leftday")
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 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1213 (insert "\\righthead")
1215 (let ((d (cal-tex-incr-date date
3)))
1216 (if (= (calendar-extract-month date
)
1217 (calendar-extract-month d
))
1219 (cal-tex-month-name (calendar-extract-month date
))
1220 (calendar-extract-year date
))
1221 (if (= (calendar-extract-year date
)
1222 (calendar-extract-year d
))
1223 (format "%s---%s %s"
1224 (cal-tex-month-name (calendar-extract-month date
))
1225 (cal-tex-month-name (calendar-extract-month d
))
1226 (calendar-extract-year date
))
1227 (format "%s %s---%s %s"
1228 (cal-tex-month-name (calendar-extract-month date
))
1229 (calendar-extract-year date
)
1230 (cal-tex-month-name (calendar-extract-month d
))
1231 (calendar-extract-year d
))))))
1234 (insert "\\rightday")
1235 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1236 (cal-tex-arg (number-to-string (calendar-extract-day date
)))
1237 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1238 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1239 (cal-tex-arg (eval cal-tex-daily-string
))
1241 (setq date
(cal-tex-incr-date date
)))
1243 (insert "\\weekend")
1244 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date
)))
1245 (cal-tex-arg (number-to-string (calendar-extract-day date
)))
1246 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1247 (cal-tex-arg (cal-tex-latexify-list holidays date
))
1248 (cal-tex-arg (eval cal-tex-daily-string
))
1250 (setq date
(cal-tex-incr-date date
)))
1251 (unless (= i
(1- n
))
1252 (run-hooks 'cal-tex-week-hook
)
1254 (cal-tex-end-document)
1255 (run-hooks 'cal-tex-hook
)))
1258 (defun cal-tex-cursor-filofax-daily (&optional arg
)
1259 "Day-per-page Filofax style calendar for week indicated by cursor.
1260 Optional prefix argument ARG specifies number of weeks (default 1),
1261 starting on Mondays. The calendar shows holiday and diary
1262 entries if `cal-tex-holidays' and `cal-tex-diary', respectively,
1263 are non-nil. Pages are ruled if `cal-tex-rules' is non-nil."
1265 (let* ((n (or arg
1))
1266 (date (calendar-gregorian-from-absolute
1267 (calendar-dayname-on-or-before
1269 (calendar-absolute-from-gregorian
1270 (calendar-cursor-to-date t
)))))
1271 (month (calendar-extract-month date
))
1272 (year (calendar-extract-year date
))
1273 (day (calendar-extract-day date
))
1274 (d1 (calendar-absolute-from-gregorian date
))
1276 (holidays (if cal-tex-holidays
1277 (cal-tex-list-holidays d1 d2
)))
1278 (diary-list (if cal-tex-diary
1279 (cal-tex-list-diary-entries
1281 (calendar-absolute-from-gregorian (list month
1 year
))
1283 (cal-tex-preamble "twoside")
1284 (cal-tex-cmd "\\textwidth 3.25in")
1285 (cal-tex-cmd "\\textheight 6.5in")
1286 (cal-tex-cmd "\\oddsidemargin 1.75in")
1287 (cal-tex-cmd "\\evensidemargin 1.5in")
1288 (cal-tex-cmd "\\topmargin 0pt")
1289 (cal-tex-cmd "\\headheight -0.875in")
1290 (cal-tex-cmd "\\headsep 0.125in")
1291 (cal-tex-cmd "\\footskip .125in")
1292 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1293 \\long\\def\\rightday#1#2#3{%
1294 \\rule{\\textwidth}{0.3pt}\\\\%
1295 \\hbox to \\textwidth{%
1298 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1299 \\hbox to \\textwidth{\\vbox {\\raggedleft \\em #2}}%
1300 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1301 \\long\\def\\weekend#1#2#3{%
1302 \\rule{\\textwidth}{0.3pt}\\\\%
1303 \\hbox to \\textwidth{%
1306 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1307 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1308 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1309 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1310 \\long\\def\\leftday#1#2#3{%
1311 \\rule{\\textwidth}{0.3pt}\\\\%
1312 \\hbox to \\textwidth{%
1315 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1316 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1317 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1319 \\setbox\\LineBox=\\hbox to\\textwidth{%
1320 \\vrule height.2in width0pt\\leaders\\hrule\\hfill}
1321 \\def\\linesfill{\\par\\leaders\\copy\\LineBox\\vfill}
1323 (cal-tex-b-document)
1324 (cal-tex-cmd "\\pagestyle{empty}")
1327 (let ((even (zerop (% j
2))))
1331 (cal-tex-arg (calendar-date-string date
))
1336 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1337 (cal-tex-arg (cal-tex-latexify-list holidays date
"\\\\" t
))
1338 (cal-tex-arg (eval cal-tex-daily-string
))
1341 (insert "\\linesfill\n")
1342 (insert "\\vfill\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1344 (setq date
(cal-tex-incr-date date
)))
1347 (insert "\\lefthead")
1348 (cal-tex-arg (calendar-date-string date
))
1349 (insert "\\weekend")
1350 (cal-tex-arg (cal-tex-latexify-list diary-list date
))
1351 (cal-tex-arg (cal-tex-latexify-list holidays date
"\\\\" t
))
1352 (cal-tex-arg (eval cal-tex-daily-string
))
1355 (insert "\\linesfill\n")
1357 (setq date
(cal-tex-incr-date date
)))
1359 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1360 (unless (= i
(1- n
))
1361 (run-hooks 'cal-tex-week-hook
)
1363 (cal-tex-end-document)
1364 (run-hooks 'cal-tex-hook
)))
1372 (defun cal-tex-cursor-day (&optional arg
)
1373 "Make a buffer with LaTeX commands for the day cursor is on.
1374 Optional prefix argument ARG specifies number of days. The calendar shows
1375 the hours between `cal-tex-daily-start' and `cal-tex-daily-end', using
1376 the 24-hour clock if `cal-tex-24' is non-nil."
1378 (let ((n (or arg
1))
1379 (date (calendar-absolute-from-gregorian (calendar-cursor-to-date t
))))
1380 (cal-tex-preamble "12pt")
1381 (cal-tex-cmd "\\textwidth 6.5in")
1382 (cal-tex-cmd "\\textheight 10.5in")
1383 (cal-tex-b-document)
1384 (cal-tex-cmd "\\pagestyle{empty}")
1386 (cal-tex-vspace "-1.7in")
1387 (cal-tex-daily-page (calendar-gregorian-from-absolute date
))
1388 (setq date
(1+ date
))
1389 (unless (= i
(1- n
))
1391 (run-hooks 'cal-tex-daily-hook
)))
1392 (cal-tex-end-document)
1393 (run-hooks 'cal-tex-hook
)))
1395 (defun cal-tex-daily-page (date)
1396 "Make a calendar page for Gregorian DATE on 8.5 by 11 paper.
1397 Uses the 24-hour clock if `cal-tex-24' is non-nil. Produces
1398 hourly sections for the period specified by `cal-tex-daily-start'
1399 and `cal-tex-daily-end'."
1400 (let ((month-name (cal-tex-month-name (calendar-extract-month date
)))
1401 (i (1- cal-tex-daily-start
))
1403 (cal-tex-banner "cal-tex-daily-page")
1404 (cal-tex-b-makebox "4cm" "l")
1405 (cal-tex-b-parbox "b" "3.8cm")
1406 (cal-tex-rule "0mm" "0mm" "2cm")
1407 (cal-tex-Huge (number-to-string (calendar-extract-day date
)))
1409 (cal-tex-bf month-name
)
1411 (cal-tex-hspace "1cm")
1412 (cal-tex-scriptsize (eval cal-tex-daily-string
))
1413 (cal-tex-hspace "3.5cm")
1416 (cal-tex-b-makebox "4cm" "r")
1417 (cal-tex-bf (cal-tex-LaTeXify-string (calendar-day-name date
)))
1420 (cal-tex-hspace ".4cm")
1421 (cal-tex-rule "0mm" "16.1cm" "1mm")
1423 (while (<= (setq i
(1+ i
)) cal-tex-daily-end
)
1424 (cal-tex-cmd "\\noindent")
1425 (setq hour
(if cal-tex-24
1428 (if (zerop hour
) (setq hour
12))
1429 (cal-tex-b-makebox "1cm" "c")
1430 (cal-tex-arg (number-to-string hour
))
1432 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1434 (cal-tex-b-makebox "1cm" "c")
1435 (cal-tex-arg "$\\diamond$" )
1437 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1438 (cal-tex-nl ".2cm"))
1440 (insert (cal-tex-mini-calendar
1441 (calendar-extract-month (cal-tex-previous-month date
))
1442 (calendar-extract-year (cal-tex-previous-month date
))
1443 "lastmonth" "1.1in" "1in"))
1444 (insert (cal-tex-mini-calendar
1445 (calendar-extract-month date
)
1446 (calendar-extract-year date
)
1447 "thismonth" "1.1in" "1in"))
1448 (insert (cal-tex-mini-calendar
1449 (calendar-extract-month (cal-tex-next-month date
))
1450 (calendar-extract-year (cal-tex-next-month date
))
1451 "nextmonth" "1.1in" "1in"))
1452 (insert "\\hbox to \\textwidth{")
1454 (insert "\\lastmonth")
1456 (insert "\\thismonth")
1458 (insert "\\nextmonth")
1461 (cal-tex-banner "end of cal-tex-daily-page")))
1467 (defun cal-tex-mini-calendar (month year name width height
&optional ptsize colsep
)
1468 "Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT.
1469 Optional string PTSIZE gives the point size (default \"scriptsize\").
1470 Optional string COLSEP gives the column separation (default \"1mm\")."
1471 (or colsep
(setq colsep
"1mm"))
1472 (or ptsize
(setq ptsize
"scriptsize"))
1473 (let ((blank-days ; at start of month
1475 (- (calendar-day-of-week (list month
1 year
))
1476 calendar-week-start-day
)
1478 (last (calendar-last-day-of-month month year
))
1479 (str (concat "\\def\\" name
"{\\hbox to" width
"{%\n"
1480 "\\vbox to" height
"{%\n"
1481 "\\vfil \\hbox to" width
"{%\n"
1484 "{@{\\hspace{0mm}}r@{\\hspace{" colsep
1485 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{" colsep
1486 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{" colsep
1487 "}}r@{\\hspace{" colsep
"}}r@{\\hspace{0mm}}}%\n"
1488 "\\multicolumn{7}{c}{"
1489 (cal-tex-month-name month
)
1491 (number-to-string year
)
1496 (cal-tex-LaTeXify-string
1497 (substring (aref calendar-day-name-array
1498 (mod (+ calendar-week-start-day i
) 7))
1504 (dotimes (idummy blank-days
)
1505 (setq str
(concat str
" & ")))
1507 (setq str
(concat str
(number-to-string (1+ i
)))
1508 str
(concat str
(if (zerop (mod (+ i
1 blank-days
) 7))
1513 (setq str
(concat str
"\n\\end{tabular}\\hfil}\\vfil}}}%\n"))
1517 ;;; Various calendar functions
1520 (defun cal-tex-incr-date (date &optional n
)
1521 "The date of the day following DATE.
1522 If optional N is given, the date of N days after DATE."
1523 (calendar-gregorian-from-absolute
1524 (+ (or n
1) (calendar-absolute-from-gregorian date
))))
1526 (defun cal-tex-latexify-list (date-list date
&optional separator final-separator
)
1527 "Return string with concatenated, LaTeX-ified entries in DATE-LIST for DATE.
1528 Use double backslash as a separator unless optional SEPARATOR is given.
1529 If resulting string is not empty, put separator at end if optional
1530 FINAL-SEPARATOR is non-nil."
1531 (or separator
(setq separator
"\\\\"))
1534 (mapconcat (lambda (x) (cal-tex-LaTeXify-string x
))
1535 (dolist (d date-list
(reverse result
))
1537 (calendar-date-equal date
(car d
))
1538 (setq result
(cons (cadr d
) result
))))
1540 (if (and final-separator
1541 (not (string-equal result
"")))
1542 (concat result separator
)
1545 (defun cal-tex-previous-month (date)
1546 "Return the date of the first day in the month previous to DATE."
1547 (let ((month (calendar-extract-month date
))
1548 (year (calendar-extract-year date
)))
1549 (calendar-increment-month month year -
1)
1550 (list month
1 year
)))
1552 (defun cal-tex-next-month (date)
1553 "Return the date of the first day in the month following DATE."
1554 (let ((month (calendar-extract-month date
))
1555 (year (calendar-extract-year date
)))
1556 (calendar-increment-month month year
1)
1557 (list month
1 year
)))
1563 (defun cal-tex-end-document ()
1564 "Finish the LaTeX document.
1565 Insert the trailer to LaTeX document, pop to LaTeX buffer, add
1566 informative header, and run HOOK."
1567 (cal-tex-e-document)
1569 (pop-to-buffer cal-tex-buffer
)
1570 (goto-char (point-min))
1571 ;; FIXME auctex equivalents?
1573 (format "\tThis buffer was produced by cal-tex.el.
1574 \tTo print a calendar, type
1575 \t\tM-x tex-buffer RET
1576 \t\tM-x tex-print RET")))
1578 (defun cal-tex-insert-preamble (weeks landscape size
&optional append
)
1579 "Initialize the output LaTeX calendar buffer, `cal-tex-buffer'.
1580 Select the output buffer, and insert the preamble for a calendar
1581 of WEEKS weeks. Insert code for landscape mode if LANDSCAPE is
1582 non-nil. Use point-size SIZE. Optional argument APPEND, if
1583 non-nil, means add to end of buffer without erasing current contents."
1584 (let ((width "18cm")
1590 (cal-tex-preamble size
)
1593 (cal-tex-cmd "\\oddsidemargin -1.75cm")
1594 (cal-tex-cmd "\\def\\holidaymult{.06}"))
1595 (cal-tex-cmd "\\special{landscape}")
1596 (cal-tex-cmd "\\textwidth 9.5in")
1597 (cal-tex-cmd "\\textheight 7in")
1599 (cal-tex-cmd "\\def\\holidaymult{.08}"))
1600 (cal-tex-cmd cal-tex-caldate
)
1601 (cal-tex-cmd cal-tex-myday
)
1602 (cal-tex-b-document)
1603 (cal-tex-cmd "\\pagestyle{empty}"))
1604 (cal-tex-cmd "\\setlength{\\cellwidth}" width
)
1605 (insert (format "\\setlength{\\cellwidth}{%f\\cellwidth}\n"
1606 (/ 1.1 (length cal-tex-which-days
))))
1607 (cal-tex-cmd "\\setlength{\\cellheight}" height
)
1608 (insert (format "\\setlength{\\cellheight}{%f\\cellheight}\n"
1610 (cal-tex-cmd "\\ \\par")
1611 (cal-tex-vspace "-3cm")))
1613 (defconst cal-tex-LaTeX-subst-list
1615 ("\"".
"''") ; quote changes meaning when list is reversed
1616 ;; Don't think this is necessary, and in any case, does not work:
1617 ;; "LaTeX Error: \verb illegal in command argument".
1618 ;;; ("@" . "\\verb|@|")
1628 ("\n" .
"\\ \\\\")) ; \\ needed for e.g \begin{center}\n AA\end{center}
1629 "Alist of symbols and their LaTeX replacements.")
1631 (defun cal-tex-LaTeXify-string (string)
1632 "Protect special characters in STRING from LaTeX."
1637 (list cal-tex-LaTeX-subst-list
)
1639 (while (not (string-equal tail
""))
1640 (setq ch
(substring-no-properties tail
0 1)
1641 pair
(assoc ch list
))
1642 (if (and pair
(string-equal ch
"\""))
1643 (setq list
(reverse list
))) ; quote changes meaning each time
1644 (setq tail
(substring-no-properties tail
1)
1645 head
(concat head
(if pair
(cdr pair
) ch
))))
1648 (defun cal-tex-month-name (month)
1649 "The name of MONTH, LaTeX-ified."
1650 (cal-tex-LaTeXify-string (calendar-month-name month
)))
1652 (defun cal-tex-hfill ()
1656 (defun cal-tex-newpage ()
1658 (insert "\\newpage%\n"))
1660 (defun cal-tex-noindent ()
1662 (insert "\\noindent"))
1664 (defun cal-tex-vspace (space)
1665 "Insert vspace command to move SPACE vertically."
1666 (insert "\\vspace*{" space
"}")
1669 (defun cal-tex-hspace (space)
1670 "Insert hspace command to move SPACE horizontally."
1671 (insert "\\hspace*{" space
"}")
1674 (defun cal-tex-comment (&optional comment
)
1675 "Insert `% ', followed by optional string COMMENT, followed by newline.
1676 COMMENT may contain newlines, which are prefixed by `% ' in the output."
1677 (insert (format "%% %s\n"
1679 (replace-regexp-in-string "\n" "\n% " comment
)
1682 (defun cal-tex-banner (comment)
1683 "Insert string COMMENT, separated by blank lines."
1684 (cal-tex-comment (format "\n\n\n\t\t\t%s\n" comment
)))
1686 (defun cal-tex-nl (&optional skip comment
)
1687 "End a line with \\. If SKIP, then add that much spacing.
1688 Add trailing COMMENT if present."
1689 (insert (format "\\\\%s"
1691 (format "[%s]" skip
)
1693 (cal-tex-comment comment
))
1695 (defun cal-tex-arg (&optional text
)
1696 "Insert a brace {} pair containing the optional string TEXT."
1697 (insert (format "{%s}" (or text
""))))
1699 (defun cal-tex-cmd (cmd &optional arg
)
1700 "Insert LaTeX CMD, with optional argument ARG, and end with %."
1709 (defun cal-tex-b-document ()
1710 "Insert beginning of document."
1711 (cal-tex-cmd "\\begin{document}"))
1713 (defun cal-tex-e-document ()
1714 "Insert end of document."
1715 (cal-tex-cmd "\\end{document}"))
1717 (defun cal-tex-b-center ()
1718 "Insert beginning of centered block."
1719 (cal-tex-cmd "\\begin{center}"))
1721 (defun cal-tex-e-center ()
1722 "Insert end of centered block."
1724 (cal-tex-cmd "\\end{center}"))
1732 (defun cal-tex-b-parbox (position width
)
1733 "Insert parbox with parameters POSITION and WIDTH."
1734 (insert "\\parbox[" position
"]{" width
"}{")
1737 (defun cal-tex-e-parbox (&optional height
)
1738 "Insert end of parbox. Optionally, force it to be a given HEIGHT."
1741 (cal-tex-rule "0mm" "0mm" height
))
1743 (cal-tex-comment "end parbox"))
1745 (defun cal-tex-b-framebox (width position
)
1746 "Insert framebox with parameters WIDTH and POSITION (clr)."
1747 (insert "\\framebox[" width
"][" position
"]{" )
1750 (defun cal-tex-e-framebox ()
1751 "Insert end of framebox."
1754 (cal-tex-comment "end framebox"))
1757 (defun cal-tex-b-makebox ( width position
)
1758 "Insert makebox with parameters WIDTH and POSITION (clr)."
1759 (insert "\\makebox[" width
"][" position
"]{" )
1762 (defun cal-tex-e-makebox ()
1763 "Insert end of makebox."
1766 (cal-tex-comment "end makebox"))
1769 (defun cal-tex-rule (lower width height
)
1770 "Insert a rule with parameters LOWER WIDTH HEIGHT."
1771 (insert "\\rule[" lower
"]{" width
"}{" height
"}"))
1777 (defun cal-tex-em (string)
1778 "Insert STRING in italic font."
1779 (insert "\\textit{" string
"}"))
1781 (defun cal-tex-bf (string)
1782 "Insert STRING in bf font."
1783 (insert "\\textbf{ " string
"}"))
1785 (defun cal-tex-scriptsize (string)
1786 "Insert STRING in scriptsize font."
1787 (insert "{\\scriptsize " string
"}"))
1789 (defun cal-tex-huge (string)
1790 "Insert STRING in huge font."
1791 (insert "{\\huge " string
"}"))
1793 (defun cal-tex-Huge (string)
1794 "Insert STRING in Huge font."
1795 (insert "{\\Huge " string
"}"))
1797 (defun cal-tex-Huge-bf (string)
1798 "Insert STRING in Huge bf font."
1799 (insert "\\textbf{\\Huge " string
"}"))
1801 (defun cal-tex-large (string)
1802 "Insert STRING in large font."
1803 (insert "{\\large " string
"}"))
1805 (defun cal-tex-large-bf (string)
1806 "Insert STRING in large bf font."
1807 (insert "\\textbf{\\large " string
"}"))
1812 ;; arch-tag: ca8168a4-5a00-4508-a565-17e3bccce6d0
1813 ;;; cal-tex.el ends here