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