]> code.delx.au - gnu-emacs/blob - lisp/calendar/cal-tex.el
cal-tex-cursor-week-at-a-glance small fixes
[gnu-emacs] / lisp / calendar / cal-tex.el
1 ;;; cal-tex.el --- calendar functions for printing calendars with LaTeX
2
3 ;; Copyright (C) 1995, 2001-2012 Free Software Foundation, Inc.
4
5 ;; Author: Steve Fisk <fisk@bowdoin.edu>
6 ;; Edward M. Reingold <reingold@cs.uiuc.edu>
7 ;; Maintainer: Glenn Morris <rgm@gnu.org>
8 ;; Keywords: calendar
9 ;; Human-Keywords: Calendar, LaTeX
10 ;; Package: calendar
11
12 ;; This file is part of GNU Emacs.
13
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
18
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
23
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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 ;; The user commands are:
33 ;; cal-tex-cursor-year
34 ;; cal-tex-cursor-year-landscape
35 ;; cal-tex-cursor-filofax-year
36 ;; cal-tex-cursor-month-landscape
37 ;; cal-tex-cursor-month
38 ;; cal-tex-cursor-week
39 ;; cal-tex-cursor-week2
40 ;; cal-tex-cursor-week-iso
41 ;; cal-tex-cursor-week-monday
42 ;; cal-tex-cursor-filofax-2week
43 ;; cal-tex-cursor-filofax-week
44 ;; cal-tex-cursor-filofax-daily
45 ;; cal-tex-cursor-day
46
47 ;; TO DO
48 ;;
49 ;; (*) Add holidays and diary entries to daily calendar.
50 ;;
51 ;; (*) Add diary entries to weekly calendar functions.
52 ;;
53 ;; (*) Make calendar styles for A4 paper.
54 ;;
55 ;; (*) Make monthly styles Filofax paper.
56
57 ;;; Code:
58
59 (require 'calendar)
60
61 ;;;
62 ;;; Customizable variables
63 ;;;
64
65 (defgroup calendar-tex nil
66 "Options for printing calendar with LaTeX."
67 :prefix "cal-tex-"
68 :group 'calendar)
69
70 (defcustom cal-tex-which-days '(0 1 2 3 4 5 6)
71 "The days of the week that are displayed on the portrait monthly calendar.
72 Sunday is 0, Monday is 1, and so on. The default is to print from Sunday to
73 Saturday. For example, use '(1 3 5) to only print Monday, Wednesday, Friday."
74 :type '(repeat integer)
75 :group 'calendar-tex)
76
77 (defcustom cal-tex-holidays t
78 "Non-nil means holidays are printed in the LaTeX calendars that support it.
79 Setting this to nil may speed up calendar generation."
80 :type 'boolean
81 :group 'calendar-tex)
82
83 (defcustom cal-tex-diary nil
84 "Non-nil means diary entries are printed in LaTeX calendars that support it.
85 At present, this only affects the monthly, filofax, and iso-week
86 calendars (i.e. not the yearly, plain weekly, or daily calendars).
87 Setting this to nil may speed up calendar generation."
88 :type 'boolean
89 :group 'calendar-tex)
90
91 (defcustom cal-tex-rules nil
92 "Non-nil means pages will be ruled in some LaTeX calendar styles.
93 At present, this only affects the daily filofax calendar."
94 :type 'boolean
95 :group 'calendar-tex)
96
97 (defcustom cal-tex-daily-string
98 '(let* ((year (calendar-extract-year date))
99 (day (calendar-day-number date))
100 (days-remaining (- (calendar-day-number (list 12 31 year)) day)))
101 (format "%d/%d" day days-remaining))
102 "Lisp expression giving the date format to use in the LaTeX calendars.
103 This should be an expression involving the variable `date'. When
104 this expression is called, `date' is a list of the form '(MONTH DAY YEAR)'.
105
106 The string resulting from evaluating this expression is placed at
107 the bottom center of each date in monthly calendars, next to the
108 date in the weekly calendars, and in the top center of daily calendars.
109
110 The default is ordinal day number of the year and the number of
111 days remaining. As an example, setting this to
112
113 '(calendar-hebrew-date-string date)
114
115 will put the Hebrew date at the bottom of each day."
116 :type 'sexp
117 :group 'calendar-tex)
118
119 (defcustom cal-tex-buffer "calendar.tex"
120 "The name for the output LaTeX calendar buffer."
121 :type 'string
122 :group 'calendar-tex)
123
124 (defcustom cal-tex-24 nil
125 "Non-nil means use a 24 hour clock in the daily calendar."
126 :type 'boolean
127 :group 'calendar-tex)
128
129 (defcustom cal-tex-daily-start 8
130 "The first hour of the daily LaTeX calendar page.
131 At present, this only affects `cal-tex-cursor-day'."
132 :type 'integer
133 :group 'calendar-tex)
134
135 (defcustom cal-tex-daily-end 20
136 "The last hour of the daily LaTeX calendar page.
137 At present, this only affects `cal-tex-cursor-day'."
138 :type 'integer
139 :group 'calendar-tex)
140
141 (defcustom cal-tex-preamble-extra nil
142 "A string giving extra LaTeX commands to insert in the calendar preamble.
143 For example, to include extra packages:
144 \"\\\\usepackage{foo}\\n\\\\usepackage{bar}\\n\"."
145 :type '(choice (const nil)
146 ;; An example to help people format things in custom.
147 (string :value "\\usepackage{foo}\n\\usepackage{bar}\n"))
148 :group 'calendar-tex
149 :version "22.1")
150
151 (defcustom cal-tex-hook nil
152 "List of functions called after any LaTeX calendar buffer is generated.
153 You can use this to do post-processing on the buffer. For example, to change
154 characters with diacritical marks to their LaTeX equivalents, use
155 (add-hook 'cal-tex-hook
156 (lambda () (iso-iso2tex (point-min) (point-max))))"
157 :type 'hook
158 :group 'calendar-tex)
159
160 (defcustom cal-tex-year-hook nil
161 "List of functions called after a LaTeX year calendar buffer is generated."
162 :type 'hook
163 :group 'calendar-tex)
164
165 (defcustom cal-tex-month-hook nil
166 "List of functions called after a LaTeX month calendar buffer is generated."
167 :type 'hook
168 :group 'calendar-tex)
169
170 (defcustom cal-tex-week-hook nil
171 "List of functions called after a LaTeX week calendar buffer is generated."
172 :type 'hook
173 :group 'calendar-tex)
174
175 (defcustom cal-tex-daily-hook nil
176 "List of functions called after a LaTeX daily calendar buffer is generated."
177 :type 'hook
178 :group 'calendar-tex)
179
180 ;;;
181 ;;; Definitions for LaTeX code
182 ;;;
183
184 (defconst cal-tex-day-prefix "\\caldate{%s}{%s}"
185 "The initial LaTeX code for a day.
186 The holidays, diary entries, bottom string, and the text follow.")
187
188 (defconst cal-tex-day-name-format "\\myday{%s}%%"
189 "The format for LaTeX code for a day name.
190 The names are taken from `calendar-day-name-array'.")
191
192 (defconst cal-tex-cal-one-month
193 "\\def\\calmonth#1#2%
194 {\\begin{center}%
195 \\Huge\\bf\\uppercase{#1} #2 \\\\[1cm]%
196 \\end{center}}%
197 \\vspace*{-1.5cm}%
198 %
199 "
200 "LaTeX code for the month header, for a single month calendar.")
201
202 (defconst cal-tex-cal-multi-month
203 "\\def\\calmonth#1#2#3#4%
204 {\\begin{center}%
205 \\Huge\\bf #1 #2---#3 #4\\\\[1cm]%
206 \\end{center}}%
207 \\vspace*{-1.5cm}%
208 %
209 "
210 "LaTeX code for the month header, for a multi-month calendar.")
211
212 (defconst cal-tex-myday
213 "\\renewcommand{\\myday}[1]%
214 {\\makebox[\\cellwidth]{\\hfill\\large\\bf#1\\hfill}}
215 %
216 "
217 "LaTeX code for a day heading.")
218
219 (defconst cal-tex-caldate
220 "\\fboxsep=0pt
221 \\long\\def\\caldate#1#2#3#4#5#6{%
222 \\fbox{\\hbox to\\cellwidth{%
223 \\vbox to\\cellheight{%
224 \\hbox to\\cellwidth{%
225 {\\hspace*{1mm}\\Large \\bf \\strut #2}\\hspace{.05\\cellwidth}%
226 \\raisebox{\\holidaymult\\cellheight}%
227 {\\parbox[t]{.75\\cellwidth}{\\tiny \\raggedright #4}}}
228 \\hbox to\\cellwidth{%
229 \\hspace*{1mm}\\parbox{.95\\cellwidth}{\\tiny \\raggedright #3}}
230 \\hspace*{1mm}%
231 \\hbox to\\cellwidth{#6}%
232 \\vfill%
233 \\hbox to\\cellwidth{\\hfill \\tiny #5 \\hfill}%
234 \\vskip 1.4pt}%
235 \\hskip -0.4pt}}}
236 "
237 "LaTeX code to insert one box with date info in calendar.
238 This definition is the heart of the calendar!")
239
240 (autoload 'holiday-in-range "holidays")
241
242 (define-obsolete-function-alias 'cal-tex-list-holidays 'holiday-in-range "24.3")
243
244 (autoload 'diary-list-entries "diary-lib")
245
246 (defun cal-tex-list-diary-entries (d1 d2)
247 "Generate a list of all diary-entries from absolute date D1 to D2."
248 (let (diary-list-include-blanks)
249 (diary-list-entries (calendar-gregorian-from-absolute d1)
250 (1+ (- d2 d1)) t)))
251
252 (defun cal-tex-preamble (&optional args)
253 "Insert the LaTeX calendar preamble into `cal-tex-buffer'.
254 Preamble includes initial definitions for various LaTeX commands.
255 Optional string ARGS are included as options for the article document class."
256 ;; FIXME use generate-new-buffer, and adjust cal-tex-end-document.
257 (set-buffer (get-buffer-create cal-tex-buffer))
258 (insert (format "\\documentclass%s{article}\n"
259 (if (stringp args)
260 (format "[%s]" args)
261 "")))
262 (if (stringp cal-tex-preamble-extra)
263 (insert cal-tex-preamble-extra "\n"))
264 (insert "\\hbadness 20000
265 \\hfuzz=1000pt
266 \\vbadness 20000
267 \\lineskip 0pt
268 \\marginparwidth 0pt
269 \\oddsidemargin -2cm
270 \\evensidemargin -2cm
271 \\marginparsep 0pt
272 \\topmargin 0pt
273 \\textwidth 7.5in
274 \\textheight 9.5in
275 \\newlength{\\cellwidth}
276 \\newlength{\\cellheight}
277 \\newlength{\\boxwidth}
278 \\newlength{\\boxheight}
279 \\newlength{\\cellsize}
280 \\newcommand{\\myday}[1]{}
281 \\newcommand{\\caldate}[6]{}
282 \\newcommand{\\nocaldate}[6]{}
283 \\newcommand{\\calsmall}[6]{}
284 %
285 "))
286
287 ;;;
288 ;;; Yearly calendars
289 ;;;
290
291 ;;;###cal-autoload
292 (defun cal-tex-cursor-year (&optional n event)
293 "Make a buffer with LaTeX commands for the year cursor is on.
294 Optional prefix argument N specifies number of years.
295 Optional EVENT indicates a buffer position to use instead of point."
296 (interactive (list (prefix-numeric-value current-prefix-arg)
297 last-nonmenu-event))
298 (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t event))
299 (or n 1)))
300
301 ;;;###cal-autoload
302 (defun cal-tex-cursor-year-landscape (&optional n event)
303 "Make a buffer with LaTeX commands for the year cursor is on.
304 Optional prefix argument N specifies number of years.
305 Optional EVENT indicates a buffer position to use instead of point."
306 (interactive (list (prefix-numeric-value current-prefix-arg)
307 last-nonmenu-event))
308 (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t event))
309 (or n 1) t))
310
311 (defun cal-tex-year (year n &optional landscape)
312 "Make a one page yearly calendar of YEAR; do this for N years.
313 There are four rows of three months each, unless optional
314 LANDSCAPE is non-nil, in which case the calendar is printed in
315 landscape mode with three rows of four months each."
316 (cal-tex-insert-preamble 1 landscape "12pt")
317 (if landscape
318 (cal-tex-vspace "-.6cm")
319 (cal-tex-vspace "-3.1cm"))
320 (dotimes (j n)
321 (insert "\\vfill%\n")
322 (cal-tex-b-center)
323 (cal-tex-Huge (number-to-string year))
324 (cal-tex-e-center)
325 (cal-tex-vspace "1cm")
326 (cal-tex-b-center)
327 (cal-tex-b-parbox "l" (if landscape "5.9in" "4.3in"))
328 (insert "\n")
329 (cal-tex-noindent)
330 (cal-tex-nl)
331 (dotimes (i 12)
332 (insert (cal-tex-mini-calendar (1+ i) year "month" "1.1in" "1in"))
333 (insert "\\month")
334 (cal-tex-hspace "0.5in")
335 (if (zerop (mod (1+ i) (if landscape 4 3)))
336 (cal-tex-nl "0.5in")))
337 (cal-tex-e-parbox)
338 (cal-tex-e-center)
339 (insert "\\vfill%\n")
340 (setq year (1+ year))
341 (if (= j (1- n))
342 (cal-tex-end-document)
343 (cal-tex-newpage))
344 (run-hooks 'cal-tex-year-hook))
345 (run-hooks 'cal-tex-hook))
346
347 ;;;###cal-autoload
348 (defun cal-tex-cursor-filofax-year (&optional n event)
349 "Make a Filofax one page yearly calendar of year indicated by cursor.
350 Optional prefix argument N specifies number of years.
351 Optional EVENT indicates a buffer position to use instead of point."
352 (interactive (list (prefix-numeric-value current-prefix-arg)
353 last-nonmenu-event))
354 (or n (setq n 1))
355 (let ((year (calendar-extract-year (calendar-cursor-to-date t event))))
356 (cal-tex-preamble "twoside")
357 (cal-tex-cmd "\\textwidth 3.25in")
358 (cal-tex-cmd "\\textheight 6.5in")
359 (cal-tex-cmd "\\oddsidemargin 1.675in")
360 (cal-tex-cmd "\\evensidemargin 1.675in")
361 (cal-tex-cmd "\\topmargin 0pt")
362 (cal-tex-cmd "\\headheight -0.875in")
363 (cal-tex-cmd "\\fboxsep 0.5mm")
364 (cal-tex-cmd "\\pagestyle{empty}")
365 (cal-tex-b-document)
366 (cal-tex-cmd "\\vspace*{0.25in}")
367 (dotimes (j n)
368 (insert (format "\\hfil \\textbf{\\Large %s} \\hfil\\\\\n" year))
369 (cal-tex-b-center)
370 (cal-tex-b-parbox "l" "\\textwidth")
371 (insert "\n")
372 (cal-tex-noindent)
373 (cal-tex-nl)
374 (let ((month-names; don't use default in case user changed it
375 ;; These are only used to define the command names, not
376 ;; the names of the months they insert.
377 ["January" "February" "March" "April" "May" "June"
378 "July" "August" "September" "October" "November" "December"]))
379 (dotimes (i 12)
380 (insert (cal-tex-mini-calendar (1+ i) year (aref month-names i)
381 "1in" ".9in" "tiny" "0.6mm"))))
382 (insert
383 "\\noindent\\fbox{\\January}\\fbox{\\February}\\fbox{\\March}\\\\
384 \\noindent\\fbox{\\April}\\fbox{\\May}\\fbox{\\June}\\\\
385 \\noindent\\fbox{\\July}\\fbox{\\August}\\fbox{\\September}\\\\
386 \\noindent\\fbox{\\October}\\fbox{\\November}\\fbox{\\December}
387 ")
388 (cal-tex-e-parbox)
389 (cal-tex-e-center)
390 (setq year (1+ year))
391 (if (= j (1- n))
392 (cal-tex-end-document)
393 (cal-tex-newpage)
394 (cal-tex-cmd "\\vspace*{0.25in}"))
395 (run-hooks 'cal-tex-year-hook))
396 (run-hooks 'cal-tex-hook)))
397
398 ;;;
399 ;;; Monthly calendars
400 ;;;
401
402 ;;;###cal-autoload
403 (defun cal-tex-cursor-month-landscape (&optional n event)
404 "Make a LaTeX calendar buffer for the month the cursor is on.
405 Optional prefix argument N specifies number of months to be
406 produced (default 1). The output is in landscape format, one
407 month to a page. It shows holiday and diary entries if
408 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
409 Optional EVENT indicates a buffer position to use instead of point."
410 (interactive (list (prefix-numeric-value current-prefix-arg)
411 last-nonmenu-event))
412 (or n (setq n 1))
413 (let* ((date (calendar-cursor-to-date t event))
414 (month (calendar-extract-month date))
415 (year (calendar-extract-year date))
416 (end-month month)
417 (end-year year)
418 (cal-tex-which-days '(0 1 2 3 4 5 6))
419 (d1 (calendar-absolute-from-gregorian (list month 1 year)))
420 (d2 (progn
421 (calendar-increment-month end-month end-year (1- n))
422 (calendar-absolute-from-gregorian
423 (list end-month
424 (calendar-last-day-of-month end-month end-year)
425 end-year))))
426 (diary-list (if cal-tex-diary (cal-tex-list-diary-entries d1 d2)))
427 (holidays (if cal-tex-holidays (holiday-in-range d1 d2)))
428 other-month other-year small-months-at-start)
429 (cal-tex-insert-preamble (cal-tex-number-weeks month year 1) t "12pt")
430 (cal-tex-cmd cal-tex-cal-one-month)
431 (dotimes (i n)
432 (setq other-month month
433 other-year year)
434 (calendar-increment-month other-month other-year -1)
435 (insert (cal-tex-mini-calendar other-month other-year "lastmonth"
436 "\\cellwidth" "\\cellheight"))
437 (calendar-increment-month other-month other-year 2)
438 (insert (cal-tex-mini-calendar other-month other-year "nextmonth"
439 "\\cellwidth" "\\cellheight"))
440 (cal-tex-insert-month-header 1 month year month year)
441 (cal-tex-insert-day-names)
442 (cal-tex-nl ".2cm")
443 (if (setq small-months-at-start
444 (< 1 (mod (- (calendar-day-of-week (list month 1 year))
445 calendar-week-start-day)
446 7)))
447 (insert "\\lastmonth\\nextmonth\\hspace*{-2\\cellwidth}"))
448 (cal-tex-insert-blank-days month year cal-tex-day-prefix)
449 (cal-tex-insert-days month year diary-list holidays
450 cal-tex-day-prefix)
451 (cal-tex-insert-blank-days-at-end month year cal-tex-day-prefix)
452 (if (and (not small-months-at-start)
453 (< 1 (mod (- (1- calendar-week-start-day)
454 (calendar-day-of-week
455 (list month
456 (calendar-last-day-of-month month year)
457 year)))
458 7)))
459 (insert "\\vspace*{-\\cellwidth}\\hspace*{-2\\cellwidth}"
460 "\\lastmonth\\nextmonth%
461 "))
462 (unless (= i (1- n))
463 (run-hooks 'cal-tex-month-hook)
464 (cal-tex-newpage)
465 (calendar-increment-month month year 1)
466 (cal-tex-vspace "-2cm")
467 (cal-tex-insert-preamble
468 (cal-tex-number-weeks month year 1) t "12pt" t))))
469 (cal-tex-end-document)
470 (run-hooks 'cal-tex-hook))
471
472 ;;;###cal-autoload
473 (defun cal-tex-cursor-month (&optional n event)
474 "Make a LaTeX calendar buffer for the month the cursor is on.
475 Optional prefix argument N specifies number of months to be
476 produced (default 1). The calendar is condensed onto one page.
477 It shows holiday and diary entries if `cal-tex-holidays' and
478 `cal-tex-diary', respectively, are non-nil. Optional EVENT
479 indicates a buffer position to use instead of point."
480 (interactive (list (prefix-numeric-value current-prefix-arg)
481 last-nonmenu-event))
482 (or n (setq n 1))
483 (let* ((date (calendar-cursor-to-date t event))
484 (month (calendar-extract-month date))
485 (year (calendar-extract-year date))
486 (end-month month)
487 (end-year year)
488 ;; FIXME -landscape sets cal-tex-which-days?
489 (d1 (calendar-absolute-from-gregorian (list month 1 year)))
490 (d2 (progn
491 (calendar-increment-month end-month end-year (1- n))
492 (calendar-absolute-from-gregorian
493 (list end-month
494 (calendar-last-day-of-month end-month end-year)
495 end-year))))
496 (diary-list (if cal-tex-diary (cal-tex-list-diary-entries d1 d2)))
497 (holidays (if cal-tex-holidays (holiday-in-range d1 d2))))
498 (cal-tex-insert-preamble (cal-tex-number-weeks month year n) nil "12pt")
499 (if (> n 1)
500 (cal-tex-cmd cal-tex-cal-multi-month)
501 (cal-tex-cmd cal-tex-cal-one-month))
502 (cal-tex-insert-month-header n month year end-month end-year)
503 (cal-tex-insert-day-names)
504 (cal-tex-nl ".2cm")
505 (cal-tex-insert-blank-days month year cal-tex-day-prefix)
506 (dotimes (_idummy n)
507 (cal-tex-insert-days month year diary-list holidays cal-tex-day-prefix)
508 (when (= (calendar-week-end-day)
509 (calendar-day-of-week
510 (list month
511 (calendar-last-day-of-month month year)
512 year))) ; last day of month was last day of week
513 (cal-tex-hfill)
514 (cal-tex-nl))
515 (calendar-increment-month month year 1))
516 (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix))
517 (cal-tex-end-document)
518 (run-hooks 'cal-tex-hook))
519
520 (defun cal-tex-insert-days (month year diary-list holidays day-format)
521 "Insert LaTeX commands for a range of days in monthly calendars.
522 LaTeX commands are inserted for the days of the MONTH in YEAR.
523 Diary entries on DIARY-LIST are included. Holidays on HOLIDAYS
524 are included. Each day is formatted using format DAY-FORMAT."
525 (let ((blank-days ; at start of month
526 (mod
527 (- (calendar-day-of-week (list month 1 year))
528 calendar-week-start-day)
529 7))
530 (last (calendar-last-day-of-month month year))
531 date j)
532 (dotimes (i last)
533 (setq j (1+ i) ; 1-last, incl
534 date (list month j year))
535 (when (memq (calendar-day-of-week date) cal-tex-which-days)
536 (insert (format day-format (cal-tex-month-name month) j))
537 (cal-tex-arg (cal-tex-latexify-list diary-list date))
538 (cal-tex-arg (cal-tex-latexify-list holidays date))
539 (cal-tex-arg (eval cal-tex-daily-string))
540 (cal-tex-arg)
541 (cal-tex-comment))
542 (when (and (zerop (mod (+ j blank-days) 7))
543 (/= j last))
544 (cal-tex-hfill)
545 (cal-tex-nl)))))
546
547 (defun cal-tex-insert-day-names ()
548 "Insert the names of the days at top of a monthly calendar."
549 (let (j)
550 (dotimes (i 7)
551 (if (memq (setq j (mod (+ calendar-week-start-day i) 7))
552 cal-tex-which-days)
553 (insert (format cal-tex-day-name-format
554 (cal-tex-LaTeXify-string
555 (aref calendar-day-name-array j)))))
556 (cal-tex-comment))))
557
558 (defun cal-tex-insert-month-header (n month year end-month end-year)
559 "Create a title for a calendar.
560 A title is inserted for a calendar with N months starting with
561 MONTH YEAR and ending with END-MONTH END-YEAR."
562 (let ((month-name (cal-tex-month-name month))
563 (end-month-name (cal-tex-month-name end-month)))
564 (if (= 1 n)
565 (insert (format "\\calmonth{%s}{%s}\n\\vspace*{-0.5cm}"
566 month-name year) )
567 (insert (format "\\calmonth{%s}{%s}{%s}{%s}\n\\vspace*{-0.5cm}"
568 month-name year end-month-name end-year))))
569 (cal-tex-comment))
570
571 (defun cal-tex-insert-blank-days (month year day-format)
572 "Insert code for initial days not in calendar.
573 Insert LaTeX code for the blank days at the beginning of the MONTH in
574 YEAR. The entry is formatted using DAY-FORMAT. If the entire week is
575 blank, no days are inserted."
576 (if (cal-tex-first-blank-p month year)
577 (let ((blank-days ; at start of month
578 (mod
579 (- (calendar-day-of-week (list month 1 year))
580 calendar-week-start-day)
581 7)))
582 (dotimes (i blank-days)
583 (if (memq (mod (+ calendar-week-start-day i) 7) cal-tex-which-days)
584 (insert (format day-format " " " ") "{}{}{}{}%\n"))))))
585
586 (defun cal-tex-insert-blank-days-at-end (month year day-format)
587 "Insert code for final days not in calendar.
588 Insert LaTeX code for the blank days at the end of the MONTH in YEAR.
589 The entry is formatted using DAY-FORMAT."
590 (if (cal-tex-last-blank-p month year)
591 (let* ((last-day (calendar-last-day-of-month month year))
592 (blank-days ; at end of month
593 (mod
594 (- (calendar-day-of-week (list month last-day year))
595 calendar-week-start-day)
596 7))
597 (i blank-days))
598 (while (<= (setq i (1+ i)) 6)
599 (if (memq (mod (+ calendar-week-start-day i) 7) cal-tex-which-days)
600 (insert (format day-format "" "") "{}{}{}{}%\n"))))))
601
602 (defun cal-tex-first-blank-p (month year)
603 "Determine if any days of the first week will be printed.
604 Return t if there will there be any days of the first week printed
605 in the calendar starting in MONTH YEAR."
606 ;; Check days 1-7 of the month, until we find the last day of the week.
607 (catch 'found
608 (let (dow)
609 (dotimes (i 7)
610 (if (memq (setq dow (calendar-day-of-week (list month (1+ i) year)))
611 cal-tex-which-days)
612 (throw 'found t)
613 (if (= dow (calendar-week-end-day)) (throw 'found nil)))))))
614
615 (defun cal-tex-last-blank-p (month year)
616 "Determine if any days of the last week will be printed.
617 Return t if there will there be any days of the last week printed
618 in the calendar starting in MONTH YEAR."
619 ;; Check backwards from the last day of the month, until we find the
620 ;; start of the last week in the month.
621 (catch 'found
622 (let ((last-day (calendar-last-day-of-month month year))
623 dow)
624 (dotimes (i 7)
625 (if (memq (setq dow (calendar-day-of-week
626 (list month (- last-day i) year)))
627 cal-tex-which-days)
628 (throw 'found t)
629 (if (= dow calendar-week-start-day) (throw 'found nil)))))))
630
631 (defun cal-tex-number-weeks (month year n)
632 "Determine the number of weeks in a range of dates.
633 Compute the number of weeks in the calendar starting with MONTH and YEAR,
634 and lasting N months, including only the days in WHICH-DAYS. As it stands,
635 this is only an upper bound."
636 (let ((d (list month 1 year)))
637 (calendar-increment-month month year (1- n))
638 (/ (- (calendar-dayname-on-or-before
639 calendar-week-start-day
640 (+ 7 (calendar-absolute-from-gregorian
641 (list month (calendar-last-day-of-month month year) year))))
642 (calendar-dayname-on-or-before
643 calendar-week-start-day
644 (calendar-absolute-from-gregorian d)))
645 7)))
646
647 ;;;
648 ;;; Weekly calendars
649 ;;;
650
651 (defconst cal-tex-LaTeX-hourbox
652 "\\newcommand{\\hourbox}[2]%
653 {\\makebox[2em]{\\rule{0cm}{#2ex}#1}\\rule{3in}{.15mm}}\n"
654 "One hour and a line on the right.")
655
656 ;; TODO cal-tex-diary-support.
657 ;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
658 ;;;###cal-autoload
659 (defun cal-tex-cursor-week (&optional n event)
660 "Make a LaTeX calendar buffer for a two-page one-week calendar.
661 It applies to the week that point is in. The optional prefix
662 argument N specifies number of weeks (default 1). The calendar
663 shows holidays if `cal-tex-holidays' is non-nil (note that diary
664 entries are not shown). The calendar shows the hours 8-12am, 1-5pm."
665 (interactive (list (prefix-numeric-value current-prefix-arg)
666 last-nonmenu-event))
667 (or n (setq n 1))
668 (let* ((date (calendar-gregorian-from-absolute
669 (calendar-dayname-on-or-before
670 calendar-week-start-day
671 (calendar-absolute-from-gregorian
672 (calendar-cursor-to-date t event)))))
673 (month (calendar-extract-month date))
674 (year (calendar-extract-year date))
675 (d1 (calendar-absolute-from-gregorian date))
676 (d2 (+ (* 7 n) d1))
677 (holidays (if cal-tex-holidays
678 (holiday-in-range d1 d2))))
679 (cal-tex-preamble "11pt")
680 (cal-tex-cmd "\\textwidth 6.5in")
681 (cal-tex-cmd "\\textheight 10.5in")
682 (cal-tex-cmd "\\oddsidemargin 0in")
683 (cal-tex-cmd "\\evensidemargin 0in")
684 (insert cal-tex-LaTeX-hourbox)
685 (cal-tex-b-document)
686 (cal-tex-cmd "\\pagestyle{empty}")
687 (dotimes (i n)
688 (cal-tex-vspace "-1.5in")
689 (cal-tex-b-center)
690 (cal-tex-Huge-bf (format "\\uppercase{%s}"
691 (cal-tex-month-name month)))
692 (cal-tex-hspace "2em")
693 (cal-tex-Huge-bf (number-to-string year))
694 (cal-tex-nl ".5cm")
695 (cal-tex-e-center)
696 (cal-tex-hspace "-.2in")
697 (cal-tex-b-parbox "l" "7in")
698 (dotimes (_jdummy 7)
699 (cal-tex-week-hours date holidays "3.1")
700 (setq date (cal-tex-incr-date date)))
701 (cal-tex-e-parbox)
702 (setq month (calendar-extract-month date)
703 year (calendar-extract-year date))
704 (unless (= i (1- n))
705 (run-hooks 'cal-tex-week-hook)
706 (cal-tex-newpage)))
707 (cal-tex-end-document)
708 (run-hooks 'cal-tex-hook)))
709
710 ;; TODO cal-tex-diary support.
711 ;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
712 ;;;###cal-autoload
713 (defun cal-tex-cursor-week2 (&optional n event)
714 "Make a LaTeX calendar buffer for a two-page one-week calendar.
715 It applies to the week that point is in. Optional prefix
716 argument N specifies number of weeks (default 1). The calendar
717 shows holidays if `cal-tex-holidays' is non-nil (note that diary
718 entries are not shown). The calendar shows the hours 8-12am, 1-5pm.
719 Optional EVENT indicates a buffer position to use instead of point."
720 (interactive (list (prefix-numeric-value current-prefix-arg)
721 last-nonmenu-event))
722 (or n (setq n 1))
723 (let* ((date (calendar-gregorian-from-absolute
724 (calendar-dayname-on-or-before
725 calendar-week-start-day
726 (calendar-absolute-from-gregorian
727 (calendar-cursor-to-date t event)))))
728 (month (calendar-extract-month date))
729 (year (calendar-extract-year date))
730 (d1 (calendar-absolute-from-gregorian date))
731 (d2 (+ (* 7 n) d1))
732 (holidays (if cal-tex-holidays
733 (holiday-in-range d1 d2))))
734 (cal-tex-preamble "12pt")
735 (cal-tex-cmd "\\textwidth 6.5in")
736 (cal-tex-cmd "\\textheight 10.5in")
737 (cal-tex-cmd "\\oddsidemargin 0in")
738 (cal-tex-cmd "\\evensidemargin 0in")
739 (insert cal-tex-LaTeX-hourbox)
740 (cal-tex-b-document)
741 (cal-tex-cmd "\\pagestyle{empty}")
742 (dotimes (i n)
743 (cal-tex-vspace "-1.5in")
744 (cal-tex-b-center)
745 (cal-tex-Huge-bf (format "\\uppercase{%s}"
746 (cal-tex-month-name month)))
747 (cal-tex-hspace "2em")
748 (cal-tex-Huge-bf (number-to-string year))
749 (cal-tex-nl ".5cm")
750 (cal-tex-e-center)
751 (cal-tex-hspace "-.2in")
752 (cal-tex-b-parbox "l" "\\textwidth")
753 (dotimes (_jdummy 3)
754 (cal-tex-week-hours date holidays "5")
755 (setq date (cal-tex-incr-date date)))
756 (cal-tex-e-parbox)
757 (cal-tex-nl)
758 (insert (cal-tex-mini-calendar
759 (calendar-extract-month (cal-tex-previous-month date))
760 (calendar-extract-year (cal-tex-previous-month date))
761 "lastmonth" "1.1in" "1in"))
762 (insert (cal-tex-mini-calendar
763 (calendar-extract-month date)
764 (calendar-extract-year date)
765 "thismonth" "1.1in" "1in"))
766 (insert (cal-tex-mini-calendar
767 (calendar-extract-month (cal-tex-next-month date))
768 (calendar-extract-year (cal-tex-next-month date))
769 "nextmonth" "1.1in" "1in"))
770 (insert "\\hbox to \\textwidth{")
771 (cal-tex-hfill)
772 (insert "\\lastmonth")
773 (cal-tex-hfill)
774 (insert "\\thismonth")
775 (cal-tex-hfill)
776 (insert "\\nextmonth")
777 (cal-tex-hfill)
778 (insert "}")
779 (cal-tex-nl)
780 (cal-tex-b-parbox "l" "\\textwidth")
781 (dotimes (_jdummy 4)
782 (cal-tex-week-hours date holidays "5")
783 (setq date (cal-tex-incr-date date)))
784 (cal-tex-e-parbox)
785 (setq month (calendar-extract-month date)
786 year (calendar-extract-year date))
787 (unless (= i (1- n))
788 (run-hooks 'cal-tex-week-hook)
789 (cal-tex-newpage)))
790 (cal-tex-end-document)
791 (run-hooks 'cal-tex-hook)))
792
793 (autoload 'calendar-iso-from-absolute "cal-iso")
794
795 ;;;###cal-autoload
796 (defun cal-tex-cursor-week-iso (&optional n event)
797 "Make a LaTeX calendar buffer for a one page ISO-style weekly calendar.
798 Optional prefix argument N specifies number of weeks (default 1).
799 The calendar shows holiday and diary entries if
800 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
801 It does not show hours of the day. Optional EVENT indicates a buffer
802 position to use instead of point."
803 (interactive (list (prefix-numeric-value current-prefix-arg)
804 last-nonmenu-event))
805 (or n (setq n 1))
806 (let* ((date (calendar-gregorian-from-absolute
807 (calendar-dayname-on-or-before
808 1
809 (calendar-absolute-from-gregorian
810 (calendar-cursor-to-date t event)))))
811 (month (calendar-extract-month date))
812 (year (calendar-extract-year date))
813 (day (calendar-extract-day date))
814 (d1 (calendar-absolute-from-gregorian date))
815 (d2 (+ (* 7 n) d1))
816 (holidays (if cal-tex-holidays
817 (holiday-in-range d1 d2)))
818 (diary-list (if cal-tex-diary
819 (cal-tex-list-diary-entries d1 d2)))
820 s)
821 (cal-tex-preamble "11pt")
822 (cal-tex-cmd "\\textwidth 6.5in")
823 (cal-tex-cmd "\\textheight 10.5in")
824 (cal-tex-cmd "\\oddsidemargin 0in")
825 (cal-tex-cmd "\\evensidemargin 0in")
826 (cal-tex-b-document)
827 (cal-tex-cmd "\\pagestyle{empty}")
828 (dotimes (i n)
829 (cal-tex-vspace "-1.5in")
830 (cal-tex-b-center)
831 (cal-tex-Huge-bf
832 (let ((d (calendar-iso-from-absolute
833 (calendar-absolute-from-gregorian date))))
834 (format "Week %d of %d"
835 (calendar-extract-month d)
836 (calendar-extract-year d))))
837 (cal-tex-nl ".5cm")
838 (cal-tex-e-center)
839 (cal-tex-b-parbox "l" "\\textwidth")
840 (dotimes (_j 7)
841 (cal-tex-b-parbox "t" "\\textwidth")
842 (cal-tex-b-parbox "t" "\\textwidth")
843 (cal-tex-rule "0pt" "\\textwidth" ".2mm")
844 (cal-tex-nl)
845 (cal-tex-b-parbox "t" "\\textwidth")
846 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date)))
847 (insert ", ")
848 (cal-tex-large-bf (cal-tex-month-name month))
849 (insert " ")
850 (cal-tex-large-bf (number-to-string day))
851 (unless (string-equal "" (setq s (cal-tex-latexify-list
852 holidays date "; ")))
853 (insert ": ")
854 (cal-tex-large-bf s))
855 (cal-tex-hfill)
856 (insert " " (eval cal-tex-daily-string))
857 (cal-tex-e-parbox)
858 (cal-tex-nl)
859 (cal-tex-noindent)
860 (cal-tex-b-parbox "t" "\\textwidth")
861 (unless (string-equal "" (setq s (cal-tex-latexify-list
862 diary-list date)))
863 (insert "\\vbox to 0pt{")
864 (cal-tex-large-bf s)
865 (insert "}"))
866 (cal-tex-e-parbox)
867 (cal-tex-nl)
868 (setq date (cal-tex-incr-date date)
869 month (calendar-extract-month date)
870 day (calendar-extract-day date))
871 (cal-tex-e-parbox)
872 (cal-tex-e-parbox "2cm")
873 (cal-tex-nl)
874 (setq month (calendar-extract-month date)
875 year (calendar-extract-year date)))
876 (cal-tex-e-parbox)
877 (unless (= i (1- n))
878 (run-hooks 'cal-tex-week-hook)
879 (cal-tex-newpage)))
880 (cal-tex-end-document)
881 (run-hooks 'cal-tex-hook)))
882
883 ;; TODO respect cal-tex-daily-start,end?
884 ;; Using different numbers of hours will probably break some layouts.
885 (defun cal-tex-week-hours (date holidays height)
886 "Insert hourly entries for DATE with HOLIDAYS, with line height HEIGHT.
887 Uses the 24-hour clock if `cal-tex-24' is non-nil. Note that the hours
888 shown are hard-coded to 8-12, 13-17."
889 (let ((month (calendar-extract-month date))
890 (day (calendar-extract-day date))
891 (year (calendar-extract-year date))
892 morning afternoon s)
893 (cal-tex-comment "begin cal-tex-week-hours")
894 (cal-tex-cmd "\\ \\\\[-.2cm]")
895 (cal-tex-cmd "\\noindent")
896 (cal-tex-b-parbox "l" "6.8in")
897 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date)))
898 (insert ", ")
899 (cal-tex-large-bf (cal-tex-month-name month))
900 (insert " ")
901 (cal-tex-large-bf (number-to-string day))
902 (unless (string-equal "" (setq s (cal-tex-latexify-list
903 holidays date "; ")))
904 (insert ": ")
905 (cal-tex-large-bf s))
906 (cal-tex-hfill)
907 (insert " " (eval cal-tex-daily-string))
908 (cal-tex-e-parbox)
909 (cal-tex-nl "-.3cm")
910 (cal-tex-rule "0pt" "6.8in" ".2mm")
911 (cal-tex-nl "-.1cm")
912 (dotimes (i 5)
913 (setq morning (+ i 8) ; 8-12 incl
914 afternoon (if cal-tex-24
915 (+ i 13) ; 13-17 incl
916 (1+ i))) ; 1-5 incl
917 (cal-tex-cmd "\\hourbox" (number-to-string morning))
918 (cal-tex-arg height)
919 (cal-tex-hspace ".4cm")
920 (cal-tex-cmd "\\hourbox" (number-to-string afternoon))
921 (cal-tex-arg height)
922 (cal-tex-nl))))
923
924 ;; TODO cal-tex-diary support.
925 ;; TODO respect cal-tex-daily-start,end (see cal-tex-weekly4-box).
926 ;;;###cal-autoload
927 (defun cal-tex-cursor-week-monday (&optional n event)
928 "Make a LaTeX calendar buffer for a two-page one-week calendar.
929 It applies to the week that point is in, and starts on Monday.
930 Optional prefix argument N specifies number of weeks (default 1).
931 The calendar shows holidays if `cal-tex-holidays' is
932 non-nil (note that diary entries are not shown). The calendar shows
933 the hours 8-12am, 1-5pm. Optional EVENT indicates a buffer position
934 to use instead of point."
935 (interactive (list (prefix-numeric-value current-prefix-arg)
936 last-nonmenu-event))
937 (or n (setq n 1))
938 (let ((date (calendar-gregorian-from-absolute
939 (calendar-dayname-on-or-before
940 0
941 (calendar-absolute-from-gregorian
942 (calendar-cursor-to-date t event))))))
943 (cal-tex-preamble "11pt")
944 (cal-tex-cmd "\\textwidth 6.5in")
945 (cal-tex-cmd "\\textheight 10.5in")
946 (cal-tex-cmd "\\oddsidemargin 0in")
947 (cal-tex-cmd "\\evensidemargin 0in")
948 (cal-tex-b-document)
949 (dotimes (i n)
950 (cal-tex-vspace "-1cm")
951 (insert "\\noindent ")
952 (cal-tex-weekly4-box (cal-tex-incr-date date) nil)
953 (cal-tex-weekly4-box (cal-tex-incr-date date 4) nil)
954 (cal-tex-nl ".2cm")
955 (cal-tex-weekly4-box (cal-tex-incr-date date 2) nil)
956 (cal-tex-weekly4-box (cal-tex-incr-date date 5) nil)
957 (cal-tex-nl ".2cm")
958 (cal-tex-weekly4-box (cal-tex-incr-date date 3) nil)
959 (cal-tex-weekly4-box (cal-tex-incr-date date 6) t)
960 (unless (= i (1- n))
961 (run-hooks 'cal-tex-week-hook)
962 (setq date (cal-tex-incr-date date 7))
963 (cal-tex-newpage)))
964 (cal-tex-end-document)
965 (run-hooks 'cal-tex-hook)))
966
967 ;; TODO respect cal-tex-daily-start,end?
968 ;; Using different numbers of hours will probably break some layouts.
969 (defun cal-tex-weekly4-box (date weekend)
970 "Make one box for DATE, different if WEEKEND.
971 Uses the 24-hour clock if `cal-tex-24' is non-nil. Note that the hours
972 shown are hard-coded to 8-12, 13-17."
973 (let* ((day (calendar-extract-day date))
974 (month (calendar-extract-month date))
975 (year (calendar-extract-year date))
976 (dayname (cal-tex-LaTeXify-string (calendar-day-name date)))
977 (date1 (cal-tex-incr-date date))
978 (day1 (calendar-extract-day date1))
979 (month1 (calendar-extract-month date1))
980 (year1 (calendar-extract-year date1))
981 (dayname1 (cal-tex-LaTeXify-string (calendar-day-name date1))))
982 (cal-tex-b-framebox "8cm" "l")
983 (cal-tex-b-parbox "b" "7.5cm")
984 (insert (format "\\textbf{\\Large %s,} %s/%s/%s\\\\\n"
985 dayname month day year))
986 (cal-tex-rule "0pt" "7.5cm" ".5mm")
987 (cal-tex-nl)
988 (unless weekend
989 (dotimes (i 5)
990 (insert (format "\\textsf{\\large %d}\\\\\n" (+ i 8))))
991 (dotimes (i 5)
992 (insert (format "\\textsf{\\large %d}\\\\\n"
993 (if cal-tex-24
994 (+ i 13) ; 13-17 incl
995 (1+ i)))))) ; 1-5 incl
996 (cal-tex-nl ".5cm")
997 (when weekend
998 (cal-tex-vspace "1cm")
999 (insert "\\ \\vfill")
1000 (insert (format "\\textbf{\\Large %s,} %s/%s/%s\\\\\n"
1001 dayname1 month1 day1 year1))
1002 (cal-tex-rule "0pt" "7.5cm" ".5mm")
1003 (cal-tex-nl "1.5cm")
1004 (cal-tex-vspace "1cm"))
1005 (cal-tex-e-parbox)
1006 (cal-tex-e-framebox)
1007 (cal-tex-hspace "1cm")))
1008
1009 ;;;###cal-autoload
1010 (defun cal-tex-cursor-week-at-a-glance (&optional n event)
1011 "One-week-at-a-glance full page calendar for week indicated by cursor.
1012 Optional prefix argument N specifies number of weeks (default 1),
1013 starting on Mondays. The calendar shows holiday and diary entries
1014 if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
1015 It does not show hours of the day. Optional EVENT indicates a buffer
1016 position to use instead of point."
1017 (interactive (list (prefix-numeric-value current-prefix-arg)
1018 last-nonmenu-event))
1019 (or n (setq n 1))
1020 (let* ((date (calendar-gregorian-from-absolute
1021 (calendar-dayname-on-or-before
1022 1
1023 (calendar-absolute-from-gregorian
1024 (calendar-cursor-to-date t event)))))
1025 (month (calendar-extract-month date))
1026 (year (calendar-extract-year date))
1027 (day (calendar-extract-day date))
1028 (d1 (calendar-absolute-from-gregorian date))
1029 (d2 (+ (* 7 n) d1))
1030 (holidays (if cal-tex-holidays
1031 (holiday-in-range d1 d2)))
1032 (diary-list (if cal-tex-diary
1033 (cal-tex-list-diary-entries d1 d2))))
1034 (cal-tex-preamble "twoside,12pt")
1035 (cal-tex-cmd "\\textwidth 7in")
1036 (cal-tex-cmd "\\textheight 10.5in")
1037 (cal-tex-cmd "\\oddsidemargin 0in")
1038 (cal-tex-cmd "\\evensidemargin 0in")
1039 (cal-tex-cmd "\\topmargin 0pt")
1040 (cal-tex-cmd "\\headheight -0.875in")
1041 (cal-tex-cmd "\\headsep 0.125in")
1042 (cal-tex-cmd "\\footskip .125in")
1043 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1044 \\long\\def\\rightday#1#2#3#4#5{%
1045 \\rule{\\textwidth}{0.3pt}\\\\%
1046 \\hbox to \\textwidth{%
1047 \\vbox to 2.75in{%
1048 \\vspace*{2pt}%
1049 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1050 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1051 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1052 \\long\\def\\weekend#1#2#3#4#5{%
1053 \\rule{\\textwidth}{0.3pt}\\\\%
1054 \\hbox to \\textwidth{%
1055 \\vbox to 1.8in{%
1056 \\vspace*{2pt}%
1057 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1058 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1059 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1060 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1061 \\long\\def\\leftday#1#2#3#4#5{%
1062 \\rule{\\textwidth}{0.3pt}\\\\%
1063 \\hbox to \\textwidth{%
1064 \\vbox to 2.75in{%
1065 \\vspace*{2pt}%
1066 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1067 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1068 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1069 ")
1070 (cal-tex-b-document)
1071 (cal-tex-cmd "\\pagestyle{empty}\\ ")
1072 (cal-tex-newpage)
1073 (dotimes (i n)
1074 (insert "\\lefthead")
1075 (cal-tex-arg
1076 (let ((d (cal-tex-incr-date date 2)))
1077 (if (= (calendar-extract-month date)
1078 (calendar-extract-month d))
1079 (format "%s %s"
1080 (cal-tex-month-name (calendar-extract-month date))
1081 (calendar-extract-year date))
1082 (if (= (calendar-extract-year date)
1083 (calendar-extract-year d))
1084 (format "%s---%s %s"
1085 (cal-tex-month-name (calendar-extract-month date))
1086 (cal-tex-month-name (calendar-extract-month d))
1087 (calendar-extract-year date))
1088 (format "%s %s---%s %s"
1089 (cal-tex-month-name (calendar-extract-month date))
1090 (calendar-extract-year date)
1091 (cal-tex-month-name (calendar-extract-month d))
1092 (calendar-extract-year d))))))
1093 (insert "%\n")
1094 (dotimes (_jdummy 3)
1095 (insert "\\leftday")
1096 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1097 (cal-tex-arg (number-to-string (calendar-extract-day date)))
1098 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1099 (cal-tex-arg (cal-tex-latexify-list holidays date))
1100 (cal-tex-arg (eval cal-tex-daily-string))
1101 (insert "%\n")
1102 (setq date (cal-tex-incr-date date)))
1103 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1104 (cal-tex-nl)
1105 (insert (cal-tex-mini-calendar
1106 (calendar-extract-month (cal-tex-previous-month date))
1107 (calendar-extract-year (cal-tex-previous-month date))
1108 "lastmonth" "1.1in" "1in"))
1109 (insert (cal-tex-mini-calendar
1110 (calendar-extract-month date)
1111 (calendar-extract-year date)
1112 "thismonth" "1.1in" "1in"))
1113 (insert (cal-tex-mini-calendar
1114 (calendar-extract-month (cal-tex-next-month date))
1115 (calendar-extract-year (cal-tex-next-month date))
1116 "nextmonth" "1.1in" "1in"))
1117 (insert "\\hbox to \\textwidth{")
1118 (cal-tex-hfill)
1119 (insert "\\lastmonth")
1120 (cal-tex-hfill)
1121 (insert "\\thismonth")
1122 (cal-tex-hfill)
1123 (insert "\\nextmonth")
1124 (cal-tex-hfill)
1125 (insert "}")
1126 (cal-tex-newpage)
1127 (insert "\\righthead")
1128 (cal-tex-arg
1129 (let ((d (cal-tex-incr-date date 3)))
1130 (if (= (calendar-extract-month date)
1131 (calendar-extract-month d))
1132 (format "%s %s"
1133 (cal-tex-month-name (calendar-extract-month date))
1134 (calendar-extract-year date))
1135 (if (= (calendar-extract-year date)
1136 (calendar-extract-year d))
1137 (format "%s---%s %s"
1138 (cal-tex-month-name (calendar-extract-month date))
1139 (cal-tex-month-name (calendar-extract-month d))
1140 (calendar-extract-year date))
1141 (format "%s %s---%s %s"
1142 (cal-tex-month-name (calendar-extract-month date))
1143 (calendar-extract-year date)
1144 (cal-tex-month-name (calendar-extract-month d))
1145 (calendar-extract-year d))))))
1146 (insert "%\n")
1147 (dotimes (_jdummy 2)
1148 (insert "\\rightday")
1149 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1150 (cal-tex-arg (number-to-string (calendar-extract-day date)))
1151 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1152 (cal-tex-arg (cal-tex-latexify-list holidays date))
1153 (cal-tex-arg (eval cal-tex-daily-string))
1154 (insert "%\n")
1155 (setq date (cal-tex-incr-date date)))
1156 (dotimes (_jdummy 2)
1157 (insert "\\weekend")
1158 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1159 (cal-tex-arg (number-to-string (calendar-extract-day date)))
1160 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1161 (cal-tex-arg (cal-tex-latexify-list holidays date))
1162 (cal-tex-arg (eval cal-tex-daily-string))
1163 (insert "%\n")
1164 (setq date (cal-tex-incr-date date)))
1165 (unless (= i (1- n))
1166 (run-hooks 'cal-tex-week-hook)
1167 (cal-tex-newpage)))
1168 (cal-tex-end-document)
1169 (run-hooks 'cal-tex-hook)))
1170
1171 ;;;###cal-autoload
1172 (defun cal-tex-cursor-filofax-2week (&optional n event)
1173 "Two-weeks-at-a-glance Filofax style calendar for week cursor is in.
1174 Optional prefix argument N specifies number of weeks (default 1).
1175 The calendar shows holiday and diary entries if
1176 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
1177 Optional EVENT indicates a buffer position to use instead of point."
1178 (interactive (list (prefix-numeric-value current-prefix-arg)
1179 last-nonmenu-event))
1180 (or n (setq n 1))
1181 (let* ((date (calendar-gregorian-from-absolute
1182 (calendar-dayname-on-or-before
1183 calendar-week-start-day
1184 (calendar-absolute-from-gregorian
1185 (calendar-cursor-to-date t event)))))
1186 (month (calendar-extract-month date))
1187 (year (calendar-extract-year date))
1188 (day (calendar-extract-day date))
1189 (d1 (calendar-absolute-from-gregorian date))
1190 (d2 (+ (* 7 n) d1))
1191 (holidays (if cal-tex-holidays
1192 (holiday-in-range d1 d2)))
1193 (diary-list (if cal-tex-diary
1194 (cal-tex-list-diary-entries d1 d2))))
1195 (cal-tex-preamble "twoside")
1196 (cal-tex-cmd "\\textwidth 3.25in")
1197 (cal-tex-cmd "\\textheight 6.5in")
1198 (cal-tex-cmd "\\oddsidemargin 1.75in")
1199 (cal-tex-cmd "\\evensidemargin 1.5in")
1200 (cal-tex-cmd "\\topmargin 0pt")
1201 (cal-tex-cmd "\\headheight -0.875in")
1202 (cal-tex-cmd "\\headsep 0.125in")
1203 (cal-tex-cmd "\\footskip .125in")
1204 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1205 \\long\\def\\rightday#1#2#3#4#5{%
1206 \\rule{\\textwidth}{0.3pt}\\\\%
1207 \\hbox to \\textwidth{%
1208 \\vbox to 0.7in{%
1209 \\vspace*{2pt}%
1210 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1211 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1212 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1213 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1214 \\long\\def\\leftday#1#2#3#4#5{%
1215 \\rule{\\textwidth}{0.3pt}\\\\%
1216 \\hbox to \\textwidth{%
1217 \\vbox to 0.7in{%
1218 \\vspace*{2pt}%
1219 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1220 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1221 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1222 ")
1223 (cal-tex-b-document)
1224 (cal-tex-cmd "\\pagestyle{empty}")
1225 (dotimes (i n)
1226 (if (zerop (mod i 2))
1227 (insert "\\righthead")
1228 (insert "\\lefthead"))
1229 (cal-tex-arg
1230 (let ((d (cal-tex-incr-date date 6)))
1231 (if (= (calendar-extract-month date)
1232 (calendar-extract-month d))
1233 (format "%s %s"
1234 (cal-tex-month-name (calendar-extract-month date))
1235 (calendar-extract-year date))
1236 (if (= (calendar-extract-year date)
1237 (calendar-extract-year d))
1238 (format "%s---%s %s"
1239 (cal-tex-month-name (calendar-extract-month date))
1240 (cal-tex-month-name (calendar-extract-month d))
1241 (calendar-extract-year date))
1242 (format "%s %s---%s %s"
1243 (cal-tex-month-name (calendar-extract-month date))
1244 (calendar-extract-year date)
1245 (cal-tex-month-name (calendar-extract-month d))
1246 (calendar-extract-year d))))))
1247 (insert "%\n")
1248 (dotimes (_jdummy 7)
1249 (if (zerop (mod i 2))
1250 (insert "\\rightday")
1251 (insert "\\leftday"))
1252 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1253 (cal-tex-arg (number-to-string (calendar-extract-day date)))
1254 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1255 (cal-tex-arg (cal-tex-latexify-list holidays date))
1256 (cal-tex-arg (eval cal-tex-daily-string))
1257 (insert "%\n")
1258 (setq date (cal-tex-incr-date date)))
1259 (unless (= i (1- n))
1260 (run-hooks 'cal-tex-week-hook)
1261 (cal-tex-newpage)))
1262 (cal-tex-end-document)
1263 (run-hooks 'cal-tex-hook)))
1264
1265 ;;;###cal-autoload
1266 (defun cal-tex-cursor-filofax-week (&optional n event)
1267 "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
1268 Optional prefix argument N specifies number of weeks (default 1),
1269 starting on Mondays. The calendar shows holiday and diary entries
1270 if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
1271 Optional EVENT indicates a buffer position to use instead of point."
1272 (interactive (list (prefix-numeric-value current-prefix-arg)
1273 last-nonmenu-event))
1274 (or n (setq n 1))
1275 (let* ((date (calendar-gregorian-from-absolute
1276 (calendar-dayname-on-or-before
1277 1
1278 (calendar-absolute-from-gregorian
1279 (calendar-cursor-to-date t event)))))
1280 (month (calendar-extract-month date))
1281 (year (calendar-extract-year date))
1282 (day (calendar-extract-day date))
1283 (d1 (calendar-absolute-from-gregorian date))
1284 (d2 (+ (* 7 n) d1))
1285 (holidays (if cal-tex-holidays
1286 (holiday-in-range d1 d2)))
1287 (diary-list (if cal-tex-diary
1288 (cal-tex-list-diary-entries d1 d2))))
1289 (cal-tex-preamble "twoside")
1290 (cal-tex-cmd "\\textwidth 3.25in")
1291 (cal-tex-cmd "\\textheight 6.5in")
1292 (cal-tex-cmd "\\oddsidemargin 1.75in")
1293 (cal-tex-cmd "\\evensidemargin 1.5in")
1294 (cal-tex-cmd "\\topmargin 0pt")
1295 (cal-tex-cmd "\\headheight -0.875in")
1296 (cal-tex-cmd "\\headsep 0.125in")
1297 (cal-tex-cmd "\\footskip .125in")
1298 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1299 \\long\\def\\rightday#1#2#3#4#5{%
1300 \\rule{\\textwidth}{0.3pt}\\\\%
1301 \\hbox to \\textwidth{%
1302 \\vbox to 1.85in{%
1303 \\vspace*{2pt}%
1304 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1305 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1306 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1307 \\long\\def\\weekend#1#2#3#4#5{%
1308 \\rule{\\textwidth}{0.3pt}\\\\%
1309 \\hbox to \\textwidth{%
1310 \\vbox to .8in{%
1311 \\vspace*{2pt}%
1312 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1313 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1314 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1315 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1316 \\long\\def\\leftday#1#2#3#4#5{%
1317 \\rule{\\textwidth}{0.3pt}\\\\%
1318 \\hbox to \\textwidth{%
1319 \\vbox to 1.85in{%
1320 \\vspace*{2pt}%
1321 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1322 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1323 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1324 ")
1325 (cal-tex-b-document)
1326 (cal-tex-cmd "\\pagestyle{empty}\\ ")
1327 (cal-tex-newpage)
1328 (dotimes (i n)
1329 (insert "\\lefthead")
1330 (cal-tex-arg
1331 (let ((d (cal-tex-incr-date date 2)))
1332 (if (= (calendar-extract-month date)
1333 (calendar-extract-month d))
1334 (format "%s %s"
1335 (cal-tex-month-name (calendar-extract-month date))
1336 (calendar-extract-year date))
1337 (if (= (calendar-extract-year date)
1338 (calendar-extract-year d))
1339 (format "%s---%s %s"
1340 (cal-tex-month-name (calendar-extract-month date))
1341 (cal-tex-month-name (calendar-extract-month d))
1342 (calendar-extract-year date))
1343 (format "%s %s---%s %s"
1344 (cal-tex-month-name (calendar-extract-month date))
1345 (calendar-extract-year date)
1346 (cal-tex-month-name (calendar-extract-month d))
1347 (calendar-extract-year d))))))
1348 (insert "%\n")
1349 (dotimes (_jdummy 3)
1350 (insert "\\leftday")
1351 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1352 (cal-tex-arg (number-to-string (calendar-extract-day date)))
1353 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1354 (cal-tex-arg (cal-tex-latexify-list holidays date))
1355 (cal-tex-arg (eval cal-tex-daily-string))
1356 (insert "%\n")
1357 (setq date (cal-tex-incr-date date)))
1358 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1359 (cal-tex-newpage)
1360 (insert "\\righthead")
1361 (cal-tex-arg
1362 (let ((d (cal-tex-incr-date date 3)))
1363 (if (= (calendar-extract-month date)
1364 (calendar-extract-month d))
1365 (format "%s %s"
1366 (cal-tex-month-name (calendar-extract-month date))
1367 (calendar-extract-year date))
1368 (if (= (calendar-extract-year date)
1369 (calendar-extract-year d))
1370 (format "%s---%s %s"
1371 (cal-tex-month-name (calendar-extract-month date))
1372 (cal-tex-month-name (calendar-extract-month d))
1373 (calendar-extract-year date))
1374 (format "%s %s---%s %s"
1375 (cal-tex-month-name (calendar-extract-month date))
1376 (calendar-extract-year date)
1377 (cal-tex-month-name (calendar-extract-month d))
1378 (calendar-extract-year d))))))
1379 (insert "%\n")
1380 (dotimes (_jdummy 2)
1381 (insert "\\rightday")
1382 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1383 (cal-tex-arg (number-to-string (calendar-extract-day date)))
1384 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1385 (cal-tex-arg (cal-tex-latexify-list holidays date))
1386 (cal-tex-arg (eval cal-tex-daily-string))
1387 (insert "%\n")
1388 (setq date (cal-tex-incr-date date)))
1389 (dotimes (_jdummy 2)
1390 (insert "\\weekend")
1391 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1392 (cal-tex-arg (number-to-string (calendar-extract-day date)))
1393 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1394 (cal-tex-arg (cal-tex-latexify-list holidays date))
1395 (cal-tex-arg (eval cal-tex-daily-string))
1396 (insert "%\n")
1397 (setq date (cal-tex-incr-date date)))
1398 (unless (= i (1- n))
1399 (run-hooks 'cal-tex-week-hook)
1400 (cal-tex-newpage)))
1401 (cal-tex-end-document)
1402 (run-hooks 'cal-tex-hook)))
1403
1404 ;;;###cal-autoload
1405 (defun cal-tex-cursor-filofax-daily (&optional n event)
1406 "Day-per-page Filofax style calendar for week indicated by cursor.
1407 Optional prefix argument N specifies number of weeks (default 1),
1408 starting on Mondays. The calendar shows holiday and diary
1409 entries if `cal-tex-holidays' and `cal-tex-diary', respectively,
1410 are non-nil. Pages are ruled if `cal-tex-rules' is non-nil.
1411 Optional EVENT indicates a buffer position to use instead of point."
1412 (interactive (list (prefix-numeric-value current-prefix-arg)
1413 last-nonmenu-event))
1414 (or n (setq n 1))
1415 (let* ((date (calendar-gregorian-from-absolute
1416 (calendar-dayname-on-or-before
1417 1
1418 (calendar-absolute-from-gregorian
1419 (calendar-cursor-to-date t event)))))
1420 (month (calendar-extract-month date))
1421 (year (calendar-extract-year date))
1422 (day (calendar-extract-day date))
1423 (d1 (calendar-absolute-from-gregorian date))
1424 (d2 (+ (* 7 n) d1))
1425 (holidays (if cal-tex-holidays
1426 (holiday-in-range d1 d2)))
1427 (diary-list (if cal-tex-diary
1428 (cal-tex-list-diary-entries d1 d2))))
1429 (cal-tex-preamble "twoside")
1430 (cal-tex-cmd "\\textwidth 3.25in")
1431 (cal-tex-cmd "\\textheight 6.5in")
1432 (cal-tex-cmd "\\oddsidemargin 1.75in")
1433 (cal-tex-cmd "\\evensidemargin 1.5in")
1434 (cal-tex-cmd "\\topmargin 0pt")
1435 (cal-tex-cmd "\\headheight -0.875in")
1436 (cal-tex-cmd "\\headsep 0.125in")
1437 (cal-tex-cmd "\\footskip .125in")
1438 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1439 \\long\\def\\rightday#1#2#3{%
1440 \\rule{\\textwidth}{0.3pt}\\\\%
1441 \\hbox to \\textwidth{%
1442 \\vbox {%
1443 \\vspace*{2pt}%
1444 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1445 \\hbox to \\textwidth{\\vbox {\\raggedleft \\em #2}}%
1446 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1447 \\long\\def\\weekend#1#2#3{%
1448 \\rule{\\textwidth}{0.3pt}\\\\%
1449 \\hbox to \\textwidth{%
1450 \\vbox {%
1451 \\vspace*{2pt}%
1452 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1453 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1454 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1455 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1456 \\long\\def\\leftday#1#2#3{%
1457 \\rule{\\textwidth}{0.3pt}\\\\%
1458 \\hbox to \\textwidth{%
1459 \\vbox {%
1460 \\vspace*{2pt}%
1461 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1462 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1463 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1464 \\newbox\\LineBox
1465 \\setbox\\LineBox=\\hbox to\\textwidth{%
1466 \\vrule height.2in width0pt\\leaders\\hrule\\hfill}
1467 \\def\\linesfill{\\par\\leaders\\copy\\LineBox\\vfill}
1468 ")
1469 (cal-tex-b-document)
1470 (cal-tex-cmd "\\pagestyle{empty}")
1471 (dotimes (i n)
1472 (dotimes (j 4)
1473 (let ((even (zerop (% j 2))))
1474 (insert (if even
1475 "\\righthead"
1476 "\\lefthead"))
1477 (cal-tex-arg (calendar-date-string date))
1478 (insert "%\n")
1479 (insert (if even
1480 "\\rightday"
1481 "\\leftday")))
1482 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1483 (cal-tex-arg (cal-tex-latexify-list holidays date "\\\\" t))
1484 (cal-tex-arg (eval cal-tex-daily-string))
1485 (insert "%\n")
1486 (if cal-tex-rules
1487 (insert "\\linesfill\n")
1488 (insert "\\vfill\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1489 (cal-tex-newpage)
1490 (setq date (cal-tex-incr-date date)))
1491 (insert "%\n")
1492 (dotimes (_jdummy 2)
1493 (insert "\\lefthead")
1494 (cal-tex-arg (calendar-date-string date))
1495 (insert "\\weekend")
1496 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1497 (cal-tex-arg (cal-tex-latexify-list holidays date "\\\\" t))
1498 (cal-tex-arg (eval cal-tex-daily-string))
1499 (insert "%\n")
1500 (if cal-tex-rules
1501 (insert "\\linesfill\n")
1502 (insert "\\vfill"))
1503 (setq date (cal-tex-incr-date date)))
1504 (or cal-tex-rules
1505 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1506 (unless (= i (1- n))
1507 (run-hooks 'cal-tex-week-hook)
1508 (cal-tex-newpage)))
1509 (cal-tex-end-document)
1510 (run-hooks 'cal-tex-hook)))
1511
1512
1513 ;;;
1514 ;;; Daily calendars
1515 ;;;
1516
1517 ;;;###cal-autoload
1518 (defun cal-tex-cursor-day (&optional n event)
1519 "Make a buffer with LaTeX commands for the day cursor is on.
1520 Optional prefix argument N specifies number of days. The calendar shows
1521 the hours between `cal-tex-daily-start' and `cal-tex-daily-end', using
1522 the 24-hour clock if `cal-tex-24' is non-nil. Optional EVENT indicates
1523 a buffer position to use instead of point."
1524 (interactive (list (prefix-numeric-value current-prefix-arg)
1525 last-nonmenu-event))
1526 (or n (setq n 1))
1527 (let ((date (calendar-absolute-from-gregorian
1528 (calendar-cursor-to-date t event))))
1529 (cal-tex-preamble "12pt")
1530 (cal-tex-cmd "\\textwidth 6.5in")
1531 (cal-tex-cmd "\\textheight 10.5in")
1532 (cal-tex-b-document)
1533 (cal-tex-cmd "\\pagestyle{empty}")
1534 (dotimes (i n)
1535 (cal-tex-vspace "-1.7in")
1536 (cal-tex-daily-page (calendar-gregorian-from-absolute date))
1537 (setq date (1+ date))
1538 (unless (= i (1- n))
1539 (cal-tex-newpage)
1540 (run-hooks 'cal-tex-daily-hook)))
1541 (cal-tex-end-document)
1542 (run-hooks 'cal-tex-hook)))
1543
1544 (defun cal-tex-daily-page (date)
1545 "Make a calendar page for Gregorian DATE on 8.5 by 11 paper.
1546 Uses the 24-hour clock if `cal-tex-24' is non-nil. Produces
1547 hourly sections for the period specified by `cal-tex-daily-start'
1548 and `cal-tex-daily-end'."
1549 (let ((month-name (cal-tex-month-name (calendar-extract-month date)))
1550 (i (1- cal-tex-daily-start))
1551 hour)
1552 (cal-tex-banner "cal-tex-daily-page")
1553 (cal-tex-b-makebox "4cm" "l")
1554 (cal-tex-b-parbox "b" "3.8cm")
1555 (cal-tex-rule "0mm" "0mm" "2cm")
1556 (cal-tex-Huge (number-to-string (calendar-extract-day date)))
1557 (cal-tex-nl ".5cm")
1558 (cal-tex-bf month-name )
1559 (cal-tex-e-parbox)
1560 (cal-tex-hspace "1cm")
1561 (cal-tex-scriptsize (eval cal-tex-daily-string))
1562 (cal-tex-hspace "3.5cm")
1563 (cal-tex-e-makebox)
1564 (cal-tex-hfill)
1565 (cal-tex-b-makebox "4cm" "r")
1566 (cal-tex-bf (cal-tex-LaTeXify-string (calendar-day-name date)))
1567 (cal-tex-e-makebox)
1568 (cal-tex-nl)
1569 (cal-tex-hspace ".4cm")
1570 (cal-tex-rule "0mm" "16.1cm" "1mm")
1571 (cal-tex-nl ".1cm")
1572 (while (<= (setq i (1+ i)) cal-tex-daily-end)
1573 (cal-tex-cmd "\\noindent")
1574 (setq hour (if cal-tex-24
1575 i
1576 (mod i 12)))
1577 (if (zerop hour) (setq hour 12))
1578 (cal-tex-b-makebox "1cm" "c")
1579 (cal-tex-arg (number-to-string hour))
1580 (cal-tex-e-makebox)
1581 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1582 (cal-tex-nl ".2cm")
1583 (cal-tex-b-makebox "1cm" "c")
1584 (cal-tex-arg "$\\diamond$" )
1585 (cal-tex-e-makebox)
1586 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1587 (cal-tex-nl ".2cm"))
1588 (cal-tex-hfill)
1589 (insert (cal-tex-mini-calendar
1590 (calendar-extract-month (cal-tex-previous-month date))
1591 (calendar-extract-year (cal-tex-previous-month date))
1592 "lastmonth" "1.1in" "1in"))
1593 (insert (cal-tex-mini-calendar
1594 (calendar-extract-month date)
1595 (calendar-extract-year date)
1596 "thismonth" "1.1in" "1in"))
1597 (insert (cal-tex-mini-calendar
1598 (calendar-extract-month (cal-tex-next-month date))
1599 (calendar-extract-year (cal-tex-next-month date))
1600 "nextmonth" "1.1in" "1in"))
1601 (insert "\\hbox to \\textwidth{")
1602 (cal-tex-hfill)
1603 (insert "\\lastmonth")
1604 (cal-tex-hfill)
1605 (insert "\\thismonth")
1606 (cal-tex-hfill)
1607 (insert "\\nextmonth")
1608 (cal-tex-hfill)
1609 (insert "}")
1610 (cal-tex-banner "end of cal-tex-daily-page")))
1611
1612 ;;;
1613 ;;; Mini calendars
1614 ;;;
1615
1616 (defun cal-tex-mini-calendar (month year name width height &optional ptsize colsep)
1617 "Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT.
1618 Optional string PTSIZE gives the point size (default \"scriptsize\").
1619 Optional string COLSEP gives the column separation (default \"1mm\")."
1620 (or colsep (setq colsep "1mm"))
1621 (or ptsize (setq ptsize "scriptsize"))
1622 (let ((blank-days ; at start of month
1623 (mod
1624 (- (calendar-day-of-week (list month 1 year))
1625 calendar-week-start-day)
1626 7))
1627 (last( calendar-last-day-of-month month year))
1628 (str (concat "\\def\\" name "{\\hbox to" width "{%\n"
1629 "\\vbox to" height "{%\n"
1630 "\\vfil \\hbox to" width "{%\n"
1631 "\\hfil\\" ptsize
1632 "\\begin{tabular}"
1633 "{@{\\hspace{0mm}}r@{\\hspace{" colsep
1634 "}}r@{\\hspace{" colsep "}}r@{\\hspace{" colsep
1635 "}}r@{\\hspace{" colsep "}}r@{\\hspace{" colsep
1636 "}}r@{\\hspace{" colsep "}}r@{\\hspace{0mm}}}%\n"
1637 "\\multicolumn{7}{c}{"
1638 (cal-tex-month-name month)
1639 " "
1640 (number-to-string year)
1641 "}\\\\[1mm]\n")))
1642 (dotimes (i 7)
1643 (setq str
1644 (concat str
1645 (cal-tex-LaTeXify-string
1646 (substring (aref calendar-day-name-array
1647 (mod (+ calendar-week-start-day i) 7))
1648
1649 0 2))
1650 (if (= i 6)
1651 "\\\\[0.7mm]\n"
1652 " & "))))
1653 (dotimes (_idummy blank-days)
1654 (setq str (concat str " & ")))
1655 (dotimes (i last)
1656 (setq str (concat str (number-to-string (1+ i)))
1657 str (concat str (if (zerop (mod (+ i 1 blank-days) 7))
1658 (if (= i (1- last))
1659 ""
1660 "\\\\[0.5mm]\n")
1661 " & "))))
1662 (setq str (concat str "\n\\end{tabular}\\hfil}\\vfil}}}%\n"))
1663 str))
1664
1665 ;;;
1666 ;;; Various calendar functions
1667 ;;;
1668
1669 (defun cal-tex-incr-date (date &optional n)
1670 "The date of the day following DATE.
1671 If optional N is given, the date of N days after DATE."
1672 (calendar-gregorian-from-absolute
1673 (+ (or n 1) (calendar-absolute-from-gregorian date))))
1674
1675 (defun cal-tex-latexify-list (date-list date &optional separator final-separator)
1676 "Return string with concatenated, LaTeX-ified entries in DATE-LIST for DATE.
1677 Use double backslash as a separator unless optional SEPARATOR is given.
1678 If resulting string is not empty, put separator at end if optional
1679 FINAL-SEPARATOR is non-nil."
1680 (or separator (setq separator "\\\\"))
1681 (let (result)
1682 (setq result
1683 (mapconcat (lambda (x) (cal-tex-LaTeXify-string x))
1684 (dolist (d date-list (reverse result))
1685 (and (car d)
1686 (calendar-date-equal date (car d))
1687 (setq result (cons (cadr d) result))))
1688 separator))
1689 (if (and final-separator
1690 (not (string-equal result "")))
1691 (concat result separator)
1692 result)))
1693
1694 (defun cal-tex-previous-month (date)
1695 "Return the date of the first day in the month previous to DATE."
1696 (let ((month (calendar-extract-month date))
1697 (year (calendar-extract-year date)))
1698 (calendar-increment-month month year -1)
1699 (list month 1 year)))
1700
1701 (defun cal-tex-next-month (date)
1702 "Return the date of the first day in the month following DATE."
1703 (let ((month (calendar-extract-month date))
1704 (year (calendar-extract-year date)))
1705 (calendar-increment-month month year 1)
1706 (list month 1 year)))
1707
1708 ;;;
1709 ;;; LaTeX Code
1710 ;;;
1711
1712 (defun cal-tex-end-document ()
1713 "Finish the LaTeX document.
1714 Insert the trailer to LaTeX document, pop to LaTeX buffer, add
1715 informative header, and run HOOK."
1716 (cal-tex-e-document)
1717 (or (and cal-tex-preamble-extra
1718 (string-match "inputenc" cal-tex-preamble-extra))
1719 (when (re-search-backward "[^[:ascii:]]" nil 'move)
1720 (goto-char (point-min))
1721 (when (search-forward "documentclass" nil t)
1722 (forward-line 1)
1723 ;; Eg for some Bahai holidays.
1724 ;; FIXME latin1 might not always be right.
1725 (insert "\\usepackage[latin1]{inputenc}\n"))))
1726 (latex-mode)
1727 (pop-to-buffer cal-tex-buffer)
1728 (goto-char (point-min))
1729 ;; FIXME auctex equivalents?
1730 (cal-tex-comment
1731 (format "\tThis buffer was produced by cal-tex.el.
1732 \tTo print a calendar, type
1733 \t\tM-x tex-buffer RET
1734 \t\tM-x tex-print RET")))
1735
1736 (defun cal-tex-insert-preamble (weeks landscape size &optional append)
1737 "Initialize the output LaTeX calendar buffer, `cal-tex-buffer'.
1738 Select the output buffer, and insert the preamble for a calendar
1739 of WEEKS weeks. Insert code for landscape mode if LANDSCAPE is
1740 non-nil. Use point-size SIZE. Optional argument APPEND, if
1741 non-nil, means add to end of buffer without erasing current contents."
1742 (let ((width "18cm")
1743 (height "24cm"))
1744 (when landscape
1745 (setq width "24cm"
1746 height "18cm"))
1747 (unless append
1748 (cal-tex-preamble size)
1749 (if (not landscape)
1750 (progn
1751 (cal-tex-cmd "\\oddsidemargin -1.75cm")
1752 (cal-tex-cmd "\\def\\holidaymult{.06}"))
1753 (cal-tex-cmd "\\special{landscape}")
1754 (cal-tex-cmd "\\textwidth 9.5in")
1755 (cal-tex-cmd "\\textheight 7in")
1756 (cal-tex-comment)
1757 (cal-tex-cmd "\\def\\holidaymult{.08}"))
1758 (cal-tex-cmd cal-tex-caldate)
1759 (cal-tex-cmd cal-tex-myday)
1760 (cal-tex-b-document)
1761 (cal-tex-cmd "\\pagestyle{empty}"))
1762 (cal-tex-cmd "\\setlength{\\cellwidth}" width)
1763 (insert (format "\\setlength{\\cellwidth}{%f\\cellwidth}\n"
1764 (/ 1.1 (length cal-tex-which-days))))
1765 (cal-tex-cmd "\\setlength{\\cellheight}" height)
1766 (insert (format "\\setlength{\\cellheight}{%f\\cellheight}\n"
1767 (/ 1.0 weeks)))
1768 (cal-tex-cmd "\\ \\par")
1769 (cal-tex-vspace "-3cm")))
1770
1771 (defconst cal-tex-LaTeX-subst-list
1772 '(("\"". "``")
1773 ("\"". "''") ; quote changes meaning when list is reversed
1774 ;; Don't think this is necessary, and in any case, does not work:
1775 ;; "LaTeX Error: \verb illegal in command argument".
1776 ;;; ("@" . "\\verb|@|")
1777 ("&" . "\\&")
1778 ("%" . "\\%")
1779 ("$" . "\\$")
1780 ("#" . "\\#")
1781 ("_" . "\\_")
1782 ("{" . "\\{")
1783 ("}" . "\\}")
1784 ("<" . "$<$")
1785 (">" . "$>$")
1786 ("\n" . "\\ \\\\")) ; \\ needed for e.g \begin{center}\n AA\end{center}
1787 "Alist of symbols and their LaTeX replacements.")
1788
1789 (defun cal-tex-LaTeXify-string (string)
1790 "Protect special characters in STRING from LaTeX."
1791 (if (not string)
1792 ""
1793 (let ((head "")
1794 (tail string)
1795 (list cal-tex-LaTeX-subst-list)
1796 ch pair)
1797 (while (not (string-equal tail ""))
1798 (setq ch (substring-no-properties tail 0 1)
1799 pair (assoc ch list))
1800 (if (and pair (string-equal ch "\""))
1801 (setq list (reverse list))) ; quote changes meaning each time
1802 (setq tail (substring-no-properties tail 1)
1803 head (concat head (if pair (cdr pair) ch))))
1804 head)))
1805
1806 (defun cal-tex-month-name (month)
1807 "The name of MONTH, LaTeX-ified."
1808 (cal-tex-LaTeXify-string (calendar-month-name month)))
1809
1810 (defun cal-tex-hfill ()
1811 "Insert hfill."
1812 (insert "\\hfill"))
1813
1814 (defun cal-tex-newpage ()
1815 "Insert newpage."
1816 (insert "\\newpage%\n"))
1817
1818 (defun cal-tex-noindent ()
1819 "Insert noindent."
1820 (insert "\\noindent"))
1821
1822 (defun cal-tex-vspace (space)
1823 "Insert vspace command to move SPACE vertically."
1824 (insert "\\vspace*{" space "}")
1825 (cal-tex-comment))
1826
1827 (defun cal-tex-hspace (space)
1828 "Insert hspace command to move SPACE horizontally."
1829 (insert "\\hspace*{" space "}")
1830 (cal-tex-comment))
1831
1832 (defun cal-tex-comment (&optional comment)
1833 "Insert `% ', followed by optional string COMMENT, followed by newline.
1834 COMMENT may contain newlines, which are prefixed by `% ' in the output."
1835 (insert (format "%% %s\n"
1836 (if comment
1837 (replace-regexp-in-string "\n" "\n% " comment)
1838 ""))))
1839
1840 (defun cal-tex-banner (comment)
1841 "Insert string COMMENT, separated by blank lines."
1842 (cal-tex-comment (format "\n\n\n\t\t\t%s\n" comment)))
1843
1844 (defun cal-tex-nl (&optional skip comment)
1845 "End a line with \\. If SKIP, then add that much spacing.
1846 Add trailing COMMENT if present."
1847 (insert (format "\\\\%s"
1848 (if skip
1849 (format "[%s]" skip)
1850 "")))
1851 (cal-tex-comment comment))
1852
1853 (defun cal-tex-arg (&optional text)
1854 "Insert a brace {} pair containing the optional string TEXT."
1855 (insert (format "{%s}" (or text ""))))
1856
1857 (defun cal-tex-cmd (cmd &optional arg)
1858 "Insert LaTeX CMD, with optional argument ARG, and end with %."
1859 (insert cmd)
1860 (cal-tex-arg arg)
1861 (cal-tex-comment))
1862
1863 ;;;
1864 ;;; Environments
1865 ;;;
1866
1867 (defun cal-tex-b-document ()
1868 "Insert beginning of document."
1869 (cal-tex-cmd "\\begin{document}"))
1870
1871 (defun cal-tex-e-document ()
1872 "Insert end of document."
1873 (cal-tex-cmd "\\end{document}"))
1874
1875 (defun cal-tex-b-center ()
1876 "Insert beginning of centered block."
1877 (cal-tex-cmd "\\begin{center}"))
1878
1879 (defun cal-tex-e-center ()
1880 "Insert end of centered block."
1881 (cal-tex-comment)
1882 (cal-tex-cmd "\\end{center}"))
1883
1884
1885 ;;;
1886 ;;; Boxes
1887 ;;;
1888
1889
1890 (defun cal-tex-b-parbox (position width)
1891 "Insert parbox with parameters POSITION and WIDTH."
1892 (insert "\\parbox[" position "]{" width "}{")
1893 (cal-tex-comment))
1894
1895 (defun cal-tex-e-parbox (&optional height)
1896 "Insert end of parbox. Optionally, force it to be a given HEIGHT."
1897 (cal-tex-comment)
1898 (if height
1899 (cal-tex-rule "0mm" "0mm" height))
1900 (insert "}")
1901 (cal-tex-comment "end parbox"))
1902
1903 (defun cal-tex-b-framebox (width position)
1904 "Insert framebox with parameters WIDTH and POSITION (clr)."
1905 (insert "\\framebox[" width "][" position "]{" )
1906 (cal-tex-comment))
1907
1908 (defun cal-tex-e-framebox ()
1909 "Insert end of framebox."
1910 (cal-tex-comment)
1911 (insert "}")
1912 (cal-tex-comment "end framebox"))
1913
1914
1915 (defun cal-tex-b-makebox (width position)
1916 "Insert makebox with parameters WIDTH and POSITION (clr)."
1917 (insert "\\makebox[" width "][" position "]{" )
1918 (cal-tex-comment))
1919
1920 (defun cal-tex-e-makebox ()
1921 "Insert end of makebox."
1922 (cal-tex-comment)
1923 (insert "}")
1924 (cal-tex-comment "end makebox"))
1925
1926
1927 (defun cal-tex-rule (lower width height)
1928 "Insert a rule with parameters LOWER WIDTH HEIGHT."
1929 (insert "\\rule[" lower "]{" width "}{" height "}"))
1930
1931 ;;;
1932 ;;; Fonts
1933 ;;;
1934
1935 (defun cal-tex-em (string)
1936 "Insert STRING in italic font."
1937 (insert "\\textit{" string "}"))
1938
1939 (defun cal-tex-bf (string)
1940 "Insert STRING in bf font."
1941 (insert "\\textbf{ " string "}"))
1942
1943 (defun cal-tex-scriptsize (string)
1944 "Insert STRING in scriptsize font."
1945 (insert "{\\scriptsize " string "}"))
1946
1947 (defun cal-tex-huge (string)
1948 "Insert STRING in huge font."
1949 (insert "{\\huge " string "}"))
1950
1951 (defun cal-tex-Huge (string)
1952 "Insert STRING in Huge font."
1953 (insert "{\\Huge " string "}"))
1954
1955 (defun cal-tex-Huge-bf (string)
1956 "Insert STRING in Huge bf font."
1957 (insert "\\textbf{\\Huge " string "}"))
1958
1959 (defun cal-tex-large (string)
1960 "Insert STRING in large font."
1961 (insert "{\\large " string "}"))
1962
1963 (defun cal-tex-large-bf (string)
1964 "Insert STRING in large bf font."
1965 (insert "\\textbf{\\large " string "}"))
1966
1967
1968 (provide 'cal-tex)
1969
1970 ;;; cal-tex.el ends here