1 ;;; muse-poem.el --- publish a poem to LaTex or PDF
3 ;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
5 ;; This file is part of Emacs Muse. It is not part of GNU Emacs.
7 ;; Emacs Muse is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published
9 ;; by the Free Software Foundation; either version 2, or (at your
10 ;; option) any later version.
12 ;; Emacs Muse is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with Emacs Muse; 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.
24 ;; This file specifies a form for recording poetry. It is as follows.
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:
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.
60 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
62 ;; Muse Poem Publishing
64 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
67 (require 'muse-project
)
69 (defgroup muse-poem nil
70 "Rules for marking up a Muse file as a LaTeX article."
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}
86 \\renewcommand{\\poemtoc}{section}
87 \\settocdepth{section}
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. This may be text or a filename."
99 (defcustom muse-poem-latex-footer
"\n\\vfill
103 "Footer used for publishing LaTeX files. This may be text or a filename."
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
)
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}
127 \\title{<lisp>(muse-publishing-directive \"title\")</lisp>}
128 \\author{<lisp>(muse-publishing-directive \"author\")</lisp>}
129 \\date{<lisp>(muse-publishing-directive \"date\")</lisp>}
135 \\renewcommand{\\poemtoc}{section}
136 \\settocdepth{section}\n"
137 "Header used for publishing a book of poems in LaTeX form.
138 This may be text or a filename."
142 (defcustom muse-chapbook-latex-footer
"\n\\end{document}"
143 "Footer used for publishing a book of poems in LaTeX form.
144 This may be text or a filename."
148 (defvar muse-poem-longest-line
"")
150 (defcustom muse-poem-chapbook-strings
151 '((begin-verse .
"\\newpage
155 \\poemtitle{<lisp>(muse-publishing-directive \"title\")</lisp>}
157 \\settowidth{\\versewidth}{<lisp>muse-poem-longest-line</lisp>}
159 \\begin{verse}[\\versewidth]\n")
160 (end-verse .
"\n\\end{verse}\n\\vfill\n\\mbox{}")
161 (verse-space .
"\\vin "))
162 "Strings used for marking up books of poems.
163 These cover the most basic kinds of markup, the handling of which
164 differs little between the various styles."
165 :type
'(alist :key-type symbol
:value-type string
)
168 (defun muse-poem-prepare-buffer ()
169 (goto-char (point-min))
172 (delete-region (point) (1+ (muse-line-end-position)))
174 (let ((beg (point)) end line
)
175 (if (search-forward "\n\n\n" nil t
)
177 (setq end
(copy-marker (match-beginning 0) t
))
178 (replace-match "\n</verse>\n")
179 (delete-region (point) (point-max)))
180 (goto-char (point-max))
182 (insert "</verse>\n"))
184 (set (make-local-variable 'muse-poem-longest-line
) "")
185 (while (< (point) end
)
186 (setq line
(buffer-substring-no-properties (point)
187 (muse-line-end-position)))
188 (if (> (length line
) (length muse-poem-longest-line
))
189 (setq muse-poem-longest-line line
))
193 (defvar muse-poem-tag
'("poem" nil t muse-poem-markup-tag
))
195 (defun muse-poem-markup-tag (beg end attrs
)
196 "This markup tag allows a poem to be included from another project page.
197 The form of usage is:
198 <poem title=\"page.name\">"
199 (let ((page (cdr (assoc (cdr (assoc "title" attrs
))
200 (muse-project-file-alist))))
203 (insert " *Reference to\n unknown poem \""
204 (cdr (assoc "title" attrs
)) "\".*\n")
207 (muse-with-temp-buffer
208 (insert-file-contents page
)
209 (goto-char (point-min))
210 (if (assoc "nohead" attrs
)
213 (delete-region (point-min) (point)))
215 (search-forward "\n\n\n")
216 (replace-match "\n\n"))
217 (if (search-forward "\n\n\n" nil t
)
218 (setq end
(match-beginning 0))
219 (setq end
(point-max)))
220 (buffer-substring-no-properties (point-min) end
)))
221 (setq end
(point-marker))
223 (unless (assoc "nohead" attrs
)
225 (while (< (point) end
)
229 (add-to-list 'muse-publish-markup-tags muse-poem-tag
)
231 (unless (assoc "poem-latex" muse-publishing-styles
)
232 (muse-derive-style "poem-latex" "latex"
233 :before
'muse-poem-prepare-buffer
234 :strings
'muse-poem-markup-strings
235 :header
'muse-poem-latex-header
236 :footer
'muse-poem-latex-footer
)
238 (muse-derive-style "poem-pdf" "pdf"
239 :before
'muse-poem-prepare-buffer
240 :strings
'muse-poem-markup-strings
241 :header
'muse-poem-latex-header
242 :footer
'muse-poem-latex-footer
)
244 (muse-derive-style "chapbook-latex" "latex"
245 :before
'muse-poem-prepare-buffer
246 :strings
'muse-poem-chapbook-strings
247 :header
'muse-chapbook-latex-header
248 :footer
'muse-chapbook-latex-footer
)
250 (muse-derive-style "chapbook-pdf" "pdf"
251 :before
'muse-poem-prepare-buffer
252 :strings
'muse-poem-chapbook-strings
253 :header
'muse-chapbook-latex-header
254 :footer
'muse-chapbook-latex-footer
))
258 ;;; muse-poem.el ends here