Make permissions more consistent
[muse-el.git] / muse-poem.el
blob6ff25546be5d332159a5604130bdc7d00dd3e37a
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;;
3 ;; Muse Poem Publishing
4 ;;
5 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7 ;;; Commentary:
9 ;; I use a very particular for recording poetry. It is:
11 ;; Title
14 ;; Body of poem
17 ;; Annotations, history, notes, etc.
19 ;; The `muse-poem' module makes it easy to attractively publish and
20 ;; reference poems in this format, using the "memoir" module for LaTeX
21 ;; publishing. It will also markup poems for every other output
22 ;; style, though none are nearly as pretty.
24 ;; Once a poem is written in this format, just publish it to PDF using
25 ;; the "poem-pdf" style. To make an inlined reference to a poem that
26 ;; you've written -- for example, from a blog page -- there is a
27 ;; "poem" tag defined by this module:
29 ;; <poem title="name.of.poem.page">
31 ;; Let's assume the template above was called "name.of.poem.page";
32 ;; then the above tag would result in this inclusion:
34 ;; ** Title
36 ;; > Body of poem
38 ;; I use this module for publishing all of the poems on my website,
39 ;; which are at: http://www.newartisans.com/johnw/poems.html.
41 (require 'muse-latex)
42 (require 'muse-project)
44 (defgroup muse-poem nil
45 "Rules for marking up a Muse file as a LaTeX article."
46 :group 'muse-latex)
48 (defcustom muse-poem-latex-header
49 "\\documentclass[14pt,oneside]{memoir}
51 \\usepackage[english]{babel}
52 \\usepackage[latin1]{inputenc}
53 \\usepackage[T1]{fontenc}
55 \\setlength{\\beforepoemtitleskip}{-5.0ex}
57 \\begin{document}
59 \\pagestyle{empty}
61 \\renewcommand{\\poemtoc}{section}
62 \\settocdepth{section}
64 \\mbox{}
65 \\vfill
67 \\poemtitle{<lisp>(muse-publishing-directive \"title\")</lisp>}
69 \\settowidth{\\versewidth}{<lisp>muse-poem-longest-line</lisp>}\n\n"
70 "Header used for publishing LaTeX poems."
71 :type '(choice string file)
72 :group 'muse-poem)
74 (defcustom muse-poem-latex-footer "\n\\vfill
75 \\mbox{}
77 \\end{document}"
78 "Footer used for publishing LaTeX files."
79 :type '(choice string file)
80 :group 'muse-poem)
82 (defvar muse-poem-markup-strings
83 '((begin-verse . "\\begin{verse}[\\versewidth]\n")
84 (verse-space . "\\vin "))
85 "Redefine the section heads, to match my private LaTeX setup.")
87 (defcustom muse-chapbook-latex-header
88 "\\documentclass{book}
90 \\usepackage[english]{babel}
91 \\usepackage[latin1]{inputenc}
92 \\usepackage[T1]{fontenc}
94 \\setlength{\\beforepoemtitleskip}{-5.0ex}
96 \\begin{document}
98 \\title{<lisp>(muse-publishing-directive \"title\")</lisp>}
99 \\author{<lisp>(muse-publishing-directive \"author\")</lisp>}
100 \\date{<lisp>(muse-publishing-directive \"date\")</lisp>}
102 \\maketitle
104 \\tableofcontents
106 \\renewcommand{\\poemtoc}{section}
107 \\settocdepth{section}\n"
108 "Header used for publishing books to LaTeX."
109 :type '(choice string file)
110 :group 'muse-poem)
112 (defcustom muse-chapbook-latex-footer "\n\\end{document}"
113 "Footer used for publishing books to LaTeX."
114 :type '(choice string file)
115 :group 'muse-poem)
117 (defvar muse-poem-longest-line "")
119 (defvar muse-poem-chapbook-strings
120 '((begin-verse . "\\newpage
121 \\mbox{}
122 \\vfill
124 \\poemtitle{<lisp>(muse-publishing-directive \"title\")</lisp>}
126 \\settowidth{\\versewidth}{<lisp>muse-poem-longest-line</lisp>}
128 \\begin{verse}[\\versewidth]\n")
129 (end-verse . "\n\\end{verse}\n\\vfill\n\\mbox{}")
130 (verse-space . "\\vin "))
131 "Redefine the section heads, to match my private LaTeX setup.")
133 (defun muse-poem-prepare-buffer ()
134 (goto-char (point-min))
135 (insert "#title ")
136 (forward-line 1)
137 (delete-region (point) (1+ (line-end-position)))
138 (insert "\n<verse>")
139 (let ((beg (point)) end line)
140 (if (search-forward "\n\n\n" nil t)
141 (progn
142 (setq end (copy-marker (match-beginning 0) t))
143 (replace-match "\n</verse>\n")
144 (delete-region (point) (point-max)))
145 (goto-char (point-max))
146 (setq end (point))
147 (insert "</verse>\n"))
148 (goto-char (1+ beg))
149 (set (make-local-variable 'muse-poem-longest-line) "")
150 (while (< (point) end)
151 (setq line (buffer-substring-no-properties (point)
152 (line-end-position)))
153 (if (> (length line) (length muse-poem-longest-line))
154 (setq muse-poem-longest-line line))
155 (forward-line 1))
156 nil))
158 (eval-when-compile
159 (defvar muse-current-project))
161 (defvar muse-poem-tag '("poem" nil t muse-poem-markup-tag))
163 (defun muse-poem-markup-tag (beg end attrs)
164 "This markup tag allows a poem to be included from another project page.
165 The form of usage is:
166 <poem title=\"page.name\">"
167 (let ((page (cdr (assoc (cdr (assoc "title" attrs))
168 (muse-project-file-alist))))
169 beg start end text)
170 (if (null page)
171 (insert " *Reference to\n unknown poem \""
172 (cdr (assoc "title" attrs)) "\".*\n")
173 (setq beg (point))
174 (insert
175 (with-temp-buffer
176 (insert-file-contents page)
177 (goto-char (point-min))
178 (if (assoc "nohead" attrs)
179 (progn
180 (forward-line 3)
181 (delete-region (point-min) (point)))
182 (insert "** ")
183 (search-forward "\n\n\n")
184 (replace-match "\n\n"))
185 (if (search-forward "\n\n\n" nil t)
186 (setq end (match-beginning 0))
187 (setq end (point-max)))
188 (buffer-substring-no-properties (point-min) end)))
189 (setq end (point-marker))
190 (goto-char beg)
191 (unless (assoc "nohead" attrs)
192 (forward-line 2))
193 (while (< (point) end)
194 (insert "> ")
195 (forward-line 1)))))
197 (add-to-list 'muse-publish-markup-tags muse-poem-tag)
199 (unless (assoc "poem-latex" muse-publishing-styles)
200 (muse-derive-style "poem-latex" "latex"
201 :before 'muse-poem-prepare-buffer
202 :strings 'muse-poem-markup-strings
203 :header 'muse-poem-latex-header
204 :footer 'muse-poem-latex-footer)
206 (muse-derive-style "poem-pdf" "pdf"
207 :before 'muse-poem-prepare-buffer
208 :strings 'muse-poem-markup-strings
209 :header 'muse-poem-latex-header
210 :footer 'muse-poem-latex-footer)
212 (muse-derive-style "chapbook-latex" "latex"
213 :before 'muse-poem-prepare-buffer
214 :strings 'muse-poem-chapbook-strings
215 :header 'muse-chapbook-latex-header
216 :footer 'muse-chapbook-latex-footer)
218 (muse-derive-style "chapbook-pdf" "pdf"
219 :before 'muse-poem-prepare-buffer
220 :strings 'muse-poem-chapbook-strings
221 :header 'muse-chapbook-latex-header
222 :footer 'muse-chapbook-latex-footer))
224 (provide 'muse-poem)
226 ;;; muse-poem.el ends here