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