Merged from mwolson@gnu.org--2006 (patch 81)
[muse-el.git] / lisp / muse-poem.el
blob80cfbfbdbb38120c296ef33354f114293ec50f8e
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.
22 ;;; Commentary:
24 ;; This file specifies a form for recording poetry. It is as follows.
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. This may be text or a filename."
96 :type 'string
97 :group 'muse-poem)
99 (defcustom muse-poem-latex-footer "\n\\vfill
100 \\mbox{}
102 \\end{document}"
103 "Footer used for publishing LaTeX files. This may be text or a filename."
104 :type 'string
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 This may be text or a filename."
139 :type 'string
140 :group 'muse-poem)
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."
145 :type 'string
146 :group 'muse-poem)
148 (defvar muse-poem-longest-line "")
150 (defcustom muse-poem-chapbook-strings
151 '((begin-verse . "\\newpage
152 \\mbox{}
153 \\vfill
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)
166 :group 'muse-poem)
168 (defun muse-poem-prepare-buffer ()
169 (goto-char (point-min))
170 (insert "#title ")
171 (forward-line 1)
172 (delete-region (point) (1+ (muse-line-end-position)))
173 (insert "\n<verse>")
174 (let ((beg (point)) end line)
175 (if (search-forward "\n\n\n" nil t)
176 (progn
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))
181 (setq end (point))
182 (insert "</verse>\n"))
183 (goto-char (1+ beg))
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))
190 (forward-line 1))
191 nil))
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))))
201 beg end)
202 (if (null page)
203 (insert " *Reference to\n unknown poem \""
204 (cdr (assoc "title" attrs)) "\".*\n")
205 (setq beg (point))
206 (insert
207 (muse-with-temp-buffer
208 (insert-file-contents page)
209 (goto-char (point-min))
210 (if (assoc "nohead" attrs)
211 (progn
212 (forward-line 3)
213 (delete-region (point-min) (point)))
214 (insert "** ")
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))
222 (goto-char beg)
223 (unless (assoc "nohead" attrs)
224 (forward-line 2))
225 (while (< (point) end)
226 (insert "> ")
227 (forward-line 1)))))
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))
256 (provide 'muse-poem)
258 ;;; muse-poem.el ends here