* ptexinfmt.el (texinfo-format-geq, texinfo-format-leq,): Support @geq and @leq.
[elisp/wanderlust.git] / utils / ptexinfmt.el
1 ;;; ptexinfmt.el -- portable Texinfo formatter.
2
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>
7
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
14
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.
19
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.
24
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.
29
30 ;;; Commentary:
31
32 ;; Original code: Yoshiki Hayashi <yoshiki@xemacs.org>
33 ;;      makeinfo.el (gnujdoc project)
34
35 ;; Support texinfmt.el 2.32 or later.
36
37 ;; Modified by Yamaoka not to use APEL functions.
38
39 ;; Unimplemented command:
40 ;;  @abbr
41 ;;  @float, @caption, @shortcaption, @listoffloats
42 ;;  @deftypecv[x]
43 ;;  @headitem
44 ;;  @comma{}
45 ;;  @quotation (optional arguments)
46 ;;  @acronym (optional argument)
47 ;;  @dofirstparagraphindent
48 ;;  @indent
49 ;;  @verbatiminclude
50 ;;  @\
51 ;;  @definfoenclose
52 ;;  @deftypeivar
53 ;;  @deftypeop
54 ;;  @allowcodebreaks
55 ;;  @thischapternum
56 ;;  @quotedblleft @quotedblright
57 ;;  @quoteleft @quoteright  @quotedblbase @quotesinglbase
58 ;;  @guillemetleft @guillemetright @guilsinglleft @guilsinglright.
59
60 ;;; Code:
61
62 (require 'texinfmt)
63
64 ;;; Broken
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'.")
68
69 (put 'ptexinfmt-broken-facility 'lisp-indent-function 'defun)
70 (defmacro ptexinfmt-broken-facility (facility docstring assertion
71                                               &optional dummy)
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))
79      (if assertion
80          nil
81        (put facility 'broken-docstring docstring)
82        (if ptexinfmt-disable-broken-notice-flag
83            nil
84          (message "BROKEN FACILITY DETECTED: %s" docstring)))))
85
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))
91     `(prog1
92          ,name
93        (if (get ,name 'broken)
94            (defalias ,name
95              (function (lambda ,@args)))))))
96
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))
102     `(prog1
103          ,name
104        (if (fboundp ,name)
105            nil
106          (defalias ,name
107            (function (lambda ,@args)))))))
108
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))
114     `(prog1
115          (defvar ,name)
116        (if (boundp ',name)
117            nil
118          (defvar ,name ,@args)))))
119
120 ;; sort -fd
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
127       nil
128     t))
129
130 ;; @var
131 (ptexinfmt-broken-facility texinfo-format-var
132   "Don't perse @var argument."
133   (condition-case nil
134       (with-temp-buffer
135         (let (texinfo-enclosure-list texinfo-alias-list)
136           (texinfo-mode)
137           (insert "@var{@asis{foo}}\n")
138           (texinfo-format-expand-region (point-min) (point-max))
139           t))
140     (error nil)))
141
142 ;; @xref
143 (ptexinfmt-broken-facility texinfo-format-xref
144   "Can't format @xref, 1st argument is empty."
145   (condition-case nil
146       (with-temp-buffer
147         (let (texinfo-enclosure-list texinfo-alias-list)
148           (texinfo-mode)
149           (insert "@xref{, xref, , file}\n")
150           (texinfo-format-expand-region (point-min) (point-max))
151           t))
152     (error nil)))
153
154 ;; @uref
155 (ptexinfmt-broken-facility texinfo-format-uref
156   "Parse twice @uref argument."
157   (condition-case nil
158       (with-temp-buffer
159         (let (texinfo-enclosure-list texinfo-alias-list)
160           (texinfo-mode)
161           (insert "@uref{mailto:foo@@noncommand.example.com}\n")
162           (texinfo-format-expand-region (point-min) (point-max))
163           t))
164     (error nil)))
165
166 ;; @multitable
167 (ptexinfmt-broken-facility texinfo-multitable-widths
168   "`texinfo-multitable-widths' unsupport wide-char."
169   (if (fboundp 'texinfo-multitable-widths)
170       (with-temp-buffer
171         (let ((str "\e$BI}9-J8;z\e(B"))
172           (texinfo-mode)
173           (insert (format " {%s}\n" str))
174           (goto-char (point-min))
175           (if (= (car (texinfo-multitable-widths)) (length str))
176               t
177             nil)))
178     ;; function definition is void
179     nil))
180
181 (ptexinfmt-broken-facility texinfo-multitable-item
182   "`texinfo-multitable-item' unsupport wide-char."
183   (not (get 'texinfo-multitable-widths 'broken)))
184
185
186 ;;; Hardcopy and HTML (discard)
187 ;; html
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)
191
192 ;; size
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)
201
202 ;; style
203 (put 'setchapternewpage 'texinfo-format 'texinfo-discard-line-with-args)
204 (put 'kbdinputstyle 'texinfo-format 'texinfo-discard-line-with-args)
205
206 ;; flags
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)
211
212 ;; head & foot
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)
220
221 ;; misc
222 (put 'page 'texinfo-format 'texinfo-discard-line)
223 (put 'hyphenation 'texinfo-format 'texinfo-discard-command-and-arg)
224
225 ;; @slanted{} (makeinfo 4.8 or later)
226 (put 'slanted 'texinfo-format 'texinfo-format-noop)
227
228 ;; @sansserif{} (makeinfo 4.8 or later)
229 (put 'sansserif 'texinfo-format 'texinfo-format-noop)
230
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)
235   (insert " "))
236
237 \f
238 ;;; Directory File
239 ;; @direcategory
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)
244                    (progn
245                      (skip-chars-forward " ")
246                      (point)))
247     (insert "INFO-DIR-SECTION " str "\n")))
248
249 ;; @direntry
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"))
255
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))
261
262
263 ;;; Block Enclosing
264 ;; @detailmenu ... @end detailmenu
265 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
266 (put 'detailmenu 'texinfo-end 'texinfo-discard-command)
267
268 ;; @smalldisplay ... @end smalldisplay
269 (put 'smalldisplay 'texinfo-format 'texinfo-format-example)
270 (put 'smalldisplay 'texinfo-end 'texinfo-end-example)
271
272 ;; @smallformat ... @end smallformat
273 (put 'smallformat 'texinfo-format 'texinfo-format-flushleft)
274 (put 'smallformat 'texinfo-end 'texinfo-end-flushleft)
275
276 ;; @cartouche  ... @end cartouche
277 (put 'cartouche 'texinfo-format 'texinfo-discard-line)
278 (put 'cartouche 'texinfo-end 'texinfo-discard-command)
279
280
281 ;;; Conditional
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)
285
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)
289
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)
293
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)
297
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")
303                         (point))))
304
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")
310                         (point))))
311
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")
317                         (point))))
318
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")
324                         (point))))
325
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")
331                         (point))))
332
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")
338                         (point))))
339
340 \f
341 ;;; Marking
342 ;; @indicateurl, @url, @env, @command, 
343 (put 'env 'texinfo-format 'texinfo-format-code)
344 (put 'command 'texinfo-format 'texinfo-format-code)
345
346 (put 'indicateurl 'texinfo-format 'texinfo-format-code)
347 (put 'url 'texinfo-format 'texinfo-format-uref) ; Texinfo 4.7
348
349 ;; @acronym
350 (put 'acronym 'texinfo-format 'texinfo-format-var)
351
352 (ptexinfmt-defun-if-broken texinfo-format-var ()
353   (let ((arg (texinfo-parse-expanded-arg)))
354     (texinfo-discard-command)
355     (insert (upcase arg))))
356
357 ;; @key
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))
362
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)
370     ;; if displayed-text
371     (if (nth 1 args)
372         (insert (nth 1 args) " <" (nth 0 args) ">")
373       (insert "<" (nth 0 args) ">"))))
374
375 ;; @option
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))
383                             t))
384       (insert "`" (texinfo-parse-arg-discard) "'")
385     (insert (texinfo-parse-arg-discard)))
386   (goto-char texinfo-command-start))
387
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.
394
395 For example, @verb\{|@|\} results in @ and
396 @verb\{+@'e?`!`+} results in @'e?`!`."
397
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"))
407   (delete-char 1))
408
409 \f
410 ;;; @LaTeX, @registeredsymbol{}
411 (put 'LaTeX 'texinfo-format 'texinfo-format-LaTeX)
412 (ptexinfmt-defun-if-void texinfo-format-LaTeX ()
413   (texinfo-parse-arg-discard)
414   (insert "LaTeX"))
415
416 (put 'registeredsymbol 'texinfo-format 'texinfo-format-registeredsymbol)
417 (ptexinfmt-defun-if-void texinfo-format-registeredsymbol ()
418   (texinfo-parse-arg-discard)
419   (insert "(R)"))
420
421 ;;; Accents and Special characters
422 ;; @euro{}      ==>     Euro
423 (put 'euro 'texinfo-format 'texinfo-format-euro)
424 (ptexinfmt-defun-if-void texinfo-format-euro ()
425   (texinfo-parse-arg-discard)
426   (insert "Euro "))
427
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)
432   (insert "#"))
433
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)
438   (insert "a"))
439
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)
444   (insert "o"))
445
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))
451
452 ;; @oe{}        ==>     oe
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))
457
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))
463
464 ;; @aa{}        ==>     aa
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))
469
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))
475
476 ;; @ae{}        ==>     ae
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))
481
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))
487
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))
493
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))
499
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))
505
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))
511
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))
517
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))
523
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))
529
530
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))
536
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))
542
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))
548
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))
554
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))
560
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))
566
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))
572
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))
578
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))
584
585 ;; @.
586 (put '\. 'texinfo-format 'texinfo-format-\.)
587 (ptexinfmt-defun-if-void texinfo-format-\. ()
588   (texinfo-discard-command)
589   (insert "."))
590
591 ;; @:
592 (put '\: 'texinfo-format 'texinfo-format-\:)
593 (ptexinfmt-defun-if-void texinfo-format-\: ()
594   (texinfo-discard-command))
595
596 ;; @-
597 (put '\- 'texinfo-format 'texinfo-format-soft-hyphen)
598 (ptexinfmt-defun-if-void texinfo-format-soft-hyphen ()
599   (texinfo-discard-command))
600
601 ;; @/
602 (put '\/ 'texinfo-format 'texinfo-format-\/)
603 (ptexinfmt-defun-if-void texinfo-format-\/ ()
604   (texinfo-discard-command))
605
606 ;; @textdegree
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))
611
612 ;; @geq{}
613 (put 'geq 'texinfo-format 'texinfo-format-geq)
614 (ptexinfmt-defun-if-void texinfo-format-geq ()
615   (insert ">=" (texinfo-parse-arg-discard))
616   (goto-char texinfo-command-start))
617
618 ;; @leq{}
619 (put 'leq 'texinfo-format 'texinfo-format-leq)
620 (ptexinfmt-defun-if-void texinfo-format-leq ()
621   (insert "<=" (texinfo-parse-arg-discard))
622   (goto-char texinfo-command-start))
623
624 \f
625 ;;; Cross References
626 ;; @ref, @xref
627 (put 'ref 'texinfo-format 'texinfo-format-xref)
628
629 (ptexinfmt-defun-if-broken texinfo-format-xref ()
630   (let ((args (texinfo-format-parse-args)))
631     (texinfo-discard-command)
632     (insert "*Note ")
633     (let ((fname (or (nth 1 args) (nth 2 args))))
634       (if (null (or fname (nth 3 args)))
635           (insert (nth 0 args) "::")
636         (insert (or fname (nth 0 args)) ": ")
637         (if (nth 3 args)
638             (insert "(" (nth 3 args) ")"))
639         (unless (null (nth 0 args))
640           (insert (nth 0 args)))))))
641
642 ;; @uref{URL [,TEXT] [,REPLACEMENT]}
643 (put 'uref 'texinfo-format 'texinfo-format-uref)
644 (ptexinfmt-defun-if-broken texinfo-format-uref ()
645   "Format URL and optional URL-TITLE.
646 Insert ` ... ' around URL if no URL-TITLE argument;
647 otherwise, insert URL-TITLE followed by URL in parentheses."
648   (let ((args (texinfo-format-parse-args)))
649     (texinfo-discard-command)
650     ;; if url-title
651     (if (nth 1 args)
652         (insert  (nth 1 args) " (" (nth 0 args) ")")
653       (insert "`" (nth 0 args) "'"))))
654
655 ;; @inforef
656 (put 'inforef 'texinfo-format 'texinfo-format-inforef)
657 (ptexinfmt-defun-if-void texinfo-format-inforef ()
658   (let ((args (texinfo-format-parse-args)))
659     (texinfo-discard-command)
660     (if (nth 1 args)
661         (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))
662       (insert "*Note " "(" (nth 2 args) ")" (car args) "::"))))
663
664
665 ;; @anchor
666 ;; don't emulation
667 ;; If support @anchor for Mule 2.3, We must fix informat.el and info.el:
668 ;;  - Info-tagify suport @anthor-*-refill.
669 ;;  - info.el support Ref in Tag table.
670 (unless (get 'anchor 'texinfo-format)
671   (put 'anchor 'texinfo-format 'texinfo-discard-command-and-arg))
672
673
674 \f
675 ;;; New command definition
676 ;; @alias NEW=EXISTING
677 (put 'alias 'texinfo-format 'texinfo-alias)
678 (ptexinfmt-defun-if-void texinfo-alias ()
679   (let ((start (1- (point)))
680         args)
681     (skip-chars-forward " ")
682     (save-excursion (end-of-line) (setq texinfo-command-end (point)))
683     (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
684         (error "Invalid alias command")
685       (setq texinfo-alias-list
686             (cons
687              (cons
688               (buffer-substring (match-beginning 1) (match-end 1))
689               (buffer-substring (match-beginning 2) (match-end 2)))
690              texinfo-alias-list))
691       (texinfo-discard-command))))
692
693 \f
694 ;;; Indent
695 ;; @exampleindent INDENT  (makeinfo 4.0 or later)
696
697 ;; @paragraphindent INDENT  (makeinfo 4.0 or later)
698 ;; INDENT: asis, 0, n
699
700 ;; @firstparagraphindent WORD   (makeinfo 4.6 or later)
701 ;; WORD: none, insert
702
703
704 \f
705 ;;; Special
706 ;; @image{FILENAME [, WIDTH] [, HEIGHT]}
707 (put 'image 'texinfo-format 'texinfo-format-image)
708 (ptexinfmt-defun-if-void texinfo-format-image ()
709   ;; I don't know makeinfo parse FILENAME.
710   (let ((args (texinfo-format-parse-args))
711         filename)
712     (when (null (nth 0 args))
713       (error "Invalid image command"))
714     (texinfo-discard-command)
715     ;; makeinfo uses FILENAME.txt
716     (setq filename (format "%s.txt" (nth 0 args)))
717     (message "Reading included file: %s" filename)
718     ;; verbatim for Info output
719     (goto-char (+ (point) (cadr (insert-file-contents filename))))
720     (message "Reading included file: %s...done" filename)))
721
722
723 \f
724 ;;; @multitable ... @end multitable
725 (ptexinfmt-defvar-if-void texinfo-extra-inter-column-width 0
726   "*Number of extra spaces between entries (columns) in @multitable.")
727
728 (ptexinfmt-defvar-if-void texinfo-multitable-buffer-name
729   "*multitable-temporary-buffer*")
730 (ptexinfmt-defvar-if-void texinfo-multitable-rectangle-name
731   "texinfo-multitable-temp-")
732
733 ;; These commands are defined in texinfo.tex for printed output.
734 (put 'multitableparskip 'texinfo-format 'texinfo-discard-line-with-args)
735 (put 'multitableparindent 'texinfo-format 'texinfo-discard-line-with-args)
736 (put 'multitablecolmargin 'texinfo-format 'texinfo-discard-line-with-args)
737 (put 'multitablelinespace 'texinfo-format 'texinfo-discard-line-with-args)
738
739 (put 'multitable 'texinfo-format 'texinfo-multitable)
740
741 (ptexinfmt-defun-if-void texinfo-multitable ()
742   "Produce multi-column tables."
743
744 ;; This function pushes information onto the `texinfo-stack'.
745 ;; A stack element consists of:
746 ;;   - type-of-command, i.e., multitable
747 ;;   - the information about column widths, and
748 ;;   - the position of texinfo-command-start.
749 ;; e.g., ('multitable (1 2 3 4) 123)
750 ;; The command line is then deleted.
751   (texinfo-push-stack
752    'multitable
753    ;; push width information on stack
754    (texinfo-multitable-widths))
755   (texinfo-discard-line-with-args))
756
757 (put 'multitable 'texinfo-end 'texinfo-end-multitable)
758 (ptexinfmt-defun-if-void texinfo-end-multitable ()
759   "Discard the @end multitable line and pop the stack of multitable."
760   (texinfo-discard-command)
761   (texinfo-pop-stack 'multitable))
762
763 (ptexinfmt-defun-if-broken texinfo-multitable-widths ()
764   "Return list of widths of each column in a multi-column table."
765   (let (texinfo-multitable-width-list)
766     ;; Fractions format:
767     ;;  @multitable @columnfractions .25 .3 .45
768     ;;
769     ;; Template format:
770     ;;  @multitable {Column 1 template} {Column 2} {Column 3 example}
771     ;; Place point before first argument
772     (skip-chars-forward " \t")
773     (cond
774      ;; Check for common misspelling
775      ((looking-at "@columnfraction ")
776       (error "In @multitable, @columnfractions misspelled"))
777      ;; Case 1: @columnfractions .25 .3 .45
778      ((looking-at "@columnfractions")
779       (forward-word 1)
780       (while (not (eolp))
781         (setq texinfo-multitable-width-list
782               (cons
783                (truncate
784                 (1-
785                  (* fill-column (read (get-buffer (current-buffer))))))
786                texinfo-multitable-width-list))))
787      ;;
788      ;; Case 2: {Column 1 template} {Column 2} {Column 3 example}
789      ((looking-at "{")
790       (let ((start-of-templates (point)))
791         (while (not (eolp))
792           (skip-chars-forward " \t")
793           (let* ((start-of-template (1+ (point)))
794                  (end-of-template
795                   ;; forward-sexp works with braces in Texinfo mode
796                   (progn (forward-sexp 1) (1- (point)))))
797             (setq texinfo-multitable-width-list
798                   (cons (- (progn
799                              (goto-char end-of-template)
800                              (current-column))
801                            (progn
802                              (goto-char start-of-template)
803                              (current-column)))
804                         texinfo-multitable-width-list))
805             ;; Remove carriage return from within a template, if any.
806             ;; This helps those those who want to use more than
807             ;; one line's worth of words in @multitable line.
808             (narrow-to-region start-of-template end-of-template)
809             (goto-char (point-min))
810             (while (search-forward "\n" nil t)
811               (delete-char -1))
812             (goto-char (point-max))
813             (widen)
814             (forward-char 1)))))
815      ;;
816      ;; Case 3: Trouble
817      (t
818       (error "\
819 You probably need to specify column widths for @multitable correctly")))
820     ;; Check whether columns fit on page.
821     (let ((desired-columns
822            (+
823             ;; between column spaces
824             (length texinfo-multitable-width-list)
825             ;; additional between column spaces, if any
826             texinfo-extra-inter-column-width
827             ;; sum of spaces for each entry
828             (apply '+ texinfo-multitable-width-list))))
829       (if (> desired-columns fill-column)
830           (error (format "\
831 Multi-column table width, %d chars, is greater than page width, %d chars."
832                          desired-columns fill-column))))
833     texinfo-multitable-width-list))
834
835 ;; @item  A1  @tab  A2  @tab  A3
836 (ptexinfmt-defun-if-void texinfo-multitable-extract-row ()
837   "Return multitable row, as a string.
838 End of row is beginning of next @item or beginning of @end.
839 Cells within rows are separated by @tab."
840   (skip-chars-forward " \t")
841   (let* ((start (point))
842          (end (progn
843                 (re-search-forward "@item\\|@end")
844                 (match-beginning 0)))
845          (row (progn (goto-char end)
846                      (skip-chars-backward " ")
847                      ;; remove whitespace at end of argument
848                      (delete-region (point) end)
849                      (buffer-substring start (point)))))
850     (delete-region texinfo-command-start end)
851     row))
852
853 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
854 (ptexinfmt-defun-if-void texinfo-multitable-item ()
855   "Format a row within a multicolumn table.
856 Cells in row are separated by @tab.
857 Widths of cells are specified by the arguments in the @multitable line.
858 All cells are made to be the same height.
859 This command is executed when texinfmt sees @item inside @multitable."
860   (let ((original-buffer (current-buffer))
861         (table-widths (reverse (car (cdr (car texinfo-stack)))))
862         (existing-fill-column fill-column)
863         start
864         end
865         (table-column       0)
866         (table-entry-height 0)
867         ;; unformatted row looks like:  A1  @tab  A2  @tab  A3
868         ;; extract-row command deletes the source line in the table.
869         (unformated-row (texinfo-multitable-extract-row)))
870     ;; Use a temporary buffer
871     (set-buffer (get-buffer-create texinfo-multitable-buffer-name))
872     (delete-region (point-min) (point-max))
873     (insert unformated-row)
874     (goto-char (point-min))
875 ;; 1. Check for correct number of @tab in line.
876     (let ((tab-number 1)) ;; one @tab between two columns
877       (while (search-forward "@tab" nil t)
878         (setq tab-number (1+ tab-number)))
879       (if (/= tab-number (length table-widths))
880           (error "Wrong number of @tab's in a @multitable row")))
881     (goto-char (point-min))
882 ;; 2. Format each cell, and copy to a rectangle
883     ;; buffer looks like this:    A1  @tab  A2  @tab  A3
884     ;; Cell #1: format up to @tab
885     ;; Cell #2: format up to @tab
886     ;; Cell #3: format up to eob
887     (while (not (eobp))
888       (setq start (point))
889       (setq end (save-excursion
890                   (if (search-forward "@tab" nil 'move)
891                       ;; Delete the @tab command, including the @-sign
892                       (delete-region
893                        (point)
894                        (progn (forward-word -1) (1- (point)))))
895                   (point)))
896       ;; Set fill-column *wider* than needed to produce inter-column space
897       (setq fill-column (+ 1
898                            texinfo-extra-inter-column-width
899                            (nth table-column table-widths)))
900       (narrow-to-region start end)
901       ;; Remove whitespace before and after entry.
902       (skip-chars-forward " ")
903       (delete-region (point) (save-excursion (beginning-of-line) (point)))
904       (goto-char (point-max))
905       (skip-chars-backward " ")
906       (delete-region (point) (save-excursion (end-of-line) (point)))
907       ;; Temorarily set texinfo-stack to nil so texinfo-format-scan
908       ;; does not see an unterminated @multitable.
909       (let (texinfo-stack) ;; nil
910         (texinfo-format-scan))
911       (let (fill-prefix) ;; no fill prefix
912         (fill-region (point-min) (point-max)))
913       (setq table-entry-height
914             (max table-entry-height (count-lines (point-min) (point-max))))
915 ;; 3. Move point to end of bottom line, and pad that line to fill column.
916       (goto-char (point-min))
917       (forward-line (1- table-entry-height))
918       (let* ((beg (point)) ;; beginning of line
919              ;; add one more space for inter-column spacing
920              (needed-whitespace
921               (1+
922                (- fill-column
923                   (progn
924                     (end-of-line)
925                     (current-column)))))) ;; end of existing line
926         (insert (make-string
927                  (if (> needed-whitespace 0) needed-whitespace 1)
928                  ? )))
929       ;; now, put formatted cell into a rectangle
930       (set (intern (concat texinfo-multitable-rectangle-name
931                            (int-to-string table-column)))
932            (extract-rectangle (point-min) (point)))
933       (delete-region (point-min) (point))
934       (goto-char (point-max))
935       (setq table-column (1+ table-column))
936       (widen))
937 ;; 4. Add extra lines to rectangles so all are of same height
938     (let ((total-number-of-columns table-column)
939           (column-number 0)
940           here)
941       (while (> table-column 0)
942         (let ((this-rectangle (int-to-string table-column)))
943           (while (< (length this-rectangle) table-entry-height)
944             (setq this-rectangle (append this-rectangle '("")))))
945         (setq table-column (1- table-column)))
946 ;; 5. Insert formatted rectangles in original buffer
947       (switch-to-buffer original-buffer)
948       (open-line table-entry-height)
949       (while (< column-number total-number-of-columns)
950         (setq here (point))
951         (insert-rectangle
952          (eval (intern
953                 (concat texinfo-multitable-rectangle-name
954                         (int-to-string column-number)))))
955         (goto-char here)
956         (end-of-line)
957         (setq column-number (1+ column-number))))
958     (kill-buffer texinfo-multitable-buffer-name)
959     (setq fill-column existing-fill-column)))
960
961 \f
962 (ptexinfmt-defun-if-broken texinfo-format-printindex ()
963   (let ((indexelts (symbol-value
964                     (cdr (assoc (texinfo-parse-arg-discard)
965                                 texinfo-indexvar-alist))))
966         opoint)
967     (insert "\n* Menu:\n\n")
968     (setq opoint (point))
969     (texinfo-print-index nil indexelts)
970
971     (if (memq system-type '(vax-vms windows-nt ms-dos))
972         (texinfo-sort-region opoint (point))
973       (shell-command-on-region opoint (point) "sort -fd" 1))))
974
975 \f
976 ;; @copying ... @end copying
977 ;; that Emacs 21.4 and lesser and XEmacs don't support.
978 (if (fboundp 'texinfo-copying)
979     nil
980   (defvar texinfo-copying-text ""
981     "Text of the copyright notice and copying permissions.")
982
983   (defun texinfo-copying ()
984     "Copy the copyright notice and copying permissions from the Texinfo file,
985 as indicated by the @copying ... @end copying command;
986 insert the text with the @insertcopying command."
987     (let ((beg (progn (beginning-of-line) (point)))
988           (end  (progn (re-search-forward "^@end copying[ \t]*\n") (point))))
989       (setq texinfo-copying-text
990             (buffer-substring-no-properties
991              (save-excursion (goto-char beg) (forward-line 1) (point))
992              (save-excursion (goto-char end) (forward-line -1) (point))))
993       (delete-region beg end)))
994
995   (defun texinfo-insertcopying ()
996     "Insert the copyright notice and copying permissions from the Texinfo file,
997 which are indicated by the @copying ... @end copying command."
998     (insert (concat "\n" texinfo-copying-text)))
999
1000   (defadvice texinfo-format-scan (before expand-@copying-section activate)
1001     "Extract @copying and replace @insertcopying with it."
1002     (goto-char (point-min))
1003     (when (search-forward "@copying" nil t)
1004       (texinfo-copying))
1005     (while (search-forward "@insertcopying" nil t)
1006       (delete-region (match-beginning 0) (match-end 0))
1007       (texinfo-insertcopying))))
1008
1009 (provide 'ptexinfmt)
1010
1011 ;;; ptexinfmt.el ends here