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