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