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., 59 Temple Place - Suite 330, Boston,
20 ;; MA 02111-1307, 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 Texinfo files."
58 (defcustom muse-texinfo-pdf-extension
".pdf"
59 "Default file extension for publishing Texinfo 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 @node Top, Overview, , (dir)
82 @c Page published by Emacs Muse begins here\n\n"
83 "Text to prepend to a Muse page being published as Texinfo.
84 This text may contain <lisp> markup tags."
88 (defcustom muse-texinfo-footer
89 "\n@c Page published by Emacs Muse ends here
90 <lisp>(and muse-publish-generate-contents \"@contents\")</lisp>
92 "Text to append to a Muse page being published as Texinfo.
93 This text may contain <lisp> markup tags."
97 (defcustom muse-texinfo-markup-regexps
98 '(;; join together the parts of a list or table
100 "@end \\(\\(multi\\)?table\\|itemize\\|enumerate\\)\n+@\\1.*\n+" 0 ""))
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 (url-link .
"@uref{%s, %s}")
125 (email-addr .
"@email{%s}")
130 (section .
"@chapter ")
131 (subsection .
"@section ")
132 (subsubsection .
"@subsection ")
133 (footnote .
"@footnote{")
135 (begin-underline .
"")
137 (begin-literal .
"@samp{")
139 (begin-emph .
"@emph{")
141 (begin-more-emph .
"@strong{")
142 (end-more-emph .
"}")
143 (begin-most-emph .
"@strong{@emph{")
144 (end-most-emph .
"}}")
145 (begin-verse .
"@display\n")
146 (end-verse-line .
"")
147 (verse-space .
"@ @ ")
148 (end-verse .
"\n@end display")
149 (begin-example .
"@example")
150 (end-example .
"@end example")
151 (begin-center .
"@center\n")
152 (end-center .
"\n@end center")
153 (begin-quote .
"@quotation\n")
154 (end-quote .
"\n@end quotation")
155 (begin-uli .
"@itemize @bullet\n@item\n")
156 (end-uli .
"\n@end itemize")
157 (begin-oli .
"@enumerate\n@item\n")
158 (end-oli .
"\n@end enumerate")
159 (begin-ddt .
"@table @strong\n@item ")
161 (end-ddt .
"\n@end table"))
162 "Strings used for marking up text.
163 These cover the most basic kinds of markup, the handling of which
164 differs little between the various styles."
165 :type
'(alist :key-type symbol
:value-type string
)
166 :group
'muse-texinfo
)
168 (defcustom muse-texinfo-markup-specials
170 "A table of characters which must be represented specially."
171 :type
'(alist :key-type character
:value-type string
)
172 :group
'muse-texinfo
)
174 (defun muse-texinfo-markup-table ()
177 (delete-region (match-beginning 0) (match-end 0))))
178 (fields (split-string str
"\\s-*|+\\s-*")) field
)
179 (insert "@multitable @columnfractions ")
180 (dotimes (field (length fields
))
181 (insert (number-to-string (/ 1.0 (length fields
))) " "))
182 (insert "\n@item " (mapconcat 'identity fields
" @tab "))
183 (insert "\n@end multitable")))
185 (defun muse-texinfo-finalize-buffer ()
186 (goto-char (point-min))
187 (muse-latex-fixup-dquotes)
188 (texinfo-insert-node-lines (point-min) (point-max) t
)
189 (texinfo-all-menus-update t
))
191 (defun muse-texinfo-pdf-browse-file (file)
192 (shell-command (concat "open " file
)))
194 (defun muse-texinfo-info-generate (file output-path final-target
)
195 (muse-publish-transform-output
196 file output-path final-target
"Info"
198 (lambda (file output-path
)
199 (if muse-texinfo-process-natively
200 (save-window-excursion
203 (let ((inhibit-read-only t
))
204 (texinfo-format-buffer))
206 (kill-buffer (current-buffer))
207 (let ((buf (get-file-buffer file
)))
208 (with-current-buffer buf
209 (set-buffer-modified-p nil
)
210 (kill-buffer (current-buffer))))
213 (concat "makeinfo --enable-encoding --output="
214 output-path
" " file
))))))))
216 (defun muse-texinfo-pdf-generate (file output-path final-target
)
217 (muse-publish-transform-output
218 file output-path final-target
"PDF"
220 (lambda (file output-path
)
221 (= 0 (shell-command (concat "texi2pdf -q --clean --output="
222 output-path
" " file
)))))))
224 (unless (assoc "texi" muse-publishing-styles
)
225 (muse-define-style "texi"
226 :suffix
'muse-texinfo-extension
227 :regexps
'muse-texinfo-markup-regexps
228 :functions
'muse-texinfo-markup-functions
229 :strings
'muse-texinfo-markup-strings
230 :specials
'muse-texinfo-markup-specials
231 :after
'muse-texinfo-finalize-buffer
232 :header
'muse-texinfo-header
233 :footer
'muse-texinfo-footer
236 (muse-derive-style "info" "texi"
237 :final
'muse-texinfo-info-generate
238 :osuffix
'muse-texinfo-info-extension
241 (muse-derive-style "info-pdf" "texi"
242 :final
'muse-texinfo-pdf-generate
243 :osuffix
'muse-texinfo-pdf-extension
244 :browser
'muse-texinfo-pdf-browse-file
))
246 (provide 'muse-texinfo
)
248 ;;; muse-texinfo.el ends here