cal-tex.el 69.1 KB
Newer Older
1
;;; cal-tex.el --- calendar functions for printing calendars with LaTeX
Edward M. Reingold's avatar
Edward M. Reingold committed
2

Paul Eggert's avatar
Paul Eggert committed
3
;; Copyright (C) 1995, 2001-2019 Free Software Foundation, Inc.
Edward M. Reingold's avatar
Edward M. Reingold committed
4 5

;; Author: Steve Fisk <fisk@bowdoin.edu>
6
;;         Edward M. Reingold <reingold@cs.uiuc.edu>
Glenn Morris's avatar
Glenn Morris committed
7
;; Maintainer: emacs-devel@gnu.org
Edward M. Reingold's avatar
Edward M. Reingold committed
8 9
;; Keywords: calendar
;; Human-Keywords: Calendar, LaTeX
10
;; Package: calendar
Edward M. Reingold's avatar
Edward M. Reingold committed
11 12 13

;; This file is part of GNU Emacs.

14
;; GNU Emacs is free software: you can redistribute it and/or modify
Edward M. Reingold's avatar
Edward M. Reingold committed
15
;; it under the terms of the GNU General Public License as published by
16 17
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
Edward M. Reingold's avatar
Edward M. Reingold committed
18 19 20 21 22 23 24

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
25
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
Edward M. Reingold's avatar
Edward M. Reingold committed
26 27 28

;;; Commentary:

Edward M. Reingold's avatar
Edward M. Reingold committed
29 30
;; This collection of functions implements the creation of LaTeX calendars
;; based on the user's holiday choices and diary file.
Edward M. Reingold's avatar
Edward M. Reingold committed
31

32 33 34 35 36 37 38 39
;; The user commands are:
;; cal-tex-cursor-year
;; cal-tex-cursor-year-landscape
;; cal-tex-cursor-filofax-year
;; cal-tex-cursor-month-landscape
;; cal-tex-cursor-month
;; cal-tex-cursor-week
;; cal-tex-cursor-week2
40
;; cal-tex-cursor-week2-summary
41 42 43 44 45 46 47
;; cal-tex-cursor-week-iso
;; cal-tex-cursor-week-monday
;; cal-tex-cursor-filofax-2week
;; cal-tex-cursor-filofax-week
;; cal-tex-cursor-filofax-daily
;; cal-tex-cursor-day

Erik Naggum's avatar
Erik Naggum committed
48 49 50 51 52 53 54 55
;; TO DO
;;
;;     (*)  Add holidays and diary entries to daily calendar.
;;
;;     (*)  Add diary entries to weekly calendar functions.
;;
;;     (*)  Make calendar styles for A4 paper.
;;
56
;;     (*)  Make monthly styles Filofax paper.
Edward M. Reingold's avatar
Edward M. Reingold committed
57 58 59 60 61 62

;;; Code:

(require 'calendar)

;;;
63
;;; Customizable variables
Edward M. Reingold's avatar
Edward M. Reingold committed
64 65
;;;

66 67 68 69 70
(defgroup calendar-tex nil
  "Options for printing calendar with LaTeX."
  :prefix "cal-tex-"
  :group 'calendar)

Richard M. Stallman's avatar
Richard M. Stallman committed
71
(defcustom cal-tex-which-days '(0 1 2 3 4 5 6)
72
  "The days of the week that are displayed on the portrait monthly calendar.
Edward M. Reingold's avatar
Edward M. Reingold committed
73
Sunday is 0, Monday is 1, and so on.  The default is to print from Sunday to
74
Saturday.  For example, use '(1 3 5) to only print Monday, Wednesday, Friday."
Richard M. Stallman's avatar
Richard M. Stallman committed
75 76
  :type '(repeat integer)
  :group 'calendar-tex)
Edward M. Reingold's avatar
Edward M. Reingold committed
77

Richard M. Stallman's avatar
Richard M. Stallman committed
78
(defcustom cal-tex-holidays t
79
  "Non-nil means holidays are printed in the LaTeX calendars that support it.
80
Setting this to nil may speed up calendar generation."
Richard M. Stallman's avatar
Richard M. Stallman committed
81 82
  :type 'boolean
  :group 'calendar-tex)
Edward M. Reingold's avatar
Edward M. Reingold committed
83

Richard M. Stallman's avatar
Richard M. Stallman committed
84
(defcustom cal-tex-diary nil
85
  "Non-nil means diary entries are printed in LaTeX calendars that support it.
86
Setting this to nil may speed up calendar generation."
Richard M. Stallman's avatar
Richard M. Stallman committed
87 88
  :type 'boolean
  :group 'calendar-tex)
Edward M. Reingold's avatar
Edward M. Reingold committed
89

90
(defcustom cal-tex-rules nil
91 92
  "Non-nil means pages will be ruled in some LaTeX calendar styles.
At present, this only affects the daily filofax calendar."
93 94 95
  :type 'boolean
  :group 'calendar-tex)

Richard M. Stallman's avatar
Richard M. Stallman committed
96
(defcustom cal-tex-daily-string
97
  '(let* ((year (calendar-extract-year date))
98
          (day (calendar-day-number date))
Edward M. Reingold's avatar
Edward M. Reingold committed
99
          (days-remaining (- (calendar-day-number (list 12 31 year)) day)))
100
     (format "%d/%d" day days-remaining))
101 102
  "Lisp expression giving the date format to use in the LaTeX calendars.
This should be an expression involving the variable `date'.  When
103
this expression is called, `date' is a list of the form `(MONTH DAY YEAR)'.
104 105 106 107

The string resulting from evaluating this expression is placed at
the bottom center of each date in monthly calendars, next to the
date in the weekly calendars, and in the top center of daily calendars.
Edward M. Reingold's avatar
Edward M. Reingold committed
108

109 110
The default is ordinal day number of the year and the number of
days remaining.  As an example, setting this to
Edward M. Reingold's avatar
Edward M. Reingold committed
111

112
    '(calendar-hebrew-date-string date)
Edward M. Reingold's avatar
Edward M. Reingold committed
113

Richard M. Stallman's avatar
Richard M. Stallman committed
114 115 116 117 118
will put the Hebrew date at the bottom of each day."
  :type 'sexp
  :group 'calendar-tex)

(defcustom cal-tex-buffer "calendar.tex"
119
  "The name for the output LaTeX calendar buffer."
Richard M. Stallman's avatar
Richard M. Stallman committed
120 121 122 123
  :type 'string
  :group 'calendar-tex)

(defcustom cal-tex-24 nil
124
  "Non-nil means use a 24 hour clock in the daily calendar."
Richard M. Stallman's avatar
Richard M. Stallman committed
125 126 127 128
  :type 'boolean
  :group 'calendar-tex)

(defcustom cal-tex-daily-start 8
129 130
  "The first hour of the daily LaTeX calendar page.
At present, this only affects `cal-tex-cursor-day'."
Richard M. Stallman's avatar
Richard M. Stallman committed
131 132 133 134
  :type 'integer
  :group 'calendar-tex)

(defcustom cal-tex-daily-end 20
135
  "The last hour of the daily LaTeX calendar page.
Juanma Barranquero's avatar
Juanma Barranquero committed
136
At present, this only affects `cal-tex-cursor-day'."
Richard M. Stallman's avatar
Richard M. Stallman committed
137 138
  :type 'integer
  :group 'calendar-tex)
Edward M. Reingold's avatar
Edward M. Reingold committed
139

140 141 142 143
(defcustom cal-tex-preamble-extra nil
  "A string giving extra LaTeX commands to insert in the calendar preamble.
For example, to include extra packages:
\"\\\\usepackage{foo}\\n\\\\usepackage{bar}\\n\"."
144 145 146
  :type '(choice (const nil)
                 ;; An example to help people format things in custom.
                 (string :value "\\usepackage{foo}\n\\usepackage{bar}\n"))
147 148 149
  :group 'calendar-tex
  :version "22.1")

150
(defcustom cal-tex-hook nil
151
  "List of functions called after any LaTeX calendar buffer is generated.
152
You can use this to do post-processing on the buffer.  For example, to change
153
characters with diacritical marks to their LaTeX equivalents, use
154
    (add-hook \\='cal-tex-hook
155
              (lambda () (iso-iso2tex (point-min) (point-max))))"
156 157 158 159
  :type 'hook
  :group 'calendar-tex)

(defcustom cal-tex-year-hook nil
160
  "List of functions called after a LaTeX year calendar buffer is generated."
161 162 163 164
  :type 'hook
  :group 'calendar-tex)

(defcustom cal-tex-month-hook nil
165
  "List of functions called after a LaTeX month calendar buffer is generated."
166 167 168 169
  :type 'hook
  :group 'calendar-tex)

(defcustom cal-tex-week-hook nil
170
  "List of functions called after a LaTeX week calendar buffer is generated."
171 172 173 174
  :type 'hook
  :group 'calendar-tex)

(defcustom cal-tex-daily-hook nil
175
  "List of functions called after a LaTeX daily calendar buffer is generated."
176 177 178
  :type 'hook
  :group 'calendar-tex)

Edward M. Reingold's avatar
Edward M. Reingold committed
179 180 181 182
;;;
;;; Definitions for LaTeX code
;;;

183
(defconst cal-tex-day-prefix "\\caldate{%s}{%s}"
184
  "The initial LaTeX code for a day.
Edward M. Reingold's avatar
Edward M. Reingold committed
185
The holidays, diary entries, bottom string, and the text follow.")
186

187
(defconst cal-tex-day-name-format "\\myday{%s}%%"
188 189
  "The format for LaTeX code for a day name.
The names are taken from `calendar-day-name-array'.")
Edward M. Reingold's avatar
Edward M. Reingold committed
190

191
(defconst cal-tex-cal-one-month
192
  "\\def\\calmonth#1#2%
Edward M. Reingold's avatar
Edward M. Reingold committed
193 194
{\\begin{center}%
\\Huge\\bf\\uppercase{#1} #2 \\\\[1cm]%
195
\\end{center}}%
Edward M. Reingold's avatar
Edward M. Reingold committed
196 197 198
\\vspace*{-1.5cm}%
%
"
199
  "LaTeX code for the month header, for a single month calendar.")
Edward M. Reingold's avatar
Edward M. Reingold committed
200

201
(defconst cal-tex-cal-multi-month
202
  "\\def\\calmonth#1#2#3#4%
Edward M. Reingold's avatar
Edward M. Reingold committed
203 204
{\\begin{center}%
\\Huge\\bf #1 #2---#3 #4\\\\[1cm]%
205
\\end{center}}%
Edward M. Reingold's avatar
Edward M. Reingold committed
206 207 208
\\vspace*{-1.5cm}%
%
"
209
  "LaTeX code for the month header, for a multi-month calendar.")
Edward M. Reingold's avatar
Edward M. Reingold committed
210

211
(defconst cal-tex-myday
212
  "\\renewcommand{\\myday}[1]%
Edward M. Reingold's avatar
Edward M. Reingold committed
213 214 215
{\\makebox[\\cellwidth]{\\hfill\\large\\bf#1\\hfill}}
%
"
216
  "LaTeX code for a day heading.")
Edward M. Reingold's avatar
Edward M. Reingold committed
217

218
(defconst cal-tex-caldate
Edward M. Reingold's avatar
Edward M. Reingold committed
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
"\\fboxsep=0pt
\\long\\def\\caldate#1#2#3#4#5#6{%
    \\fbox{\\hbox to\\cellwidth{%
     \\vbox to\\cellheight{%
       \\hbox to\\cellwidth{%
          {\\hspace*{1mm}\\Large \\bf \\strut #2}\\hspace{.05\\cellwidth}%
          \\raisebox{\\holidaymult\\cellheight}%
                   {\\parbox[t]{.75\\cellwidth}{\\tiny \\raggedright #4}}}
       \\hbox to\\cellwidth{%
           \\hspace*{1mm}\\parbox{.95\\cellwidth}{\\tiny \\raggedright #3}}
       \\hspace*{1mm}%
       \\hbox to\\cellwidth{#6}%
       \\vfill%
       \\hbox to\\cellwidth{\\hfill \\tiny #5 \\hfill}%
       \\vskip 1.4pt}%
     \\hskip -0.4pt}}}
"
  "LaTeX code to insert one box with date info in calendar.
This definition is the heart of the calendar!")

239 240 241 242 243 244 245 246
(defconst cal-tex-lefthead
  "\\def\\lefthead#1{\\noindent {\\normalsize \\bf #1}\\hfill\\\\[-6pt]}\n"
  "LaTeX code for left header.")

(defconst cal-tex-righthead
  "\\def\\righthead#1{\\hfill {\\normalsize \\bf #1}\\\\[-6pt]}\n"
  "LaTeX code for right header.")

247 248
(autoload 'holiday-in-range "holidays")

249 250
(autoload 'diary-list-entries "diary-lib")

Edward M. Reingold's avatar
Edward M. Reingold committed
251 252
(defun cal-tex-list-diary-entries (d1 d2)
  "Generate a list of all diary-entries from absolute date D1 to D2."
253 254 255
  (let (diary-list-include-blanks)
    (diary-list-entries (calendar-gregorian-from-absolute d1)
                        (1+ (- d2 d1)) t)))
Edward M. Reingold's avatar
Edward M. Reingold committed
256 257

(defun cal-tex-preamble (&optional args)
258
  "Insert the LaTeX calendar preamble into `cal-tex-buffer'.
259
Preamble includes initial definitions for various LaTeX commands.
260 261 262 263 264 265 266
Optional string ARGS are included as options for the article
document class with inclusion of default values \"12pt\" for
size, and \"a4paper\" for paper unless size or paper are already
specified in ARGS.  When ARGS is omitted, by default the option
\"12pt,a4paper\" is passed. When ARGS has any other value, then
no option is passed to the class.

Paul Eggert's avatar
Paul Eggert committed
267
Insert the \"\\usepackage{geometry}\" directive when ARGS
268
contains the \"landscape\" string."
269
  (set-buffer (generate-new-buffer cal-tex-buffer))
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
  (save-match-data
    (insert (format "\\documentclass%s{article}\n"
                    (cond
                     ((stringp args)
                      ;; set default size
                      (unless (string-match "\\(^\\|,\\) *[0-9]+pt *\\(,\\|$\\)" args)
                        (setq args (concat args ",12pt")))
                      ;; set default paper
                      (unless (string-match "\\(^\\|,\\) *\\([ab][4-5]\\|le\\(tter\\|gal\\)\\|executive\\)paper *\\(,\\|$\\)" args)
                        (setq args (concat args ",a4paper")))
                      (when (string= (substring args 0 1) ",")
                        (setq args (substring args 1)))
                      (if (string= args "") "" (format "[%s]" args)))
                     ((null args) "[12pt]")
                     (t ""))))
    (if (and (stringp args) (string-match "\\<landscape\\>" args))
      (insert "\\usepackage{geometry}\n")))
287 288
  (if (stringp cal-tex-preamble-extra)
      (insert cal-tex-preamble-extra "\n"))
289
  ;; FIXME boxwidth and boxheight unused?
290
  (insert "\\hbadness 20000
291
\\hfuzz=1000pt
Edward M. Reingold's avatar
Edward M. Reingold committed
292
\\vbadness 20000
293
\\lineskip 0pt
Edward M. Reingold's avatar
Edward M. Reingold committed
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
\\marginparwidth 0pt
\\oddsidemargin  -2cm
\\evensidemargin -2cm
\\marginparsep   0pt
\\topmargin      0pt
\\textwidth      7.5in
\\textheight     9.5in
\\newlength{\\cellwidth}
\\newlength{\\cellheight}
\\newlength{\\boxwidth}
\\newlength{\\boxheight}
\\newlength{\\cellsize}
\\newcommand{\\myday}[1]{}
\\newcommand{\\caldate}[6]{}
\\newcommand{\\nocaldate}[6]{}
\\newcommand{\\calsmall}[6]{}
%
"))

;;;
;;;  Yearly calendars
;;;

317
;;;###cal-autoload
Glenn Morris's avatar
Glenn Morris committed
318
(defun cal-tex-cursor-year (&optional n event)
Edward M. Reingold's avatar
Edward M. Reingold committed
319
  "Make a buffer with LaTeX commands for the year cursor is on.
Glenn Morris's avatar
Glenn Morris committed
320 321 322 323 324 325
Optional prefix argument N specifies number of years.
Optional EVENT indicates a buffer position to use instead of point."
  (interactive (list (prefix-numeric-value current-prefix-arg)
                     last-nonmenu-event))
  (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t event))
                (or n 1)))
Edward M. Reingold's avatar
Edward M. Reingold committed
326

327
;;;###cal-autoload
Glenn Morris's avatar
Glenn Morris committed
328
(defun cal-tex-cursor-year-landscape (&optional n event)
Edward M. Reingold's avatar
Edward M. Reingold committed
329
  "Make a buffer with LaTeX commands for the year cursor is on.
Glenn Morris's avatar
Glenn Morris committed
330 331 332 333 334 335
Optional prefix argument N specifies number of years.
Optional EVENT indicates a buffer position to use instead of point."
  (interactive (list (prefix-numeric-value current-prefix-arg)
                     last-nonmenu-event))
  (cal-tex-year (calendar-extract-year (calendar-cursor-to-date t event))
                (or n 1) t))
Edward M. Reingold's avatar
Edward M. Reingold committed
336 337 338

(defun cal-tex-year (year n &optional landscape)
  "Make a one page yearly calendar of YEAR; do this for N years.
339 340 341
There are four rows of three months each, unless optional
LANDSCAPE is non-nil, in which case the calendar is printed in
landscape mode with three rows of four months each."
342
  (cal-tex-insert-preamble 1 (and landscape "landscape"))
Edward M. Reingold's avatar
Edward M. Reingold committed
343 344 345
  (if landscape
      (cal-tex-vspace "-.6cm")
    (cal-tex-vspace "-3.1cm"))
346
  (dotimes (j n)
347 348 349 350 351 352 353 354 355 356
    (insert "\\vfill%\n")
    (cal-tex-b-center)
    (cal-tex-Huge (number-to-string year))
    (cal-tex-e-center)
    (cal-tex-vspace "1cm")
    (cal-tex-b-center)
    (cal-tex-b-parbox "l" (if landscape "5.9in" "4.3in"))
    (insert "\n")
    (cal-tex-noindent)
    (cal-tex-nl)
357 358 359 360 361 362
    (dotimes (i 12)
      (insert (cal-tex-mini-calendar (1+ i) year "month" "1.1in" "1in"))
      (insert "\\month")
      (cal-tex-hspace "0.5in")
      (if (zerop (mod (1+ i) (if landscape 4 3)))
          (cal-tex-nl "0.5in")))
363 364 365 366
    (cal-tex-e-parbox)
    (cal-tex-e-center)
    (insert "\\vfill%\n")
    (setq year (1+ year))
367 368 369
    (if (= j (1- n))
        (cal-tex-end-document)
      (cal-tex-newpage))
370
    (run-hooks 'cal-tex-year-hook))
Edward M. Reingold's avatar
Edward M. Reingold committed
371 372
  (run-hooks 'cal-tex-hook))

373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391

(defun cal-tex-filofax-paper (&optional year)
  "Insert some page size settings for filofax layouts."
  (insert "\\textwidth 3.25in
\\textheight 6.5in
\\headheight -0.875in
\\topmargin 0pt
")
  (insert
   ;; Why is this one subtly different?  Who knows...
   (if year "\\oddsidemargin 1.675in
\\evensidemargin 1.675in
"
     "\\oddsidemargin 1.75in
\\evensidemargin 1.5in
\\headsep 0.125in
\\footskip 0.125in
")))

Glenn Morris's avatar
Glenn Morris committed
392 393 394
(defun cal-tex-longday (funcname height)
  "Insert LaTeX code for a long day function."
  (insert "\\long\\def\\" funcname "#1#2#3#4#5{%
395 396 397
   \\rule{\\textwidth}{0.3pt}\\\\%
   \\hbox to \\textwidth{%
     \\vbox to " height "{%
Glenn Morris's avatar
Glenn Morris committed
398 399 400 401 402 403 404 405 406
       \\vspace*{2pt}%
       \\hbox to \\textwidth{"
     (if (string-equal funcname "leftday")
         "\\noindent {\\normalsize \\bf #2} \\small #1 \\hfill #5}%\n"
       "\\small #5 \\hfill #1 {\\normalsize \\bf #2}}%\n")
     "       \\hbox to \\textwidth{\\vbox {\\"
     (if (string-equal funcname "leftday") "noindent" "raggedleft")
     " \\footnotesize \\em #4}}%
       \\hbox to \\textwidth{\\vbox to 0pt {\\noindent \\footnotesize #3}}}}\\\\}\n"))
407

408 409 410 411 412 413 414 415 416 417 418 419 420
(defun cal-tex-shortday (funcname)
  "Insert LaTeX code for a short day function."
  (insert "\\long\\def\\" funcname "#1#2#3{%
   \\rule{\\textwidth}{0.3pt}\\\\%
   \\hbox to \\textwidth{%
     \\vbox {%
          \\vspace*{2pt}%
          \\hbox to \\textwidth{\\hfill \\small #3 \\hfill}%
          \\hbox to \\textwidth{\\vbox {\\"
          (if (string-equal funcname "rightday") "raggedleft" "noindent")
          " \\em #2}}%
          \\hbox to \\textwidth{\\vbox {\\noindent \\footnotesize #1}}}}}\n"))

421
;;;###cal-autoload
Glenn Morris's avatar
Glenn Morris committed
422
(defun cal-tex-cursor-filofax-year (&optional n event)
Edward M. Reingold's avatar
Edward M. Reingold committed
423
  "Make a Filofax one page yearly calendar of year indicated by cursor.
Glenn Morris's avatar
Glenn Morris committed
424 425 426 427 428 429
Optional prefix argument N specifies number of years.
Optional EVENT indicates a buffer position to use instead of point."
  (interactive (list (prefix-numeric-value current-prefix-arg)
                     last-nonmenu-event))
  (or n (setq n 1))
  (let ((year (calendar-extract-year (calendar-cursor-to-date t event))))
Edward M. Reingold's avatar
Edward M. Reingold committed
430
    (cal-tex-preamble "twoside")
431
    (cal-tex-filofax-paper 'year)
432
    (cal-tex-cmd "\\fboxsep 0.5mm")
Glenn Morris's avatar
Glenn Morris committed
433
    (cal-tex-cmd "\\pagestyle" "empty")
Edward M. Reingold's avatar
Edward M. Reingold committed
434
    (cal-tex-b-document)
Glenn Morris's avatar
Glenn Morris committed
435
    (cal-tex-vspace "0.25in")
436
    (dotimes (j n)
437
      (insert (format "\\hfil \\textbf{\\Large %s} \\hfil\\\\\n" year))
438 439 440 441 442 443 444 445 446 447
      (cal-tex-b-center)
      (cal-tex-b-parbox "l" "\\textwidth")
      (insert "\n")
      (cal-tex-noindent)
      (cal-tex-nl)
      (let ((month-names; don't use default in case user changed it
             ;; These are only used to define the command names, not
             ;; the names of the months they insert.
             ["January" "February" "March" "April" "May" "June"
              "July" "August" "September" "October" "November" "December"]))
448 449
        (dotimes (i 12)
          (insert (cal-tex-mini-calendar (1+ i) year (aref month-names i)
450 451 452
                                         "1in" ".9in" "tiny" "0.6mm"))))
      (insert
       "\\noindent\\fbox{\\January}\\fbox{\\February}\\fbox{\\March}\\\\
Edward M. Reingold's avatar
Edward M. Reingold committed
453 454 455 456
\\noindent\\fbox{\\April}\\fbox{\\May}\\fbox{\\June}\\\\
\\noindent\\fbox{\\July}\\fbox{\\August}\\fbox{\\September}\\\\
\\noindent\\fbox{\\October}\\fbox{\\November}\\fbox{\\December}
")
457 458 459
      (cal-tex-e-parbox)
      (cal-tex-e-center)
      (setq year (1+ year))
460
      (if (= j (1- n))
461 462
          (cal-tex-end-document)
        (cal-tex-newpage)
Glenn Morris's avatar
Glenn Morris committed
463
        (cal-tex-vspace "0.25in"))
464
      (run-hooks 'cal-tex-year-hook))
Edward M. Reingold's avatar
Edward M. Reingold committed
465 466 467 468 469 470
    (run-hooks 'cal-tex-hook)))

;;;
;;;  Monthly calendars
;;;

471
;;;###cal-autoload
Glenn Morris's avatar
Glenn Morris committed
472
(defun cal-tex-cursor-month-landscape (&optional n event)
473
  "Make a LaTeX calendar buffer for the month the cursor is on.
Glenn Morris's avatar
Glenn Morris committed
474
Optional prefix argument N specifies number of months to be
475 476
produced (default 1).  The output is in landscape format, one
month to a page.  It shows holiday and diary entries if
Glenn Morris's avatar
Glenn Morris committed
477 478 479 480 481 482
`cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
Optional EVENT indicates a buffer position to use instead of point."
  (interactive (list (prefix-numeric-value current-prefix-arg)
                     last-nonmenu-event))
  (or n (setq n 1))
  (let* ((date (calendar-cursor-to-date t event))
483 484
         (month (calendar-extract-month date))
         (year (calendar-extract-year date))
Edward M. Reingold's avatar
Edward M. Reingold committed
485 486
         (end-month month)
         (end-year year)
487 488
         (cal-tex-which-days '(0 1 2 3 4 5 6))
         (d1 (calendar-absolute-from-gregorian (list month 1 year)))
489 490 491 492 493 494 495
         (d2 (progn
               (calendar-increment-month end-month end-year (1- n))
               (calendar-absolute-from-gregorian
                (list end-month
                      (calendar-last-day-of-month end-month end-year)
                      end-year))))
         (diary-list (if cal-tex-diary (cal-tex-list-diary-entries d1 d2)))
496
         (holidays (if cal-tex-holidays (holiday-in-range d1 d2)))
497
         other-month other-year small-months-at-start)
498
    (cal-tex-insert-preamble (cal-tex-number-weeks month year 1) "landscape")
499 500 501 502
    (cal-tex-cmd cal-tex-cal-one-month)
    (dotimes (i n)
      (setq other-month month
            other-year year)
503
      (calendar-increment-month other-month other-year -1)
504 505
      (insert (cal-tex-mini-calendar other-month other-year "lastmonth"
                                     "\\cellwidth" "\\cellheight"))
506
      (calendar-increment-month other-month other-year 2)
507 508 509 510 511 512 513
      (insert (cal-tex-mini-calendar other-month other-year "nextmonth"
                                     "\\cellwidth" "\\cellheight"))
      (cal-tex-insert-month-header 1 month year month year)
      (cal-tex-insert-day-names)
      (cal-tex-nl ".2cm")
      (if (setq small-months-at-start
                (< 1 (mod (- (calendar-day-of-week (list month 1 year))
514
                               calendar-week-start-day)
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
                          7)))
          (insert "\\lastmonth\\nextmonth\\hspace*{-2\\cellwidth}"))
      (cal-tex-insert-blank-days month year cal-tex-day-prefix)
      (cal-tex-insert-days month year diary-list holidays
                           cal-tex-day-prefix)
      (cal-tex-insert-blank-days-at-end month year cal-tex-day-prefix)
      (if (and (not small-months-at-start)
               (< 1 (mod (- (1- calendar-week-start-day)
                            (calendar-day-of-week
                             (list month
                                   (calendar-last-day-of-month month year)
                                   year)))
                         7)))
          (insert "\\vspace*{-\\cellwidth}\\hspace*{-2\\cellwidth}"
                  "\\lastmonth\\nextmonth%
530
"))
531 532 533
      (unless (= i (1- n))
        (run-hooks 'cal-tex-month-hook)
        (cal-tex-newpage)
534
        (calendar-increment-month month year 1)
535 536
        (cal-tex-vspace "-2cm")
        (cal-tex-insert-preamble
537
         (cal-tex-number-weeks month year 1) "landscape" t))))
538 539
  (cal-tex-end-document)
  (run-hooks 'cal-tex-hook))
Edward M. Reingold's avatar
Edward M. Reingold committed
540

541
;;;###cal-autoload
Glenn Morris's avatar
Glenn Morris committed
542
(defun cal-tex-cursor-month (&optional n event)
543
  "Make a LaTeX calendar buffer for the month the cursor is on.
Glenn Morris's avatar
Glenn Morris committed
544
Optional prefix argument N specifies number of months to be
545 546
produced (default 1).  The calendar is condensed onto one page.
It shows holiday and diary entries if `cal-tex-holidays' and
Glenn Morris's avatar
Glenn Morris committed
547 548 549 550 551 552
`cal-tex-diary', respectively, are non-nil.  Optional EVENT
indicates a buffer position to use instead of point."
  (interactive (list (prefix-numeric-value current-prefix-arg)
                     last-nonmenu-event))
  (or n (setq n 1))
  (let* ((date (calendar-cursor-to-date t event))
553 554
         (month (calendar-extract-month date))
         (year (calendar-extract-year date))
Edward M. Reingold's avatar
Edward M. Reingold committed
555 556
         (end-month month)
         (end-year year)
557
         ;; FIXME -landscape sets cal-tex-which-days?
558
         (d1 (calendar-absolute-from-gregorian (list month 1 year)))
559 560 561 562 563 564 565
         (d2 (progn
               (calendar-increment-month end-month end-year (1- n))
               (calendar-absolute-from-gregorian
                (list end-month
                      (calendar-last-day-of-month end-month end-year)
                      end-year))))
         (diary-list (if cal-tex-diary (cal-tex-list-diary-entries d1 d2)))
566
         (holidays (if cal-tex-holidays (holiday-in-range d1 d2))))
567
    (cal-tex-insert-preamble (cal-tex-number-weeks month year n))
568 569 570 571 572 573 574
    (if (> n 1)
        (cal-tex-cmd cal-tex-cal-multi-month)
      (cal-tex-cmd cal-tex-cal-one-month))
    (cal-tex-insert-month-header n month year end-month end-year)
    (cal-tex-insert-day-names)
    (cal-tex-nl ".2cm")
    (cal-tex-insert-blank-days month year cal-tex-day-prefix)
575
    (dotimes (_idummy n)
576
      (cal-tex-insert-days month year diary-list holidays cal-tex-day-prefix)
577 578 579 580 581
      (when (= (calendar-week-end-day)
               (calendar-day-of-week
                (list month
                      (calendar-last-day-of-month month year)
                      year))) ; last day of month was last day of week
582 583
        (cal-tex-hfill)
        (cal-tex-nl))
584
      (calendar-increment-month month year 1))
585 586
    (cal-tex-insert-blank-days-at-end end-month end-year cal-tex-day-prefix))
  (cal-tex-end-document)
Edward M. Reingold's avatar
Edward M. Reingold committed
587 588
  (run-hooks 'cal-tex-hook))

589
(defun cal-tex-insert-days (month year diary-list holidays day-format)
Edward M. Reingold's avatar
Edward M. Reingold committed
590 591
  "Insert LaTeX commands for a range of days in monthly calendars.
LaTeX commands are inserted for the days of the MONTH in YEAR.
592 593
Diary entries on DIARY-LIST are included.  Holidays on HOLIDAYS
are included.  Each day is formatted using format DAY-FORMAT."
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
  (let ((blank-days                     ; at start of month
         (mod
          (- (calendar-day-of-week (list month 1 year))
             calendar-week-start-day)
          7))
        (last (calendar-last-day-of-month month year))
        date j)
    (dotimes (i last)
      (setq j (1+ i)                    ; 1-last, incl
            date (list month j year))
      (when (memq (calendar-day-of-week date) cal-tex-which-days)
        (insert (format day-format (cal-tex-month-name month) j))
        (cal-tex-arg (cal-tex-latexify-list diary-list date))
        (cal-tex-arg (cal-tex-latexify-list holidays date))
        (cal-tex-arg (eval cal-tex-daily-string))
        (cal-tex-arg)
        (cal-tex-comment))
      (when (and (zerop (mod (+ j blank-days) 7))
                 (/= j last))
        (cal-tex-hfill)
        (cal-tex-nl)))))
Edward M. Reingold's avatar
Edward M. Reingold committed
615 616 617

(defun cal-tex-insert-day-names ()
  "Insert the names of the days at top of a monthly calendar."
618 619 620 621 622 623 624 625
  (let (j)
    (dotimes (i 7)
      (if (memq (setq j (mod (+ calendar-week-start-day i) 7))
                cal-tex-which-days)
          (insert (format cal-tex-day-name-format
                          (cal-tex-LaTeXify-string
                           (aref calendar-day-name-array j)))))
      (cal-tex-comment))))
Edward M. Reingold's avatar
Edward M. Reingold committed
626 627 628

(defun cal-tex-insert-month-header (n month year end-month end-year)
  "Create a title for a calendar.
629
A title is inserted for a calendar with N months starting with
Edward M. Reingold's avatar
Edward M. Reingold committed
630
MONTH YEAR and ending with END-MONTH END-YEAR."
631 632
  (let ((month-name (cal-tex-month-name month))
        (end-month-name (cal-tex-month-name end-month)))
Edward M. Reingold's avatar
Edward M. Reingold committed
633 634
    (if (= 1 n)
        (insert (format "\\calmonth{%s}{%s}\n\\vspace*{-0.5cm}"
635 636 637
                        month-name year) )
      (insert (format "\\calmonth{%s}{%s}{%s}{%s}\n\\vspace*{-0.5cm}"
                      month-name year end-month-name end-year))))
Edward M. Reingold's avatar
Edward M. Reingold committed
638 639 640 641 642 643 644 645
  (cal-tex-comment))

(defun cal-tex-insert-blank-days (month year day-format)
  "Insert code for initial days not in calendar.
Insert LaTeX code for the blank days at the beginning of the MONTH in
YEAR.  The entry is formatted using DAY-FORMAT.  If the entire week is
blank, no days are inserted."
  (if (cal-tex-first-blank-p month year)
646 647 648 649 650 651
      (let ((blank-days                ; at start of month
             (mod
              (- (calendar-day-of-week (list month 1 year))
                 calendar-week-start-day)
              7)))
        (dotimes (i blank-days)
652
          (if (memq (mod (+ calendar-week-start-day i) 7) cal-tex-which-days)
653
              (insert (format day-format " " " ") "{}{}{}{}%\n"))))))
Edward M. Reingold's avatar
Edward M. Reingold committed
654 655 656 657 658 659 660

(defun cal-tex-insert-blank-days-at-end (month year day-format)
  "Insert code for final days not in calendar.
Insert LaTeX code for the blank days at the end of the MONTH in YEAR.
The entry is formatted using DAY-FORMAT."
  (if (cal-tex-last-blank-p month year)
      (let* ((last-day (calendar-last-day-of-month month year))
661
             (blank-days                ; at end of month
Edward M. Reingold's avatar
Edward M. Reingold committed
662 663 664
              (mod
               (- (calendar-day-of-week (list month last-day year))
                  calendar-week-start-day)
665 666 667
               7))
             (i blank-days))
        (while (<= (setq i (1+ i)) 6)
668
          (if (memq (mod (+ calendar-week-start-day i) 7) cal-tex-which-days)
669
              (insert (format day-format "" "") "{}{}{}{}%\n"))))))
Edward M. Reingold's avatar
Edward M. Reingold committed
670 671 672 673 674

(defun cal-tex-first-blank-p (month year)
  "Determine if any days of the first week will be printed.
Return t if there will there be any days of the first week printed
in the calendar starting in MONTH YEAR."
675 676 677 678 679 680 681 682
  ;; Check days 1-7 of the month, until we find the last day of the week.
  (catch 'found
    (let (dow)
      (dotimes (i 7)
        (if (memq (setq dow (calendar-day-of-week (list month (1+ i) year)))
                  cal-tex-which-days)
            (throw 'found t)
          (if (= dow (calendar-week-end-day)) (throw 'found nil)))))))
Edward M. Reingold's avatar
Edward M. Reingold committed
683 684 685 686 687

(defun cal-tex-last-blank-p (month year)
  "Determine if any days of the last week will be printed.
Return t if there will there be any days of the last week printed
in the calendar starting in MONTH YEAR."
688 689 690 691
  ;; Check backwards from the last day of the month, until we find the
  ;; start of the last week in the month.
  (catch 'found
    (let ((last-day (calendar-last-day-of-month month year))
692
          dow)
693 694 695 696 697 698
      (dotimes (i 7)
        (if (memq (setq dow (calendar-day-of-week
                             (list month (- last-day i) year)))
                  cal-tex-which-days)
            (throw 'found t)
          (if (= dow calendar-week-start-day) (throw 'found nil)))))))
Edward M. Reingold's avatar
Edward M. Reingold committed
699 700 701

(defun cal-tex-number-weeks (month year n)
  "Determine the number of weeks in a range of dates.
Juanma Barranquero's avatar
Juanma Barranquero committed
702
Compute the number of weeks in the calendar starting with MONTH and YEAR,
703
and lasting N months, including only the days in WHICH-DAYS.  As it stands,
Edward M. Reingold's avatar
Edward M. Reingold committed
704 705
this is only an upper bound."
  (let ((d (list month 1 year)))
706
    (calendar-increment-month month year (1- n))
Edward M. Reingold's avatar
Edward M. Reingold committed
707 708 709 710 711 712 713 714 715 716 717 718 719
    (/ (- (calendar-dayname-on-or-before
           calendar-week-start-day
           (+ 7 (calendar-absolute-from-gregorian
                   (list month (calendar-last-day-of-month month year) year))))
          (calendar-dayname-on-or-before
           calendar-week-start-day
           (calendar-absolute-from-gregorian d)))
       7)))

;;;
;;; Weekly calendars
;;;

720
(defconst cal-tex-LaTeX-hourbox
721 722 723 724
  "\\newcommand{\\hourbox}[2]%
{\\makebox[2em]{\\rule{0cm}{#2ex}#1}\\rule{3in}{.15mm}}\n"
  "One hour and a line on the right.")

725 726 727 728 729 730 731 732 733
(defun cal-tex-weekly-paper (&optional nomargins)
  "Insert some page size settings for weekly layouts."
  (insert "\\textwidth 6.5in
\\textheight 10.5in
")
  (or nomargins (insert "\\oddsidemargin 0in
\\evensidemargin 0in
")))

734
;; TODO cal-tex-diary-support.
735
;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
736
;;;###cal-autoload
Glenn Morris's avatar
Glenn Morris committed
737
(defun cal-tex-cursor-week (&optional n event)
738 739 740 741 742 743 744 745 746
  "Make a one page LaTeX calendar for one week, showing hours of the day.
There are two columns; with 8-12am in the first and 1-5pm in the second.
It shows holidays if `cal-tex-holidays' is non-nil.
It does not show diary entries.

The optional prefix argument N specifies a number of weeks (default 1).

By default, the calendar is for the week at point; the optional
argument EVENT specifies a different buffer position."
Glenn Morris's avatar
Glenn Morris committed
747 748 749 750
  (interactive (list (prefix-numeric-value current-prefix-arg)
                     last-nonmenu-event))
  (or n (setq n 1))
  (let* ((date (calendar-gregorian-from-absolute
Edward M. Reingold's avatar
Edward M. Reingold committed
751 752 753
                (calendar-dayname-on-or-before
                 calendar-week-start-day
                 (calendar-absolute-from-gregorian
Glenn Morris's avatar
Glenn Morris committed
754
                  (calendar-cursor-to-date t event)))))
755 756
         (month (calendar-extract-month date))
         (year (calendar-extract-year date))
757 758
         (d1 (calendar-absolute-from-gregorian date))
         (d2 (+ (* 7 n) d1))
Edward M. Reingold's avatar
Edward M. Reingold committed
759
         (holidays (if cal-tex-holidays
760
                       (holiday-in-range d1 d2))))
Edward M. Reingold's avatar
Edward M. Reingold committed
761
    (cal-tex-preamble "11pt")
762
    (cal-tex-weekly-paper)
Edward M. Reingold's avatar
Edward M. Reingold committed
763 764
    (insert cal-tex-LaTeX-hourbox)
    (cal-tex-b-document)
Glenn Morris's avatar
Glenn Morris committed
765
    (cal-tex-cmd "\\pagestyle" "empty")
766
    (dotimes (i n)
767 768 769 770 771 772 773 774 775 776
      (cal-tex-vspace "-1.5in")
      (cal-tex-b-center)
      (cal-tex-Huge-bf (format "\\uppercase{%s}"
                               (cal-tex-month-name month)))
      (cal-tex-hspace "2em")
      (cal-tex-Huge-bf (number-to-string year))
      (cal-tex-nl ".5cm")
      (cal-tex-e-center)
      (cal-tex-hspace "-.2in")
      (cal-tex-b-parbox "l" "7in")
777
      (dotimes (_jdummy 7)
778 779 780
        (cal-tex-week-hours date holidays "3.1")
        (setq date (cal-tex-incr-date date)))
      (cal-tex-e-parbox)
781 782
      (setq month (calendar-extract-month date)
            year (calendar-extract-year date))
783 784 785
      (unless (= i (1- n))
        (run-hooks 'cal-tex-week-hook)
        (cal-tex-newpage)))
Edward M. Reingold's avatar
Edward M. Reingold committed
786 787 788
    (cal-tex-end-document)
    (run-hooks 'cal-tex-hook)))

789
;; TODO cal-tex-diary support.
790
;; TODO respect cal-tex-daily-start,end (see cal-tex-week-hours).
791
;;;###cal-autoload
Glenn Morris's avatar
Glenn Morris committed
792
(defun cal-tex-cursor-week2 (&optional n event)
793 794 795 796 797 798 799 800 801
  "Make a two page LaTeX calendar for one week, showing hours of the day.
There are two columns; with 8-12am in the first and 1-5pm in the second.
It shows holidays if `cal-tex-holidays' is non-nil.
It does not show diary entries.

The optional prefix argument N specifies a number of weeks (default 1).

By default, the calendar is for the week at point; the optional
argument EVENT specifies a different buffer position."
Glenn Morris's avatar
Glenn Morris committed
802 803 804 805
  (interactive (list (prefix-numeric-value current-prefix-arg)
                     last-nonmenu-event))
  (or n (setq n 1))
  (let* ((date (calendar-gregorian-from-absolute
Edward M. Reingold's avatar
Edward M. Reingold committed
806 807 808
                (calendar-dayname-on-or-before
                 calendar-week-start-day
                 (calendar-absolute-from-gregorian
Glenn Morris's avatar
Glenn Morris committed
809
                  (calendar-cursor-to-date t event)))))
810 811
         (month (calendar-extract-month date))
         (year (calendar-extract-year date))
812 813
         (d1 (calendar-absolute-from-gregorian date))
         (d2 (+ (* 7 n) d1))
Edward M. Reingold's avatar
Edward M. Reingold committed
814
         (holidays (if cal-tex-holidays
815
                       (holiday-in-range d1 d2))))
Edward M. Reingold's avatar
Edward M. Reingold committed
816
    (cal-tex-preamble "12pt")
817
    (cal-tex-weekly-paper)
Edward M. Reingold's avatar
Edward M. Reingold committed
818 819
    (insert cal-tex-LaTeX-hourbox)
    (cal-tex-b-document)
Glenn Morris's avatar
Glenn Morris committed
820
    (cal-tex-cmd "\\pagestyle" "empty")
821
    (dotimes (i n)
822 823 824 825 826 827 828 829 830 831
      (cal-tex-vspace "-1.5in")
      (cal-tex-b-center)
      (cal-tex-Huge-bf (format "\\uppercase{%s}"
                               (cal-tex-month-name month)))
      (cal-tex-hspace "2em")
      (cal-tex-Huge-bf (number-to-string year))
      (cal-tex-nl ".5cm")
      (cal-tex-e-center)
      (cal-tex-hspace "-.2in")
      (cal-tex-b-parbox "l" "\\textwidth")
832
      (dotimes (_jdummy 3)
833 834 835 836 837
        (cal-tex-week-hours date holidays "5")
        (setq date (cal-tex-incr-date date)))
      (cal-tex-e-parbox)
      (cal-tex-nl)
      (insert (cal-tex-mini-calendar
838 839
               (calendar-extract-month (cal-tex-previous-month date))
               (calendar-extract-year (cal-tex-previous-month date))
840 841
               "lastmonth" "1.1in" "1in"))
      (insert (cal-tex-mini-calendar
842 843
               (calendar-extract-month date)
               (calendar-extract-year date)
844 845
               "thismonth" "1.1in" "1in"))
      (insert (cal-tex-mini-calendar
846 847
               (calendar-extract-month (cal-tex-next-month date))
               (calendar-extract-year (cal-tex-next-month date))
848 849 850 851 852 853 854 855 856 857 858 859
               "nextmonth" "1.1in" "1in"))
      (insert "\\hbox to \\textwidth{")
      (cal-tex-hfill)
      (insert "\\lastmonth")
      (cal-tex-hfill)
      (insert "\\thismonth")
      (cal-tex-hfill)
      (insert "\\nextmonth")
      (cal-tex-hfill)
      (insert "}")
      (cal-tex-nl)
      (cal-tex-b-parbox "l" "\\textwidth")
860
      (dotimes (_jdummy 4)
861 862 863
        (cal-tex-week-hours date holidays "5")
        (setq date (cal-tex-incr-date date)))
      (cal-tex-e-parbox)
864 865
      (setq month (calendar-extract-month date)
            year (calendar-extract-year date))
866 867 868
      (unless (= i (1- n))
        (run-hooks 'cal-tex-week-hook)
        (cal-tex-newpage)))
Edward M. Reingold's avatar
Edward M. Reingold committed
869 870 871
    (cal-tex-end-document)
    (run-hooks 'cal-tex-hook)))

872 873 874
(autoload 'calendar-iso-from-absolute "cal-iso")

;;;###cal-autoload
Glenn Morris's avatar
Glenn Morris committed
875
(defun cal-tex-cursor-week-iso (&optional n event)
876 877 878 879 880 881 882 883 884
  "Make a one page LaTeX calendar for one week, in the ISO-style.
It does not show hours of the day.
It shows holidays if `cal-tex-holidays' is non-nil.
It shows diary entries if `cal-tex-diary' is non-nil.

The optional prefix argument N specifies a number of weeks (default 1).

By default, the calendar is for the week at point; the optional
argument EVENT specifies a different buffer position."
Glenn Morris's avatar
Glenn Morris committed
885 886 887 888
  (interactive (list (prefix-numeric-value current-prefix-arg)
                     last-nonmenu-event))
  (or n (setq n 1))
  (let* ((date (calendar-gregorian-from-absolute
Edward M. Reingold's avatar
Edward M. Reingold committed
889 890 891
                (calendar-dayname-on-or-before
                 1
                 (calendar-absolute-from-gregorian
Glenn Morris's avatar
Glenn Morris committed
892
                  (calendar-cursor-to-date t event)))))
893 894 895
         (month (calendar-extract-month date))
         (year (calendar-extract-year date))
         (day (calendar-extract-day date))
896 897
         (d1 (calendar-absolute-from-gregorian date))
         (d2 (+ (* 7 n) d1))
Edward M. Reingold's avatar
Edward M. Reingold committed
898
         (holidays (if cal-tex-holidays
899
                       (holiday-in-range d1 d2)))
Edward M. Reingold's avatar
Edward M. Reingold committed
900
         (diary-list (if cal-tex-diary
Glenn Morris's avatar
Glenn Morris committed
901
                         (cal-tex-list-diary-entries d1 d2)))
902
         s)
Edward M. Reingold's avatar
Edward M. Reingold committed
903
    (cal-tex-preamble "11pt")
904
    (cal-tex-weekly-paper)
Edward M. Reingold's avatar
Edward M. Reingold committed
905
    (cal-tex-b-document)
Glenn Morris's avatar
Glenn Morris committed
906
    (cal-tex-cmd "\\pagestyle" "empty")
907
    (dotimes (i n)
908 909 910
      (cal-tex-vspace "-1.5in")
      (cal-tex-b-center)
      (cal-tex-Huge-bf
911 912
       (let ((d (calendar-iso-from-absolute
                 (calendar-absolute-from-gregorian date))))
913
         (format "Week %d of %d"
914 915
                 (calendar-extract-month d)
                 (calendar-extract-year d))))
916 917 918
      (cal-tex-nl ".5cm")
      (cal-tex-e-center)
      (cal-tex-b-parbox "l" "\\textwidth")
919
      (dotimes (_j 7)
920 921 922 923 924 925 926 927
        (cal-tex-b-parbox "t" "\\textwidth")
        (cal-tex-b-parbox "t" "\\textwidth")
        (cal-tex-rule "0pt" "\\textwidth" ".2mm")
        (cal-tex-nl)
        (cal-tex-b-parbox "t" "\\textwidth")
        (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date)))
        (insert ", ")
        (cal-tex-large-bf (cal-tex-month-name month))
928
        (insert "\\ ")
929
        (cal-tex-large-bf (number-to-string day))
930 931 932 933
        (unless (string-equal "" (setq s (cal-tex-latexify-list
                                          holidays date "; ")))
          (insert ": ")
          (cal-tex-large-bf s))
934 935 936 937 938 939
        (cal-tex-hfill)
        (insert " " (eval cal-tex-daily-string))
        (cal-tex-e-parbox)
        (cal-tex-nl)
        (cal-tex-noindent)
        (cal-tex-b-parbox "t" "\\textwidth")
940 941 942 943 944
        (unless (string-equal "" (setq s (cal-tex-latexify-list
                                          diary-list date)))
          (insert "\\vbox to 0pt{")
          (cal-tex-large-bf s)
          (insert "}"))
945 946
        (cal-tex-e-parbox)
        (cal-tex-nl)
947
        (setq date (cal-tex-incr-date date)
948 949
              month (calendar-extract-month date)
              day (calendar-extract-day date))
950 951 952
        (cal-tex-e-parbox)
        (cal-tex-e-parbox "2cm")
        (cal-tex-nl)
953 954
        (setq month (calendar-extract-month date)
              year (calendar-extract-year date)))
955
      (cal-tex-e-parbox)
956 957 958
      (unless (= i (1- n))
        (run-hooks 'cal-tex-week-hook)
        (cal-tex-newpage)))
Edward M. Reingold's avatar
Edward M. Reingold committed
959 960 961
    (cal-tex-end-document)
    (run-hooks 'cal-tex-hook)))

962 963
;; TODO respect cal-tex-daily-start,end?
;; Using different numbers of hours will probably break some layouts.
Edward M. Reingold's avatar
Edward M. Reingold committed
964
(defun cal-tex-week-hours (date holidays height)
965
  "Insert hourly entries for DATE with HOLIDAYS, with line height HEIGHT.
966 967
Uses the 24-hour clock if `cal-tex-24' is non-nil.  Note that the hours
shown are hard-coded to 8-12, 13-17."
968 969 970
  (let ((month (calendar-extract-month date))
        (day (calendar-extract-day date))
        (year (calendar-extract-year date))
971
        morning afternoon s)
Edward M. Reingold's avatar
Edward M. Reingold committed
972 973 974 975
  (cal-tex-comment "begin cal-tex-week-hours")
  (cal-tex-cmd  "\\ \\\\[-.2cm]")
  (cal-tex-cmd "\\noindent")
  (cal-tex-b-parbox "l" "6.8in")
976
  (cal-tex-large-bf (cal-tex-LaTeXify-string (calendar-day-name date)))
Edward M. Reingold's avatar
Edward M. Reingold committed
977
  (insert ", ")
978
  (cal-tex-large-bf (cal-tex-month-name month))
979
  (insert "\\ ")
Edward M. Reingold's avatar
Edward M. Reingold committed
980
  (cal-tex-large-bf (number-to-string day))
981 982 983 984
  (unless (string-equal "" (setq s (cal-tex-latexify-list
                                    holidays date "; ")))
    (insert ": ")
    (cal-tex-large-bf s))
Edward M. Reingold's avatar
Edward M. Reingold committed
985 986 987 988 989 990
  (cal-tex-hfill)
  (insert " " (eval cal-tex-daily-string))
  (cal-tex-e-parbox)
  (cal-tex-nl "-.3cm")
  (cal-tex-rule "0pt" "6.8in" ".2mm")
  (cal-tex-nl "-.1cm")
991 992 993 994 995 996 997 998 999 1000 1001
  (dotimes (i 5)
    (setq morning (+ i 8)               ; 8-12 incl
          afternoon (if cal-tex-24
                        (+ i 13)        ; 13-17 incl
                      (1+ i)))          ; 1-5 incl
    (cal-tex-cmd "\\hourbox" (number-to-string morning))
    (cal-tex-arg height)
    (cal-tex-hspace ".4cm")
    (cal-tex-cmd "\\hourbox" (number-to-string afternoon))
    (cal-tex-arg height)
    (cal-tex-nl))))
Edward M. Reingold's avatar
Edward M. Reingold committed
1002

1003
;; TODO cal-tex-diary support.
1004
;; TODO respect cal-tex-daily-start,end (see cal-tex-weekly4-box).
1005
;;;###cal-autoload
Glenn Morris's avatar
Glenn Morris committed
1006
(defun cal-tex-cursor-week-monday (&optional n event)
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016
  "Make a one page LaTeX calendar for one week, showing hours of the day.
There are two columns; with M-W in the first and T-S in the second.
<