1 ;;; ptexinfmt.el -- portable Texinfo formatter.
3 ;; Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993,
4 ;; 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
5 ;; Copyright (C) 1999 Yoshiki Hayashi <yoshiki@xemacs.org>
6 ;; Copyright (C) 2000 TAKAHASHI Kaoru <kaoru@kaisei.org>
8 ;; Author: TAKAHASHI Kaoru <kaoru@kaisei.org>
9 ;; Yoshiki Hayashi <yoshiki@xemacs.org>
10 ;; Katsumi Yamaoka <yamaoka@jpl.org>
11 ;; Maintainer: TAKAHASHI Kaoru <kaoru@kaisei.org>
12 ;; Created: 7 Jul 2000
13 ;; Keywords: maint, tex, docs, emulation, compatibility
15 ;; This program is free software; you can redistribute it and/or
16 ;; modify it under the terms of the GNU General Public License as
17 ;; published by the Free Software Foundation; either version 2, or (at
18 ;; your option) any later version.
20 ;; This program is distributed in the hope that it will be useful, but
21 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 ;; General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 ;; Boston, MA 02110-1301, USA.
32 ;; Original code: Yoshiki Hayashi <yoshiki@xemacs.org>
33 ;; makeinfo.el (gnujdoc project)
35 ;; Support texinfmt.el 2.32 or later.
37 ;; Modified by Yamaoka not to use APEL functions.
39 ;; Unimplemented command:
41 ;; @float, @caption, @shortcaption, @listoffloats
45 ;; @quotation (optional arguments)
46 ;; @acronym (optional argument)
47 ;; @dofirstparagraphindent
56 ;; @quotedblleft @quotedblright
57 ;; @quoteleft @quoteright @quotedblbase @quotesinglbase
58 ;; @guillemetleft @guillemetright @guilsinglleft @guilsinglright.
65 (defvar ptexinfmt-disable-broken-notice-flag t
66 "If non-nil disable notice, when call `ptexinfmt-broken-facility'.
67 This is last argument in `ptexinfmt-broken-facility'.")
69 (put 'ptexinfmt-broken-facility 'lisp-indent-function 'defun)
70 (defmacro ptexinfmt-broken-facility (facility docstring assertion
72 "Declare a symbol FACILITY is broken if ASSERTION is nil.
73 DOCSTRING will be printed if ASSERTION is nil and
74 `ptexinfmt-disable-broken-notice-flag' is nil."
75 `(let ((facility ',facility)
76 (docstring ,docstring)
77 (assertion (eval ',assertion)))
78 (put facility 'broken (not assertion))
81 (put facility 'broken-docstring docstring)
82 (if ptexinfmt-disable-broken-notice-flag
84 (message "BROKEN FACILITY DETECTED: %s" docstring)))))
86 (put 'ptexinfmt-defun-if-broken 'lisp-indent-function 'defun)
87 (defmacro ptexinfmt-defun-if-broken (&rest args)
88 "Redefine a function just like `defun' if it is considered broken."
89 (let ((name (list 'quote (car args))))
90 (setq args (cdr args))
93 (if (get ,name 'broken)
95 (function (lambda ,@args)))))))
97 (put 'ptexinfmt-defun-if-void 'lisp-indent-function 'defun)
98 (defmacro ptexinfmt-defun-if-void (&rest args)
99 "Define a function just like `defun' unless it is already defined."
100 (let ((name (list 'quote (car args))))
101 (setq args (cdr args))
107 (function (lambda ,@args)))))))
109 (put 'ptexinfmt-defvar-if-void 'lisp-indent-function 'defun)
110 (defmacro ptexinfmt-defvar-if-void (&rest args)
111 "Define a variable just like `defvar' unless it is already defined."
112 (let ((name (car args)))
113 (setq args (cdr args))
118 (defvar ,name ,@args)))))
121 (ptexinfmt-broken-facility texinfo-format-printindex
122 "Can't sort on Mule for Windows."
123 (if (and (memq system-type '(windows-nt ms-dos))
124 ;;; I don't know version threshold.
125 ;;; (string< texinfmt-version "2.37 of 24 May 1997")
126 (boundp 'MULE) (not (featurep 'meadow))) ; Mule for Windows
131 (ptexinfmt-broken-facility texinfo-format-var
132 "Don't perse @var argument."
135 (let (texinfo-enclosure-list texinfo-alias-list)
137 (insert "@var{@asis{foo}}\n")
138 (texinfo-format-expand-region (point-min) (point-max))
143 (ptexinfmt-broken-facility texinfo-format-xref
144 "Can't format @xref, 1st argument is empty."
147 (let (texinfo-enclosure-list texinfo-alias-list)
149 (insert "@xref{, xref, , file}\n")
150 (texinfo-format-expand-region (point-min) (point-max))
155 (ptexinfmt-broken-facility texinfo-format-uref
156 "Parse twice @uref argument."
159 (let (texinfo-enclosure-list texinfo-alias-list)
161 (insert "@uref{mailto:foo@@noncommand.example.com}\n")
162 (texinfo-format-expand-region (point-min) (point-max))
167 (ptexinfmt-broken-facility texinfo-multitable-widths
168 "`texinfo-multitable-widths' unsupport wide-char."
169 (if (fboundp 'texinfo-multitable-widths)
171 (let ((str "
\e$BI}9-J8;z
\e(B"))
173 (insert (format " {%s}\n" str))
174 (goto-char (point-min))
175 (if (= (car (texinfo-multitable-widths)) (length str))
178 ;; function definition is void
181 (ptexinfmt-broken-facility texinfo-multitable-item
182 "`texinfo-multitable-item' unsupport wide-char."
183 (not (get 'texinfo-multitable-widths 'broken)))
186 ;;; Hardcopy and HTML (discard)
188 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
189 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
190 (put 'documentdescription 'texinfo-format 'texinfo-discard-line-with-args)
193 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
194 (put 'letterpaper 'texinfo-format 'texinfo-discard-line)
195 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
196 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
197 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
198 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
199 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
200 (put 'fonttextsize 'texinfo-format 'texinfo-discard-line-with-args)
203 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
204 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
207 (put 'setcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
208 (put 'setshortcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
209 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
210 (put 'frenchspacing 'texinfo-format 'texinfo-discard-line-with-args)
213 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
214 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
215 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
216 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
217 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
218 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
219 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
222 (put 'page 'texinfo-format 'texinfo-discard-line)
223 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
225 ;; @slanted{} (makeinfo 4.8 or later)
226 (put 'slanted 'texinfo-format 'texinfo-format-noop)
228 ;; @sansserif{} (makeinfo 4.8 or later)
229 (put 'sansserif 'texinfo-format 'texinfo-format-noop)
231 ;; @tie{} (makeinfo 4.3 or later)
232 (put 'tie 'texinfo-format 'texinfo-format-tie)
233 (ptexinfmt-defun-if-void texinfo-format-tie ()
234 (texinfo-parse-arg-discard)
240 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
241 (ptexinfmt-defun-if-void texinfo-format-dircategory ()
242 (let ((str (texinfo-parse-arg-discard)))
243 (delete-region (point)
245 (skip-chars-forward " ")
247 (insert "INFO-DIR-SECTION " str "\n")))
250 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
251 (ptexinfmt-defun-if-void texinfo-format-direntry ()
252 (texinfo-push-stack 'direntry nil)
253 (texinfo-discard-line)
254 (insert "START-INFO-DIR-ENTRY\n"))
256 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
257 (ptexinfmt-defun-if-void texinfo-end-direntry ()
258 (texinfo-discard-command)
259 (insert "END-INFO-DIR-ENTRY\n\n")
260 (texinfo-pop-stack 'direntry))
264 ;; @detailmenu ... @end detailmenu
265 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
266 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
268 ;; @smalldisplay ... @end smalldisplay
269 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
270 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
272 ;; @smallformat ... @end smallformat
273 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
274 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
276 ;; @cartouche ... @end cartouche
277 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
278 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
282 ;; @ifnottex ... @end ifnottex (makeinfo 3.11 or later)
283 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
284 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
286 ;; @ifnothtml ... @end ifnothtml (makeinfo 3.11 or later)
287 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
288 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
290 ;; @ifnotplaintext ... @end ifnotplaintext (makeinfo 4.2 or later)
291 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
292 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
294 ;; @ifnotdocbook ... @end ifnotdocbook (makeinfo 4.7 or later)
295 (put 'ifnotdocbook 'texinfo-format 'texinfo-discard-line)
296 (put 'ifnotdocbook 'texinfo-end 'texinfo-discard-command)
298 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
299 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
300 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
301 (delete-region texinfo-command-start
302 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
305 ;; @html ... @end html (makeinfo 3.11 or later)
306 (put 'html 'texinfo-format 'texinfo-format-html)
307 (ptexinfmt-defun-if-void texinfo-format-html ()
308 (delete-region texinfo-command-start
309 (progn (re-search-forward "@end html[ \t]*\n")
312 ;; @docbook ... @end docbook (makeinfo 4.7 or later)
313 (put 'docbook 'texinfo-format 'texinfo-format-docbook)
314 (ptexinfmt-defun-if-void texinfo-format-docbook ()
315 (delete-region texinfo-command-start
316 (progn (re-search-forward "@end docbook[ \t]*\n")
319 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
320 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
321 (defun texinfo-format-ifhtml ()
322 (delete-region texinfo-command-start
323 (progn (re-search-forward "@end ifhtml[ \t]*\n")
326 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
327 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
328 (ptexinfmt-defun-if-void texinfo-format-ifplaintext ()
329 (delete-region texinfo-command-start
330 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
333 ;; @ifdocbook ... @end ifdocbook (makeinfo 4.7 or later)
334 (put 'ifdocbook 'texinfo-format 'texinfo-format-ifdocbook)
335 (ptexinfmt-defun-if-void texinfo-format-ifdocbook ()
336 (delete-region texinfo-command-start
337 (progn (re-search-forward "@end ifdocbook[ \t]*\n")
342 ;; @indicateurl, @url, @env, @command,
343 (put 'env 'texinfo-format 'texinfo-format-code)
344 (put 'command 'texinfo-format 'texinfo-format-code)
346 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
347 (put 'url 'texinfo-format 'texinfo-format-uref) ; Texinfo 4.7
350 (put 'acronym 'texinfo-format 'texinfo-format-var)
352 (ptexinfmt-defun-if-broken texinfo-format-var ()
353 (let ((arg (texinfo-parse-expanded-arg)))
354 (texinfo-discard-command)
355 (insert (upcase arg))))
358 (put 'key 'texinfo-format 'texinfo-format-key)
359 (ptexinfmt-defun-if-void texinfo-format-key ()
360 (insert (texinfo-parse-arg-discard))
361 (goto-char texinfo-command-start))
363 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
364 (put 'email 'texinfo-format 'texinfo-format-email)
365 (ptexinfmt-defun-if-void texinfo-format-email ()
366 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
367 Insert < ... > around EMAIL-ADDRESS."
368 (let ((args (texinfo-format-parse-args)))
369 (texinfo-discard-command)
372 (insert (nth 1 args) " <" (nth 0 args) ">")
373 (insert "<" (nth 0 args) ">"))))
376 (put 'option 'texinfo-format 'texinfo-format-option)
377 (ptexinfmt-defun-if-void texinfo-format-option ()
378 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
379 ;; `looking-at-backward' not available in v. 18.57, 20.2
380 ;; searched-for character is a control-H
381 (if (not (search-backward "\010"
382 (save-excursion (beginning-of-line) (point))
384 (insert "`" (texinfo-parse-arg-discard) "'")
385 (insert (texinfo-parse-arg-discard)))
386 (goto-char texinfo-command-start))
388 ;; @verb{<char>TEXT<char>} (makeinfo 4.1 or later)
389 (put 'verb 'texinfo-format 'texinfo-format-verb)
390 (ptexinfmt-defun-if-void texinfo-format-verb ()
391 "Format text between non-quoted unique delimiter characters verbatim.
392 Enclose the verbatim text, including the delimiters, in braces. Print
393 text exactly as written (but not the delimiters) in a fixed-width.
395 For example, @verb\{|@|\} results in @ and
396 @verb\{+@'e?`!`+} results in @'e?`!`."
398 (let ((delimiter (buffer-substring-no-properties
399 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
400 (unless (looking-at "{")
401 (error "Not found: @verb start brace"))
402 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
403 (search-forward delimiter))
404 (delete-backward-char 1)
405 (unless (looking-at "}")
406 (error "Not found: @verb end brace"))
410 ;;; @LaTeX, @registeredsymbol{}
411 (put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX)
412 (ptexinfmt-defun-if-void texinfo-format-LaTeX ()
413 (texinfo-parse-arg-discard)
416 (put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol)
417 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
418 (texinfo-parse-arg-discard)
421 ;;; Accents and Special characters
423 (put 'euro 'texinfo-format 'texinfo-format-euro)
424 (ptexinfmt-defun-if-void texinfo-format-euro ()
425 (texinfo-parse-arg-discard)
428 ;; @pounds{} ==> # Pounds Sterling
429 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
430 (ptexinfmt-defun-if-void texinfo-format-pounds ()
431 (texinfo-parse-arg-discard)
434 ;; @ordf{} ==> a Spanish feminine
435 (put 'ordf 'texinfo-format 'texinfo-format-ordf)
436 (ptexinfmt-defun-if-void texinfo-format-ordf ()
437 (texinfo-parse-arg-discard)
440 ;; @ordm{} ==> o Spanish masculine
441 (put 'ordm 'texinfo-format 'texinfo-format-ordm)
442 (ptexinfmt-defun-if-void texinfo-format-ordm ()
443 (texinfo-parse-arg-discard)
446 ;; @OE{} ==> OE French-OE-ligature
447 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
448 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
449 (insert "OE" (texinfo-parse-arg-discard))
450 (goto-char texinfo-command-start))
453 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
454 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
455 (insert "oe" (texinfo-parse-arg-discard))
456 (goto-char texinfo-command-start))
458 ;; @AA{} ==> AA Scandinavian-A-with-circle
459 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
460 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
461 (insert "AA" (texinfo-parse-arg-discard))
462 (goto-char texinfo-command-start))
465 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
466 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
467 (insert "aa" (texinfo-parse-arg-discard))
468 (goto-char texinfo-command-start))
470 ;; @AE{} ==> AE Latin-Scandinavian-AE
471 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
472 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
473 (insert "AE" (texinfo-parse-arg-discard))
474 (goto-char texinfo-command-start))
477 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
478 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
479 (insert "ae" (texinfo-parse-arg-discard))
480 (goto-char texinfo-command-start))
482 ;; @ss{} ==> ss German-sharp-S
483 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
484 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
485 (insert "ss" (texinfo-parse-arg-discard))
486 (goto-char texinfo-command-start))
488 ;; @questiondown{} ==> ? upside-down-question-mark
489 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
490 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
491 (insert "?" (texinfo-parse-arg-discard))
492 (goto-char texinfo-command-start))
494 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
495 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
496 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
497 (insert "!" (texinfo-parse-arg-discard))
498 (goto-char texinfo-command-start))
500 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
501 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
502 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
503 (insert (texinfo-parse-arg-discard) "/L")
504 (goto-char texinfo-command-start))
506 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
507 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
508 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
509 (insert (texinfo-parse-arg-discard) "/l")
510 (goto-char texinfo-command-start))
512 ;; @O{} ==> O/ Scandinavian O-with-slash
513 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
514 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
515 (insert (texinfo-parse-arg-discard) "O/")
516 (goto-char texinfo-command-start))
518 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
519 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
520 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
521 (insert (texinfo-parse-arg-discard) "o/")
522 (goto-char texinfo-command-start))
524 ;; @,{c} ==> c, cedilla accent
525 (put '\, 'texinfo-format 'texinfo-format-cedilla-accent)
526 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
527 (insert (texinfo-parse-arg-discard) ",")
528 (goto-char texinfo-command-start))
531 ;; @dotaccent{o} ==> .o overdot-accent
532 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
533 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
534 (insert "." (texinfo-parse-arg-discard))
535 (goto-char texinfo-command-start))
537 ;; @ubaraccent{o} ==> _o underbar-accent
538 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
539 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
540 (insert "_" (texinfo-parse-arg-discard))
541 (goto-char texinfo-command-start))
543 ;; @udotaccent{o} ==> o-. underdot-accent
544 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
545 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
546 (insert (texinfo-parse-arg-discard) "-.")
547 (goto-char texinfo-command-start))
549 ;; @H{o} ==> ""o long Hungarian umlaut
550 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
551 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
552 (insert "\"\"" (texinfo-parse-arg-discard))
553 (goto-char texinfo-command-start))
555 ;; @ringaccent{o} ==> *o ring accent
556 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
557 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
558 (insert "*" (texinfo-parse-arg-discard))
559 (goto-char texinfo-command-start))
561 ;; @tieaccent{oo} ==> [oo tie after accent
562 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
563 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
564 (insert "[" (texinfo-parse-arg-discard))
565 (goto-char texinfo-command-start))
567 ;; @u{o} ==> (o breve accent
568 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
569 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
570 (insert "(" (texinfo-parse-arg-discard))
571 (goto-char texinfo-command-start))
573 ;; @v{o} ==> <o hacek accent
574 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
575 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
576 (insert "<" (texinfo-parse-arg-discard))
577 (goto-char texinfo-command-start))
579 ;; @dotless{i} ==> i dotless i and dotless j
580 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
581 (ptexinfmt-defun-if-void texinfo-format-dotless ()
582 (insert (texinfo-parse-arg-discard))
583 (goto-char texinfo-command-start))
586 (put '\. 'texinfo-format 'texinfo-format-\.)
587 (ptexinfmt-defun-if-void texinfo-format-\. ()
588 (texinfo-discard-command)
592 (put '\: 'texinfo-format 'texinfo-format-\:)
593 (ptexinfmt-defun-if-void texinfo-format-\: ()
594 (texinfo-discard-command))
597 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
598 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
599 (texinfo-discard-command))
602 (put '\/ 'texinfo-format 'texinfo-format-\/)
603 (ptexinfmt-defun-if-void texinfo-format-\/ ()
604 (texinfo-discard-command))
607 (put 'textdegree 'texinfo-format 'texinfo-format-textdegree)
608 (ptexinfmt-defun-if-void texinfo-format-textdegree ()
609 (insert "o" (texinfo-parse-arg-discard))
610 (goto-char texinfo-command-start))
615 (put 'ref 'texinfo-format 'texinfo-format-xref)
617 (ptexinfmt-defun-if-broken texinfo-format-xref ()
618 (let ((args (texinfo-format-parse-args)))
619 (texinfo-discard-command)
621 (let ((fname (or (nth 1 args) (nth 2 args))))
622 (if (null (or fname (nth 3 args)))
623 (insert (nth 0 args) "::")
624 (insert (or fname (nth 0 args)) ": ")
626 (insert "(" (nth 3 args) ")"))
627 (unless (null (nth 0 args))
628 (insert (nth 0 args)))))))
630 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
631 (put 'uref 'texinfo-format 'texinfo-format-uref)
632 (ptexinfmt-defun-if-broken texinfo-format-uref ()
633 "Format URL and optional URL-TITLE.
634 Insert ` ... ' around URL if no URL-TITLE argument;
635 otherwise, insert URL-TITLE followed by URL in parentheses."
636 (let ((args (texinfo-format-parse-args)))
637 (texinfo-discard-command)
640 (insert (nth 1 args) " (" (nth 0 args) ")")
641 (insert "`" (nth 0 args) "'"))))
644 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
645 (ptexinfmt-defun-if-void texinfo-format-inforef ()
646 (let ((args (texinfo-format-parse-args)))
647 (texinfo-discard-command)
649 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
650 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
655 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
656 ;; - Info-tagify suport @anthor-*-refill.
657 ;; - info.el support Ref in Tag table.
658 (unless (get 'anchor 'texinfo-format)
659 (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
663 ;;; New command definition
664 ;; @alias NEW=EXISTING
665 (put 'alias 'texinfo-format 'texinfo-alias)
666 (ptexinfmt-defun-if-void texinfo-alias ()
667 (let ((start (1- (point)))
669 (skip-chars-forward " ")
670 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
671 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
672 (error "Invalid alias command")
673 (setq texinfo-alias-list
676 (buffer-substring (match-beginning 1) (match-end 1))
677 (buffer-substring (match-beginning 2) (match-end 2)))
679 (texinfo-discard-command))))
683 ;; @exampleindent INDENT (makeinfo 4.0 or later)
685 ;; @paragraphindent INDENT (makeinfo 4.0 or later)
686 ;; INDENT: asis, 0, n
688 ;; @firstparagraphindent WORD (makeinfo 4.6 or later)
689 ;; WORD: none, insert
694 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
695 (put 'image 'texinfo-format 'texinfo-format-image)
696 (ptexinfmt-defun-if-void texinfo-format-image ()
697 ;; I don't know makeinfo parse FILENAME.
698 (let ((args (texinfo-format-parse-args))
700 (when (null (nth 0 args))
701 (error "Invalid image command"))
702 (texinfo-discard-command)
703 ;; makeinfo uses FILENAME.txt
704 (setq filename (format "%s.txt" (nth 0 args)))
705 (message "Reading included file: %s" filename)
706 ;; verbatim for Info output
707 (goto-char (+ (point) (cadr (insert-file-contents filename))))
708 (message "Reading included file: %s...done" filename)))
712 ;;; @multitable ... @end multitable
713 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
714 "*Number of extra spaces between entries (columns) in @multitable.")
716 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
717 "*multitable-temporary-buffer*")
718 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
719 "texinfo-multitable-temp-")
721 ;; These commands are defined in texinfo.tex for printed output.
722 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
723 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
724 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
725 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
727 (put 'multitable 'texinfo-format 'texinfo-multitable)
729 (ptexinfmt-defun-if-void texinfo-multitable ()
730 "Produce multi-column tables."
732 ;; This function pushes information onto the `texinfo-stack'.
733 ;; A stack element consists of:
734 ;; - type-of-command, i.e., multitable
735 ;; - the information about column widths, and
736 ;; - the position of texinfo-command-start.
737 ;; e.g., ('multitable (1 2 3 4) 123)
738 ;; The command line is then deleted.
741 ;; push width information on stack
742 (texinfo-multitable-widths))
743 (texinfo-discard-line-with-args))
745 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
746 (ptexinfmt-defun-if-void texinfo-end-multitable ()
747 "Discard the @end multitable line and pop the stack of multitable."
748 (texinfo-discard-command)
749 (texinfo-pop-stack 'multitable))
751 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
752 "Return list of widths of each column in a multi-column table."
753 (let (texinfo-multitable-width-list)
755 ;; @multitable @columnfractions .25 .3 .45
758 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
759 ;; Place point before first argument
760 (skip-chars-forward " \t")
762 ;; Check for common misspelling
763 ((looking-at "@columnfraction ")
764 (error "In @multitable, @columnfractions misspelled"))
765 ;; Case 1: @columnfractions .25 .3 .45
766 ((looking-at "@columnfractions")
769 (setq texinfo-multitable-width-list
773 (* fill-column (read (get-buffer (current-buffer))))))
774 texinfo-multitable-width-list))))
776 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
778 (let ((start-of-templates (point)))
780 (skip-chars-forward " \t")
781 (let* ((start-of-template (1+ (point)))
783 ;; forward-sexp works with braces in Texinfo mode
784 (progn (forward-sexp 1) (1- (point)))))
785 (setq texinfo-multitable-width-list
787 (goto-char end-of-template)
790 (goto-char start-of-template)
792 texinfo-multitable-width-list))
793 ;; Remove carriage return from within a template, if any.
794 ;; This helps those those who want to use more than
795 ;; one line's worth of words in @multitable line.
796 (narrow-to-region start-of-template end-of-template)
797 (goto-char (point-min))
798 (while (search-forward "\n" nil t)
800 (goto-char (point-max))
807 You probably need to specify column widths for @multitable correctly")))
808 ;; Check whether columns fit on page.
809 (let ((desired-columns
811 ;; between column spaces
812 (length texinfo-multitable-width-list)
813 ;; additional between column spaces, if any
814 texinfo-extra-inter-column-width
815 ;; sum of spaces for each entry
816 (apply '+ texinfo-multitable-width-list))))
817 (if (> desired-columns fill-column)
819 Multi-column table width, %d chars, is greater than page width, %d chars."
820 desired-columns fill-column))))
821 texinfo-multitable-width-list))
823 ;; @item A1 @tab A2 @tab A3
824 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
825 "Return multitable row, as a string.
826 End of row is beginning of next @item or beginning of @end.
827 Cells within rows are separated by @tab."
828 (skip-chars-forward " \t")
829 (let* ((start (point))
831 (re-search-forward "@item\\|@end")
832 (match-beginning 0)))
833 (row (progn (goto-char end)
834 (skip-chars-backward " ")
835 ;; remove whitespace at end of argument
836 (delete-region (point) end)
837 (buffer-substring start (point)))))
838 (delete-region texinfo-command-start end)
841 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
842 (ptexinfmt-defun-if-void texinfo-multitable-item ()
843 "Format a row within a multicolumn table.
844 Cells in row are separated by @tab.
845 Widths of cells are specified by the arguments in the @multitable line.
846 All cells are made to be the same height.
847 This command is executed when texinfmt sees @item inside @multitable."
848 (let ((original-buffer (current-buffer))
849 (table-widths (reverse (car (cdr (car texinfo-stack)))))
850 (existing-fill-column fill-column)
854 (table-entry-height 0)
855 ;; unformatted row looks like: A1 @tab A2 @tab A3
856 ;; extract-row command deletes the source line in the table.
857 (unformated-row (texinfo-multitable-extract-row)))
858 ;; Use a temporary buffer
859 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
860 (delete-region (point-min) (point-max))
861 (insert unformated-row)
862 (goto-char (point-min))
863 ;; 1. Check for correct number of @tab in line.
864 (let ((tab-number 1)) ;; one @tab between two columns
865 (while (search-forward "@tab" nil t)
866 (setq tab-number (1+ tab-number)))
867 (if (/= tab-number (length table-widths))
868 (error "Wrong number of @tab's in a @multitable row")))
869 (goto-char (point-min))
870 ;; 2. Format each cell, and copy to a rectangle
871 ;; buffer looks like this: A1 @tab A2 @tab A3
872 ;; Cell #1: format up to @tab
873 ;; Cell #2: format up to @tab
874 ;; Cell #3: format up to eob
877 (setq end (save-excursion
878 (if (search-forward "@tab" nil 'move)
879 ;; Delete the @tab command, including the @-sign
882 (progn (forward-word -1) (1- (point)))))
884 ;; Set fill-column *wider* than needed to produce inter-column space
885 (setq fill-column (+ 1
886 texinfo-extra-inter-column-width
887 (nth table-column table-widths)))
888 (narrow-to-region start end)
889 ;; Remove whitespace before and after entry.
890 (skip-chars-forward " ")
891 (delete-region (point) (save-excursion (beginning-of-line) (point)))
892 (goto-char (point-max))
893 (skip-chars-backward " ")
894 (delete-region (point) (save-excursion (end-of-line) (point)))
895 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
896 ;; does not see an unterminated @multitable.
897 (let (texinfo-stack) ;; nil
898 (texinfo-format-scan))
899 (let (fill-prefix) ;; no fill prefix
900 (fill-region (point-min) (point-max)))
901 (setq table-entry-height
902 (max table-entry-height (count-lines (point-min) (point-max))))
903 ;; 3. Move point to end of bottom line, and pad that line to fill column.
904 (goto-char (point-min))
905 (forward-line (1- table-entry-height))
906 (let* ((beg (point)) ;; beginning of line
907 ;; add one more space for inter-column spacing
913 (current-column)))))) ;; end of existing line
915 (if (> needed-whitespace 0) needed-whitespace 1)
917 ;; now, put formatted cell into a rectangle
918 (set (intern (concat texinfo-multitable-rectangle-name
919 (int-to-string table-column)))
920 (extract-rectangle (point-min) (point)))
921 (delete-region (point-min) (point))
922 (goto-char (point-max))
923 (setq table-column (1+ table-column))
925 ;; 4. Add extra lines to rectangles so all are of same height
926 (let ((total-number-of-columns table-column)
929 (while (> table-column 0)
930 (let ((this-rectangle (int-to-string table-column)))
931 (while (< (length this-rectangle) table-entry-height)
932 (setq this-rectangle (append this-rectangle '("")))))
933 (setq table-column (1- table-column)))
934 ;; 5. Insert formatted rectangles in original buffer
935 (switch-to-buffer original-buffer)
936 (open-line table-entry-height)
937 (while (< column-number total-number-of-columns)
941 (concat texinfo-multitable-rectangle-name
942 (int-to-string column-number)))))
945 (setq column-number (1+ column-number))))
946 (kill-buffer texinfo-multitable-buffer-name)
947 (setq fill-column existing-fill-column)))
950 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
951 (let ((indexelts (symbol-value
952 (cdr (assoc (texinfo-parse-arg-discard)
953 texinfo-indexvar-alist))))
955 (insert "\n* Menu:\n\n")
956 (setq opoint (point))
957 (texinfo-print-index nil indexelts)
959 (if (memq system-type '(vax-vms windows-nt ms-dos))
960 (texinfo-sort-region opoint (point))
961 (shell-command-on-region opoint (point) "sort -fd" 1))))
964 ;; @copying ... @end copying
965 ;; that Emacs 21.4 and lesser and XEmacs don't support.
966 (if (fboundp 'texinfo-copying)
968 (defvar texinfo-copying-text ""
969 "Text of the copyright notice and copying permissions.")
971 (defun texinfo-copying ()
972 "Copy the copyright notice and copying permissions from the Texinfo file,
973 as indicated by the @copying ... @end copying command;
974 insert the text with the @insertcopying command."
975 (let ((beg (progn (beginning-of-line) (point)))
976 (end (progn (re-search-forward "^@end copying[ \t]*\n") (point))))
977 (setq texinfo-copying-text
978 (buffer-substring-no-properties
979 (save-excursion (goto-char beg) (forward-line 1) (point))
980 (save-excursion (goto-char end) (forward-line -1) (point))))
981 (delete-region beg end)))
983 (defun texinfo-insertcopying ()
984 "Insert the copyright notice and copying permissions from the Texinfo file,
985 which are indicated by the @copying ... @end copying command."
986 (insert (concat "\n" texinfo-copying-text)))
988 (defadvice texinfo-format-scan (before expand-@copying-section activate)
989 "Extract @copying and replace @insertcopying with it."
990 (goto-char (point-min))
991 (when (search-forward "@copying" nil t)
993 (while (search-forward "@insertcopying" nil t)
994 (delete-region (match-beginning 0) (match-end 0))
995 (texinfo-insertcopying))))
999 ;;; ptexinfmt.el ends here