~ubuntu-branches/ubuntu/karmic/muse-el/karmic

« back to all changes in this revision

Viewing changes to lisp/muse-poem.el

  • Committer: Bazaar Package Importer
  • Author(s): Michael W. Olson (GNU address)
  • Date: 2005-12-17 12:11:27 UTC
  • Revision ID: james.westby@ubuntu.com-20051217121127-b4yfr70a7hnrexdg
Tags: upstream-3.02.5
ImportĀ upstreamĀ versionĀ 3.02.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;;; muse-poem.el --- publish a poem to LaTex or PDF
 
2
 
 
3
;; Copyright (C) 2004, 2005  Free Software Foundation, Inc.
 
4
 
 
5
;; This file is not part of GNU Emacs.
 
6
 
 
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.
 
11
;;
 
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.
 
16
;;
 
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.
 
21
 
 
22
;;; Commentary:
 
23
 
 
24
;; I use a very particular for recording poetry.  It is:
 
25
;;
 
26
;;   Title
 
27
;;
 
28
;;
 
29
;;   Body of poem
 
30
;;
 
31
;;
 
32
;;   Annotations, history, notes, etc.
 
33
;;
 
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.
 
38
;;
 
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:
 
43
;;
 
44
;;   <poem title="name.of.poem.page">
 
45
;;
 
46
;; Let's assume the template above was called "name.of.poem.page";
 
47
;; then the above tag would result in this inclusion:
 
48
;;
 
49
;;   ** Title
 
50
;;
 
51
;;   > Body of poem
 
52
;;
 
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.
 
55
 
 
56
;;; Contributors:
 
57
 
 
58
;;; Code:
 
59
 
 
60
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
61
;;
 
62
;; Muse Poem Publishing
 
63
;;
 
64
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
65
 
 
66
(require 'muse-latex)
 
67
(require 'muse-project)
 
68
 
 
69
(defgroup muse-poem nil
 
70
  "Rules for marking up a Muse file as a LaTeX article."
 
71
  :group 'muse-latex)
 
72
 
 
73
(defcustom muse-poem-latex-header
 
74
  "\\documentclass[14pt,oneside]{memoir}
 
75
 
 
76
\\usepackage[english]{babel}
 
77
\\usepackage[latin1]{inputenc}
 
78
\\usepackage[T1]{fontenc}
 
79
 
 
80
\\setlength{\\beforepoemtitleskip}{-5.0ex}
 
81
 
 
82
\\begin{document}
 
83
 
 
84
\\pagestyle{empty}
 
85
 
 
86
\\renewcommand{\\poemtoc}{section}
 
87
\\settocdepth{section}
 
88
 
 
89
\\mbox{}
 
90
\\vfill
 
91
 
 
92
\\poemtitle{<lisp>(muse-publishing-directive \"title\")</lisp>}
 
93
 
 
94
\\settowidth{\\versewidth}{<lisp>muse-poem-longest-line</lisp>}\n\n"
 
95
  "Header used for publishing LaTeX poems.  This may be text or a filename."
 
96
  :type 'string
 
97
  :group 'muse-poem)
 
98
 
 
99
(defcustom muse-poem-latex-footer "\n\\vfill
 
100
\\mbox{}
 
101
 
 
102
\\end{document}"
 
103
  "Footer used for publishing LaTeX files.  This may be text or a filename."
 
104
  :type 'string
 
105
  :group 'muse-poem)
 
106
 
 
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)
 
115
 
 
116
(defcustom muse-chapbook-latex-header
 
117
  "\\documentclass{book}
 
118
 
 
119
\\usepackage[english]{babel}
 
120
\\usepackage[latin1]{inputenc}
 
121
\\usepackage[T1]{fontenc}
 
122
 
 
123
\\setlength{\\beforepoemtitleskip}{-5.0ex}
 
124
 
 
125
\\begin{document}
 
126
 
 
127
\\title{<lisp>(muse-publishing-directive \"title\")</lisp>}
 
128
\\author{<lisp>(muse-publishing-directive \"author\")</lisp>}
 
129
\\date{<lisp>(muse-publishing-directive \"date\")</lisp>}
 
130
 
 
131
\\maketitle
 
132
 
 
133
\\tableofcontents
 
134
 
 
135
\\renewcommand{\\poemtoc}{section}
 
136
\\settocdepth{section}\n"
 
137
  "Header used for publishing a book of poems in LaTeX form.
 
138
This may be text or a filename."
 
139
  :type 'string
 
140
  :group 'muse-poem)
 
141
 
 
142
(defcustom muse-chapbook-latex-footer "\n\\end{document}"
 
143
  "Footer used for publishing a book of poems in LaTeX form.
 
144
This may be text or a filename."
 
145
  :type 'string
 
146
  :group 'muse-poem)
 
147
 
 
148
(defvar muse-poem-longest-line "")
 
149
 
 
150
(defcustom muse-poem-chapbook-strings
 
151
  '((begin-verse . "\\newpage
 
152
\\mbox{}
 
153
\\vfill
 
154
 
 
155
\\poemtitle{<lisp>(muse-publishing-directive \"title\")</lisp>}
 
156
 
 
157
\\settowidth{\\versewidth}{<lisp>muse-poem-longest-line</lisp>}
 
158
 
 
159
\\begin{verse}[\\versewidth]\n")
 
160
    (end-verse   . "\n\\end{verse}\n\\vfill\n\\mbox{}")
 
161
    (verse-space . "\\vin "))
 
162
  "Strings used for marking up books of poems.
 
163
These cover the most basic kinds of markup, the handling of which
 
164
differs little between the various styles."
 
165
  :type '(alist :key-type symbol :value-type string)
 
166
  :group 'muse-poem)
 
167
 
 
168
(defun muse-poem-prepare-buffer ()
 
169
  (goto-char (point-min))
 
170
  (insert "#title ")
 
171
  (forward-line 1)
 
172
  (delete-region (point) (1+ (muse-line-end-position)))
 
173
  (insert "\n<verse>")
 
174
  (let ((beg (point)) end line)
 
175
    (if (search-forward "\n\n\n" nil t)
 
176
        (progn
 
177
          (setq end (copy-marker (match-beginning 0) t))
 
178
          (replace-match "\n</verse>\n")
 
179
          (delete-region (point) (point-max)))
 
180
      (goto-char (point-max))
 
181
      (setq end (point))
 
182
      (insert "</verse>\n"))
 
183
    (goto-char (1+ beg))
 
184
    (set (make-local-variable 'muse-poem-longest-line) "")
 
185
    (while (< (point) end)
 
186
      (setq line (buffer-substring-no-properties (point)
 
187
                                                 (muse-line-end-position)))
 
188
      (if (> (length line) (length muse-poem-longest-line))
 
189
          (setq muse-poem-longest-line line))
 
190
      (forward-line 1))
 
191
    nil))
 
192
 
 
193
(defvar muse-poem-tag '("poem" nil t muse-poem-markup-tag))
 
194
 
 
195
(defun muse-poem-markup-tag (beg end attrs)
 
196
  "This markup tag allows a poem to be included from another project page.
 
197
The form of usage is:
 
198
  <poem title=\"page.name\">"
 
199
  (let ((page (cdr (assoc (cdr (assoc "title" attrs))
 
200
                          (muse-project-file-alist))))
 
201
        beg end)
 
202
    (if (null page)
 
203
        (insert "  *Reference to\n  unknown poem \""
 
204
                (cdr (assoc "title" attrs)) "\".*\n")
 
205
      (setq beg (point))
 
206
      (insert
 
207
       (muse-with-temp-buffer
 
208
         (insert-file-contents page)
 
209
         (goto-char (point-min))
 
210
         (if (assoc "nohead" attrs)
 
211
             (progn
 
212
               (forward-line 3)
 
213
               (delete-region (point-min) (point)))
 
214
           (insert "** ")
 
215
           (search-forward "\n\n\n")
 
216
           (replace-match "\n\n"))
 
217
         (if (search-forward "\n\n\n" nil t)
 
218
             (setq end (match-beginning 0))
 
219
           (setq end (point-max)))
 
220
         (buffer-substring-no-properties (point-min) end)))
 
221
      (setq end (point-marker))
 
222
      (goto-char beg)
 
223
      (unless (assoc "nohead" attrs)
 
224
        (forward-line 2))
 
225
      (while (< (point) end)
 
226
        (insert "> ")
 
227
        (forward-line 1)))))
 
228
 
 
229
(add-to-list 'muse-publish-markup-tags muse-poem-tag)
 
230
 
 
231
(unless (assoc "poem-latex" muse-publishing-styles)
 
232
  (muse-derive-style "poem-latex" "latex"
 
233
                     :before  'muse-poem-prepare-buffer
 
234
                     :strings 'muse-poem-markup-strings
 
235
                     :header  'muse-poem-latex-header
 
236
                     :footer  'muse-poem-latex-footer)
 
237
 
 
238
  (muse-derive-style "poem-pdf" "pdf"
 
239
                     :before  'muse-poem-prepare-buffer
 
240
                     :strings 'muse-poem-markup-strings
 
241
                     :header  'muse-poem-latex-header
 
242
                     :footer  'muse-poem-latex-footer)
 
243
 
 
244
  (muse-derive-style "chapbook-latex" "latex"
 
245
                     :before  'muse-poem-prepare-buffer
 
246
                     :strings 'muse-poem-chapbook-strings
 
247
                     :header  'muse-chapbook-latex-header
 
248
                     :footer  'muse-chapbook-latex-footer)
 
249
 
 
250
  (muse-derive-style "chapbook-pdf" "pdf"
 
251
                     :before  'muse-poem-prepare-buffer
 
252
                     :strings 'muse-poem-chapbook-strings
 
253
                     :header  'muse-chapbook-latex-header
 
254
                     :footer  'muse-chapbook-latex-footer))
 
255
 
 
256
(provide 'muse-poem)
 
257
 
 
258
;;; muse-poem.el ends here