comparison lisp/calendar/cal-tex.el @ 13195:b558ab9fbef4

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