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:
41 ;; @float, @caption, @shortcaption, @listoffloats
45 ;; @quotation (optional arguments)
46 ;; @acronym (optional argument)
47 ;; @dofirstparagraphindent
62 (defvar ptexinfmt-disable-broken-notice-flag t
63 "If non-nil disable notice, when call `ptexinfmt-broken-facility'.
64 This is last argument in `ptexinfmt-broken-facility'.")
66 (put 'ptexinfmt-broken-facility 'lisp-indent-function 'defun)
67 (defmacro ptexinfmt-broken-facility (facility docstring assertion
69 "Declare a symbol FACILITY is broken if ASSERTION is nil.
70 DOCSTRING will be printed if ASSERTION is nil and
71 `ptexinfmt-disable-broken-notice-flag' is nil."
72 (` (let ((facility '(, facility))
73 (docstring (, docstring))
74 (assertion (eval '(, assertion))))
75 (put facility 'broken (not assertion))
78 (put facility 'broken-docstring docstring)
79 (if ptexinfmt-disable-broken-notice-flag
81 (message "BROKEN FACILITY DETECTED: %s" docstring))))))
83 (put 'ptexinfmt-defun-if-broken 'lisp-indent-function 'defun)
84 (defmacro ptexinfmt-defun-if-broken (&rest args)
85 "Redefine a function just like `defun' if it is considered broken."
86 (let ((name (list 'quote (car args))))
87 (setq args (cdr args))
90 (if (get (, name) 'broken)
92 (function (lambda (,@ args)))))))))
94 (put 'ptexinfmt-defun-if-void 'lisp-indent-function 'defun)
95 (defmacro ptexinfmt-defun-if-void (&rest args)
96 "Define a function just like `defun' unless it is already defined."
97 (let ((name (list 'quote (car args))))
98 (setq args (cdr args))
101 (if (fboundp (, name))
104 (function (lambda (,@ args)))))))))
106 (put 'ptexinfmt-defvar-if-void 'lisp-indent-function 'defun)
107 (defmacro ptexinfmt-defvar-if-void (&rest args)
108 "Define a variable just like `defvar' unless it is already defined."
109 (let ((name (car args)))
110 (setq args (cdr args))
113 (if (boundp '(, name))
115 (defvar (, name) (,@ args)))))))
118 (ptexinfmt-broken-facility texinfo-format-printindex
119 "Can't sort on Mule for Windows."
123 (ptexinfmt-broken-facility texinfo-format-var
124 "Don't perse @var argument."
127 (let (texinfo-enclosure-list texinfo-alias-list)
129 (insert "@var{@asis{foo}}\n")
130 (texinfo-format-expand-region (point-min) (point-max))
135 (ptexinfmt-broken-facility texinfo-format-xref
136 "Can't format @xref, 1st argument is empty."
139 (let (texinfo-enclosure-list texinfo-alias-list)
141 (insert "@xref{, xref, , file}\n")
142 (texinfo-format-expand-region (point-min) (point-max))
147 (ptexinfmt-broken-facility texinfo-format-uref
148 "Parse twice @uref argument."
151 (let (texinfo-enclosure-list texinfo-alias-list)
153 (insert "@uref{mailto:foo@@noncommand.example.com}\n")
154 (texinfo-format-expand-region (point-min) (point-max))
159 (ptexinfmt-broken-facility texinfo-multitable-widths
160 "`texinfo-multitable-widths' unsupport wide-char."
161 (if (fboundp 'texinfo-multitable-widths)
163 (let ((str "
\e$BI}9-J8;z
\e(B"))
165 (insert (format " {%s}\n" str))
166 (goto-char (point-min))
167 (if (= (car (texinfo-multitable-widths)) (length str))
170 ;; function definition is void
173 (ptexinfmt-broken-facility texinfo-multitable-item
174 "`texinfo-multitable-item' unsupport wide-char."
175 (not (get 'texinfo-multitable-widths 'broken)))
178 ;;; Hardcopy and HTML (discard)
180 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
181 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
182 (put 'documentdescription 'texinfo-format 'texinfo-discard-line-with-args)
185 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
186 (put 'letterpaper 'texinfo-format 'texinfo-discard-line)
187 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
188 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
189 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
190 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
191 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
194 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
195 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
198 (put 'setcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
199 (put 'setshortcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
200 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
201 (put 'frenchspacing 'texinfo-format 'texinfo-discard-line-with-args)
204 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
205 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
206 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
207 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
208 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
209 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
210 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
213 (put 'page 'texinfo-format 'texinfo-discard-line)
214 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
216 ;; @slanted{} (makeinfo 4.8 or later)
217 (put 'slanted 'texinfo-format 'texinfo-format-noop)
219 ;; @sansserif{} (makeinfo 4.8 or later)
220 (put 'sansserif 'texinfo-format 'texinfo-format-noop)
222 ;; @tie{} (makeinfo 4.3 or later)
223 (put 'tie 'texinfo-format 'texinfo-format-tie)
224 (ptexinfmt-defun-if-void texinfo-format-tie ()
225 (texinfo-parse-arg-discard)
231 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
232 (ptexinfmt-defun-if-void texinfo-format-dircategory ()
233 (let ((str (texinfo-parse-arg-discard)))
234 (delete-region (point)
236 (skip-chars-forward " ")
238 (insert "INFO-DIR-SECTION " str "\n")))
241 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
242 (ptexinfmt-defun-if-void texinfo-format-direntry ()
243 (texinfo-push-stack 'direntry nil)
244 (texinfo-discard-line)
245 (insert "START-INFO-DIR-ENTRY\n"))
247 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
248 (ptexinfmt-defun-if-void texinfo-end-direntry ()
249 (texinfo-discard-command)
250 (insert "END-INFO-DIR-ENTRY\n\n")
251 (texinfo-pop-stack 'direntry))
255 ;; @detailmenu ... @end detailmenu
256 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
257 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
259 ;; @smalldisplay ... @end smalldisplay
260 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
261 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
263 ;; @smallformat ... @end smallformat
264 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
265 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
267 ;; @cartouche ... @end cartouche
268 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
269 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
273 ;; @ifnottex ... @end ifnottex (makeinfo 3.11 or later)
274 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
275 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
277 ;; @ifnothtml ... @end ifnothtml (makeinfo 3.11 or later)
278 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
279 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
281 ;; @ifnotplaintext ... @end ifnotplaintext (makeinfo 4.2 or later)
282 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
283 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
285 ;; @ifnotdocbook ... @end ifnotdocbook (makeinfo 4.7 or later)
286 (put 'ifnotdocbook 'texinfo-format 'texinfo-discard-line)
287 (put 'ifnotdocbook 'texinfo-end 'texinfo-discard-command)
289 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
290 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
291 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
292 (delete-region texinfo-command-start
293 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
296 ;; @html ... @end html (makeinfo 3.11 or later)
297 (put 'html 'texinfo-format 'texinfo-format-html)
298 (ptexinfmt-defun-if-void texinfo-format-html ()
299 (delete-region texinfo-command-start
300 (progn (re-search-forward "@end html[ \t]*\n")
303 ;; @docbook ... @end docbook (makeinfo 4.7 or later)
304 (put 'docbook 'texinfo-format 'texinfo-format-docbook)
305 (ptexinfmt-defun-if-void texinfo-format-docbook ()
306 (delete-region texinfo-command-start
307 (progn (re-search-forward "@end docbook[ \t]*\n")
310 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
311 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
312 (defun texinfo-format-ifhtml ()
313 (delete-region texinfo-command-start
314 (progn (re-search-forward "@end ifhtml[ \t]*\n")
317 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
318 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
319 (ptexinfmt-defun-if-void texinfo-format-ifplaintext ()
320 (delete-region texinfo-command-start
321 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
324 ;; @ifdocbook ... @end ifdocbook (makeinfo 4.7 or later)
325 (put 'ifdocbook 'texinfo-format 'texinfo-format-ifdocbook)
326 (ptexinfmt-defun-if-void texinfo-format-ifdocbook ()
327 (delete-region texinfo-command-start
328 (progn (re-search-forward "@end ifdocbook[ \t]*\n")
333 ;; @indicateurl, @url, @env, @command,
334 (put 'env 'texinfo-format 'texinfo-format-code)
335 (put 'command 'texinfo-format 'texinfo-format-code)
337 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
338 (put 'url 'texinfo-format 'texinfo-format-uref) ; Texinfo 4.7
341 (put 'acronym 'texinfo-format 'texinfo-format-var)
343 (ptexinfmt-defun-if-broken texinfo-format-var ()
344 (let ((arg (texinfo-parse-expanded-arg)))
345 (texinfo-discard-command)
346 (insert (upcase arg))))
349 (put 'key 'texinfo-format 'texinfo-format-key)
350 (ptexinfmt-defun-if-void texinfo-format-key ()
351 (insert (texinfo-parse-arg-discard))
352 (goto-char texinfo-command-start))
354 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
355 (put 'email 'texinfo-format 'texinfo-format-email)
356 (ptexinfmt-defun-if-void texinfo-format-email ()
357 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
358 Insert < ... > around EMAIL-ADDRESS."
359 (let ((args (texinfo-format-parse-args)))
360 (texinfo-discard-command)
363 (insert (nth 1 args) " <" (nth 0 args) ">")
364 (insert "<" (nth 0 args) ">"))))
367 (put 'option 'texinfo-format 'texinfo-format-option)
368 (ptexinfmt-defun-if-void texinfo-format-option ()
369 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
370 ;; `looking-at-backward' not available in v. 18.57, 20.2
371 ;; searched-for character is a control-H
372 (if (not (search-backward "\010"
373 (save-excursion (beginning-of-line) (point))
375 (insert "`" (texinfo-parse-arg-discard) "'")
376 (insert (texinfo-parse-arg-discard)))
377 (goto-char texinfo-command-start))
379 ;; @verb{<char>TEXT<char>} (makeinfo 4.1 or later)
380 (put 'verb 'texinfo-format 'texinfo-format-verb)
381 (ptexinfmt-defun-if-void texinfo-format-verb ()
382 "Format text between non-quoted unique delimiter characters verbatim.
383 Enclose the verbatim text, including the delimiters, in braces. Print
384 text exactly as written (but not the delimiters) in a fixed-width.
386 For example, @verb\{|@|\} results in @ and
387 @verb\{+@'e?`!`+} results in @'e?`!`."
389 (let ((delimiter (buffer-substring-no-properties
390 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
391 (unless (looking-at "{")
392 (error "Not found: @verb start brace"))
393 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
394 (search-forward delimiter))
395 (delete-backward-char 1)
396 (unless (looking-at "}")
397 (error "Not found: @verb end brace"))
401 ;;; @LaTeX, @registeredsymbol{}
402 (put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX)
403 (ptexinfmt-defun-if-void texinfo-format-LaTeX ()
404 (texinfo-parse-arg-discard)
407 (put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol)
408 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
409 (texinfo-parse-arg-discard)
412 ;;; Accents and Special characters
414 (put 'euro 'texinfo-format 'texinfo-format-euro)
415 (ptexinfmt-defun-if-void texinfo-format-euro ()
416 (texinfo-parse-arg-discard)
419 ;; @pounds{} ==> # Pounds Sterling
420 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
421 (ptexinfmt-defun-if-void texinfo-format-pounds ()
422 (texinfo-parse-arg-discard)
425 ;; @ordf{} ==> a Spanish feminine
426 (put 'ordf 'texinfo-format 'texinfo-format-ordf)
427 (ptexinfmt-defun-if-void texinfo-format-ordf ()
428 (texinfo-parse-arg-discard)
431 ;; @ordm{} ==> o Spanish masculine
432 (put 'ordm 'texinfo-format 'texinfo-format-ordm)
433 (ptexinfmt-defun-if-void texinfo-format-ordm ()
434 (texinfo-parse-arg-discard)
437 ;; @OE{} ==> OE French-OE-ligature
438 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
439 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
440 (insert "OE" (texinfo-parse-arg-discard))
441 (goto-char texinfo-command-start))
444 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
445 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
446 (insert "oe" (texinfo-parse-arg-discard))
447 (goto-char texinfo-command-start))
449 ;; @AA{} ==> AA Scandinavian-A-with-circle
450 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
451 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
452 (insert "AA" (texinfo-parse-arg-discard))
453 (goto-char texinfo-command-start))
456 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
457 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
458 (insert "aa" (texinfo-parse-arg-discard))
459 (goto-char texinfo-command-start))
461 ;; @AE{} ==> AE Latin-Scandinavian-AE
462 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
463 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
464 (insert "AE" (texinfo-parse-arg-discard))
465 (goto-char texinfo-command-start))
468 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
469 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
470 (insert "ae" (texinfo-parse-arg-discard))
471 (goto-char texinfo-command-start))
473 ;; @ss{} ==> ss German-sharp-S
474 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
475 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
476 (insert "ss" (texinfo-parse-arg-discard))
477 (goto-char texinfo-command-start))
479 ;; @questiondown{} ==> ? upside-down-question-mark
480 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
481 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
482 (insert "?" (texinfo-parse-arg-discard))
483 (goto-char texinfo-command-start))
485 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
486 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
487 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
488 (insert "!" (texinfo-parse-arg-discard))
489 (goto-char texinfo-command-start))
491 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
492 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
493 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
494 (insert (texinfo-parse-arg-discard) "/L")
495 (goto-char texinfo-command-start))
497 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
498 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
499 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
500 (insert (texinfo-parse-arg-discard) "/l")
501 (goto-char texinfo-command-start))
503 ;; @O{} ==> O/ Scandinavian O-with-slash
504 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
505 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
506 (insert (texinfo-parse-arg-discard) "O/")
507 (goto-char texinfo-command-start))
509 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
510 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
511 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
512 (insert (texinfo-parse-arg-discard) "o/")
513 (goto-char texinfo-command-start))
515 ;; @,{c} ==> c, cedilla accent
516 (put ', 'texinfo-format 'texinfo-format-cedilla-accent)
517 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
518 (insert (texinfo-parse-arg-discard) ",")
519 (goto-char texinfo-command-start))
522 ;; @dotaccent{o} ==> .o overdot-accent
523 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
524 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
525 (insert "." (texinfo-parse-arg-discard))
526 (goto-char texinfo-command-start))
528 ;; @ubaraccent{o} ==> _o underbar-accent
529 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
530 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
531 (insert "_" (texinfo-parse-arg-discard))
532 (goto-char texinfo-command-start))
534 ;; @udotaccent{o} ==> o-. underdot-accent
535 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
536 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
537 (insert (texinfo-parse-arg-discard) "-.")
538 (goto-char texinfo-command-start))
540 ;; @H{o} ==> ""o long Hungarian umlaut
541 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
542 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
543 (insert "\"\"" (texinfo-parse-arg-discard))
544 (goto-char texinfo-command-start))
546 ;; @ringaccent{o} ==> *o ring accent
547 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
548 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
549 (insert "*" (texinfo-parse-arg-discard))
550 (goto-char texinfo-command-start))
552 ;; @tieaccent{oo} ==> [oo tie after accent
553 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
554 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
555 (insert "[" (texinfo-parse-arg-discard))
556 (goto-char texinfo-command-start))
558 ;; @u{o} ==> (o breve accent
559 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
560 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
561 (insert "(" (texinfo-parse-arg-discard))
562 (goto-char texinfo-command-start))
564 ;; @v{o} ==> <o hacek accent
565 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
566 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
567 (insert "<" (texinfo-parse-arg-discard))
568 (goto-char texinfo-command-start))
570 ;; @dotless{i} ==> i dotless i and dotless j
571 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
572 (ptexinfmt-defun-if-void texinfo-format-dotless ()
573 (insert (texinfo-parse-arg-discard))
574 (goto-char texinfo-command-start))
577 (put '\. 'texinfo-format 'texinfo-format-\.)
578 (ptexinfmt-defun-if-void texinfo-format-\. ()
579 (texinfo-discard-command)
583 (put '\: 'texinfo-format 'texinfo-format-\:)
584 (ptexinfmt-defun-if-void texinfo-format-\: ()
585 (texinfo-discard-command))
588 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
589 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
590 (texinfo-discard-command))
593 (put '\/ 'texinfo-format 'texinfo-format-\/)
594 (ptexinfmt-defun-if-void texinfo-format-\/ ()
595 (texinfo-discard-command))
600 (put 'ref 'texinfo-format 'texinfo-format-xref)
602 (ptexinfmt-defun-if-broken texinfo-format-xref ()
603 (let ((args (texinfo-format-parse-args)))
604 (texinfo-discard-command)
606 (let ((fname (or (nth 1 args) (nth 2 args))))
607 (if (null (or fname (nth 3 args)))
608 (insert (nth 0 args) "::")
609 (insert (or fname (nth 0 args)) ": ")
611 (insert "(" (nth 3 args) ")"))
612 (unless (null (nth 0 args))
613 (insert (nth 0 args)))))))
615 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
616 (put 'uref 'texinfo-format 'texinfo-format-uref)
617 (ptexinfmt-defun-if-broken texinfo-format-uref ()
618 "Format URL and optional URL-TITLE.
619 Insert ` ... ' around URL if no URL-TITLE argument;
620 otherwise, insert URL-TITLE followed by URL in parentheses."
621 (let ((args (texinfo-format-parse-args)))
622 (texinfo-discard-command)
625 (insert (nth 1 args) " (" (nth 0 args) ")")
626 (insert "`" (nth 0 args) "'"))))
629 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
630 (ptexinfmt-defun-if-void texinfo-format-inforef ()
631 (let ((args (texinfo-format-parse-args)))
632 (texinfo-discard-command)
634 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
635 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
640 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
641 ;; - Info-tagify suport @anthor-*-refill.
642 ;; - info.el support Ref in Tag table.
643 (unless (get 'anchor 'texinfo-format)
644 (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
648 ;;; New command definition
649 ;; @alias NEW=EXISTING
650 (put 'alias 'texinfo-format 'texinfo-alias)
651 (ptexinfmt-defun-if-void texinfo-alias ()
652 (let ((start (1- (point)))
654 (skip-chars-forward " ")
655 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
656 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
657 (error "Invalid alias command")
658 (setq texinfo-alias-list
661 (buffer-substring (match-beginning 1) (match-end 1))
662 (buffer-substring (match-beginning 2) (match-end 2)))
664 (texinfo-discard-command))))
668 ;; @exampleindent INDENT (makeinfo 4.0 or later)
670 ;; @paragraphindent INDENT (makeinfo 4.0 or later)
671 ;; INDENT: asis, 0, n
673 ;; @firstparagraphindent WORD (makeinfo 4.6 or later)
674 ;; WORD: none, insert
679 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
680 (put 'image 'texinfo-format 'texinfo-format-image)
681 (ptexinfmt-defun-if-void texinfo-format-image ()
682 ;; I don't know makeinfo parse FILENAME.
683 (let ((args (texinfo-format-parse-args))
685 (when (null (nth 0 args))
686 (error "Invalid image command"))
687 (texinfo-discard-command)
688 ;; makeinfo uses FILENAME.txt
689 (setq filename (format "%s.txt" (nth 0 args)))
690 (message "Reading included file: %s" filename)
691 ;; verbatim for Info output
692 (goto-char (+ (point) (cadr (insert-file-contents filename))))
693 (message "Reading included file: %s...done" filename)))
695 ;; @hyphenation command discards an argument within braces
696 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
697 (ptexinfmt-defun-if-void texinfo-discard-command-and-arg ()
698 "Discard both @-command and its argument in braces."
699 (goto-char texinfo-command-end)
701 (setq texinfo-command-end (point))
702 (delete-region texinfo-command-start texinfo-command-end))
705 ;;; @multitable ... @end multitable
706 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
707 "*Number of extra spaces between entries (columns) in @multitable.")
709 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
710 "*multitable-temporary-buffer*")
711 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
712 "texinfo-multitable-temp-")
714 ;; These commands are defined in texinfo.tex for printed output.
715 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
716 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
717 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
718 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
720 (put 'multitable 'texinfo-format 'texinfo-multitable)
722 (ptexinfmt-defun-if-void texinfo-multitable ()
723 "Produce multi-column tables."
725 ;; This function pushes information onto the `texinfo-stack'.
726 ;; A stack element consists of:
727 ;; - type-of-command, i.e., multitable
728 ;; - the information about column widths, and
729 ;; - the position of texinfo-command-start.
730 ;; e.g., ('multitable (1 2 3 4) 123)
731 ;; The command line is then deleted.
734 ;; push width information on stack
735 (texinfo-multitable-widths))
736 (texinfo-discard-line-with-args))
738 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
739 (ptexinfmt-defun-if-void texinfo-end-multitable ()
740 "Discard the @end multitable line and pop the stack of multitable."
741 (texinfo-discard-command)
742 (texinfo-pop-stack 'multitable))
744 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
745 "Return list of widths of each column in a multi-column table."
746 (let (texinfo-multitable-width-list)
748 ;; @multitable @columnfractions .25 .3 .45
751 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
752 ;; Place point before first argument
753 (skip-chars-forward " \t")
755 ;; Check for common misspelling
756 ((looking-at "@columnfraction ")
757 (error "In @multitable, @columnfractions misspelled"))
758 ;; Case 1: @columnfractions .25 .3 .45
759 ((looking-at "@columnfractions")
762 (setq texinfo-multitable-width-list
766 (* fill-column (read (get-buffer (current-buffer))))))
767 texinfo-multitable-width-list))))
769 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
771 (let ((start-of-templates (point)))
773 (skip-chars-forward " \t")
774 (let* ((start-of-template (1+ (point)))
776 ;; forward-sexp works with braces in Texinfo mode
777 (progn (forward-sexp 1) (1- (point)))))
778 (setq texinfo-multitable-width-list
780 (goto-char end-of-template)
783 (goto-char start-of-template)
785 texinfo-multitable-width-list))
786 ;; Remove carriage return from within a template, if any.
787 ;; This helps those those who want to use more than
788 ;; one line's worth of words in @multitable line.
789 (narrow-to-region start-of-template end-of-template)
790 (goto-char (point-min))
791 (while (search-forward "\n" nil t)
793 (goto-char (point-max))
800 You probably need to specify column widths for @multitable correctly")))
801 ;; Check whether columns fit on page.
802 (let ((desired-columns
804 ;; between column spaces
805 (length texinfo-multitable-width-list)
806 ;; additional between column spaces, if any
807 texinfo-extra-inter-column-width
808 ;; sum of spaces for each entry
809 (apply '+ texinfo-multitable-width-list))))
810 (if (> desired-columns fill-column)
812 Multi-column table width, %d chars, is greater than page width, %d chars."
813 desired-columns fill-column))))
814 texinfo-multitable-width-list))
816 ;; @item A1 @tab A2 @tab A3
817 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
818 "Return multitable row, as a string.
819 End of row is beginning of next @item or beginning of @end.
820 Cells within rows are separated by @tab."
821 (skip-chars-forward " \t")
822 (let* ((start (point))
824 (re-search-forward "@item\\|@end")
825 (match-beginning 0)))
826 (row (progn (goto-char end)
827 (skip-chars-backward " ")
828 ;; remove whitespace at end of argument
829 (delete-region (point) end)
830 (buffer-substring start (point)))))
831 (delete-region texinfo-command-start end)
834 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
835 (ptexinfmt-defun-if-void texinfo-multitable-item ()
836 "Format a row within a multicolumn table.
837 Cells in row are separated by @tab.
838 Widths of cells are specified by the arguments in the @multitable line.
839 All cells are made to be the same height.
840 This command is executed when texinfmt sees @item inside @multitable."
841 (let ((original-buffer (current-buffer))
842 (table-widths (reverse (car (cdr (car texinfo-stack)))))
843 (existing-fill-column fill-column)
847 (table-entry-height 0)
848 ;; unformatted row looks like: A1 @tab A2 @tab A3
849 ;; extract-row command deletes the source line in the table.
850 (unformated-row (texinfo-multitable-extract-row)))
851 ;; Use a temporary buffer
852 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
853 (delete-region (point-min) (point-max))
854 (insert unformated-row)
855 (goto-char (point-min))
856 ;; 1. Check for correct number of @tab in line.
857 (let ((tab-number 1)) ;; one @tab between two columns
858 (while (search-forward "@tab" nil t)
859 (setq tab-number (1+ tab-number)))
860 (if (/= tab-number (length table-widths))
861 (error "Wrong number of @tab's in a @multitable row")))
862 (goto-char (point-min))
863 ;; 2. Format each cell, and copy to a rectangle
864 ;; buffer looks like this: A1 @tab A2 @tab A3
865 ;; Cell #1: format up to @tab
866 ;; Cell #2: format up to @tab
867 ;; Cell #3: format up to eob
870 (setq end (save-excursion
871 (if (search-forward "@tab" nil 'move)
872 ;; Delete the @tab command, including the @-sign
875 (progn (forward-word -1) (1- (point)))))
877 ;; Set fill-column *wider* than needed to produce inter-column space
878 (setq fill-column (+ 1
879 texinfo-extra-inter-column-width
880 (nth table-column table-widths)))
881 (narrow-to-region start end)
882 ;; Remove whitespace before and after entry.
883 (skip-chars-forward " ")
884 (delete-region (point) (save-excursion (beginning-of-line) (point)))
885 (goto-char (point-max))
886 (skip-chars-backward " ")
887 (delete-region (point) (save-excursion (end-of-line) (point)))
888 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
889 ;; does not see an unterminated @multitable.
890 (let (texinfo-stack) ;; nil
891 (texinfo-format-scan))
892 (let (fill-prefix) ;; no fill prefix
893 (fill-region (point-min) (point-max)))
894 (setq table-entry-height
895 (max table-entry-height (count-lines (point-min) (point-max))))
896 ;; 3. Move point to end of bottom line, and pad that line to fill column.
897 (goto-char (point-min))
898 (forward-line (1- table-entry-height))
899 (let* ((beg (point)) ;; beginning of line
900 ;; add one more space for inter-column spacing
906 (current-column)))))) ;; end of existing line
908 (if (> needed-whitespace 0) needed-whitespace 1)
910 ;; now, put formatted cell into a rectangle
911 (set (intern (concat texinfo-multitable-rectangle-name
912 (int-to-string table-column)))
913 (extract-rectangle (point-min) (point)))
914 (delete-region (point-min) (point))
915 (goto-char (point-max))
916 (setq table-column (1+ table-column))
918 ;; 4. Add extra lines to rectangles so all are of same height
919 (let ((total-number-of-columns table-column)
922 (while (> table-column 0)
923 (let ((this-rectangle (int-to-string table-column)))
924 (while (< (length this-rectangle) table-entry-height)
925 (setq this-rectangle (append this-rectangle '("")))))
926 (setq table-column (1- table-column)))
927 ;; 5. Insert formatted rectangles in original buffer
928 (switch-to-buffer original-buffer)
929 (open-line table-entry-height)
930 (while (< column-number total-number-of-columns)
934 (concat texinfo-multitable-rectangle-name
935 (int-to-string column-number)))))
938 (setq column-number (1+ column-number))))
939 (kill-buffer texinfo-multitable-buffer-name)
940 (setq fill-column existing-fill-column)))
943 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
944 (let ((indexelts (symbol-value
945 (cdr (assoc (texinfo-parse-arg-discard)
946 texinfo-indexvar-alist))))
948 (insert "\n* Menu:\n\n")
949 (setq opoint (point))
950 (texinfo-print-index nil indexelts)
952 (if (memq system-type '(vax-vms windows-nt ms-dos))
953 (texinfo-sort-region opoint (point))
954 (shell-command-on-region opoint (point) "sort -fd" 1))))
958 ;;; ptexinfmt.el ends here