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