9c01ab40c0c02b9303930c55013d29a728fda593
[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 ;; Let's assume this is something to with twopage documents.
1101 ;; It has the downside that we start with a blank page.
1102 ;; It doesn't make obvious sense when oddside and evenside margins
1103 ;; are the same (non-filofax), but consider the left and right
1104 ;; versions of various functions as applicable to even and odd pages.
1105 (cal-tex-newpage)
1106 (dotimes (i n)
1107 (insert "\\lefthead")
1108 (cal-tex-arg
1109 (let ((d (cal-tex-incr-date date 2)))
1110 (if (= (calendar-extract-month date)
1111 (calendar-extract-month d))
1112 (format "%s %s"
1113 (cal-tex-month-name (calendar-extract-month date))
1114 (calendar-extract-year date))
1115 (if (= (calendar-extract-year date)
1116 (calendar-extract-year d))
1117 (format "%s---%s %s"
1118 (cal-tex-month-name (calendar-extract-month date))
1119 (cal-tex-month-name (calendar-extract-month d))
1120 (calendar-extract-year date))
1121 (format "%s %s---%s %s"
1122 (cal-tex-month-name (calendar-extract-month date))
1123 (calendar-extract-year date)
1124 (cal-tex-month-name (calendar-extract-month d))
1125 (calendar-extract-year d))))))
1126 (insert "%\n")
1127 (dotimes (_jdummy 3)
1128 (insert "\\leftday")
1129 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1130 (cal-tex-arg (number-to-string (calendar-extract-day date)))
1131 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1132 (cal-tex-arg (cal-tex-latexify-list holidays date))
1133 (cal-tex-arg (eval cal-tex-daily-string))
1134 (insert "%\n")
1135 (setq date (cal-tex-incr-date date)))
1136 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1137 (unless filofax
1138 (cal-tex-nl)
1139 (insert (cal-tex-mini-calendar
1140 (calendar-extract-month (cal-tex-previous-month date))
1141 (calendar-extract-year (cal-tex-previous-month date))
1142 "lastmonth" "1.1in" "1in"))
1143 (insert (cal-tex-mini-calendar
1144 (calendar-extract-month date)
1145 (calendar-extract-year date)
1146 "thismonth" "1.1in" "1in"))
1147 (insert (cal-tex-mini-calendar
1148 (calendar-extract-month (cal-tex-next-month date))
1149 (calendar-extract-year (cal-tex-next-month date))
1150 "nextmonth" "1.1in" "1in"))
1151 (insert "\\hbox to \\textwidth{")
1152 (cal-tex-hfill)
1153 (insert "\\lastmonth")
1154 (cal-tex-hfill)
1155 (insert "\\thismonth")
1156 (cal-tex-hfill)
1157 (insert "\\nextmonth")
1158 (cal-tex-hfill)
1159 (insert "}"))
1160 (cal-tex-newpage)
1161 (insert "\\righthead")
1162 (cal-tex-arg
1163 (let ((d (cal-tex-incr-date date 3)))
1164 (if (= (calendar-extract-month date)
1165 (calendar-extract-month d))
1166 (format "%s %s"
1167 (cal-tex-month-name (calendar-extract-month date))
1168 (calendar-extract-year date))
1169 (if (= (calendar-extract-year date)
1170 (calendar-extract-year d))
1171 (format "%s---%s %s"
1172 (cal-tex-month-name (calendar-extract-month date))
1173 (cal-tex-month-name (calendar-extract-month d))
1174 (calendar-extract-year date))
1175 (format "%s %s---%s %s"
1176 (cal-tex-month-name (calendar-extract-month date))
1177 (calendar-extract-year date)
1178 (cal-tex-month-name (calendar-extract-month d))
1179 (calendar-extract-year d))))))
1180 (insert "%\n")
1181 (dotimes (_jdummy 2)
1182 (insert "\\rightday")
1183 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1184 (cal-tex-arg (number-to-string (calendar-extract-day date)))
1185 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1186 (cal-tex-arg (cal-tex-latexify-list holidays date))
1187 (cal-tex-arg (eval cal-tex-daily-string))
1188 (insert "%\n")
1189 (setq date (cal-tex-incr-date date)))
1190 (dotimes (_jdummy 2)
1191 (insert "\\weekend")
1192 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1193 (cal-tex-arg (number-to-string (calendar-extract-day date)))
1194 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1195 (cal-tex-arg (cal-tex-latexify-list holidays date))
1196 (cal-tex-arg (eval cal-tex-daily-string))
1197 (insert "%\n")
1198 (setq date (cal-tex-incr-date date)))
1199 (unless (= i (1- n))
1200 (run-hooks 'cal-tex-week-hook)
1201 (cal-tex-newpage)))
1202 (cal-tex-end-document)
1203 (run-hooks 'cal-tex-hook)))
1204
1205 ;;;###cal-autoload
1206 (defun cal-tex-cursor-week-at-a-glance (&optional n event)
1207 "One-week-at-a-glance full page calendar for week indicated by cursor.
1208 Optional prefix argument N specifies number of weeks (default 1),
1209 starting on Mondays. The calendar shows holiday and diary entries
1210 if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
1211 It does not show hours of the day. Optional EVENT indicates a buffer
1212 position to use instead of point."
1213 (interactive (list (prefix-numeric-value current-prefix-arg)
1214 last-nonmenu-event))
1215 (cal-tex-weekly-common n event))
1216
1217 ;;;###cal-autoload
1218 (defun cal-tex-cursor-filofax-2week (&optional n event)
1219 "Two-weeks-at-a-glance Filofax style calendar for week cursor is in.
1220 Optional prefix argument N specifies number of weeks (default 1).
1221 The calendar shows holiday and diary entries if
1222 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
1223 Optional EVENT indicates a buffer position to use instead of point."
1224 (interactive (list (prefix-numeric-value current-prefix-arg)
1225 last-nonmenu-event))
1226 (or n (setq n 1))
1227 (let* ((date (calendar-gregorian-from-absolute
1228 (calendar-dayname-on-or-before
1229 calendar-week-start-day
1230 (calendar-absolute-from-gregorian
1231 (calendar-cursor-to-date t event)))))
1232 (month (calendar-extract-month date))
1233 (year (calendar-extract-year date))
1234 (day (calendar-extract-day date))
1235 (d1 (calendar-absolute-from-gregorian date))
1236 (d2 (+ (* 7 n) d1))
1237 (holidays (if cal-tex-holidays
1238 (holiday-in-range d1 d2)))
1239 (diary-list (if cal-tex-diary
1240 (cal-tex-list-diary-entries d1 d2))))
1241 (cal-tex-preamble "twoside")
1242 (cal-tex-filofax-paper)
1243 (insert cal-tex-righthead)
1244 (cal-tex-longday "rightday" "0.7in")
1245 (insert cal-tex-lefthead)
1246 (cal-tex-longday "leftday" "0.7in")
1247 (cal-tex-b-document)
1248 (cal-tex-cmd "\\pagestyle" "empty")
1249 (dotimes (i n)
1250 (if (zerop (mod i 2))
1251 (insert "\\righthead")
1252 (insert "\\lefthead"))
1253 (cal-tex-arg
1254 (let ((d (cal-tex-incr-date date 6)))
1255 (if (= (calendar-extract-month date)
1256 (calendar-extract-month d))
1257 (format "%s %s"
1258 (cal-tex-month-name (calendar-extract-month date))
1259 (calendar-extract-year date))
1260 (if (= (calendar-extract-year date)
1261 (calendar-extract-year d))
1262 (format "%s---%s %s"
1263 (cal-tex-month-name (calendar-extract-month date))
1264 (cal-tex-month-name (calendar-extract-month d))
1265 (calendar-extract-year date))
1266 (format "%s %s---%s %s"
1267 (cal-tex-month-name (calendar-extract-month date))
1268 (calendar-extract-year date)
1269 (cal-tex-month-name (calendar-extract-month d))
1270 (calendar-extract-year d))))))
1271 (insert "%\n")
1272 (dotimes (_jdummy 7)
1273 (if (zerop (mod i 2))
1274 (insert "\\rightday")
1275 (insert "\\leftday"))
1276 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1277 (cal-tex-arg (number-to-string (calendar-extract-day date)))
1278 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1279 (cal-tex-arg (cal-tex-latexify-list holidays date))
1280 (cal-tex-arg (eval cal-tex-daily-string))
1281 (insert "%\n")
1282 (setq date (cal-tex-incr-date date)))
1283 (unless (= i (1- n))
1284 (run-hooks 'cal-tex-week-hook)
1285 (cal-tex-newpage)))
1286 (cal-tex-end-document)
1287 (run-hooks 'cal-tex-hook)))
1288
1289 ;;;###cal-autoload
1290 (defun cal-tex-cursor-filofax-week (&optional n event)
1291 "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
1292 Optional prefix argument N specifies number of weeks (default 1),
1293 starting on Mondays. The calendar shows holiday and diary entries
1294 if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
1295 Optional EVENT indicates a buffer position to use instead of point."
1296 (interactive (list (prefix-numeric-value current-prefix-arg)
1297 last-nonmenu-event))
1298 (cal-tex-weekly-common n event t))
1299
1300 ;;;###cal-autoload
1301 (defun cal-tex-cursor-filofax-daily (&optional n event)
1302 "Day-per-page Filofax style calendar for week indicated by cursor.
1303 Optional prefix argument N specifies number of weeks (default 1),
1304 starting on Mondays. The calendar shows holiday and diary
1305 entries if `cal-tex-holidays' and `cal-tex-diary', respectively,
1306 are non-nil. Pages are ruled if `cal-tex-rules' is non-nil.
1307 Optional EVENT indicates a buffer position to use instead of point."
1308 (interactive (list (prefix-numeric-value current-prefix-arg)
1309 last-nonmenu-event))
1310 (or n (setq n 1))
1311 (let* ((date (calendar-gregorian-from-absolute
1312 (calendar-dayname-on-or-before
1313 1
1314 (calendar-absolute-from-gregorian
1315 (calendar-cursor-to-date t event)))))
1316 (month (calendar-extract-month date))
1317 (year (calendar-extract-year date))
1318 (day (calendar-extract-day date))
1319 (d1 (calendar-absolute-from-gregorian date))
1320 (d2 (+ (* 7 n) d1))
1321 (holidays (if cal-tex-holidays
1322 (holiday-in-range d1 d2)))
1323 (diary-list (if cal-tex-diary
1324 (cal-tex-list-diary-entries d1 d2))))
1325 (cal-tex-preamble "twoside")
1326 (cal-tex-filofax-paper)
1327 (insert cal-tex-righthead)
1328 (cal-tex-shortday "rightday")
1329 (cal-tex-shortday "weekend")
1330 (insert cal-tex-lefthead)
1331 (cal-tex-shortday "leftday")
1332 (insert "\\newbox\\LineBox
1333 \\setbox\\LineBox=\\hbox to\\textwidth{%
1334 \\vrule height.2in width0pt\\leaders\\hrule\\hfill}
1335 \\def\\linesfill{\\par\\leaders\\copy\\LineBox\\vfill}
1336 ")
1337 (cal-tex-b-document)
1338 (cal-tex-cmd "\\pagestyle" "empty")
1339 (dotimes (i n)
1340 (dotimes (j 4)
1341 (let ((even (zerop (% j 2))))
1342 (insert (if even
1343 "\\righthead"
1344 "\\lefthead"))
1345 (cal-tex-arg (calendar-date-string date))
1346 (insert "%\n")
1347 (insert (if even
1348 "\\rightday"
1349 "\\leftday")))
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\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1357 (cal-tex-newpage)
1358 (setq date (cal-tex-incr-date date)))
1359 (insert "%\n")
1360 (dotimes (_jdummy 2)
1361 (insert "\\lefthead")
1362 (cal-tex-arg (calendar-date-string date))
1363 (insert "\\weekend")
1364 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1365 (cal-tex-arg (cal-tex-latexify-list holidays date "\\\\" t))
1366 (cal-tex-arg (eval cal-tex-daily-string))
1367 (insert "%\n")
1368 (if cal-tex-rules
1369 (insert "\\linesfill\n")
1370 (insert "\\vfill"))
1371 (setq date (cal-tex-incr-date date)))
1372 (or cal-tex-rules
1373 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1374 (unless (= i (1- n))
1375 (run-hooks 'cal-tex-week-hook)
1376 (cal-tex-newpage)))
1377 (cal-tex-end-document)
1378 (run-hooks 'cal-tex-hook)))
1379
1380
1381 ;;;
1382 ;;; Daily calendars
1383 ;;;
1384
1385 ;;;###cal-autoload
1386 (defun cal-tex-cursor-day (&optional n event)
1387 "Make a buffer with LaTeX commands for the day cursor is on.
1388 Optional prefix argument N specifies number of days. The calendar shows
1389 the hours between `cal-tex-daily-start' and `cal-tex-daily-end', using
1390 the 24-hour clock if `cal-tex-24' is non-nil. Optional EVENT indicates
1391 a buffer position to use instead of point."
1392 (interactive (list (prefix-numeric-value current-prefix-arg)
1393 last-nonmenu-event))
1394 (or n (setq n 1))
1395 (let ((date (calendar-absolute-from-gregorian
1396 (calendar-cursor-to-date t event))))
1397 (cal-tex-preamble "12pt")
1398 (cal-tex-weekly-paper 'nomargins)
1399 (cal-tex-b-document)
1400 (cal-tex-cmd "\\pagestyle" "empty")
1401 (dotimes (i n)
1402 (cal-tex-vspace "-1.7in")
1403 (cal-tex-daily-page (calendar-gregorian-from-absolute date))
1404 (setq date (1+ date))
1405 (unless (= i (1- n))
1406 (cal-tex-newpage)
1407 (run-hooks 'cal-tex-daily-hook)))
1408 (cal-tex-end-document)
1409 (run-hooks 'cal-tex-hook)))
1410
1411 (defun cal-tex-daily-page (date)
1412 "Make a calendar page for Gregorian DATE on 8.5 by 11 paper.
1413 Uses the 24-hour clock if `cal-tex-24' is non-nil. Produces
1414 hourly sections for the period specified by `cal-tex-daily-start'
1415 and `cal-tex-daily-end'."
1416 (let ((month-name (cal-tex-month-name (calendar-extract-month date)))
1417 (i (1- cal-tex-daily-start))
1418 hour)
1419 (cal-tex-banner "cal-tex-daily-page")
1420 (cal-tex-b-makebox "4cm" "l")
1421 (cal-tex-b-parbox "b" "3.8cm")
1422 (cal-tex-rule "0mm" "0mm" "2cm")
1423 (cal-tex-Huge (number-to-string (calendar-extract-day date)))
1424 (cal-tex-nl ".5cm")
1425 (cal-tex-bf month-name )
1426 (cal-tex-e-parbox)
1427 (cal-tex-hspace "1cm")
1428 (cal-tex-scriptsize (eval cal-tex-daily-string))
1429 (cal-tex-hspace "3.5cm")
1430 (cal-tex-e-makebox)
1431 (cal-tex-hfill)
1432 (cal-tex-b-makebox "4cm" "r")
1433 (cal-tex-bf (cal-tex-LaTeXify-string (calendar-day-name date)))
1434 (cal-tex-e-makebox)
1435 (cal-tex-nl)
1436 (cal-tex-hspace ".4cm")
1437 (cal-tex-rule "0mm" "16.1cm" "1mm")
1438 (cal-tex-nl ".1cm")
1439 (while (<= (setq i (1+ i)) cal-tex-daily-end)
1440 (cal-tex-cmd "\\noindent")
1441 (setq hour (if cal-tex-24
1442 i
1443 (mod i 12)))
1444 (if (zerop hour) (setq hour 12))
1445 (cal-tex-b-makebox "1cm" "c")
1446 (cal-tex-arg (number-to-string hour))
1447 (cal-tex-e-makebox)
1448 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1449 (cal-tex-nl ".2cm")
1450 (cal-tex-b-makebox "1cm" "c")
1451 (cal-tex-arg "$\\diamond$" )
1452 (cal-tex-e-makebox)
1453 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1454 (cal-tex-nl ".2cm"))
1455 (cal-tex-hfill)
1456 (insert (cal-tex-mini-calendar
1457 (calendar-extract-month (cal-tex-previous-month date))
1458 (calendar-extract-year (cal-tex-previous-month date))
1459 "lastmonth" "1.1in" "1in"))
1460 (insert (cal-tex-mini-calendar
1461 (calendar-extract-month date)
1462 (calendar-extract-year date)
1463 "thismonth" "1.1in" "1in"))
1464 (insert (cal-tex-mini-calendar
1465 (calendar-extract-month (cal-tex-next-month date))
1466 (calendar-extract-year (cal-tex-next-month date))
1467 "nextmonth" "1.1in" "1in"))
1468 (insert "\\hbox to \\textwidth{")
1469 (cal-tex-hfill)
1470 (insert "\\lastmonth")
1471 (cal-tex-hfill)
1472 (insert "\\thismonth")
1473 (cal-tex-hfill)
1474 (insert "\\nextmonth")
1475 (cal-tex-hfill)
1476 (insert "}")
1477 (cal-tex-banner "end of cal-tex-daily-page")))
1478
1479 ;;;
1480 ;;; Mini calendars
1481 ;;;
1482
1483 (defun cal-tex-mini-calendar (month year name width height &optional ptsize colsep)
1484 "Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT.
1485 Optional string PTSIZE gives the point size (default \"scriptsize\").
1486 Optional string COLSEP gives the column separation (default \"1mm\")."
1487 (or colsep (setq colsep "1mm"))
1488 (or ptsize (setq ptsize "scriptsize"))
1489 (let ((blank-days ; at start of month
1490 (mod
1491 (- (calendar-day-of-week (list month 1 year))
1492 calendar-week-start-day)
1493 7))
1494 (last( calendar-last-day-of-month month year))
1495 (str (concat "\\def\\" name "{\\hbox to" width "{%\n"
1496 "\\vbox to" height "{%\n"
1497 "\\vfil \\hbox to" width "{%\n"
1498 "\\hfil\\" ptsize
1499 "\\begin{tabular}"
1500 "{@{\\hspace{0mm}}r@{\\hspace{" colsep
1501 "}}r@{\\hspace{" colsep "}}r@{\\hspace{" colsep
1502 "}}r@{\\hspace{" colsep "}}r@{\\hspace{" colsep
1503 "}}r@{\\hspace{" colsep "}}r@{\\hspace{0mm}}}%\n"
1504 "\\multicolumn{7}{c}{"
1505 (cal-tex-month-name month)
1506 " "
1507 (number-to-string year)
1508 "}\\\\[1mm]\n")))
1509 (dotimes (i 7)
1510 (setq str
1511 (concat str
1512 (cal-tex-LaTeXify-string
1513 (substring (aref calendar-day-name-array
1514 (mod (+ calendar-week-start-day i) 7))
1515
1516 0 2))
1517 (if (= i 6)
1518 "\\\\[0.7mm]\n"
1519 " & "))))
1520 (dotimes (_idummy blank-days)
1521 (setq str (concat str " & ")))
1522 (dotimes (i last)
1523 (setq str (concat str (number-to-string (1+ i)))
1524 str (concat str (if (zerop (mod (+ i 1 blank-days) 7))
1525 (if (= i (1- last))
1526 ""
1527 "\\\\[0.5mm]\n")
1528 " & "))))
1529 (setq str (concat str "\n\\end{tabular}\\hfil}\\vfil}}}%\n"))
1530 str))
1531
1532 ;;;
1533 ;;; Various calendar functions
1534 ;;;
1535
1536 (defun cal-tex-incr-date (date &optional n)
1537 "The date of the day following DATE.
1538 If optional N is given, the date of N days after DATE."
1539 (calendar-gregorian-from-absolute
1540 (+ (or n 1) (calendar-absolute-from-gregorian date))))
1541
1542 (defun cal-tex-latexify-list (date-list date &optional separator final-separator)
1543 "Return string with concatenated, LaTeX-ified entries in DATE-LIST for DATE.
1544 Use double backslash as a separator unless optional SEPARATOR is given.
1545 If resulting string is not empty, put separator at end if optional
1546 FINAL-SEPARATOR is non-nil."
1547 (or separator (setq separator "\\\\"))
1548 (let (result)
1549 (setq result
1550 (mapconcat (lambda (x) (cal-tex-LaTeXify-string x))
1551 (dolist (d date-list (reverse result))
1552 (and (car d)
1553 (calendar-date-equal date (car d))
1554 (setq result (cons (cadr d) result))))
1555 separator))
1556 (if (and final-separator
1557 (not (string-equal result "")))
1558 (concat result separator)
1559 result)))
1560
1561 (defun cal-tex-previous-month (date)
1562 "Return the date of the first day in the month previous to DATE."
1563 (let ((month (calendar-extract-month date))
1564 (year (calendar-extract-year date)))
1565 (calendar-increment-month month year -1)
1566 (list month 1 year)))
1567
1568 (defun cal-tex-next-month (date)
1569 "Return the date of the first day in the month following DATE."
1570 (let ((month (calendar-extract-month date))
1571 (year (calendar-extract-year date)))
1572 (calendar-increment-month month year 1)
1573 (list month 1 year)))
1574
1575 ;;;
1576 ;;; LaTeX Code
1577 ;;;
1578
1579 (defun cal-tex-end-document ()
1580 "Finish the LaTeX document.
1581 Insert the trailer to LaTeX document, pop to LaTeX buffer, add
1582 informative header, and run HOOK."
1583 (cal-tex-e-document)
1584 (or (and cal-tex-preamble-extra
1585 (string-match "inputenc" cal-tex-preamble-extra))
1586 (when (re-search-backward "[^[:ascii:]]" nil 'move)
1587 (goto-char (point-min))
1588 (when (search-forward "documentclass" nil t)
1589 (forward-line 1)
1590 ;; Eg for some Bahai holidays.
1591 ;; FIXME latin1 might not always be right.
1592 (insert "\\usepackage[latin1]{inputenc}\n"))))
1593 (latex-mode)
1594 (pop-to-buffer (current-buffer))
1595 (goto-char (point-min))
1596 ;; FIXME auctex equivalents?
1597 (cal-tex-comment
1598 (format "\tThis buffer was produced by cal-tex.el.
1599 \tTo print a calendar, type
1600 \t\tM-x tex-buffer RET
1601 \t\tM-x tex-print RET")))
1602
1603 (defun cal-tex-insert-preamble (weeks landscape size &optional append)
1604 "Initialize the output LaTeX calendar buffer, `cal-tex-buffer'.
1605 Select the output buffer, and insert the preamble for a calendar
1606 of WEEKS weeks. Insert code for landscape mode if LANDSCAPE is
1607 non-nil. Use point-size SIZE. Optional argument APPEND, if
1608 non-nil, means add to end of buffer without erasing current contents."
1609 (let ((width "18cm")
1610 (height "24cm"))
1611 (when landscape
1612 (setq width "24cm"
1613 height "18cm"))
1614 (unless append
1615 (cal-tex-preamble size)
1616 (if (not landscape)
1617 (progn
1618 (cal-tex-cmd "\\oddsidemargin -1.75cm")
1619 (cal-tex-cmd "\\def\\holidaymult" ".06"))
1620 (cal-tex-cmd "\\special" "landscape")
1621 (cal-tex-cmd "\\textwidth 9.5in")
1622 (cal-tex-cmd "\\textheight 7in")
1623 (cal-tex-comment)
1624 (cal-tex-cmd "\\def\\holidaymult" ".08"))
1625 (cal-tex-cmd cal-tex-caldate)
1626 (cal-tex-cmd cal-tex-myday)
1627 (cal-tex-b-document)
1628 (cal-tex-cmd "\\pagestyle" "empty"))
1629 (cal-tex-cmd "\\setlength{\\cellwidth}" width)
1630 (insert (format "\\setlength{\\cellwidth}{%f\\cellwidth}\n"
1631 (/ 1.1 (length cal-tex-which-days))))
1632 (cal-tex-cmd "\\setlength{\\cellheight}" height)
1633 (insert (format "\\setlength{\\cellheight}{%f\\cellheight}\n"
1634 (/ 1.0 weeks)))
1635 (cal-tex-cmd "\\ \\par")
1636 (cal-tex-vspace "-3cm")))
1637
1638 (defconst cal-tex-LaTeX-subst-list
1639 '(("\"". "``")
1640 ("\"". "''") ; quote changes meaning when list is reversed
1641 ;; Don't think this is necessary, and in any case, does not work:
1642 ;; "LaTeX Error: \verb illegal in command argument".
1643 ;;; ("@" . "\\verb|@|")
1644 ("&" . "\\&")
1645 ("%" . "\\%")
1646 ("$" . "\\$")
1647 ("#" . "\\#")
1648 ("_" . "\\_")
1649 ("{" . "\\{")
1650 ("}" . "\\}")
1651 ("<" . "$<$")
1652 (">" . "$>$")
1653 ("\n" . "\\ \\\\")) ; \\ needed for e.g \begin{center}\n AA\end{center}
1654 "Alist of symbols and their LaTeX replacements.")
1655
1656 (defun cal-tex-LaTeXify-string (string)
1657 "Protect special characters in STRING from LaTeX."
1658 (if (not string)
1659 ""
1660 (let ((head "")
1661 (tail string)
1662 (list cal-tex-LaTeX-subst-list)
1663 ch pair)
1664 (while (not (string-equal tail ""))
1665 (setq ch (substring-no-properties tail 0 1)
1666 pair (assoc ch list))
1667 (if (and pair (string-equal ch "\""))
1668 (setq list (reverse list))) ; quote changes meaning each time
1669 (setq tail (substring-no-properties tail 1)
1670 head (concat head (if pair (cdr pair) ch))))
1671 head)))
1672
1673 (defun cal-tex-month-name (month)
1674 "The name of MONTH, LaTeX-ified."
1675 (cal-tex-LaTeXify-string (calendar-month-name month)))
1676
1677 (defun cal-tex-hfill ()
1678 "Insert hfill."
1679 (insert "\\hfill"))
1680
1681 (defun cal-tex-newpage ()
1682 "Insert newpage."
1683 (insert "\\newpage%\n"))
1684
1685 (defun cal-tex-noindent ()
1686 "Insert noindent."
1687 (insert "\\noindent"))
1688
1689 (defun cal-tex-vspace (space)
1690 "Insert vspace command to move SPACE vertically."
1691 (cal-tex-cmd "\\vspace*" space))
1692
1693 (defun cal-tex-hspace (space)
1694 "Insert hspace command to move SPACE horizontally."
1695 (cal-tex-cmd "\\hspace*" space))
1696
1697 (defun cal-tex-comment (&optional comment)
1698 "Insert `% ', followed by optional string COMMENT, followed by newline.
1699 COMMENT may contain newlines, which are prefixed by `% ' in the output."
1700 (insert (format "%% %s\n"
1701 (if comment
1702 (replace-regexp-in-string "\n" "\n% " comment)
1703 ""))))
1704
1705 (defun cal-tex-banner (comment)
1706 "Insert string COMMENT, separated by blank lines."
1707 (cal-tex-comment (format "\n\n\n\t\t\t%s\n" comment)))
1708
1709 (defun cal-tex-nl (&optional skip comment)
1710 "End a line with \\. If SKIP, then add that much spacing.
1711 Add trailing COMMENT if present."
1712 (insert (format "\\\\%s"
1713 (if skip
1714 (format "[%s]" skip)
1715 "")))
1716 (cal-tex-comment comment))
1717
1718 (defun cal-tex-arg (&optional text)
1719 "Insert a brace {} pair containing the optional string TEXT."
1720 (insert (format "{%s}" (or text ""))))
1721
1722 (defun cal-tex-cmd (cmd &optional arg)
1723 "Insert LaTeX CMD, with optional argument ARG, and end with %."
1724 (insert cmd)
1725 (cal-tex-arg arg)
1726 (cal-tex-comment))
1727
1728 ;;;
1729 ;;; Environments
1730 ;;;
1731
1732 (defun cal-tex-b-document ()
1733 "Insert beginning of document."
1734 (cal-tex-cmd "\\begin" "document"))
1735
1736 (defun cal-tex-e-document ()
1737 "Insert end of document."
1738 (cal-tex-cmd "\\end" "document"))
1739
1740 (defun cal-tex-b-center ()
1741 "Insert beginning of centered block."
1742 (cal-tex-cmd "\\begin" "center"))
1743
1744 (defun cal-tex-e-center ()
1745 "Insert end of centered block."
1746 (cal-tex-comment)
1747 (cal-tex-cmd "\\end" "center"))
1748
1749
1750 ;;;
1751 ;;; Boxes
1752 ;;;
1753
1754
1755 (defun cal-tex-b-parbox (position width)
1756 "Insert parbox with parameters POSITION and WIDTH."
1757 (insert "\\parbox[" position "]{" width "}{")
1758 (cal-tex-comment))
1759
1760 (defun cal-tex-e-parbox (&optional height)
1761 "Insert end of parbox. Optionally, force it to be a given HEIGHT."
1762 (cal-tex-comment)
1763 (if height
1764 (cal-tex-rule "0mm" "0mm" height))
1765 (insert "}")
1766 (cal-tex-comment "end parbox"))
1767
1768 (defun cal-tex-b-framebox (width position)
1769 "Insert framebox with parameters WIDTH and POSITION (clr)."
1770 (insert "\\framebox[" width "][" position "]{" )
1771 (cal-tex-comment))
1772
1773 (defun cal-tex-e-framebox ()
1774 "Insert end of framebox."
1775 (cal-tex-comment)
1776 (insert "}")
1777 (cal-tex-comment "end framebox"))
1778
1779
1780 (defun cal-tex-b-makebox (width position)
1781 "Insert makebox with parameters WIDTH and POSITION (clr)."
1782 (insert "\\makebox[" width "][" position "]{" )
1783 (cal-tex-comment))
1784
1785 (defun cal-tex-e-makebox ()
1786 "Insert end of makebox."
1787 (cal-tex-comment)
1788 (insert "}")
1789 (cal-tex-comment "end makebox"))
1790
1791
1792 (defun cal-tex-rule (lower width height)
1793 "Insert a rule with parameters LOWER WIDTH HEIGHT."
1794 (insert "\\rule[" lower "]{" width "}{" height "}"))
1795
1796 ;;;
1797 ;;; Fonts
1798 ;;;
1799
1800 (defun cal-tex-em (string)
1801 "Insert STRING in italic font."
1802 (cal-tex-cmd "\\textit" string))
1803
1804 (defun cal-tex-bf (string)
1805 "Insert STRING in bf font."
1806 (cal-tex-cmd "\\textbf" string))
1807
1808 (defun cal-tex-scriptsize (string)
1809 "Insert STRING in scriptsize font."
1810 (cal-tex-arg (concat "\\scriptsize " string)))
1811
1812 (defun cal-tex-huge (string)
1813 "Insert STRING in huge font."
1814 (cal-tex-arg (concat "\\huge " string)))
1815
1816 (defun cal-tex-Huge (string)
1817 "Insert STRING in Huge font."
1818 (cal-tex-arg (concat "\\Huge " string)))
1819
1820 (defun cal-tex-Huge-bf (string)
1821 "Insert STRING in Huge bf font."
1822 (cal-tex-cmd "\\textbf" (concat "\\Huge " string)))
1823
1824 (defun cal-tex-large (string)
1825 "Insert STRING in large font."
1826 (cal-tex-arg (concat "\\large " string)))
1827
1828 (defun cal-tex-large-bf (string)
1829 "Insert STRING in large bf font."
1830 (cal-tex-cmd "\\textbf" (concat "\\large " string)))
1831
1832
1833 (provide 'cal-tex)
1834
1835 ;;; cal-tex.el ends here