Try to make Muse play nice with outline minor mode.
[muse-el.git] / lisp / muse-poem.el
blob7e76b6f96f741cc3e739865a8fd2d2cbdae79f18
1 ;;; muse-poem.el --- Publish a poem to LaTex or PDF.
3 ;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
5 ;; This file is not part of GNU Emacs.
7 ;; This is free software; you can redistribute it and/or modify it under
8 ;; the terms of the GNU General Public License as published by the Free
9 ;; Software Foundation; either version 2, or (at your option) any later
10 ;; version.
12 ;; This is distributed in the hope that it will be useful, but WITHOUT
13 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 ;; for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ;; Boston, MA 02110-1301, USA.
22 ;;; Commentary:
24 ;; I use a very particular for recording poetry. It is:
26 ;; Title
29 ;; Body of poem
32 ;; Annotations, history, notes, etc.
34 ;; The `muse-poem' module makes it easy to attractively publish and
35 ;; reference poems in this format, using the "memoir" module for LaTeX
36 ;; publishing. It will also markup poems for every other output
37 ;; style, though none are nearly as pretty.
39 ;; Once a poem is written in this format, just publish it to PDF using
40 ;; the "poem-pdf" style. To make an inlined reference to a poem that
41 ;; you've written -- for example, from a blog page -- there is a
42 ;; "poem" tag defined by this module:
44 ;; <poem title="name.of.poem.page">
46 ;; Let's assume the template above was called "name.of.poem.page";
47 ;; then the above tag would result in this inclusion:
49 ;; ** Title
51 ;; > Body of poem
53 ;; I use this module for publishing all of the poems on my website,
54 ;; which are at: http://www.newartisans.com/johnw/poems.html.
56 ;;; Contributors:
58 ;;; Code:
60 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
62 ;; Muse Poem Publishing
64 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
66 (require 'muse-latex)
67 (require 'muse-project)
69 (defgroup muse-poem nil
70 "Rules for marking up a Muse file as a LaTeX article."
71 :group 'muse-latex)
73 (defcustom muse-poem-latex-header
74 "\\documentclass[14pt,oneside]{memoir}
76 \\usepackage[english]{babel}
77 \\usepackage[latin1]{inputenc}
78 \\usepackage[T1]{fontenc}
80 \\setlength{\\beforepoemtitleskip}{-5.0ex}
82 \\begin{document}
84 \\pagestyle{empty}
86 \\renewcommand{\\poemtoc}{section}
87 \\settocdepth{section}
89 \\mbox{}
90 \\vfill
92 \\poemtitle{<lisp>(muse-publishing-directive \"title\")</lisp>}
94 \\settowidth{\\versewidth}{<lisp>muse-poem-longest-line</lisp>}\n\n"
95 "Header used for publishing LaTeX poems."
96 :type '(choice string file)
97 :group 'muse-poem)
99 (defcustom muse-poem-latex-footer "\n\\vfill
100 \\mbox{}
102 \\end{document}"
103 "Footer used for publishing LaTeX files."
104 :type '(choice string file)
105 :group 'muse-poem)
107 (defcustom muse-poem-markup-strings
108 '((begin-verse . "\\begin{verse}[\\versewidth]\n")
109 (verse-space . "\\vin "))
110 "Strings used for marking up poems.
111 These cover the most basic kinds of markup, the handling of which
112 differs little between the various styles."
113 :type '(alist :key-type symbol :value-type string)
114 :group 'muse-poem)
116 (defcustom muse-chapbook-latex-header
117 "\\documentclass{book}
119 \\usepackage[english]{babel}
120 \\usepackage[latin1]{inputenc}
121 \\usepackage[T1]{fontenc}
123 \\setlength{\\beforepoemtitleskip}{-5.0ex}
125 \\begin{document}
127 \\title{<lisp>(muse-publishing-directive \"title\")</lisp>}
128 \\author{<lisp>(muse-publishing-directive \"author\")</lisp>}
129 \\date{<lisp>(muse-publishing-directive \"date\")</lisp>}
131 \\maketitle
133 \\tableofcontents
135 \\renewcommand{\\poemtoc}{section}
136 \\settocdepth{section}\n"
137 "Header used for publishing a book of poems in LaTeX form."
138 :type '(choice string file)
139 :group 'muse-poem)
141 (defcustom muse-chapbook-latex-footer "\n\\end{document}"
142 "Footer used for publishing a book of poems in LaTeX form."
143 :type '(choice string file)
144 :group 'muse-poem)
146 (defvar muse-poem-longest-line "")
148 (defcustom muse-poem-chapbook-strings
149 '((begin-verse . "\\newpage
150 \\mbox{}
151 \\vfill
153 \\poemtitle{<lisp>(muse-publishing-directive \"title\")</lisp>}
155 \\settowidth{\\versewidth}{<lisp>muse-poem-longest-line</lisp>}
157 \\begin{verse}[\\versewidth]\n")
158 (end-verse . "\n\\end{verse}\n\\vfill\n\\mbox{}")
159 (verse-space . "\\vin "))
160 "Strings used for marking up books of poems.
161 These cover the most basic kinds of markup, the handling of which
162 differs little between the various styles."
163 :type '(alist :key-type symbol :value-type string)
164 :group 'muse-poem)
166 (defun muse-poem-prepare-buffer ()
167 (goto-char (point-min))
168 (insert "#title ")
169 (forward-line 1)
170 (delete-region (point) (1+ (muse-line-end-position)))
171 (insert "\n<verse>")
172 (let ((beg (point)) end line)
173 (if (search-forward "\n\n\n" nil t)
174 (progn
175 (setq end (copy-marker (match-beginning 0) t))
176 (replace-match "\n</verse>\n")
177 (delete-region (point) (point-max)))
178 (goto-char (point-max))
179 (setq end (point))
180 (insert "</verse>\n"))
181 (goto-char (1+ beg))
182 (set (make-local-variable 'muse-poem-longest-line) "")
183 (while (< (point) end)
184 (setq line (buffer-substring-no-properties (point)
185 (muse-line-end-position)))
186 (if (> (length line) (length muse-poem-longest-line))
187 (setq muse-poem-longest-line line))
188 (forward-line 1))
189 nil))
191 (eval-when-compile
192 (defvar muse-current-project))
194 (defvar muse-poem-tag '("poem" nil t muse-poem-markup-tag))
196 (defun muse-poem-markup-tag (beg end attrs)
197 "This markup tag allows a poem to be included from another project page.
198 The form of usage is:
199 <poem title=\"page.name\">"
200 (let ((page (cdr (assoc (cdr (assoc "title" attrs))
201 (muse-project-file-alist))))
202 beg end)
203 (if (null page)
204 (insert " *Reference to\n unknown poem \""
205 (cdr (assoc "title" attrs)) "\".*\n")
206 (setq beg (point))
207 (insert
208 (with-temp-buffer
209 (insert-file-contents page)
210 (goto-char (point-min))
211 (if (assoc "nohead" attrs)
212 (progn
213 (forward-line 3)
214 (delete-region (point-min) (point)))
215 (insert "** ")
216 (search-forward "\n\n\n")
217 (replace-match "\n\n"))
218 (if (search-forward "\n\n\n" nil t)
219 (setq end (match-beginning 0))
220 (setq end (point-max)))
221 (buffer-substring-no-properties (point-min) end)))
222 (setq end (point-marker))
223 (goto-char beg)
224 (unless (assoc "nohead" attrs)
225 (forward-line 2))
226 (while (< (point) end)
227 (insert "> ")
228 (forward-line 1)))))
230 (add-to-list 'muse-publish-markup-tags muse-poem-tag)
232 (unless (assoc "poem-latex" muse-publishing-styles)
233 (muse-derive-style "poem-latex" "latex"
234 :before 'muse-poem-prepare-buffer
235 :strings 'muse-poem-markup-strings
236 :header 'muse-poem-latex-header
237 :footer 'muse-poem-latex-footer)
239 (muse-derive-style "poem-pdf" "pdf"
240 :before 'muse-poem-prepare-buffer
241 :strings 'muse-poem-markup-strings
242 :header 'muse-poem-latex-header
243 :footer 'muse-poem-latex-footer)
245 (muse-derive-style "chapbook-latex" "latex"
246 :before 'muse-poem-prepare-buffer
247 :strings 'muse-poem-chapbook-strings
248 :header 'muse-chapbook-latex-header
249 :footer 'muse-chapbook-latex-footer)
251 (muse-derive-style "chapbook-pdf" "pdf"
252 :before 'muse-poem-prepare-buffer
253 :strings 'muse-poem-chapbook-strings
254 :header 'muse-chapbook-latex-header
255 :footer 'muse-chapbook-latex-footer))
257 (provide 'muse-poem)
259 ;;; muse-poem.el ends here