Add `muse-current-file', fix minor QuickStart issue.
[muse-el.git] / lisp / muse-poem.el
blob84441175ef40dbe681eb156baa3c66ee57004455
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 (defvar muse-poem-tag '("poem" nil t muse-poem-markup-tag))
193 (defun muse-poem-markup-tag (beg end attrs)
194 "This markup tag allows a poem to be included from another project page.
195 The form of usage is:
196 <poem title=\"page.name\">"
197 (let ((page (cdr (assoc (cdr (assoc "title" attrs))
198 (muse-project-file-alist))))
199 beg end)
200 (if (null page)
201 (insert " *Reference to\n unknown poem \""
202 (cdr (assoc "title" attrs)) "\".*\n")
203 (setq beg (point))
204 (insert
205 (with-temp-buffer
206 (insert-file-contents page)
207 (goto-char (point-min))
208 (if (assoc "nohead" attrs)
209 (progn
210 (forward-line 3)
211 (delete-region (point-min) (point)))
212 (insert "** ")
213 (search-forward "\n\n\n")
214 (replace-match "\n\n"))
215 (if (search-forward "\n\n\n" nil t)
216 (setq end (match-beginning 0))
217 (setq end (point-max)))
218 (buffer-substring-no-properties (point-min) end)))
219 (setq end (point-marker))
220 (goto-char beg)
221 (unless (assoc "nohead" attrs)
222 (forward-line 2))
223 (while (< (point) end)
224 (insert "> ")
225 (forward-line 1)))))
227 (add-to-list 'muse-publish-markup-tags muse-poem-tag)
229 (unless (assoc "poem-latex" muse-publishing-styles)
230 (muse-derive-style "poem-latex" "latex"
231 :before 'muse-poem-prepare-buffer
232 :strings 'muse-poem-markup-strings
233 :header 'muse-poem-latex-header
234 :footer 'muse-poem-latex-footer)
236 (muse-derive-style "poem-pdf" "pdf"
237 :before 'muse-poem-prepare-buffer
238 :strings 'muse-poem-markup-strings
239 :header 'muse-poem-latex-header
240 :footer 'muse-poem-latex-footer)
242 (muse-derive-style "chapbook-latex" "latex"
243 :before 'muse-poem-prepare-buffer
244 :strings 'muse-poem-chapbook-strings
245 :header 'muse-chapbook-latex-header
246 :footer 'muse-chapbook-latex-footer)
248 (muse-derive-style "chapbook-pdf" "pdf"
249 :before 'muse-poem-prepare-buffer
250 :strings 'muse-poem-chapbook-strings
251 :header 'muse-chapbook-latex-header
252 :footer 'muse-chapbook-latex-footer))
254 (provide 'muse-poem)
256 ;;; muse-poem.el ends here