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 (enddots .
"@enddots{}")
139 (section .
"@chapter ")
140 (subsection .
"@section ")
141 (subsubsection .
"@subsection ")
142 (section-other .
"@subsubheading ")
143 (footnote .
"@footnote{")
145 (begin-underline .
"_")
146 (end-underline .
"_")
147 (begin-literal .
"@samp{")
149 (begin-emph .
"@emph{")
151 (begin-more-emph .
"@strong{")
152 (end-more-emph .
"}")
153 (begin-most-emph .
"@strong{@emph{")
154 (end-most-emph .
"}}")
155 (begin-verse .
"@display\n")
156 (end-verse-line .
"")
157 (verse-space .
"@ @ ")
158 (end-verse .
"\n@end display")
159 (begin-example .
"@example")
160 (end-example .
"@end example")
161 (begin-center .
"@quotation\n")
162 (end-center .
"\n@end quotation")
163 (begin-quote .
"@quotation\n")
164 (end-quote .
"\n@end quotation")
165 (begin-uli .
"@itemize @bullet\n@item\n")
166 (end-uli .
"\n@end itemize")
167 (begin-oli .
"@enumerate\n@item\n")
168 (end-oli .
"\n@end enumerate")
169 (begin-ddt .
"@table @strong\n@item ")
171 (end-ddt .
"\n@end table"))
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 (defun muse-texinfo-insert-anchor (anchor)
187 "Insert an anchor, either before the next word, or within a tag."
188 (skip-chars-forward muse-regexp-space
)
189 (when (looking-at "<\\([^ />]+\\)>")
190 (goto-char (match-end 0)))
191 (insert "@anchor{" anchor
"}"))
193 (defun muse-texinfo-markup-anchor ()
195 (muse-texinfo-insert-anchor (match-string 2)))
198 (defun muse-texinfo-markup-table ()
201 (delete-region (match-beginning 0) (match-end 0))))
202 (fields (split-string str
"\\s-*|+\\s-*")))
203 (insert "@multitable @columnfractions")
204 (dotimes (field (length fields
))
205 (insert " " (number-to-string (/ 1.0 (length fields
)))))
206 (insert "\n@item " (mapconcat 'identity fields
" @tab "))
207 (insert "\n@end multitable")))
209 (defun muse-texinfo-finalize-buffer ()
210 (goto-char (point-min))
211 (muse-latex-fixup-dquotes)
212 (texinfo-insert-node-lines (point-min) (point-max) t
)
213 (texinfo-all-menus-update t
))
215 (defun muse-texinfo-pdf-browse-file (file)
216 (shell-command (concat "open " file
)))
218 (defun muse-texinfo-info-generate (file output-path final-target
)
219 ;; The version of `texinfmt.el' that comes with Emacs 21 doesn't
220 ;; support @documentencoding, so hack it in.
221 (when (and (not (featurep 'xemacs
))
222 (eq emacs-major-version
21))
223 (put 'documentencoding
'texinfo-format
224 'texinfo-discard-line-with-args
))
225 (muse-publish-transform-output
226 file output-path final-target
"Info"
228 (lambda (file output-path
)
229 (if muse-texinfo-process-natively
230 (save-window-excursion
233 (let ((inhibit-read-only t
))
234 (texinfo-format-buffer))
236 (kill-buffer (current-buffer))
237 (let ((buf (get-file-buffer file
)))
238 (with-current-buffer buf
239 (set-buffer-modified-p nil
)
240 (kill-buffer (current-buffer))))
243 (concat "makeinfo --enable-encoding --output="
244 output-path
" " file
))))))))
246 (defun muse-texinfo-pdf-generate (file output-path final-target
)
247 (muse-publish-transform-output
248 file output-path final-target
"PDF"
250 (lambda (file output-path
)
251 (= 0 (shell-command (concat "texi2pdf -q --clean --output="
252 output-path
" " file
)))))))
254 (unless (assoc "texi" muse-publishing-styles
)
255 (muse-define-style "texi"
256 :suffix
'muse-texinfo-extension
257 :regexps
'muse-texinfo-markup-regexps
258 :functions
'muse-texinfo-markup-functions
259 :strings
'muse-texinfo-markup-strings
260 :specials
'muse-texinfo-markup-specials
261 :after
'muse-texinfo-finalize-buffer
262 :header
'muse-texinfo-header
263 :footer
'muse-texinfo-footer
266 (muse-derive-style "info" "texi"
267 :final
'muse-texinfo-info-generate
268 :osuffix
'muse-texinfo-info-extension
271 (muse-derive-style "info-pdf" "texi"
272 :final
'muse-texinfo-pdf-generate
273 :osuffix
'muse-texinfo-pdf-extension
274 :browser
'muse-texinfo-pdf-browse-file
))
276 (provide 'muse-texinfo
)
278 ;;; muse-texinfo.el ends here