1 ;;; ptexinfmt.el -- portable Texinfo formatter.
3 ;; Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993,
4 ;; 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
5 ;; Copyright (C) 1999 Yoshiki Hayashi <yoshiki@xemacs.org>
6 ;; Copyright (C) 2000, 2001, 2002 TAKAHASHI Kaoru <kaoru@kaisei.org>
8 ;; Author: TAKAHASHI Kaoru <kaoru@kaisei.org>
9 ;; Yoshiki Hayashi <yoshiki@xemacs.org>
10 ;; Katsumi Yamaoka <yamaoka@jpl.org>
11 ;; Maintainer: TAKAHASHI Kaoru <kaoru@kaisei.org>
12 ;; Created: 7 Jul 2000
13 ;; Keywords: maint, tex, docs, emulation, compatibility
15 ;; This program is free software; you can redistribute it and/or
16 ;; modify it under the terms of the GNU General Public License as
17 ;; published by the Free Software Foundation; either version 2, or (at
18 ;; your option) any later version.
20 ;; This program is distributed in the hope that it will be useful, but
21 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 ;; General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 ;; Boston, MA 02110-1301, USA.
32 ;; Original code: Yoshiki Hayashi <yoshiki@xemacs.org>
33 ;; makeinfo.el (gnujdoc project)
35 ;; Support texinfmt.el 2.32 or later.
37 ;; Modified by Yamaoka not to use APEL functions.
39 ;; Unimplemented command:
41 ;; @float, @caption, @shortcaption, @listoffloats
45 ;; @quotation (optional arguments)
46 ;; @acronym (optional argument)
47 ;; @dofirstparagraphindent
56 ;; @quotedblleft @quotedblright
57 ;; @quoteleft @quoteright @quotedblbase @quotesinglbase
58 ;; @guillemetleft @guillemetright @guilsinglleft @guilsinglright.
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."
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)
195 (put 'fonttextsize 'texinfo-format 'texinfo-discard-line-with-args)
198 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
199 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
202 (put 'setcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
203 (put 'setshortcontentsaftertitlepage 'texinfo-format 'texinfo-discard-line)
204 (put 'novalidate 'texinfo-format 'texinfo-discard-line-with-args)
205 (put 'frenchspacing 'texinfo-format 'texinfo-discard-line-with-args)
208 (put 'headings 'texinfo-format 'texinfo-discard-line-with-args)
209 (put 'evenfooting 'texinfo-format 'texinfo-discard-line-with-args)
210 (put 'evenheading 'texinfo-format 'texinfo-discard-line-with-args)
211 (put 'oddfooting 'texinfo-format 'texinfo-discard-line-with-args)
212 (put 'oddheading 'texinfo-format 'texinfo-discard-line-with-args)
213 (put 'everyfooting 'texinfo-format 'texinfo-discard-line-with-args)
214 (put 'everyheading 'texinfo-format 'texinfo-discard-line-with-args)
217 (put 'page 'texinfo-format 'texinfo-discard-line)
218 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
220 ;; @slanted{} (makeinfo 4.8 or later)
221 (put 'slanted 'texinfo-format 'texinfo-format-noop)
223 ;; @sansserif{} (makeinfo 4.8 or later)
224 (put 'sansserif 'texinfo-format 'texinfo-format-noop)
226 ;; @tie{} (makeinfo 4.3 or later)
227 (put 'tie 'texinfo-format 'texinfo-format-tie)
228 (ptexinfmt-defun-if-void texinfo-format-tie ()
229 (texinfo-parse-arg-discard)
235 (put 'dircategory 'texinfo-format 'texinfo-format-dircategory)
236 (ptexinfmt-defun-if-void texinfo-format-dircategory ()
237 (let ((str (texinfo-parse-arg-discard)))
238 (delete-region (point)
240 (skip-chars-forward " ")
242 (insert "INFO-DIR-SECTION " str "\n")))
245 (put 'direntry 'texinfo-format 'texinfo-format-direntry)
246 (ptexinfmt-defun-if-void texinfo-format-direntry ()
247 (texinfo-push-stack 'direntry nil)
248 (texinfo-discard-line)
249 (insert "START-INFO-DIR-ENTRY\n"))
251 (put 'direntry 'texinfo-end 'texinfo-end-direntry)
252 (ptexinfmt-defun-if-void texinfo-end-direntry ()
253 (texinfo-discard-command)
254 (insert "END-INFO-DIR-ENTRY\n\n")
255 (texinfo-pop-stack 'direntry))
259 ;; @detailmenu ... @end detailmenu
260 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
261 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
263 ;; @smalldisplay ... @end smalldisplay
264 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
265 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
267 ;; @smallformat ... @end smallformat
268 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
269 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
271 ;; @cartouche ... @end cartouche
272 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
273 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
277 ;; @ifnottex ... @end ifnottex (makeinfo 3.11 or later)
278 (put 'ifnottex 'texinfo-format 'texinfo-discard-line)
279 (put 'ifnottex 'texinfo-end 'texinfo-discard-command)
281 ;; @ifnothtml ... @end ifnothtml (makeinfo 3.11 or later)
282 (put 'ifnothtml 'texinfo-format 'texinfo-discard-line)
283 (put 'ifnothtml 'texinfo-end 'texinfo-discard-command)
285 ;; @ifnotplaintext ... @end ifnotplaintext (makeinfo 4.2 or later)
286 (put 'ifnotplaintext 'texinfo-format 'texinfo-discard-line)
287 (put 'ifnotplaintext 'texinfo-end 'texinfo-discard-command)
289 ;; @ifnotdocbook ... @end ifnotdocbook (makeinfo 4.7 or later)
290 (put 'ifnotdocbook 'texinfo-format 'texinfo-discard-line)
291 (put 'ifnotdocbook 'texinfo-end 'texinfo-discard-command)
293 ;; @ifnotinfo ... @end ifnotinfo (makeinfo 3.11 or later)
294 (put 'ifnotinfo 'texinfo-format 'texinfo-format-ifnotinfo)
295 (ptexinfmt-defun-if-void texinfo-format-ifnotinfo ()
296 (delete-region texinfo-command-start
297 (progn (re-search-forward "@end ifnotinfo[ \t]*\n")
300 ;; @html ... @end html (makeinfo 3.11 or later)
301 (put 'html 'texinfo-format 'texinfo-format-html)
302 (ptexinfmt-defun-if-void texinfo-format-html ()
303 (delete-region texinfo-command-start
304 (progn (re-search-forward "@end html[ \t]*\n")
307 ;; @docbook ... @end docbook (makeinfo 4.7 or later)
308 (put 'docbook 'texinfo-format 'texinfo-format-docbook)
309 (ptexinfmt-defun-if-void texinfo-format-docbook ()
310 (delete-region texinfo-command-start
311 (progn (re-search-forward "@end docbook[ \t]*\n")
314 ;; @ifhtml ... @end ifhtml (makeinfo 3.8 or later)
315 (put 'ifhtml 'texinfo-format 'texinfo-format-ifhtml)
316 (defun texinfo-format-ifhtml ()
317 (delete-region texinfo-command-start
318 (progn (re-search-forward "@end ifhtml[ \t]*\n")
321 ;; @ifplaintext ... @end ifplaintext (makeinfo 4.2 or later)
322 (put 'ifplaintext 'texinfo-format 'texinfo-format-ifplaintext)
323 (ptexinfmt-defun-if-void texinfo-format-ifplaintext ()
324 (delete-region texinfo-command-start
325 (progn (re-search-forward "@end ifplaintext[ \t]*\n")
328 ;; @ifdocbook ... @end ifdocbook (makeinfo 4.7 or later)
329 (put 'ifdocbook 'texinfo-format 'texinfo-format-ifdocbook)
330 (ptexinfmt-defun-if-void texinfo-format-ifdocbook ()
331 (delete-region texinfo-command-start
332 (progn (re-search-forward "@end ifdocbook[ \t]*\n")
337 ;; @indicateurl, @url, @env, @command,
338 (put 'env 'texinfo-format 'texinfo-format-code)
339 (put 'command 'texinfo-format 'texinfo-format-code)
341 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
342 (put 'url 'texinfo-format 'texinfo-format-uref) ; Texinfo 4.7
345 (put 'acronym 'texinfo-format 'texinfo-format-var)
347 (ptexinfmt-defun-if-broken texinfo-format-var ()
348 (let ((arg (texinfo-parse-expanded-arg)))
349 (texinfo-discard-command)
350 (insert (upcase arg))))
353 (put 'key 'texinfo-format 'texinfo-format-key)
354 (ptexinfmt-defun-if-void texinfo-format-key ()
355 (insert (texinfo-parse-arg-discard))
356 (goto-char texinfo-command-start))
358 ;; @email{EMAIL-ADDRESS[, DISPLAYED-TEXT]}
359 (put 'email 'texinfo-format 'texinfo-format-email)
360 (ptexinfmt-defun-if-void texinfo-format-email ()
361 "Format EMAIL-ADDRESS and optional DISPLAYED-TXT.
362 Insert < ... > around EMAIL-ADDRESS."
363 (let ((args (texinfo-format-parse-args)))
364 (texinfo-discard-command)
367 (insert (nth 1 args) " <" (nth 0 args) ">")
368 (insert "<" (nth 0 args) ">"))))
371 (put 'option 'texinfo-format 'texinfo-format-option)
372 (ptexinfmt-defun-if-void texinfo-format-option ()
373 "Insert ` ... ' around arg unless inside a table; in that case, no quotes."
374 ;; `looking-at-backward' not available in v. 18.57, 20.2
375 ;; searched-for character is a control-H
376 (if (not (search-backward "\010"
377 (save-excursion (beginning-of-line) (point))
379 (insert "`" (texinfo-parse-arg-discard) "'")
380 (insert (texinfo-parse-arg-discard)))
381 (goto-char texinfo-command-start))
383 ;; @verb{<char>TEXT<char>} (makeinfo 4.1 or later)
384 (put 'verb 'texinfo-format 'texinfo-format-verb)
385 (ptexinfmt-defun-if-void texinfo-format-verb ()
386 "Format text between non-quoted unique delimiter characters verbatim.
387 Enclose the verbatim text, including the delimiters, in braces. Print
388 text exactly as written (but not the delimiters) in a fixed-width.
390 For example, @verb\{|@|\} results in @ and
391 @verb\{+@'e?`!`+} results in @'e?`!`."
393 (let ((delimiter (buffer-substring-no-properties
394 (1+ texinfo-command-end) (+ 2 texinfo-command-end))))
395 (unless (looking-at "{")
396 (error "Not found: @verb start brace"))
397 (delete-region texinfo-command-start (+ 2 texinfo-command-end))
398 (search-forward delimiter))
399 (delete-backward-char 1)
400 (unless (looking-at "}")
401 (error "Not found: @verb end brace"))
405 ;;; @LaTeX, @registeredsymbol{}
406 (put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX)
407 (ptexinfmt-defun-if-void texinfo-format-LaTeX ()
408 (texinfo-parse-arg-discard)
411 (put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol)
412 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
413 (texinfo-parse-arg-discard)
416 ;;; Accents and Special characters
418 (put 'euro 'texinfo-format 'texinfo-format-euro)
419 (ptexinfmt-defun-if-void texinfo-format-euro ()
420 (texinfo-parse-arg-discard)
423 ;; @pounds{} ==> # Pounds Sterling
424 (put 'pounds 'texinfo-format 'texinfo-format-pounds)
425 (ptexinfmt-defun-if-void texinfo-format-pounds ()
426 (texinfo-parse-arg-discard)
429 ;; @ordf{} ==> a Spanish feminine
430 (put 'ordf 'texinfo-format 'texinfo-format-ordf)
431 (ptexinfmt-defun-if-void texinfo-format-ordf ()
432 (texinfo-parse-arg-discard)
435 ;; @ordm{} ==> o Spanish masculine
436 (put 'ordm 'texinfo-format 'texinfo-format-ordm)
437 (ptexinfmt-defun-if-void texinfo-format-ordm ()
438 (texinfo-parse-arg-discard)
441 ;; @OE{} ==> OE French-OE-ligature
442 (put 'OE 'texinfo-format 'texinfo-format-French-OE-ligature)
443 (ptexinfmt-defun-if-void texinfo-format-French-OE-ligature ()
444 (insert "OE" (texinfo-parse-arg-discard))
445 (goto-char texinfo-command-start))
448 (put 'oe 'texinfo-format 'texinfo-format-French-oe-ligature)
449 (ptexinfmt-defun-if-void texinfo-format-French-oe-ligature () ; lower case
450 (insert "oe" (texinfo-parse-arg-discard))
451 (goto-char texinfo-command-start))
453 ;; @AA{} ==> AA Scandinavian-A-with-circle
454 (put 'AA 'texinfo-format 'texinfo-format-Scandinavian-A-with-circle)
455 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-A-with-circle ()
456 (insert "AA" (texinfo-parse-arg-discard))
457 (goto-char texinfo-command-start))
460 (put 'aa 'texinfo-format 'texinfo-format-Scandinavian-a-with-circle)
461 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-a-with-circle () ; lower case
462 (insert "aa" (texinfo-parse-arg-discard))
463 (goto-char texinfo-command-start))
465 ;; @AE{} ==> AE Latin-Scandinavian-AE
466 (put 'AE 'texinfo-format 'texinfo-format-Latin-Scandinavian-AE)
467 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-AE ()
468 (insert "AE" (texinfo-parse-arg-discard))
469 (goto-char texinfo-command-start))
472 (put 'ae 'texinfo-format 'texinfo-format-Latin-Scandinavian-ae)
473 (ptexinfmt-defun-if-void texinfo-format-Latin-Scandinavian-ae () ; lower case
474 (insert "ae" (texinfo-parse-arg-discard))
475 (goto-char texinfo-command-start))
477 ;; @ss{} ==> ss German-sharp-S
478 (put 'ss 'texinfo-format 'texinfo-format-German-sharp-S)
479 (ptexinfmt-defun-if-void texinfo-format-German-sharp-S ()
480 (insert "ss" (texinfo-parse-arg-discard))
481 (goto-char texinfo-command-start))
483 ;; @questiondown{} ==> ? upside-down-question-mark
484 (put 'questiondown 'texinfo-format 'texinfo-format-upside-down-question-mark)
485 (ptexinfmt-defun-if-void texinfo-format-upside-down-question-mark ()
486 (insert "?" (texinfo-parse-arg-discard))
487 (goto-char texinfo-command-start))
489 ;; @exclamdown{} ==> ! upside-down-exclamation-mark
490 (put 'exclamdown 'texinfo-format 'texinfo-format-upside-down-exclamation-mark)
491 (ptexinfmt-defun-if-void texinfo-format-upside-down-exclamation-mark ()
492 (insert "!" (texinfo-parse-arg-discard))
493 (goto-char texinfo-command-start))
495 ;; @L{} ==> L/ Polish suppressed-L (Lslash)
496 (put 'L 'texinfo-format 'texinfo-format-Polish-suppressed-L)
497 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-L ()
498 (insert (texinfo-parse-arg-discard) "/L")
499 (goto-char texinfo-command-start))
501 ;; @l{} ==> l/ Polish suppressed-L (Lslash) (lower case)
502 (put 'l 'texinfo-format 'texinfo-format-Polish-suppressed-l-lower-case)
503 (ptexinfmt-defun-if-void texinfo-format-Polish-suppressed-l-lower-case ()
504 (insert (texinfo-parse-arg-discard) "/l")
505 (goto-char texinfo-command-start))
507 ;; @O{} ==> O/ Scandinavian O-with-slash
508 (put 'O 'texinfo-format 'texinfo-format-Scandinavian-O-with-slash)
509 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-O-with-slash ()
510 (insert (texinfo-parse-arg-discard) "O/")
511 (goto-char texinfo-command-start))
513 ;; @o{} ==> o/ Scandinavian O-with-slash (lower case)
514 (put 'o 'texinfo-format 'texinfo-format-Scandinavian-o-with-slash-lower-case)
515 (ptexinfmt-defun-if-void texinfo-format-Scandinavian-o-with-slash-lower-case ()
516 (insert (texinfo-parse-arg-discard) "o/")
517 (goto-char texinfo-command-start))
519 ;; @,{c} ==> c, cedilla accent
520 (put '\, 'texinfo-format 'texinfo-format-cedilla-accent)
521 (ptexinfmt-defun-if-void texinfo-format-cedilla-accent ()
522 (insert (texinfo-parse-arg-discard) ",")
523 (goto-char texinfo-command-start))
526 ;; @dotaccent{o} ==> .o overdot-accent
527 (put 'dotaccent 'texinfo-format 'texinfo-format-overdot-accent)
528 (ptexinfmt-defun-if-void texinfo-format-overdot-accent ()
529 (insert "." (texinfo-parse-arg-discard))
530 (goto-char texinfo-command-start))
532 ;; @ubaraccent{o} ==> _o underbar-accent
533 (put 'ubaraccent 'texinfo-format 'texinfo-format-underbar-accent)
534 (ptexinfmt-defun-if-void texinfo-format-underbar-accent ()
535 (insert "_" (texinfo-parse-arg-discard))
536 (goto-char texinfo-command-start))
538 ;; @udotaccent{o} ==> o-. underdot-accent
539 (put 'udotaccent 'texinfo-format 'texinfo-format-underdot-accent)
540 (ptexinfmt-defun-if-void texinfo-format-underdot-accent ()
541 (insert (texinfo-parse-arg-discard) "-.")
542 (goto-char texinfo-command-start))
544 ;; @H{o} ==> ""o long Hungarian umlaut
545 (put 'H 'texinfo-format 'texinfo-format-long-Hungarian-umlaut)
546 (ptexinfmt-defun-if-void texinfo-format-long-Hungarian-umlaut ()
547 (insert "\"\"" (texinfo-parse-arg-discard))
548 (goto-char texinfo-command-start))
550 ;; @ringaccent{o} ==> *o ring accent
551 (put 'ringaccent 'texinfo-format 'texinfo-format-ring-accent)
552 (ptexinfmt-defun-if-void texinfo-format-ring-accent ()
553 (insert "*" (texinfo-parse-arg-discard))
554 (goto-char texinfo-command-start))
556 ;; @tieaccent{oo} ==> [oo tie after accent
557 (put 'tieaccent 'texinfo-format 'texinfo-format-tie-after-accent)
558 (ptexinfmt-defun-if-void texinfo-format-tie-after-accent ()
559 (insert "[" (texinfo-parse-arg-discard))
560 (goto-char texinfo-command-start))
562 ;; @u{o} ==> (o breve accent
563 (put 'u 'texinfo-format 'texinfo-format-breve-accent)
564 (ptexinfmt-defun-if-void texinfo-format-breve-accent ()
565 (insert "(" (texinfo-parse-arg-discard))
566 (goto-char texinfo-command-start))
568 ;; @v{o} ==> <o hacek accent
569 (put 'v 'texinfo-format 'texinfo-format-hacek-accent)
570 (ptexinfmt-defun-if-void texinfo-format-hacek-accent ()
571 (insert "<" (texinfo-parse-arg-discard))
572 (goto-char texinfo-command-start))
574 ;; @dotless{i} ==> i dotless i and dotless j
575 (put 'dotless 'texinfo-format 'texinfo-format-dotless)
576 (ptexinfmt-defun-if-void texinfo-format-dotless ()
577 (insert (texinfo-parse-arg-discard))
578 (goto-char texinfo-command-start))
581 (put '\. 'texinfo-format 'texinfo-format-\.)
582 (ptexinfmt-defun-if-void texinfo-format-\. ()
583 (texinfo-discard-command)
587 (put '\: 'texinfo-format 'texinfo-format-\:)
588 (ptexinfmt-defun-if-void texinfo-format-\: ()
589 (texinfo-discard-command))
592 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
593 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
594 (texinfo-discard-command))
597 (put '\/ 'texinfo-format 'texinfo-format-\/)
598 (ptexinfmt-defun-if-void texinfo-format-\/ ()
599 (texinfo-discard-command))
602 (put 'textdegree 'texinfo-format 'texinfo-format-textdegree)
603 (ptexinfmt-defun-if-void texinfo-format-textdegree ()
604 (insert "o" (texinfo-parse-arg-discard))
605 (goto-char texinfo-command-start))
610 (put 'ref 'texinfo-format 'texinfo-format-xref)
612 (ptexinfmt-defun-if-broken texinfo-format-xref ()
613 (let ((args (texinfo-format-parse-args)))
614 (texinfo-discard-command)
616 (let ((fname (or (nth 1 args) (nth 2 args))))
617 (if (null (or fname (nth 3 args)))
618 (insert (nth 0 args) "::")
619 (insert (or fname (nth 0 args)) ": ")
621 (insert "(" (nth 3 args) ")"))
622 (unless (null (nth 0 args))
623 (insert (nth 0 args)))))))
625 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
626 (put 'uref 'texinfo-format 'texinfo-format-uref)
627 (ptexinfmt-defun-if-broken texinfo-format-uref ()
628 "Format URL and optional URL-TITLE.
629 Insert ` ... ' around URL if no URL-TITLE argument;
630 otherwise, insert URL-TITLE followed by URL in parentheses."
631 (let ((args (texinfo-format-parse-args)))
632 (texinfo-discard-command)
635 (insert (nth 1 args) " (" (nth 0 args) ")")
636 (insert "`" (nth 0 args) "'"))))
639 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
640 (ptexinfmt-defun-if-void texinfo-format-inforef ()
641 (let ((args (texinfo-format-parse-args)))
642 (texinfo-discard-command)
644 (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
645 (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
650 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
651 ;; - Info-tagify suport @anthor-*-refill.
652 ;; - info.el support Ref in Tag table.
653 (unless (get 'anchor 'texinfo-format)
654 (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
658 ;;; New command definition
659 ;; @alias NEW=EXISTING
660 (put 'alias 'texinfo-format 'texinfo-alias)
661 (ptexinfmt-defun-if-void texinfo-alias ()
662 (let ((start (1- (point)))
664 (skip-chars-forward " ")
665 (save-excursion (end-of-line) (setq texinfo-command-end (point)))
666 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
667 (error "Invalid alias command")
668 (setq texinfo-alias-list
671 (buffer-substring (match-beginning 1) (match-end 1))
672 (buffer-substring (match-beginning 2) (match-end 2)))
674 (texinfo-discard-command))))
678 ;; @exampleindent INDENT (makeinfo 4.0 or later)
680 ;; @paragraphindent INDENT (makeinfo 4.0 or later)
681 ;; INDENT: asis, 0, n
683 ;; @firstparagraphindent WORD (makeinfo 4.6 or later)
684 ;; WORD: none, insert
689 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
690 (put 'image 'texinfo-format 'texinfo-format-image)
691 (ptexinfmt-defun-if-void texinfo-format-image ()
692 ;; I don't know makeinfo parse FILENAME.
693 (let ((args (texinfo-format-parse-args))
695 (when (null (nth 0 args))
696 (error "Invalid image command"))
697 (texinfo-discard-command)
698 ;; makeinfo uses FILENAME.txt
699 (setq filename (format "%s.txt" (nth 0 args)))
700 (message "Reading included file: %s" filename)
701 ;; verbatim for Info output
702 (goto-char (+ (point) (cadr (insert-file-contents filename))))
703 (message "Reading included file: %s...done" filename)))
705 ;; @hyphenation command discards an argument within braces
706 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
707 (ptexinfmt-defun-if-void texinfo-discard-command-and-arg ()
708 "Discard both @-command and its argument in braces."
709 (goto-char texinfo-command-end)
711 (setq texinfo-command-end (point))
712 (delete-region texinfo-command-start texinfo-command-end))
715 ;;; @multitable ... @end multitable
716 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
717 "*Number of extra spaces between entries (columns) in @multitable.")
719 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
720 "*multitable-temporary-buffer*")
721 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
722 "texinfo-multitable-temp-")
724 ;; These commands are defined in texinfo.tex for printed output.
725 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
726 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
727 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
728 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
730 (put 'multitable 'texinfo-format 'texinfo-multitable)
732 (ptexinfmt-defun-if-void texinfo-multitable ()
733 "Produce multi-column tables."
735 ;; This function pushes information onto the `texinfo-stack'.
736 ;; A stack element consists of:
737 ;; - type-of-command, i.e., multitable
738 ;; - the information about column widths, and
739 ;; - the position of texinfo-command-start.
740 ;; e.g., ('multitable (1 2 3 4) 123)
741 ;; The command line is then deleted.
744 ;; push width information on stack
745 (texinfo-multitable-widths))
746 (texinfo-discard-line-with-args))
748 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
749 (ptexinfmt-defun-if-void texinfo-end-multitable ()
750 "Discard the @end multitable line and pop the stack of multitable."
751 (texinfo-discard-command)
752 (texinfo-pop-stack 'multitable))
754 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
755 "Return list of widths of each column in a multi-column table."
756 (let (texinfo-multitable-width-list)
758 ;; @multitable @columnfractions .25 .3 .45
761 ;; @multitable {Column 1 template} {Column 2} {Column 3 example}
762 ;; Place point before first argument
763 (skip-chars-forward " \t")
765 ;; Check for common misspelling
766 ((looking-at "@columnfraction ")
767 (error "In @multitable, @columnfractions misspelled"))
768 ;; Case 1: @columnfractions .25 .3 .45
769 ((looking-at "@columnfractions")
772 (setq texinfo-multitable-width-list
776 (* fill-column (read (get-buffer (current-buffer))))))
777 texinfo-multitable-width-list))))
779 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
781 (let ((start-of-templates (point)))
783 (skip-chars-forward " \t")
784 (let* ((start-of-template (1+ (point)))
786 ;; forward-sexp works with braces in Texinfo mode
787 (progn (forward-sexp 1) (1- (point)))))
788 (setq texinfo-multitable-width-list
790 (goto-char end-of-template)
793 (goto-char start-of-template)
795 texinfo-multitable-width-list))
796 ;; Remove carriage return from within a template, if any.
797 ;; This helps those those who want to use more than
798 ;; one line's worth of words in @multitable line.
799 (narrow-to-region start-of-template end-of-template)
800 (goto-char (point-min))
801 (while (search-forward "\n" nil t)
803 (goto-char (point-max))
810 You probably need to specify column widths for @multitable correctly")))
811 ;; Check whether columns fit on page.
812 (let ((desired-columns
814 ;; between column spaces
815 (length texinfo-multitable-width-list)
816 ;; additional between column spaces, if any
817 texinfo-extra-inter-column-width
818 ;; sum of spaces for each entry
819 (apply '+ texinfo-multitable-width-list))))
820 (if (> desired-columns fill-column)
822 Multi-column table width, %d chars, is greater than page width, %d chars."
823 desired-columns fill-column))))
824 texinfo-multitable-width-list))
826 ;; @item A1 @tab A2 @tab A3
827 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
828 "Return multitable row, as a string.
829 End of row is beginning of next @item or beginning of @end.
830 Cells within rows are separated by @tab."
831 (skip-chars-forward " \t")
832 (let* ((start (point))
834 (re-search-forward "@item\\|@end")
835 (match-beginning 0)))
836 (row (progn (goto-char end)
837 (skip-chars-backward " ")
838 ;; remove whitespace at end of argument
839 (delete-region (point) end)
840 (buffer-substring start (point)))))
841 (delete-region texinfo-command-start end)
844 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
845 (ptexinfmt-defun-if-void texinfo-multitable-item ()
846 "Format a row within a multicolumn table.
847 Cells in row are separated by @tab.
848 Widths of cells are specified by the arguments in the @multitable line.
849 All cells are made to be the same height.
850 This command is executed when texinfmt sees @item inside @multitable."
851 (let ((original-buffer (current-buffer))
852 (table-widths (reverse (car (cdr (car texinfo-stack)))))
853 (existing-fill-column fill-column)
857 (table-entry-height 0)
858 ;; unformatted row looks like: A1 @tab A2 @tab A3
859 ;; extract-row command deletes the source line in the table.
860 (unformated-row (texinfo-multitable-extract-row)))
861 ;; Use a temporary buffer
862 (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
863 (delete-region (point-min) (point-max))
864 (insert unformated-row)
865 (goto-char (point-min))
866 ;; 1. Check for correct number of @tab in line.
867 (let ((tab-number 1)) ;; one @tab between two columns
868 (while (search-forward "@tab" nil t)
869 (setq tab-number (1+ tab-number)))
870 (if (/= tab-number (length table-widths))
871 (error "Wrong number of @tab's in a @multitable row")))
872 (goto-char (point-min))
873 ;; 2. Format each cell, and copy to a rectangle
874 ;; buffer looks like this: A1 @tab A2 @tab A3
875 ;; Cell #1: format up to @tab
876 ;; Cell #2: format up to @tab
877 ;; Cell #3: format up to eob
880 (setq end (save-excursion
881 (if (search-forward "@tab" nil 'move)
882 ;; Delete the @tab command, including the @-sign
885 (progn (forward-word -1) (1- (point)))))
887 ;; Set fill-column *wider* than needed to produce inter-column space
888 (setq fill-column (+ 1
889 texinfo-extra-inter-column-width
890 (nth table-column table-widths)))
891 (narrow-to-region start end)
892 ;; Remove whitespace before and after entry.
893 (skip-chars-forward " ")
894 (delete-region (point) (save-excursion (beginning-of-line) (point)))
895 (goto-char (point-max))
896 (skip-chars-backward " ")
897 (delete-region (point) (save-excursion (end-of-line) (point)))
898 ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
899 ;; does not see an unterminated @multitable.
900 (let (texinfo-stack) ;; nil
901 (texinfo-format-scan))
902 (let (fill-prefix) ;; no fill prefix
903 (fill-region (point-min) (point-max)))
904 (setq table-entry-height
905 (max table-entry-height (count-lines (point-min) (point-max))))
906 ;; 3. Move point to end of bottom line, and pad that line to fill column.
907 (goto-char (point-min))
908 (forward-line (1- table-entry-height))
909 (let* ((beg (point)) ;; beginning of line
910 ;; add one more space for inter-column spacing
916 (current-column)))))) ;; end of existing line
918 (if (> needed-whitespace 0) needed-whitespace 1)
920 ;; now, put formatted cell into a rectangle
921 (set (intern (concat texinfo-multitable-rectangle-name
922 (int-to-string table-column)))
923 (extract-rectangle (point-min) (point)))
924 (delete-region (point-min) (point))
925 (goto-char (point-max))
926 (setq table-column (1+ table-column))
928 ;; 4. Add extra lines to rectangles so all are of same height
929 (let ((total-number-of-columns table-column)
932 (while (> table-column 0)
933 (let ((this-rectangle (int-to-string table-column)))
934 (while (< (length this-rectangle) table-entry-height)
935 (setq this-rectangle (append this-rectangle '("")))))
936 (setq table-column (1- table-column)))
937 ;; 5. Insert formatted rectangles in original buffer
938 (switch-to-buffer original-buffer)
939 (open-line table-entry-height)
940 (while (< column-number total-number-of-columns)
944 (concat texinfo-multitable-rectangle-name
945 (int-to-string column-number)))))
948 (setq column-number (1+ column-number))))
949 (kill-buffer texinfo-multitable-buffer-name)
950 (setq fill-column existing-fill-column)))
953 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
954 (let ((indexelts (symbol-value
955 (cdr (assoc (texinfo-parse-arg-discard)
956 texinfo-indexvar-alist))))
958 (insert "\n* Menu:\n\n")
959 (setq opoint (point))
960 (texinfo-print-index nil indexelts)
962 (if (memq system-type '(vax-vms windows-nt ms-dos))
963 (texinfo-sort-region opoint (point))
964 (shell-command-on-region opoint (point) "sort -fd" 1))))
968 ;; @copying ... @end copying
969 ;; that Emacs 21.4 and lesser and XEmacs don't support.
970 (if (fboundp 'texinfo-copying)
972 (defvar texinfo-copying-text ""
973 "Text of the copyright notice and copying permissions.")
975 (defun texinfo-copying ()
976 "Copy the copyright notice and copying permissions from the Texinfo file,
977 as indicated by the @copying ... @end copying command;
978 insert the text with the @insertcopying command."
979 (let ((beg (progn (beginning-of-line) (point)))
980 (end (progn (re-search-forward "^@end copying[ \t]*\n") (point))))
981 (setq texinfo-copying-text
982 (buffer-substring-no-properties
983 (save-excursion (goto-char beg) (forward-line 1) (point))
984 (save-excursion (goto-char end) (forward-line -1) (point))))
985 (delete-region beg end)))
987 (defun texinfo-insertcopying ()
988 "Insert the copyright notice and copying permissions from the Texinfo file,
989 which are indicated by the @copying ... @end copying command."
990 (insert (concat "\n" texinfo-copying-text)))
992 (defadvice texinfo-format-scan (before expand-@copying-section activate)
993 "Extract @copying and replace @insertcopying with it."
994 (goto-char (point-min))
995 (when (search-forward "@copying" nil t)
997 (while (search-forward "@insertcopying" nil t)
998 (delete-region (match-beginning 0) (match-end 0))
999 (texinfo-insertcopying))))
1001 (provide 'ptexinfmt)
1003 ;;; ptexinfmt.el ends here