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