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