1 ;;; muse-texinfo.el --- publish entries to Texinfo format or PDF
3 ;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
5 ;; This file is part of Emacs Muse. It is not part of GNU Emacs.
7 ;; Emacs Muse is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published
9 ;; by the Free Software Foundation; either version 2, or (at your
10 ;; option) any later version.
12 ;; Emacs Muse is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with Emacs Muse; 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.
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;; Muse Texinfo Publishing
32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34 (require 'muse-publish
)
38 (defgroup muse-texinfo nil
39 "Rules for marking up a Muse file as a Texinfo article."
42 (defcustom muse-texinfo-process-natively t
43 "If non-nil, use the Emacs `texinfmt' module to make Info files."
48 (defcustom muse-texinfo-extension
".texi"
49 "Default file extension for publishing Texinfo files."
53 (defcustom muse-texinfo-info-extension
".info"
54 "Default file extension for publishing Info files."
58 (defcustom muse-texinfo-pdf-extension
".pdf"
59 "Default file extension for publishing PDF files."
63 (defcustom muse-texinfo-header
64 "\\input texinfo @c -*-texinfo-*-
66 @setfilename <lisp>(concat (muse-page-name) \".info\")</lisp>
67 @settitle <lisp>(muse-publishing-directive \"title\")</lisp>
69 @documentencoding iso-8859-1
76 @title <lisp>(muse-publishing-directive \"title\")</lisp>
77 @author <lisp>(muse-publishing-directive \"author\")</lisp>
80 <lisp>(and muse-publish-generate-contents \"@contents\")</lisp>
82 @node Top, Overview, , (dir)
84 @c Page published by Emacs Muse begins here\n\n"
85 "Text to prepend to a Muse page being published as Texinfo.
86 This may be text or a filename.
87 It may contain <lisp> markup tags."
91 (defcustom muse-texinfo-footer
92 "\n@c Page published by Emacs Muse ends here
94 "Text to append to a Muse page being published as Texinfo.
95 This may be text or a filename.
96 It may contain <lisp> markup tags."
100 (defcustom muse-texinfo-markup-regexps nil
101 "List of markup rules for publishing a Muse page to Texinfo.
102 For more on the structure of this list, see `muse-publish-markup-regexps'."
103 :type
'(repeat (choice
104 (list :tag
"Markup rule"
106 (choice regexp symbol
)
108 (choice string function symbol
))
110 :group
'muse-texinfo
)
112 (defcustom muse-texinfo-markup-functions
113 '((table . muse-texinfo-markup-table
)
114 (heading . muse-texinfo-markup-heading
))
115 "An alist of style types to custom functions for that kind of text.
116 For more on the structure of this list, see
117 `muse-publish-markup-functions'."
118 :type
'(alist :key-type symbol
:value-type function
)
119 :group
'muse-texinfo
)
121 (defcustom muse-texinfo-markup-strings
122 '((image-with-desc .
"@center @image{%1%, , , %3%, %2%}@*\n@center %3%")
123 (image .
"@noindent @image{%s, , , , %s}")
124 (image-link .
"@uref{%s, %s.%s}")
125 (anchor-ref .
"@ref{%s, %s}")
127 (link .
"@ref{Top, , Overview, %s, %s}")
128 (link-and-anchor .
"@ref{%2%, , %2%, %1%, %3%}")
129 (email-addr .
"@email{%s}")
130 (anchor .
"@anchor{%s} ")
132 (comment-begin .
"@ignore\n")
133 (comment-end .
"\n@end ignore\n")
135 (no-break-space .
"@w{ }")
136 (enddots .
"@enddots{}")
138 (section .
"@chapter ")
139 (subsection .
"@section ")
140 (subsubsection .
"@subsection ")
141 (section-other .
"@subsubheading ")
142 (footnote .
"@footnote{")
144 (begin-underline .
"_")
145 (end-underline .
"_")
146 (begin-literal .
"@samp{")
148 (begin-emph .
"@emph{")
150 (begin-more-emph .
"@strong{")
151 (end-more-emph .
"}")
152 (begin-most-emph .
"@strong{@emph{")
153 (end-most-emph .
"}}")
154 (begin-verse .
"@display\n")
155 (end-verse-line .
"")
156 (verse-space .
"@ @ ")
157 (end-verse .
"\n@end display")
158 (begin-example .
"@example")
159 (end-example .
"@end example")
160 (begin-center .
"@quotation\n")
161 (end-center .
"\n@end quotation")
162 (begin-quote .
"@quotation\n")
163 (end-quote .
"\n@end quotation")
164 (begin-uli .
"@itemize @bullet\n")
165 (end-uli .
"\n@end itemize")
166 (begin-uli-item .
"@item\n")
167 (begin-oli .
"@enumerate\n")
168 (end-oli .
"\n@end enumerate")
169 (begin-oli-item .
"@item\n")
170 (begin-dl .
"@table @strong\n")
171 (end-dl .
"\n@end table")
172 (begin-ddt .
"@item "))
173 "Strings used for marking up text.
174 These cover the most basic kinds of markup, the handling of which
175 differs little between the various styles."
176 :type
'(alist :key-type symbol
:value-type string
)
177 :group
'muse-texinfo
)
179 (defcustom muse-texinfo-markup-specials
183 "A table of characters which must be represented specially."
184 :type
'(alist :key-type character
:value-type string
)
185 :group
'muse-texinfo
)
187 (defcustom muse-texinfo-markup-specials-url
192 "A table of characters which must be represented specially.
193 These are applied to URLs."
194 :type
'(alist :key-type character
:value-type string
)
195 :group
'muse-texinfo
)
197 (defun muse-texinfo-decide-specials (context)
198 "Determine the specials to escape, depending on CONTEXT."
199 (cond ((memq context
'(url image
))
200 muse-texinfo-markup-specials-url
)
201 (t muse-texinfo-markup-specials
)))
203 (defun muse-texinfo-markup-table ()
204 (let* ((table-info (muse-publish-table-fields (match-beginning 0)
206 (row-len (car table-info
))
207 (field-list (cdr table-info
)))
209 (muse-insert-markup "@multitable @columnfractions")
210 (dotimes (field row-len
)
211 (muse-insert-markup " " (number-to-string (/ 1.0 row-len
))))
212 (dolist (fields field-list
)
213 (let ((type (car fields
)))
214 (setq fields
(cdr fields
))
215 (muse-insert-markup "\n@item ")
216 (insert (car fields
))
217 (setq fields
(cdr fields
))
218 (dolist (field fields
)
219 (muse-insert-markup " @tab ")
221 (muse-insert-markup "\n@end multitable")
224 (defun muse-texinfo-remove-links (string)
225 "Remove explicit links from STRING, replacing them with the link
228 If no description exists for the link, use the link itself."
230 (while (setq start
(string-match muse-explicit-link-regexp string
233 (replace-match (or (match-string 2 string
)
234 (match-string 1 string
))
238 (defun muse-texinfo-markup-heading ()
240 (muse-publish-markup-heading))
241 (let* ((eol (muse-line-end-position))
242 (orig-heading (buffer-substring (point) eol
))
244 (delete-region (point) eol
)
245 ;; don't allow links to be published in headings
246 (insert (muse-texinfo-remove-links orig-heading
))
247 (muse-publish-mark-read-only beg
(point))))
249 (defun muse-texinfo-finalize-buffer ()
250 (muse-latex-fixup-dquotes)
251 (texinfo-insert-node-lines (point-min) (point-max) t
)
252 (texinfo-all-menus-update t
))
254 (defun muse-texinfo-pdf-browse-file (file)
255 (shell-command (concat "open " file
)))
257 (defun muse-texinfo-info-generate (file output-path final-target
)
258 ;; The version of `texinfmt.el' that comes with Emacs 21 doesn't
259 ;; support @documentencoding, so hack it in.
260 (when (and (not (featurep 'xemacs
))
261 (eq emacs-major-version
21))
262 (put 'documentencoding
'texinfo-format
263 'texinfo-discard-line-with-args
))
264 (muse-publish-transform-output
265 file output-path final-target
"Info"
267 (lambda (file output-path
)
268 (if muse-texinfo-process-natively
269 (save-window-excursion
272 (let ((inhibit-read-only t
))
273 (texinfo-format-buffer))
275 (kill-buffer (current-buffer))
276 (let ((buf (get-file-buffer file
)))
277 (with-current-buffer buf
278 (set-buffer-modified-p nil
)
279 (kill-buffer (current-buffer))))
282 (concat "makeinfo --enable-encoding --output="
283 output-path
" " file
))))))))
285 (defun muse-texinfo-pdf-generate (file output-path final-target
)
286 (muse-publish-transform-output
287 file output-path final-target
"PDF"
289 (lambda (file output-path
)
290 (= 0 (shell-command (concat "texi2pdf -q --clean --output="
291 output-path
" " file
)))))))
293 (unless (assoc "texi" muse-publishing-styles
)
294 (muse-define-style "texi"
295 :suffix
'muse-texinfo-extension
296 :regexps
'muse-texinfo-markup-regexps
297 :functions
'muse-texinfo-markup-functions
298 :strings
'muse-texinfo-markup-strings
299 :specials
'muse-texinfo-decide-specials
300 :after
'muse-texinfo-finalize-buffer
301 :header
'muse-texinfo-header
302 :footer
'muse-texinfo-footer
305 (muse-derive-style "info" "texi"
306 :final
'muse-texinfo-info-generate
307 :link-suffix
'muse-texinfo-info-extension
308 :osuffix
'muse-texinfo-info-extension
311 (muse-derive-style "info-pdf" "texi"
312 :final
'muse-texinfo-pdf-generate
313 :link-suffix
'muse-texinfo-pdf-extension
314 :osuffix
'muse-texinfo-pdf-extension
315 :browser
'muse-texinfo-pdf-browse-file
))
317 (provide 'muse-texinfo
)
319 ;;; muse-texinfo.el ends here