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