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