Introduce :link-suffix. muse-wiki: Don't mangle acronyms in titles.
[muse-el.git] / lisp / muse-texinfo.el
blob8325ec39d1d1bbea5b0c06de56d2ec1866669a6d
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
103 "@end \\(\\(multi\\)?table\\|itemize\\|enumerate\\)\n+@\\1.*\n+" 0 ""))
104 "List of markup rules for publishing a Muse page to Texinfo.
105 For more on the structure of this list, see `muse-publish-markup-regexps'."
106 :type '(repeat (choice
107 (list :tag "Markup rule"
108 integer
109 (choice regexp symbol)
110 integer
111 (choice string function symbol))
112 function))
113 :group 'muse-texinfo)
115 (defcustom muse-texinfo-markup-functions
116 '((anchor . muse-texinfo-markup-anchor)
117 (table . muse-texinfo-markup-table))
118 "An alist of style types to custom functions for that kind of text.
119 For more on the structure of this list, see
120 `muse-publish-markup-functions'."
121 :type '(alist :key-type symbol :value-type function)
122 :group 'muse-texinfo)
124 (defcustom muse-texinfo-markup-strings
125 '((image-with-desc . "@image{%s}")
126 (image-link . "@image{%s}")
127 (url-with-image . "@uref{%s, %s}")
128 (url-link . "@uref{%s, %s}")
129 (internal-link . "@ref{%s, %s}")
130 (email-addr . "@email{%s}")
131 (emdash . "---")
132 (rule . "@sp 1")
133 (enddots . "@enddots")
134 (dots . "@dots")
135 (section . "@chapter ")
136 (subsection . "@section ")
137 (subsubsection . "@subsection ")
138 (section-other . "@subsubheading ")
139 (footnote . "@footnote{")
140 (footnote-end . "}")
141 (begin-underline . "_")
142 (end-underline . "_")
143 (begin-literal . "@samp{")
144 (end-literal . "}")
145 (begin-emph . "@emph{")
146 (end-emph . "}")
147 (begin-more-emph . "@strong{")
148 (end-more-emph . "}")
149 (begin-most-emph . "@strong{@emph{")
150 (end-most-emph . "}}")
151 (begin-verse . "@display\n")
152 (end-verse-line . "")
153 (verse-space . "@ @ ")
154 (end-verse . "\n@end display")
155 (begin-example . "@example")
156 (end-example . "@end example")
157 (begin-center . "@center\n")
158 (end-center . "\n@end center")
159 (begin-quote . "@quotation\n")
160 (end-quote . "\n@end quotation")
161 (begin-uli . "@itemize @bullet\n@item\n")
162 (end-uli . "\n@end itemize")
163 (begin-oli . "@enumerate\n@item\n")
164 (end-oli . "\n@end enumerate")
165 (begin-ddt . "@table @strong\n@item ")
166 (start-dde . "\n")
167 (end-ddt . "\n@end table"))
168 "Strings used for marking up text.
169 These cover the most basic kinds of markup, the handling of which
170 differs little between the various styles."
171 :type '(alist :key-type symbol :value-type string)
172 :group 'muse-texinfo)
174 (defcustom muse-texinfo-markup-specials
175 '((?@ . "@@")
176 (?{ . "@{")
177 (?} . "@}"))
178 "A table of characters which must be represented specially."
179 :type '(alist :key-type character :value-type string)
180 :group 'muse-texinfo)
182 (defun muse-texinfo-insert-anchor (anchor)
183 "Insert an anchor, either before the next word, or within a tag."
184 (skip-chars-forward muse-regexp-space)
185 (when (looking-at "<\\([^ />]+\\)>")
186 (goto-char (match-end 0)))
187 (insert "@anchor{" anchor "}"))
189 (defun muse-texinfo-markup-anchor ()
190 (save-match-data
191 (muse-texinfo-insert-anchor (match-string 1)))
194 (defun muse-texinfo-markup-table ()
195 (let* ((str (prog1
196 (match-string 1)
197 (delete-region (match-beginning 0) (match-end 0))))
198 (fields (split-string str "\\s-*|+\\s-*")))
199 (insert "@multitable @columnfractions")
200 (dotimes (field (length fields))
201 (insert " " (number-to-string (/ 1.0 (length fields)))))
202 (insert "\n@item " (mapconcat 'identity fields " @tab "))
203 (insert "\n@end multitable")))
205 (defun muse-texinfo-finalize-buffer ()
206 (goto-char (point-min))
207 (muse-latex-fixup-dquotes)
208 (texinfo-insert-node-lines (point-min) (point-max) t)
209 (texinfo-all-menus-update t))
211 (defun muse-texinfo-pdf-browse-file (file)
212 (shell-command (concat "open " file)))
214 (defun muse-texinfo-info-generate (file output-path final-target)
215 ;; The version of `texinfmt.el' that comes with Emacs 21 doesn't
216 ;; support @documentencoding, so hack it in.
217 (when (and (not (featurep 'xemacs))
218 (eq emacs-major-version 21))
219 (put 'documentencoding 'texinfo-format
220 'texinfo-discard-line-with-args))
221 (muse-publish-transform-output
222 file output-path final-target "Info"
223 (function
224 (lambda (file output-path)
225 (if muse-texinfo-process-natively
226 (save-window-excursion
227 (save-excursion
228 (find-file file)
229 (let ((inhibit-read-only t))
230 (texinfo-format-buffer))
231 (save-buffer)
232 (kill-buffer (current-buffer))
233 (let ((buf (get-file-buffer file)))
234 (with-current-buffer buf
235 (set-buffer-modified-p nil)
236 (kill-buffer (current-buffer))))
238 (= 0 (shell-command
239 (concat "makeinfo --enable-encoding --output="
240 output-path " " file))))))))
242 (defun muse-texinfo-pdf-generate (file output-path final-target)
243 (muse-publish-transform-output
244 file output-path final-target "PDF"
245 (function
246 (lambda (file output-path)
247 (= 0 (shell-command (concat "texi2pdf -q --clean --output="
248 output-path " " file)))))))
250 (unless (assoc "texi" muse-publishing-styles)
251 (muse-define-style "texi"
252 :suffix 'muse-texinfo-extension
253 :regexps 'muse-texinfo-markup-regexps
254 :functions 'muse-texinfo-markup-functions
255 :strings 'muse-texinfo-markup-strings
256 :specials 'muse-texinfo-markup-specials
257 :after 'muse-texinfo-finalize-buffer
258 :header 'muse-texinfo-header
259 :footer 'muse-texinfo-footer
260 :browser 'find-file)
262 (muse-derive-style "info" "texi"
263 :final 'muse-texinfo-info-generate
264 :osuffix 'muse-texinfo-info-extension
265 :browser 'info)
267 (muse-derive-style "info-pdf" "texi"
268 :final 'muse-texinfo-pdf-generate
269 :osuffix 'muse-texinfo-pdf-extension
270 :browser 'muse-texinfo-pdf-browse-file))
272 (provide 'muse-texinfo)
274 ;;; muse-texinfo.el ends here