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 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:
41 ;; @float, @caption, @shortcaption, @listoffloats
45 ;; @quotation (optional arguments)
46 ;; @acronym (optional argument)
47 ;; @dofirstparagraphindent
56 ;; @quotedblleft @quotedblright
57 ;; @quoteleft @quoteright @quotedblbase @quotesinglbase
58 ;; @guillemetleft @guillemetright @guilsinglleft @guilsinglright.
65 (defvar ptexinfmt-disable-broken-notice-flag t
66 "If non-nil disable notice, when call `ptexinfmt-broken-facility'.
67 This is last argument in `ptexinfmt-broken-facility'.")
69 (put 'ptexinfmt-broken-facility 'lisp-indent-function 'defun)
70 (defmacro ptexinfmt-broken-facility (facility docstring assertion
72 "Declare a symbol FACILITY is broken if ASSERTION is nil.
73 DOCSTRING will be printed if ASSERTION is nil and
74 `ptexinfmt-disable-broken-notice-flag' is nil."
75 `(let ((facility ',facility)
76 (docstring ,docstring)
77 (assertion (eval ',assertion)))
78 (put facility 'broken (not assertion))
81 (put facility 'broken-docstring docstring)
82 (if ptexinfmt-disable-broken-notice-flag
84 (message "BROKEN FACILITY DETECTED: %s" docstring)))))
86 (put 'ptexinfmt-defun-if-broken 'lisp-indent-function 'defun)
87 (defmacro ptexinfmt-defun-if-broken (&rest args)
88 "Redefine a function just like `defun' if it is considered broken."
89 (let ((name (list 'quote (car args))))
90 (setq args (cdr args))
93 (if (get ,name 'broken)
95 (function (lambda ,@args)))))))
97 (put 'ptexinfmt-defun-if-void 'lisp-indent-function 'defun)
98 (defmacro ptexinfmt-defun-if-void (&rest args)
99 "Define a function just like `defun' unless it is already defined."
100 (let ((name (list 'quote (car args))))
101 (setq args (cdr args))
107 (function (lambda ,@args)))))))
109 (put 'ptexinfmt-defvar-if-void 'lisp-indent-function 'defun)
110 (defmacro ptexinfmt-defvar-if-void (&rest args)
111 "Define a variable just like `defvar' unless it is already defined."
112 (let ((name (car args)))
113 (setq args (cdr args))
118 (defvar ,name ,@args)))))
121 (ptexinfmt-broken-facility texinfo-format-printindex
122 "Can't sort on Mule for Windows."
123 (if (and (memq system-type '(windows-nt ms-dos))
124 ;;; I don't know version threshold.
125 ;;; (string< texinfmt-version "2.37 of 24 May 1997")
126 (boundp 'MULE) (not (featurep 'meadow))) ; Mule for Windows
131 (ptexinfmt-broken-facility texinfo-format-var
132 "Don't perse @var argument."
135 (let (texinfo-enclosure-list texinfo-alias-list)
137 (insert "@var{@asis{foo}}\n")
138 (texinfo-format-expand-region (point-min) (point-max))
143 (ptexinfmt-broken-facility texinfo-format-xref
144 "Can't format @xref, 1st argument is empty."
147 (let (texinfo-enclosure-list texinfo-alias-list)
149 (insert "@xref{, xref, , file}\n")
150 (texinfo-format-expand-region (point-min) (point-max))
155 (ptexinfmt-broken-facility texinfo-format-uref
156 "Parse twice @uref argument."
159 (let (texinfo-enclosure-list texinfo-alias-list)
161 (insert "@uref{mailto:foo@@noncommand.example.com}\n")
162 (texinfo-format-expand-region (point-min) (point-max))
167 (ptexinfmt-broken-facility texinfo-multitable-widths
168 "`texinfo-multitable-widths' unsupport wide-char."
169 (if (fboundp 'texinfo-multitable-widths)
171 (let ((str "
\e$BI}9-J8;z
\e(B"))
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{} (makeinfo 4.8 or later)
226 (put 'slanted 'texinfo-format 'texinfo-format-noop)
228 ;; @sansserif{} (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)
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")))
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)
299 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
300 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
301 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
302 (delete-region texinfo-command-start
303 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
306 ;; @html ... @end html (makeinfo 3.11 or later)
307 (put 'html 'texinfo-format 'texinfo-format-html)
308 (ptexinfmt-defun-if-void texinfo-format-html ()
309 (delete-region texinfo-command-start
310 (progn (re-search-forward "@end html[ \t]*\n")
313 ;; @docbook ... @end docbook (makeinfo 4.7 or later)
314 (put 'docbook 'texinfo-format 'texinfo-format-docbook)
315 (ptexinfmt-defun-if-void texinfo-format-docbook ()
316 (delete-region texinfo-command-start
317 (progn (re-search-forward "@end docbook[ \t]*\n")
320 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
321 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
322 (defun texinfo-format-ifhtml ()
323 (delete-region texinfo-command-start
324 (progn (re-search-forward "@end ifhtml[ \t]*\n")
327 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
328 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
329 (ptexinfmt-defun-if-void texinfo-format-ifplaintext ()
330 (delete-region texinfo-command-start
331 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
334 ;; @ifdocbook ... @end ifdocbook (makeinfo 4.7 or later)
335 (put 'ifdocbook 'texinfo-format 'texinfo-format-ifdocbook)
336 (ptexinfmt-defun-if-void texinfo-format-ifdocbook ()
337 (delete-region texinfo-command-start
338 (progn (re-search-forward "@end ifdocbook[ \t]*\n")
344 ;; @indicateurl, @url, @env, @command,
345 (put 'env 'texinfo-format 'texinfo-format-code)
346 (put 'command 'texinfo-format 'texinfo-format-code)
348 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
349 (put 'url 'texinfo-format 'texinfo-format-uref) ; Texinfo 4.7
352 (put 'acronym 'texinfo-format 'texinfo-format-var)
354 (ptexinfmt-defun-if-broken texinfo-format-var ()
355 (let ((arg (texinfo-parse-expanded-arg)))
356 (texinfo-discard-command)
357 (insert (upcase arg))))
360 (put 'key 'texinfo-format 'texinfo-format-key)
361 (ptexinfmt-defun-if-void texinfo-format-key ()
362 (insert (texinfo-parse-arg-discard))
363 (goto-char texinfo-command-start))
365 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
366 (put 'email 'texinfo-format 'texinfo-format-email)
367 (ptexinfmt-defun-if-void texinfo-format-email ()
368 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
369 Insert < ... > around EMAIL-ADDRESS."
370 (let ((args (texinfo-format-parse-args)))
371 (texinfo-discard-command)
374 (insert (nth 1 args) " <" (nth 0 args) ">")
375 (insert "<" (nth 0 args) ">"))))
378 (put 'option 'texinfo-format 'texinfo-format-option)
379 (ptexinfmt-defun-if-void texinfo-format-option ()
380 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
381 ;; `looking-at-backward' not available in v. 18.57, 20.2
382 ;; searched-for character is a control-H
383 (if (not (search-backward "\010"
384 (save-excursion (beginning-of-line) (point))
386 (insert "`" (texinfo-parse-arg-discard) "'")
387 (insert (texinfo-parse-arg-discard)))
388 (goto-char texinfo-command-start))
390 ;; @verb{<char>TEXT<char>} (makeinfo 4.1 or later)
391 (put 'verb 'texinfo-format 'texinfo-format-verb)
392 (ptexinfmt-defun-if-void texinfo-format-verb ()
393 "Format text between non-quoted unique delimiter characters verbatim.
394 Enclose the verbatim text, including the delimiters, in braces. Print
395 text exactly as written (but not the delimiters) in a fixed-width.
397 For example, @verb\{|@|\} results in @ and
398 @verb\{+@'e?`!`+} results in @'e?`!`."
400 (let ((delimiter (buffer-substring-no-properties
401 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
402 (unless (looking-at "{")
403 (error "Not found: @verb start brace"))
404 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
405 (search-forward delimiter))
406 (delete-backward-char 1)
407 (unless (looking-at "}")
408 (error "Not found: @verb end brace"))
412 ;;; @LaTeX, @registeredsymbol{}
413 (put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX)
414 (ptexinfmt-defun-if-void texinfo-format-LaTeX ()
415 (texinfo-parse-arg-discard)
418 (put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol)
419 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
420 (texinfo-parse-arg-discard)
423 ;;; Accents and Special characters
425 (put 'euro 'texinfo-format 'texinfo-format-euro)
426 (ptexinfmt-defun-if-void texinfo-format-euro ()
427 (texinfo-parse-arg-discard)
430 ;; @pounds{} ==> # Pounds Sterling
431 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
432 (ptexinfmt-defun-if-void texinfo-format-pounds ()
433 (texinfo-parse-arg-discard)
436 ;; @ordf{} ==> a Spanish feminine
437 (put 'ordf 'texinfo-format 'texinfo-format-ordf)
438 (ptexinfmt-defun-if-void texinfo-format-ordf ()
439 (texinfo-parse-arg-discard)
442 ;; @ordm{} ==> o Spanish masculine
443 (put 'ordm 'texinfo-format 'texinfo-format-ordm)
444 (ptexinfmt-defun-if-void texinfo-format-ordm ()
445 (texinfo-parse-arg-discard)
448 ;; @OE{} ==> OE French-OE-ligature
449 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
450 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
451 (insert "OE" (texinfo-parse-arg-discard))
452 (goto-char texinfo-command-start))
455 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
456 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
457 (insert "oe" (texinfo-parse-arg-discard))
458 (goto-char texinfo-command-start))
460 ;; @AA{} ==> AA Scandinavian-A-with-circle
461 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
462 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
463 (insert "AA" (texinfo-parse-arg-discard))
464 (goto-char texinfo-command-start))
467 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
468 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
469 (insert "aa" (texinfo-parse-arg-discard))
470 (goto-char texinfo-command-start))
472 ;; @AE{} ==> AE Latin-Scandinavian-AE
473 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
474 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
475 (insert "AE" (texinfo-parse-arg-discard))
476 (goto-char texinfo-command-start))
479 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
480 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
481 (insert "ae" (texinfo-parse-arg-discard))
482 (goto-char texinfo-command-start))
484 ;; @ss{} ==> ss German-sharp-S
485 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
486 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
487 (insert "ss" (texinfo-parse-arg-discard))
488 (goto-char texinfo-command-start))
490 ;; @questiondown{} ==> ? upside-down-question-mark
491 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
492 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
493 (insert "?" (texinfo-parse-arg-discard))
494 (goto-char texinfo-command-start))
496 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
497 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
498 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
499 (insert "!" (texinfo-parse-arg-discard))
500 (goto-char texinfo-command-start))
502 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
503 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
504 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
505 (insert (texinfo-parse-arg-discard) "/L")
506 (goto-char texinfo-command-start))
508 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
509 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
510 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
511 (insert (texinfo-parse-arg-discard) "/l")
512 (goto-char texinfo-command-start))
514 ;; @O{} ==> O/ Scandinavian O-with-slash
515 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
516 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
517 (insert (texinfo-parse-arg-discard) "O/")
518 (goto-char texinfo-command-start))
520 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
521 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
522 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
523 (insert (texinfo-parse-arg-discard) "o/")
524 (goto-char texinfo-command-start))
526 ;; @,{c} ==> c, cedilla accent
527 (put '\, 'texinfo-format 'texinfo-format-cedilla-accent)
528 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
529 (insert (texinfo-parse-arg-discard) ",")
530 (goto-char texinfo-command-start))
533 ;; @dotaccent{o} ==> .o overdot-accent
534 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
535 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
536 (insert "." (texinfo-parse-arg-discard))
537 (goto-char texinfo-command-start))
539 ;; @ubaraccent{o} ==> _o underbar-accent
540 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
541 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
542 (insert "_" (texinfo-parse-arg-discard))
543 (goto-char texinfo-command-start))
545 ;; @udotaccent{o} ==> o-. underdot-accent
546 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
547 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
548 (insert (texinfo-parse-arg-discard) "-.")
549 (goto-char texinfo-command-start))
551 ;; @H{o} ==> ""o long Hungarian umlaut
552 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
553 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
554 (insert "\"\"" (texinfo-parse-arg-discard))
555 (goto-char texinfo-command-start))
557 ;; @ringaccent{o} ==> *o ring accent
558 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
559 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
560 (insert "*" (texinfo-parse-arg-discard))
561 (goto-char texinfo-command-start))
563 ;; @tieaccent{oo} ==> [oo tie after accent
564 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
565 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
566 (insert "[" (texinfo-parse-arg-discard))
567 (goto-char texinfo-command-start))
569 ;; @u{o} ==> (o breve accent
570 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
571 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
572 (insert "(" (texinfo-parse-arg-discard))
573 (goto-char texinfo-command-start))
575 ;; @v{o} ==> <o hacek accent
576 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
577 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
578 (insert "<" (texinfo-parse-arg-discard))
579 (goto-char texinfo-command-start))
581 ;; @dotless{i} ==> i dotless i and dotless j
582 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
583 (ptexinfmt-defun-if-void texinfo-format-dotless ()
584 (insert (texinfo-parse-arg-discard))
585 (goto-char texinfo-command-start))
588 (put '\. 'texinfo-format 'texinfo-format-\.)
589 (ptexinfmt-defun-if-void texinfo-format-\. ()
590 (texinfo-discard-command)
594 (put '\: 'texinfo-format 'texinfo-format-\:)
595 (ptexinfmt-defun-if-void texinfo-format-\: ()
596 (texinfo-discard-command))
599 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
600 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
601 (texinfo-discard-command))
604 (put '\/ 'texinfo-format 'texinfo-format-\/)
605 (ptexinfmt-defun-if-void texinfo-format-\/ ()
606 (texinfo-discard-command))
609 (put 'textdegree 'texinfo-format 'texinfo-format-textdegree)
610 (ptexinfmt-defun-if-void texinfo-format-textdegree ()
611 (insert "o" (texinfo-parse-arg-discard))
612 (goto-char texinfo-command-start))
617 (put 'ref 'texinfo-format 'texinfo-format-xref)
619 (ptexinfmt-defun-if-broken texinfo-format-xref ()
620 (let ((args (texinfo-format-parse-args)))
621 (texinfo-discard-command)
623 (let ((fname (or (nth 1 args) (nth 2 args))))
624 (if (null (or fname (nth 3 args)))
625 (insert (nth 0 args) "::")
626 (insert (or fname (nth 0 args)) ": ")
628 (insert "(" (nth 3 args) ")"))
629 (unless (null (nth 0 args))
630 (insert (nth 0 args)))))))
632 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
633 (put 'uref 'texinfo-format 'texinfo-format-uref)
634 (ptexinfmt-defun-if-broken texinfo-format-uref ()
635 "Format URL and optional URL-TITLE.
636 Insert ` ... ' around URL if no URL-TITLE argument;
637 otherwise, insert URL-TITLE followed by URL in parentheses."
638 (let ((args (texinfo-format-parse-args)))
639 (texinfo-discard-command)
642 (insert (nth 1 args) " (" (nth 0 args) ")")
643 (insert "`" (nth 0 args) "'"))))
646 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
647 (ptexinfmt-defun-if-void texinfo-format-inforef ()
648 (let ((args (texinfo-format-parse-args)))
649 (texinfo-discard-command)
651 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
652 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
657 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
658 ;; - Info-tagify suport @anthor-*-refill.
659 ;; - info.el support Ref in Tag table.
660 (unless (get 'anchor 'texinfo-format)
661 (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
665 ;;; New command definition
666 ;; @alias NEW=EXISTING
667 (put 'alias 'texinfo-format 'texinfo-alias)
668 (ptexinfmt-defun-if-void texinfo-alias ()
669 (let ((start (1- (point)))
671 (skip-chars-forward " ")
672 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
673 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
674 (error "Invalid alias command")
675 (setq texinfo-alias-list
678 (buffer-substring (match-beginning 1) (match-end 1))
679 (buffer-substring (match-beginning 2) (match-end 2)))
681 (texinfo-discard-command))))
685 ;; @exampleindent INDENT (makeinfo 4.0 or later)
687 ;; @paragraphindent INDENT (makeinfo 4.0 or later)
688 ;; INDENT: asis, 0, n
690 ;; @firstparagraphindent WORD (makeinfo 4.6 or later)
691 ;; WORD: none, insert
696 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
697 (put 'image 'texinfo-format 'texinfo-format-image)
698 (ptexinfmt-defun-if-void texinfo-format-image ()
699 ;; I don't know makeinfo parse FILENAME.
700 (let ((args (texinfo-format-parse-args))
702 (when (null (nth 0 args))
703 (error "Invalid image command"))
704 (texinfo-discard-command)
705 ;; makeinfo uses FILENAME.txt
706 (setq filename (format "%s.txt" (nth 0 args)))
707 (message "Reading included file: %s" filename)
708 ;; verbatim for Info output
709 (goto-char (+ (point) (cadr (insert-file-contents filename))))
710 (message "Reading included file: %s...done" filename)))
714 ;;; @multitable ... @end multitable
715 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
716 "*Number of extra spaces between entries (columns) in @multitable.")
718 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
719 "*multitable-temporary-buffer*")
720 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
721 "texinfo-multitable-temp-")
723 ;; These commands are defined in texinfo.tex for printed output.
724 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
725 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
726 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
727 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
729 (put 'multitable 'texinfo-format 'texinfo-multitable)
731 (ptexinfmt-defun-if-void texinfo-multitable ()
732 "Produce multi-column tables."
734 ;; This function pushes information onto the `texinfo-stack'.
735 ;; A stack element consists of:
736 ;; - type-of-command, i.e., multitable
737 ;; - the information about column widths, and
738 ;; - the position of texinfo-command-start.
739 ;; e.g., ('multitable (1 2 3 4) 123)
740 ;; The command line is then deleted.
743 ;; push width information on stack
744 (texinfo-multitable-widths))
745 (texinfo-discard-line-with-args))
747 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
748 (ptexinfmt-defun-if-void texinfo-end-multitable ()
749 "Discard the @end multitable line and pop the stack of multitable."
750 (texinfo-discard-command)
751 (texinfo-pop-stack 'multitable))
753 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
754 "Return list of widths of each column in a multi-column table."
755 (let (texinfo-multitable-width-list)
757 ;; @multitable @columnfractions .25 .3 .45
760 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
761 ;; Place point before first argument
762 (skip-chars-forward " \t")
764 ;; Check for common misspelling
765 ((looking-at "@columnfraction ")
766 (error "In @multitable, @columnfractions misspelled"))
767 ;; Case 1: @columnfractions .25 .3 .45
768 ((looking-at "@columnfractions")
771 (setq texinfo-multitable-width-list
775 (* fill-column (read (get-buffer (current-buffer))))))
776 texinfo-multitable-width-list))))
778 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
780 (let ((start-of-templates (point)))
782 (skip-chars-forward " \t")
783 (let* ((start-of-template (1+ (point)))
785 ;; forward-sexp works with braces in Texinfo mode
786 (progn (forward-sexp 1) (1- (point)))))
787 (setq texinfo-multitable-width-list
789 (goto-char end-of-template)
792 (goto-char start-of-template)
794 texinfo-multitable-width-list))
795 ;; Remove carriage return from within a template, if any.
796 ;; This helps those those who want to use more than
797 ;; one line's worth of words in @multitable line.
798 (narrow-to-region start-of-template end-of-template)
799 (goto-char (point-min))
800 (while (search-forward "\n" nil t)
802 (goto-char (point-max))
809 You probably need to specify column widths for @multitable correctly")))
810 ;; Check whether columns fit on page.
811 (let ((desired-columns
813 ;; between column spaces
814 (length texinfo-multitable-width-list)
815 ;; additional between column spaces, if any
816 texinfo-extra-inter-column-width
817 ;; sum of spaces for each entry
818 (apply '+ texinfo-multitable-width-list))))
819 (if (> desired-columns fill-column)
821 Multi-column table width, %d chars, is greater than page width, %d chars."
822 desired-columns fill-column))))
823 texinfo-multitable-width-list))
825 ;; @item A1 @tab A2 @tab A3
826 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
827 "Return multitable row, as a string.
828 End of row is beginning of next @item or beginning of @end.
829 Cells within rows are separated by @tab."
830 (skip-chars-forward " \t")
831 (let* ((start (point))
833 (re-search-forward "@item\\|@end")
834 (match-beginning 0)))
835 (row (progn (goto-char end)
836 (skip-chars-backward " ")
837 ;; remove whitespace at end of argument
838 (delete-region (point) end)
839 (buffer-substring start (point)))))
840 (delete-region texinfo-command-start end)
843 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
844 (ptexinfmt-defun-if-void texinfo-multitable-item ()
845 "Format a row within a multicolumn table.
846 Cells in row are separated by @tab.
847 Widths of cells are specified by the arguments in the @multitable line.
848 All cells are made to be the same height.
849 This command is executed when texinfmt sees @item inside @multitable."
850 (let ((original-buffer (current-buffer))
851 (table-widths (reverse (car (cdr (car texinfo-stack)))))
852 (existing-fill-column fill-column)
856 (table-entry-height 0)
857 ;; unformatted row looks like: A1 @tab A2 @tab A3
858 ;; extract-row command deletes the source line in the table.
859 (unformated-row (texinfo-multitable-extract-row)))
860 ;; Use a temporary buffer
861 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
862 (delete-region (point-min) (point-max))
863 (insert unformated-row)
864 (goto-char (point-min))
865 ;; 1. Check for correct number of @tab in line.
866 (let ((tab-number 1)) ;; one @tab between two columns
867 (while (search-forward "@tab" nil t)
868 (setq tab-number (1+ tab-number)))
869 (if (/= tab-number (length table-widths))
870 (error "Wrong number of @tab's in a @multitable row")))
871 (goto-char (point-min))
872 ;; 2. Format each cell, and copy to a rectangle
873 ;; buffer looks like this: A1 @tab A2 @tab A3
874 ;; Cell #1: format up to @tab
875 ;; Cell #2: format up to @tab
876 ;; Cell #3: format up to eob
879 (setq end (save-excursion
880 (if (search-forward "@tab" nil 'move)
881 ;; Delete the @tab command, including the @-sign
884 (progn (forward-word -1) (1- (point)))))
886 ;; Set fill-column *wider* than needed to produce inter-column space
887 (setq fill-column (+ 1
888 texinfo-extra-inter-column-width
889 (nth table-column table-widths)))
890 (narrow-to-region start end)
891 ;; Remove whitespace before and after entry.
892 (skip-chars-forward " ")
893 (delete-region (point) (save-excursion (beginning-of-line) (point)))
894 (goto-char (point-max))
895 (skip-chars-backward " ")
896 (delete-region (point) (save-excursion (end-of-line) (point)))
897 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
898 ;; does not see an unterminated @multitable.
899 (let (texinfo-stack) ;; nil
900 (texinfo-format-scan))
901 (let (fill-prefix) ;; no fill prefix
902 (fill-region (point-min) (point-max)))
903 (setq table-entry-height
904 (max table-entry-height (count-lines (point-min) (point-max))))
905 ;; 3. Move point to end of bottom line, and pad that line to fill column.
906 (goto-char (point-min))
907 (forward-line (1- table-entry-height))
908 (let* ((beg (point)) ;; beginning of line
909 ;; add one more space for inter-column spacing
915 (current-column)))))) ;; end of existing line
917 (if (> needed-whitespace 0) needed-whitespace 1)
919 ;; now, put formatted cell into a rectangle
920 (set (intern (concat texinfo-multitable-rectangle-name
921 (int-to-string table-column)))
922 (extract-rectangle (point-min) (point)))
923 (delete-region (point-min) (point))
924 (goto-char (point-max))
925 (setq table-column (1+ table-column))
927 ;; 4. Add extra lines to rectangles so all are of same height
928 (let ((total-number-of-columns table-column)
931 (while (> table-column 0)
932 (let ((this-rectangle (int-to-string table-column)))
933 (while (< (length this-rectangle) table-entry-height)
934 (setq this-rectangle (append this-rectangle '("")))))
935 (setq table-column (1- table-column)))
936 ;; 5. Insert formatted rectangles in original buffer
937 (switch-to-buffer original-buffer)
938 (open-line table-entry-height)
939 (while (< column-number total-number-of-columns)
943 (concat texinfo-multitable-rectangle-name
944 (int-to-string column-number)))))
947 (setq column-number (1+ column-number))))
948 (kill-buffer texinfo-multitable-buffer-name)
949 (setq fill-column existing-fill-column)))
952 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
953 (let ((indexelts (symbol-value
954 (cdr (assoc (texinfo-parse-arg-discard)
955 texinfo-indexvar-alist))))
957 (insert "\n* Menu:\n\n")
958 (setq opoint (point))
959 (texinfo-print-index nil indexelts)
961 (if (memq system-type '(vax-vms windows-nt ms-dos))
962 (texinfo-sort-region opoint (point))
963 (shell-command-on-region opoint (point) "sort -fd" 1))))
967 ;;; ptexinfmt.el ends here