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