cal-tex.el 69 KB

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