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