Don't compile documentation by default.
[muse-el.git] / muse-poem.el
blobf84b20eaf6a3b1ea9bcb1a3b4bf1279aad86f532
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., 59 Temple Place - Suite 330, Boston,
20 ;; MA 02111-1307, 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 (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}
121 \\begin{document}
123 \\title{<lisp>(muse-publishing-directive \"title\")</lisp>}
124 \\author{<lisp>(muse-publishing-directive \"author\")</lisp>}
125 \\date{<lisp>(muse-publishing-directive \"date\")</lisp>}
127 \\maketitle
129 \\tableofcontents
131 \\renewcommand{\\poemtoc}{section}
132 \\settocdepth{section}\n"
133 "Header used for publishing books to LaTeX."
134 :type '(choice string file)
135 :group 'muse-poem)
137 (defcustom muse-chapbook-latex-footer "\n\\end{document}"
138 "Footer used for publishing books to LaTeX."
139 :type '(choice string file)
140 :group 'muse-poem)
142 (defvar muse-poem-longest-line "")
144 (defvar muse-poem-chapbook-strings
145 '((begin-verse . "\\newpage
146 \\mbox{}
147 \\vfill
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))
160 (insert "#title ")
161 (forward-line 1)
162 (delete-region (point) (1+ (line-end-position)))
163 (insert "\n<verse>")
164 (let ((beg (point)) end line)
165 (if (search-forward "\n\n\n" nil t)
166 (progn
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))
171 (setq end (point))
172 (insert "</verse>\n"))
173 (goto-char (1+ beg))
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))
180 (forward-line 1))
181 nil))
183 (eval-when-compile
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))))
194 beg start end text)
195 (if (null page)
196 (insert " *Reference to\n unknown poem \""
197 (cdr (assoc "title" attrs)) "\".*\n")
198 (setq beg (point))
199 (insert
200 (with-temp-buffer
201 (insert-file-contents page)
202 (goto-char (point-min))
203 (if (assoc "nohead" attrs)
204 (progn
205 (forward-line 3)
206 (delete-region (point-min) (point)))
207 (insert "** ")
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))
215 (goto-char beg)
216 (unless (assoc "nohead" attrs)
217 (forward-line 2))
218 (while (< (point) end)
219 (insert "> ")
220 (forward-line 1)))))
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))
249 (provide 'muse-poem)
251 ;;; muse-poem.el ends here