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
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
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., 59 Temple Place - Suite 330, Boston,
20 ;; MA 02111-1307, USA.
24 ;; I use a very particular for recording poetry. It is:
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."
96 :type
'(choice string file
)
99 (defcustom muse-poem-latex-footer
"\n\\vfill
103 "Footer used for publishing LaTeX files."
104 :type
'(choice string file
)
107 (defvar muse-poem-markup-strings
108 '((begin-verse .
"\\begin{verse}[\\versewidth]\n")
109 (verse-space .
"\\vin "))
110 "Redefine the section heads, to match my private LaTeX setup.")
112 (defcustom muse-chapbook-latex-header
113 "\\documentclass{book}
115 \\usepackage[english]{babel}
116 \\usepackage[latin1]{inputenc}
117 \\usepackage[T1]{fontenc}
119 \\setlength{\\beforepoemtitleskip}{-5.0ex}
123 \\title{<lisp>(muse-publishing-directive \"title\")</lisp>}
124 \\author{<lisp>(muse-publishing-directive \"author\")</lisp>}
125 \\date{<lisp>(muse-publishing-directive \"date\")</lisp>}
131 \\renewcommand{\\poemtoc}{section}
132 \\settocdepth{section}\n"
133 "Header used for publishing books to LaTeX."
134 :type
'(choice string file
)
137 (defcustom muse-chapbook-latex-footer
"\n\\end{document}"
138 "Footer used for publishing books to LaTeX."
139 :type
'(choice string file
)
142 (defvar muse-poem-longest-line
"")
144 (defvar muse-poem-chapbook-strings
145 '((begin-verse .
"\\newpage
149 \\poemtitle{<lisp>(muse-publishing-directive \"title\")</lisp>}
151 \\settowidth{\\versewidth}{<lisp>muse-poem-longest-line</lisp>}
153 \\begin{verse}[\\versewidth]\n")
154 (end-verse .
"\n\\end{verse}\n\\vfill\n\\mbox{}")
155 (verse-space .
"\\vin "))
156 "Redefine the section heads, to match my private LaTeX setup.")
158 (defun muse-poem-prepare-buffer ()
159 (goto-char (point-min))
162 (delete-region (point) (1+ (line-end-position)))
164 (let ((beg (point)) end line
)
165 (if (search-forward "\n\n\n" nil t
)
167 (setq end
(copy-marker (match-beginning 0) t
))
168 (replace-match "\n</verse>\n")
169 (delete-region (point) (point-max)))
170 (goto-char (point-max))
172 (insert "</verse>\n"))
174 (set (make-local-variable 'muse-poem-longest-line
) "")
175 (while (< (point) end
)
176 (setq line
(buffer-substring-no-properties (point)
177 (line-end-position)))
178 (if (> (length line
) (length muse-poem-longest-line
))
179 (setq muse-poem-longest-line line
))
184 (defvar muse-current-project
))
186 (defvar muse-poem-tag
'("poem" nil t muse-poem-markup-tag
))
188 (defun muse-poem-markup-tag (beg end attrs
)
189 "This markup tag allows a poem to be included from another project page.
190 The form of usage is:
191 <poem title=\"page.name\">"
192 (let ((page (cdr (assoc (cdr (assoc "title" attrs
))
193 (muse-project-file-alist))))
196 (insert " *Reference to\n unknown poem \""
197 (cdr (assoc "title" attrs
)) "\".*\n")
201 (insert-file-contents page
)
202 (goto-char (point-min))
203 (if (assoc "nohead" attrs
)
206 (delete-region (point-min) (point)))
208 (search-forward "\n\n\n")
209 (replace-match "\n\n"))
210 (if (search-forward "\n\n\n" nil t
)
211 (setq end
(match-beginning 0))
212 (setq end
(point-max)))
213 (buffer-substring-no-properties (point-min) end
)))
214 (setq end
(point-marker))
216 (unless (assoc "nohead" attrs
)
218 (while (< (point) end
)
222 (add-to-list 'muse-publish-markup-tags muse-poem-tag
)
224 (unless (assoc "poem-latex" muse-publishing-styles
)
225 (muse-derive-style "poem-latex" "latex"
226 :before
'muse-poem-prepare-buffer
227 :strings
'muse-poem-markup-strings
228 :header
'muse-poem-latex-header
229 :footer
'muse-poem-latex-footer
)
231 (muse-derive-style "poem-pdf" "pdf"
232 :before
'muse-poem-prepare-buffer
233 :strings
'muse-poem-markup-strings
234 :header
'muse-poem-latex-header
235 :footer
'muse-poem-latex-footer
)
237 (muse-derive-style "chapbook-latex" "latex"
238 :before
'muse-poem-prepare-buffer
239 :strings
'muse-poem-chapbook-strings
240 :header
'muse-chapbook-latex-header
241 :footer
'muse-chapbook-latex-footer
)
243 (muse-derive-style "chapbook-pdf" "pdf"
244 :before
'muse-poem-prepare-buffer
245 :strings
'muse-poem-chapbook-strings
246 :header
'muse-chapbook-latex-header
247 :footer
'muse-chapbook-latex-footer
))
251 ;;; muse-poem.el ends here