1 ;;; muse-texinfo.el --- Publish entries to Texinfo format 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
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
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.
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
101 '(;; join together the parts of a list or table
103 "@end \\(\\(multi\\)?table\\|itemize\\|enumerate\\)\n+@\\1.*\n+" 0 ""))
104 "List of markup rules for publishing a Muse page to Texinfo.
105 For more on the structure of this list, see `muse-publish-markup-regexps'."
106 :type
'(repeat (choice
107 (list :tag
"Markup rule"
109 (choice regexp symbol
)
111 (choice string function symbol
))
113 :group
'muse-texinfo
)
115 (defcustom muse-texinfo-markup-functions
116 '((table . muse-texinfo-markup-table
))
117 "An alist of style types to custom functions for that kind of text.
118 For more on the structure of this list, see
119 `muse-publish-markup-functions'."
120 :type
'(alist :key-type symbol
:value-type function
)
121 :group
'muse-texinfo
)
123 (defcustom muse-texinfo-markup-strings
124 '((image-with-desc .
"@image{%s}")
125 (image-link .
"@image{%s}")
126 (url-with-image .
"@uref{%s, %s}")
127 (url-link .
"@uref{%s, %s}")
128 (email-addr .
"@email{%s}")
131 (enddots .
"@enddots")
133 (section .
"@chapter ")
134 (subsection .
"@section ")
135 (subsubsection .
"@subsection ")
136 (section-other .
"@subsubheading ")
137 (footnote .
"@footnote{")
139 (begin-underline .
"_")
140 (end-underline .
"_")
141 (begin-literal .
"@samp{")
143 (begin-emph .
"@emph{")
145 (begin-more-emph .
"@strong{")
146 (end-more-emph .
"}")
147 (begin-most-emph .
"@strong{@emph{")
148 (end-most-emph .
"}}")
149 (begin-verse .
"@display\n")
150 (end-verse-line .
"")
151 (verse-space .
"@ @ ")
152 (end-verse .
"\n@end display")
153 (begin-example .
"@example")
154 (end-example .
"@end example")
155 (begin-center .
"@center\n")
156 (end-center .
"\n@end center")
157 (begin-quote .
"@quotation\n")
158 (end-quote .
"\n@end quotation")
159 (begin-uli .
"@itemize @bullet\n@item\n")
160 (end-uli .
"\n@end itemize")
161 (begin-oli .
"@enumerate\n@item\n")
162 (end-oli .
"\n@end enumerate")
163 (begin-ddt .
"@table @strong\n@item ")
165 (end-ddt .
"\n@end table"))
166 "Strings used for marking up text.
167 These cover the most basic kinds of markup, the handling of which
168 differs little between the various styles."
169 :type
'(alist :key-type symbol
:value-type string
)
170 :group
'muse-texinfo
)
172 (defcustom muse-texinfo-markup-specials
176 "A table of characters which must be represented specially."
177 :type
'(alist :key-type character
:value-type string
)
178 :group
'muse-texinfo
)
180 (defun muse-texinfo-markup-table ()
183 (delete-region (match-beginning 0) (match-end 0))))
184 (fields (split-string str
"\\s-*|+\\s-*")))
185 (insert "@multitable @columnfractions")
186 (dotimes (field (length fields
))
187 (insert " " (number-to-string (/ 1.0 (length fields
)))))
188 (insert "\n@item " (mapconcat 'identity fields
" @tab "))
189 (insert "\n@end multitable")))
191 (defun muse-texinfo-finalize-buffer ()
192 (goto-char (point-min))
193 (muse-latex-fixup-dquotes)
194 (texinfo-insert-node-lines (point-min) (point-max) t
)
195 (texinfo-all-menus-update t
))
197 (defun muse-texinfo-pdf-browse-file (file)
198 (shell-command (concat "open " file
)))
200 (defun muse-texinfo-info-generate (file output-path final-target
)
201 ;; The version of `texinfmt.el' that comes with Emacs 21 doesn't
202 ;; support @documentencoding, so hack it in.
203 (when (and (not (featurep 'xemacs
))
204 (eq emacs-major-version
21))
205 (put 'documentencoding
'texinfo-format
206 'texinfo-discard-line-with-args
))
207 (muse-publish-transform-output
208 file output-path final-target
"Info"
210 (lambda (file output-path
)
211 (if muse-texinfo-process-natively
212 (save-window-excursion
215 (let ((inhibit-read-only t
))
216 (texinfo-format-buffer))
218 (kill-buffer (current-buffer))
219 (let ((buf (get-file-buffer file
)))
220 (with-current-buffer buf
221 (set-buffer-modified-p nil
)
222 (kill-buffer (current-buffer))))
225 (concat "makeinfo --enable-encoding --output="
226 output-path
" " file
))))))))
228 (defun muse-texinfo-pdf-generate (file output-path final-target
)
229 (muse-publish-transform-output
230 file output-path final-target
"PDF"
232 (lambda (file output-path
)
233 (= 0 (shell-command (concat "texi2pdf -q --clean --output="
234 output-path
" " file
)))))))
236 (unless (assoc "texi" muse-publishing-styles
)
237 (muse-define-style "texi"
238 :suffix
'muse-texinfo-extension
239 :regexps
'muse-texinfo-markup-regexps
240 :functions
'muse-texinfo-markup-functions
241 :strings
'muse-texinfo-markup-strings
242 :specials
'muse-texinfo-markup-specials
243 :after
'muse-texinfo-finalize-buffer
244 :header
'muse-texinfo-header
245 :footer
'muse-texinfo-footer
248 (muse-derive-style "info" "texi"
249 :final
'muse-texinfo-info-generate
250 :osuffix
'muse-texinfo-info-extension
253 (muse-derive-style "info-pdf" "texi"
254 :final
'muse-texinfo-pdf-generate
255 :osuffix
'muse-texinfo-pdf-extension
256 :browser
'muse-texinfo-pdf-browse-file
))
258 (provide 'muse-texinfo
)
260 ;;; muse-texinfo.el ends here