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