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