Makefile: Correctly exclude htmlize-hack.el from byte-compilation.
[muse-el.git] / lisp / muse-poem.el
blobd531458f73924c763b9f2ce1d5722126838694b0
1 ;;; muse-poem.el --- publish a poem to LaTex or PDF
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
6 ;; This file is part of Emacs Muse. It is not part of GNU Emacs.
8 ;; Emacs Muse is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published
10 ;; by the Free Software Foundation; either version 3, or (at your
11 ;; option) any later version.
13 ;; Emacs Muse is distributed in the hope that it will be useful, but
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ;; General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with Emacs Muse; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 ;; Boston, MA 02110-1301, USA.
23 ;;; Commentary:
25 ;; This file specifies a form for recording poetry. It is as follows.
27 ;; Title
30 ;; Body of poem
33 ;; Annotations, history, notes, etc.
35 ;; The `muse-poem' module makes it easy to attractively publish and
36 ;; reference poems in this format, using the "memoir" module for LaTeX
37 ;; publishing. It will also markup poems for every other output
38 ;; style, though none are nearly as pretty.
40 ;; Once a poem is written in this format, just publish it to PDF using
41 ;; the "poem-pdf" style. To make an inlined reference to a poem that
42 ;; you've written -- for example, from a blog page -- there is a
43 ;; "poem" tag defined by this module:
45 ;; <poem title="name.of.poem.page">
47 ;; Let's assume the template above was called "name.of.poem.page";
48 ;; then the above tag would result in this inclusion:
50 ;; ** Title
52 ;; > Body of poem
54 ;; I use this module for publishing all of the poems on my website,
55 ;; which are at: http://www.newartisans.com/johnw/poems.html.
57 ;;; Contributors:
59 ;;; Code:
61 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
63 ;; Muse Poem Publishing
65 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
67 (require 'muse-latex)
68 (require 'muse-project)
70 (defgroup muse-poem nil
71 "Rules for marking up a Muse file as a LaTeX article."
72 :group 'muse-latex)
74 (defcustom muse-poem-latex-header
75 "\\documentclass[14pt,oneside]{memoir}
77 \\usepackage[english]{babel}
78 \\usepackage[latin1]{inputenc}
79 \\usepackage[T1]{fontenc}
81 \\setlength{\\beforepoemtitleskip}{-5.0ex}
83 \\begin{document}
85 \\pagestyle{empty}
87 \\renewcommand{\\poemtoc}{section}
88 \\settocdepth{section}
90 \\mbox{}
91 \\vfill
93 \\poemtitle{<lisp>(muse-publishing-directive \"title\")</lisp>}
95 \\settowidth{\\versewidth}{<lisp>muse-poem-longest-line</lisp>}\n\n"
96 "Header used for publishing LaTeX poems. This may be text or a filename."
97 :type 'string
98 :group 'muse-poem)
100 (defcustom muse-poem-latex-footer "\n\\vfill
101 \\mbox{}
103 \\end{document}"
104 "Footer used for publishing LaTeX files. This may be text or a filename."
105 :type 'string
106 :group 'muse-poem)
108 (defcustom muse-poem-markup-strings
109 '((begin-verse . "\\begin{verse}[\\versewidth]\n")
110 (verse-space . "\\vin "))
111 "Strings used for marking up poems.
112 These cover the most basic kinds of markup, the handling of which
113 differs little between the various styles."
114 :type '(alist :key-type symbol :value-type string)
115 :group 'muse-poem)
117 (defcustom muse-chapbook-latex-header
118 "\\documentclass{book}
120 \\usepackage[english]{babel}
121 \\usepackage[latin1]{inputenc}
122 \\usepackage[T1]{fontenc}
124 \\setlength{\\beforepoemtitleskip}{-5.0ex}
126 \\begin{document}
128 \\title{<lisp>(muse-publishing-directive \"title\")</lisp>}
129 \\author{<lisp>(muse-publishing-directive \"author\")</lisp>}
130 \\date{<lisp>(muse-publishing-directive \"date\")</lisp>}
132 \\maketitle
134 \\tableofcontents
136 \\renewcommand{\\poemtoc}{section}
137 \\settocdepth{section}\n"
138 "Header used for publishing a book of poems in LaTeX form.
139 This may be text or a filename."
140 :type 'string
141 :group 'muse-poem)
143 (defcustom muse-chapbook-latex-footer "\n\\end{document}"
144 "Footer used for publishing a book of poems in LaTeX form.
145 This may be text or a filename."
146 :type 'string
147 :group 'muse-poem)
149 (defvar muse-poem-longest-line "")
151 (defcustom muse-poem-chapbook-strings
152 '((begin-verse . "\\newpage
153 \\mbox{}
154 \\vfill
156 \\poemtitle{<lisp>(muse-publishing-directive \"title\")</lisp>}
158 \\settowidth{\\versewidth}{<lisp>muse-poem-longest-line</lisp>}
160 \\begin{verse}[\\versewidth]\n")
161 (end-verse . "\n\\end{verse}\n\\vfill\n\\mbox{}")
162 (verse-space . "\\vin "))
163 "Strings used for marking up books of poems.
164 These cover the most basic kinds of markup, the handling of which
165 differs little between the various styles."
166 :type '(alist :key-type symbol :value-type string)
167 :group 'muse-poem)
169 (defun muse-poem-prepare-buffer ()
170 (goto-char (point-min))
171 (insert "#title ")
172 (forward-line 1)
173 (delete-region (point) (1+ (muse-line-end-position)))
174 (insert "\n<verse>")
175 (let ((beg (point)) end line)
176 (if (search-forward "\n\n\n" nil t)
177 (progn
178 (setq end (copy-marker (match-beginning 0) t))
179 (replace-match "\n</verse>\n")
180 (delete-region (point) (point-max)))
181 (goto-char (point-max))
182 (setq end (point))
183 (insert "</verse>\n"))
184 (goto-char (1+ beg))
185 (set (make-local-variable 'muse-poem-longest-line) "")
186 (while (< (point) end)
187 (setq line (buffer-substring-no-properties (point)
188 (muse-line-end-position)))
189 (if (> (length line) (length muse-poem-longest-line))
190 (setq muse-poem-longest-line line))
191 (forward-line 1))
192 nil))
194 (defvar muse-poem-tag '("poem" nil t nil 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 (muse-with-temp-buffer
209 (muse-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))
229 (set-marker end nil))))
231 (put 'muse-poem-markup-tag 'muse-dangerous-tag t)
233 (add-to-list 'muse-publish-markup-tags muse-poem-tag)
235 ;;; Register the Muse POEM Publishers
237 (muse-derive-style "poem-latex" "latex"
238 :before 'muse-poem-prepare-buffer
239 :strings 'muse-poem-markup-strings
240 :header 'muse-poem-latex-header
241 :footer 'muse-poem-latex-footer)
243 (muse-derive-style "poem-pdf" "pdf"
244 :before 'muse-poem-prepare-buffer
245 :strings 'muse-poem-markup-strings
246 :header 'muse-poem-latex-header
247 :footer 'muse-poem-latex-footer)
249 (muse-derive-style "chapbook-latex" "latex"
250 :before 'muse-poem-prepare-buffer
251 :strings 'muse-poem-chapbook-strings
252 :header 'muse-chapbook-latex-header
253 :footer 'muse-chapbook-latex-footer)
255 (muse-derive-style "chapbook-pdf" "pdf"
256 :before 'muse-poem-prepare-buffer
257 :strings 'muse-poem-chapbook-strings
258 :header 'muse-chapbook-latex-header
259 :footer 'muse-chapbook-latex-footer)
261 (provide 'muse-poem)
263 ;;; muse-poem.el ends here