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