1 ;;; ptexinfmt.el -- portable Texinfo formatter.
3 ;; Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993,
4 ;; 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
5 ;; Copyright (C) 1999 Yoshiki Hayashi <yoshiki@xemacs.org>
6 ;; Copyright (C) 2000, 2001, 2002 TAKAHASHI Kaoru <kaoru@kaisei.org>
8 ;; Author: TAKAHASHI Kaoru <kaoru@kaisei.org>
9 ;; Yoshiki Hayashi <yoshiki@xemacs.org>
10 ;; Katsumi Yamaoka <yamaoka@jpl.org>
11 ;; Maintainer: TAKAHASHI Kaoru <kaoru@kaisei.org>
12 ;; Created: 7 Jul 2000
13 ;; Keywords: maint, tex, docs, emulation, compatibility
15 ;; This program is free software; you can redistribute it and/or
16 ;; modify it under the terms of the GNU General Public License as
17 ;; published by the Free Software Foundation; either version 2, or (at
18 ;; your option) any later version.
20 ;; This program is distributed in the hope that it will be useful, but
21 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 ;; General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 ;; Boston, MA 02110-1301, USA.
32 ;; Original code: Yoshiki Hayashi <yoshiki@xemacs.org>
33 ;; makeinfo.el (gnujdoc project)
35 ;; Support texinfmt.el 2.32 or later.
37 ;; Modified by Yamaoka not to use APEL functions.
39 ;; Unimplemented command:
40 ;; @abbr{ABBREVIATION}
41 ;; @float ... @end float, @caption{TEXT}, @shortcaption{TEXT}, @listoffloats
45 ;; @quotation (optional arguments)
46 ;; @acronym{ACRONYM[, MEANING]} (optional argument)
47 ;; @dofirstparagraphindent
49 ;; @verbatiminclude FILENAME
51 ;; @definfoenclose phoo,//,\\
52 ;; @deftypeivar CLASS DATA-TYPE VARIABLE-NAME
53 ;; @deftypeop CATEGORY CLASS DATA-TYPE NAME ARGUMENTS...
54 ;; @allowcodebreaks false
56 ;; @quotedblleft @quotedblright
57 ;; @quoteleft @quoteright @quotedblbase @quotesinglbase
58 ;; @guillemetleft @guillemetright @guilsinglleft @guilsinglright.
59 ;; @clicksequence, @click, @clickstyle, @arrow
66 (defvar ptexinfmt-disable-broken-notice-flag t
67 "If non-nil disable notice, when call `ptexinfmt-broken-facility'.
68 This is last argument in `ptexinfmt-broken-facility'.")
70 (put 'ptexinfmt-broken-facility 'lisp-indent-function 'defun)
71 (defmacro ptexinfmt-broken-facility (facility docstring assertion
73 "Declare a symbol FACILITY is broken if ASSERTION is nil.
74 DOCSTRING will be printed if ASSERTION is nil and
75 `ptexinfmt-disable-broken-notice-flag' is nil."
76 `(let ((facility ',facility)
77 (docstring ,docstring)
78 (assertion (eval ',assertion)))
79 (put facility 'broken (not assertion))
82 (put facility 'broken-docstring docstring)
83 (if ptexinfmt-disable-broken-notice-flag
85 (message "BROKEN FACILITY DETECTED: %s" docstring)))))
87 (put 'ptexinfmt-defun-if-broken 'lisp-indent-function 'defun)
88 (defmacro ptexinfmt-defun-if-broken (&rest args)
89 "Redefine a function just like `defun' if it is considered broken."
90 (let ((name (list 'quote (car args))))
91 (setq args (cdr args))
94 (if (get ,name 'broken)
96 (function (lambda ,@args)))))))
98 (put 'ptexinfmt-defun-if-void 'lisp-indent-function 'defun)
99 (defmacro ptexinfmt-defun-if-void (&rest args)
100 "Define a function just like `defun' unless it is already defined."
101 (let ((name (list 'quote (car args))))
102 (setq args (cdr args))
108 (function (lambda ,@args)))))))
110 (put 'ptexinfmt-defvar-if-void 'lisp-indent-function 'defun)
111 (defmacro ptexinfmt-defvar-if-void (&rest args)
112 "Define a variable just like `defvar' unless it is already defined."
113 (let ((name (car args)))
114 (setq args (cdr args))
119 (defvar ,name ,@args)))))
122 (ptexinfmt-broken-facility texinfo-format-printindex
123 "Can't sort on Mule for Windows."
126 ;; @var{METASYNTACTIC-VARIABLE}
127 (ptexinfmt-broken-facility texinfo-format-var
128 "Don't perse @var argument."
131 (let (texinfo-enclosure-list texinfo-alias-list)
133 (insert "@var{@asis{foo}}\n")
134 (texinfo-format-expand-region (point-min) (point-max))
138 ;; @xref{NODE-NAME[, CROSS-REFERENCE-NAME, TITLE-OR-TOPIC,
139 ;; INFO-FILE-NAME, PRINTED-MANUAL-TITLE]}.
140 (ptexinfmt-broken-facility texinfo-format-xref
141 "Can't format @xref, 1st argument is empty."
144 (let (texinfo-enclosure-list texinfo-alias-list)
146 (insert "@xref{, xref, , file}\n")
147 (texinfo-format-expand-region (point-min) (point-max))
151 ;; @uref{URL[, TEXT][, REPLACEMENT]}
152 (ptexinfmt-broken-facility texinfo-format-uref
153 "Parse twice @uref argument."
156 (let (texinfo-enclosure-list texinfo-alias-list)
158 (insert "@uref{mailto:foo@@noncommand.example.com}\n")
159 (texinfo-format-expand-region (point-min) (point-max))
164 (ptexinfmt-broken-facility texinfo-multitable-widths
165 "`texinfo-multitable-widths' unsupport wide-char."
166 (if (fboundp 'texinfo-multitable-widths)
168 (let ((str (string (make-char 'japanese-jisx0208 73 125)
169 (make-char 'japanese-jisx0208 57 45)
170 (make-char 'japanese-jisx0208 74 56)
171 (make-char 'japanese-jisx0208 59 122))))
173 (insert (format " {%s}\n" str))
174 (goto-char (point-min))
175 (if (= (car (texinfo-multitable-widths)) (length str))
178 ;; function definition is void
181 (ptexinfmt-broken-facility texinfo-multitable-item
182 "`texinfo-multitable-item' unsupport wide-char."
183 (not (get 'texinfo-multitable-widths 'broken)))
186 ;;; Hardcopy and HTML (discard)
188 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
189 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
190 (put 'documentdescription 'texinfo-format 'texinfo-discard-line-with-args)
193 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
194 (put 'letterpaper 'texinfo-format 'texinfo-discard-line)
195 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
196 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
197 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
198 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
199 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
200 (put 'fonttextsize 'texinfo-format 'texinfo-discard-line-with-args)
203 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
204 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
207 (put 'setcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
208 (put 'setshortcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
209 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
210 (put 'frenchspacing 'texinfo-format 'texinfo-discard-line-with-args)
213 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
214 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
215 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
216 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
217 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
218 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
219 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
222 (put 'page 'texinfo-format 'texinfo-discard-line)
223 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
225 ;; @slanted{TEXT} (makeinfo 4.8 or later)
226 (put 'slanted 'texinfo-format 'texinfo-format-noop)
228 ;; @sansserif{TEXT} (makeinfo 4.8 or later)
229 (put 'sansserif 'texinfo-format 'texinfo-format-noop)
231 ;; @tie{} (makeinfo 4.3 or later)
232 (put 'tie 'texinfo-format 'texinfo-format-tie)
233 (ptexinfmt-defun-if-void texinfo-format-tie ()
234 (texinfo-parse-arg-discard)
239 ;; @direcategory DIRPART
240 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
241 (ptexinfmt-defun-if-void texinfo-format-dircategory ()
242 (let ((str (texinfo-parse-arg-discard)))
243 (delete-region (point)
245 (skip-chars-forward " ")
247 (insert "INFO-DIR-SECTION " str "\n")))
249 ;; @direntry ... @end direntry
250 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
251 (ptexinfmt-defun-if-void texinfo-format-direntry ()
252 (texinfo-push-stack 'direntry nil)
253 (texinfo-discard-line)
254 (insert "START-INFO-DIR-ENTRY\n"))
256 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
257 (ptexinfmt-defun-if-void texinfo-end-direntry ()
258 (texinfo-discard-command)
259 (insert "END-INFO-DIR-ENTRY\n\n")
260 (texinfo-pop-stack 'direntry))
264 ;; @detailmenu ... @end detailmenu
265 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
266 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
268 ;; @smalldisplay ... @end smalldisplay
269 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
270 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
272 ;; @smallformat ... @end smallformat
273 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
274 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
276 ;; @cartouche ... @end cartouche
277 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
278 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
282 ;; @ifnottex ... @end ifnottex (makeinfo 3.11 or later)
283 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
284 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
286 ;; @ifnothtml ... @end ifnothtml (makeinfo 3.11 or later)
287 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
288 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
290 ;; @ifnotplaintext ... @end ifnotplaintext (makeinfo 4.2 or later)
291 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
292 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
294 ;; @ifnotdocbook ... @end ifnotdocbook (makeinfo 4.7 or later)
295 (put 'ifnotdocbook 'texinfo-format 'texinfo-discard-line)
296 (put 'ifnotdocbook 'texinfo-end 'texinfo-discard-command)
298 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
299 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
300 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
301 (delete-region texinfo-command-start
302 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
305 ;; @html ... @end html (makeinfo 3.11 or later)
306 (put 'html 'texinfo-format 'texinfo-format-html)
307 (ptexinfmt-defun-if-void texinfo-format-html ()
308 (delete-region texinfo-command-start
309 (progn (re-search-forward "@end html[ \t]*\n")
312 ;; @docbook ... @end docbook (makeinfo 4.7 or later)
313 (put 'docbook 'texinfo-format 'texinfo-format-docbook)
314 (ptexinfmt-defun-if-void texinfo-format-docbook ()
315 (delete-region texinfo-command-start
316 (progn (re-search-forward "@end docbook[ \t]*\n")
319 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
320 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
321 (defun texinfo-format-ifhtml ()
322 (delete-region texinfo-command-start
323 (progn (re-search-forward "@end ifhtml[ \t]*\n")
326 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
327 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
328 (ptexinfmt-defun-if-void texinfo-format-ifplaintext ()
329 (delete-region texinfo-command-start
330 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
333 ;; @ifdocbook ... @end ifdocbook (makeinfo 4.7 or later)
334 (put 'ifdocbook 'texinfo-format 'texinfo-format-ifdocbook)
335 (ptexinfmt-defun-if-void texinfo-format-ifdocbook ()
336 (delete-region texinfo-command-start
337 (progn (re-search-forward "@end ifdocbook[ \t]*\n")
342 ;; @env{ENVIRONMENT-VARIABLE}
343 (put 'env 'texinfo-format 'texinfo-format-code)
345 ;; @command{COMMAND-NAME}
346 (put 'command 'texinfo-format 'texinfo-format-code)
348 ;; @indicateurl{INDICATEURL}
349 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
351 ;; @url{URL[, DISPLAYED-TEXT][, REPLACEMENT}
352 (put 'url 'texinfo-format 'texinfo-format-uref) ; Texinfo 4.7
355 (put 'acronym 'texinfo-format 'texinfo-format-var)
357 ;; @var{METASYNTACTIC-VARIABLE}
358 (ptexinfmt-defun-if-broken texinfo-format-var ()
359 (let ((arg (texinfo-parse-expanded-arg)))
360 (texinfo-discard-command)
361 (insert (upcase arg))))
364 (put 'key 'texinfo-format 'texinfo-format-key)
365 (ptexinfmt-defun-if-void texinfo-format-key ()
366 (insert (texinfo-parse-arg-discard))
367 (goto-char texinfo-command-start))
369 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
370 (put 'email 'texinfo-format 'texinfo-format-email)
371 (ptexinfmt-defun-if-void texinfo-format-email ()
372 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
373 Insert < ... > around EMAIL-ADDRESS."
374 (let ((args (texinfo-format-parse-args)))
375 (texinfo-discard-command)
378 (insert (nth 1 args) " <" (nth 0 args) ">")
379 (insert "<" (nth 0 args) ">"))))
381 ;; @option{OPTION-NAME}
382 (put 'option 'texinfo-format 'texinfo-format-option)
383 (ptexinfmt-defun-if-void texinfo-format-option ()
384 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
385 ;; `looking-at-backward' not available in v. 18.57, 20.2
386 ;; searched-for character is a control-H
387 (if (not (search-backward "\010"
388 (save-excursion (beginning-of-line) (point))
390 (insert "`" (texinfo-parse-arg-discard) "'")
391 (insert (texinfo-parse-arg-discard)))
392 (goto-char texinfo-command-start))
394 ;; @verb{<char>TEXT<char>} (makeinfo 4.1 or later)
395 (put 'verb 'texinfo-format 'texinfo-format-verb)
396 (ptexinfmt-defun-if-void texinfo-format-verb ()
397 "Format text between non-quoted unique delimiter characters verbatim.
398 Enclose the verbatim text, including the delimiters, in braces. Print
399 text exactly as written (but not the delimiters) in a fixed-width.
401 For example, @verb\{|@|\} results in @ and
402 @verb\{+@'e?`!`+} results in @'e?`!`."
404 (let ((delimiter (buffer-substring-no-properties
405 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
406 (unless (looking-at "{")
407 (error "Not found: @verb start brace"))
408 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
409 (search-forward delimiter))
411 (unless (looking-at "}")
412 (error "Not found: @verb end brace"))
417 (put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX)
418 (ptexinfmt-defun-if-void texinfo-format-LaTeX ()
419 (texinfo-parse-arg-discard)
422 ;; @registeredsymbol{}
423 (put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol)
424 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
425 (texinfo-parse-arg-discard)
428 ;;; Accents and Special characters
430 (put 'euro 'texinfo-format 'texinfo-format-euro)
431 (ptexinfmt-defun-if-void texinfo-format-euro ()
432 (texinfo-parse-arg-discard)
435 ;; @pounds{} ==> # Pounds Sterling
436 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
437 (ptexinfmt-defun-if-void texinfo-format-pounds ()
438 (texinfo-parse-arg-discard)
441 ;; @ordf{} ==> a Spanish feminine
442 (put 'ordf 'texinfo-format 'texinfo-format-ordf)
443 (ptexinfmt-defun-if-void texinfo-format-ordf ()
444 (texinfo-parse-arg-discard)
447 ;; @ordm{} ==> o Spanish masculine
448 (put 'ordm 'texinfo-format 'texinfo-format-ordm)
449 (ptexinfmt-defun-if-void texinfo-format-ordm ()
450 (texinfo-parse-arg-discard)
453 ;; @OE{} ==> OE French-OE-ligature
454 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
455 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
456 (insert "OE" (texinfo-parse-arg-discard))
457 (goto-char texinfo-command-start))
460 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
461 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
462 (insert "oe" (texinfo-parse-arg-discard))
463 (goto-char texinfo-command-start))
465 ;; @AA{} ==> AA Scandinavian-A-with-circle
466 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
467 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
468 (insert "AA" (texinfo-parse-arg-discard))
469 (goto-char texinfo-command-start))
472 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
473 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
474 (insert "aa" (texinfo-parse-arg-discard))
475 (goto-char texinfo-command-start))
477 ;; @AE{} ==> AE Latin-Scandinavian-AE
478 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
479 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
480 (insert "AE" (texinfo-parse-arg-discard))
481 (goto-char texinfo-command-start))
484 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
485 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
486 (insert "ae" (texinfo-parse-arg-discard))
487 (goto-char texinfo-command-start))
489 ;; @ss{} ==> ss German-sharp-S
490 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
491 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
492 (insert "ss" (texinfo-parse-arg-discard))
493 (goto-char texinfo-command-start))
495 ;; @questiondown{} ==> ? upside-down-question-mark
496 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
497 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
498 (insert "?" (texinfo-parse-arg-discard))
499 (goto-char texinfo-command-start))
501 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
502 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
503 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
504 (insert "!" (texinfo-parse-arg-discard))
505 (goto-char texinfo-command-start))
507 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
508 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
509 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
510 (insert (texinfo-parse-arg-discard) "/L")
511 (goto-char texinfo-command-start))
513 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
514 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
515 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
516 (insert (texinfo-parse-arg-discard) "/l")
517 (goto-char texinfo-command-start))
519 ;; @O{} ==> O/ Scandinavian O-with-slash
520 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
521 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
522 (insert (texinfo-parse-arg-discard) "O/")
523 (goto-char texinfo-command-start))
525 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
526 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
527 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
528 (insert (texinfo-parse-arg-discard) "o/")
529 (goto-char texinfo-command-start))
531 ;; @,{c} ==> c, cedilla accent
532 (put '\, 'texinfo-format 'texinfo-format-cedilla-accent)
533 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
534 (insert (texinfo-parse-arg-discard) ",")
535 (goto-char texinfo-command-start))
538 ;; @dotaccent{o} ==> .o overdot-accent
539 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
540 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
541 (insert "." (texinfo-parse-arg-discard))
542 (goto-char texinfo-command-start))
544 ;; @ubaraccent{o} ==> _o underbar-accent
545 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
546 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
547 (insert "_" (texinfo-parse-arg-discard))
548 (goto-char texinfo-command-start))
550 ;; @udotaccent{o} ==> o-. underdot-accent
551 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
552 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
553 (insert (texinfo-parse-arg-discard) "-.")
554 (goto-char texinfo-command-start))
556 ;; @H{o} ==> ""o long Hungarian umlaut
557 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
558 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
559 (insert "\"\"" (texinfo-parse-arg-discard))
560 (goto-char texinfo-command-start))
562 ;; @ringaccent{o} ==> *o ring accent
563 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
564 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
565 (insert "*" (texinfo-parse-arg-discard))
566 (goto-char texinfo-command-start))
568 ;; @tieaccent{oo} ==> [oo tie after accent
569 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
570 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
571 (insert "[" (texinfo-parse-arg-discard))
572 (goto-char texinfo-command-start))
574 ;; @u{o} ==> (o breve accent
575 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
576 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
577 (insert "(" (texinfo-parse-arg-discard))
578 (goto-char texinfo-command-start))
580 ;; @v{o} ==> <o hacek accent
581 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
582 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
583 (insert "<" (texinfo-parse-arg-discard))
584 (goto-char texinfo-command-start))
586 ;; @dotless{i} ==> i dotless i and dotless j
587 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
588 (ptexinfmt-defun-if-void texinfo-format-dotless ()
589 (insert (texinfo-parse-arg-discard))
590 (goto-char texinfo-command-start))
593 (put '\. 'texinfo-format 'texinfo-format-\.)
594 (ptexinfmt-defun-if-void texinfo-format-\. ()
595 (texinfo-discard-command)
599 (put '\: 'texinfo-format 'texinfo-format-\:)
600 (ptexinfmt-defun-if-void texinfo-format-\: ()
601 (texinfo-discard-command))
604 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
605 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
606 (texinfo-discard-command))
609 (put '\/ 'texinfo-format 'texinfo-format-\/)
610 (ptexinfmt-defun-if-void texinfo-format-\/ ()
611 (texinfo-discard-command))
614 (put 'textdegree 'texinfo-format 'texinfo-format-textdegree)
615 (ptexinfmt-defun-if-void texinfo-format-textdegree ()
616 (insert "o" (texinfo-parse-arg-discard))
617 (goto-char texinfo-command-start))
620 (put 'geq 'texinfo-format 'texinfo-format-geq)
621 (ptexinfmt-defun-if-void texinfo-format-geq ()
622 (insert ">=" (texinfo-parse-arg-discard))
623 (goto-char texinfo-command-start))
626 (put 'leq 'texinfo-format 'texinfo-format-leq)
627 (ptexinfmt-defun-if-void texinfo-format-leq ()
628 (insert "<=" (texinfo-parse-arg-discard))
629 (goto-char texinfo-command-start))
633 ;; @ref{NODE-NAME, ...}
634 ;; @xref{NODE-NAME, ...}
635 (put 'ref 'texinfo-format 'texinfo-format-xref)
637 (ptexinfmt-defun-if-broken texinfo-format-xref ()
638 (let ((args (texinfo-format-parse-args)))
639 (texinfo-discard-command)
641 (let ((fname (or (nth 1 args) (nth 2 args))))
642 (if (null (or fname (nth 3 args)))
643 (insert (nth 0 args) "::")
644 (insert (or fname (nth 0 args)) ": ")
646 (insert "(" (nth 3 args) ")"))
647 (unless (null (nth 0 args))
648 (insert (nth 0 args)))))))
650 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
651 (put 'uref 'texinfo-format 'texinfo-format-uref)
652 (ptexinfmt-defun-if-broken texinfo-format-uref ()
653 "Format URL and optional URL-TITLE.
654 Insert ` ... ' around URL if no URL-TITLE argument;
655 otherwise, insert URL-TITLE followed by URL in parentheses."
656 (let ((args (texinfo-format-parse-args)))
657 (texinfo-discard-command)
660 (insert (nth 1 args) " (" (nth 0 args) ")")
661 (insert "`" (nth 0 args) "'"))))
663 ;; @inforef{NODE-NAME, CROSS-REFERENCE-NAME, INFO-FILE-NAME}
664 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
665 (ptexinfmt-defun-if-void texinfo-format-inforef ()
666 (let ((args (texinfo-format-parse-args)))
667 (texinfo-discard-command)
669 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
670 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
675 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
676 ;; - Info-tagify suport @anthor-*-refill.
677 ;; - info.el support Ref in Tag table.
678 (unless (get 'anchor 'texinfo-format)
679 (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
683 ;;; New command definition
684 ;; @alias NEW=EXISTING
685 (put 'alias 'texinfo-format 'texinfo-alias)
686 (ptexinfmt-defun-if-void texinfo-alias ()
687 (let ((start (1- (point)))
689 (skip-chars-forward " ")
690 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
691 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
692 (error "Invalid alias command")
693 (setq texinfo-alias-list
696 (buffer-substring (match-beginning 1) (match-end 1))
697 (buffer-substring (match-beginning 2) (match-end 2)))
699 (texinfo-discard-command))))
703 ;; @exampleindent INDENT (makeinfo 4.0 or later)
705 ;; @paragraphindent INDENT (makeinfo 4.0 or later)
706 ;; INDENT: asis, 0, n
708 ;; @firstparagraphindent WORD (makeinfo 4.6 or later)
709 ;; WORD: none, insert
714 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
715 (put 'image 'texinfo-format 'texinfo-format-image)
716 (ptexinfmt-defun-if-void texinfo-format-image ()
717 ;; I don't know makeinfo parse FILENAME.
718 (let ((args (texinfo-format-parse-args))
720 (when (null (nth 0 args))
721 (error "Invalid image command"))
722 (texinfo-discard-command)
723 ;; makeinfo uses FILENAME.txt
724 (setq filename (format "%s.txt" (nth 0 args)))
725 (message "Reading included file: %s" filename)
726 ;; verbatim for Info output
727 (goto-char (+ (point) (cadr (insert-file-contents filename))))
728 (message "Reading included file: %s...done" filename)))
730 ;; @hyphenation command discards an argument within braces
731 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
732 (ptexinfmt-defun-if-void texinfo-discard-command-and-arg ()
733 "Discard both @-command and its argument in braces."
734 (goto-char texinfo-command-end)
736 (setq texinfo-command-end (point))
737 (delete-region texinfo-command-start texinfo-command-end))
740 ;;; @multitable ... @end multitable
741 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
742 "*Number of extra spaces between entries (columns) in @multitable.")
744 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
745 "*multitable-temporary-buffer*")
746 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
747 "texinfo-multitable-temp-")
749 ;; These commands are defined in texinfo.tex for printed output.
750 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
751 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
752 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
753 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
755 (put 'multitable 'texinfo-format 'texinfo-multitable)
757 (ptexinfmt-defun-if-void texinfo-multitable ()
758 "Produce multi-column tables."
760 ;; This function pushes information onto the `texinfo-stack'.
761 ;; A stack element consists of:
762 ;; - type-of-command, i.e., multitable
763 ;; - the information about column widths, and
764 ;; - the position of texinfo-command-start.
765 ;; e.g., ('multitable (1 2 3 4) 123)
766 ;; The command line is then deleted.
769 ;; push width information on stack
770 (texinfo-multitable-widths))
771 (texinfo-discard-line-with-args))
773 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
774 (ptexinfmt-defun-if-void texinfo-end-multitable ()
775 "Discard the @end multitable line and pop the stack of multitable."
776 (texinfo-discard-command)
777 (texinfo-pop-stack 'multitable))
779 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
780 "Return list of widths of each column in a multi-column table."
781 (let (texinfo-multitable-width-list)
783 ;; @multitable @columnfractions .25 .3 .45
786 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
787 ;; Place point before first argument
788 (skip-chars-forward " \t")
790 ;; Check for common misspelling
791 ((looking-at "@columnfraction ")
792 (error "In @multitable, @columnfractions misspelled"))
793 ;; Case 1: @columnfractions .25 .3 .45
794 ((looking-at "@columnfractions")
797 (setq texinfo-multitable-width-list
801 (* fill-column (read (get-buffer (current-buffer))))))
802 texinfo-multitable-width-list))))
804 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
806 (let ((start-of-templates (point)))
808 (skip-chars-forward " \t")
809 (let* ((start-of-template (1+ (point)))
811 ;; forward-sexp works with braces in Texinfo mode
812 (progn (forward-sexp 1) (1- (point)))))
813 (setq texinfo-multitable-width-list
815 (goto-char end-of-template)
818 (goto-char start-of-template)
820 texinfo-multitable-width-list))
821 ;; Remove carriage return from within a template, if any.
822 ;; This helps those those who want to use more than
823 ;; one line's worth of words in @multitable line.
824 (narrow-to-region start-of-template end-of-template)
825 (goto-char (point-min))
826 (while (search-forward "\n" nil t)
828 (goto-char (point-max))
835 You probably need to specify column widths for @multitable correctly")))
836 ;; Check whether columns fit on page.
837 (let ((desired-columns
839 ;; between column spaces
840 (length texinfo-multitable-width-list)
841 ;; additional between column spaces, if any
842 texinfo-extra-inter-column-width
843 ;; sum of spaces for each entry
844 (apply '+ texinfo-multitable-width-list))))
845 (if (> desired-columns fill-column)
847 Multi-column table width, %d chars, is greater than page width, %d chars."
848 desired-columns fill-column))))
849 texinfo-multitable-width-list))
851 ;; @item A1 @tab A2 @tab A3
852 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
853 "Return multitable row, as a string.
854 End of row is beginning of next @item or beginning of @end.
855 Cells within rows are separated by @tab."
856 (skip-chars-forward " \t")
857 (let* ((start (point))
859 (re-search-forward "@item\\|@end")
860 (match-beginning 0)))
861 (row (progn (goto-char end)
862 (skip-chars-backward " ")
863 ;; remove whitespace at end of argument
864 (delete-region (point) end)
865 (buffer-substring start (point)))))
866 (delete-region texinfo-command-start end)
869 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
870 (ptexinfmt-defun-if-void texinfo-multitable-item ()
871 "Format a row within a multicolumn table.
872 Cells in row are separated by @tab.
873 Widths of cells are specified by the arguments in the @multitable line.
874 All cells are made to be the same height.
875 This command is executed when texinfmt sees @item inside @multitable."
876 (let ((original-buffer (current-buffer))
877 (table-widths (reverse (car (cdr (car texinfo-stack)))))
878 (existing-fill-column fill-column)
882 (table-entry-height 0)
883 ;; unformatted row looks like: A1 @tab A2 @tab A3
884 ;; extract-row command deletes the source line in the table.
885 (unformated-row (texinfo-multitable-extract-row)))
886 ;; Use a temporary buffer
887 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
888 (delete-region (point-min) (point-max))
889 (insert unformated-row)
890 (goto-char (point-min))
891 ;; 1. Check for correct number of @tab in line.
892 (let ((tab-number 1)) ;; one @tab between two columns
893 (while (search-forward "@tab" nil t)
894 (setq tab-number (1+ tab-number)))
895 (if (/= tab-number (length table-widths))
896 (error "Wrong number of @tab's in a @multitable row")))
897 (goto-char (point-min))
898 ;; 2. Format each cell, and copy to a rectangle
899 ;; buffer looks like this: A1 @tab A2 @tab A3
900 ;; Cell #1: format up to @tab
901 ;; Cell #2: format up to @tab
902 ;; Cell #3: format up to eob
905 (setq end (save-excursion
906 (if (search-forward "@tab" nil 'move)
907 ;; Delete the @tab command, including the @-sign
910 (progn (forward-word -1) (1- (point)))))
912 ;; Set fill-column *wider* than needed to produce inter-column space
913 (setq fill-column (+ 1
914 texinfo-extra-inter-column-width
915 (nth table-column table-widths)))
916 (narrow-to-region start end)
917 ;; Remove whitespace before and after entry.
918 (skip-chars-forward " ")
919 (delete-region (point) (save-excursion (beginning-of-line) (point)))
920 (goto-char (point-max))
921 (skip-chars-backward " ")
922 (delete-region (point) (save-excursion (end-of-line) (point)))
923 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
924 ;; does not see an unterminated @multitable.
925 (let (texinfo-stack) ;; nil
926 (texinfo-format-scan))
927 (let (fill-prefix) ;; no fill prefix
928 (fill-region (point-min) (point-max)))
929 (setq table-entry-height
930 (max table-entry-height (count-lines (point-min) (point-max))))
931 ;; 3. Move point to end of bottom line, and pad that line to fill column.
932 (goto-char (point-min))
933 (forward-line (1- table-entry-height))
934 (let* ((beg (point)) ;; beginning of line
935 ;; add one more space for inter-column spacing
941 (current-column)))))) ;; end of existing line
943 (if (> needed-whitespace 0) needed-whitespace 1)
945 ;; now, put formatted cell into a rectangle
946 (set (intern (concat texinfo-multitable-rectangle-name
947 (int-to-string table-column)))
948 (extract-rectangle (point-min) (point)))
949 (delete-region (point-min) (point))
950 (goto-char (point-max))
951 (setq table-column (1+ table-column))
953 ;; 4. Add extra lines to rectangles so all are of same height
954 (let ((total-number-of-columns table-column)
957 (while (> table-column 0)
958 (let ((this-rectangle (int-to-string table-column)))
959 (while (< (length this-rectangle) table-entry-height)
960 (setq this-rectangle (append this-rectangle '("")))))
961 (setq table-column (1- table-column)))
962 ;; 5. Insert formatted rectangles in original buffer
963 (switch-to-buffer original-buffer)
964 (open-line table-entry-height)
965 (while (< column-number total-number-of-columns)
969 (concat texinfo-multitable-rectangle-name
970 (int-to-string column-number)))))
973 (setq column-number (1+ column-number))))
974 (kill-buffer texinfo-multitable-buffer-name)
975 (setq fill-column existing-fill-column)))
978 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
979 (let ((indexelts (symbol-value
980 (cdr (assoc (texinfo-parse-arg-discard)
981 texinfo-indexvar-alist))))
983 (insert "\n* Menu:\n\n")
984 (setq opoint (point))
985 (texinfo-print-index nil indexelts)
987 (if (memq system-type '(vax-vms windows-nt ms-dos))
988 (texinfo-sort-region opoint (point))
989 (shell-command-on-region opoint (point) "sort -fd" 1))))
992 ;; @copying ... @end copying
993 ;; that Emacs 21.4 and lesser and XEmacs don't support.
994 (if (fboundp 'texinfo-copying)
996 (defvar texinfo-copying-text ""
997 "Text of the copyright notice and copying permissions.")
999 (defun texinfo-copying ()
1000 "Copy the copyright notice and copying permissions from the Texinfo file,
1001 as indicated by the @copying ... @end copying command;
1002 insert the text with the @insertcopying command."
1003 (let ((beg (progn (beginning-of-line) (point)))
1004 (end (progn (re-search-forward "^@end copying[ \t]*\n") (point))))
1005 (setq texinfo-copying-text
1006 (buffer-substring-no-properties
1007 (save-excursion (goto-char beg) (forward-line 1) (point))
1008 (save-excursion (goto-char end) (forward-line -1) (point))))
1009 (delete-region beg end)))
1011 (defun texinfo-insertcopying ()
1012 "Insert the copyright notice and copying permissions from the Texinfo file,
1013 which are indicated by the @copying ... @end copying command."
1014 (insert (concat "\n" texinfo-copying-text)))
1016 (defadvice texinfo-format-scan (before expand-@copying-section activate)
1017 "Extract @copying and replace @insertcopying with it."
1018 (goto-char (point-min))
1019 (when (search-forward "@copying" nil t)
1021 (while (search-forward "@insertcopying" nil t)
1022 (delete-region (match-beginning 0) (match-end 0))
1023 (texinfo-insertcopying))))
1025 (provide 'ptexinfmt)
1027 ;;; ptexinfmt.el ends here