]> code.delx.au - gnu-emacs-elpa/blob - packages/muse/muse-poem.el
Merge commit '0cda39255827f283e7578cd469ae42daad9556a2' from js2-mode
[gnu-emacs-elpa] / packages / muse / muse-poem.el
1 ;;; muse-poem.el --- publish a poem to LaTex or PDF
2
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
5
6 ;; This file is part of Emacs Muse. It is not part of GNU Emacs.
7
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.
12
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.
17
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.
22
23 ;;; Commentary:
24
25 ;; This file specifies a form for recording poetry. It is as follows.
26 ;;
27 ;; Title
28 ;;
29 ;;
30 ;; Body of poem
31 ;;
32 ;;
33 ;; Annotations, history, notes, etc.
34 ;;
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.
39 ;;
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:
44 ;;
45 ;; <poem title="name.of.poem.page">
46 ;;
47 ;; Let's assume the template above was called "name.of.poem.page";
48 ;; then the above tag would result in this inclusion:
49 ;;
50 ;; ** Title
51 ;;
52 ;; > Body of poem
53 ;;
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.
56
57 ;;; Contributors:
58
59 ;;; Code:
60
61 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
62 ;;
63 ;; Muse Poem Publishing
64 ;;
65 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
66
67 (require 'muse-latex)
68 (require 'muse-project)
69
70 (defgroup muse-poem nil
71 "Rules for marking up a Muse file as a LaTeX article."
72 :group 'muse-latex)
73
74 (defcustom muse-poem-latex-header
75 "\\documentclass[14pt,oneside]{memoir}
76
77 \\usepackage[english]{babel}
78 \\usepackage[latin1]{inputenc}
79 \\usepackage[T1]{fontenc}
80
81 \\setlength{\\beforepoemtitleskip}{-5.0ex}
82
83 \\begin{document}
84
85 \\pagestyle{empty}
86
87 \\renewcommand{\\poemtoc}{section}
88 \\settocdepth{section}
89
90 \\mbox{}
91 \\vfill
92
93 \\poemtitle{<lisp>(muse-publishing-directive \"title\")</lisp>}
94
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)
99
100 (defcustom muse-poem-latex-footer "\n\\vfill
101 \\mbox{}
102
103 \\end{document}"
104 "Footer used for publishing LaTeX files. This may be text or a filename."
105 :type 'string
106 :group 'muse-poem)
107
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)
116
117 (defcustom muse-chapbook-latex-header
118 "\\documentclass{book}
119
120 \\usepackage[english]{babel}
121 \\usepackage[latin1]{inputenc}
122 \\usepackage[T1]{fontenc}
123
124 \\setlength{\\beforepoemtitleskip}{-5.0ex}
125
126 \\begin{document}
127
128 \\title{<lisp>(muse-publishing-directive \"title\")</lisp>}
129 \\author{<lisp>(muse-publishing-directive \"author\")</lisp>}
130 \\date{<lisp>(muse-publishing-directive \"date\")</lisp>}
131
132 \\maketitle
133
134 \\tableofcontents
135
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)
142
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)
148
149 (defvar muse-poem-longest-line "")
150
151 (defcustom muse-poem-chapbook-strings
152 '((begin-verse . "\\newpage
153 \\mbox{}
154 \\vfill
155
156 \\poemtitle{<lisp>(muse-publishing-directive \"title\")</lisp>}
157
158 \\settowidth{\\versewidth}{<lisp>muse-poem-longest-line</lisp>}
159
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)
168
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))
193
194 (defvar muse-poem-tag '("poem" nil t nil muse-poem-markup-tag))
195
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))))
230
231 (put 'muse-poem-markup-tag 'muse-dangerous-tag t)
232
233 (add-to-list 'muse-publish-markup-tags muse-poem-tag)
234
235 ;;; Register the Muse POEM Publishers
236
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)
242
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)
248
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)
254
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)
260
261 (provide 'muse-poem)
262
263 ;;; muse-poem.el ends here