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