muse-latex: Make lecture notes and slides work with images, title page, TOC.
[muse-el.git] / examples / johnw / muse-init.el
blob5ef9eb487ca72889564a3207d5d5a04a0c186094
1 (require 'muse)
2 (require 'muse-mode)
3 (require 'muse-colors)
4 (require 'muse-project)
5 (require 'muse-book)
7 (require 'muse-html)
8 (require 'muse-latex)
9 (require 'muse-texinfo)
11 (require 'muse-journal)
12 (require 'muse-poem)
13 (require 'muse-message)
15 (require 'muse-http)
17 ;;(require 'muse-arabic)
18 ;;(require 'muse-cite)
20 (eval-after-load "whitespace"
21 '(add-to-list 'whitespace-modes 'muse-mode))
23 (defun muse-maybe-convert-poem ()
24 (if (string-match "/poems/" muse-publishing-current-file)
25 (muse-poem-prepare-buffer)))
27 (defun muse-insert-reset-chapter ()
28 (insert "\n\\setcounter{chapter}{1}\n"))
30 (defun muse-insert-all-poems-header ()
31 (insert "\n\\renewcommand{\\poemtoc}{chapter}
32 \\settocdepth{chapter}\n"))
34 ;; I use my own sectioning commands in conjunction with memoir.cls
35 (setcdr (assq 'chapter muse-latex-markup-strings) "\\mychapter{")
36 (setcdr (assq 'section muse-latex-markup-strings) "\\mysection{")
37 (setcdr (assq 'subsection muse-latex-markup-strings) "\\mysubsection{")
38 (setcdr (assq 'subsubsection muse-latex-markup-strings) "\\mysubsubsection{")
40 ;; Relocate the images directory
41 ;(setcdr (assq 'image-with-desc muse-latex-markup-strings)
42 ; "\\includegraphics[width=\\textwidth]{../%s}")
43 (setcdr (assq 'image-with-desc muse-latex-markup-strings)
44 "\\includegraphics[scale=0.6]{../%s}")
45 (setcdr (assq 'image-link muse-latex-markup-strings)
46 "\\includegraphics[scale=0.6]{../%s}")
47 (setcdr (assq 'url-with-image muse-latex-markup-strings)
48 "%% %s\n\\includegraphics[scale=0.6]{../%s}")
50 (muse-derive-style "site-html" "html"
51 :maintainer "jwiegley@hotmail.com"
52 :before 'muse-maybe-convert-poem
53 :after 'muse-my-html-finalize-buffer
54 :final 'muse-site-html-set-mode
55 :header "~/Documents/site/header.html"
56 :footer "~/Documents/site/footer.html")
57 (muse-derive-style "site-journal-html" "journal-html"
58 :maintainer "jwiegley@hotmail.com"
59 :before 'muse-my-journal-find-entries
60 :after 'muse-my-journal-insert-contents
61 :final 'muse-site-html-set-mode
62 :header "~/Documents/site/header.html"
63 :footer "~/Documents/site/footer.html")
64 (muse-derive-style "newartisans-html" "html"
65 :maintainer "johnw@newartisans.com"
66 :header "~/Sites/newartisans/header.html"
67 :footer "~/Sites/newartisans/footer.html")
68 (muse-derive-style "newartisans-journal-html" "journal-html"
69 :maintainer "johnw@newartisans.com"
70 :header "~/Sites/newartisans/header.html"
71 :footer "~/Sites/newartisans/footer.html")
73 (custom-set-variables
74 '(muse-project-alist
75 (quote
76 (("website" ; my various writings
77 (:book-part "Essays"
78 :book-funcall muse-insert-reset-chapter
79 "~/Documents/essays"
80 :book-part "Stories"
81 :book-funcall muse-insert-reset-chapter
82 "~/Documents/stories"
83 :book-part "Journal"
84 :book-style "journal-book-pdf"
85 :book-funcall muse-insert-reset-chapter
86 "~/Documents/journal/early"
87 "~/Documents/journal/summer2003"
88 "~/Documents/journal/j2003"
89 "~/Documents/journal/j2004"
90 "~/Documents/journal/j2005"
91 "~/Documents/journal/journal"
92 "~/Documents/journal/pending"
93 :book-part "Poems"
94 :book-style "chapbook-pdf"
95 :book-funcall muse-insert-all-poems-header
96 :book-funcall muse-insert-reset-chapter
97 :nochapters t ; do automatically add chapters
98 :book-chapter "Mystical"
99 "~/Documents/poems/mystical"
100 :book-chapter "Romance"
101 "~/Documents/poems/romantic"
102 :book-chapter "Nature"
103 "~/Documents/poems/natural"
104 :book-chapter "Melancholoy"
105 "~/Documents/poems/melancholy"
106 :book-chapter "Commentary"
107 "~/Documents/poems/commentary"
108 :book-end t
109 "~/Documents/contents"
110 "~/Documents/notes"
111 :default "journal")
113 (:base "site-html" :path "~/Sites/johnw"
114 :include "/contents/recent")
115 (:base "pdf" :path "~/Sites/johnw/pdf"
116 :include "/\\(essays\\|stories\\)/")
117 (:base "poem-pdf" :path "~/Sites/johnw/pdf"
118 :include "/poems/")
119 (:base "site-html" :path "~/Sites/johnw"
120 :exclude "/journal/")
121 (:base "journal-pdf" :path "~/Sites/johnw/pdf"
122 :include "/journal/")
123 (:base "site-journal-html" :path "~/Sites/johnw"
124 :include "/journal/")
125 (:base "journal-rdf" :path "~/Sites/johnw"
126 :include "/journal/journal"
127 :base-url "http://johnwiegley.com/")
128 (:base "journal-rss" :path "~/Sites/johnw"
129 :include "/journal/journal"
130 :base-url "http://johnwiegley.com/")
131 (:base "journal-rss" :path "~/Sites/johnw"
132 :include "/journal/pending"
133 :base-url "http://johnwiegley.com/"))
134 ("thoughts" ; collected writings
135 (:book-end t
136 "~/Documents/thoughts/thoughts"
137 :default "thoughts")
138 (:base "journal-pdf" :path "~/Sites/johnw/pdf")
139 (:base "site-journal-html" :path "~/Sites/johnw"))
140 ("newartisans" ; my company
141 ("~/Documents/newartisans"
142 :default "index")
143 (:base "newartisans-html" :path "~/Sites/newartisans"
144 :exclude "/news")
145 (:base "newartisans-journal-html" :path "~/Sites/newartisans"
146 :include "/news"))
147 ("planner" ; my company
148 ("~/Private/plan"
149 :default "TaskPool"
150 :major-mode planner-mode)))))
151 '(muse-mode-highlight-p t nil (muse-colors))
152 '(muse-mode-auto-p t nil (muse-project))
153 '(muse-latex-header "~/Documents/site/header.tex")
154 '(muse-latex-footer "~/Documents/site/footer.tex")
155 '(muse-book-latex-header "~/Documents/site/book-header.tex")
156 '(muse-poem-latex-header "~/Documents/site/poem-header.tex")
157 '(muse-poem-latex-footer "~/Documents/site/poem-footer.tex")
158 '(muse-chapbook-latex-header "~/Documents/site/chapbook-header.tex")
159 ;;'(muse-before-publish-hook (quote (muse-cite-munge-footnotes)))
160 '(muse-mode-hook (quote (list footnote-mode turn-on-auto-fill flyspell-mode))))
162 (defun muse-publish-my-books (&optional force)
163 (interactive "P")
164 (muse-book-publish-project
165 '("essays" ("~/Documents/essays"))
166 "essays" "Collected Essays" "book-pdf" "~/Sites/johnw/pdf" force)
167 (muse-book-publish-project
168 '("stories" ("~/Documents/stories"))
169 "stories" "Collected Stories" "book-pdf" "~/Sites/johnw/pdf" force)
170 (muse-book-publish-project
171 '("myjournal"
172 ("~/Documents/journal/early"
173 "~/Documents/journal/summer2003"
174 "~/Documents/journal/j2003"
175 "~/Documents/journal/j2004"
176 "~/Documents/journal/j2005"
177 "~/Documents/journal/journal"
178 :book-end t
179 "~/Documents/poems/mystical"
180 "~/Documents/poems/romantic"
181 "~/Documents/poems/natural"
182 "~/Documents/poems/melancholy"
183 "~/Documents/poems/commentary"))
184 "myjournal" "Thought Journal" "journal-book-pdf" "~/Sites/johnw/pdf" force)
185 (muse-book-publish-project
186 '("poems"
187 (:nochapters t ; do automatically add chapters
188 :book-chapter "Mystical"
189 "~/Documents/poems/mystical"
190 :book-chapter "Romance"
191 "~/Documents/poems/romantic"
192 :book-chapter "Nature"
193 "~/Documents/poems/natural"
194 :book-chapter "Melancholoy"
195 "~/Documents/poems/melancholy"
196 :book-chapter "Commentary"
197 "~/Documents/poems/commentary"))
198 "poems" "Collected Poems" "chapbook-pdf" "~/Sites/johnw/pdf" force)
199 (muse-book-publish-project
200 "website" "writings" "Collected Writings" "book-pdf"
201 "~/Sites/johnw/pdf" force))
203 (defun modules-get-version-and-date (module)
204 (let (version date)
205 (with-temp-buffer
206 (insert-file-contents-literally module nil 0 1000)
207 (if (re-search-forward "Version:\\s-+\\(.*\\)" nil t)
208 (setq version (match-string 1))))
209 (setq date (format-time-string "%Y-%m-%d"
210 (nth 5 (file-attributes module))))
211 (concat (and muse-publishing-p "<span class=\"version\">")
212 (if version
213 (format "%s (%s)" date version)
214 date)
215 (and muse-publishing-p "</span>"))))
217 (defun muse-blog-add-entry ()
218 (interactive)
219 (muse-project-find-file "journal" "website")
220 (goto-char (point-min))
221 (forward-line 3)
222 (insert "* " (format-time-string "%Y%m%d: ")
223 (read-string "Journal entry title: ")
224 "\n\n\n\n")
225 (forward-line -2))
227 (defun muse-my-html-insert-contents (&optional ignore)
228 (let ((index 1)
229 base contents l)
230 (save-excursion
231 (goto-char (point-min))
232 (search-forward "Page published by Emacs Muse begins here" nil t)
233 (catch 'done
234 (while (re-search-forward "^<h\\([0-9]+\\)>\\(.+?\\)</h\\1>" nil t)
235 (unless (get-text-property (point) 'read-only)
236 (setq l (1- (string-to-number (match-string 1))))
237 (if (null base)
238 (setq base l)
239 (if (< l base)
240 (throw 'done t)))
241 (when (<= l 1)
242 (setq contents (cons (cons l (muse-match-string-no-properties 2))
243 contents))
244 (goto-char (match-beginning 2))
245 (muse-html-insert-anchor (concat "sec" (int-to-string index)))
246 (setq index (1+ index)))))))
247 (setq index 1 contents (reverse contents))
248 (when (> (length contents) 0)
249 (goto-char (point-min))
250 (or (search-forward "<h2>Archives</h2>" nil t)
251 (search-forward "#include virtual=\"/sidebar.html\"" nil t))
252 (beginning-of-line)
253 (insert "<h2>Contents</h2>\n\n<ul>\n")
254 (dolist (item contents)
255 (insert "<li><a href=\"" (muse-publish-output-name)
256 "#sec" (int-to-string index) "\">"
257 (muse-publish-strip-tags (cdr item))
258 "</a></li>\n")
259 (setq index (1+ index)))
260 (insert "</ul>\n"))))
262 (defun muse-my-html-finalize-buffer ()
263 (when muse-publish-generate-contents
264 (muse-my-html-insert-contents (cdr muse-publish-generate-contents))
265 (setq muse-publish-generate-contents nil))
266 (when (string= (muse-publish-output-name) "recent.html")
267 (goto-char (point-min))
268 (search-forward "Page published by Emacs Muse")
269 (forward-line 1)
270 (delete-region (point-min) (point))
271 (search-forward "Page published by Emacs Muse")
272 (beginning-of-line)
273 (delete-region (point) (point-max))))
275 (defun muse-site-html-set-mode (file output-path final-target)
276 (set-file-modes output-path ?\755))
278 (defvar muse-my-journal-entries nil)
279 (defvar muse-my-journal-nested t)
281 (defun muse-my-journal-find-entries ()
282 (goto-char (point-min))
283 (let ((heading-regexp (concat "^\\* " muse-journal-heading-regexp "$"))
284 (inhibit-read-only t)
285 entries)
286 (while (re-search-forward heading-regexp nil t)
287 (let ((begin (match-beginning 0))
288 (date (match-string 1))
289 (title (muse-match-string-no-properties 2))
290 enclosure qotd desc)
291 (if title
292 (save-match-data
293 (if (string-match muse-explicit-link-regexp title)
294 (setq enclosure (match-string 1 title)
295 title (match-string 2 title)))))
296 (save-match-data
297 (when (and date
298 (string-match
299 (concat "\\([1-9][0-9][0-9][0-9]\\)[./]?"
300 "\\([0-1][0-9]\\)[./]?\\([0-3][0-9]\\)") date))
301 (setq date (encode-time 0 0 0
302 (string-to-number (match-string 3 date))
303 (string-to-number (match-string 2 date))
304 (string-to-number (match-string 1 date))
305 (current-time-zone)))))
306 (while (string-match "\\*" title)
307 (setq title (replace-match "" nil nil title)))
308 (unless muse-my-journal-nested
309 (let* ((path (muse-style-element :path))
310 (item-path
311 (concat (expand-file-name (format-time-string "%Y/%m")
312 path)
313 "/" (muse-journal-anchorize-title title)))
314 (end
315 (save-excursion
316 (if (re-search-forward heading-regexp nil t)
317 (match-beginning 0)
318 (if (re-search-forward "^Footnotes:" nil t)
319 (match-beginning 0)
320 (point-max)))))
321 (data (buffer-substring begin end))
322 (footnotes
323 (save-excursion
324 (if (re-search-forward "^Footnotes:" nil t)
325 (buffer-substring (match-beginning 0) (point-max)))))
326 (project (muse-project)))
327 (save-excursion
328 (unless (file-directory-p (file-name-directory item-path))
329 (make-directory (file-name-directory item-path) t))
330 (find-file item-path)
331 (erase-buffer)
332 (insert "#title " title ?\n)
333 (insert "#date " (format-time-string "%B %e, %Y" date) ?\n)
334 (insert ?\n)
335 (setq begin (point))
336 (insert data)
337 (goto-char begin)
338 (forward-line 2)
339 (delete-region begin (point))
340 (goto-char (point-max))
341 (if footnotes
342 (insert ?\n footnotes))
343 (save-buffer)
344 (kill-buffer (current-buffer))
345 (let ((muse-my-journal-nested t)
346 (muse-current-project project))
347 (muse-publish-file item-path "journal-pdf"
348 (file-name-directory item-path))
349 (muse-publish-file item-path "site-journal-html"
350 (file-name-directory item-path)))
351 (delete-file item-path))))
352 (set (make-local-variable 'muse-my-journal-entries)
353 (cons (cons title date)
354 muse-my-journal-entries))))))
356 (defun muse-my-journal-insert-contents ()
357 (goto-char (point-min))
358 (or (search-forward "<h2>Archives</h2>" nil t)
359 (search-forward "#include virtual=\"/sidebar.html\"" nil t))
360 (beginning-of-line)
361 (if (string= "journal" (muse-page-name))
362 (insert "<h2>Recent Entries</h2>\n\n<ul>\n")
363 (insert "<h2>Contents</h2>\n\n<ul>\n"))
364 (dolist (entry (nreverse muse-my-journal-entries))
365 ;;(setq date (format-time-string "%m/%d" date))
366 ;;(if (= ?0 (aref date 0))
367 ;; (setq date (substring date 1)))
368 (insert (format "<li><a href=\"%s#%s\">%s</a></li>\n"
369 (muse-publish-output-name)
370 (muse-journal-anchorize-title (car entry))
371 (car entry))))
372 (insert "</ul>\n\n")
373 ;; jww (2005-04-17): a hack to rewrite MP3 titles
374 (goto-char (point-min))
375 (let ((inhibit-read-only t))
376 (while (re-search-forward "<h2><a href=\"\\([^\"]+\\)\">\\(.+?\\)</a></h2>" nil t)
377 (replace-match "<h2><a href=\"\\1\"><img src=\"images/speak.png\"></img></a>&nbsp;\\2</h2>"))))
379 ;; (eval-when-compile
380 ;; (defvar muse-current-project))
382 ;; (defvar muse-ref-tag '("ref" nil t muse-ref-markup-tag))
384 ;; (defun muse-ref-markup-tag (beg end attrs)
385 ;; "This markup tag allows a poem to be included from another project page.
386 ;; The form of usage is:
387 ;; <ref title=\"page.name[#subtitle]\">"
388 ;; (let ((page (cdr (assoc (cdr (assoc "title" attrs))
389 ;; (muse-project-file-alist))))
390 ;; beg start end text)
391 ;; (if (null page)
392 ;; (insert " *Reference to\n unknown page \""
393 ;; (cdr (assoc "title" attrs)) "\".*\n")
394 ;; (setq beg (point))
395 ;; (let (title)
396 ;; (if (string-match "html" muse-publishing-current-style)
397 ;; t
398 ;; (insert
399 ;; (with-temp-buffer
400 ;; (insert-file-contents page)
401 ;; (goto-char (point-min))
402 ;; (forward-paragraph)
403 ;; (forward-line)
404 ;; (buffer-substring-no-properties (point) (point-max)))))))))
406 ;; (add-to-list 'muse-publish-markup-tags muse-ref-tag)
408 (when (and window-system (load "httpd" t))
409 (require 'muse-http)
410 ;;(add-hook 'after-init-hook 'httpd-start)
411 (setq httpd-document-root (expand-file-name "~/Sites/johnw")))
413 ;;(setq
414 ;; muse-cite-titles
415 ;; '(("Bahá'u'lláh"
416 ;; ("Kitáb-i-Íqán"
417 ;; "http://bahai-library.com/?file=bahaullah_kitab_iqan.html"
418 ;; "http://bahai-library.com/?file=bahaullah_kitab_iqan.html#%d"))
419 ;; ("`Abdu'l-Bahá"
420 ;; ("Promulgation of Universal Peace"
421 ;; "http://bahai-library.com/?file=abdulbaha_promulgation_universal_peace.html"
422 ;; "http://www.bahai-library.com/writings/abdulbaha/pup/pup.html#%d"))))
424 (provide 'muse-init)