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
102 (10000 ,(concat "@end \\(\\(multi\\)?table\\|itemize\\|enumerate\\)"
106 "List of markup rules for publishing a Muse page to Texinfo.
107 For more on the structure of this list, see `muse-publish-markup-regexps'."
108 :type
'(repeat (choice
109 (list :tag
"Markup rule"
111 (choice regexp symbol
)
113 (choice string function symbol
))
115 :group
'muse-texinfo
)
117 (defcustom muse-texinfo-markup-functions
118 '((anchor . muse-texinfo-markup-anchor
)
119 (table . muse-texinfo-markup-table
))
120 "An alist of style types to custom functions for that kind of text.
121 For more on the structure of this list, see
122 `muse-publish-markup-functions'."
123 :type
'(alist :key-type symbol
:value-type function
)
124 :group
'muse-texinfo
)
126 (defcustom muse-texinfo-markup-strings
127 '((image-with-desc .
"@image{%s}")
128 (image-link .
"@image{%s}")
129 (url-with-image .
"@uref{%s, %s}")
130 (url-link .
"@uref{%s, %s}")
131 (internal-link .
"@ref{%s, %s}")
132 (email-addr .
"@email{%s}")
134 (comment-begin .
"@ignore\n")
135 (comment-end .
"\n@end ignore\n")
137 (no-break-space .
"@w{ }")
138 (enddots .
"@enddots{}")
140 (section .
"@chapter ")
141 (subsection .
"@section ")
142 (subsubsection .
"@subsection ")
143 (section-other .
"@subsubheading ")
144 (footnote .
"@footnote{")
146 (begin-underline .
"_")
147 (end-underline .
"_")
148 (begin-literal .
"@samp{")
150 (begin-emph .
"@emph{")
152 (begin-more-emph .
"@strong{")
153 (end-more-emph .
"}")
154 (begin-most-emph .
"@strong{@emph{")
155 (end-most-emph .
"}}")
156 (begin-verse .
"@display\n")
157 (end-verse-line .
"")
158 (verse-space .
"@ @ ")
159 (end-verse .
"\n@end display")
160 (begin-example .
"@example")
161 (end-example .
"@end example")
162 (begin-center .
"@quotation\n")
163 (end-center .
"\n@end quotation")
164 (begin-quote .
"@quotation\n")
165 (end-quote .
"\n@end quotation")
166 (begin-uli .
"@itemize @bullet\n@item\n")
167 (end-uli .
"\n@end itemize")
168 (begin-oli .
"@enumerate\n@item\n")
169 (end-oli .
"\n@end enumerate")
170 (begin-ddt .
"@table @strong\n@item ")
172 (end-ddt .
"\n@end table"))
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 (defun muse-texinfo-insert-anchor (anchor)
188 "Insert an anchor, either before the next word, or within a tag."
189 (unless (get-text-property (match-end 1) 'noemphasis
)
190 (skip-chars-forward muse-regexp-space
)
191 (when (looking-at "<\\([^ />]+\\)>")
192 (goto-char (match-end 0)))
193 (insert "@anchor{" anchor
"}")))
195 (defun muse-texinfo-markup-anchor ()
197 (muse-texinfo-insert-anchor (match-string 2)))
200 (defun muse-texinfo-markup-table ()
203 (delete-region (match-beginning 0) (match-end 0))))
204 (fields (split-string str
"\\s-*|+\\s-*")))
205 (insert "@multitable @columnfractions")
206 (dotimes (field (length fields
))
207 (insert " " (number-to-string (/ 1.0 (length fields
)))))
208 (insert "\n@item " (mapconcat 'identity fields
" @tab "))
209 (insert "\n@end multitable")))
211 (defun muse-texinfo-finalize-buffer ()
212 (goto-char (point-min))
213 (muse-latex-fixup-dquotes)
214 (texinfo-insert-node-lines (point-min) (point-max) t
)
215 (texinfo-all-menus-update t
))
217 (defun muse-texinfo-pdf-browse-file (file)
218 (shell-command (concat "open " file
)))
220 (defun muse-texinfo-info-generate (file output-path final-target
)
221 ;; The version of `texinfmt.el' that comes with Emacs 21 doesn't
222 ;; support @documentencoding, so hack it in.
223 (when (and (not (featurep 'xemacs
))
224 (eq emacs-major-version
21))
225 (put 'documentencoding
'texinfo-format
226 'texinfo-discard-line-with-args
))
227 (muse-publish-transform-output
228 file output-path final-target
"Info"
230 (lambda (file output-path
)
231 (if muse-texinfo-process-natively
232 (save-window-excursion
235 (let ((inhibit-read-only t
))
236 (texinfo-format-buffer))
238 (kill-buffer (current-buffer))
239 (let ((buf (get-file-buffer file
)))
240 (with-current-buffer buf
241 (set-buffer-modified-p nil
)
242 (kill-buffer (current-buffer))))
245 (concat "makeinfo --enable-encoding --output="
246 output-path
" " file
))))))))
248 (defun muse-texinfo-pdf-generate (file output-path final-target
)
249 (muse-publish-transform-output
250 file output-path final-target
"PDF"
252 (lambda (file output-path
)
253 (= 0 (shell-command (concat "texi2pdf -q --clean --output="
254 output-path
" " file
)))))))
256 (unless (assoc "texi" muse-publishing-styles
)
257 (muse-define-style "texi"
258 :suffix
'muse-texinfo-extension
259 :regexps
'muse-texinfo-markup-regexps
260 :functions
'muse-texinfo-markup-functions
261 :strings
'muse-texinfo-markup-strings
262 :specials
'muse-texinfo-markup-specials
263 :after
'muse-texinfo-finalize-buffer
264 :header
'muse-texinfo-header
265 :footer
'muse-texinfo-footer
268 (muse-derive-style "info" "texi"
269 :final
'muse-texinfo-info-generate
270 :osuffix
'muse-texinfo-info-extension
273 (muse-derive-style "info-pdf" "texi"
274 :final
'muse-texinfo-pdf-generate
275 :osuffix
'muse-texinfo-pdf-extension
276 :browser
'muse-texinfo-pdf-browse-file
))
278 (provide 'muse-texinfo
)
280 ;;; muse-texinfo.el ends here