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.
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))
105 (if (fboundp (, name))
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))
117 (if (boundp '(, name))
119 (defvar (, name) (,@ args)))))))
122 (ptexinfmt-broken-facility texinfo-format-printindex
123 "Can't sort on Mule for Windows."
124 (if (and (memq system-type '(windows-nt ms-dos))
125 ;;; I don't know version threshold.
126 ;;; (string< texinfmt-version "2.37 of 24 May 1997")
127 (boundp 'MULE) (not (featurep 'meadow))) ; Mule for Windows
132 (ptexinfmt-broken-facility texinfo-format-var
133 "Don't perse @var argument."
136 (let (texinfo-enclosure-list texinfo-alias-list)
138 (insert "@var{@asis{foo}}\n")
139 (texinfo-format-expand-region (point-min) (point-max))
144 (ptexinfmt-broken-facility texinfo-format-xref
145 "Can't format @xref, 1st argument is empty."
148 (let (texinfo-enclosure-list texinfo-alias-list)
150 (insert "@xref{, xref, , file}\n")
151 (texinfo-format-expand-region (point-min) (point-max))
156 (ptexinfmt-broken-facility texinfo-format-uref
157 "Parse twice @uref argument."
160 (let (texinfo-enclosure-list texinfo-alias-list)
162 (insert "@uref{mailto:foo@@noncommand.example.com}\n")
163 (texinfo-format-expand-region (point-min) (point-max))
168 (ptexinfmt-broken-facility texinfo-multitable-widths
169 "`texinfo-multitable-widths' unsupport wide-char."
170 (if (fboundp 'texinfo-multitable-widths)
172 (let ((str "
\e$BI}9-J8;z
\e(B"))
174 (insert (format " {%s}\n" str))
175 (goto-char (point-min))
176 (if (= (car (texinfo-multitable-widths)) (length str))
179 ;; function definition is void
182 (ptexinfmt-broken-facility texinfo-multitable-item
183 "`texinfo-multitable-item' unsupport wide-char."
184 (not (get 'texinfo-multitable-widths 'broken)))
187 ;;; Hardcopy and HTML (discard)
189 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
190 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
191 (put 'documentdescription 'texinfo-format 'texinfo-discard-line-with-args)
194 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
195 (put 'letterpaper 'texinfo-format 'texinfo-discard-line)
196 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
197 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
198 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
199 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
200 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
201 (put 'fonttextsize 'texinfo-format 'texinfo-discard-line-with-args)
204 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
205 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
208 (put 'setcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
209 (put 'setshortcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
210 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
211 (put 'frenchspacing 'texinfo-format 'texinfo-discard-line-with-args)
214 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
215 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
216 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
217 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
218 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
219 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
220 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
223 (put 'page 'texinfo-format 'texinfo-discard-line)
224 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
226 ;; @slanted{} (makeinfo 4.8 or later)
227 (put 'slanted 'texinfo-format 'texinfo-format-noop)
229 ;; @sansserif{} (makeinfo 4.8 or later)
230 (put 'sansserif 'texinfo-format 'texinfo-format-noop)
232 ;; @tie{} (makeinfo 4.3 or later)
233 (put 'tie 'texinfo-format 'texinfo-format-tie)
234 (ptexinfmt-defun-if-void texinfo-format-tie ()
235 (texinfo-parse-arg-discard)
241 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
242 (ptexinfmt-defun-if-void texinfo-format-dircategory ()
243 (let ((str (texinfo-parse-arg-discard)))
244 (delete-region (point)
246 (skip-chars-forward " ")
248 (insert "INFO-DIR-SECTION " str "\n")))
251 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
252 (ptexinfmt-defun-if-void texinfo-format-direntry ()
253 (texinfo-push-stack 'direntry nil)
254 (texinfo-discard-line)
255 (insert "START-INFO-DIR-ENTRY\n"))
257 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
258 (ptexinfmt-defun-if-void texinfo-end-direntry ()
259 (texinfo-discard-command)
260 (insert "END-INFO-DIR-ENTRY\n\n")
261 (texinfo-pop-stack 'direntry))
265 ;; @detailmenu ... @end detailmenu
266 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
267 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
269 ;; @smalldisplay ... @end smalldisplay
270 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
271 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
273 ;; @smallformat ... @end smallformat
274 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
275 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
277 ;; @cartouche ... @end cartouche
278 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
279 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
283 ;; @ifnottex ... @end ifnottex (makeinfo 3.11 or later)
284 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
285 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
287 ;; @ifnothtml ... @end ifnothtml (makeinfo 3.11 or later)
288 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
289 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
291 ;; @ifnotplaintext ... @end ifnotplaintext (makeinfo 4.2 or later)
292 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
293 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
295 ;; @ifnotdocbook ... @end ifnotdocbook (makeinfo 4.7 or later)
296 (put 'ifnotdocbook 'texinfo-format 'texinfo-discard-line)
297 (put 'ifnotdocbook 'texinfo-end 'texinfo-discard-command)
300 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
301 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
302 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
303 (delete-region texinfo-command-start
304 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
307 ;; @html ... @end html (makeinfo 3.11 or later)
308 (put 'html 'texinfo-format 'texinfo-format-html)
309 (ptexinfmt-defun-if-void texinfo-format-html ()
310 (delete-region texinfo-command-start
311 (progn (re-search-forward "@end html[ \t]*\n")
314 ;; @docbook ... @end docbook (makeinfo 4.7 or later)
315 (put 'docbook 'texinfo-format 'texinfo-format-docbook)
316 (ptexinfmt-defun-if-void texinfo-format-docbook ()
317 (delete-region texinfo-command-start
318 (progn (re-search-forward "@end docbook[ \t]*\n")
321 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
322 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
323 (defun texinfo-format-ifhtml ()
324 (delete-region texinfo-command-start
325 (progn (re-search-forward "@end ifhtml[ \t]*\n")
328 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
329 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
330 (ptexinfmt-defun-if-void texinfo-format-ifplaintext ()
331 (delete-region texinfo-command-start
332 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
335 ;; @ifdocbook ... @end ifdocbook (makeinfo 4.7 or later)
336 (put 'ifdocbook 'texinfo-format 'texinfo-format-ifdocbook)
337 (ptexinfmt-defun-if-void texinfo-format-ifdocbook ()
338 (delete-region texinfo-command-start
339 (progn (re-search-forward "@end ifdocbook[ \t]*\n")
345 ;; @indicateurl, @url, @env, @command,
346 (put 'env 'texinfo-format 'texinfo-format-code)
347 (put 'command 'texinfo-format 'texinfo-format-code)
349 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
350 (put 'url 'texinfo-format 'texinfo-format-uref) ; Texinfo 4.7
353 (put 'acronym 'texinfo-format 'texinfo-format-var)
355 (ptexinfmt-defun-if-broken texinfo-format-var ()
356 (let ((arg (texinfo-parse-expanded-arg)))
357 (texinfo-discard-command)
358 (insert (upcase arg))))
361 (put 'key 'texinfo-format 'texinfo-format-key)
362 (ptexinfmt-defun-if-void texinfo-format-key ()
363 (insert (texinfo-parse-arg-discard))
364 (goto-char texinfo-command-start))
366 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
367 (put 'email 'texinfo-format 'texinfo-format-email)
368 (ptexinfmt-defun-if-void texinfo-format-email ()
369 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
370 Insert < ... > around EMAIL-ADDRESS."
371 (let ((args (texinfo-format-parse-args)))
372 (texinfo-discard-command)
375 (insert (nth 1 args) " <" (nth 0 args) ">")
376 (insert "<" (nth 0 args) ">"))))
379 (put 'option 'texinfo-format 'texinfo-format-option)
380 (ptexinfmt-defun-if-void texinfo-format-option ()
381 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
382 ;; `looking-at-backward' not available in v. 18.57, 20.2
383 ;; searched-for character is a control-H
384 (if (not (search-backward "\010"
385 (save-excursion (beginning-of-line) (point))
387 (insert "`" (texinfo-parse-arg-discard) "'")
388 (insert (texinfo-parse-arg-discard)))
389 (goto-char texinfo-command-start))
391 ;; @verb{<char>TEXT<char>} (makeinfo 4.1 or later)
392 (put 'verb 'texinfo-format 'texinfo-format-verb)
393 (ptexinfmt-defun-if-void texinfo-format-verb ()
394 "Format text between non-quoted unique delimiter characters verbatim.
395 Enclose the verbatim text, including the delimiters, in braces. Print
396 text exactly as written (but not the delimiters) in a fixed-width.
398 For example, @verb\{|@|\} results in @ and
399 @verb\{+@'e?`!`+} results in @'e?`!`."
401 (let ((delimiter (buffer-substring-no-properties
402 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
403 (unless (looking-at "{")
404 (error "Not found: @verb start brace"))
405 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
406 (search-forward delimiter))
407 (delete-backward-char 1)
408 (unless (looking-at "}")
409 (error "Not found: @verb end brace"))
413 ;;; @LaTeX, @registeredsymbol{}
414 (put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX)
415 (ptexinfmt-defun-if-void texinfo-format-LaTeX ()
416 (texinfo-parse-arg-discard)
419 (put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol)
420 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
421 (texinfo-parse-arg-discard)
424 ;;; Accents and Special characters
426 (put 'euro 'texinfo-format 'texinfo-format-euro)
427 (ptexinfmt-defun-if-void texinfo-format-euro ()
428 (texinfo-parse-arg-discard)
431 ;; @pounds{} ==> # Pounds Sterling
432 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
433 (ptexinfmt-defun-if-void texinfo-format-pounds ()
434 (texinfo-parse-arg-discard)
437 ;; @ordf{} ==> a Spanish feminine
438 (put 'ordf 'texinfo-format 'texinfo-format-ordf)
439 (ptexinfmt-defun-if-void texinfo-format-ordf ()
440 (texinfo-parse-arg-discard)
443 ;; @ordm{} ==> o Spanish masculine
444 (put 'ordm 'texinfo-format 'texinfo-format-ordm)
445 (ptexinfmt-defun-if-void texinfo-format-ordm ()
446 (texinfo-parse-arg-discard)
449 ;; @OE{} ==> OE French-OE-ligature
450 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
451 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
452 (insert "OE" (texinfo-parse-arg-discard))
453 (goto-char texinfo-command-start))
456 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
457 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
458 (insert "oe" (texinfo-parse-arg-discard))
459 (goto-char texinfo-command-start))
461 ;; @AA{} ==> AA Scandinavian-A-with-circle
462 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
463 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
464 (insert "AA" (texinfo-parse-arg-discard))
465 (goto-char texinfo-command-start))
468 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
469 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
470 (insert "aa" (texinfo-parse-arg-discard))
471 (goto-char texinfo-command-start))
473 ;; @AE{} ==> AE Latin-Scandinavian-AE
474 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
475 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
476 (insert "AE" (texinfo-parse-arg-discard))
477 (goto-char texinfo-command-start))
480 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
481 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
482 (insert "ae" (texinfo-parse-arg-discard))
483 (goto-char texinfo-command-start))
485 ;; @ss{} ==> ss German-sharp-S
486 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
487 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
488 (insert "ss" (texinfo-parse-arg-discard))
489 (goto-char texinfo-command-start))
491 ;; @questiondown{} ==> ? upside-down-question-mark
492 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
493 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
494 (insert "?" (texinfo-parse-arg-discard))
495 (goto-char texinfo-command-start))
497 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
498 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
499 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
500 (insert "!" (texinfo-parse-arg-discard))
501 (goto-char texinfo-command-start))
503 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
504 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
505 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
506 (insert (texinfo-parse-arg-discard) "/L")
507 (goto-char texinfo-command-start))
509 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
510 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
511 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
512 (insert (texinfo-parse-arg-discard) "/l")
513 (goto-char texinfo-command-start))
515 ;; @O{} ==> O/ Scandinavian O-with-slash
516 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
517 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
518 (insert (texinfo-parse-arg-discard) "O/")
519 (goto-char texinfo-command-start))
521 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
522 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
523 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
524 (insert (texinfo-parse-arg-discard) "o/")
525 (goto-char texinfo-command-start))
527 ;; @,{c} ==> c, cedilla accent
528 (put ', 'texinfo-format 'texinfo-format-cedilla-accent)
529 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
530 (insert (texinfo-parse-arg-discard) ",")
531 (goto-char texinfo-command-start))
534 ;; @dotaccent{o} ==> .o overdot-accent
535 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
536 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
537 (insert "." (texinfo-parse-arg-discard))
538 (goto-char texinfo-command-start))
540 ;; @ubaraccent{o} ==> _o underbar-accent
541 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
542 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
543 (insert "_" (texinfo-parse-arg-discard))
544 (goto-char texinfo-command-start))
546 ;; @udotaccent{o} ==> o-. underdot-accent
547 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
548 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
549 (insert (texinfo-parse-arg-discard) "-.")
550 (goto-char texinfo-command-start))
552 ;; @H{o} ==> ""o long Hungarian umlaut
553 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
554 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
555 (insert "\"\"" (texinfo-parse-arg-discard))
556 (goto-char texinfo-command-start))
558 ;; @ringaccent{o} ==> *o ring accent
559 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
560 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
561 (insert "*" (texinfo-parse-arg-discard))
562 (goto-char texinfo-command-start))
564 ;; @tieaccent{oo} ==> [oo tie after accent
565 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
566 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
567 (insert "[" (texinfo-parse-arg-discard))
568 (goto-char texinfo-command-start))
570 ;; @u{o} ==> (o breve accent
571 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
572 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
573 (insert "(" (texinfo-parse-arg-discard))
574 (goto-char texinfo-command-start))
576 ;; @v{o} ==> <o hacek accent
577 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
578 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
579 (insert "<" (texinfo-parse-arg-discard))
580 (goto-char texinfo-command-start))
582 ;; @dotless{i} ==> i dotless i and dotless j
583 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
584 (ptexinfmt-defun-if-void texinfo-format-dotless ()
585 (insert (texinfo-parse-arg-discard))
586 (goto-char texinfo-command-start))
589 (put '\. 'texinfo-format 'texinfo-format-\.)
590 (ptexinfmt-defun-if-void texinfo-format-\. ()
591 (texinfo-discard-command)
595 (put '\: 'texinfo-format 'texinfo-format-\:)
596 (ptexinfmt-defun-if-void texinfo-format-\: ()
597 (texinfo-discard-command))
600 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
601 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
602 (texinfo-discard-command))
605 (put '\/ 'texinfo-format 'texinfo-format-\/)
606 (ptexinfmt-defun-if-void texinfo-format-\/ ()
607 (texinfo-discard-command))
610 (put 'textdegree 'texinfo-format 'texinfo-format-textdegree)
611 (ptexinfmt-defun-if-void texinfo-format-textdegree ()
612 (insert "o" (texinfo-parse-arg-discard))
613 (goto-char texinfo-command-start))
618 (put 'ref 'texinfo-format 'texinfo-format-xref)
620 (ptexinfmt-defun-if-broken texinfo-format-xref ()
621 (let ((args (texinfo-format-parse-args)))
622 (texinfo-discard-command)
624 (let ((fname (or (nth 1 args) (nth 2 args))))
625 (if (null (or fname (nth 3 args)))
626 (insert (nth 0 args) "::")
627 (insert (or fname (nth 0 args)) ": ")
629 (insert "(" (nth 3 args) ")"))
630 (unless (null (nth 0 args))
631 (insert (nth 0 args)))))))
633 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
634 (put 'uref 'texinfo-format 'texinfo-format-uref)
635 (ptexinfmt-defun-if-broken texinfo-format-uref ()
636 "Format URL and optional URL-TITLE.
637 Insert ` ... ' around URL if no URL-TITLE argument;
638 otherwise, insert URL-TITLE followed by URL in parentheses."
639 (let ((args (texinfo-format-parse-args)))
640 (texinfo-discard-command)
643 (insert (nth 1 args) " (" (nth 0 args) ")")
644 (insert "`" (nth 0 args) "'"))))
647 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
648 (ptexinfmt-defun-if-void texinfo-format-inforef ()
649 (let ((args (texinfo-format-parse-args)))
650 (texinfo-discard-command)
652 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
653 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
658 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
659 ;; - Info-tagify suport @anthor-*-refill.
660 ;; - info.el support Ref in Tag table.
661 (unless (get 'anchor 'texinfo-format)
662 (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
666 ;;; New command definition
667 ;; @alias NEW=EXISTING
668 (put 'alias 'texinfo-format 'texinfo-alias)
669 (ptexinfmt-defun-if-void texinfo-alias ()
670 (let ((start (1- (point)))
672 (skip-chars-forward " ")
673 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
674 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
675 (error "Invalid alias command")
676 (setq texinfo-alias-list
679 (buffer-substring (match-beginning 1) (match-end 1))
680 (buffer-substring (match-beginning 2) (match-end 2)))
682 (texinfo-discard-command))))
686 ;; @exampleindent INDENT (makeinfo 4.0 or later)
688 ;; @paragraphindent INDENT (makeinfo 4.0 or later)
689 ;; INDENT: asis, 0, n
691 ;; @firstparagraphindent WORD (makeinfo 4.6 or later)
692 ;; WORD: none, insert
697 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
698 (put 'image 'texinfo-format 'texinfo-format-image)
699 (ptexinfmt-defun-if-void texinfo-format-image ()
700 ;; I don't know makeinfo parse FILENAME.
701 (let ((args (texinfo-format-parse-args))
703 (when (null (nth 0 args))
704 (error "Invalid image command"))
705 (texinfo-discard-command)
706 ;; makeinfo uses FILENAME.txt
707 (setq filename (format "%s.txt" (nth 0 args)))
708 (message "Reading included file: %s" filename)
709 ;; verbatim for Info output
710 (goto-char (+ (point) (cadr (insert-file-contents filename))))
711 (message "Reading included file: %s...done" filename)))
715 ;;; @multitable ... @end multitable
716 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
717 "*Number of extra spaces between entries (columns) in @multitable.")
719 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
720 "*multitable-temporary-buffer*")
721 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
722 "texinfo-multitable-temp-")
724 ;; These commands are defined in texinfo.tex for printed output.
725 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
726 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
727 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
728 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
730 (put 'multitable 'texinfo-format 'texinfo-multitable)
732 (ptexinfmt-defun-if-void texinfo-multitable ()
733 "Produce multi-column tables."
735 ;; This function pushes information onto the `texinfo-stack'.
736 ;; A stack element consists of:
737 ;; - type-of-command, i.e., multitable
738 ;; - the information about column widths, and
739 ;; - the position of texinfo-command-start.
740 ;; e.g., ('multitable (1 2 3 4) 123)
741 ;; The command line is then deleted.
744 ;; push width information on stack
745 (texinfo-multitable-widths))
746 (texinfo-discard-line-with-args))
748 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
749 (ptexinfmt-defun-if-void texinfo-end-multitable ()
750 "Discard the @end multitable line and pop the stack of multitable."
751 (texinfo-discard-command)
752 (texinfo-pop-stack 'multitable))
754 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
755 "Return list of widths of each column in a multi-column table."
756 (let (texinfo-multitable-width-list)
758 ;; @multitable @columnfractions .25 .3 .45
761 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
762 ;; Place point before first argument
763 (skip-chars-forward " \t")
765 ;; Check for common misspelling
766 ((looking-at "@columnfraction ")
767 (error "In @multitable, @columnfractions misspelled"))
768 ;; Case 1: @columnfractions .25 .3 .45
769 ((looking-at "@columnfractions")
772 (setq texinfo-multitable-width-list
776 (* fill-column (read (get-buffer (current-buffer))))))
777 texinfo-multitable-width-list))))
779 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
781 (let ((start-of-templates (point)))
783 (skip-chars-forward " \t")
784 (let* ((start-of-template (1+ (point)))
786 ;; forward-sexp works with braces in Texinfo mode
787 (progn (forward-sexp 1) (1- (point)))))
788 (setq texinfo-multitable-width-list
790 (goto-char end-of-template)
793 (goto-char start-of-template)
795 texinfo-multitable-width-list))
796 ;; Remove carriage return from within a template, if any.
797 ;; This helps those those who want to use more than
798 ;; one line's worth of words in @multitable line.
799 (narrow-to-region start-of-template end-of-template)
800 (goto-char (point-min))
801 (while (search-forward "\n" nil t)
803 (goto-char (point-max))
810 You probably need to specify column widths for @multitable correctly")))
811 ;; Check whether columns fit on page.
812 (let ((desired-columns
814 ;; between column spaces
815 (length texinfo-multitable-width-list)
816 ;; additional between column spaces, if any
817 texinfo-extra-inter-column-width
818 ;; sum of spaces for each entry
819 (apply '+ texinfo-multitable-width-list))))
820 (if (> desired-columns fill-column)
822 Multi-column table width, %d chars, is greater than page width, %d chars."
823 desired-columns fill-column))))
824 texinfo-multitable-width-list))
826 ;; @item A1 @tab A2 @tab A3
827 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
828 "Return multitable row, as a string.
829 End of row is beginning of next @item or beginning of @end.
830 Cells within rows are separated by @tab."
831 (skip-chars-forward " \t")
832 (let* ((start (point))
834 (re-search-forward "@item\\|@end")
835 (match-beginning 0)))
836 (row (progn (goto-char end)
837 (skip-chars-backward " ")
838 ;; remove whitespace at end of argument
839 (delete-region (point) end)
840 (buffer-substring start (point)))))
841 (delete-region texinfo-command-start end)
844 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
845 (ptexinfmt-defun-if-void texinfo-multitable-item ()
846 "Format a row within a multicolumn table.
847 Cells in row are separated by @tab.
848 Widths of cells are specified by the arguments in the @multitable line.
849 All cells are made to be the same height.
850 This command is executed when texinfmt sees @item inside @multitable."
851 (let ((original-buffer (current-buffer))
852 (table-widths (reverse (car (cdr (car texinfo-stack)))))
853 (existing-fill-column fill-column)
857 (table-entry-height 0)
858 ;; unformatted row looks like: A1 @tab A2 @tab A3
859 ;; extract-row command deletes the source line in the table.
860 (unformated-row (texinfo-multitable-extract-row)))
861 ;; Use a temporary buffer
862 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
863 (delete-region (point-min) (point-max))
864 (insert unformated-row)
865 (goto-char (point-min))
866 ;; 1. Check for correct number of @tab in line.
867 (let ((tab-number 1)) ;; one @tab between two columns
868 (while (search-forward "@tab" nil t)
869 (setq tab-number (1+ tab-number)))
870 (if (/= tab-number (length table-widths))
871 (error "Wrong number of @tab's in a @multitable row")))
872 (goto-char (point-min))
873 ;; 2. Format each cell, and copy to a rectangle
874 ;; buffer looks like this: A1 @tab A2 @tab A3
875 ;; Cell #1: format up to @tab
876 ;; Cell #2: format up to @tab
877 ;; Cell #3: format up to eob
880 (setq end (save-excursion
881 (if (search-forward "@tab" nil 'move)
882 ;; Delete the @tab command, including the @-sign
885 (progn (forward-word -1) (1- (point)))))
887 ;; Set fill-column *wider* than needed to produce inter-column space
888 (setq fill-column (+ 1
889 texinfo-extra-inter-column-width
890 (nth table-column table-widths)))
891 (narrow-to-region start end)
892 ;; Remove whitespace before and after entry.
893 (skip-chars-forward " ")
894 (delete-region (point) (save-excursion (beginning-of-line) (point)))
895 (goto-char (point-max))
896 (skip-chars-backward " ")
897 (delete-region (point) (save-excursion (end-of-line) (point)))
898 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
899 ;; does not see an unterminated @multitable.
900 (let (texinfo-stack) ;; nil
901 (texinfo-format-scan))
902 (let (fill-prefix) ;; no fill prefix
903 (fill-region (point-min) (point-max)))
904 (setq table-entry-height
905 (max table-entry-height (count-lines (point-min) (point-max))))
906 ;; 3. Move point to end of bottom line, and pad that line to fill column.
907 (goto-char (point-min))
908 (forward-line (1- table-entry-height))
909 (let* ((beg (point)) ;; beginning of line
910 ;; add one more space for inter-column spacing
916 (current-column)))))) ;; end of existing line
918 (if (> needed-whitespace 0) needed-whitespace 1)
920 ;; now, put formatted cell into a rectangle
921 (set (intern (concat texinfo-multitable-rectangle-name
922 (int-to-string table-column)))
923 (extract-rectangle (point-min) (point)))
924 (delete-region (point-min) (point))
925 (goto-char (point-max))
926 (setq table-column (1+ table-column))
928 ;; 4. Add extra lines to rectangles so all are of same height
929 (let ((total-number-of-columns table-column)
932 (while (> table-column 0)
933 (let ((this-rectangle (int-to-string table-column)))
934 (while (< (length this-rectangle) table-entry-height)
935 (setq this-rectangle (append this-rectangle '("")))))
936 (setq table-column (1- table-column)))
937 ;; 5. Insert formatted rectangles in original buffer
938 (switch-to-buffer original-buffer)
939 (open-line table-entry-height)
940 (while (< column-number total-number-of-columns)
944 (concat texinfo-multitable-rectangle-name
945 (int-to-string column-number)))))
948 (setq column-number (1+ column-number))))
949 (kill-buffer texinfo-multitable-buffer-name)
950 (setq fill-column existing-fill-column)))
953 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
954 (let ((indexelts (symbol-value
955 (cdr (assoc (texinfo-parse-arg-discard)
956 texinfo-indexvar-alist))))
958 (insert "\n* Menu:\n\n")
959 (setq opoint (point))
960 (texinfo-print-index nil indexelts)
962 (if (memq system-type '(vax-vms windows-nt ms-dos))
963 (texinfo-sort-region opoint (point))
964 (shell-command-on-region opoint (point) "sort -fd" 1))))
968 ;;; ptexinfmt.el ends here