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