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