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 "An alist of style types to custom functions for that kind of text.
115 For more on the structure of this list, see
116 `muse-publish-markup-functions'."
117 :type
'(alist :key-type symbol
:value-type function
)
118 :group
'muse-texinfo
)
120 (defcustom muse-texinfo-markup-strings
121 '((image-with-desc .
"@image{%s}")
122 (image-link .
"@image{%s}")
123 (url-with-image .
"@uref{%s, %s}")
124 (anchor-ref .
"@ref{%s, %s}")
125 (url .
"@uref{%s, %s}")
126 (link .
"@ref{Top, , Overview, %s, %s}")
127 (link-and-anchor .
"@ref{%2%, , %2%, %1%, %3%}")
128 (email-addr .
"@email{%s}")
129 (anchor .
"@anchor{%s} ")
131 (comment-begin .
"@ignore\n")
132 (comment-end .
"\n@end ignore\n")
134 (no-break-space .
"@w{ }")
135 (enddots .
"@enddots{}")
137 (section .
"@chapter ")
138 (subsection .
"@section ")
139 (subsubsection .
"@subsection ")
140 (section-other .
"@subsubheading ")
141 (footnote .
"@footnote{")
143 (begin-underline .
"_")
144 (end-underline .
"_")
145 (begin-literal .
"@samp{")
147 (begin-emph .
"@emph{")
149 (begin-more-emph .
"@strong{")
150 (end-more-emph .
"}")
151 (begin-most-emph .
"@strong{@emph{")
152 (end-most-emph .
"}}")
153 (begin-verse .
"@display\n")
154 (end-verse-line .
"")
155 (verse-space .
"@ @ ")
156 (end-verse .
"\n@end display")
157 (begin-example .
"@example")
158 (end-example .
"@end example")
159 (begin-center .
"@quotation\n")
160 (end-center .
"\n@end quotation")
161 (begin-quote .
"@quotation\n")
162 (end-quote .
"\n@end quotation")
163 (begin-uli .
"@itemize @bullet\n")
164 (end-uli .
"\n@end itemize")
165 (begin-uli-item .
"@item\n")
166 (begin-oli .
"@enumerate\n")
167 (end-oli .
"\n@end enumerate")
168 (begin-oli-item .
"@item\n")
169 (begin-dl .
"@table @strong\n")
170 (end-dl .
"\n@end table")
171 (begin-ddt .
"@item "))
172 "Strings used for marking up text.
173 These cover the most basic kinds of markup, the handling of which
174 differs little between the various styles."
175 :type
'(alist :key-type symbol
:value-type string
)
176 :group
'muse-texinfo
)
178 (defcustom muse-texinfo-markup-specials
182 "A table of characters which must be represented specially."
183 :type
'(alist :key-type character
:value-type string
)
184 :group
'muse-texinfo
)
186 (defcustom muse-texinfo-markup-specials-url
191 "A table of characters which must be represented specially.
192 These are applied to URLs."
193 :type
'(alist :key-type character
:value-type string
)
194 :group
'muse-texinfo
)
196 (defun muse-texinfo-decide-specials (context)
197 "Determine the specials to escape, depending on CONTEXT."
198 (cond ((eq context
'url
)
199 muse-texinfo-markup-specials-url
)
200 (t muse-texinfo-markup-specials
)))
202 (defun muse-texinfo-markup-table ()
203 (let* ((table-info (muse-publish-table-fields (match-beginning 0)
205 (row-len (car table-info
))
206 (field-list (cdr table-info
)))
207 (muse-insert-markup "@multitable @columnfractions")
208 (dotimes (field row-len
)
209 (muse-insert-markup " " (number-to-string (/ 1.0 row-len
))))
210 (dolist (fields field-list
)
211 (let ((type (car fields
)))
212 (setq fields
(cdr fields
))
213 (muse-insert-markup "\n@item ")
214 (insert (car fields
))
215 (setq fields
(cdr fields
))
216 (dolist (field fields
)
217 (muse-insert-markup " @tab ")
219 (muse-insert-markup "\n@end multitable")
222 (defun muse-texinfo-finalize-buffer ()
223 (goto-char (point-min))
224 (muse-latex-fixup-dquotes)
225 (texinfo-insert-node-lines (point-min) (point-max) t
)
226 (texinfo-all-menus-update t
))
228 (defun muse-texinfo-pdf-browse-file (file)
229 (shell-command (concat "open " file
)))
231 (defun muse-texinfo-info-generate (file output-path final-target
)
232 ;; The version of `texinfmt.el' that comes with Emacs 21 doesn't
233 ;; support @documentencoding, so hack it in.
234 (when (and (not (featurep 'xemacs
))
235 (eq emacs-major-version
21))
236 (put 'documentencoding
'texinfo-format
237 'texinfo-discard-line-with-args
))
238 (muse-publish-transform-output
239 file output-path final-target
"Info"
241 (lambda (file output-path
)
242 (if muse-texinfo-process-natively
243 (save-window-excursion
246 (let ((inhibit-read-only t
))
247 (texinfo-format-buffer))
249 (kill-buffer (current-buffer))
250 (let ((buf (get-file-buffer file
)))
251 (with-current-buffer buf
252 (set-buffer-modified-p nil
)
253 (kill-buffer (current-buffer))))
256 (concat "makeinfo --enable-encoding --output="
257 output-path
" " file
))))))))
259 (defun muse-texinfo-pdf-generate (file output-path final-target
)
260 (muse-publish-transform-output
261 file output-path final-target
"PDF"
263 (lambda (file output-path
)
264 (= 0 (shell-command (concat "texi2pdf -q --clean --output="
265 output-path
" " file
)))))))
267 (unless (assoc "texi" muse-publishing-styles
)
268 (muse-define-style "texi"
269 :suffix
'muse-texinfo-extension
270 :regexps
'muse-texinfo-markup-regexps
271 :functions
'muse-texinfo-markup-functions
272 :strings
'muse-texinfo-markup-strings
273 :specials
'muse-texinfo-decide-specials
274 :after
'muse-texinfo-finalize-buffer
275 :header
'muse-texinfo-header
276 :footer
'muse-texinfo-footer
279 (muse-derive-style "info" "texi"
280 :final
'muse-texinfo-info-generate
281 :link-suffix
'muse-texinfo-info-extension
282 :osuffix
'muse-texinfo-info-extension
285 (muse-derive-style "info-pdf" "texi"
286 :final
'muse-texinfo-pdf-generate
287 :link-suffix
'muse-texinfo-pdf-extension
288 :osuffix
'muse-texinfo-pdf-extension
289 :browser
'muse-texinfo-pdf-browse-file
))
291 (provide 'muse-texinfo
)
293 ;;; muse-texinfo.el ends here