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
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))
108 (function (lambda ,@args)))))))
110 (put 'ptexinfmt-defvar-if-void 'lisp-indent-function 'defun)
111 (defmacro ptexinfmt-defvar-if-void (&rest args)
112 "Define a variable just like `defvar' unless it is already defined."
113 (let ((name (car args)))
114 (setq args (cdr args))
119 (defvar ,name ,@args)))))
122 (ptexinfmt-broken-facility texinfo-format-printindex
123 "Can't sort on Mule for Windows."
127 (ptexinfmt-broken-facility texinfo-format-var
128 "Don't perse @var argument."
131 (let (texinfo-enclosure-list texinfo-alias-list)
133 (insert "@var{@asis{foo}}\n")
134 (texinfo-format-expand-region (point-min) (point-max))
139 (ptexinfmt-broken-facility texinfo-format-xref
140 "Can't format @xref, 1st argument is empty."
143 (let (texinfo-enclosure-list texinfo-alias-list)
145 (insert "@xref{, xref, , file}\n")
146 (texinfo-format-expand-region (point-min) (point-max))
151 (ptexinfmt-broken-facility texinfo-format-uref
152 "Parse twice @uref argument."
155 (let (texinfo-enclosure-list texinfo-alias-list)
157 (insert "@uref{mailto:foo@@noncommand.example.com}\n")
158 (texinfo-format-expand-region (point-min) (point-max))
163 (ptexinfmt-broken-facility texinfo-multitable-widths
164 "`texinfo-multitable-widths' unsupport wide-char."
165 (if (fboundp 'texinfo-multitable-widths)
167 (let ((str "
\e$BI}9-J8;z
\e(B"))
169 (insert (format " {%s}\n" str))
170 (goto-char (point-min))
171 (if (= (car (texinfo-multitable-widths)) (length str))
174 ;; function definition is void
177 (ptexinfmt-broken-facility texinfo-multitable-item
178 "`texinfo-multitable-item' unsupport wide-char."
179 (not (get 'texinfo-multitable-widths 'broken)))
182 ;;; Hardcopy and HTML (discard)
184 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
185 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
186 (put 'documentdescription 'texinfo-format 'texinfo-discard-line-with-args)
189 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
190 (put 'letterpaper 'texinfo-format 'texinfo-discard-line)
191 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
192 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
193 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
194 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
195 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
196 (put 'fonttextsize 'texinfo-format 'texinfo-discard-line-with-args)
199 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
200 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
203 (put 'setcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
204 (put 'setshortcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
205 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
206 (put 'frenchspacing 'texinfo-format 'texinfo-discard-line-with-args)
209 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
210 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
211 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
212 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
213 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
214 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
215 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
218 (put 'page 'texinfo-format 'texinfo-discard-line)
219 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
221 ;; @slanted{} (makeinfo 4.8 or later)
222 (put 'slanted 'texinfo-format 'texinfo-format-noop)
224 ;; @sansserif{} (makeinfo 4.8 or later)
225 (put 'sansserif 'texinfo-format 'texinfo-format-noop)
227 ;; @tie{} (makeinfo 4.3 or later)
228 (put 'tie 'texinfo-format 'texinfo-format-tie)
229 (ptexinfmt-defun-if-void texinfo-format-tie ()
230 (texinfo-parse-arg-discard)
236 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
237 (ptexinfmt-defun-if-void texinfo-format-dircategory ()
238 (let ((str (texinfo-parse-arg-discard)))
239 (delete-region (point)
241 (skip-chars-forward " ")
243 (insert "INFO-DIR-SECTION " str "\n")))
246 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
247 (ptexinfmt-defun-if-void texinfo-format-direntry ()
248 (texinfo-push-stack 'direntry nil)
249 (texinfo-discard-line)
250 (insert "START-INFO-DIR-ENTRY\n"))
252 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
253 (ptexinfmt-defun-if-void texinfo-end-direntry ()
254 (texinfo-discard-command)
255 (insert "END-INFO-DIR-ENTRY\n\n")
256 (texinfo-pop-stack 'direntry))
260 ;; @detailmenu ... @end detailmenu
261 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
262 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
264 ;; @smalldisplay ... @end smalldisplay
265 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
266 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
268 ;; @smallformat ... @end smallformat
269 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
270 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
272 ;; @cartouche ... @end cartouche
273 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
274 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
278 ;; @ifnottex ... @end ifnottex (makeinfo 3.11 or later)
279 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
280 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
282 ;; @ifnothtml ... @end ifnothtml (makeinfo 3.11 or later)
283 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
284 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
286 ;; @ifnotplaintext ... @end ifnotplaintext (makeinfo 4.2 or later)
287 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
288 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
290 ;; @ifnotdocbook ... @end ifnotdocbook (makeinfo 4.7 or later)
291 (put 'ifnotdocbook 'texinfo-format 'texinfo-discard-line)
292 (put 'ifnotdocbook 'texinfo-end 'texinfo-discard-command)
294 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
295 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
296 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
297 (delete-region texinfo-command-start
298 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
301 ;; @html ... @end html (makeinfo 3.11 or later)
302 (put 'html 'texinfo-format 'texinfo-format-html)
303 (ptexinfmt-defun-if-void texinfo-format-html ()
304 (delete-region texinfo-command-start
305 (progn (re-search-forward "@end html[ \t]*\n")
308 ;; @docbook ... @end docbook (makeinfo 4.7 or later)
309 (put 'docbook 'texinfo-format 'texinfo-format-docbook)
310 (ptexinfmt-defun-if-void texinfo-format-docbook ()
311 (delete-region texinfo-command-start
312 (progn (re-search-forward "@end docbook[ \t]*\n")
315 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
316 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
317 (defun texinfo-format-ifhtml ()
318 (delete-region texinfo-command-start
319 (progn (re-search-forward "@end ifhtml[ \t]*\n")
322 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
323 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
324 (ptexinfmt-defun-if-void texinfo-format-ifplaintext ()
325 (delete-region texinfo-command-start
326 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
329 ;; @ifdocbook ... @end ifdocbook (makeinfo 4.7 or later)
330 (put 'ifdocbook 'texinfo-format 'texinfo-format-ifdocbook)
331 (ptexinfmt-defun-if-void texinfo-format-ifdocbook ()
332 (delete-region texinfo-command-start
333 (progn (re-search-forward "@end ifdocbook[ \t]*\n")
338 ;; @indicateurl, @url, @env, @command,
339 (put 'env 'texinfo-format 'texinfo-format-code)
340 (put 'command 'texinfo-format 'texinfo-format-code)
342 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
343 (put 'url 'texinfo-format 'texinfo-format-uref) ; Texinfo 4.7
346 (put 'acronym 'texinfo-format 'texinfo-format-var)
348 (ptexinfmt-defun-if-broken texinfo-format-var ()
349 (let ((arg (texinfo-parse-expanded-arg)))
350 (texinfo-discard-command)
351 (insert (upcase arg))))
354 (put 'key 'texinfo-format 'texinfo-format-key)
355 (ptexinfmt-defun-if-void texinfo-format-key ()
356 (insert (texinfo-parse-arg-discard))
357 (goto-char texinfo-command-start))
359 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
360 (put 'email 'texinfo-format 'texinfo-format-email)
361 (ptexinfmt-defun-if-void texinfo-format-email ()
362 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
363 Insert < ... > around EMAIL-ADDRESS."
364 (let ((args (texinfo-format-parse-args)))
365 (texinfo-discard-command)
368 (insert (nth 1 args) " <" (nth 0 args) ">")
369 (insert "<" (nth 0 args) ">"))))
372 (put 'option 'texinfo-format 'texinfo-format-option)
373 (ptexinfmt-defun-if-void texinfo-format-option ()
374 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
375 ;; `looking-at-backward' not available in v. 18.57, 20.2
376 ;; searched-for character is a control-H
377 (if (not (search-backward "\010"
378 (save-excursion (beginning-of-line) (point))
380 (insert "`" (texinfo-parse-arg-discard) "'")
381 (insert (texinfo-parse-arg-discard)))
382 (goto-char texinfo-command-start))
384 ;; @verb{<char>TEXT<char>} (makeinfo 4.1 or later)
385 (put 'verb 'texinfo-format 'texinfo-format-verb)
386 (ptexinfmt-defun-if-void texinfo-format-verb ()
387 "Format text between non-quoted unique delimiter characters verbatim.
388 Enclose the verbatim text, including the delimiters, in braces. Print
389 text exactly as written (but not the delimiters) in a fixed-width.
391 For example, @verb\{|@|\} results in @ and
392 @verb\{+@'e?`!`+} results in @'e?`!`."
394 (let ((delimiter (buffer-substring-no-properties
395 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
396 (unless (looking-at "{")
397 (error "Not found: @verb start brace"))
398 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
399 (search-forward delimiter))
400 (delete-backward-char 1)
401 (unless (looking-at "}")
402 (error "Not found: @verb end brace"))
406 ;;; @LaTeX, @registeredsymbol{}
407 (put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX)
408 (ptexinfmt-defun-if-void texinfo-format-LaTeX ()
409 (texinfo-parse-arg-discard)
412 (put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol)
413 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
414 (texinfo-parse-arg-discard)
417 ;;; Accents and Special characters
419 (put 'euro 'texinfo-format 'texinfo-format-euro)
420 (ptexinfmt-defun-if-void texinfo-format-euro ()
421 (texinfo-parse-arg-discard)
424 ;; @pounds{} ==> # Pounds Sterling
425 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
426 (ptexinfmt-defun-if-void texinfo-format-pounds ()
427 (texinfo-parse-arg-discard)
430 ;; @ordf{} ==> a Spanish feminine
431 (put 'ordf 'texinfo-format 'texinfo-format-ordf)
432 (ptexinfmt-defun-if-void texinfo-format-ordf ()
433 (texinfo-parse-arg-discard)
436 ;; @ordm{} ==> o Spanish masculine
437 (put 'ordm 'texinfo-format 'texinfo-format-ordm)
438 (ptexinfmt-defun-if-void texinfo-format-ordm ()
439 (texinfo-parse-arg-discard)
442 ;; @OE{} ==> OE French-OE-ligature
443 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
444 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
445 (insert "OE" (texinfo-parse-arg-discard))
446 (goto-char texinfo-command-start))
449 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
450 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
451 (insert "oe" (texinfo-parse-arg-discard))
452 (goto-char texinfo-command-start))
454 ;; @AA{} ==> AA Scandinavian-A-with-circle
455 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
456 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
457 (insert "AA" (texinfo-parse-arg-discard))
458 (goto-char texinfo-command-start))
461 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
462 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
463 (insert "aa" (texinfo-parse-arg-discard))
464 (goto-char texinfo-command-start))
466 ;; @AE{} ==> AE Latin-Scandinavian-AE
467 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
468 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
469 (insert "AE" (texinfo-parse-arg-discard))
470 (goto-char texinfo-command-start))
473 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
474 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
475 (insert "ae" (texinfo-parse-arg-discard))
476 (goto-char texinfo-command-start))
478 ;; @ss{} ==> ss German-sharp-S
479 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
480 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
481 (insert "ss" (texinfo-parse-arg-discard))
482 (goto-char texinfo-command-start))
484 ;; @questiondown{} ==> ? upside-down-question-mark
485 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
486 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
487 (insert "?" (texinfo-parse-arg-discard))
488 (goto-char texinfo-command-start))
490 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
491 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
492 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
493 (insert "!" (texinfo-parse-arg-discard))
494 (goto-char texinfo-command-start))
496 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
497 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
498 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
499 (insert (texinfo-parse-arg-discard) "/L")
500 (goto-char texinfo-command-start))
502 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
503 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
504 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
505 (insert (texinfo-parse-arg-discard) "/l")
506 (goto-char texinfo-command-start))
508 ;; @O{} ==> O/ Scandinavian O-with-slash
509 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
510 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
511 (insert (texinfo-parse-arg-discard) "O/")
512 (goto-char texinfo-command-start))
514 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
515 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
516 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
517 (insert (texinfo-parse-arg-discard) "o/")
518 (goto-char texinfo-command-start))
520 ;; @,{c} ==> c, cedilla accent
521 (put '\, 'texinfo-format 'texinfo-format-cedilla-accent)
522 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
523 (insert (texinfo-parse-arg-discard) ",")
524 (goto-char texinfo-command-start))
527 ;; @dotaccent{o} ==> .o overdot-accent
528 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
529 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
530 (insert "." (texinfo-parse-arg-discard))
531 (goto-char texinfo-command-start))
533 ;; @ubaraccent{o} ==> _o underbar-accent
534 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
535 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
536 (insert "_" (texinfo-parse-arg-discard))
537 (goto-char texinfo-command-start))
539 ;; @udotaccent{o} ==> o-. underdot-accent
540 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
541 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
542 (insert (texinfo-parse-arg-discard) "-.")
543 (goto-char texinfo-command-start))
545 ;; @H{o} ==> ""o long Hungarian umlaut
546 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
547 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
548 (insert "\"\"" (texinfo-parse-arg-discard))
549 (goto-char texinfo-command-start))
551 ;; @ringaccent{o} ==> *o ring accent
552 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
553 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
554 (insert "*" (texinfo-parse-arg-discard))
555 (goto-char texinfo-command-start))
557 ;; @tieaccent{oo} ==> [oo tie after accent
558 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
559 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
560 (insert "[" (texinfo-parse-arg-discard))
561 (goto-char texinfo-command-start))
563 ;; @u{o} ==> (o breve accent
564 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
565 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
566 (insert "(" (texinfo-parse-arg-discard))
567 (goto-char texinfo-command-start))
569 ;; @v{o} ==> <o hacek accent
570 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
571 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
572 (insert "<" (texinfo-parse-arg-discard))
573 (goto-char texinfo-command-start))
575 ;; @dotless{i} ==> i dotless i and dotless j
576 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
577 (ptexinfmt-defun-if-void texinfo-format-dotless ()
578 (insert (texinfo-parse-arg-discard))
579 (goto-char texinfo-command-start))
582 (put '\. 'texinfo-format 'texinfo-format-\.)
583 (ptexinfmt-defun-if-void texinfo-format-\. ()
584 (texinfo-discard-command)
588 (put '\: 'texinfo-format 'texinfo-format-\:)
589 (ptexinfmt-defun-if-void texinfo-format-\: ()
590 (texinfo-discard-command))
593 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
594 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
595 (texinfo-discard-command))
598 (put '\/ 'texinfo-format 'texinfo-format-\/)
599 (ptexinfmt-defun-if-void texinfo-format-\/ ()
600 (texinfo-discard-command))
603 (put 'textdegree 'texinfo-format 'texinfo-format-textdegree)
604 (ptexinfmt-defun-if-void texinfo-format-textdegree ()
605 (insert "o" (texinfo-parse-arg-discard))
606 (goto-char texinfo-command-start))
611 (put 'ref 'texinfo-format 'texinfo-format-xref)
613 (ptexinfmt-defun-if-broken texinfo-format-xref ()
614 (let ((args (texinfo-format-parse-args)))
615 (texinfo-discard-command)
617 (let ((fname (or (nth 1 args) (nth 2 args))))
618 (if (null (or fname (nth 3 args)))
619 (insert (nth 0 args) "::")
620 (insert (or fname (nth 0 args)) ": ")
622 (insert "(" (nth 3 args) ")"))
623 (unless (null (nth 0 args))
624 (insert (nth 0 args)))))))
626 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
627 (put 'uref 'texinfo-format 'texinfo-format-uref)
628 (ptexinfmt-defun-if-broken texinfo-format-uref ()
629 "Format URL and optional URL-TITLE.
630 Insert ` ... ' around URL if no URL-TITLE argument;
631 otherwise, insert URL-TITLE followed by URL in parentheses."
632 (let ((args (texinfo-format-parse-args)))
633 (texinfo-discard-command)
636 (insert (nth 1 args) " (" (nth 0 args) ")")
637 (insert "`" (nth 0 args) "'"))))
640 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
641 (ptexinfmt-defun-if-void texinfo-format-inforef ()
642 (let ((args (texinfo-format-parse-args)))
643 (texinfo-discard-command)
645 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
646 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
651 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
652 ;; - Info-tagify suport @anthor-*-refill.
653 ;; - info.el support Ref in Tag table.
654 (unless (get 'anchor 'texinfo-format)
655 (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
659 ;;; New command definition
660 ;; @alias NEW=EXISTING
661 (put 'alias 'texinfo-format 'texinfo-alias)
662 (ptexinfmt-defun-if-void texinfo-alias ()
663 (let ((start (1- (point)))
665 (skip-chars-forward " ")
666 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
667 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
668 (error "Invalid alias command")
669 (setq texinfo-alias-list
672 (buffer-substring (match-beginning 1) (match-end 1))
673 (buffer-substring (match-beginning 2) (match-end 2)))
675 (texinfo-discard-command))))
679 ;; @exampleindent INDENT (makeinfo 4.0 or later)
681 ;; @paragraphindent INDENT (makeinfo 4.0 or later)
682 ;; INDENT: asis, 0, n
684 ;; @firstparagraphindent WORD (makeinfo 4.6 or later)
685 ;; WORD: none, insert
690 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
691 (put 'image 'texinfo-format 'texinfo-format-image)
692 (ptexinfmt-defun-if-void texinfo-format-image ()
693 ;; I don't know makeinfo parse FILENAME.
694 (let ((args (texinfo-format-parse-args))
696 (when (null (nth 0 args))
697 (error "Invalid image command"))
698 (texinfo-discard-command)
699 ;; makeinfo uses FILENAME.txt
700 (setq filename (format "%s.txt" (nth 0 args)))
701 (message "Reading included file: %s" filename)
702 ;; verbatim for Info output
703 (goto-char (+ (point) (cadr (insert-file-contents filename))))
704 (message "Reading included file: %s...done" filename)))
706 ;; @hyphenation command discards an argument within braces
707 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
708 (ptexinfmt-defun-if-void texinfo-discard-command-and-arg ()
709 "Discard both @-command and its argument in braces."
710 (goto-char texinfo-command-end)
712 (setq texinfo-command-end (point))
713 (delete-region texinfo-command-start texinfo-command-end))
716 ;;; @multitable ... @end multitable
717 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
718 "*Number of extra spaces between entries (columns) in @multitable.")
720 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
721 "*multitable-temporary-buffer*")
722 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
723 "texinfo-multitable-temp-")
725 ;; These commands are defined in texinfo.tex for printed output.
726 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
727 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
728 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
729 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
731 (put 'multitable 'texinfo-format 'texinfo-multitable)
733 (ptexinfmt-defun-if-void texinfo-multitable ()
734 "Produce multi-column tables."
736 ;; This function pushes information onto the `texinfo-stack'.
737 ;; A stack element consists of:
738 ;; - type-of-command, i.e., multitable
739 ;; - the information about column widths, and
740 ;; - the position of texinfo-command-start.
741 ;; e.g., ('multitable (1 2 3 4) 123)
742 ;; The command line is then deleted.
745 ;; push width information on stack
746 (texinfo-multitable-widths))
747 (texinfo-discard-line-with-args))
749 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
750 (ptexinfmt-defun-if-void texinfo-end-multitable ()
751 "Discard the @end multitable line and pop the stack of multitable."
752 (texinfo-discard-command)
753 (texinfo-pop-stack 'multitable))
755 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
756 "Return list of widths of each column in a multi-column table."
757 (let (texinfo-multitable-width-list)
759 ;; @multitable @columnfractions .25 .3 .45
762 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
763 ;; Place point before first argument
764 (skip-chars-forward " \t")
766 ;; Check for common misspelling
767 ((looking-at "@columnfraction ")
768 (error "In @multitable, @columnfractions misspelled"))
769 ;; Case 1: @columnfractions .25 .3 .45
770 ((looking-at "@columnfractions")
773 (setq texinfo-multitable-width-list
777 (* fill-column (read (get-buffer (current-buffer))))))
778 texinfo-multitable-width-list))))
780 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
782 (let ((start-of-templates (point)))
784 (skip-chars-forward " \t")
785 (let* ((start-of-template (1+ (point)))
787 ;; forward-sexp works with braces in Texinfo mode
788 (progn (forward-sexp 1) (1- (point)))))
789 (setq texinfo-multitable-width-list
791 (goto-char end-of-template)
794 (goto-char start-of-template)
796 texinfo-multitable-width-list))
797 ;; Remove carriage return from within a template, if any.
798 ;; This helps those those who want to use more than
799 ;; one line's worth of words in @multitable line.
800 (narrow-to-region start-of-template end-of-template)
801 (goto-char (point-min))
802 (while (search-forward "\n" nil t)
804 (goto-char (point-max))
811 You probably need to specify column widths for @multitable correctly")))
812 ;; Check whether columns fit on page.
813 (let ((desired-columns
815 ;; between column spaces
816 (length texinfo-multitable-width-list)
817 ;; additional between column spaces, if any
818 texinfo-extra-inter-column-width
819 ;; sum of spaces for each entry
820 (apply '+ texinfo-multitable-width-list))))
821 (if (> desired-columns fill-column)
823 Multi-column table width, %d chars, is greater than page width, %d chars."
824 desired-columns fill-column))))
825 texinfo-multitable-width-list))
827 ;; @item A1 @tab A2 @tab A3
828 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
829 "Return multitable row, as a string.
830 End of row is beginning of next @item or beginning of @end.
831 Cells within rows are separated by @tab."
832 (skip-chars-forward " \t")
833 (let* ((start (point))
835 (re-search-forward "@item\\|@end")
836 (match-beginning 0)))
837 (row (progn (goto-char end)
838 (skip-chars-backward " ")
839 ;; remove whitespace at end of argument
840 (delete-region (point) end)
841 (buffer-substring start (point)))))
842 (delete-region texinfo-command-start end)
845 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
846 (ptexinfmt-defun-if-void texinfo-multitable-item ()
847 "Format a row within a multicolumn table.
848 Cells in row are separated by @tab.
849 Widths of cells are specified by the arguments in the @multitable line.
850 All cells are made to be the same height.
851 This command is executed when texinfmt sees @item inside @multitable."
852 (let ((original-buffer (current-buffer))
853 (table-widths (reverse (car (cdr (car texinfo-stack)))))
854 (existing-fill-column fill-column)
858 (table-entry-height 0)
859 ;; unformatted row looks like: A1 @tab A2 @tab A3
860 ;; extract-row command deletes the source line in the table.
861 (unformated-row (texinfo-multitable-extract-row)))
862 ;; Use a temporary buffer
863 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
864 (delete-region (point-min) (point-max))
865 (insert unformated-row)
866 (goto-char (point-min))
867 ;; 1. Check for correct number of @tab in line.
868 (let ((tab-number 1)) ;; one @tab between two columns
869 (while (search-forward "@tab" nil t)
870 (setq tab-number (1+ tab-number)))
871 (if (/= tab-number (length table-widths))
872 (error "Wrong number of @tab's in a @multitable row")))
873 (goto-char (point-min))
874 ;; 2. Format each cell, and copy to a rectangle
875 ;; buffer looks like this: A1 @tab A2 @tab A3
876 ;; Cell #1: format up to @tab
877 ;; Cell #2: format up to @tab
878 ;; Cell #3: format up to eob
881 (setq end (save-excursion
882 (if (search-forward "@tab" nil 'move)
883 ;; Delete the @tab command, including the @-sign
886 (progn (forward-word -1) (1- (point)))))
888 ;; Set fill-column *wider* than needed to produce inter-column space
889 (setq fill-column (+ 1
890 texinfo-extra-inter-column-width
891 (nth table-column table-widths)))
892 (narrow-to-region start end)
893 ;; Remove whitespace before and after entry.
894 (skip-chars-forward " ")
895 (delete-region (point) (save-excursion (beginning-of-line) (point)))
896 (goto-char (point-max))
897 (skip-chars-backward " ")
898 (delete-region (point) (save-excursion (end-of-line) (point)))
899 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
900 ;; does not see an unterminated @multitable.
901 (let (texinfo-stack) ;; nil
902 (texinfo-format-scan))
903 (let (fill-prefix) ;; no fill prefix
904 (fill-region (point-min) (point-max)))
905 (setq table-entry-height
906 (max table-entry-height (count-lines (point-min) (point-max))))
907 ;; 3. Move point to end of bottom line, and pad that line to fill column.
908 (goto-char (point-min))
909 (forward-line (1- table-entry-height))
910 (let* ((beg (point)) ;; beginning of line
911 ;; add one more space for inter-column spacing
917 (current-column)))))) ;; end of existing line
919 (if (> needed-whitespace 0) needed-whitespace 1)
921 ;; now, put formatted cell into a rectangle
922 (set (intern (concat texinfo-multitable-rectangle-name
923 (int-to-string table-column)))
924 (extract-rectangle (point-min) (point)))
925 (delete-region (point-min) (point))
926 (goto-char (point-max))
927 (setq table-column (1+ table-column))
929 ;; 4. Add extra lines to rectangles so all are of same height
930 (let ((total-number-of-columns table-column)
933 (while (> table-column 0)
934 (let ((this-rectangle (int-to-string table-column)))
935 (while (< (length this-rectangle) table-entry-height)
936 (setq this-rectangle (append this-rectangle '("")))))
937 (setq table-column (1- table-column)))
938 ;; 5. Insert formatted rectangles in original buffer
939 (switch-to-buffer original-buffer)
940 (open-line table-entry-height)
941 (while (< column-number total-number-of-columns)
945 (concat texinfo-multitable-rectangle-name
946 (int-to-string column-number)))))
949 (setq column-number (1+ column-number))))
950 (kill-buffer texinfo-multitable-buffer-name)
951 (setq fill-column existing-fill-column)))
954 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
955 (let ((indexelts (symbol-value
956 (cdr (assoc (texinfo-parse-arg-discard)
957 texinfo-indexvar-alist))))
959 (insert "\n* Menu:\n\n")
960 (setq opoint (point))
961 (texinfo-print-index nil indexelts)
963 (if (memq system-type '(vax-vms windows-nt ms-dos))
964 (texinfo-sort-region opoint (point))
965 (shell-command-on-region opoint (point) "sort -fd" 1))))
969 ;;; ptexinfmt.el ends here