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., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, 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.
45 (defvar ptexinfmt-disable-broken-notice-flag t
46 "If non-nil disable notice, when call `ptexinfmt-broken-facility'.
47 This is last argument in `ptexinfmt-broken-facility'.")
49 (put 'ptexinfmt-broken-facility 'lisp-indent-function 'defun)
50 (defmacro ptexinfmt-broken-facility (facility docstring assertion
52 "Declare a symbol FACILITY is broken if ASSERTION is nil.
53 DOCSTRING will be printed if ASSERTION is nil and
54 `ptexinfmt-disable-broken-notice-flag' is nil."
55 (` (let ((facility '(, facility))
56 (docstring (, docstring))
57 (assertion (eval '(, assertion))))
58 (put facility 'broken (not assertion))
61 (put facility 'broken-docstring docstring)
62 (if ptexinfmt-disable-broken-notice-flag
64 (message "BROKEN FACILITY DETECTED: %s" docstring))))))
66 (put 'ptexinfmt-defun-if-broken 'lisp-indent-function 'defun)
67 (defmacro ptexinfmt-defun-if-broken (&rest args)
68 "Redefine a function just like `defun' if it is considered broken."
69 (let ((name (list 'quote (car args))))
70 (setq args (cdr args))
73 (if (get (, name) 'broken)
75 (function (lambda (,@ args)))))))))
77 (put 'ptexinfmt-defun-if-void 'lisp-indent-function 'defun)
78 (defmacro ptexinfmt-defun-if-void (&rest args)
79 "Define a function just like `defun' unless it is already defined."
80 (let ((name (list 'quote (car args))))
81 (setq args (cdr args))
84 (if (fboundp (, name))
87 (function (lambda (,@ args)))))))))
89 (put 'ptexinfmt-defvar-if-void 'lisp-indent-function 'defun)
90 (defmacro ptexinfmt-defvar-if-void (&rest args)
91 "Define a variable just like `defvar' unless it is already defined."
92 (let ((name (car args)))
93 (setq args (cdr args))
96 (if (boundp '(, name))
98 (defvar (, name) (,@ args)))))))
101 (ptexinfmt-broken-facility texinfo-format-printindex
102 "Can't sort on Mule for Windows."
106 (ptexinfmt-broken-facility texinfo-format-var
107 "Don't perse @var argument."
110 (let (texinfo-enclosure-list texinfo-alias-list)
112 (insert "@var{@asis{foo}}\n")
113 (texinfo-format-expand-region (point-min) (point-max))
118 (ptexinfmt-broken-facility texinfo-format-xref
119 "Can't format @xref, 1st argument is empty."
122 (let (texinfo-enclosure-list texinfo-alias-list)
124 (insert "@xref{, xref, , file}\n")
125 (texinfo-format-expand-region (point-min) (point-max))
130 (ptexinfmt-broken-facility texinfo-format-uref
131 "Parse twice @uref argument."
134 (let (texinfo-enclosure-list texinfo-alias-list)
136 (insert "@uref{mailto:foo@@noncommand.example.com}\n")
137 (texinfo-format-expand-region (point-min) (point-max))
142 (ptexinfmt-broken-facility texinfo-multitable-widths
143 "`texinfo-multitable-widths' unsupport wide-char."
144 (if (fboundp 'texinfo-multitable-widths)
146 (let ((str "
\e$BI}9-J8;z
\e(B"))
148 (insert (format " {%s}\n" str))
149 (goto-char (point-min))
150 (if (= (car (texinfo-multitable-widths)) (length str))
153 ;; function definition is void
156 (ptexinfmt-broken-facility texinfo-multitable-item
157 "`texinfo-multitable-item' unsupport wide-char."
158 (not (get 'texinfo-multitable-widths 'broken)))
161 ;;; Hardcopy and HTML (discard)
163 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
164 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
165 (put 'documentdescription 'texinfo-format 'texinfo-discard-line-with-args)
168 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
169 (put 'letterpaper 'texinfo-format 'texinfo-discard-line)
170 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
171 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
172 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
173 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
174 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
177 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
178 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
181 (put 'setcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
182 (put 'setshortcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
183 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
186 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
187 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
188 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
189 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
190 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
191 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
192 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
195 (put 'page 'texinfo-format 'texinfo-discard-line)
196 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
198 ;; @tie{} (makeinfo 4.3 or later)
199 (put 'tie 'texinfo-format 'texinfo-format-tie)
200 (ptexinfmt-defun-if-void texinfo-format-tie ()
201 (texinfo-parse-arg-discard)
207 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
208 (ptexinfmt-defun-if-void texinfo-format-dircategory ()
209 (let ((str (texinfo-parse-arg-discard)))
210 (delete-region (point)
212 (skip-chars-forward " ")
214 (insert "INFO-DIR-SECTION " str "\n")))
217 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
218 (ptexinfmt-defun-if-void texinfo-format-direntry ()
219 (texinfo-push-stack 'direntry nil)
220 (texinfo-discard-line)
221 (insert "START-INFO-DIR-ENTRY\n"))
223 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
224 (ptexinfmt-defun-if-void texinfo-end-direntry ()
225 (texinfo-discard-command)
226 (insert "END-INFO-DIR-ENTRY\n\n")
227 (texinfo-pop-stack 'direntry))
231 ;; @detailmenu ... @end detailmenu
232 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
233 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
235 ;; @smalldisplay ... @end smalldisplay
236 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
237 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
239 ;; @smallformat ... @end smallformat
240 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
241 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
243 ;; @cartouche ... @end cartouche
244 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
245 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
249 ;; @ifnottex ... @end ifnottex (makeinfo 3.11 or later)
250 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
251 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
253 ;; @ifnothtml ... @end ifnothtml (makeinfo 3.11 or later)
254 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
255 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
257 ;; @ifnotplaintext ... @end ifnotplaintext (makeinfo 4.2 or later)
258 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
259 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
261 ;; @ifnotdocbook ... @end ifnotdocbook (makeinfo 4.7 or later)
262 (put 'ifnotdocbook 'texinfo-format 'texinfo-discard-line)
263 (put 'ifnotdocbook 'texinfo-end 'texinfo-discard-command)
265 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
266 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
267 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
268 (delete-region texinfo-command-start
269 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
272 ;; @html ... @end html (makeinfo 3.11 or later)
273 (put 'html 'texinfo-format 'texinfo-format-html)
274 (ptexinfmt-defun-if-void texinfo-format-html ()
275 (delete-region texinfo-command-start
276 (progn (re-search-forward "@end html[ \t]*\n")
279 ;; @docbook ... @end docbook (makeinfo 4.7 or later)
280 (put 'docbook 'texinfo-format 'texinfo-format-docbook)
281 (ptexinfmt-defun-if-void texinfo-format-docbook ()
282 (delete-region texinfo-command-start
283 (progn (re-search-forward "@end docbook[ \t]*\n")
286 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
287 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
288 (defun texinfo-format-ifhtml ()
289 (delete-region texinfo-command-start
290 (progn (re-search-forward "@end ifhtml[ \t]*\n")
293 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
294 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
295 (ptexinfmt-defun-if-void texinfo-format-ifplaintext ()
296 (delete-region texinfo-command-start
297 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
300 ;; @ifdocbook ... @end ifdocbook (makeinfo 4.7 or later)
301 (put 'ifdocbook 'texinfo-format 'texinfo-format-ifdocbook)
302 (ptexinfmt-defun-if-void texinfo-format-ifdocbook ()
303 (delete-region texinfo-command-start
304 (progn (re-search-forward "@end ifdocbook[ \t]*\n")
309 ;; @indicateurl, @url, @env, @command,
310 (put 'env 'texinfo-format 'texinfo-format-code)
311 (put 'command 'texinfo-format 'texinfo-format-code)
313 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
314 (put 'url 'texinfo-format 'texinfo-format-uref) ; Texinfo 4.7
317 (put 'acronym 'texinfo-format 'texinfo-format-var)
319 (ptexinfmt-defun-if-broken texinfo-format-var ()
320 (let ((arg (texinfo-parse-expanded-arg)))
321 (texinfo-discard-command)
322 (insert (upcase arg))))
325 (put 'key 'texinfo-format 'texinfo-format-key)
326 (ptexinfmt-defun-if-void texinfo-format-key ()
327 (insert (texinfo-parse-arg-discard))
328 (goto-char texinfo-command-start))
330 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
331 (put 'email 'texinfo-format 'texinfo-format-email)
332 (ptexinfmt-defun-if-void texinfo-format-email ()
333 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
334 Insert < ... > around EMAIL-ADDRESS."
335 (let ((args (texinfo-format-parse-args)))
336 (texinfo-discard-command)
339 (insert (nth 1 args) " <" (nth 0 args) ">")
340 (insert "<" (nth 0 args) ">"))))
343 (put 'option 'texinfo-format 'texinfo-format-option)
344 (ptexinfmt-defun-if-void texinfo-format-option ()
345 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
346 ;; `looking-at-backward' not available in v. 18.57, 20.2
347 ;; searched-for character is a control-H
348 (if (not (search-backward "\010"
349 (save-excursion (beginning-of-line) (point))
351 (insert "`" (texinfo-parse-arg-discard) "'")
352 (insert (texinfo-parse-arg-discard)))
353 (goto-char texinfo-command-start))
355 ;; @verb{<char>TEXT<char>} (makeinfo 4.1 or later)
356 (put 'verb 'texinfo-format 'texinfo-format-verb)
357 (ptexinfmt-defun-if-void texinfo-format-verb ()
358 "Format text between non-quoted unique delimiter characters verbatim.
359 Enclose the verbatim text, including the delimiters, in braces. Print
360 text exactly as written (but not the delimiters) in a fixed-width.
362 For example, @verb\{|@|\} results in @ and
363 @verb\{+@'e?`!`+} results in @'e?`!`."
365 (let ((delimiter (buffer-substring-no-properties
366 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
367 (unless (looking-at "{")
368 (error "Not found: @verb start brace"))
369 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
370 (search-forward delimiter))
371 (delete-backward-char 1)
372 (unless (looking-at "}")
373 (error "Not found: @verb end brace"))
377 ;;; @LaTeX, @registeredsymbol{}
378 (put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX)
379 (ptexinfmt-defun-if-void texinfo-format-LaTeX ()
380 (texinfo-parse-arg-discard)
383 (put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol)
384 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
385 (texinfo-parse-arg-discard)
388 ;;; Accents and Special characters
389 ;; @pounds{} ==> # Pounds Sterling
390 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
391 (ptexinfmt-defun-if-void texinfo-format-pounds ()
392 (texinfo-parse-arg-discard)
395 ;; @ordf{} ==> a Spanish feminine
396 (put 'ordf 'texinfo-format 'texinfo-format-ordf)
397 (ptexinfmt-defun-if-void texinfo-format-ordf ()
398 (texinfo-parse-arg-discard)
401 ;; @ordm{} ==> o Spanish masculine
402 (put 'ordm 'texinfo-format 'texinfo-format-ordm)
403 (ptexinfmt-defun-if-void texinfo-format-ordm ()
404 (texinfo-parse-arg-discard)
407 ;; @OE{} ==> OE French-OE-ligature
408 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
409 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
410 (insert "OE" (texinfo-parse-arg-discard))
411 (goto-char texinfo-command-start))
414 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
415 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
416 (insert "oe" (texinfo-parse-arg-discard))
417 (goto-char texinfo-command-start))
419 ;; @AA{} ==> AA Scandinavian-A-with-circle
420 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
421 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
422 (insert "AA" (texinfo-parse-arg-discard))
423 (goto-char texinfo-command-start))
426 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
427 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
428 (insert "aa" (texinfo-parse-arg-discard))
429 (goto-char texinfo-command-start))
431 ;; @AE{} ==> AE Latin-Scandinavian-AE
432 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
433 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
434 (insert "AE" (texinfo-parse-arg-discard))
435 (goto-char texinfo-command-start))
438 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
439 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
440 (insert "ae" (texinfo-parse-arg-discard))
441 (goto-char texinfo-command-start))
443 ;; @ss{} ==> ss German-sharp-S
444 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
445 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
446 (insert "ss" (texinfo-parse-arg-discard))
447 (goto-char texinfo-command-start))
449 ;; @questiondown{} ==> ? upside-down-question-mark
450 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
451 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
452 (insert "?" (texinfo-parse-arg-discard))
453 (goto-char texinfo-command-start))
455 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
456 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
457 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
458 (insert "!" (texinfo-parse-arg-discard))
459 (goto-char texinfo-command-start))
461 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
462 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
463 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
464 (insert (texinfo-parse-arg-discard) "/L")
465 (goto-char texinfo-command-start))
467 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
468 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
469 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
470 (insert (texinfo-parse-arg-discard) "/l")
471 (goto-char texinfo-command-start))
473 ;; @O{} ==> O/ Scandinavian O-with-slash
474 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
475 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
476 (insert (texinfo-parse-arg-discard) "O/")
477 (goto-char texinfo-command-start))
479 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
480 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
481 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
482 (insert (texinfo-parse-arg-discard) "o/")
483 (goto-char texinfo-command-start))
485 ;; @,{c} ==> c, cedilla accent
486 (put ', 'texinfo-format 'texinfo-format-cedilla-accent)
487 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
488 (insert (texinfo-parse-arg-discard) ",")
489 (goto-char texinfo-command-start))
492 ;; @dotaccent{o} ==> .o overdot-accent
493 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
494 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
495 (insert "." (texinfo-parse-arg-discard))
496 (goto-char texinfo-command-start))
498 ;; @ubaraccent{o} ==> _o underbar-accent
499 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
500 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
501 (insert "_" (texinfo-parse-arg-discard))
502 (goto-char texinfo-command-start))
504 ;; @udotaccent{o} ==> o-. underdot-accent
505 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
506 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
507 (insert (texinfo-parse-arg-discard) "-.")
508 (goto-char texinfo-command-start))
510 ;; @H{o} ==> ""o long Hungarian umlaut
511 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
512 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
513 (insert "\"\"" (texinfo-parse-arg-discard))
514 (goto-char texinfo-command-start))
516 ;; @ringaccent{o} ==> *o ring accent
517 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
518 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
519 (insert "*" (texinfo-parse-arg-discard))
520 (goto-char texinfo-command-start))
522 ;; @tieaccent{oo} ==> [oo tie after accent
523 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
524 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
525 (insert "[" (texinfo-parse-arg-discard))
526 (goto-char texinfo-command-start))
528 ;; @u{o} ==> (o breve accent
529 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
530 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
531 (insert "(" (texinfo-parse-arg-discard))
532 (goto-char texinfo-command-start))
534 ;; @v{o} ==> <o hacek accent
535 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
536 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
537 (insert "<" (texinfo-parse-arg-discard))
538 (goto-char texinfo-command-start))
540 ;; @dotless{i} ==> i dotless i and dotless j
541 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
542 (ptexinfmt-defun-if-void texinfo-format-dotless ()
543 (insert (texinfo-parse-arg-discard))
544 (goto-char texinfo-command-start))
547 (put '\. 'texinfo-format 'texinfo-format-\.)
548 (ptexinfmt-defun-if-void texinfo-format-\. ()
549 (texinfo-discard-command)
553 (put '\: 'texinfo-format 'texinfo-format-\:)
554 (ptexinfmt-defun-if-void texinfo-format-\: ()
555 (texinfo-discard-command))
558 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
559 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
560 (texinfo-discard-command))
563 (put '\/ 'texinfo-format 'texinfo-format-\/)
564 (ptexinfmt-defun-if-void texinfo-format-\/ ()
565 (texinfo-discard-command))
570 (put 'ref 'texinfo-format 'texinfo-format-xref)
572 (ptexinfmt-defun-if-broken texinfo-format-xref ()
573 (let ((args (texinfo-format-parse-args)))
574 (texinfo-discard-command)
576 (let ((fname (or (nth 1 args) (nth 2 args))))
577 (if (null (or fname (nth 3 args)))
578 (insert (nth 0 args) "::")
579 (insert (or fname (nth 0 args)) ": ")
581 (insert "(" (nth 3 args) ")"))
582 (unless (null (nth 0 args))
583 (insert (nth 0 args)))))))
585 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
586 (put 'uref 'texinfo-format 'texinfo-format-uref)
587 (ptexinfmt-defun-if-broken texinfo-format-uref ()
588 "Format URL and optional URL-TITLE.
589 Insert ` ... ' around URL if no URL-TITLE argument;
590 otherwise, insert URL-TITLE followed by URL in parentheses."
591 (let ((args (texinfo-format-parse-args)))
592 (texinfo-discard-command)
595 (insert (nth 1 args) " (" (nth 0 args) ")")
596 (insert "`" (nth 0 args) "'"))))
599 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
600 (ptexinfmt-defun-if-void texinfo-format-inforef ()
601 (let ((args (texinfo-format-parse-args)))
602 (texinfo-discard-command)
604 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
605 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
610 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
611 ;; - Info-tagify suport @anthor-*-refill.
612 ;; - info.el support Ref in Tag table.
613 (unless (get 'anchor 'texinfo-format)
614 (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
618 ;;; New command definition
619 ;; @alias NEW=EXISTING
620 (put 'alias 'texinfo-format 'texinfo-alias)
621 (ptexinfmt-defun-if-void texinfo-alias ()
622 (let ((start (1- (point)))
624 (skip-chars-forward " ")
625 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
626 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
627 (error "Invalid alias command")
628 (setq texinfo-alias-list
631 (buffer-substring (match-beginning 1) (match-end 1))
632 (buffer-substring (match-beginning 2) (match-end 2)))
634 (texinfo-discard-command))))
638 ;; @exampleindent INDENT (makeinfo 4.0 or later)
640 ;; @paragraphindent INDENT (makeinfo 4.0 or later)
641 ;; INDENT: asis, 0, n
643 ;; @firstparagraphindent WORD (makeinfo 4.6 or later)
644 ;; WORD: none, insert
649 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
650 (put 'image 'texinfo-format 'texinfo-format-image)
651 (ptexinfmt-defun-if-void texinfo-format-image ()
652 ;; I don't know makeinfo parse FILENAME.
653 (let ((args (texinfo-format-parse-args))
655 (when (null (nth 0 args))
656 (error "Invalid image command"))
657 (texinfo-discard-command)
658 ;; makeinfo uses FILENAME.txt
659 (setq filename (format "%s.txt" (nth 0 args)))
660 (message "Reading included file: %s" filename)
661 ;; verbatim for Info output
662 (goto-char (+ (point) (cadr (insert-file-contents filename))))
663 (message "Reading included file: %s...done" filename)))
665 ;; @hyphenation command discards an argument within braces
666 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
667 (ptexinfmt-defun-if-void texinfo-discard-command-and-arg ()
668 "Discard both @-command and its argument in braces."
669 (goto-char texinfo-command-end)
671 (setq texinfo-command-end (point))
672 (delete-region texinfo-command-start texinfo-command-end))
675 ;;; @multitable ... @end multitable
676 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
677 "*Number of extra spaces between entries (columns) in @multitable.")
679 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
680 "*multitable-temporary-buffer*")
681 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
682 "texinfo-multitable-temp-")
684 ;; These commands are defined in texinfo.tex for printed output.
685 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
686 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
687 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
688 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
690 (put 'multitable 'texinfo-format 'texinfo-multitable)
692 (ptexinfmt-defun-if-void texinfo-multitable ()
693 "Produce multi-column tables."
695 ;; This function pushes information onto the `texinfo-stack'.
696 ;; A stack element consists of:
697 ;; - type-of-command, i.e., multitable
698 ;; - the information about column widths, and
699 ;; - the position of texinfo-command-start.
700 ;; e.g., ('multitable (1 2 3 4) 123)
701 ;; The command line is then deleted.
704 ;; push width information on stack
705 (texinfo-multitable-widths))
706 (texinfo-discard-line-with-args))
708 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
709 (ptexinfmt-defun-if-void texinfo-end-multitable ()
710 "Discard the @end multitable line and pop the stack of multitable."
711 (texinfo-discard-command)
712 (texinfo-pop-stack 'multitable))
714 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
715 "Return list of widths of each column in a multi-column table."
716 (let (texinfo-multitable-width-list)
718 ;; @multitable @columnfractions .25 .3 .45
721 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
722 ;; Place point before first argument
723 (skip-chars-forward " \t")
725 ;; Check for common misspelling
726 ((looking-at "@columnfraction ")
727 (error "In @multitable, @columnfractions misspelled"))
728 ;; Case 1: @columnfractions .25 .3 .45
729 ((looking-at "@columnfractions")
732 (setq texinfo-multitable-width-list
736 (* fill-column (read (get-buffer (current-buffer))))))
737 texinfo-multitable-width-list))))
739 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
741 (let ((start-of-templates (point)))
743 (skip-chars-forward " \t")
744 (let* ((start-of-template (1+ (point)))
746 ;; forward-sexp works with braces in Texinfo mode
747 (progn (forward-sexp 1) (1- (point)))))
748 (setq texinfo-multitable-width-list
750 (goto-char end-of-template)
753 (goto-char start-of-template)
755 texinfo-multitable-width-list))
756 ;; Remove carriage return from within a template, if any.
757 ;; This helps those those who want to use more than
758 ;; one line's worth of words in @multitable line.
759 (narrow-to-region start-of-template end-of-template)
760 (goto-char (point-min))
761 (while (search-forward "\n" nil t)
763 (goto-char (point-max))
770 You probably need to specify column widths for @multitable correctly")))
771 ;; Check whether columns fit on page.
772 (let ((desired-columns
774 ;; between column spaces
775 (length texinfo-multitable-width-list)
776 ;; additional between column spaces, if any
777 texinfo-extra-inter-column-width
778 ;; sum of spaces for each entry
779 (apply '+ texinfo-multitable-width-list))))
780 (if (> desired-columns fill-column)
782 Multi-column table width, %d chars, is greater than page width, %d chars."
783 desired-columns fill-column))))
784 texinfo-multitable-width-list))
786 ;; @item A1 @tab A2 @tab A3
787 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
788 "Return multitable row, as a string.
789 End of row is beginning of next @item or beginning of @end.
790 Cells within rows are separated by @tab."
791 (skip-chars-forward " \t")
792 (let* ((start (point))
794 (re-search-forward "@item\\|@end")
795 (match-beginning 0)))
796 (row (progn (goto-char end)
797 (skip-chars-backward " ")
798 ;; remove whitespace at end of argument
799 (delete-region (point) end)
800 (buffer-substring start (point)))))
801 (delete-region texinfo-command-start end)
804 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
805 (ptexinfmt-defun-if-void texinfo-multitable-item ()
806 "Format a row within a multicolumn table.
807 Cells in row are separated by @tab.
808 Widths of cells are specified by the arguments in the @multitable line.
809 All cells are made to be the same height.
810 This command is executed when texinfmt sees @item inside @multitable."
811 (let ((original-buffer (current-buffer))
812 (table-widths (reverse (car (cdr (car texinfo-stack)))))
813 (existing-fill-column fill-column)
817 (table-entry-height 0)
818 ;; unformatted row looks like: A1 @tab A2 @tab A3
819 ;; extract-row command deletes the source line in the table.
820 (unformated-row (texinfo-multitable-extract-row)))
821 ;; Use a temporary buffer
822 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
823 (delete-region (point-min) (point-max))
824 (insert unformated-row)
825 (goto-char (point-min))
826 ;; 1. Check for correct number of @tab in line.
827 (let ((tab-number 1)) ;; one @tab between two columns
828 (while (search-forward "@tab" nil t)
829 (setq tab-number (1+ tab-number)))
830 (if (/= tab-number (length table-widths))
831 (error "Wrong number of @tab's in a @multitable row")))
832 (goto-char (point-min))
833 ;; 2. Format each cell, and copy to a rectangle
834 ;; buffer looks like this: A1 @tab A2 @tab A3
835 ;; Cell #1: format up to @tab
836 ;; Cell #2: format up to @tab
837 ;; Cell #3: format up to eob
840 (setq end (save-excursion
841 (if (search-forward "@tab" nil 'move)
842 ;; Delete the @tab command, including the @-sign
845 (progn (forward-word -1) (1- (point)))))
847 ;; Set fill-column *wider* than needed to produce inter-column space
848 (setq fill-column (+ 1
849 texinfo-extra-inter-column-width
850 (nth table-column table-widths)))
851 (narrow-to-region start end)
852 ;; Remove whitespace before and after entry.
853 (skip-chars-forward " ")
854 (delete-region (point) (save-excursion (beginning-of-line) (point)))
855 (goto-char (point-max))
856 (skip-chars-backward " ")
857 (delete-region (point) (save-excursion (end-of-line) (point)))
858 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
859 ;; does not see an unterminated @multitable.
860 (let (texinfo-stack) ;; nil
861 (texinfo-format-scan))
862 (let (fill-prefix) ;; no fill prefix
863 (fill-region (point-min) (point-max)))
864 (setq table-entry-height
865 (max table-entry-height (count-lines (point-min) (point-max))))
866 ;; 3. Move point to end of bottom line, and pad that line to fill column.
867 (goto-char (point-min))
868 (forward-line (1- table-entry-height))
869 (let* ((beg (point)) ;; beginning of line
870 ;; add one more space for inter-column spacing
876 (current-column)))))) ;; end of existing line
878 (if (> needed-whitespace 0) needed-whitespace 1)
880 ;; now, put formatted cell into a rectangle
881 (set (intern (concat texinfo-multitable-rectangle-name
882 (int-to-string table-column)))
883 (extract-rectangle (point-min) (point)))
884 (delete-region (point-min) (point))
885 (goto-char (point-max))
886 (setq table-column (1+ table-column))
888 ;; 4. Add extra lines to rectangles so all are of same height
889 (let ((total-number-of-columns table-column)
892 (while (> table-column 0)
893 (let ((this-rectangle (int-to-string table-column)))
894 (while (< (length this-rectangle) table-entry-height)
895 (setq this-rectangle (append this-rectangle '("")))))
896 (setq table-column (1- table-column)))
897 ;; 5. Insert formatted rectangles in original buffer
898 (switch-to-buffer original-buffer)
899 (open-line table-entry-height)
900 (while (< column-number total-number-of-columns)
904 (concat texinfo-multitable-rectangle-name
905 (int-to-string column-number)))))
908 (setq column-number (1+ column-number))))
909 (kill-buffer texinfo-multitable-buffer-name)
910 (setq fill-column existing-fill-column)))
913 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
914 (let ((indexelts (symbol-value
915 (cdr (assoc (texinfo-parse-arg-discard)
916 texinfo-indexvar-alist))))
918 (insert "\n* Menu:\n\n")
919 (setq opoint (point))
920 (texinfo-print-index nil indexelts)
922 (if (memq system-type '(vax-vms windows-nt ms-dos))
923 (texinfo-sort-region opoint (point))
924 (shell-command-on-region opoint (point) "sort -fd" 1))))
928 ;;; ptexinfmt.el ends here