If more than 1 blank separates list/table items, separate them.
[muse-el.git] / lisp / muse-texinfo.el
blobc8a7c2cd45424f9c78b6b308e75d537674f8bbd8
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
10 ;; version.
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
15 ;; for more details.
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.
22 ;;; Commentary:
24 ;;; Contributors:
26 ;;; Code:
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;; Muse Texinfo Publishing
32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34 (require 'muse-publish)
35 (require 'muse-latex)
36 (require 'texnfo-upd)
38 (defgroup muse-texinfo nil
39 "Rules for marking up a Muse file as a Texinfo article."
40 :group 'muse-publish)
42 (defcustom muse-texinfo-process-natively t
43 "If non-nil, use the Emacs `texinfmt' module to make Info files."
44 :type 'boolean
45 :require 'texinfmt
46 :group 'muse-texinfo)
48 (defcustom muse-texinfo-extension ".texi"
49 "Default file extension for publishing Texinfo files."
50 :type 'string
51 :group 'muse-texinfo)
53 (defcustom muse-texinfo-info-extension ".info"
54 "Default file extension for publishing Info files."
55 :type 'string
56 :group 'muse-texinfo)
58 (defcustom muse-texinfo-pdf-extension ".pdf"
59 "Default file extension for publishing PDF files."
60 :type 'string
61 :group 'muse-texinfo)
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
71 @iftex
72 @finalout
73 @end iftex
75 @titlepage
76 @title <lisp>(muse-publishing-directive \"title\")</lisp>
77 @author <lisp>(muse-publishing-directive \"author\")</lisp>
78 @end titlepage
80 <lisp>(and muse-publish-generate-contents \"@contents\")</lisp>
82 @node Top, Overview, , (dir)
83 @top Overview
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."
88 :type 'string
89 :group 'muse-texinfo)
91 (defcustom muse-texinfo-footer
92 "\n@c Page published by Emacs Muse ends here
93 @bye\n"
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."
97 :type 'string
98 :group 'muse-texinfo)
100 (defcustom muse-texinfo-markup-regexps
101 `(;; join together the parts of a list or table
102 (10000 ,(concat "@end \\(\\(multi\\)?table\\|itemize\\|enumerate\\)"
103 "\n\\{1,2\\}"
104 "@\\1.*\n+")
105 0 ""))
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"
110 integer
111 (choice regexp symbol)
112 integer
113 (choice string function symbol))
114 function))
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}")
133 (emdash . "---")
134 (rule . "@sp 1")
135 (enddots . "@enddots")
136 (dots . "@dots")
137 (section . "@chapter ")
138 (subsection . "@section ")
139 (subsubsection . "@subsection ")
140 (section-other . "@subsubheading ")
141 (footnote . "@footnote{")
142 (footnote-end . "}")
143 (begin-underline . "_")
144 (end-underline . "_")
145 (begin-literal . "@samp{")
146 (end-literal . "}")
147 (begin-emph . "@emph{")
148 (end-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 . "@center\n")
160 (end-center . "\n@end center")
161 (begin-quote . "@quotation\n")
162 (end-quote . "\n@end quotation")
163 (begin-uli . "@itemize @bullet\n@item\n")
164 (end-uli . "\n@end itemize")
165 (begin-oli . "@enumerate\n@item\n")
166 (end-oli . "\n@end enumerate")
167 (begin-ddt . "@table @strong\n@item ")
168 (start-dde . "\n")
169 (end-ddt . "\n@end table"))
170 "Strings used for marking up text.
171 These cover the most basic kinds of markup, the handling of which
172 differs little between the various styles."
173 :type '(alist :key-type symbol :value-type string)
174 :group 'muse-texinfo)
176 (defcustom muse-texinfo-markup-specials
177 '((?@ . "@@")
178 (?{ . "@{")
179 (?} . "@}"))
180 "A table of characters which must be represented specially."
181 :type '(alist :key-type character :value-type string)
182 :group 'muse-texinfo)
184 (defun muse-texinfo-insert-anchor (anchor)
185 "Insert an anchor, either before the next word, or within a tag."
186 (skip-chars-forward muse-regexp-space)
187 (when (looking-at "<\\([^ />]+\\)>")
188 (goto-char (match-end 0)))
189 (insert "@anchor{" anchor "}"))
191 (defun muse-texinfo-markup-anchor ()
192 (save-match-data
193 (muse-texinfo-insert-anchor (match-string 1)))
196 (defun muse-texinfo-markup-table ()
197 (let* ((str (prog1
198 (match-string 1)
199 (delete-region (match-beginning 0) (match-end 0))))
200 (fields (split-string str "\\s-*|+\\s-*")))
201 (insert "@multitable @columnfractions")
202 (dotimes (field (length fields))
203 (insert " " (number-to-string (/ 1.0 (length fields)))))
204 (insert "\n@item " (mapconcat 'identity fields " @tab "))
205 (insert "\n@end multitable")))
207 (defun muse-texinfo-finalize-buffer ()
208 (goto-char (point-min))
209 (muse-latex-fixup-dquotes)
210 (texinfo-insert-node-lines (point-min) (point-max) t)
211 (texinfo-all-menus-update t))
213 (defun muse-texinfo-pdf-browse-file (file)
214 (shell-command (concat "open " file)))
216 (defun muse-texinfo-info-generate (file output-path final-target)
217 ;; The version of `texinfmt.el' that comes with Emacs 21 doesn't
218 ;; support @documentencoding, so hack it in.
219 (when (and (not (featurep 'xemacs))
220 (eq emacs-major-version 21))
221 (put 'documentencoding 'texinfo-format
222 'texinfo-discard-line-with-args))
223 (muse-publish-transform-output
224 file output-path final-target "Info"
225 (function
226 (lambda (file output-path)
227 (if muse-texinfo-process-natively
228 (save-window-excursion
229 (save-excursion
230 (find-file file)
231 (let ((inhibit-read-only t))
232 (texinfo-format-buffer))
233 (save-buffer)
234 (kill-buffer (current-buffer))
235 (let ((buf (get-file-buffer file)))
236 (with-current-buffer buf
237 (set-buffer-modified-p nil)
238 (kill-buffer (current-buffer))))
240 (= 0 (shell-command
241 (concat "makeinfo --enable-encoding --output="
242 output-path " " file))))))))
244 (defun muse-texinfo-pdf-generate (file output-path final-target)
245 (muse-publish-transform-output
246 file output-path final-target "PDF"
247 (function
248 (lambda (file output-path)
249 (= 0 (shell-command (concat "texi2pdf -q --clean --output="
250 output-path " " file)))))))
252 (unless (assoc "texi" muse-publishing-styles)
253 (muse-define-style "texi"
254 :suffix 'muse-texinfo-extension
255 :regexps 'muse-texinfo-markup-regexps
256 :functions 'muse-texinfo-markup-functions
257 :strings 'muse-texinfo-markup-strings
258 :specials 'muse-texinfo-markup-specials
259 :after 'muse-texinfo-finalize-buffer
260 :header 'muse-texinfo-header
261 :footer 'muse-texinfo-footer
262 :browser 'find-file)
264 (muse-derive-style "info" "texi"
265 :final 'muse-texinfo-info-generate
266 :osuffix 'muse-texinfo-info-extension
267 :browser 'info)
269 (muse-derive-style "info-pdf" "texi"
270 :final 'muse-texinfo-pdf-generate
271 :osuffix 'muse-texinfo-pdf-extension
272 :browser 'muse-texinfo-pdf-browse-file))
274 (provide 'muse-texinfo)
276 ;;; muse-texinfo.el ends here