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