Add markup for comments, via parts of patch-261.
[muse-el.git] / lisp / muse-texinfo.el
blob52a0b5673b650ef5e86540f59285f573eb3e2ce8
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 (comment-begin . "@ignore\n")
135 (comment-end . "\n@end ignore\n")
136 (rule . "@sp 1")
137 (enddots . "@enddots")
138 (dots . "@dots")
139 (section . "@chapter ")
140 (subsection . "@section ")
141 (subsubsection . "@subsection ")
142 (section-other . "@subsubheading ")
143 (footnote . "@footnote{")
144 (footnote-end . "}")
145 (begin-underline . "_")
146 (end-underline . "_")
147 (begin-literal . "@samp{")
148 (end-literal . "}")
149 (begin-emph . "@emph{")
150 (end-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 . "@center\n")
162 (end-center . "\n@end center")
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 ")
170 (start-dde . "\n")
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
179 '((?@ . "@@")
180 (?{ . "@{")
181 (?} . "@}"))
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 ()
194 (save-match-data
195 (muse-texinfo-insert-anchor (match-string 2)))
196 (match-string 1))
198 (defun muse-texinfo-markup-table ()
199 (let* ((str (prog1
200 (match-string 1)
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"
227 (function
228 (lambda (file output-path)
229 (if muse-texinfo-process-natively
230 (save-window-excursion
231 (save-excursion
232 (find-file file)
233 (let ((inhibit-read-only t))
234 (texinfo-format-buffer))
235 (save-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))))
242 (= 0 (shell-command
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"
249 (function
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
264 :browser 'find-file)
266 (muse-derive-style "info" "texi"
267 :final 'muse-texinfo-info-generate
268 :osuffix 'muse-texinfo-info-extension
269 :browser 'info)
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