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