1 ;;; muse-groff.el --- publish groff -mom -mwww files
3 ;; Copyright (C) 2005 Free Software Foundation, Inc.
5 ;; Author: Andrew J. Korty (ajk AT iu DOT edu)
6 ;; Date: Tue 5-Jul-2005
8 ;; This file is part of Emacs Muse. It is not part of GNU Emacs.
10 ;; Emacs Muse is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published
12 ;; by the Free Software Foundation; either version 2, or (at your
13 ;; option) any later version.
15 ;; Emacs Muse is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with Emacs Muse; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
31 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 ;; Muse Publishing Using groff -mom -mwww
35 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37 (require 'muse-publish
)
39 (defgroup muse-groff nil
40 "Rules for marking up a Muse file with groff -mom -mwww macros."
43 (defcustom muse-groff-extension
".groff"
44 "Default file extension for publishing groff -mom -mwww files."
48 (defcustom muse-groff-pdf-extension
".pdf"
49 "Default file extension for publishing groff -mom -mwww files to PDF."
53 (defcustom muse-groff-header
54 ".TITLE \"<lisp>(muse-publishing-directive \"title\")</lisp>\"
55 .SUBTITLE \"<lisp>(muse-publishing-directive \"date\")</lisp>\"
56 .AUTHOR \"<lisp>(muse-publishing-directive \"author\")</lisp>\"
64 <lisp>(and muse-publish-generate-contents \".TOC\n\")</lisp>\n"
65 "Header used for publishing groff -mom -mwww files."
66 :type
'(choice string file
)
69 (defcustom muse-groff-footer
" "
70 "Footer used for publishing groff -mom -mwww files."
71 :type
'(choice string file
)
74 (defcustom muse-groff-markup-regexps
75 `((10400 ,(concat "\\(\n</\\(blockquote\\|center\\)>\\)?\n"
78 "]*\n\\)+\\(<\\(blockquote\\|center\\)>\n\\)?")
79 0 muse-groff-markup-paragraph
))
80 "List of markup regexps for identifying regions in a Muse page.
81 For more on the structure of this list, see `muse-publish-markup-regexps'."
82 :type
'(repeat (choice
83 (list :tag
"Markup rule"
85 (choice regexp symbol
)
87 (choice string function symbol
))
91 (defcustom muse-groff-markup-functions
92 '((table . muse-groff-markup-table
))
93 "An alist of style types to custom functions for that kind of text.
94 For more on the structure of this list, see
95 `muse-publish-markup-functions'."
96 :type
'(alist :key-type symbol
:value-type function
)
99 (defcustom muse-groff-markup-tags
101 "A list of tag specifications, for specially marking up GROFF."
102 :type
'(repeat (list (string :tag
"Markup tag")
103 (boolean :tag
"Expect closing tag" :value t
)
104 (boolean :tag
"Parse attributes" :value nil
)
108 (defcustom muse-groff-markup-strings
109 `((image-with-desc .
"\n.MPIMG -R %s.%s\n")
110 (image .
"\n.MPIMG -R %s.%s\n")
111 (image-link .
"\n.\\\" %s\n.MPIMG -R %s.%s")
112 (url .
"\n.URL %s %s\n\\z")
113 (link .
"\n.URL %s %s\n\\z")
114 (email-addr .
"\f[C]%s\f[]")
117 (no-break-space .
"\\h")
120 ;; (part . "\\part{")
122 ;; (chapter . "\\chapter{")
123 ;; (chapter-end . "}")
124 (section .
".HEAD \"")
126 (subsection .
".SUBHEAD \"")
127 (subsection-end .
"\"")
128 (subsubsection .
".PARAHEAD \"")
129 (subsubsection-end .
"\"")
130 ;; (footnote . "\\c\n.FOOTNOTE\n")
131 ;; (footnote-end . "\n.FOOTNOTE OFF\n")
132 ;; (footnotemark . "\\footnotemark[%d]")
133 ;; (footnotetext . "\\footnotetext[%d]{")
134 ;; (footnotetext-end . "}")
135 (begin-underline .
"\n.UNDERSCORE \"")
136 (end-underline .
"\"\n")
137 (begin-literal .
"\\fC")
138 (end-literal .
"\\fP")
139 (begin-emph .
"\\fI")
141 (begin-more-emph .
"\\fB")
142 (end-more-emph .
"\\fP")
143 (begin-most-emph .
"\\f(BI")
144 (end-most-emph .
"\\fP")
145 (begin-verse .
".QUOTE")
146 (end-verse .
".QUOTE OFF")
147 (begin-center .
"\n.CENTER\n")
148 (end-center .
"\n.QUAD L\n")
149 (begin-example .
,(concat
150 ".QUOTE_FONT CR\n.QUOTE_INDENT 1\n"".QUOTE_SIZE -2\n"
151 ".UNDERLINE_QUOTES OFF\n.QUOTE"))
152 (end-example .
".QUOTE OFF")
153 (begin-quote .
".BLOCKQUOTE")
154 (end-quote .
".BLOCKQUOTE OFF")
155 (begin-uli .
".list BULLET\n.SHIFT_LIST 2m\n.ITEM\n")
156 (end-uli .
"\n.LIST OFF")
157 (begin-oli .
".list DIGIT\n.SHIFT_LIST 2m\n.ITEM\n")
158 (end-oli .
"\n.LIST OFF")
160 (begin-dde .
"\\fP\n.IR 4P\n")
161 (end-ddt .
".IRX CLEAR"))
162 "Strings used for marking up text.
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
)
168 (defcustom muse-groff-markup-specials
170 "A table of characters which must be represented specially."
171 :type
'(alist :key-type character
:value-type string
)
174 (defun muse-groff-markup-paragraph ()
175 (let ((end (copy-marker (match-end 0) t
)))
176 (goto-char (1+ (match-beginning 0)))
177 (delete-region (point) end
)
178 (unless (looking-at "\.\\(\\(\\(SUB\\|PARA\\)?HEAD \\)\\|RULE$\\)")
179 (muse-insert-markup ".ALD .5v\n.PP\n.ne 2\n"))))
181 (defun muse-groff-protect-leading-chars ()
182 "Protect leading periods and apostrophes from being interpreted as
184 (while (re-search-forward "^[.']" nil t
)
185 (replace-match "\\\\&\\&" t
)))
187 (defun muse-groff-concat-lists ()
191 (while (re-search-forward "^\.LIST[ \t]+\\(.*\\)\n" nil t
)
192 (setq arg
(match-string 1))
193 (if (string= arg
"OFF")
194 (setq begin
(match-beginning 0))
195 (if (and begin
(string= type arg
))
196 (delete-region begin
(match-end 0))
200 (defun muse-groff-fixup-dquotes ()
201 "Fixup double quotes."
203 (while (search-forward "\"" nil t
)
204 (unless (get-text-property (match-beginning 0) 'read-only
)
205 (if (and (bolp) (eq (char-before) ?
\n))
214 (defun muse-groff-prepare-buffer ()
215 (goto-char (point-min))
216 (muse-groff-protect-leading-chars))
218 (defun muse-groff-finalize-buffer ()
219 (goto-char (point-min))
220 (muse-groff-concat-lists))
222 (defun muse-groff-pdf-browse-file (file)
223 (shell-command (concat "open " file
)))
225 (defun muse-groff-pdf-generate (file output-path final-target
)
226 (muse-publish-transform-output
227 file output-path final-target
"PDF"
229 (lambda (file output-path
)
232 (concat "file=%s; ext=%s; cd %s && cp $file$ext $file.ref && "
233 "groff -mom -mwww -t $file$ext > $file.ps && "
235 (file-name-sans-extension file
)
237 (file-name-directory output-path
))))
238 (shell-command command
))))
241 (unless (assoc "groff" muse-publishing-styles
)
242 (muse-define-style "groff"
243 :suffix
'muse-groff-extension
244 :regexps
'muse-groff-markup-regexps
245 ;;; :functions 'muse-groff-markup-functions
246 :strings
'muse-groff-markup-strings
247 :tags
'muse-groff-markup-tags
248 :specials
'muse-groff-markup-specials
249 :before
'muse-groff-prepare-buffer
250 :after
'muse-groff-finalize-buffer
251 :header
'muse-groff-header
252 :footer
'muse-groff-footer
255 (muse-derive-style "groff-pdf" "groff"
256 :final
'muse-groff-pdf-generate
257 :browser
'muse-groff-pdf-browse-file
258 :osuffix
'muse-groff-pdf-extension
))
260 (provide 'muse-groff
)
262 ;;; muse-groff.el ends here
265 ;; indent-tabs-mode: nil