]> code.delx.au - gnu-emacs/blob - lisp/calendar/cal-tex.el
Use new file name diary-lib.
[gnu-emacs] / lisp / calendar / cal-tex.el
1 ;;; cal-tex.el --- calendar functions for printing calendars with LaTeX.
2
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
4
5 ;; Author: Steve Fisk <fisk@bowdoin.edu>
6 ;; Edward M. Reingold <reingold@cs.uiuc.edu>
7 ;; Keywords: calendar
8 ;; Human-Keywords: Calendar, LaTeX
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25
26 ;;; Commentary:
27
28 ;; This collection of functions implements the creation of LaTeX calendars
29 ;; based on the user's holiday choices and diary file.
30
31 ;;; TO DO
32 ;;;
33 ;;; (*) Add holidays and diary entries to daily calendar.
34 ;;;
35 ;;; (*) Add diary entries to weekly calendar functions.
36 ;;;
37 ;;; (*) Make calendar styles for A4 paper.
38 ;;;
39 ;;; (*) Make daily and monthly styles Filofax paper.
40 ;;;
41 ;;; (*) Improve the LaTeX command that produces the boxes in the monthly
42 ;;; calendar to eliminate slight gap--what causes it?!
43
44 ;;; Code:
45
46 (require 'calendar)
47
48 (autoload 'list-diary-entries "diary-lib" nil t)
49 (autoload 'calendar-holiday-list "holidays" nil t)
50 (autoload 'calendar-iso-from-absolute "cal-iso" nil t)
51
52 ;;;
53 ;;; Customizable variables
54 ;;;
55
56 (defvar cal-tex-which-days '(0 1 2 3 4 5 6)
57 "*The days of the week that are displayed on the portrait monthly calendar.
58 Sunday is 0, Monday is 1, and so on. The default is to print from Sunday to
59 Saturday. For example, use
60
61 (setq cal-tex-which-days '(1 3 5))
62
63 to only print Monday, Wednesday, Friday.")
64
65 (defvar cal-tex-holidays t
66 "*If t (default), then the holidays are also printed.
67 If finding the holidays is too slow, set this to nil.")
68
69 (defvar cal-tex-diary nil
70 "*If t, the diary entries are printed in the calendar.")
71
72 (defvar cal-tex-daily-string
73 '(let* ((year (extract-calendar-year date))
74 (day (calendar-day-number date))
75 (days-remaining (- (calendar-day-number (list 12 31 year)) day)))
76 (format "%d/%d" day days-remaining))
77 "*An expression in the variable `date' whose value is placed on date.
78 The string resulting from evaluating this expression is placed at the bottom
79 center of `date' on the monthly calendar, next to the date in the weekly
80 calendars, and in the top center of daily calendars.
81
82 Default is ordinal day number of the year and the number of days remaining.
83 As an example of what you do, setting this to
84
85 '(progn
86 (require 'cal-hebrew)
87 (calendar-hebrew-date-string date))
88
89 will put the Hebrew date at the bottom of each day.")
90
91 (defvar cal-tex-buffer "calendar.tex"
92 "*The name for the tex-ed calendar.")
93
94 (defvar cal-tex-24 nil
95 "*If t, use a 24 hour clock in the daily calendar.")
96
97 (defvar cal-tex-daily-start 8
98 "*The first hour of the daily calendar page.")
99
100 (defvar cal-tex-daily-end 20
101 "*The last hour of the daily calendar page.")
102
103 ;;;
104 ;;; Definitions for LaTeX code
105 ;;;
106
107 (defvar cal-tex-day-prefix "\\caldate{%s}{%s}"
108 "The initial LaTeX code for a day.
109 The holidays, diary entries, bottom string, and the text follow.")
110
111 (defvar cal-tex-day-name-format "\\myday{%s}%%"
112 "The format for LaTeX code for a day name. The names are taken from
113 calendar-day-name-array.")
114
115 (defvar cal-tex-cal-one-month
116 "\\def\\calmonth#1#2%
117 {\\begin{center}%
118 \\Huge\\bf\\uppercase{#1} #2 \\\\[1cm]%
119 \\end{center}}%
120 \\vspace*{-1.5cm}%
121 %
122 "
123 "LaTeX code for the month header")
124
125 (defvar cal-tex-cal-multi-month
126 "\\def\\calmonth#1#2#3#4%
127 {\\begin{center}%
128 \\Huge\\bf #1 #2---#3 #4\\\\[1cm]%
129 \\end{center}}%
130 \\vspace*{-1.5cm}%
131 %
132 "
133 "LaTeX code for the month header")
134
135 (defvar cal-tex-myday
136 "\\renewcommand{\\myday}[1]%
137 {\\makebox[\\cellwidth]{\\hfill\\large\\bf#1\\hfill}}
138 %
139 "
140 "LaTeX code for a day heading")
141
142 (defvar cal-tex-caldate
143 "\\fboxsep=0pt
144 \\long\\def\\caldate#1#2#3#4#5#6{%
145 \\fbox{\\hbox to\\cellwidth{%
146 \\vbox to\\cellheight{%
147 \\hbox to\\cellwidth{%
148 {\\hspace*{1mm}\\Large \\bf \\strut #2}\\hspace{.05\\cellwidth}%
149 \\raisebox{\\holidaymult\\cellheight}%
150 {\\parbox[t]{.75\\cellwidth}{\\tiny \\raggedright #4}}}
151 \\hbox to\\cellwidth{%
152 \\hspace*{1mm}\\parbox{.95\\cellwidth}{\\tiny \\raggedright #3}}
153 \\hspace*{1mm}%
154 \\hbox to\\cellwidth{#6}%
155 \\vfill%
156 \\hbox to\\cellwidth{\\hfill \\tiny #5 \\hfill}%
157 \\vskip 1.4pt}%
158 \\hskip -0.4pt}}}
159 "
160 "LaTeX code to insert one box with date info in calendar.
161 This definition is the heart of the calendar!")
162
163 (defun cal-tex-list-holidays (d1 d2)
164 "Generate a list of all holidays from absolute date D1 to D2."
165 (let* ((result nil)
166 (start (calendar-gregorian-from-absolute d1))
167 (start-month (extract-calendar-month start))
168 (start-year (extract-calendar-year start)))
169 (increment-calendar-month start-month start-year 1)
170 (let* ((end (calendar-gregorian-from-absolute d2))
171 (end-month (extract-calendar-month end))
172 (end-year (extract-calendar-year end)))
173 (if (= (extract-calendar-day end) 1)
174 (increment-calendar-month end-month end-year -1))
175 (let* ((s (calendar-absolute-from-gregorian
176 (list start-month 1 start-year)))
177 (e (calendar-absolute-from-gregorian
178 (list end-month 1 end-year)))
179 (d s)
180 (never t)
181 (displayed-month start-month)
182 (displayed-year start-year))
183 (while (or never (<= d e))
184 (setq result (append result (calendar-holiday-list)))
185 (setq never nil)
186 (increment-calendar-month displayed-month displayed-year 3)
187 (setq d (calendar-absolute-from-gregorian
188 (list displayed-month 1 displayed-year))))))
189 (let ((in-range)
190 (p result))
191 (while p
192 (and (car (car p))
193 (let ((a (calendar-absolute-from-gregorian (car (car p)))))
194 (and (<= d1 a) (<= a d2)))
195 (setq in-range (append (list (car p)) in-range)))
196 (setq p (cdr p)))
197 in-range)))
198
199 (defun cal-tex-list-diary-entries (d1 d2)
200 "Generate a list of all diary-entries from absolute date D1 to D2."
201 (let ((diary-display-hook nil))
202 (list-diary-entries
203 (calendar-gregorian-from-absolute d1)
204 (1+ (- d2 d1)))))
205
206 (defun cal-tex-preamble (&optional args)
207 "Insert the LaTeX preamble.
208 Preamble Includes initial definitions for various LaTeX commands.
209 Optional ARGS are included."
210 (set-buffer (get-buffer-create cal-tex-buffer))
211 (erase-buffer)
212 (insert "\\documentstyle")
213 (if args
214 (insert "[" args "]"))
215 (insert "{article}\n"
216 "\\hbadness 20000
217 \\vbadness 20000
218 \\marginparwidth 0pt
219 \\oddsidemargin -2cm
220 \\evensidemargin -2cm
221 \\marginparsep 0pt
222 \\topmargin 0pt
223 \\textwidth 7.5in
224 \\textheight 9.5in
225 \\newlength{\\cellwidth}
226 \\newlength{\\cellheight}
227 \\newlength{\\boxwidth}
228 \\newlength{\\boxheight}
229 \\newlength{\\cellsize}
230 \\newcommand{\\myday}[1]{}
231 \\newcommand{\\caldate}[6]{}
232 \\newcommand{\\nocaldate}[6]{}
233 \\newcommand{\\calsmall}[6]{}
234 %
235 "))
236
237 ;;;
238 ;;; Yearly calendars
239 ;;;
240
241 (defun cal-tex-cursor-year (&optional arg)
242 "Make a buffer with LaTeX commands for the year cursor is on.
243 Optional prefix argument specifies number of years."
244 (interactive "P")
245 (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
246 (if arg arg 1)))
247
248 (defun cal-tex-cursor-year-landscape (&optional arg)
249 "Make a buffer with LaTeX commands for the year cursor is on.
250 Optional prefix argument specifies number of years."
251 (interactive "P")
252 (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
253 (if arg arg 1)
254 t))
255
256 (defun cal-tex-year (year n &optional landscape)
257 "Make a one page yearly calendar of YEAR; do this for N years.
258 There are four rows of three months each, unless optional LANDSCAPE is t,
259 in which case the calendar isprinted in landscape mode with three rows of
260 four months each."
261 (cal-tex-insert-preamble 1 landscape "12pt")
262 (if landscape
263 (cal-tex-vspace "-.6cm")
264 (cal-tex-vspace "-3.1cm"))
265 (calendar-for-loop j from 1 to n do
266 (insert "\\vfill%\n")
267 (cal-tex-b-center)
268 (cal-tex-Huge (number-to-string year))
269 (cal-tex-e-center)
270 (cal-tex-vspace "1cm")
271 (cal-tex-b-center)
272 (cal-tex-b-parbox "l" (if landscape "5.9in" "4.3in"))
273 (insert "\n")
274 (cal-tex-noindent)
275 (cal-tex-nl)
276 (calendar-for-loop i from 1 to 12 do
277 (insert (cal-tex-mini-calendar i year "month" "1.1in" "1in"))
278 (insert "\\month")
279 (cal-tex-hspace "0.5in")
280 (if (zerop (mod i (if landscape 4 3)))
281 (cal-tex-nl "0.5in")))
282 (cal-tex-e-parbox)
283 (cal-tex-e-center)
284 (insert "\\vfill%\n")
285 (setq year (1+ year))
286 (if (/= j n)
287 (cal-tex-newpage)
288 (cal-tex-end-document))
289 (run-hooks 'cal-tex-year-hook))
290 (run-hooks 'cal-tex-hook))
291
292 (defun cal-tex-cursor-filofax-year (&optional arg)
293 "Make a Filofax one page yearly calendar of year indicated by cursor.
294 Optional parameter specifies number of years."
295 (interactive "P")
296 (let* ((n (if arg arg 1))
297 (year (extract-calendar-year (calendar-cursor-to-date t))))
298 (cal-tex-preamble "twoside")
299 (cal-tex-cmd "\\textwidth 3.25in")
300 (cal-tex-cmd "\\textheight 6.5in")
301 (cal-tex-cmd "\\oddsidemargin 1.6in")
302 (cal-tex-cmd "\\evensidemargin 1.55in")
303 (cal-tex-cmd "\\topmargin 0pt")
304 (cal-tex-cmd "\\headheight -0.875in")
305 (cal-tex-cmd "\\pagestyle{empty}")
306 (cal-tex-b-document)
307 (calendar-for-loop j from 1 to n do
308 (insert (format "\\hfil {\\Large \\bf %s} \\hfil\\\\\n" year))
309 (cal-tex-b-center)
310 (cal-tex-b-parbox "l" "\\textwidth")
311 (insert "\n")
312 (cal-tex-noindent)
313 (cal-tex-nl)
314 (calendar-for-loop i from 1 to 12 do
315 (insert (cal-tex-mini-calendar i year
316 (calendar-month-name i)
317 "1.05in" ".8in" "tiny")))
318 (insert
319 "\\noindent\\fbox{\\January}\\fbox{\\February}\\fbox{\\March}\\\\
320 \\noindent\\fbox{\\April}\\fbox{\\May}\\fbox{\\June}\\\\
321 \\noindent\\fbox{\\July}\\fbox{\\August}\\fbox{\\September}\\\\
322 \\noindent\\fbox{\\October}\\fbox{\\November}\\fbox{\\December}
323 ")
324 (cal-tex-e-parbox)
325 (cal-tex-e-center)
326 (setq year (1+ year))
327 (if (/= j n)
328 (cal-tex-newpage)
329 (cal-tex-end-document))
330 (run-hooks 'cal-tex-year-hook))
331 (run-hooks 'cal-tex-hook)))
332
333 ;;;
334 ;;; Monthly calendars
335 ;;;
336
337 (defun cal-tex-cursor-month-landscape (&optional arg)
338 "Make a buffer with LaTeX commands for the month cursor is on.
339 Optional prefix argument specifies number of months to be produced.
340 The output is in landscape format, one month to a page."
341 (interactive "P")
342 (let* ((n (if arg arg 1))
343 (date (calendar-cursor-to-date t))
344 (month (extract-calendar-month date))
345 (year (extract-calendar-year date))
346 (end-month month)
347 (end-year year)
348 (cal-tex-which-days '(0 1 2 3 4 5 6)))
349 (increment-calendar-month end-month end-year (1- n))
350 (let ((diary-list (if cal-tex-diary
351 (cal-tex-list-diary-entries
352 (calendar-absolute-from-gregorian
353 (list month 1 year))
354 (calendar-absolute-from-gregorian
355 (list end-month
356 (calendar-last-day-of-month
357 end-month end-year)
358 end-year)))))
359 (holidays (if cal-tex-holidays
360 (cal-tex-list-holidays
361 (calendar-absolute-from-gregorian
362 (list month 1 year))
363 (calendar-absolute-from-gregorian
364 (list end-month
365 (calendar-last-day-of-month end-month end-year)
366 end-year)))))
367 (other-month)
368 (other-year)
369 (small-months-at-start))
370 (cal-tex-insert-preamble (cal-tex-number-weeks month year 1) t "12pt")
371 (cal-tex-cmd cal-tex-cal-one-month)
372 (calendar-for-loop i from 1 to n do
373 (setq other-month month)
374 (setq other-year year)
375 (increment-calendar-month other-month other-year -1)
376 (insert (cal-tex-mini-calendar other-month other-year "lastmonth"
377 "\\cellwidth" "\\cellheight"))
378 (increment-calendar-month other-month other-year 2)
379 (insert (cal-tex-mini-calendar other-month other-year "nextmonth"
380 "\\cellwidth" "\\cellheight"))
381 (cal-tex-insert-month-header 1 month year month year)
382 (cal-tex-insert-day-names)
383 (cal-tex-nl ".2cm")
384 (setq small-months-at-start
385 (< 1 (mod (- (calendar-day-of-week (list month 1 year))
386 calendar-week-start-day)
387 7)))
388 (if small-months-at-start
389 (insert "\\lastmonth\\nextmonth\\hspace*{-2\\cellwidth}"))
390 (cal-tex-insert-blank-days month year cal-tex-day-prefix)
391 (cal-tex-insert-days month year diary-list holidays
392 cal-tex-day-prefix)
393 (cal-tex-insert-blank-days-at-end month year cal-tex-day-prefix)
394 (if (and (not small-months-at-start)
395 (< 1 (mod (- (1- calendar-week-start-day)
396 (calendar-day-of-week
397 (list month
398 (calendar-last-day-of-month month year)
399 year)))
400 7)))
401 (insert "\\vspace*{-\\cellwidth}\\hspace*{-2\\cellwidth}"
402 "\\lastmonth\\nextmonth"))
403 (if (/= i n)
404 (progn
405 (run-hooks 'cal-tex-month-hook)
406 (cal-tex-newpage)
407 (increment-calendar-month month year 1)
408 (cal-tex-vspace "-2cm")
409 (cal-tex-insert-preamble
410 (cal-tex-number-weeks month year 1) t "12pt" t))))
411 (cal-tex-end-document)
412 (run-hooks 'cal-tex-hook))))
413
414 (defun cal-tex-cursor-month (arg)
415 "Make a buffer with LaTeX commands for the month cursor is on.
416 Optional prefix argument specifies number of months to be produced.
417 Calendar is condensed onto one page."
418 (interactive "P")
419 (let* ((date (calendar-cursor-to-date t))
420 (month (extract-calendar-month date))
421 (year (extract-calendar-year date))
422 (end-month month)
423 (end-year year)
424 (n (if arg arg 1)))
425 (increment-calendar-month end-month end-year (1- n))
426 (let ((diary-list (if cal-tex-diary
427 (cal-tex-list-diary-entries
428 (calendar-absolute-from-gregorian
429 (list month 1 year))
430 (calendar-absolute-from-gregorian
431 (list end-month
432 (calendar-last-day-of-month
433 end-month end-year)
434 end-year)))))
435 (holidays (if cal-tex-holidays
436 (cal-tex-list-holidays
437 (calendar-absolute-from-gregorian
438 (list month 1 year))
439 (calendar-absolute-from-gregorian
440 (list end-month
441 (calendar-last-day-of-month end-month end-year)
442 end-year)))))
443 (other-month)
444 (other-year))
445 (cal-tex-insert-preamble (cal-tex-number-weeks month year n) nil"12pt")
446 (if (> n 1)
447 (cal-tex-cmd cal-tex-cal-multi-month)
448 (cal-tex-cmd cal-tex-cal-one-month))
449 (cal-tex-insert-month-header n month year end-month end-year)
450 (cal-tex-insert-day-names)
451 (cal-tex-nl ".2cm")
452 (cal-tex-insert-blank-days month year cal-tex-day-prefix)
453 (calendar-for-loop i from 1 to n do
454 (setq other-month month)
455 (setq other-year year)
456 (cal-tex-insert-days month year diary-list holidays
457 cal-tex-day-prefix)
458 (increment-calendar-month month year 1))
459 (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix)
460 (cal-tex-end-document)))
461 (run-hooks 'cal-tex-hook))
462
463 (defun cal-tex-insert-days (month year diary-list holidays day-format)
464 "Insert LaTeX commands for a range of days in monthly calendars.
465 LaTeX commands are inserted for the days of the MONTH in YEAR.
466 Diary entries on DIARY-LIST are included. Holidays on HOLIDAYS are included.
467 Each day is formatted using format DAY-FORMAT."
468 (let* ((blank-days;; at start of month
469 (mod
470 (- (calendar-day-of-week (list month 1 year))
471 calendar-week-start-day)
472 7))
473 (date)
474 (last (calendar-last-day-of-month month year)))
475 (calendar-for-loop i from 1 to last do
476 (setq date (list month i year))
477 (if (memq (calendar-day-of-week date) cal-tex-which-days)
478 (progn
479 (insert (format day-format (calendar-month-name month) i))
480 (cal-tex-arg (cal-tex-latexify-list diary-list date))
481 (cal-tex-arg (cal-tex-latexify-list holidays date))
482 (cal-tex-arg (eval cal-tex-daily-string))
483 (cal-tex-arg)
484 (cal-tex-comment)))
485 (if (and (zerop (mod (+ i blank-days) 7))
486 (/= i last))
487 (progn
488 (cal-tex-hfill)
489 (cal-tex-nl))))))
490
491 (defun cal-tex-insert-day-names ()
492 "Insert the names of the days at top of a monthly calendar."
493 (calendar-for-loop i from 0 to 6 do
494 (if (memq i cal-tex-which-days)
495 (insert (format cal-tex-day-name-format
496 (aref calendar-day-name-array
497 (mod (+ calendar-week-start-day i) 7)))))
498 (cal-tex-comment)))
499
500 (defun cal-tex-insert-month-header (n month year end-month end-year)
501 "Create a title for a calendar.
502 A title is inserted for a calendar with N months starting with
503 MONTH YEAR and ending with END-MONTH END-YEAR."
504 (let ( (month-name (calendar-month-name month))
505 (end-month-name (calendar-month-name end-month)))
506 (if (= 1 n)
507 (insert (format "\\calmonth{%s}{%s}\n\\vspace*{-0.5cm}"
508 month-name year) )
509 (insert (format "\\calmonth{%s}{%s}{%s}{%s}\n\\vspace*{-0.5cm}"
510 month-name year end-month-name end-year))))
511 (cal-tex-comment))
512
513 (defun cal-tex-insert-blank-days (month year day-format)
514 "Insert code for initial days not in calendar.
515 Insert LaTeX code for the blank days at the beginning of the MONTH in
516 YEAR. The entry is formatted using DAY-FORMAT. If the entire week is
517 blank, no days are inserted."
518 (if (cal-tex-first-blank-p month year)
519 (let* ((blank-days;; at start of month
520 (mod
521 (- (calendar-day-of-week (list month 1 year))
522 calendar-week-start-day)
523 7)))
524 (calendar-for-loop i from 0 to (1- blank-days) do
525 (if (memq i cal-tex-which-days)
526 (insert (format day-format " " " ") "{}{}{}{}%\n"))))))
527
528 (defun cal-tex-insert-blank-days-at-end (month year day-format)
529 "Insert code for final days not in calendar.
530 Insert LaTeX code for the blank days at the end of the MONTH in YEAR.
531 The entry is formatted using DAY-FORMAT."
532 (if (cal-tex-last-blank-p month year)
533 (let* ((last-day (calendar-last-day-of-month month year))
534 (blank-days;; at end of month
535 (mod
536 (- (calendar-day-of-week (list month last-day year))
537 calendar-week-start-day)
538 7)))
539 (calendar-for-loop i from (1+ blank-days) to 6 do
540 (if (memq i cal-tex-which-days)
541 (insert (format day-format "" "") "{}{}{}{}%\n"))))))
542
543 (defun cal-tex-first-blank-p (month year)
544 "Determine if any days of the first week will be printed.
545 Return t if there will there be any days of the first week printed
546 in the calendar starting in MONTH YEAR."
547 (let ((any-days nil)
548 (the-saturday)) ;the day of week of 1st Saturday
549 (calendar-for-loop i from 1 to 7 do
550 (if (= 6 (calendar-day-of-week (list month i year)))
551 (setq the-saturday i)))
552 (calendar-for-loop i from 1 to the-saturday do
553 (if (memq (calendar-day-of-week (list month i year))
554 cal-tex-which-days)
555 (setq any-days t)))
556 any-days))
557
558 (defun cal-tex-last-blank-p (month year)
559 "Determine if any days of the last week will be printed.
560 Return t if there will there be any days of the last week printed
561 in the calendar starting in MONTH YEAR."
562 (let ((any-days nil)
563 (last-day (calendar-last-day-of-month month year))
564 (the-sunday)) ;the day of week of last Sunday
565 (calendar-for-loop i from (- last-day 6) to last-day do
566 (if (= 0 (calendar-day-of-week (list month i year)))
567 (setq the-sunday i)))
568 (calendar-for-loop i from the-sunday to last-day do
569 (if (memq (calendar-day-of-week (list month i year))
570 cal-tex-which-days)
571 (setq any-days t)))
572 any-days))
573
574 (defun cal-tex-number-weeks (month year n)
575 "Determine the number of weeks in a range of dates.
576 Compute the number of weeks in the calendar starting with MONTH and YEAR,
577 and lasting N months, including only the days in WHICH-DAYS. As it stands,
578 this is only an upper bound."
579 (let ((d (list month 1 year)))
580 (increment-calendar-month month year (1- n))
581 (/ (- (calendar-dayname-on-or-before
582 calendar-week-start-day
583 (+ 7 (calendar-absolute-from-gregorian
584 (list month (calendar-last-day-of-month month year) year))))
585 (calendar-dayname-on-or-before
586 calendar-week-start-day
587 (calendar-absolute-from-gregorian d)))
588 7)))
589
590 ;;;
591 ;;; Weekly calendars
592 ;;;
593
594 (defun cal-tex-cursor-week (&optional arg)
595 "Make a buffer with LaTeX commands for a two-page one-week calendar.
596 It applies to the week that point is in.
597 Optional prefix argument specifies number of weeks.
598 Holidays are included if `cal-tex-holidays' is t."
599 (interactive "P")
600 (let* ((n (if arg arg 1))
601 (date (calendar-gregorian-from-absolute
602 (calendar-dayname-on-or-before
603 calendar-week-start-day
604 (calendar-absolute-from-gregorian
605 (calendar-cursor-to-date t)))))
606 (month (extract-calendar-month date))
607 (year (extract-calendar-year date))
608 (holidays (if cal-tex-holidays
609 (cal-tex-list-holidays
610 (calendar-absolute-from-gregorian date)
611 (+ (* 7 n)
612 (calendar-absolute-from-gregorian date))))))
613 (cal-tex-preamble "11pt")
614 (cal-tex-cmd "\\textwidth 6.5in")
615 (cal-tex-cmd "\\textheight 10.5in")
616 (cal-tex-cmd "\\oddsidemargin 0in")
617 (cal-tex-cmd "\\evensidemargin 0in")
618 (insert cal-tex-LaTeX-hourbox)
619 (cal-tex-b-document)
620 (cal-tex-cmd "\\pagestyle{empty}")
621 (calendar-for-loop i from 1 to n do
622 (cal-tex-vspace "-1.5in")
623 (cal-tex-b-center)
624 (cal-tex-Huge-bf (format "\\uppercase{%s}"
625 (calendar-month-name month)))
626 (cal-tex-hspace "2em")
627 (cal-tex-Huge-bf (number-to-string year))
628 (cal-tex-nl ".5cm")
629 (cal-tex-e-center)
630 (cal-tex-hspace "-.2in")
631 (cal-tex-b-parbox "l" "7in")
632 (calendar-for-loop j from 1 to 7 do
633 (cal-tex-week-hours date holidays "3.1")
634 (setq date (cal-tex-incr-date date)))
635 (cal-tex-e-parbox)
636 (setq month (extract-calendar-month date))
637 (setq year (extract-calendar-year date))
638 (if (/= i n)
639 (progn
640 (run-hooks 'cal-tex-week-hook)
641 (cal-tex-newpage))))
642 (cal-tex-end-document)
643 (run-hooks 'cal-tex-hook)))
644
645 (defun cal-tex-cursor-week2 (&optional arg)
646 "Make a buffer with LaTeX commands for a two-page one-week calendar.
647 It applies to the week that point is in.
648 Optional prefix argument specifies number of weeks.
649 Holidays are included if `cal-tex-holidays' is t."
650 (interactive "P")
651 (let* ((n (if arg arg 1))
652 (date (calendar-gregorian-from-absolute
653 (calendar-dayname-on-or-before
654 calendar-week-start-day
655 (calendar-absolute-from-gregorian
656 (calendar-cursor-to-date t)))))
657 (month (extract-calendar-month date))
658 (year (extract-calendar-year date))
659 (d date)
660 (holidays (if cal-tex-holidays
661 (cal-tex-list-holidays
662 (calendar-absolute-from-gregorian date)
663 (+ (* 7 n)
664 (calendar-absolute-from-gregorian date))))))
665 (cal-tex-preamble "12pt")
666 (cal-tex-cmd "\\textwidth 6.5in")
667 (cal-tex-cmd "\\textheight 10.5in")
668 (cal-tex-cmd "\\oddsidemargin 0in")
669 (cal-tex-cmd "\\evensidemargin 0in")
670 (insert cal-tex-LaTeX-hourbox)
671 (cal-tex-b-document)
672 (cal-tex-cmd "\\pagestyle{empty}")
673 (calendar-for-loop i from 1 to n do
674 (cal-tex-vspace "-1.5in")
675 (cal-tex-b-center)
676 (cal-tex-Huge-bf (format "\\uppercase{%s}"
677 (calendar-month-name month)))
678 (cal-tex-hspace "2em")
679 (cal-tex-Huge-bf (number-to-string year))
680 (cal-tex-nl ".5cm")
681 (cal-tex-e-center)
682 (cal-tex-hspace "-.2in")
683 (cal-tex-b-parbox "l" "\\textwidth")
684 (calendar-for-loop j from 1 to 3 do
685 (cal-tex-week-hours date holidays "5")
686 (setq date (cal-tex-incr-date date)))
687 (cal-tex-e-parbox)
688 (cal-tex-nl)
689 (insert (cal-tex-mini-calendar
690 (extract-calendar-month (cal-tex-previous-month date))
691 (extract-calendar-year (cal-tex-previous-month date))
692 "lastmonth" "1.1in" "1in"))
693 (insert (cal-tex-mini-calendar
694 (extract-calendar-month date)
695 (extract-calendar-year date)
696 "thismonth" "1.1in" "1in"))
697 (insert (cal-tex-mini-calendar
698 (extract-calendar-month (cal-tex-next-month date))
699 (extract-calendar-year (cal-tex-next-month date))
700 "nextmonth" "1.1in" "1in"))
701 (insert "\\hbox to \\textwidth{")
702 (cal-tex-hfill)
703 (insert "\\lastmonth")
704 (cal-tex-hfill)
705 (insert "\\thismonth")
706 (cal-tex-hfill)
707 (insert "\\nextmonth")
708 (cal-tex-hfill)
709 (insert "}")
710 (cal-tex-nl)
711 (cal-tex-b-parbox "l" "\\textwidth")
712 (calendar-for-loop j from 4 to 7 do
713 (cal-tex-week-hours date holidays "5")
714 (setq date (cal-tex-incr-date date)))
715 (cal-tex-e-parbox)
716 (setq month (extract-calendar-month date))
717 (setq year (extract-calendar-year date))
718 (if (/= i n)
719 (progn
720 (run-hooks 'cal-tex-week-hook)
721 (cal-tex-newpage))))
722 (cal-tex-end-document)
723 (run-hooks 'cal-tex-hook)))
724
725 (defun cal-tex-cursor-week-iso (&optional arg)
726 "Make a buffer with LaTeX commands for a one page ISO-style weekly calendar.
727 Optional prefix argument specifies number of weeks.
728 Diary entries are included if `cal-tex-diary' is t.
729 Holidays are included if `cal-tex-holidays' is t."
730 (interactive "P")
731 (let* ((n (if arg arg 1))
732 (date (calendar-gregorian-from-absolute
733 (calendar-dayname-on-or-before
734 1
735 (calendar-absolute-from-gregorian
736 (calendar-cursor-to-date t)))))
737 (month (extract-calendar-month date))
738 (year (extract-calendar-year date))
739 (day (extract-calendar-day date))
740 (holidays (if cal-tex-holidays
741 (cal-tex-list-holidays
742 (calendar-absolute-from-gregorian date)
743 (+ (* 7 n)
744 (calendar-absolute-from-gregorian date)))))
745 (diary-list (if cal-tex-diary
746 (cal-tex-list-diary-entries
747 (calendar-absolute-from-gregorian
748 (list month 1 year))
749 (+ (* 7 n)
750 (calendar-absolute-from-gregorian date))))))
751 (cal-tex-preamble "11pt")
752 (cal-tex-cmd "\\textwidth 6.5in")
753 (cal-tex-cmd "\\textheight 10.5in")
754 (cal-tex-cmd "\\oddsidemargin 0in")
755 (cal-tex-cmd "\\evensidemargin 0in")
756 (cal-tex-b-document)
757 (cal-tex-cmd "\\pagestyle{empty}")
758 (calendar-for-loop i from 1 to n do
759 (cal-tex-vspace "-1.5in")
760 (cal-tex-b-center)
761 (cal-tex-Huge-bf
762 (let* ((d (calendar-iso-from-absolute
763 (calendar-absolute-from-gregorian date))))
764 (format "Week %d of %d"
765 (extract-calendar-month d)
766 (extract-calendar-year d))))
767 (cal-tex-nl ".5cm")
768 (cal-tex-e-center)
769 (cal-tex-b-parbox "l" "\\textwidth")
770 (calendar-for-loop j from 1 to 7 do
771 (cal-tex-b-parbox "t" "\\textwidth")
772 (cal-tex-b-parbox "t" "\\textwidth")
773 (cal-tex-rule "0pt" "\\textwidth" ".2mm")
774 (cal-tex-nl)
775 (cal-tex-b-parbox "t" "\\textwidth")
776 (cal-tex-large-bf (calendar-day-name date))
777 (insert ", ")
778 (cal-tex-large-bf (calendar-month-name month))
779 (insert " ")
780 (cal-tex-large-bf (number-to-string day))
781 (if (not (string= "" (cal-tex-latexify-list holidays date)))
782 (progn
783 (insert ": ")
784 (cal-tex-large-bf (cal-tex-latexify-list holidays date "; "))))
785 (cal-tex-hfill)
786 (insert " " (eval cal-tex-daily-string))
787 (cal-tex-e-parbox)
788 (cal-tex-nl)
789 (cal-tex-noindent)
790 (cal-tex-b-parbox "t" "\\textwidth")
791 (if (not (string= "" (cal-tex-latexify-list diary-list date)))
792 (progn
793 (insert "\\vbox to 0pt{")
794 (cal-tex-large-bf
795 (cal-tex-latexify-list diary-list date))
796 (insert "}")))
797 (cal-tex-e-parbox)
798 (cal-tex-nl)
799 (setq date (cal-tex-incr-date date))
800 (setq month (extract-calendar-month date))
801 (setq day (extract-calendar-day date))
802 (cal-tex-e-parbox)
803 (cal-tex-e-parbox "2cm")
804 (cal-tex-nl)
805 (setq month (extract-calendar-month date))
806 (setq year (extract-calendar-year date)))
807 (cal-tex-e-parbox)%
808 (if (/= i n)
809 (progn
810 (run-hooks 'cal-tex-week-hook)
811 (cal-tex-newpage))))
812 (cal-tex-end-document)
813 (run-hooks 'cal-tex-hook)))
814
815 (defvar cal-tex-LaTeX-hourbox
816 "\\newcommand{\\hourbox}[2]%
817 {\\makebox[2em]{\\rule{0cm}{#2ex}#1}\\rule{3in}{.15mm}}\n"
818 "One hour and a line on the right.")
819
820 (defun cal-tex-week-hours (date holidays height)
821 "Insert hourly entries for DATE with HOLIDAYS, with line height HEIGHT."
822 (let ((month (extract-calendar-month date))
823 (day (extract-calendar-day date))
824 (year (extract-calendar-year date))
825 (afternoon))
826 (cal-tex-comment "begin cal-tex-week-hours")
827 (cal-tex-cmd "\\ \\\\[-.2cm]")
828 (cal-tex-cmd "\\noindent")
829 (cal-tex-b-parbox "l" "6.8in")
830 (cal-tex-large-bf (calendar-day-name date))
831 (insert ", ")
832 (cal-tex-large-bf (calendar-month-name month))
833 (insert " ")
834 (cal-tex-large-bf (number-to-string day))
835 (if (not (string= "" (cal-tex-latexify-list holidays date)))
836 (progn
837 (insert ": ")
838 (cal-tex-large-bf (cal-tex-latexify-list holidays date "; "))))
839 (cal-tex-hfill)
840 (insert " " (eval cal-tex-daily-string))
841 (cal-tex-e-parbox)
842 (cal-tex-nl "-.3cm")
843 (cal-tex-rule "0pt" "6.8in" ".2mm")
844 (cal-tex-nl "-.1cm")
845 (calendar-for-loop i from 8 to 12 do
846 (if cal-tex-24
847 (setq afternoon (+ i 5))
848 (setq afternoon (- i 7)))
849 (cal-tex-cmd "\\hourbox" (number-to-string i))
850 (cal-tex-arg height)
851 (cal-tex-hspace ".4cm")
852 (cal-tex-cmd "\\hourbox" (number-to-string afternoon))
853 (cal-tex-arg height)
854 (cal-tex-nl))))
855
856 (defun cal-tex-cursor-week-monday (&optional arg)
857 "Make a buffer with LaTeX commands for a two-page one-week calendar.
858 It applies to the week that point is in, and starts on Monday.
859 Optional prefix argument specifies number of weeks.
860 Holidays are included if `cal-tex-holidays' is t."
861 (interactive "P")
862 (let* ((n (if arg arg 1))
863 (date (calendar-gregorian-from-absolute
864 (calendar-dayname-on-or-before
865 0
866 (calendar-absolute-from-gregorian
867 (calendar-cursor-to-date t))))))
868 (cal-tex-preamble "11pt")
869 (cal-tex-cmd "\\textwidth 6.5in")
870 (cal-tex-cmd "\\textheight 10.5in")
871 (cal-tex-cmd "\\oddsidemargin 0in")
872 (cal-tex-cmd "\\evensidemargin 0in")
873 (cal-tex-b-document)
874 (calendar-for-loop i from 1 to n do
875 (cal-tex-vspace "-1cm")
876 (insert "\\noindent ")
877 (cal-tex-weekly4-box (cal-tex-incr-date date) nil)
878 (cal-tex-weekly4-box (cal-tex-incr-date date 4) nil)
879 (cal-tex-nl ".2cm")
880 (cal-tex-weekly4-box (cal-tex-incr-date date 2) nil)
881 (cal-tex-weekly4-box (cal-tex-incr-date date 5) nil)
882 (cal-tex-nl ".2cm")
883 (cal-tex-weekly4-box (cal-tex-incr-date date 3) nil)
884 (cal-tex-weekly4-box (cal-tex-incr-date date 6) t)
885 (if (/= i n)
886 (progn
887 (run-hooks 'cal-tex-week-hook)
888 (setq date (cal-tex-incr-date date 7))
889 (cal-tex-newpage))))
890 (cal-tex-end-document)
891 (run-hooks 'cal-tex-hook)))
892
893 (defun cal-tex-weekly4-box (date weekend)
894 "Make one box for DATE, different if WEEKEND."
895 (let* (
896 (day (extract-calendar-day date))
897 (month (extract-calendar-month date))
898 (year (extract-calendar-year date))
899 (dayname (calendar-day-name date))
900 (date1 (cal-tex-incr-date date))
901 (day1 (extract-calendar-day date1))
902 (month1 (extract-calendar-month date1))
903 (year1 (extract-calendar-year date1))
904 (dayname1 (calendar-day-name date1))
905 )
906 (cal-tex-b-framebox "8cm" "l")
907 (cal-tex-b-parbox "b" "7.5cm")
908 (insert (format "{\\Large\\bf %s,} %s/%s/%s\\\\\n" dayname month day year))
909 (cal-tex-rule "0pt" "7.5cm" ".5mm")
910 (cal-tex-nl)
911 (if (not weekend)
912 (progn
913 (calendar-for-loop i from 8 to 12 do
914 (insert (format "{\\large\\sf %d}\\\\\n" i)))
915 (calendar-for-loop i from 1 to 5 do
916 (insert (format "{\\large\\sf %d}\\\\\n" i)))))
917 (cal-tex-nl ".5cm")
918 (if weekend
919 (progn
920 (cal-tex-vspace "1cm")
921 (insert "\\ \\vfill")
922 (insert (format "{\\Large\\bf %s,} %s/%s/%s\\\\\n"
923 dayname1 month1 day1 year1))
924 (cal-tex-rule "0pt" "7.5cm" ".5mm")
925 (cal-tex-nl "1.5cm")
926 (cal-tex-vspace "1cm")))
927 (cal-tex-e-parbox)
928 (cal-tex-e-framebox)
929 (cal-tex-hspace "1cm")))
930
931 (defun cal-tex-cursor-filofax-2week (&optional arg)
932 "Two-weeks-at-a-glance Filofax style calendar for week indicated by cursor.
933 Optional prefix argument specifies number of weeks.
934 Diary entries are included if `cal-tex-diary' is t.
935 Holidays are included if `cal-tex-holidays' is t."
936 (interactive "P")
937 (let* ((n (if arg arg 1))
938 (date (calendar-gregorian-from-absolute
939 (calendar-dayname-on-or-before
940 calendar-week-start-day
941 (calendar-absolute-from-gregorian
942 (calendar-cursor-to-date t)))))
943 (month (extract-calendar-month date))
944 (year (extract-calendar-year date))
945 (day (extract-calendar-day date))
946 (holidays (if cal-tex-holidays
947 (cal-tex-list-holidays
948 (calendar-absolute-from-gregorian date)
949 (+ (* 7 n)
950 (calendar-absolute-from-gregorian date)))))
951 (diary-list (if cal-tex-diary
952 (cal-tex-list-diary-entries
953 (calendar-absolute-from-gregorian
954 (list month 1 year))
955 (+ (* 7 n)
956 (calendar-absolute-from-gregorian date))))))
957 (cal-tex-preamble "twoside")
958 (cal-tex-cmd "\\textwidth 3.25in")
959 (cal-tex-cmd "\\textheight 6.5in")
960 (cal-tex-cmd "\\oddsidemargin 1.75in")
961 (cal-tex-cmd "\\evensidemargin 1.5in")
962 (cal-tex-cmd "\\topmargin 0pt")
963 (cal-tex-cmd "\\headheight -0.875in")
964 (cal-tex-cmd "\\headsep 0.125in")
965 (cal-tex-cmd "\\footskip .125in")
966 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
967 \\long\\def\\rightday#1#2#3#4#5{%
968 \\rule{\\textwidth}{0.3pt}\\\\%
969 \\hbox to \\textwidth{%
970 \\vbox to 0.7in{%
971 \\vspace*{2pt}%
972 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
973 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
974 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
975 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
976 \\long\\def\\leftday#1#2#3#4#5{%
977 \\rule{\\textwidth}{0.3pt}\\\\%
978 \\hbox to \\textwidth{%
979 \\vbox to 0.7in{%
980 \\vspace*{2pt}%
981 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
982 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
983 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
984 ")
985 (cal-tex-b-document)
986 (cal-tex-cmd "\\pagestyle{empty}")
987 (calendar-for-loop i from 1 to n do
988 (if (= (mod i 2) 1)
989 (insert "\\righthead")
990 (insert "\\lefthead"))
991 (cal-tex-arg
992 (let ((d (cal-tex-incr-date date 6)))
993 (if (= (extract-calendar-month date)
994 (extract-calendar-month d))
995 (format "%s %s"
996 (calendar-month-name
997 (extract-calendar-month date))
998 (extract-calendar-year date))
999 (if (= (extract-calendar-year date)
1000 (extract-calendar-year d))
1001 (format "%s---%s %s"
1002 (calendar-month-name
1003 (extract-calendar-month date))
1004 (calendar-month-name
1005 (extract-calendar-month d))
1006 (extract-calendar-year date))
1007 (format "%s %s---%s %s"
1008 (calendar-month-name
1009 (extract-calendar-month date))
1010 (extract-calendar-year date)
1011 (calendar-month-name (extract-calendar-month d))
1012 (extract-calendar-year d))))))
1013 (insert "%\n")
1014 (calendar-for-loop j from 1 to 7 do
1015 (if (= (mod i 2) 1)
1016 (insert "\\rightday")
1017 (insert "\\leftday"))
1018 (cal-tex-arg (calendar-day-name date))
1019 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1020 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1021 (cal-tex-arg (cal-tex-latexify-list holidays date))
1022 (cal-tex-arg (eval cal-tex-daily-string))
1023 (insert "%\n")
1024 (setq date (cal-tex-incr-date date)))
1025 (if (/= i n)
1026 (progn
1027 (run-hooks 'cal-tex-week-hook)
1028 (cal-tex-newpage))))
1029 (cal-tex-end-document)
1030 (run-hooks 'cal-tex-hook)))
1031
1032 (defun cal-tex-cursor-filofax-week (&optional arg)
1033 "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
1034 Optional prefix argument specifies number of weeks.
1035 Weeks start on Monday.
1036 Diary entries are included if `cal-tex-diary' is t.
1037 Holidays are included if `cal-tex-holidays' is t."
1038 (interactive "P")
1039 (let* ((n (if arg arg 1))
1040 (date (calendar-gregorian-from-absolute
1041 (calendar-dayname-on-or-before
1042 1
1043 (calendar-absolute-from-gregorian
1044 (calendar-cursor-to-date t)))))
1045 (month (extract-calendar-month date))
1046 (year (extract-calendar-year date))
1047 (day (extract-calendar-day date))
1048 (holidays (if cal-tex-holidays
1049 (cal-tex-list-holidays
1050 (calendar-absolute-from-gregorian date)
1051 (+ (* 7 n)
1052 (calendar-absolute-from-gregorian date)))))
1053 (diary-list (if cal-tex-diary
1054 (cal-tex-list-diary-entries
1055 (calendar-absolute-from-gregorian
1056 (list month 1 year))
1057 (+ (* 7 n)
1058 (calendar-absolute-from-gregorian date))))))
1059 (cal-tex-preamble "twoside")
1060 (cal-tex-cmd "\\textwidth 3.25in")
1061 (cal-tex-cmd "\\textheight 6.5in")
1062 (cal-tex-cmd "\\oddsidemargin 1.75in")
1063 (cal-tex-cmd "\\evensidemargin 1.5in")
1064 (cal-tex-cmd "\\topmargin 0pt")
1065 (cal-tex-cmd "\\headheight -0.875in")
1066 (cal-tex-cmd "\\headsep 0.125in")
1067 (cal-tex-cmd "\\footskip .125in")
1068 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1069 \\long\\def\\rightday#1#2#3#4#5{%
1070 \\rule{\\textwidth}{0.3pt}\\\\%
1071 \\hbox to \\textwidth{%
1072 \\vbox to 1.85in{%
1073 \\vspace*{2pt}%
1074 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1075 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1076 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1077 \\long\\def\\weekend#1#2#3#4#5{%
1078 \\rule{\\textwidth}{0.3pt}\\\\%
1079 \\hbox to \\textwidth{%
1080 \\vbox to .8in{%
1081 \\vspace*{2pt}%
1082 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1083 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1084 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1085 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1086 \\long\\def\\leftday#1#2#3#4#5{%
1087 \\rule{\\textwidth}{0.3pt}\\\\%
1088 \\hbox to \\textwidth{%
1089 \\vbox to 1.85in{%
1090 \\vspace*{2pt}%
1091 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1092 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1093 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1094 ")
1095 (cal-tex-b-document)
1096 (cal-tex-cmd "\\pagestyle{empty}\\ ")
1097 (cal-tex-newpage)
1098 (calendar-for-loop i from 1 to n do
1099 (insert "\\lefthead")
1100 (cal-tex-arg
1101 (let ((d (cal-tex-incr-date date 2)))
1102 (if (= (extract-calendar-month date)
1103 (extract-calendar-month d))
1104 (format "%s %s"
1105 (calendar-month-name
1106 (extract-calendar-month date))
1107 (extract-calendar-year date))
1108 (if (= (extract-calendar-year date)
1109 (extract-calendar-year d))
1110 (format "%s---%s %s"
1111 (calendar-month-name
1112 (extract-calendar-month date))
1113 (calendar-month-name
1114 (extract-calendar-month d))
1115 (extract-calendar-year date))
1116 (format "%s %s---%s %s"
1117 (calendar-month-name
1118 (extract-calendar-month date))
1119 (extract-calendar-year date)
1120 (calendar-month-name (extract-calendar-month d))
1121 (extract-calendar-year d))))))
1122 (insert "%\n")
1123 (calendar-for-loop j from 1 to 3 do
1124 (insert "\\leftday")
1125 (cal-tex-arg (calendar-day-name date))
1126 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1127 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1128 (cal-tex-arg (cal-tex-latexify-list holidays date))
1129 (cal-tex-arg (eval cal-tex-daily-string))
1130 (insert "%\n")
1131 (setq date (cal-tex-incr-date date)))
1132 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1133 (cal-tex-newpage)
1134 (insert "\\righthead")
1135 (cal-tex-arg
1136 (let ((d (cal-tex-incr-date date 3)))
1137 (if (= (extract-calendar-month date)
1138 (extract-calendar-month d))
1139 (format "%s %s"
1140 (calendar-month-name
1141 (extract-calendar-month date))
1142 (extract-calendar-year date))
1143 (if (= (extract-calendar-year date)
1144 (extract-calendar-year d))
1145 (format "%s---%s %s"
1146 (calendar-month-name
1147 (extract-calendar-month date))
1148 (calendar-month-name
1149 (extract-calendar-month d))
1150 (extract-calendar-year date))
1151 (format "%s %s---%s %s"
1152 (calendar-month-name
1153 (extract-calendar-month date))
1154 (extract-calendar-year date)
1155 (calendar-month-name (extract-calendar-month d))
1156 (extract-calendar-year d))))))
1157 (insert "%\n")
1158 (calendar-for-loop j from 1 to 2 do
1159 (insert "\\rightday")
1160 (cal-tex-arg (calendar-day-name date))
1161 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1162 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1163 (cal-tex-arg (cal-tex-latexify-list holidays date))
1164 (cal-tex-arg (eval cal-tex-daily-string))
1165 (insert "%\n")
1166 (setq date (cal-tex-incr-date date)))
1167 (calendar-for-loop j from 1 to 2 do
1168 (insert "\\weekend")
1169 (cal-tex-arg (calendar-day-name date))
1170 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1171 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1172 (cal-tex-arg (cal-tex-latexify-list holidays date))
1173 (cal-tex-arg (eval cal-tex-daily-string))
1174 (insert "%\n")
1175 (setq date (cal-tex-incr-date date)))
1176 (if (/= i n)
1177 (progn
1178 (run-hooks 'cal-tex-week-hook)
1179 (cal-tex-newpage))))
1180 (cal-tex-end-document)
1181 (run-hooks 'cal-tex-hook)))
1182 ;;;
1183 ;;; Daily calendars
1184 ;;;
1185
1186 (defun cal-tex-cursor-day (&optional arg)
1187 "Make a buffer with LaTeX commands for the day cursor is on.
1188 Optional prefix argument specifies number of days."
1189 (interactive "P")
1190 (let ((n (if arg arg 1))
1191 (date (calendar-absolute-from-gregorian (calendar-cursor-to-date t))))
1192 (cal-tex-preamble "12pt")
1193 (cal-tex-cmd "\\textwidth 6.5in")
1194 (cal-tex-cmd "\\textheight 10.5in")
1195 (cal-tex-b-document)
1196 (cal-tex-cmd "\\pagestyle{empty}")
1197 (calendar-for-loop i from 1 to n do
1198 (cal-tex-vspace "-1.7in")
1199 (cal-tex-daily-page (calendar-gregorian-from-absolute date))
1200 (setq date (1+ date))
1201 (if (/= i n)
1202 (progn
1203 (cal-tex-newpage)
1204 (run-hooks 'cal-tex-daily-hook))))
1205 (cal-tex-end-document)
1206 (run-hooks 'cal-tex-hook)))
1207
1208 (defun cal-tex-daily-page (date)
1209 "Make a calendar page for Gregorian DATE on 8.5 by 11 paper."
1210 (let* ((hour)
1211 (month-name (calendar-month-name (extract-calendar-month date))))
1212 (cal-tex-banner "cal-tex-daily-page")
1213 (cal-tex-b-makebox "4cm" "l")
1214 (cal-tex-b-parbox "b" "3.8cm")
1215 (cal-tex-rule "0mm" "0mm" "2cm")
1216 (cal-tex-Huge (number-to-string (extract-calendar-day date)))
1217 (cal-tex-nl ".5cm")
1218 (cal-tex-bf month-name )
1219 (cal-tex-e-parbox)
1220 (cal-tex-hspace "1cm")
1221 (cal-tex-scriptsize (eval cal-tex-daily-string))
1222 (cal-tex-hspace "3.5cm")
1223 (cal-tex-e-makebox)
1224 (cal-tex-hfill)
1225 (cal-tex-b-makebox "4cm" "r")
1226 (cal-tex-bf (calendar-day-name date))
1227 (cal-tex-e-makebox)
1228 (cal-tex-nl)
1229 (cal-tex-hspace ".4cm")
1230 (cal-tex-rule "0mm" "16.1cm" "1mm")
1231 (cal-tex-nl ".1cm")
1232 (calendar-for-loop i from cal-tex-daily-start to cal-tex-daily-end do
1233 (cal-tex-cmd "\\noindent")
1234 (setq hour (if cal-tex-24
1235 i
1236 (mod i 12)))
1237 (if (= 0 hour) (setq hour 12))
1238 (cal-tex-b-makebox "1cm" "c")
1239 (cal-tex-arg (number-to-string hour))
1240 (cal-tex-e-makebox)
1241 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1242 (cal-tex-nl ".2cm")
1243 (cal-tex-b-makebox "1cm" "c")
1244 (cal-tex-arg "$\\diamond$" )
1245 (cal-tex-e-makebox)
1246 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1247 (cal-tex-nl ".2cm"))
1248 (cal-tex-hfill)
1249 (insert (cal-tex-mini-calendar
1250 (extract-calendar-month (cal-tex-previous-month date))
1251 (extract-calendar-year (cal-tex-previous-month date))
1252 "lastmonth" "1.1in" "1in"))
1253 (insert (cal-tex-mini-calendar
1254 (extract-calendar-month date)
1255 (extract-calendar-year date)
1256 "thismonth" "1.1in" "1in"))
1257 (insert (cal-tex-mini-calendar
1258 (extract-calendar-month (cal-tex-next-month date))
1259 (extract-calendar-year (cal-tex-next-month date))
1260 "nextmonth" "1.1in" "1in"))
1261 (insert "\\hbox to \\textwidth{")
1262 (cal-tex-hfill)
1263 (insert "\\lastmonth")
1264 (cal-tex-hfill)
1265 (insert "\\thismonth")
1266 (cal-tex-hfill)
1267 (insert "\\nextmonth")
1268 (cal-tex-hfill)
1269 (insert "}")
1270 (cal-tex-banner "end of cal-tex-daily-page")))
1271
1272 ;;;
1273 ;;; Mini calendars
1274 ;;;
1275
1276 (defun cal-tex-mini-calendar (month year name width height &optional size)
1277 "Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT.
1278 Optional SIZE gives the point size; scriptsize is the default,"
1279 (let* ((blank-days;; at start of month
1280 (mod
1281 (- (calendar-day-of-week (list month 1 year))
1282 calendar-week-start-day)
1283 7))
1284 (last (calendar-last-day-of-month month year))
1285 (str (concat "\\def\\" name "{\\hbox to" width "{%\n"
1286 "\\vbox to" height "{%\n"
1287 "\\vfil \\hbox to" width "{%\n"
1288 "\\hfil\\"
1289 (if size size "scriptsize")
1290 "\\begin{tabular}"
1291 "{@{\\hspace{1mm}}r@{\\hspace{1mm}}r@{\\hspace{1mm}}r@{\\hspace{1mm}}"
1292 "r@{\\hspace{1mm}}r@{\\hspace{1mm}}r@{\\hspace{1mm}}r@{\\hspace{1mm}}}%\n"
1293 "\\multicolumn{7}{c}{"
1294 (calendar-month-name month)
1295 " "
1296 (int-to-string year)
1297 "}\\\\[0.5mm]\n")))
1298 (calendar-for-loop i from 0 to 6 do
1299 (setq str (concat str
1300 (substring (aref calendar-day-name-array
1301 (mod (+ calendar-week-start-day i) 7))
1302 0 2)
1303 (if (/= i 6)
1304 " & "
1305 "\\\\[0.5mm]\n"))))
1306 (calendar-for-loop i from 1 to blank-days do
1307 (setq str (concat str " & ")))
1308 (calendar-for-loop i from 1 to last do
1309 (setq str (concat str (int-to-string i)))
1310 (setq str (concat str (if (zerop (mod (+ i blank-days) 7))
1311 (if (/= i last) "\\\\[0.5mm]\n" "")
1312 " & "))))
1313 (setq str (concat str "\n\\end{tabular}\\hfil}\\vfil}}}%\n"))
1314 str))
1315
1316 ;;;
1317 ;;; Various calendar functions
1318 ;;;
1319
1320 (defun cal-tex-incr-date (date &optional n)
1321 "The date of the day following DATE.
1322 If optional N is given, the date of N days after DATE."
1323 (calendar-gregorian-from-absolute
1324 (+ (if n n 1) (calendar-absolute-from-gregorian date))))
1325
1326 (defun cal-tex-latexify-list (date-list date &optional separator)
1327 "Return string with concatenated, LaTeXified entries in DATE_LIST for DATE.
1328 Use double backslash as a separator unless optional SEPARATOR is given."
1329 (mapconcat '(lambda (x) (cal-tex-LaTeXify-string x))
1330 (let ((result)
1331 (p date-list))
1332 (while p
1333 (and (car (car p))
1334 (calendar-date-equal date (car (car p)))
1335 (setq result (append (cdr (car p)) result)))
1336 (setq p (cdr p)))
1337 result)
1338 (if separator separator "\\\\")))
1339
1340 (defun cal-tex-previous-month (date)
1341 "Return the date of the first day in the month previous to DATE."
1342 (let* ((month (extract-calendar-month date))
1343 (year (extract-calendar-year date)))
1344 (increment-calendar-month month year -1)
1345 (list month 1 year)))
1346
1347 (defun cal-tex-next-month (date)
1348 "Return the date of the first day in the month following DATE."
1349 (let* ((month (extract-calendar-month date))
1350 (year (extract-calendar-year date)))
1351 (increment-calendar-month month year 1)
1352 (list month 1 year)))
1353
1354 ;;;
1355 ;;; LaTeX Code
1356 ;;;
1357
1358 (defun cal-tex-end-document ()
1359 "Finish the LaTeX document.
1360 Insert the trailer to LaTeX document, pop to LaTeX buffer, add
1361 informative header, and run HOOK."
1362 (cal-tex-e-document)
1363 (latex-mode)
1364 (pop-to-buffer cal-tex-buffer)
1365 (goto-char (point-min))
1366 (cal-tex-comment " This buffer was produced by cal-tex.el.")
1367 (cal-tex-comment " To print a calendar, type")
1368 (cal-tex-comment " M-x tex-buffer RET")
1369 (cal-tex-comment " M-x tex-print RET")
1370 (goto-char (point-min)))
1371
1372 (defun cal-tex-insert-preamble (weeks landscape size &optional append)
1373 "Initialize the output buffer.
1374 Select the output buffer, and insert the preamble for a calendar of
1375 WEEKS weeks. Insert code for landscape mode if LANDSCAPE is true.
1376 Use pointsize SIZE. Optional argument APPEND, if t, means add to end of
1377 without erasing current contents."
1378 (let ((width "18cm")
1379 (height "24cm"))
1380 (if landscape
1381 (progn
1382 (setq width "24cm")
1383 (setq height "18cm")))
1384 (if (not append)
1385 (progn
1386 (cal-tex-preamble size)
1387 (if (not landscape)
1388 (progn
1389 (cal-tex-cmd "\\oddsidemargin -1.75cm")
1390 (cal-tex-cmd "\\def\\holidaymult{.06}"))
1391 (cal-tex-cmd "\\special{landscape}")
1392 (cal-tex-cmd "\\textwidth 9.5in")
1393 (cal-tex-cmd "\\textheight 7in")
1394 (cal-tex-comment)
1395 (cal-tex-cmd "\\def\\holidaymult{.08}"))
1396 (cal-tex-cmd cal-tex-caldate)
1397 (cal-tex-cmd cal-tex-myday)
1398 (cal-tex-b-document)
1399 (cal-tex-cmd "\\pagestyle{empty}")))
1400 (cal-tex-cmd "\\setlength{\\cellwidth}" width)
1401 (insert (format "\\setlength{\\cellwidth}{%f\\cellwidth}\n"
1402 (/ 1.1 (length cal-tex-which-days))))
1403 (cal-tex-cmd "\\setlength{\\cellheight}" height)
1404 (insert (format "\\setlength{\\cellheight}{%f\\cellheight}\n"
1405 (/ 1.0 weeks)))
1406 (cal-tex-cmd "\\ \\par")
1407 (cal-tex-vspace "-3cm")))
1408
1409 (defvar cal-tex-LaTeX-subst-list
1410 '(("\"". "``")
1411 ("\"". "''");; Quote changes meaning when list is reversed.
1412 ("@" . "\\verb|@|")
1413 ("&" . "\\&")
1414 ("%" . "\\%")
1415 ("$" . "\\$")
1416 ("#" . "\\#")
1417 ("_" . "\\_")
1418 ("{" . "\\{")
1419 ("}" . "\\}")
1420 ("<" . "$<$")
1421 (">" . "$>$")
1422 ("\n" . "\\ \\\\")) ;\\ needed for e.g \begin{center}\n AA\end{center}
1423 "List of symbols and their replacements.")
1424
1425 (defun cal-tex-LaTeXify-string (string)
1426 "Protect special characters in STRING from LaTeX."
1427 (if (not string)
1428 ""
1429 (let ((head "")
1430 (tail string)
1431 (list cal-tex-LaTeX-subst-list))
1432 (while (not (string-equal tail ""))
1433 (let* ((ch (substring tail 0 1))
1434 (pair (assoc ch list)))
1435 (if (and pair (string-equal ch "\""))
1436 (setq list (reverse list)));; Quote changes meaning each time.
1437 (setq tail (substring tail 1))
1438 (setq head (concat head (if pair (cdr pair) ch)))))
1439 head)))
1440
1441 (defun cal-tex-hfill () "Insert hfill." (insert "\\hfill"))
1442
1443 (defun cal-tex-newpage () "Insert newpage." (insert "\\newpage%\n"))
1444
1445 (defun cal-tex-noindent () "Insert noindent." (insert "\\noindent"))
1446
1447 (defun cal-tex-vspace (space)
1448 "Insert vspace command to move SPACE vertically."
1449 (insert "\\vspace*{" space "}")
1450 (cal-tex-comment))
1451
1452 (defun cal-tex-hspace (space)
1453 "Insert hspace command to move SPACE horizontally."
1454 (insert "\\hspace*{" space "}")
1455 (cal-tex-comment))
1456
1457 (defun cal-tex-comment (&optional comment)
1458 "Insert % at end of line, include COMMENT if present, and move
1459 to next line."
1460 (insert "% ")
1461 (if comment
1462 (insert comment))
1463 (insert "\n"))
1464
1465 (defun cal-tex-banner (comment)
1466 "Insert the COMMENT separated by blank lines."
1467 (cal-tex-comment)
1468 (cal-tex-comment)
1469 (cal-tex-comment (concat "\t\t\t" comment))
1470 (cal-tex-comment))
1471
1472
1473 (defun cal-tex-nl (&optional skip comment)
1474 "End a line with \\. If SKIP, then add that much spacing.
1475 Add COMMENT if present"
1476 (insert "\\\\")
1477 (if skip
1478 (insert "[" skip "]"))
1479 (cal-tex-comment comment))
1480
1481 (defun cal-tex-arg (&optional text)
1482 "Insert optional TEXT surrounded by braces."
1483 (insert "{")
1484 (if text (insert text))
1485 (insert "}"))
1486
1487 (defun cal-tex-cmd (cmd &optional arg)
1488 "Insert LaTeX CMD, with optional ARG, and end with %"
1489 (insert cmd)
1490 (cal-tex-arg arg)
1491 (cal-tex-comment))
1492
1493 ;;;
1494 ;;; Environments
1495 ;;;
1496
1497 (defun cal-tex-b-document ()
1498 "Insert beginning of document."
1499 (cal-tex-cmd "\\begin{document}"))
1500
1501 (defun cal-tex-e-document ()
1502 "Insert end of document."
1503 (cal-tex-cmd "\\end{document}"))
1504
1505 (defun cal-tex-b-center ()
1506 "Insert beginning of centered block."
1507 (cal-tex-cmd "\\begin{center}"))
1508
1509 (defun cal-tex-e-center ()
1510 "Insert end of centered block."
1511 (cal-tex-comment)
1512 (cal-tex-cmd "\\end{center}"))
1513
1514
1515 ;;;
1516 ;;; Boxes
1517 ;;;
1518
1519
1520 (defun cal-tex-b-parbox (position width)
1521 "Insert parbox with parameters POSITION and WIDTH."
1522 (insert "\\parbox[" position "]{" width "}{")
1523 (cal-tex-comment))
1524
1525 (defun cal-tex-e-parbox (&optional height)
1526 "Insert end of parbox. Force it to be a given HEIGHT."
1527 (cal-tex-comment)
1528 (if height
1529 (cal-tex-rule "0mm" "0mm" height))
1530 (insert "}")
1531 (cal-tex-comment "end parbox"))
1532
1533 (defun cal-tex-b-framebox ( width position )
1534 "Insert framebox with parameters WIDTH and POSITION (clr)."
1535 (insert "\\framebox[" width "][" position "]{" )
1536 (cal-tex-comment))
1537
1538 (defun cal-tex-e-framebox ()
1539 "Insert end of framebox."
1540 (cal-tex-comment)
1541 (insert "}")
1542 (cal-tex-comment "end framebox"))
1543
1544
1545 (defun cal-tex-b-makebox ( width position )
1546 "Insert makebox with parameters WIDTH and POSITION (clr)."
1547 (insert "\\makebox[" width "][" position "]{" )
1548 (cal-tex-comment))
1549
1550 (defun cal-tex-e-makebox ()
1551 "Insert end of makebox."
1552 (cal-tex-comment)
1553 (insert "}")
1554 (cal-tex-comment "end makebox"))
1555
1556
1557 (defun cal-tex-rule (lower width height)
1558 "Insert a rule with parameters LOWER WIDTH HEIGHT."
1559 (insert "\\rule[" lower "]{" width "}{" height "}"))
1560
1561 ;;;
1562 ;;; Fonts
1563 ;;;
1564
1565 (defun cal-tex-em (string)
1566 "Insert STRING in bf font."
1567 (insert "{\\em " string "}"))
1568
1569 (defun cal-tex-bf (string)
1570 "Insert STRING in bf font."
1571 (insert "{\\bf " string "}"))
1572
1573 (defun cal-tex-scriptsize (string)
1574 "Insert STRING in scriptsize font."
1575 (insert "{\\scriptsize " string "}"))
1576
1577 (defun cal-tex-huge (string)
1578 "Insert STRING in huge size."
1579 (insert "{\\huge " string "}"))
1580
1581 (defun cal-tex-Huge (string)
1582 "Insert STRING in Huge size."
1583 (insert "{\\Huge " string "}"))
1584
1585 (defun cal-tex-Huge-bf (string)
1586 "Insert STRING in Huge bf size."
1587 (insert "{\\Huge\\bf " string "}"))
1588
1589 (defun cal-tex-large (string)
1590 "Insert STRING in large size."
1591 (insert "{\\large " string "}"))
1592
1593 (defun cal-tex-large-bf (string)
1594 "Insert STRING in large bf size."
1595 (insert "{\\large\\bf " string "}"))
1596
1597 (provide 'cal-tex)
1598
1599 ;;; cal-tex.el ends here