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:
40 ;; @float, @caption, @shortcaption, @listoffloats
44 ;; @quotation (optional arguments)
45 ;; @acronym (optional argument)
46 ;; @dofirstparagraphindent
60 (defvar ptexinfmt-disable-broken-notice-flag t
61 "If non-nil disable notice, when call `ptexinfmt-broken-facility'.
62 This is last argument in `ptexinfmt-broken-facility'.")
64 (put 'ptexinfmt-broken-facility 'lisp-indent-function 'defun)
65 (defmacro ptexinfmt-broken-facility (facility docstring assertion
67 "Declare a symbol FACILITY is broken if ASSERTION is nil.
68 DOCSTRING will be printed if ASSERTION is nil and
69 `ptexinfmt-disable-broken-notice-flag' is nil."
70 (` (let ((facility '(, facility))
71 (docstring (, docstring))
72 (assertion (eval '(, assertion))))
73 (put facility 'broken (not assertion))
76 (put facility 'broken-docstring docstring)
77 (if ptexinfmt-disable-broken-notice-flag
79 (message "BROKEN FACILITY DETECTED: %s" docstring))))))
81 (put 'ptexinfmt-defun-if-broken 'lisp-indent-function 'defun)
82 (defmacro ptexinfmt-defun-if-broken (&rest args)
83 "Redefine a function just like `defun' if it is considered broken."
84 (let ((name (list 'quote (car args))))
85 (setq args (cdr args))
88 (if (get (, name) 'broken)
90 (function (lambda (,@ args)))))))))
92 (put 'ptexinfmt-defun-if-void 'lisp-indent-function 'defun)
93 (defmacro ptexinfmt-defun-if-void (&rest args)
94 "Define a function just like `defun' unless it is already defined."
95 (let ((name (list 'quote (car args))))
96 (setq args (cdr args))
99 (if (fboundp (, name))
102 (function (lambda (,@ args)))))))))
104 (put 'ptexinfmt-defvar-if-void 'lisp-indent-function 'defun)
105 (defmacro ptexinfmt-defvar-if-void (&rest args)
106 "Define a variable just like `defvar' unless it is already defined."
107 (let ((name (car args)))
108 (setq args (cdr args))
111 (if (boundp '(, name))
113 (defvar (, name) (,@ args)))))))
116 (ptexinfmt-broken-facility texinfo-format-printindex
117 "Can't sort on Mule for Windows."
118 (if (and (memq system-type '(windows-nt ms-dos))
119 ;;; I don't know version threshold.
120 ;;; (string< texinfmt-version "2.37 of 24 May 1997")
121 (boundp 'MULE) (not (featurep 'meadow))) ; Mule for Windows
126 (ptexinfmt-broken-facility texinfo-format-var
127 "Don't perse @var argument."
130 (let (texinfo-enclosure-list texinfo-alias-list)
132 (insert "@var{@asis{foo}}\n")
133 (texinfo-format-expand-region (point-min) (point-max))
138 (ptexinfmt-broken-facility texinfo-format-xref
139 "Can't format @xref, 1st argument is empty."
142 (let (texinfo-enclosure-list texinfo-alias-list)
144 (insert "@xref{, xref, , file}\n")
145 (texinfo-format-expand-region (point-min) (point-max))
150 (ptexinfmt-broken-facility texinfo-format-uref
151 "Parse twice @uref argument."
154 (let (texinfo-enclosure-list texinfo-alias-list)
156 (insert "@uref{mailto:foo@@noncommand.example.com}\n")
157 (texinfo-format-expand-region (point-min) (point-max))
162 (ptexinfmt-broken-facility texinfo-multitable-widths
163 "`texinfo-multitable-widths' unsupport wide-char."
164 (if (fboundp 'texinfo-multitable-widths)
166 (let ((str "
\e$BI}9-J8;z
\e(B"))
168 (insert (format " {%s}\n" str))
169 (goto-char (point-min))
170 (if (= (car (texinfo-multitable-widths)) (length str))
173 ;; function definition is void
176 (ptexinfmt-broken-facility texinfo-multitable-item
177 "`texinfo-multitable-item' unsupport wide-char."
178 (not (get 'texinfo-multitable-widths 'broken)))
181 ;;; Hardcopy and HTML (discard)
183 (put 'documentlanguage 'texinfo-format 'texinfo-discard-line-with-args)
184 (put 'documentencoding 'texinfo-format 'texinfo-discard-line-with-args)
185 (put 'documentdescription 'texinfo-format 'texinfo-discard-line-with-args)
188 (put 'smallbook 'texinfo-format 'texinfo-discard-line)
189 (put 'letterpaper 'texinfo-format 'texinfo-discard-line)
190 (put 'afourpaper 'texinfo-format 'texinfo-discard-line)
191 (put 'afourlatex 'texinfo-format 'texinfo-discard-line)
192 (put 'afourwide 'texinfo-format 'texinfo-discard-line)
193 (put 'afivepaper 'texinfo-format 'texinfo-discard-line)
194 (put 'pagesizes 'texinfo-format 'texinfo-discard-line-with-args)
197 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
198 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
201 (put 'setcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
202 (put 'setshortcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
203 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
206 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
207 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
208 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
209 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
210 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
211 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
212 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
215 (put 'page 'texinfo-format 'texinfo-discard-line)
216 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
218 ;; @s{} (makeinfo 4.8 or later)
219 (put 's 'texinfo-format 'texinfo-format-noop)
221 ;; @tie{} (makeinfo 4.3 or later)
222 (put 'tie 'texinfo-format 'texinfo-format-tie)
223 (ptexinfmt-defun-if-void texinfo-format-tie ()
224 (texinfo-parse-arg-discard)
230 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
231 (ptexinfmt-defun-if-void texinfo-format-dircategory ()
232 (let ((str (texinfo-parse-arg-discard)))
233 (delete-region (point)
235 (skip-chars-forward " ")
237 (insert "INFO-DIR-SECTION " str "\n")))
240 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
241 (ptexinfmt-defun-if-void texinfo-format-direntry ()
242 (texinfo-push-stack 'direntry nil)
243 (texinfo-discard-line)
244 (insert "START-INFO-DIR-ENTRY\n"))
246 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
247 (ptexinfmt-defun-if-void texinfo-end-direntry ()
248 (texinfo-discard-command)
249 (insert "END-INFO-DIR-ENTRY\n\n")
250 (texinfo-pop-stack 'direntry))
254 ;; @detailmenu ... @end detailmenu
255 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
256 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
258 ;; @smalldisplay ... @end smalldisplay
259 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
260 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
262 ;; @smallformat ... @end smallformat
263 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
264 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
266 ;; @cartouche ... @end cartouche
267 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
268 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
272 ;; @ifnottex ... @end ifnottex (makeinfo 3.11 or later)
273 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
274 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
276 ;; @ifnothtml ... @end ifnothtml (makeinfo 3.11 or later)
277 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
278 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
280 ;; @ifnotplaintext ... @end ifnotplaintext (makeinfo 4.2 or later)
281 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
282 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
284 ;; @ifnotdocbook ... @end ifnotdocbook (makeinfo 4.7 or later)
285 (put 'ifnotdocbook 'texinfo-format 'texinfo-discard-line)
286 (put 'ifnotdocbook 'texinfo-end 'texinfo-discard-command)
289 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
290 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
291 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
292 (delete-region texinfo-command-start
293 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
296 ;; @html ... @end html (makeinfo 3.11 or later)
297 (put 'html 'texinfo-format 'texinfo-format-html)
298 (ptexinfmt-defun-if-void texinfo-format-html ()
299 (delete-region texinfo-command-start
300 (progn (re-search-forward "@end html[ \t]*\n")
303 ;; @docbook ... @end docbook (makeinfo 4.7 or later)
304 (put 'docbook 'texinfo-format 'texinfo-format-docbook)
305 (ptexinfmt-defun-if-void texinfo-format-docbook ()
306 (delete-region texinfo-command-start
307 (progn (re-search-forward "@end docbook[ \t]*\n")
310 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
311 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
312 (defun texinfo-format-ifhtml ()
313 (delete-region texinfo-command-start
314 (progn (re-search-forward "@end ifhtml[ \t]*\n")
317 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
318 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
319 (ptexinfmt-defun-if-void texinfo-format-ifplaintext ()
320 (delete-region texinfo-command-start
321 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
324 ;; @ifdocbook ... @end ifdocbook (makeinfo 4.7 or later)
325 (put 'ifdocbook 'texinfo-format 'texinfo-format-ifdocbook)
326 (ptexinfmt-defun-if-void texinfo-format-ifdocbook ()
327 (delete-region texinfo-command-start
328 (progn (re-search-forward "@end ifdocbook[ \t]*\n")
334 ;; @indicateurl, @url, @env, @command,
335 (put 'env 'texinfo-format 'texinfo-format-code)
336 (put 'command 'texinfo-format 'texinfo-format-code)
338 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
339 (put 'url 'texinfo-format 'texinfo-format-uref) ; Texinfo 4.7
342 (put 'acronym 'texinfo-format 'texinfo-format-var)
344 (ptexinfmt-defun-if-broken texinfo-format-var ()
345 (let ((arg (texinfo-parse-expanded-arg)))
346 (texinfo-discard-command)
347 (insert (upcase arg))))
350 (put 'key 'texinfo-format 'texinfo-format-key)
351 (ptexinfmt-defun-if-void texinfo-format-key ()
352 (insert (texinfo-parse-arg-discard))
353 (goto-char texinfo-command-start))
355 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
356 (put 'email 'texinfo-format 'texinfo-format-email)
357 (ptexinfmt-defun-if-void texinfo-format-email ()
358 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
359 Insert < ... > around EMAIL-ADDRESS."
360 (let ((args (texinfo-format-parse-args)))
361 (texinfo-discard-command)
364 (insert (nth 1 args) " <" (nth 0 args) ">")
365 (insert "<" (nth 0 args) ">"))))
368 (put 'option 'texinfo-format 'texinfo-format-option)
369 (ptexinfmt-defun-if-void texinfo-format-option ()
370 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
371 ;; `looking-at-backward' not available in v. 18.57, 20.2
372 ;; searched-for character is a control-H
373 (if (not (search-backward "\010"
374 (save-excursion (beginning-of-line) (point))
376 (insert "`" (texinfo-parse-arg-discard) "'")
377 (insert (texinfo-parse-arg-discard)))
378 (goto-char texinfo-command-start))
380 ;; @verb{<char>TEXT<char>} (makeinfo 4.1 or later)
381 (put 'verb 'texinfo-format 'texinfo-format-verb)
382 (ptexinfmt-defun-if-void texinfo-format-verb ()
383 "Format text between non-quoted unique delimiter characters verbatim.
384 Enclose the verbatim text, including the delimiters, in braces. Print
385 text exactly as written (but not the delimiters) in a fixed-width.
387 For example, @verb\{|@|\} results in @ and
388 @verb\{+@'e?`!`+} results in @'e?`!`."
390 (let ((delimiter (buffer-substring-no-properties
391 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
392 (unless (looking-at "{")
393 (error "Not found: @verb start brace"))
394 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
395 (search-forward delimiter))
396 (delete-backward-char 1)
397 (unless (looking-at "}")
398 (error "Not found: @verb end brace"))
402 ;;; @LaTeX, @registeredsymbol{}
403 (put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX)
404 (ptexinfmt-defun-if-void texinfo-format-LaTeX ()
405 (texinfo-parse-arg-discard)
408 (put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol)
409 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
410 (texinfo-parse-arg-discard)
413 ;;; Accents and Special characters
414 ;; @pounds{} ==> # Pounds Sterling
415 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
416 (ptexinfmt-defun-if-void texinfo-format-pounds ()
417 (texinfo-parse-arg-discard)
420 ;; @ordf{} ==> a Spanish feminine
421 (put 'ordf 'texinfo-format 'texinfo-format-ordf)
422 (ptexinfmt-defun-if-void texinfo-format-ordf ()
423 (texinfo-parse-arg-discard)
426 ;; @ordm{} ==> o Spanish masculine
427 (put 'ordm 'texinfo-format 'texinfo-format-ordm)
428 (ptexinfmt-defun-if-void texinfo-format-ordm ()
429 (texinfo-parse-arg-discard)
432 ;; @OE{} ==> OE French-OE-ligature
433 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
434 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
435 (insert "OE" (texinfo-parse-arg-discard))
436 (goto-char texinfo-command-start))
439 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
440 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
441 (insert "oe" (texinfo-parse-arg-discard))
442 (goto-char texinfo-command-start))
444 ;; @AA{} ==> AA Scandinavian-A-with-circle
445 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
446 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
447 (insert "AA" (texinfo-parse-arg-discard))
448 (goto-char texinfo-command-start))
451 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
452 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
453 (insert "aa" (texinfo-parse-arg-discard))
454 (goto-char texinfo-command-start))
456 ;; @AE{} ==> AE Latin-Scandinavian-AE
457 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
458 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
459 (insert "AE" (texinfo-parse-arg-discard))
460 (goto-char texinfo-command-start))
463 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
464 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
465 (insert "ae" (texinfo-parse-arg-discard))
466 (goto-char texinfo-command-start))
468 ;; @ss{} ==> ss German-sharp-S
469 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
470 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
471 (insert "ss" (texinfo-parse-arg-discard))
472 (goto-char texinfo-command-start))
474 ;; @questiondown{} ==> ? upside-down-question-mark
475 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
476 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
477 (insert "?" (texinfo-parse-arg-discard))
478 (goto-char texinfo-command-start))
480 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
481 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
482 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
483 (insert "!" (texinfo-parse-arg-discard))
484 (goto-char texinfo-command-start))
486 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
487 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
488 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
489 (insert (texinfo-parse-arg-discard) "/L")
490 (goto-char texinfo-command-start))
492 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
493 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
494 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
495 (insert (texinfo-parse-arg-discard) "/l")
496 (goto-char texinfo-command-start))
498 ;; @O{} ==> O/ Scandinavian O-with-slash
499 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
500 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
501 (insert (texinfo-parse-arg-discard) "O/")
502 (goto-char texinfo-command-start))
504 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
505 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
506 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
507 (insert (texinfo-parse-arg-discard) "o/")
508 (goto-char texinfo-command-start))
510 ;; @,{c} ==> c, cedilla accent
511 (put ', 'texinfo-format 'texinfo-format-cedilla-accent)
512 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
513 (insert (texinfo-parse-arg-discard) ",")
514 (goto-char texinfo-command-start))
517 ;; @dotaccent{o} ==> .o overdot-accent
518 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
519 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
520 (insert "." (texinfo-parse-arg-discard))
521 (goto-char texinfo-command-start))
523 ;; @ubaraccent{o} ==> _o underbar-accent
524 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
525 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
526 (insert "_" (texinfo-parse-arg-discard))
527 (goto-char texinfo-command-start))
529 ;; @udotaccent{o} ==> o-. underdot-accent
530 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
531 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
532 (insert (texinfo-parse-arg-discard) "-.")
533 (goto-char texinfo-command-start))
535 ;; @H{o} ==> ""o long Hungarian umlaut
536 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
537 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
538 (insert "\"\"" (texinfo-parse-arg-discard))
539 (goto-char texinfo-command-start))
541 ;; @ringaccent{o} ==> *o ring accent
542 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
543 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
544 (insert "*" (texinfo-parse-arg-discard))
545 (goto-char texinfo-command-start))
547 ;; @tieaccent{oo} ==> [oo tie after accent
548 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
549 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
550 (insert "[" (texinfo-parse-arg-discard))
551 (goto-char texinfo-command-start))
553 ;; @u{o} ==> (o breve accent
554 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
555 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
556 (insert "(" (texinfo-parse-arg-discard))
557 (goto-char texinfo-command-start))
559 ;; @v{o} ==> <o hacek accent
560 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
561 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
562 (insert "<" (texinfo-parse-arg-discard))
563 (goto-char texinfo-command-start))
565 ;; @dotless{i} ==> i dotless i and dotless j
566 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
567 (ptexinfmt-defun-if-void texinfo-format-dotless ()
568 (insert (texinfo-parse-arg-discard))
569 (goto-char texinfo-command-start))
572 (put '\. 'texinfo-format 'texinfo-format-\.)
573 (ptexinfmt-defun-if-void texinfo-format-\. ()
574 (texinfo-discard-command)
578 (put '\: 'texinfo-format 'texinfo-format-\:)
579 (ptexinfmt-defun-if-void texinfo-format-\: ()
580 (texinfo-discard-command))
583 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
584 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
585 (texinfo-discard-command))
588 (put '\/ 'texinfo-format 'texinfo-format-\/)
589 (ptexinfmt-defun-if-void texinfo-format-\/ ()
590 (texinfo-discard-command))
595 (put 'ref 'texinfo-format 'texinfo-format-xref)
597 (ptexinfmt-defun-if-broken texinfo-format-xref ()
598 (let ((args (texinfo-format-parse-args)))
599 (texinfo-discard-command)
601 (let ((fname (or (nth 1 args) (nth 2 args))))
602 (if (null (or fname (nth 3 args)))
603 (insert (nth 0 args) "::")
604 (insert (or fname (nth 0 args)) ": ")
606 (insert "(" (nth 3 args) ")"))
607 (unless (null (nth 0 args))
608 (insert (nth 0 args)))))))
610 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
611 (put 'uref 'texinfo-format 'texinfo-format-uref)
612 (ptexinfmt-defun-if-broken texinfo-format-uref ()
613 "Format URL and optional URL-TITLE.
614 Insert ` ... ' around URL if no URL-TITLE argument;
615 otherwise, insert URL-TITLE followed by URL in parentheses."
616 (let ((args (texinfo-format-parse-args)))
617 (texinfo-discard-command)
620 (insert (nth 1 args) " (" (nth 0 args) ")")
621 (insert "`" (nth 0 args) "'"))))
624 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
625 (ptexinfmt-defun-if-void texinfo-format-inforef ()
626 (let ((args (texinfo-format-parse-args)))
627 (texinfo-discard-command)
629 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
630 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
635 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
636 ;; - Info-tagify suport @anthor-*-refill.
637 ;; - info.el support Ref in Tag table.
638 (unless (get 'anchor 'texinfo-format)
639 (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
643 ;;; New command definition
644 ;; @alias NEW=EXISTING
645 (put 'alias 'texinfo-format 'texinfo-alias)
646 (ptexinfmt-defun-if-void texinfo-alias ()
647 (let ((start (1- (point)))
649 (skip-chars-forward " ")
650 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
651 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
652 (error "Invalid alias command")
653 (setq texinfo-alias-list
656 (buffer-substring (match-beginning 1) (match-end 1))
657 (buffer-substring (match-beginning 2) (match-end 2)))
659 (texinfo-discard-command))))
663 ;; @exampleindent INDENT (makeinfo 4.0 or later)
665 ;; @paragraphindent INDENT (makeinfo 4.0 or later)
666 ;; INDENT: asis, 0, n
668 ;; @firstparagraphindent WORD (makeinfo 4.6 or later)
669 ;; WORD: none, insert
674 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
675 (put 'image 'texinfo-format 'texinfo-format-image)
676 (ptexinfmt-defun-if-void texinfo-format-image ()
677 ;; I don't know makeinfo parse FILENAME.
678 (let ((args (texinfo-format-parse-args))
680 (when (null (nth 0 args))
681 (error "Invalid image command"))
682 (texinfo-discard-command)
683 ;; makeinfo uses FILENAME.txt
684 (setq filename (format "%s.txt" (nth 0 args)))
685 (message "Reading included file: %s" filename)
686 ;; verbatim for Info output
687 (goto-char (+ (point) (cadr (insert-file-contents filename))))
688 (message "Reading included file: %s...done" filename)))
692 ;;; @multitable ... @end multitable
693 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
694 "*Number of extra spaces between entries (columns) in @multitable.")
696 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
697 "*multitable-temporary-buffer*")
698 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
699 "texinfo-multitable-temp-")
701 ;; These commands are defined in texinfo.tex for printed output.
702 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
703 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
704 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
705 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
707 (put 'multitable 'texinfo-format 'texinfo-multitable)
709 (ptexinfmt-defun-if-void texinfo-multitable ()
710 "Produce multi-column tables."
712 ;; This function pushes information onto the `texinfo-stack'.
713 ;; A stack element consists of:
714 ;; - type-of-command, i.e., multitable
715 ;; - the information about column widths, and
716 ;; - the position of texinfo-command-start.
717 ;; e.g., ('multitable (1 2 3 4) 123)
718 ;; The command line is then deleted.
721 ;; push width information on stack
722 (texinfo-multitable-widths))
723 (texinfo-discard-line-with-args))
725 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
726 (ptexinfmt-defun-if-void texinfo-end-multitable ()
727 "Discard the @end multitable line and pop the stack of multitable."
728 (texinfo-discard-command)
729 (texinfo-pop-stack 'multitable))
731 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
732 "Return list of widths of each column in a multi-column table."
733 (let (texinfo-multitable-width-list)
735 ;; @multitable @columnfractions .25 .3 .45
738 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
739 ;; Place point before first argument
740 (skip-chars-forward " \t")
742 ;; Check for common misspelling
743 ((looking-at "@columnfraction ")
744 (error "In @multitable, @columnfractions misspelled"))
745 ;; Case 1: @columnfractions .25 .3 .45
746 ((looking-at "@columnfractions")
749 (setq texinfo-multitable-width-list
753 (* fill-column (read (get-buffer (current-buffer))))))
754 texinfo-multitable-width-list))))
756 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
758 (let ((start-of-templates (point)))
760 (skip-chars-forward " \t")
761 (let* ((start-of-template (1+ (point)))
763 ;; forward-sexp works with braces in Texinfo mode
764 (progn (forward-sexp 1) (1- (point)))))
765 (setq texinfo-multitable-width-list
767 (goto-char end-of-template)
770 (goto-char start-of-template)
772 texinfo-multitable-width-list))
773 ;; Remove carriage return from within a template, if any.
774 ;; This helps those those who want to use more than
775 ;; one line's worth of words in @multitable line.
776 (narrow-to-region start-of-template end-of-template)
777 (goto-char (point-min))
778 (while (search-forward "\n" nil t)
780 (goto-char (point-max))
787 You probably need to specify column widths for @multitable correctly")))
788 ;; Check whether columns fit on page.
789 (let ((desired-columns
791 ;; between column spaces
792 (length texinfo-multitable-width-list)
793 ;; additional between column spaces, if any
794 texinfo-extra-inter-column-width
795 ;; sum of spaces for each entry
796 (apply '+ texinfo-multitable-width-list))))
797 (if (> desired-columns fill-column)
799 Multi-column table width, %d chars, is greater than page width, %d chars."
800 desired-columns fill-column))))
801 texinfo-multitable-width-list))
803 ;; @item A1 @tab A2 @tab A3
804 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
805 "Return multitable row, as a string.
806 End of row is beginning of next @item or beginning of @end.
807 Cells within rows are separated by @tab."
808 (skip-chars-forward " \t")
809 (let* ((start (point))
811 (re-search-forward "@item\\|@end")
812 (match-beginning 0)))
813 (row (progn (goto-char end)
814 (skip-chars-backward " ")
815 ;; remove whitespace at end of argument
816 (delete-region (point) end)
817 (buffer-substring start (point)))))
818 (delete-region texinfo-command-start end)
821 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
822 (ptexinfmt-defun-if-void texinfo-multitable-item ()
823 "Format a row within a multicolumn table.
824 Cells in row are separated by @tab.
825 Widths of cells are specified by the arguments in the @multitable line.
826 All cells are made to be the same height.
827 This command is executed when texinfmt sees @item inside @multitable."
828 (let ((original-buffer (current-buffer))
829 (table-widths (reverse (car (cdr (car texinfo-stack)))))
830 (existing-fill-column fill-column)
834 (table-entry-height 0)
835 ;; unformatted row looks like: A1 @tab A2 @tab A3
836 ;; extract-row command deletes the source line in the table.
837 (unformated-row (texinfo-multitable-extract-row)))
838 ;; Use a temporary buffer
839 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
840 (delete-region (point-min) (point-max))
841 (insert unformated-row)
842 (goto-char (point-min))
843 ;; 1. Check for correct number of @tab in line.
844 (let ((tab-number 1)) ;; one @tab between two columns
845 (while (search-forward "@tab" nil t)
846 (setq tab-number (1+ tab-number)))
847 (if (/= tab-number (length table-widths))
848 (error "Wrong number of @tab's in a @multitable row")))
849 (goto-char (point-min))
850 ;; 2. Format each cell, and copy to a rectangle
851 ;; buffer looks like this: A1 @tab A2 @tab A3
852 ;; Cell #1: format up to @tab
853 ;; Cell #2: format up to @tab
854 ;; Cell #3: format up to eob
857 (setq end (save-excursion
858 (if (search-forward "@tab" nil 'move)
859 ;; Delete the @tab command, including the @-sign
862 (progn (forward-word -1) (1- (point)))))
864 ;; Set fill-column *wider* than needed to produce inter-column space
865 (setq fill-column (+ 1
866 texinfo-extra-inter-column-width
867 (nth table-column table-widths)))
868 (narrow-to-region start end)
869 ;; Remove whitespace before and after entry.
870 (skip-chars-forward " ")
871 (delete-region (point) (save-excursion (beginning-of-line) (point)))
872 (goto-char (point-max))
873 (skip-chars-backward " ")
874 (delete-region (point) (save-excursion (end-of-line) (point)))
875 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
876 ;; does not see an unterminated @multitable.
877 (let (texinfo-stack) ;; nil
878 (texinfo-format-scan))
879 (let (fill-prefix) ;; no fill prefix
880 (fill-region (point-min) (point-max)))
881 (setq table-entry-height
882 (max table-entry-height (count-lines (point-min) (point-max))))
883 ;; 3. Move point to end of bottom line, and pad that line to fill column.
884 (goto-char (point-min))
885 (forward-line (1- table-entry-height))
886 (let* ((beg (point)) ;; beginning of line
887 ;; add one more space for inter-column spacing
893 (current-column)))))) ;; end of existing line
895 (if (> needed-whitespace 0) needed-whitespace 1)
897 ;; now, put formatted cell into a rectangle
898 (set (intern (concat texinfo-multitable-rectangle-name
899 (int-to-string table-column)))
900 (extract-rectangle (point-min) (point)))
901 (delete-region (point-min) (point))
902 (goto-char (point-max))
903 (setq table-column (1+ table-column))
905 ;; 4. Add extra lines to rectangles so all are of same height
906 (let ((total-number-of-columns table-column)
909 (while (> table-column 0)
910 (let ((this-rectangle (int-to-string table-column)))
911 (while (< (length this-rectangle) table-entry-height)
912 (setq this-rectangle (append this-rectangle '("")))))
913 (setq table-column (1- table-column)))
914 ;; 5. Insert formatted rectangles in original buffer
915 (switch-to-buffer original-buffer)
916 (open-line table-entry-height)
917 (while (< column-number total-number-of-columns)
921 (concat texinfo-multitable-rectangle-name
922 (int-to-string column-number)))))
925 (setq column-number (1+ column-number))))
926 (kill-buffer texinfo-multitable-buffer-name)
927 (setq fill-column existing-fill-column)))
930 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
931 (let ((indexelts (symbol-value
932 (cdr (assoc (texinfo-parse-arg-discard)
933 texinfo-indexvar-alist))))
935 (insert "\n* Menu:\n\n")
936 (setq opoint (point))
937 (texinfo-print-index nil indexelts)
939 (if (memq system-type '(vax-vms windows-nt ms-dos))
940 (texinfo-sort-region opoint (point))
941 (shell-command-on-region opoint (point) "sort -fd" 1))))
945 ;;; ptexinfmt.el ends here