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.
39 ;; Unimplemented command:
41 ;; @float, @caption, @shortcaption, @listoffloats
45 ;; @quotation (optional arguments)
46 ;; @acronym (optional argument)
47 ;; @dofirstparagraphindent
62 (defvar ptexinfmt-disable-broken-notice-flag t
63 "If non-nil disable notice, when call `ptexinfmt-broken-facility'.
64 This is last argument in `ptexinfmt-broken-facility'.")
66 (put 'ptexinfmt-broken-facility 'lisp-indent-function 'defun)
67 (defmacro ptexinfmt-broken-facility (facility docstring assertion
69 "Declare a symbol FACILITY is broken if ASSERTION is nil.
70 DOCSTRING will be printed if ASSERTION is nil and
71 `ptexinfmt-disable-broken-notice-flag' is nil."
72 (` (let ((facility '(, facility))
73 (docstring (, docstring))
74 (assertion (eval '(, assertion))))
75 (put facility 'broken (not assertion))
78 (put facility 'broken-docstring docstring)
79 (if ptexinfmt-disable-broken-notice-flag
81 (message "BROKEN FACILITY DETECTED: %s" docstring))))))
83 (put 'ptexinfmt-defun-if-broken 'lisp-indent-function 'defun)
84 (defmacro ptexinfmt-defun-if-broken (&rest args)
85 "Redefine a function just like `defun' if it is considered broken."
86 (let ((name (list 'quote (car args))))
87 (setq args (cdr args))
90 (if (get (, name) 'broken)
92 (function (lambda (,@ args)))))))))
94 (put 'ptexinfmt-defun-if-void 'lisp-indent-function 'defun)
95 (defmacro ptexinfmt-defun-if-void (&rest args)
96 "Define a function just like `defun' unless it is already defined."
97 (let ((name (list 'quote (car args))))
98 (setq args (cdr args))
101 (if (fboundp (, name))
104 (function (lambda (,@ args)))))))))
106 (put 'ptexinfmt-defvar-if-void 'lisp-indent-function 'defun)
107 (defmacro ptexinfmt-defvar-if-void (&rest args)
108 "Define a variable just like `defvar' unless it is already defined."
109 (let ((name (car args)))
110 (setq args (cdr args))
113 (if (boundp '(, name))
115 (defvar (, name) (,@ args)))))))
118 (ptexinfmt-broken-facility texinfo-format-printindex
119 "Can't sort on Mule for Windows."
120 (if (and (memq system-type '(windows-nt ms-dos))
121 ;;; I don't know version threshold.
122 ;;; (string< texinfmt-version "2.37 of 24 May 1997")
123 (boundp 'MULE) (not (featurep 'meadow))) ; Mule for Windows
128 (ptexinfmt-broken-facility texinfo-format-var
129 "Don't perse @var argument."
132 (let (texinfo-enclosure-list texinfo-alias-list)
134 (insert "@var{@asis{foo}}\n")
135 (texinfo-format-expand-region (point-min) (point-max))
140 (ptexinfmt-broken-facility texinfo-format-xref
141 "Can't format @xref, 1st argument is empty."
144 (let (texinfo-enclosure-list texinfo-alias-list)
146 (insert "@xref{, xref, , file}\n")
147 (texinfo-format-expand-region (point-min) (point-max))
152 (ptexinfmt-broken-facility texinfo-format-uref
153 "Parse twice @uref argument."
156 (let (texinfo-enclosure-list texinfo-alias-list)
158 (insert "@uref{mailto:foo@@noncommand.example.com}\n")
159 (texinfo-format-expand-region (point-min) (point-max))
164 (ptexinfmt-broken-facility texinfo-multitable-widths
165 "`texinfo-multitable-widths' unsupport wide-char."
166 (if (fboundp 'texinfo-multitable-widths)
168 (let ((str "
\e$BI}9-J8;z
\e(B"))
170 (insert (format " {%s}\n" str))
171 (goto-char (point-min))
172 (if (= (car (texinfo-multitable-widths)) (length str))
175 ;; function definition is void
178 (ptexinfmt-broken-facility texinfo-multitable-item
179 "`texinfo-multitable-item' unsupport wide-char."
180 (not (get 'texinfo-multitable-widths 'broken)))
183 ;;; Hardcopy and HTML (discard)
185 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
186 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
187 (put 'documentdescription 'texinfo-format 'texinfo-discard-line-with-args)
190 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
191 (put 'letterpaper 'texinfo-format 'texinfo-discard-line)
192 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
193 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
194 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
195 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
196 (put 'pagesizes '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)
295 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
296 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
297 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
298 (delete-region texinfo-command-start
299 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
302 ;; @html ... @end html (makeinfo 3.11 or later)
303 (put 'html 'texinfo-format 'texinfo-format-html)
304 (ptexinfmt-defun-if-void texinfo-format-html ()
305 (delete-region texinfo-command-start
306 (progn (re-search-forward "@end html[ \t]*\n")
309 ;; @docbook ... @end docbook (makeinfo 4.7 or later)
310 (put 'docbook 'texinfo-format 'texinfo-format-docbook)
311 (ptexinfmt-defun-if-void texinfo-format-docbook ()
312 (delete-region texinfo-command-start
313 (progn (re-search-forward "@end docbook[ \t]*\n")
316 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
317 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
318 (defun texinfo-format-ifhtml ()
319 (delete-region texinfo-command-start
320 (progn (re-search-forward "@end ifhtml[ \t]*\n")
323 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
324 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
325 (ptexinfmt-defun-if-void texinfo-format-ifplaintext ()
326 (delete-region texinfo-command-start
327 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
330 ;; @ifdocbook ... @end ifdocbook (makeinfo 4.7 or later)
331 (put 'ifdocbook 'texinfo-format 'texinfo-format-ifdocbook)
332 (ptexinfmt-defun-if-void texinfo-format-ifdocbook ()
333 (delete-region texinfo-command-start
334 (progn (re-search-forward "@end ifdocbook[ \t]*\n")
340 ;; @indicateurl, @url, @env, @command,
341 (put 'env 'texinfo-format 'texinfo-format-code)
342 (put 'command 'texinfo-format 'texinfo-format-code)
344 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
345 (put 'url 'texinfo-format 'texinfo-format-uref) ; Texinfo 4.7
348 (put 'acronym 'texinfo-format 'texinfo-format-var)
350 (ptexinfmt-defun-if-broken texinfo-format-var ()
351 (let ((arg (texinfo-parse-expanded-arg)))
352 (texinfo-discard-command)
353 (insert (upcase arg))))
356 (put 'key 'texinfo-format 'texinfo-format-key)
357 (ptexinfmt-defun-if-void texinfo-format-key ()
358 (insert (texinfo-parse-arg-discard))
359 (goto-char texinfo-command-start))
361 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
362 (put 'email 'texinfo-format 'texinfo-format-email)
363 (ptexinfmt-defun-if-void texinfo-format-email ()
364 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
365 Insert < ... > around EMAIL-ADDRESS."
366 (let ((args (texinfo-format-parse-args)))
367 (texinfo-discard-command)
370 (insert (nth 1 args) " <" (nth 0 args) ">")
371 (insert "<" (nth 0 args) ">"))))
374 (put 'option 'texinfo-format 'texinfo-format-option)
375 (ptexinfmt-defun-if-void texinfo-format-option ()
376 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
377 ;; `looking-at-backward' not available in v. 18.57, 20.2
378 ;; searched-for character is a control-H
379 (if (not (search-backward "\010"
380 (save-excursion (beginning-of-line) (point))
382 (insert "`" (texinfo-parse-arg-discard) "'")
383 (insert (texinfo-parse-arg-discard)))
384 (goto-char texinfo-command-start))
386 ;; @verb{<char>TEXT<char>} (makeinfo 4.1 or later)
387 (put 'verb 'texinfo-format 'texinfo-format-verb)
388 (ptexinfmt-defun-if-void texinfo-format-verb ()
389 "Format text between non-quoted unique delimiter characters verbatim.
390 Enclose the verbatim text, including the delimiters, in braces. Print
391 text exactly as written (but not the delimiters) in a fixed-width.
393 For example, @verb\{|@|\} results in @ and
394 @verb\{+@'e?`!`+} results in @'e?`!`."
396 (let ((delimiter (buffer-substring-no-properties
397 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
398 (unless (looking-at "{")
399 (error "Not found: @verb start brace"))
400 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
401 (search-forward delimiter))
402 (delete-backward-char 1)
403 (unless (looking-at "}")
404 (error "Not found: @verb end brace"))
408 ;;; @LaTeX, @registeredsymbol{}
409 (put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX)
410 (ptexinfmt-defun-if-void texinfo-format-LaTeX ()
411 (texinfo-parse-arg-discard)
414 (put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol)
415 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
416 (texinfo-parse-arg-discard)
419 ;;; Accents and Special characters
421 (put 'euro 'texinfo-format 'texinfo-format-euro)
422 (ptexinfmt-defun-if-void texinfo-format-euro ()
423 (texinfo-parse-arg-discard)
426 ;; @pounds{} ==> # Pounds Sterling
427 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
428 (ptexinfmt-defun-if-void texinfo-format-pounds ()
429 (texinfo-parse-arg-discard)
432 ;; @ordf{} ==> a Spanish feminine
433 (put 'ordf 'texinfo-format 'texinfo-format-ordf)
434 (ptexinfmt-defun-if-void texinfo-format-ordf ()
435 (texinfo-parse-arg-discard)
438 ;; @ordm{} ==> o Spanish masculine
439 (put 'ordm 'texinfo-format 'texinfo-format-ordm)
440 (ptexinfmt-defun-if-void texinfo-format-ordm ()
441 (texinfo-parse-arg-discard)
444 ;; @OE{} ==> OE French-OE-ligature
445 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
446 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
447 (insert "OE" (texinfo-parse-arg-discard))
448 (goto-char texinfo-command-start))
451 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
452 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
453 (insert "oe" (texinfo-parse-arg-discard))
454 (goto-char texinfo-command-start))
456 ;; @AA{} ==> AA Scandinavian-A-with-circle
457 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
458 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
459 (insert "AA" (texinfo-parse-arg-discard))
460 (goto-char texinfo-command-start))
463 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
464 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
465 (insert "aa" (texinfo-parse-arg-discard))
466 (goto-char texinfo-command-start))
468 ;; @AE{} ==> AE Latin-Scandinavian-AE
469 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
470 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
471 (insert "AE" (texinfo-parse-arg-discard))
472 (goto-char texinfo-command-start))
475 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
476 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
477 (insert "ae" (texinfo-parse-arg-discard))
478 (goto-char texinfo-command-start))
480 ;; @ss{} ==> ss German-sharp-S
481 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
482 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
483 (insert "ss" (texinfo-parse-arg-discard))
484 (goto-char texinfo-command-start))
486 ;; @questiondown{} ==> ? upside-down-question-mark
487 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
488 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
489 (insert "?" (texinfo-parse-arg-discard))
490 (goto-char texinfo-command-start))
492 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
493 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
494 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
495 (insert "!" (texinfo-parse-arg-discard))
496 (goto-char texinfo-command-start))
498 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
499 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
500 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
501 (insert (texinfo-parse-arg-discard) "/L")
502 (goto-char texinfo-command-start))
504 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
505 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
506 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
507 (insert (texinfo-parse-arg-discard) "/l")
508 (goto-char texinfo-command-start))
510 ;; @O{} ==> O/ Scandinavian O-with-slash
511 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
512 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
513 (insert (texinfo-parse-arg-discard) "O/")
514 (goto-char texinfo-command-start))
516 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
517 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
518 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
519 (insert (texinfo-parse-arg-discard) "o/")
520 (goto-char texinfo-command-start))
522 ;; @,{c} ==> c, cedilla accent
523 (put ', 'texinfo-format 'texinfo-format-cedilla-accent)
524 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
525 (insert (texinfo-parse-arg-discard) ",")
526 (goto-char texinfo-command-start))
529 ;; @dotaccent{o} ==> .o overdot-accent
530 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
531 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
532 (insert "." (texinfo-parse-arg-discard))
533 (goto-char texinfo-command-start))
535 ;; @ubaraccent{o} ==> _o underbar-accent
536 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
537 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
538 (insert "_" (texinfo-parse-arg-discard))
539 (goto-char texinfo-command-start))
541 ;; @udotaccent{o} ==> o-. underdot-accent
542 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
543 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
544 (insert (texinfo-parse-arg-discard) "-.")
545 (goto-char texinfo-command-start))
547 ;; @H{o} ==> ""o long Hungarian umlaut
548 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
549 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
550 (insert "\"\"" (texinfo-parse-arg-discard))
551 (goto-char texinfo-command-start))
553 ;; @ringaccent{o} ==> *o ring accent
554 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
555 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
556 (insert "*" (texinfo-parse-arg-discard))
557 (goto-char texinfo-command-start))
559 ;; @tieaccent{oo} ==> [oo tie after accent
560 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
561 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
562 (insert "[" (texinfo-parse-arg-discard))
563 (goto-char texinfo-command-start))
565 ;; @u{o} ==> (o breve accent
566 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
567 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
568 (insert "(" (texinfo-parse-arg-discard))
569 (goto-char texinfo-command-start))
571 ;; @v{o} ==> <o hacek accent
572 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
573 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
574 (insert "<" (texinfo-parse-arg-discard))
575 (goto-char texinfo-command-start))
577 ;; @dotless{i} ==> i dotless i and dotless j
578 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
579 (ptexinfmt-defun-if-void texinfo-format-dotless ()
580 (insert (texinfo-parse-arg-discard))
581 (goto-char texinfo-command-start))
584 (put '\. 'texinfo-format 'texinfo-format-\.)
585 (ptexinfmt-defun-if-void texinfo-format-\. ()
586 (texinfo-discard-command)
590 (put '\: 'texinfo-format 'texinfo-format-\:)
591 (ptexinfmt-defun-if-void texinfo-format-\: ()
592 (texinfo-discard-command))
595 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
596 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
597 (texinfo-discard-command))
600 (put '\/ 'texinfo-format 'texinfo-format-\/)
601 (ptexinfmt-defun-if-void texinfo-format-\/ ()
602 (texinfo-discard-command))
607 (put 'ref 'texinfo-format 'texinfo-format-xref)
609 (ptexinfmt-defun-if-broken texinfo-format-xref ()
610 (let ((args (texinfo-format-parse-args)))
611 (texinfo-discard-command)
613 (let ((fname (or (nth 1 args) (nth 2 args))))
614 (if (null (or fname (nth 3 args)))
615 (insert (nth 0 args) "::")
616 (insert (or fname (nth 0 args)) ": ")
618 (insert "(" (nth 3 args) ")"))
619 (unless (null (nth 0 args))
620 (insert (nth 0 args)))))))
622 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
623 (put 'uref 'texinfo-format 'texinfo-format-uref)
624 (ptexinfmt-defun-if-broken texinfo-format-uref ()
625 "Format URL and optional URL-TITLE.
626 Insert ` ... ' around URL if no URL-TITLE argument;
627 otherwise, insert URL-TITLE followed by URL in parentheses."
628 (let ((args (texinfo-format-parse-args)))
629 (texinfo-discard-command)
632 (insert (nth 1 args) " (" (nth 0 args) ")")
633 (insert "`" (nth 0 args) "'"))))
636 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
637 (ptexinfmt-defun-if-void texinfo-format-inforef ()
638 (let ((args (texinfo-format-parse-args)))
639 (texinfo-discard-command)
641 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
642 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
647 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
648 ;; - Info-tagify suport @anthor-*-refill.
649 ;; - info.el support Ref in Tag table.
650 (unless (get 'anchor 'texinfo-format)
651 (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
655 ;;; New command definition
656 ;; @alias NEW=EXISTING
657 (put 'alias 'texinfo-format 'texinfo-alias)
658 (ptexinfmt-defun-if-void texinfo-alias ()
659 (let ((start (1- (point)))
661 (skip-chars-forward " ")
662 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
663 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
664 (error "Invalid alias command")
665 (setq texinfo-alias-list
668 (buffer-substring (match-beginning 1) (match-end 1))
669 (buffer-substring (match-beginning 2) (match-end 2)))
671 (texinfo-discard-command))))
675 ;; @exampleindent INDENT (makeinfo 4.0 or later)
677 ;; @paragraphindent INDENT (makeinfo 4.0 or later)
678 ;; INDENT: asis, 0, n
680 ;; @firstparagraphindent WORD (makeinfo 4.6 or later)
681 ;; WORD: none, insert
686 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
687 (put 'image 'texinfo-format 'texinfo-format-image)
688 (ptexinfmt-defun-if-void texinfo-format-image ()
689 ;; I don't know makeinfo parse FILENAME.
690 (let ((args (texinfo-format-parse-args))
692 (when (null (nth 0 args))
693 (error "Invalid image command"))
694 (texinfo-discard-command)
695 ;; makeinfo uses FILENAME.txt
696 (setq filename (format "%s.txt" (nth 0 args)))
697 (message "Reading included file: %s" filename)
698 ;; verbatim for Info output
699 (goto-char (+ (point) (cadr (insert-file-contents filename))))
700 (message "Reading included file: %s...done" filename)))
704 ;;; @multitable ... @end multitable
705 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
706 "*Number of extra spaces between entries (columns) in @multitable.")
708 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
709 "*multitable-temporary-buffer*")
710 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
711 "texinfo-multitable-temp-")
713 ;; These commands are defined in texinfo.tex for printed output.
714 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
715 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
716 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
717 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
719 (put 'multitable 'texinfo-format 'texinfo-multitable)
721 (ptexinfmt-defun-if-void texinfo-multitable ()
722 "Produce multi-column tables."
724 ;; This function pushes information onto the `texinfo-stack'.
725 ;; A stack element consists of:
726 ;; - type-of-command, i.e., multitable
727 ;; - the information about column widths, and
728 ;; - the position of texinfo-command-start.
729 ;; e.g., ('multitable (1 2 3 4) 123)
730 ;; The command line is then deleted.
733 ;; push width information on stack
734 (texinfo-multitable-widths))
735 (texinfo-discard-line-with-args))
737 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
738 (ptexinfmt-defun-if-void texinfo-end-multitable ()
739 "Discard the @end multitable line and pop the stack of multitable."
740 (texinfo-discard-command)
741 (texinfo-pop-stack 'multitable))
743 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
744 "Return list of widths of each column in a multi-column table."
745 (let (texinfo-multitable-width-list)
747 ;; @multitable @columnfractions .25 .3 .45
750 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
751 ;; Place point before first argument
752 (skip-chars-forward " \t")
754 ;; Check for common misspelling
755 ((looking-at "@columnfraction ")
756 (error "In @multitable, @columnfractions misspelled"))
757 ;; Case 1: @columnfractions .25 .3 .45
758 ((looking-at "@columnfractions")
761 (setq texinfo-multitable-width-list
765 (* fill-column (read (get-buffer (current-buffer))))))
766 texinfo-multitable-width-list))))
768 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
770 (let ((start-of-templates (point)))
772 (skip-chars-forward " \t")
773 (let* ((start-of-template (1+ (point)))
775 ;; forward-sexp works with braces in Texinfo mode
776 (progn (forward-sexp 1) (1- (point)))))
777 (setq texinfo-multitable-width-list
779 (goto-char end-of-template)
782 (goto-char start-of-template)
784 texinfo-multitable-width-list))
785 ;; Remove carriage return from within a template, if any.
786 ;; This helps those those who want to use more than
787 ;; one line's worth of words in @multitable line.
788 (narrow-to-region start-of-template end-of-template)
789 (goto-char (point-min))
790 (while (search-forward "\n" nil t)
792 (goto-char (point-max))
799 You probably need to specify column widths for @multitable correctly")))
800 ;; Check whether columns fit on page.
801 (let ((desired-columns
803 ;; between column spaces
804 (length texinfo-multitable-width-list)
805 ;; additional between column spaces, if any
806 texinfo-extra-inter-column-width
807 ;; sum of spaces for each entry
808 (apply '+ texinfo-multitable-width-list))))
809 (if (> desired-columns fill-column)
811 Multi-column table width, %d chars, is greater than page width, %d chars."
812 desired-columns fill-column))))
813 texinfo-multitable-width-list))
815 ;; @item A1 @tab A2 @tab A3
816 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
817 "Return multitable row, as a string.
818 End of row is beginning of next @item or beginning of @end.
819 Cells within rows are separated by @tab."
820 (skip-chars-forward " \t")
821 (let* ((start (point))
823 (re-search-forward "@item\\|@end")
824 (match-beginning 0)))
825 (row (progn (goto-char end)
826 (skip-chars-backward " ")
827 ;; remove whitespace at end of argument
828 (delete-region (point) end)
829 (buffer-substring start (point)))))
830 (delete-region texinfo-command-start end)
833 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
834 (ptexinfmt-defun-if-void texinfo-multitable-item ()
835 "Format a row within a multicolumn table.
836 Cells in row are separated by @tab.
837 Widths of cells are specified by the arguments in the @multitable line.
838 All cells are made to be the same height.
839 This command is executed when texinfmt sees @item inside @multitable."
840 (let ((original-buffer (current-buffer))
841 (table-widths (reverse (car (cdr (car texinfo-stack)))))
842 (existing-fill-column fill-column)
846 (table-entry-height 0)
847 ;; unformatted row looks like: A1 @tab A2 @tab A3
848 ;; extract-row command deletes the source line in the table.
849 (unformated-row (texinfo-multitable-extract-row)))
850 ;; Use a temporary buffer
851 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
852 (delete-region (point-min) (point-max))
853 (insert unformated-row)
854 (goto-char (point-min))
855 ;; 1. Check for correct number of @tab in line.
856 (let ((tab-number 1)) ;; one @tab between two columns
857 (while (search-forward "@tab" nil t)
858 (setq tab-number (1+ tab-number)))
859 (if (/= tab-number (length table-widths))
860 (error "Wrong number of @tab's in a @multitable row")))
861 (goto-char (point-min))
862 ;; 2. Format each cell, and copy to a rectangle
863 ;; buffer looks like this: A1 @tab A2 @tab A3
864 ;; Cell #1: format up to @tab
865 ;; Cell #2: format up to @tab
866 ;; Cell #3: format up to eob
869 (setq end (save-excursion
870 (if (search-forward "@tab" nil 'move)
871 ;; Delete the @tab command, including the @-sign
874 (progn (forward-word -1) (1- (point)))))
876 ;; Set fill-column *wider* than needed to produce inter-column space
877 (setq fill-column (+ 1
878 texinfo-extra-inter-column-width
879 (nth table-column table-widths)))
880 (narrow-to-region start end)
881 ;; Remove whitespace before and after entry.
882 (skip-chars-forward " ")
883 (delete-region (point) (save-excursion (beginning-of-line) (point)))
884 (goto-char (point-max))
885 (skip-chars-backward " ")
886 (delete-region (point) (save-excursion (end-of-line) (point)))
887 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
888 ;; does not see an unterminated @multitable.
889 (let (texinfo-stack) ;; nil
890 (texinfo-format-scan))
891 (let (fill-prefix) ;; no fill prefix
892 (fill-region (point-min) (point-max)))
893 (setq table-entry-height
894 (max table-entry-height (count-lines (point-min) (point-max))))
895 ;; 3. Move point to end of bottom line, and pad that line to fill column.
896 (goto-char (point-min))
897 (forward-line (1- table-entry-height))
898 (let* ((beg (point)) ;; beginning of line
899 ;; add one more space for inter-column spacing
905 (current-column)))))) ;; end of existing line
907 (if (> needed-whitespace 0) needed-whitespace 1)
909 ;; now, put formatted cell into a rectangle
910 (set (intern (concat texinfo-multitable-rectangle-name
911 (int-to-string table-column)))
912 (extract-rectangle (point-min) (point)))
913 (delete-region (point-min) (point))
914 (goto-char (point-max))
915 (setq table-column (1+ table-column))
917 ;; 4. Add extra lines to rectangles so all are of same height
918 (let ((total-number-of-columns table-column)
921 (while (> table-column 0)
922 (let ((this-rectangle (int-to-string table-column)))
923 (while (< (length this-rectangle) table-entry-height)
924 (setq this-rectangle (append this-rectangle '("")))))
925 (setq table-column (1- table-column)))
926 ;; 5. Insert formatted rectangles in original buffer
927 (switch-to-buffer original-buffer)
928 (open-line table-entry-height)
929 (while (< column-number total-number-of-columns)
933 (concat texinfo-multitable-rectangle-name
934 (int-to-string column-number)))))
937 (setq column-number (1+ column-number))))
938 (kill-buffer texinfo-multitable-buffer-name)
939 (setq fill-column existing-fill-column)))
942 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
943 (let ((indexelts (symbol-value
944 (cdr (assoc (texinfo-parse-arg-discard)
945 texinfo-indexvar-alist))))
947 (insert "\n* Menu:\n\n")
948 (setq opoint (point))
949 (texinfo-print-index nil indexelts)
951 (if (memq system-type '(vax-vms windows-nt ms-dos))
952 (texinfo-sort-region opoint (point))
953 (shell-command-on-region opoint (point) "sort -fd" 1))))
957 ;;; ptexinfmt.el ends here