(calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
[emacs.git] / lisp / calendar / cal-tex.el
blobb8d0dcb1634479faf19f76ecc3cf7fdd959958f3
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 ;;;
64 ;;; Customizable variables
65 ;;;
67 (defgroup calendar-tex nil
68 "Options for printing calendar with LaTeX."
69 :prefix "cal-tex-"
70 :group 'calendar)
72 (defcustom cal-tex-which-days '(0 1 2 3 4 5 6)
73 "The days of the week that are displayed on the portrait monthly calendar.
74 Sunday is 0, Monday is 1, and so on. The default is to print from Sunday to
75 Saturday. For example, use '(1 3 5) to only print Monday, Wednesday, Friday."
76 :type '(repeat integer)
77 :group 'calendar-tex)
79 (defcustom cal-tex-holidays t
80 "Non-nil means holidays are printed in the LaTeX calendars that support it.
81 Setting this to nil may speed up calendar generation."
82 :type 'boolean
83 :group 'calendar-tex)
85 (defcustom cal-tex-diary nil
86 "Non-nil means diary entries are printed in LaTeX calendars that support it.
87 At present, this only affects the monthly, filofax, and iso-week
88 calendars (i.e. not the yearly, plain weekly, or daily calendars).
89 Setting this to nil may speed up calendar generation."
90 :type 'boolean
91 :group 'calendar-tex)
93 (defcustom cal-tex-rules nil
94 "Non-nil means pages will be ruled in some LaTeX calendar styles.
95 At present, this only affects the daily filofax calendar."
96 :type 'boolean
97 :group 'calendar-tex)
99 (defcustom cal-tex-daily-string
100 '(let* ((year (extract-calendar-year date))
101 (day (calendar-day-number date))
102 (days-remaining (- (calendar-day-number (list 12 31 year)) day)))
103 (format "%d/%d" day days-remaining))
104 "Lisp expression giving the date format to use in the LaTeX calendars.
105 This should be an expression involving the variable `date'. When
106 this expression is called, `date' is a list of the form '(MONTH DAY YEAR)'.
108 The string resulting from evaluating this expression is placed at
109 the bottom center of each date in monthly calendars, next to the
110 date in the weekly calendars, and in the top center of daily calendars.
112 The default is ordinal day number of the year and the number of
113 days remaining. As an example, setting this to
115 '(calendar-hebrew-date-string date)
117 will put the Hebrew date at the bottom of each day."
118 :type 'sexp
119 :group 'calendar-tex)
121 (defcustom cal-tex-buffer "calendar.tex"
122 "The name for the output LaTeX calendar buffer."
123 :type 'string
124 :group 'calendar-tex)
126 (defcustom cal-tex-24 nil
127 "Non-nil means use a 24 hour clock in the daily calendar."
128 :type 'boolean
129 :group 'calendar-tex)
131 (defcustom cal-tex-daily-start 8
132 "The first hour of the daily LaTeX calendar page.
133 At present, this only affects `cal-tex-cursor-day'."
134 :type 'integer
135 :group 'calendar-tex)
137 (defcustom cal-tex-daily-end 20
138 "The last hour of the daily LaTeX calendar page.
139 At present, this only affects `cal-tex-cursor-day'"
140 :type 'integer
141 :group 'calendar-tex)
143 (defcustom cal-tex-preamble-extra nil
144 "A string giving extra LaTeX commands to insert in the calendar preamble.
145 For example, to include extra packages:
146 \"\\\\usepackage{foo}\\n\\\\usepackage{bar}\\n\"."
147 :type 'string
148 :group 'calendar-tex
149 :version "22.1")
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 postprocessing 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)
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)
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)
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)
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)
181 ;;; Definitions for LaTeX code
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.")
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'.")
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}%
200 "LaTeX code for the month header, for a single month calendar.")
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}%
210 "LaTeX code for the month header, for a multi-month calendar.")
212 (defconst cal-tex-myday
213 "\\renewcommand{\\myday}[1]%
214 {\\makebox[\\cellwidth]{\\hfill\\large\\bf#1\\hfill}}
217 "LaTeX code for a day heading.")
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}}}
237 "LaTeX code to insert one box with date info in calendar.
238 This definition is the heart of the calendar!")
240 (autoload 'calendar-holiday-list "holidays")
242 (defun cal-tex-list-holidays (d1 d2)
243 "Generate a list of all holidays from absolute date D1 to D2."
244 (let* ((start (calendar-gregorian-from-absolute d1))
245 (displayed-month (extract-calendar-month start))
246 (displayed-year (extract-calendar-year start))
247 (end (calendar-gregorian-from-absolute d2))
248 (end-month (extract-calendar-month end))
249 (end-year (extract-calendar-year end))
250 (number-of-intervals
251 (1+ (/ (calendar-interval displayed-month displayed-year
252 end-month end-year)
253 3)))
254 holidays in-range a)
255 (increment-calendar-month displayed-month displayed-year 1)
256 (dotimes (idummy number-of-intervals)
257 (setq holidays (append holidays (calendar-holiday-list)))
258 (increment-calendar-month displayed-month displayed-year 3))
259 (dolist (hol holidays)
260 (and (car hol)
261 (setq a (calendar-absolute-from-gregorian (car hol)))
262 (and (<= d1 a) (<= a d2))
263 (setq in-range (append (list hol) in-range))))
264 in-range))
266 (autoload 'diary-list-entries "diary-lib")
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 ;;;###cal-autoload
316 (defun cal-tex-cursor-year (&optional arg)
317 "Make a buffer with LaTeX commands for the year cursor is on.
318 Optional prefix argument ARG specifies number of years."
319 (interactive "p")
320 (cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
321 (or arg 1)))
323 ;;;###cal-autoload
324 (defun cal-tex-cursor-year-landscape (&optional arg)
325 "Make a buffer with LaTeX commands for the year cursor is on.
326 Optional prefix argument ARG specifies number of years."
327 (interactive "p")
328 (cal-tex-year (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 ;;;###cal-autoload
368 (defun cal-tex-cursor-filofax-year (&optional arg)
369 "Make a Filofax one page yearly calendar of year indicated by cursor.
370 Optional prefix argument ARG specifies number of years."
371 (interactive "p")
372 (let ((n (or arg 1))
373 (year (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 ;;;###cal-autoload
421 (defun cal-tex-cursor-month-landscape (&optional arg)
422 "Make a LaTeX calendar buffer for the month the cursor is on.
423 Optional prefix argument ARG specifies number of months to be
424 produced (default 1). The output is in landscape format, one
425 month to a page. It shows holiday and diary entries if
426 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil."
427 (interactive "p")
428 (let* ((n (or arg 1))
429 (date (calendar-cursor-to-date t))
430 (month (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 ;;;###cal-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 ;;;###cal-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 ;;;###cal-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 'calendar-iso-from-absolute "cal-iso")
810 ;;;###cal-autoload
811 (defun cal-tex-cursor-week-iso (&optional arg)
812 "Make a LaTeX calendar buffer for a one page ISO-style weekly calendar.
813 Optional prefix argument ARG specifies number of weeks (default 1).
814 The calendar shows holiday and diary entries if
815 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
816 It does not show hours of the day."
817 (interactive "p")
818 (let* ((n (or arg 1))
819 (date (calendar-gregorian-from-absolute
820 (calendar-dayname-on-or-before
822 (calendar-absolute-from-gregorian
823 (calendar-cursor-to-date t)))))
824 (month (extract-calendar-month date))
825 (year (extract-calendar-year date))
826 (day (extract-calendar-day date))
827 (d1 (calendar-absolute-from-gregorian date))
828 (d2 (+ (* 7 n) d1))
829 (holidays (if cal-tex-holidays
830 (cal-tex-list-holidays d1 d2)))
831 (diary-list (if cal-tex-diary
832 (cal-tex-list-diary-entries
833 ;; FIXME d1?
834 (calendar-absolute-from-gregorian (list month 1 year))
835 d2)))
837 (cal-tex-preamble "11pt")
838 (cal-tex-cmd "\\textwidth 6.5in")
839 (cal-tex-cmd "\\textheight 10.5in")
840 (cal-tex-cmd "\\oddsidemargin 0in")
841 (cal-tex-cmd "\\evensidemargin 0in")
842 (cal-tex-b-document)
843 (cal-tex-cmd "\\pagestyle{empty}")
844 (dotimes (i n)
845 (cal-tex-vspace "-1.5in")
846 (cal-tex-b-center)
847 (cal-tex-Huge-bf
848 (let ((d (calendar-iso-from-absolute
849 (calendar-absolute-from-gregorian date))))
850 (format "Week %d of %d"
851 (extract-calendar-month d)
852 (extract-calendar-year d))))
853 (cal-tex-nl ".5cm")
854 (cal-tex-e-center)
855 (cal-tex-b-parbox "l" "\\textwidth")
856 (dotimes (j 7)
857 (cal-tex-b-parbox "t" "\\textwidth")
858 (cal-tex-b-parbox "t" "\\textwidth")
859 (cal-tex-rule "0pt" "\\textwidth" ".2mm")
860 (cal-tex-nl)
861 (cal-tex-b-parbox "t" "\\textwidth")
862 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date)))
863 (insert ", ")
864 (cal-tex-large-bf (cal-tex-month-name month))
865 (insert " ")
866 (cal-tex-large-bf (number-to-string day))
867 (unless (string-equal "" (setq s (cal-tex-latexify-list
868 holidays date "; ")))
869 (insert ": ")
870 (cal-tex-large-bf s))
871 (cal-tex-hfill)
872 (insert " " (eval cal-tex-daily-string))
873 (cal-tex-e-parbox)
874 (cal-tex-nl)
875 (cal-tex-noindent)
876 (cal-tex-b-parbox "t" "\\textwidth")
877 (unless (string-equal "" (setq s (cal-tex-latexify-list
878 diary-list date)))
879 (insert "\\vbox to 0pt{")
880 (cal-tex-large-bf s)
881 (insert "}"))
882 (cal-tex-e-parbox)
883 (cal-tex-nl)
884 (setq date (cal-tex-incr-date date)
885 month (extract-calendar-month date)
886 day (extract-calendar-day date))
887 (cal-tex-e-parbox)
888 (cal-tex-e-parbox "2cm")
889 (cal-tex-nl)
890 (setq month (extract-calendar-month date)
891 year (extract-calendar-year date)))
892 (cal-tex-e-parbox)
893 (unless (= i (1- n))
894 (run-hooks 'cal-tex-week-hook)
895 (cal-tex-newpage)))
896 (cal-tex-end-document)
897 (run-hooks 'cal-tex-hook)))
899 ;; TODO respect cal-tex-daily-start,end?
900 ;; Using different numbers of hours will probably break some layouts.
901 (defun cal-tex-week-hours (date holidays height)
902 "Insert hourly entries for DATE with HOLIDAYS, with line height HEIGHT.
903 Uses the 24-hour clock if `cal-tex-24' is non-nil. Note that the hours
904 shown are hard-coded to 8-12, 13-17."
905 (let ((month (extract-calendar-month date))
906 (day (extract-calendar-day date))
907 (year (extract-calendar-year date))
908 morning afternoon s)
909 (cal-tex-comment "begin cal-tex-week-hours")
910 (cal-tex-cmd "\\ \\\\[-.2cm]")
911 (cal-tex-cmd "\\noindent")
912 (cal-tex-b-parbox "l" "6.8in")
913 (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date)))
914 (insert ", ")
915 (cal-tex-large-bf (cal-tex-month-name month))
916 (insert " ")
917 (cal-tex-large-bf (number-to-string day))
918 (unless (string-equal "" (setq s (cal-tex-latexify-list
919 holidays date "; ")))
920 (insert ": ")
921 (cal-tex-large-bf s))
922 (cal-tex-hfill)
923 (insert " " (eval cal-tex-daily-string))
924 (cal-tex-e-parbox)
925 (cal-tex-nl "-.3cm")
926 (cal-tex-rule "0pt" "6.8in" ".2mm")
927 (cal-tex-nl "-.1cm")
928 (dotimes (i 5)
929 (setq morning (+ i 8) ; 8-12 incl
930 afternoon (if cal-tex-24
931 (+ i 13) ; 13-17 incl
932 (1+ i))) ; 1-5 incl
933 (cal-tex-cmd "\\hourbox" (number-to-string morning))
934 (cal-tex-arg height)
935 (cal-tex-hspace ".4cm")
936 (cal-tex-cmd "\\hourbox" (number-to-string afternoon))
937 (cal-tex-arg height)
938 (cal-tex-nl))))
940 ;; TODO cal-tex-diary support.
941 ;; TODO respect cal-tex-daily-start,end (see cal-tex-weekly4-box).
942 ;;;###cal-autoload
943 (defun cal-tex-cursor-week-monday (&optional arg)
944 "Make a LaTeX calendar buffer for a two-page one-week calendar.
945 It applies to the week that point is in, and starts on Monday.
946 Optional prefix argument ARG specifies number of weeks (default 1).
947 The calendar shows holidays if `cal-tex-holidays' is
948 non-nil (note that diary entries are not shown). The calendar shows
949 the hours 8-12am, 1-5pm."
950 (interactive "p")
951 (let ((n (or arg 1))
952 (date (calendar-gregorian-from-absolute
953 (calendar-dayname-on-or-before
955 (calendar-absolute-from-gregorian
956 (calendar-cursor-to-date t))))))
957 (cal-tex-preamble "11pt")
958 (cal-tex-cmd "\\textwidth 6.5in")
959 (cal-tex-cmd "\\textheight 10.5in")
960 (cal-tex-cmd "\\oddsidemargin 0in")
961 (cal-tex-cmd "\\evensidemargin 0in")
962 (cal-tex-b-document)
963 (dotimes (i n)
964 (cal-tex-vspace "-1cm")
965 (insert "\\noindent ")
966 (cal-tex-weekly4-box (cal-tex-incr-date date) nil)
967 (cal-tex-weekly4-box (cal-tex-incr-date date 4) nil)
968 (cal-tex-nl ".2cm")
969 (cal-tex-weekly4-box (cal-tex-incr-date date 2) nil)
970 (cal-tex-weekly4-box (cal-tex-incr-date date 5) nil)
971 (cal-tex-nl ".2cm")
972 (cal-tex-weekly4-box (cal-tex-incr-date date 3) nil)
973 (cal-tex-weekly4-box (cal-tex-incr-date date 6) t)
974 (unless (= i (1- n))
975 (run-hooks 'cal-tex-week-hook)
976 (setq date (cal-tex-incr-date date 7))
977 (cal-tex-newpage)))
978 (cal-tex-end-document)
979 (run-hooks 'cal-tex-hook)))
981 ;; TODO respect cal-tex-daily-start,end?
982 ;; Using different numbers of hours will probably break some layouts.
983 (defun cal-tex-weekly4-box (date weekend)
984 "Make one box for DATE, different if WEEKEND.
985 Uses the 24-hour clock if `cal-tex-24' is non-nil. Note that the hours
986 shown are hard-coded to 8-12, 13-17."
987 (let* ((day (extract-calendar-day date))
988 (month (extract-calendar-month date))
989 (year (extract-calendar-year date))
990 (dayname (cal-tex-LaTeXify-string (calendar-day-name date)))
991 (date1 (cal-tex-incr-date date))
992 (day1 (extract-calendar-day date1))
993 (month1 (extract-calendar-month date1))
994 (year1 (extract-calendar-year date1))
995 (dayname1 (cal-tex-LaTeXify-string (calendar-day-name date1))))
996 (cal-tex-b-framebox "8cm" "l")
997 (cal-tex-b-parbox "b" "7.5cm")
998 (insert (format "\\textbf{\\Large %s,} %s/%s/%s\\\\\n"
999 dayname month day year))
1000 (cal-tex-rule "0pt" "7.5cm" ".5mm")
1001 (cal-tex-nl)
1002 (unless weekend
1003 (dotimes (i 5)
1004 (insert (format "\\textsf{\\large %d}\\\\\n" (+ i 8))))
1005 (dotimes (i 5)
1006 (insert (format "\\textsf{\\large %d}\\\\\n"
1007 (if cal-tex-24
1008 (+ i 13) ; 13-17 incl
1009 (1+ i)))))) ; 1-5 incl
1010 (cal-tex-nl ".5cm")
1011 (when weekend
1012 (cal-tex-vspace "1cm")
1013 (insert "\\ \\vfill")
1014 (insert (format "\\textbf{\\Large %s,} %s/%s/%s\\\\\n"
1015 dayname1 month1 day1 year1))
1016 (cal-tex-rule "0pt" "7.5cm" ".5mm")
1017 (cal-tex-nl "1.5cm")
1018 (cal-tex-vspace "1cm"))
1019 (cal-tex-e-parbox)
1020 (cal-tex-e-framebox)
1021 (cal-tex-hspace "1cm")))
1023 ;;;###cal-autoload
1024 (defun cal-tex-cursor-filofax-2week (&optional arg)
1025 "Two-weeks-at-a-glance Filofax style calendar for week cursor is in.
1026 Optional prefix argument ARG specifies number of weeks (default 1).
1027 The calendar shows holiday and diary entries if
1028 `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil."
1029 (interactive "p")
1030 (let* ((n (or arg 1))
1031 (date (calendar-gregorian-from-absolute
1032 (calendar-dayname-on-or-before
1033 calendar-week-start-day
1034 (calendar-absolute-from-gregorian
1035 (calendar-cursor-to-date t)))))
1036 (month (extract-calendar-month date))
1037 (year (extract-calendar-year date))
1038 (day (extract-calendar-day date))
1039 (d1 (calendar-absolute-from-gregorian date))
1040 (d2 (+ (* 7 n) d1))
1041 (holidays (if cal-tex-holidays
1042 (cal-tex-list-holidays d1 d2)))
1043 (diary-list (if cal-tex-diary
1044 (cal-tex-list-diary-entries
1045 ;; FIXME d1?
1046 (calendar-absolute-from-gregorian (list month 1 year))
1047 d2))))
1048 (cal-tex-preamble "twoside")
1049 (cal-tex-cmd "\\textwidth 3.25in")
1050 (cal-tex-cmd "\\textheight 6.5in")
1051 (cal-tex-cmd "\\oddsidemargin 1.75in")
1052 (cal-tex-cmd "\\evensidemargin 1.5in")
1053 (cal-tex-cmd "\\topmargin 0pt")
1054 (cal-tex-cmd "\\headheight -0.875in")
1055 (cal-tex-cmd "\\headsep 0.125in")
1056 (cal-tex-cmd "\\footskip .125in")
1057 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1058 \\long\\def\\rightday#1#2#3#4#5{%
1059 \\rule{\\textwidth}{0.3pt}\\\\%
1060 \\hbox to \\textwidth{%
1061 \\vbox to 0.7in{%
1062 \\vspace*{2pt}%
1063 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1064 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1065 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1066 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1067 \\long\\def\\leftday#1#2#3#4#5{%
1068 \\rule{\\textwidth}{0.3pt}\\\\%
1069 \\hbox to \\textwidth{%
1070 \\vbox to 0.7in{%
1071 \\vspace*{2pt}%
1072 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1073 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1074 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1076 (cal-tex-b-document)
1077 (cal-tex-cmd "\\pagestyle{empty}")
1078 (dotimes (i n)
1079 (if (zerop (mod i 2))
1080 (insert "\\righthead")
1081 (insert "\\lefthead"))
1082 (cal-tex-arg
1083 (let ((d (cal-tex-incr-date date 6)))
1084 (if (= (extract-calendar-month date)
1085 (extract-calendar-month d))
1086 (format "%s %s"
1087 (cal-tex-month-name (extract-calendar-month date))
1088 (extract-calendar-year date))
1089 (if (= (extract-calendar-year date)
1090 (extract-calendar-year d))
1091 (format "%s---%s %s"
1092 (cal-tex-month-name (extract-calendar-month date))
1093 (cal-tex-month-name (extract-calendar-month d))
1094 (extract-calendar-year date))
1095 (format "%s %s---%s %s"
1096 (cal-tex-month-name (extract-calendar-month date))
1097 (extract-calendar-year date)
1098 (cal-tex-month-name (extract-calendar-month d))
1099 (extract-calendar-year d))))))
1100 (insert "%\n")
1101 (dotimes (jdummy 7)
1102 (if (zerop (mod i 2))
1103 (insert "\\rightday")
1104 (insert "\\leftday"))
1105 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1106 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1107 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1108 (cal-tex-arg (cal-tex-latexify-list holidays date))
1109 (cal-tex-arg (eval cal-tex-daily-string))
1110 (insert "%\n")
1111 (setq date (cal-tex-incr-date date)))
1112 (unless (= i (1- n))
1113 (run-hooks 'cal-tex-week-hook)
1114 (cal-tex-newpage)))
1115 (cal-tex-end-document)
1116 (run-hooks 'cal-tex-hook)))
1118 ;;;###cal-autoload
1119 (defun cal-tex-cursor-filofax-week (&optional arg)
1120 "One-week-at-a-glance Filofax style calendar for week indicated by cursor.
1121 Optional prefix argument ARG specifies number of weeks (default 1),
1122 starting on Mondays. The calendar shows holiday and diary entries
1123 if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil."
1124 (interactive "p")
1125 (let* ((n (or arg 1))
1126 (date (calendar-gregorian-from-absolute
1127 (calendar-dayname-on-or-before
1129 (calendar-absolute-from-gregorian
1130 (calendar-cursor-to-date t)))))
1131 (month (extract-calendar-month date))
1132 (year (extract-calendar-year date))
1133 (day (extract-calendar-day date))
1134 (d1 (calendar-absolute-from-gregorian date))
1135 (d2 (+ (* 7 n) d1))
1136 (holidays (if cal-tex-holidays
1137 (cal-tex-list-holidays d1 d2)))
1138 (diary-list (if cal-tex-diary
1139 (cal-tex-list-diary-entries
1140 ;; FIXME d1?
1141 (calendar-absolute-from-gregorian (list month 1 year))
1142 d2))))
1143 (cal-tex-preamble "twoside")
1144 (cal-tex-cmd "\\textwidth 3.25in")
1145 (cal-tex-cmd "\\textheight 6.5in")
1146 (cal-tex-cmd "\\oddsidemargin 1.75in")
1147 (cal-tex-cmd "\\evensidemargin 1.5in")
1148 (cal-tex-cmd "\\topmargin 0pt")
1149 (cal-tex-cmd "\\headheight -0.875in")
1150 (cal-tex-cmd "\\headsep 0.125in")
1151 (cal-tex-cmd "\\footskip .125in")
1152 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1153 \\long\\def\\rightday#1#2#3#4#5{%
1154 \\rule{\\textwidth}{0.3pt}\\\\%
1155 \\hbox to \\textwidth{%
1156 \\vbox to 1.85in{%
1157 \\vspace*{2pt}%
1158 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1159 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1160 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1161 \\long\\def\\weekend#1#2#3#4#5{%
1162 \\rule{\\textwidth}{0.3pt}\\\\%
1163 \\hbox to \\textwidth{%
1164 \\vbox to .8in{%
1165 \\vspace*{2pt}%
1166 \\hbox to \\textwidth{\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%
1167 \\hbox to \\textwidth{\\vbox {\\raggedleft \\footnotesize \\em #4}}%
1168 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1169 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1170 \\long\\def\\leftday#1#2#3#4#5{%
1171 \\rule{\\textwidth}{0.3pt}\\\\%
1172 \\hbox to \\textwidth{%
1173 \\vbox to 1.85in{%
1174 \\vspace*{2pt}%
1175 \\hbox to \\textwidth{\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%
1176 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize \\em #4}}%
1177 \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}
1179 (cal-tex-b-document)
1180 (cal-tex-cmd "\\pagestyle{empty}\\ ")
1181 (cal-tex-newpage)
1182 (dotimes (i n)
1183 (insert "\\lefthead")
1184 (cal-tex-arg
1185 (let ((d (cal-tex-incr-date date 2)))
1186 (if (= (extract-calendar-month date)
1187 (extract-calendar-month d))
1188 (format "%s %s"
1189 (cal-tex-month-name (extract-calendar-month date))
1190 (extract-calendar-year date))
1191 (if (= (extract-calendar-year date)
1192 (extract-calendar-year d))
1193 (format "%s---%s %s"
1194 (cal-tex-month-name (extract-calendar-month date))
1195 (cal-tex-month-name (extract-calendar-month d))
1196 (extract-calendar-year date))
1197 (format "%s %s---%s %s"
1198 (cal-tex-month-name (extract-calendar-month date))
1199 (extract-calendar-year date)
1200 (cal-tex-month-name (extract-calendar-month d))
1201 (extract-calendar-year d))))))
1202 (insert "%\n")
1203 (dotimes (jdummy 3)
1204 (insert "\\leftday")
1205 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1206 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1207 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1208 (cal-tex-arg (cal-tex-latexify-list holidays date))
1209 (cal-tex-arg (eval cal-tex-daily-string))
1210 (insert "%\n")
1211 (setq date (cal-tex-incr-date date)))
1212 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
1213 (cal-tex-newpage)
1214 (insert "\\righthead")
1215 (cal-tex-arg
1216 (let ((d (cal-tex-incr-date date 3)))
1217 (if (= (extract-calendar-month date)
1218 (extract-calendar-month d))
1219 (format "%s %s"
1220 (cal-tex-month-name (extract-calendar-month date))
1221 (extract-calendar-year date))
1222 (if (= (extract-calendar-year date)
1223 (extract-calendar-year d))
1224 (format "%s---%s %s"
1225 (cal-tex-month-name (extract-calendar-month date))
1226 (cal-tex-month-name (extract-calendar-month d))
1227 (extract-calendar-year date))
1228 (format "%s %s---%s %s"
1229 (cal-tex-month-name (extract-calendar-month date))
1230 (extract-calendar-year date)
1231 (cal-tex-month-name (extract-calendar-month d))
1232 (extract-calendar-year d))))))
1233 (insert "%\n")
1234 (dotimes (jdummy 2)
1235 (insert "\\rightday")
1236 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1237 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1238 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1239 (cal-tex-arg (cal-tex-latexify-list holidays date))
1240 (cal-tex-arg (eval cal-tex-daily-string))
1241 (insert "%\n")
1242 (setq date (cal-tex-incr-date date)))
1243 (dotimes (jdummy 2)
1244 (insert "\\weekend")
1245 (cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
1246 (cal-tex-arg (int-to-string (extract-calendar-day date)))
1247 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1248 (cal-tex-arg (cal-tex-latexify-list holidays date))
1249 (cal-tex-arg (eval cal-tex-daily-string))
1250 (insert "%\n")
1251 (setq date (cal-tex-incr-date date)))
1252 (unless (= i (1- n))
1253 (run-hooks 'cal-tex-week-hook)
1254 (cal-tex-newpage)))
1255 (cal-tex-end-document)
1256 (run-hooks 'cal-tex-hook)))
1258 ;;;###cal-autoload
1259 (defun cal-tex-cursor-filofax-daily (&optional arg)
1260 "Day-per-page Filofax style calendar for week indicated by cursor.
1261 Optional prefix argument ARG specifies number of weeks (default 1),
1262 starting on Mondays. The calendar shows holiday and diary
1263 entries if `cal-tex-holidays' and `cal-tex-diary', respectively,
1264 are non-nil. Pages are ruled if `cal-tex-rules' is non-nil."
1265 (interactive "p")
1266 (let* ((n (or arg 1))
1267 (date (calendar-gregorian-from-absolute
1268 (calendar-dayname-on-or-before
1270 (calendar-absolute-from-gregorian
1271 (calendar-cursor-to-date t)))))
1272 (month (extract-calendar-month date))
1273 (year (extract-calendar-year date))
1274 (day (extract-calendar-day date))
1275 (d1 (calendar-absolute-from-gregorian date))
1276 (d2 (+ (* 7 n) d1))
1277 (holidays (if cal-tex-holidays
1278 (cal-tex-list-holidays d1 d2)))
1279 (diary-list (if cal-tex-diary
1280 (cal-tex-list-diary-entries
1281 ;; FIXME d1?
1282 (calendar-absolute-from-gregorian (list month 1 year))
1283 d2))))
1284 (cal-tex-preamble "twoside")
1285 (cal-tex-cmd "\\textwidth 3.25in")
1286 (cal-tex-cmd "\\textheight 6.5in")
1287 (cal-tex-cmd "\\oddsidemargin 1.75in")
1288 (cal-tex-cmd "\\evensidemargin 1.5in")
1289 (cal-tex-cmd "\\topmargin 0pt")
1290 (cal-tex-cmd "\\headheight -0.875in")
1291 (cal-tex-cmd "\\headsep 0.125in")
1292 (cal-tex-cmd "\\footskip .125in")
1293 (insert "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}
1294 \\long\\def\\rightday#1#2#3{%
1295 \\rule{\\textwidth}{0.3pt}\\\\%
1296 \\hbox to \\textwidth{%
1297 \\vbox {%
1298 \\vspace*{2pt}%
1299 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1300 \\hbox to \\textwidth{\\vbox {\\raggedleft \\em #2}}%
1301 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1302 \\long\\def\\weekend#1#2#3{%
1303 \\rule{\\textwidth}{0.3pt}\\\\%
1304 \\hbox to \\textwidth{%
1305 \\vbox {%
1306 \\vspace*{2pt}%
1307 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1308 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1309 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1310 \\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}
1311 \\long\\def\\leftday#1#2#3{%
1312 \\rule{\\textwidth}{0.3pt}\\\\%
1313 \\hbox to \\textwidth{%
1314 \\vbox {%
1315 \\vspace*{2pt}%
1316 \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
1317 \\hbox to \\textwidth{\\vbox {\\noindent \\em #2}}%
1318 \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}
1319 \\newbox\\LineBox
1320 \\setbox\\LineBox=\\hbox to\\textwidth{%
1321 \\vrule height.2in width0pt\\leaders\\hrule\\hfill}
1322 \\def\\linesfill{\\par\\leaders\\copy\\LineBox\\vfill}
1324 (cal-tex-b-document)
1325 (cal-tex-cmd "\\pagestyle{empty}")
1326 (dotimes (i n)
1327 (dotimes (j 4)
1328 (let ((even (zerop (% j 2))))
1329 (insert (if even
1330 "\\righthead"
1331 "\\lefthead"))
1332 (cal-tex-arg (calendar-date-string date))
1333 (insert "%\n")
1334 (insert (if even
1335 "\\rightday"
1336 "\\leftday")))
1337 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1338 (cal-tex-arg (cal-tex-latexify-list holidays date "\\\\" t))
1339 (cal-tex-arg (eval cal-tex-daily-string))
1340 (insert "%\n")
1341 (if cal-tex-rules
1342 (insert "\\linesfill\n")
1343 (insert "\\vfill\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1344 (cal-tex-newpage)
1345 (setq date (cal-tex-incr-date date)))
1346 (insert "%\n")
1347 (dotimes (jdummy 2)
1348 (insert "\\lefthead")
1349 (cal-tex-arg (calendar-date-string date))
1350 (insert "\\weekend")
1351 (cal-tex-arg (cal-tex-latexify-list diary-list date))
1352 (cal-tex-arg (cal-tex-latexify-list holidays date "\\\\" t))
1353 (cal-tex-arg (eval cal-tex-daily-string))
1354 (insert "%\n")
1355 (if cal-tex-rules
1356 (insert "\\linesfill\n")
1357 (insert "\\vfill"))
1358 (setq date (cal-tex-incr-date date)))
1359 (or cal-tex-rules
1360 (insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
1361 (unless (= i (1- n))
1362 (run-hooks 'cal-tex-week-hook)
1363 (cal-tex-newpage)))
1364 (cal-tex-end-document)
1365 (run-hooks 'cal-tex-hook)))
1369 ;;; Daily calendars
1372 ;;;###cal-autoload
1373 (defun cal-tex-cursor-day (&optional arg)
1374 "Make a buffer with LaTeX commands for the day cursor is on.
1375 Optional prefix argument ARG specifies number of days. The calendar shows
1376 the hours between `cal-tex-daily-start' and `cal-tex-daily-end', using
1377 the 24-hour clock if `cal-tex-24' is non-nil."
1378 (interactive "p")
1379 (let ((n (or arg 1))
1380 (date (calendar-absolute-from-gregorian (calendar-cursor-to-date t))))
1381 (cal-tex-preamble "12pt")
1382 (cal-tex-cmd "\\textwidth 6.5in")
1383 (cal-tex-cmd "\\textheight 10.5in")
1384 (cal-tex-b-document)
1385 (cal-tex-cmd "\\pagestyle{empty}")
1386 (dotimes (i n)
1387 (cal-tex-vspace "-1.7in")
1388 (cal-tex-daily-page (calendar-gregorian-from-absolute date))
1389 (setq date (1+ date))
1390 (unless (= i (1- n))
1391 (cal-tex-newpage)
1392 (run-hooks 'cal-tex-daily-hook)))
1393 (cal-tex-end-document)
1394 (run-hooks 'cal-tex-hook)))
1396 (defun cal-tex-daily-page (date)
1397 "Make a calendar page for Gregorian DATE on 8.5 by 11 paper.
1398 Uses the 24-hour clock if `cal-tex-24' is non-nil. Produces
1399 hourly sections for the period specified by `cal-tex-daily-start'
1400 and `cal-tex-daily-end'."
1401 (let ((month-name (cal-tex-month-name (extract-calendar-month date)))
1402 hour)
1403 (cal-tex-banner "cal-tex-daily-page")
1404 (cal-tex-b-makebox "4cm" "l")
1405 (cal-tex-b-parbox "b" "3.8cm")
1406 (cal-tex-rule "0mm" "0mm" "2cm")
1407 (cal-tex-Huge (number-to-string (extract-calendar-day date)))
1408 (cal-tex-nl ".5cm")
1409 (cal-tex-bf month-name )
1410 (cal-tex-e-parbox)
1411 (cal-tex-hspace "1cm")
1412 (cal-tex-scriptsize (eval cal-tex-daily-string))
1413 (cal-tex-hspace "3.5cm")
1414 (cal-tex-e-makebox)
1415 (cal-tex-hfill)
1416 (cal-tex-b-makebox "4cm" "r")
1417 (cal-tex-bf (cal-tex-LaTeXify-string (calendar-day-name date)))
1418 (cal-tex-e-makebox)
1419 (cal-tex-nl)
1420 (cal-tex-hspace ".4cm")
1421 (cal-tex-rule "0mm" "16.1cm" "1mm")
1422 (cal-tex-nl ".1cm")
1423 (calendar-for-loop i from cal-tex-daily-start to cal-tex-daily-end do
1424 (cal-tex-cmd "\\noindent")
1425 (setq hour (if cal-tex-24
1427 (mod i 12)))
1428 (if (zerop hour) (setq hour 12))
1429 (cal-tex-b-makebox "1cm" "c")
1430 (cal-tex-arg (number-to-string hour))
1431 (cal-tex-e-makebox)
1432 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1433 (cal-tex-nl ".2cm")
1434 (cal-tex-b-makebox "1cm" "c")
1435 (cal-tex-arg "$\\diamond$" )
1436 (cal-tex-e-makebox)
1437 (cal-tex-rule "0mm" "15.5cm" ".2mm")
1438 (cal-tex-nl ".2cm"))
1439 (cal-tex-hfill)
1440 (insert (cal-tex-mini-calendar
1441 (extract-calendar-month (cal-tex-previous-month date))
1442 (extract-calendar-year (cal-tex-previous-month date))
1443 "lastmonth" "1.1in" "1in"))
1444 (insert (cal-tex-mini-calendar
1445 (extract-calendar-month date)
1446 (extract-calendar-year date)
1447 "thismonth" "1.1in" "1in"))
1448 (insert (cal-tex-mini-calendar
1449 (extract-calendar-month (cal-tex-next-month date))
1450 (extract-calendar-year (cal-tex-next-month date))
1451 "nextmonth" "1.1in" "1in"))
1452 (insert "\\hbox to \\textwidth{")
1453 (cal-tex-hfill)
1454 (insert "\\lastmonth")
1455 (cal-tex-hfill)
1456 (insert "\\thismonth")
1457 (cal-tex-hfill)
1458 (insert "\\nextmonth")
1459 (cal-tex-hfill)
1460 (insert "}")
1461 (cal-tex-banner "end of cal-tex-daily-page")))
1464 ;;; Mini calendars
1467 (defun cal-tex-mini-calendar (month year name width height &optional ptsize colsep)
1468 "Produce mini-calendar for MONTH, YEAR in macro NAME with WIDTH and HEIGHT.
1469 Optional string PTSIZE gives the point size (default \"scriptsize\").
1470 Optional string COLSEP gives the column separation (default \"1mm\")."
1471 (or colsep (setq colsep "1mm"))
1472 (or ptsize (setq ptsize "scriptsize"))
1473 (let ((blank-days ; at start of month
1474 (mod
1475 (- (calendar-day-of-week (list month 1 year))
1476 calendar-week-start-day)
1478 (last (calendar-last-day-of-month month year))
1479 (str (concat "\\def\\" name "{\\hbox to" width "{%\n"
1480 "\\vbox to" height "{%\n"
1481 "\\vfil \\hbox to" width "{%\n"
1482 "\\hfil\\" ptsize
1483 "\\begin{tabular}"
1484 "{@{\\hspace{0mm}}r@{\\hspace{" colsep
1485 "}}r@{\\hspace{" colsep "}}r@{\\hspace{" colsep
1486 "}}r@{\\hspace{" colsep "}}r@{\\hspace{" colsep
1487 "}}r@{\\hspace{" colsep "}}r@{\\hspace{0mm}}}%\n"
1488 "\\multicolumn{7}{c}{"
1489 (cal-tex-month-name month)
1491 (int-to-string year)
1492 "}\\\\[1mm]\n")))
1493 (dotimes (i 7)
1494 (setq str
1495 (concat str
1496 (cal-tex-LaTeXify-string
1497 (substring (aref calendar-day-name-array
1498 (mod (+ calendar-week-start-day i) 7))
1500 0 2))
1501 (if (= i 6)
1502 "\\\\[0.7mm]\n"
1503 " & "))))
1504 (dotimes (idummy blank-days)
1505 (setq str (concat str " & ")))
1506 (dotimes (i last)
1507 (setq str (concat str (int-to-string (1+ i)))
1508 str (concat str (if (zerop (mod (+ i 1 blank-days) 7))
1509 (if (= i (1- last))
1511 "\\\\[0.5mm]\n")
1512 " & "))))
1513 (setq str (concat str "\n\\end{tabular}\\hfil}\\vfil}}}%\n"))
1514 str))
1517 ;;; Various calendar functions
1520 (defun cal-tex-incr-date (date &optional n)
1521 "The date of the day following DATE.
1522 If optional N is given, the date of N days after DATE."
1523 (calendar-gregorian-from-absolute
1524 (+ (or n 1) (calendar-absolute-from-gregorian date))))
1526 (defun cal-tex-latexify-list (date-list date &optional separator final-separator)
1527 "Return string with concatenated, LaTeX-ified entries in DATE-LIST for DATE.
1528 Use double backslash as a separator unless optional SEPARATOR is given.
1529 If resulting string is not empty, put separator at end if optional
1530 FINAL-SEPARATOR is non-nil."
1531 (or separator (setq separator "\\\\"))
1532 (let (result)
1533 (setq result
1534 (mapconcat (lambda (x) (cal-tex-LaTeXify-string x))
1535 (dolist (d date-list (reverse result))
1536 (and (car d)
1537 (calendar-date-equal date (car d))
1538 (setq result (cons (cadr d) result))))
1539 separator))
1540 (if (and final-separator
1541 (not (string-equal result "")))
1542 (concat result separator)
1543 result)))
1545 (defun cal-tex-previous-month (date)
1546 "Return the date of the first day in the month previous to DATE."
1547 (let ((month (extract-calendar-month date))
1548 (year (extract-calendar-year date)))
1549 (increment-calendar-month month year -1)
1550 (list month 1 year)))
1552 (defun cal-tex-next-month (date)
1553 "Return the date of the first day in the month following DATE."
1554 (let ((month (extract-calendar-month date))
1555 (year (extract-calendar-year date)))
1556 (increment-calendar-month month year 1)
1557 (list month 1 year)))
1560 ;;; LaTeX Code
1563 (defun cal-tex-end-document ()
1564 "Finish the LaTeX document.
1565 Insert the trailer to LaTeX document, pop to LaTeX buffer, add
1566 informative header, and run HOOK."
1567 (cal-tex-e-document)
1568 (latex-mode)
1569 (pop-to-buffer cal-tex-buffer)
1570 (goto-char (point-min))
1571 ;; FIXME auctex equivalents?
1572 (cal-tex-comment
1573 (format "\tThis buffer was produced by cal-tex.el.
1574 \tTo print a calendar, type
1575 \t\tM-x tex-buffer RET
1576 \t\tM-x tex-print RET")))
1578 (defun cal-tex-insert-preamble (weeks landscape size &optional append)
1579 "Initialize the output LaTeX calendar buffer, `cal-tex-buffer'.
1580 Select the output buffer, and insert the preamble for a calendar
1581 of WEEKS weeks. Insert code for landscape mode if LANDSCAPE is
1582 non-nil. Use pointsize SIZE. Optional argument APPEND, if
1583 non-nil, means add to end of buffer without erasing current contents."
1584 (let ((width "18cm")
1585 (height "24cm"))
1586 (when landscape
1587 (setq width "24cm"
1588 height "18cm"))
1589 (unless append
1590 (cal-tex-preamble size)
1591 (if (not landscape)
1592 (progn
1593 (cal-tex-cmd "\\oddsidemargin -1.75cm")
1594 (cal-tex-cmd "\\def\\holidaymult{.06}"))
1595 (cal-tex-cmd "\\special{landscape}")
1596 (cal-tex-cmd "\\textwidth 9.5in")
1597 (cal-tex-cmd "\\textheight 7in")
1598 (cal-tex-comment)
1599 (cal-tex-cmd "\\def\\holidaymult{.08}"))
1600 (cal-tex-cmd cal-tex-caldate)
1601 (cal-tex-cmd cal-tex-myday)
1602 (cal-tex-b-document)
1603 (cal-tex-cmd "\\pagestyle{empty}"))
1604 (cal-tex-cmd "\\setlength{\\cellwidth}" width)
1605 (insert (format "\\setlength{\\cellwidth}{%f\\cellwidth}\n"
1606 (/ 1.1 (length cal-tex-which-days))))
1607 (cal-tex-cmd "\\setlength{\\cellheight}" height)
1608 (insert (format "\\setlength{\\cellheight}{%f\\cellheight}\n"
1609 (/ 1.0 weeks)))
1610 (cal-tex-cmd "\\ \\par")
1611 (cal-tex-vspace "-3cm")))
1613 (defconst cal-tex-LaTeX-subst-list
1614 '(("\"". "``")
1615 ("\"". "''") ; quote changes meaning when list is reversed
1616 ;; Don't think this is necessary, and in any case, does not work:
1617 ;; "LaTeX Error: \verb illegal in command argument".
1618 ;;; ("@" . "\\verb|@|")
1619 ("&" . "\\&")
1620 ("%" . "\\%")
1621 ("$" . "\\$")
1622 ("#" . "\\#")
1623 ("_" . "\\_")
1624 ("{" . "\\{")
1625 ("}" . "\\}")
1626 ("<" . "$<$")
1627 (">" . "$>$")
1628 ("\n" . "\\ \\\\")) ; \\ needed for e.g \begin{center}\n AA\end{center}
1629 "Alist of symbols and their LaTeX replacements.")
1631 (defun cal-tex-LaTeXify-string (string)
1632 "Protect special characters in STRING from LaTeX."
1633 (if (not string)
1635 (let ((head "")
1636 (tail string)
1637 (list cal-tex-LaTeX-subst-list))
1638 (while (not (string-equal tail ""))
1639 (let* ((ch (substring-no-properties tail 0 1))
1640 (pair (assoc ch list)))
1641 (if (and pair (string-equal ch "\""))
1642 (setq list (reverse list))) ; quote changes meaning each time
1643 (setq tail (substring-no-properties tail 1)
1644 head (concat head (if pair (cdr pair) ch)))))
1645 head)))
1647 (defun cal-tex-month-name (month)
1648 "The name of MONTH, LaTeXified."
1649 (cal-tex-LaTeXify-string (calendar-month-name month)))
1651 (defun cal-tex-hfill ()
1652 "Insert hfill."
1653 (insert "\\hfill"))
1655 (defun cal-tex-newpage ()
1656 "Insert newpage."
1657 (insert "\\newpage%\n"))
1659 (defun cal-tex-noindent ()
1660 "Insert noindent."
1661 (insert "\\noindent"))
1663 (defun cal-tex-vspace (space)
1664 "Insert vspace command to move SPACE vertically."
1665 (insert "\\vspace*{" space "}")
1666 (cal-tex-comment))
1668 (defun cal-tex-hspace (space)
1669 "Insert hspace command to move SPACE horizontally."
1670 (insert "\\hspace*{" space "}")
1671 (cal-tex-comment))
1673 (defun cal-tex-comment (&optional comment)
1674 "Insert `% ', followed by optional string COMMENT, followed by newline.
1675 COMMENT may contain newlines, which are prefixed by `% ' in the output."
1676 (insert (format "%% %s\n"
1677 (if comment
1678 (replace-regexp-in-string "\n" "\n% " comment)
1679 ""))))
1681 (defun cal-tex-banner (comment)
1682 "Insert string COMMENT, separated by blank lines."
1683 (cal-tex-comment (format "\n\n\n\t\t\t%s\n" comment)))
1685 (defun cal-tex-nl (&optional skip comment)
1686 "End a line with \\. If SKIP, then add that much spacing.
1687 Add trailing COMMENT if present."
1688 (insert (format "\\\\%s"
1689 (if skip
1690 (format "[%s]" skip)
1691 "")))
1692 (cal-tex-comment comment))
1694 (defun cal-tex-arg (&optional text)
1695 "Insert a brace {} pair containing the optional string TEXT."
1696 (insert (format "{%s}" (or text ""))))
1698 (defun cal-tex-cmd (cmd &optional arg)
1699 "Insert LaTeX CMD, with optional argument ARG, and end with %."
1700 (insert cmd)
1701 (cal-tex-arg arg)
1702 (cal-tex-comment))
1705 ;;; Environments
1708 (defun cal-tex-b-document ()
1709 "Insert beginning of document."
1710 (cal-tex-cmd "\\begin{document}"))
1712 (defun cal-tex-e-document ()
1713 "Insert end of document."
1714 (cal-tex-cmd "\\end{document}"))
1716 (defun cal-tex-b-center ()
1717 "Insert beginning of centered block."
1718 (cal-tex-cmd "\\begin{center}"))
1720 (defun cal-tex-e-center ()
1721 "Insert end of centered block."
1722 (cal-tex-comment)
1723 (cal-tex-cmd "\\end{center}"))
1727 ;;; Boxes
1731 (defun cal-tex-b-parbox (position width)
1732 "Insert parbox with parameters POSITION and WIDTH."
1733 (insert "\\parbox[" position "]{" width "}{")
1734 (cal-tex-comment))
1736 (defun cal-tex-e-parbox (&optional height)
1737 "Insert end of parbox. Optionally, force it to be a given HEIGHT."
1738 (cal-tex-comment)
1739 (if height
1740 (cal-tex-rule "0mm" "0mm" height))
1741 (insert "}")
1742 (cal-tex-comment "end parbox"))
1744 (defun cal-tex-b-framebox (width position)
1745 "Insert framebox with parameters WIDTH and POSITION (clr)."
1746 (insert "\\framebox[" width "][" position "]{" )
1747 (cal-tex-comment))
1749 (defun cal-tex-e-framebox ()
1750 "Insert end of framebox."
1751 (cal-tex-comment)
1752 (insert "}")
1753 (cal-tex-comment "end framebox"))
1756 (defun cal-tex-b-makebox ( width position )
1757 "Insert makebox with parameters WIDTH and POSITION (clr)."
1758 (insert "\\makebox[" width "][" position "]{" )
1759 (cal-tex-comment))
1761 (defun cal-tex-e-makebox ()
1762 "Insert end of makebox."
1763 (cal-tex-comment)
1764 (insert "}")
1765 (cal-tex-comment "end makebox"))
1768 (defun cal-tex-rule (lower width height)
1769 "Insert a rule with parameters LOWER WIDTH HEIGHT."
1770 (insert "\\rule[" lower "]{" width "}{" height "}"))
1773 ;;; Fonts
1776 (defun cal-tex-em (string)
1777 "Insert STRING in italic font."
1778 (insert "\\textit{" string "}"))
1780 (defun cal-tex-bf (string)
1781 "Insert STRING in bf font."
1782 (insert "\\textbf{ " string "}"))
1784 (defun cal-tex-scriptsize (string)
1785 "Insert STRING in scriptsize font."
1786 (insert "{\\scriptsize " string "}"))
1788 (defun cal-tex-huge (string)
1789 "Insert STRING in huge font."
1790 (insert "{\\huge " string "}"))
1792 (defun cal-tex-Huge (string)
1793 "Insert STRING in Huge font."
1794 (insert "{\\Huge " string "}"))
1796 (defun cal-tex-Huge-bf (string)
1797 "Insert STRING in Huge bf font."
1798 (insert "\\textbf{\\Huge " string "}"))
1800 (defun cal-tex-large (string)
1801 "Insert STRING in large font."
1802 (insert "{\\large " string "}"))
1804 (defun cal-tex-large-bf (string)
1805 "Insert STRING in large bf font."
1806 (insert "\\textbf{\\large " string "}"))
1809 (provide 'cal-tex)
1811 ;; arch-tag: ca8168a4-5a00-4508-a565-17e3bccce6d0
1812 ;;; cal-tex.el ends here