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