[comp.emacs] LaTeXinfo - 10 of 10

mike@ists.ists.ca (Mike Clarkson) (06/03/90)

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 9 (of 9)."
# Contents:  latexinfo.el
# Wrapped by mike@sam on Sat Jun  2 18:18:16 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'latexinfo.el' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'latexinfo.el'\"
else
echo shar: Extracting \"'latexinfo.el'\" \(50239 characters\)
sed "s/^X//" >'latexinfo.el' <<'END_OF_FILE'
X;; Convert latexinfo files to info files.
X;; Copyright (C) 1985, 1986, 1988 Free Software Foundation, Inc.
X
X;; This file is not yet a part of GNU Emacs.
X
X;; GNU Emacs is distributed in the hope that it will be useful,
X;; but WITHOUT ANY WARRANTY.  No author or distributor
X;; accepts responsibility to anyone for the consequences of using it
X;; or for whether it serves any particular purpose or works at all,
X;; unless he says so in writing.  Refer to the GNU Emacs General Public
X;; License for full details.
X
X;; Everyone is granted permission to copy, modify and redistribute
X;; GNU Emacs, but only under the conditions described in the
X;; GNU Emacs General Public License.   A copy of this license is
X;; supposed to have been given to you along with GNU Emacs so you
X;; can know your rights and responsibilities.  It should be in a
X;; file named COPYING.  Among other things, the copyright notice
X;; and this notice must be preserved on all copies.
X
X
X(defvar latexinfo-formats-directory
X  (file-name-as-directory (getenv "LATEXINFO")))
X
X(if (not (memq latexinfo-formats-directory
X	       load-path))
X    (setq load-path (cons
X		     latexinfo-formats-directory
X		     load-path)))
X
X(defvar latexinfo-known-document-styles
X      '(latexinfo 11pt 12pt twoside titlepage psfonts smallverb format))
X
X(autoload 'latexinfo-mode "latexinfo-mode"
X	    "Major mode for editing latexinfo files." t)
X
X(autoload 'Info-tagify "informat" "Info Tagify" t)
X(autoload 'Info-split "informat" "Info Split" t)
X
X(put 'latexinfoversion 'latexinfo-format 'latexinfo-format-latexinfoversion)
X(defun latexinfo-format-latexinfoversion ()
X  (latexinfo-parse-noarg)
X  (insert "1.2"))
X
X(defvar latexinfo-format-syntax-table nil)
X
X(defvar latexinfo-vindex)
X(defvar latexinfo-findex)
X(defvar latexinfo-cindex)
X(defvar latexinfo-cpsubindex)
X(defvar latexinfo-pindex)
X(defvar latexinfo-tindex)
X(defvar latexinfo-kindex)
X(defvar latexinfo-last-node)
X(defvar latexinfo-node-names)
X
X(if latexinfo-format-syntax-table
X    nil
X  (setq latexinfo-format-syntax-table (make-syntax-table))
X  (modify-syntax-entry ?\" " " latexinfo-format-syntax-table)
X  (modify-syntax-entry ?* "w" latexinfo-format-syntax-table)
X  (modify-syntax-entry ?\\ "\\" latexinfo-format-syntax-table)
X  (modify-syntax-entry ?\[ "(]" latexinfo-format-syntax-table)
X  (modify-syntax-entry ?\] ")[" latexinfo-format-syntax-table)
X  (modify-syntax-entry ?\( "." latexinfo-format-syntax-table)
X  (modify-syntax-entry ?\) "." latexinfo-format-syntax-table)
X  (modify-syntax-entry ?{ "(}" latexinfo-format-syntax-table)
X  (modify-syntax-entry ?} "){" latexinfo-format-syntax-table)
X  (modify-syntax-entry ?\' "." latexinfo-format-syntax-table))
X
X(defun latexinfo-format-buffer (&optional notagify)
X  "Process the current buffer as latexinfo code, into an Info file.
XThe Info file output is generated in a buffer visiting the Info file
Xnames specified in the \\setfilename command.
X
XNon-nil argument (prefix, if interactive) means don't make tag table
Xand don't split the file if large.  You can use Info-tagify and
XInfo-split to do these manually."
X  (interactive "P")
X  (let ((lastmessage "Formatting Info file..."))
X    (message lastmessage)
X    (latexinfo-format-buffer-1)
X    (if notagify
X	nil
X      (progn
X	(if (> (buffer-size) 30000)
X	    (progn
X	      (message (setq lastmessage "Making tags table for Info file..."))
X	      (Info-tagify)))
X	(if (> (buffer-size) 100000)
X	    (progn
X	      (message (setq lastmessage "Splitting Info file..."))
X	      (Info-split)))))
X    (message (concat lastmessage
X		     (if (interactive-p) "done.  Now save it." "done.")))))
X
X(defun latexinfo-format-buffer-1 ()
X  (let (latexinfo-format-filename
X	latexinfo-example-start
X	latexinfo-command-start
X	latexinfo-command-end
X	latexinfo-command-name
X	latexinfo-last-node
X	latexinfo-vindex
X	latexinfo-findex
X	latexinfo-cindex
X	latexinfo-cpsubindex
X	latexinfo-pindex
X	latexinfo-tindex
X	latexinfo-kindex
X	latexinfo-stack
X	latexinfo-node-names
X	outfile
X	(fill-column fill-column)
X	(input-buffer (current-buffer))
X	(input-directory default-directory))
X    (save-excursion
X      (goto-char (point-min))
X      (search-forward "\\setfilename")
X      (setq latexinfo-command-end (point))
X      (setq outfile (latexinfo-parse-line-arg)))
X    (find-file outfile)
X    (latexinfo-mode)
X    (set-syntax-table latexinfo-format-syntax-table)
X    (erase-buffer)
X    (insert-buffer-substring input-buffer)
X    (goto-char (point-min))
X    (latexinfo-run-documentstyle-hooks)
X    ;; Run this after latexinfo-run-documentstyle-hooks
X    (goto-char (point-min))
X    (search-forward "\\setfilename")
X    (beginning-of-line)
X    (delete-region (point-min) (point))
X    ;; Remove \end{document} at end of file, if it is there.
X    (goto-char (point-max))
X    (if (search-backward "\\end{document}" nil t)
X	(delete-region (point) (point-max))
X      (error "Missing \\end{document}"))
X    ;; Make sure buffer ends in a newline.
X    (or (= (preceding-char) ?\n)
X	(insert "\n"))
X    ;; Scan the whole buffer, converting to Info format.
X    (goto-char (point-min))
X    (latexinfo-format-scan-noverbatim)
X    ;; Return data for indices.
X    (goto-char (point-min))
X    (list outfile
X	  latexinfo-vindex latexinfo-findex latexinfo-cindex
X	  latexinfo-pindex latexinfo-tindex latexinfo-kindex)))
X
X(defvar latexinfo-region-buffer-name "*Info Region*"
X  "*Name of the temporary buffer used by \\[latexinfo-format-region].")
X
X(defun latexinfo-format-region (region-beginning region-ending)
X  "Convert the the current region of the Latexinfo file to Info format.
XThis lets you see what that part of the file will look like in Info.
XThe command is bound to \\[latexinfo-format-region].  The text that is
Xconverted to Info is stored in a temporary buffer."
X  (interactive "r")
X  (message "Converting region to Info format...")
X  (let (latexinfo-command-start
X	latexinfo-command-end
X	latexinfo-command-name
X	latexinfo-vindex
X	latexinfo-findex
X	latexinfo-cindex
X	latexinfo-pindex
X	latexinfo-tindex
X	latexinfo-kindex
X	latexinfo-stack
X	latexinfo-format-filename
X	latexinfo-example-start
X	latexinfo-last-node
X	latexinfo-node-names
X	(fill-column fill-column)
X	(input-buffer (current-buffer))
X	(input-directory default-directory)
X	filename-beginning
X	filename-ending)
X
X;;; Find a buffer to use.
X
X    (switch-to-buffer (get-buffer-create latexinfo-region-buffer-name))
X
X    ;; Insert the region into the buffer.
X    (erase-buffer)
X
X    (save-excursion
X      (set-buffer input-buffer)
X      (save-excursion
X	(save-restriction
X	  (widen)
X	  (goto-char (point-min))
X	  ;; Initialize the buffer with the filename
X	  ;; or else explain that a filename is needed.
X	  (or (search-forward "\\setfilename"
X			      (save-excursion (forward-line 100) (point)) t)
X	      (error "The latexinfo file needs a line saying: \\setfilename <name>"))
X	  (beginning-of-line)
X	  (setq filename-beginning (point))
X	  (forward-line 1)
X	  (setq filename-ending (point)))))
X
X    ;; Insert the \\setfilename line into the buffer.
X    (insert-buffer-substring input-buffer
X			     (min filename-beginning region-beginning)  
X			     filename-ending)
X    
X    ;; Insert the region into the buffer.
X    (insert-buffer-substring input-buffer
X			     (max region-beginning filename-ending)
X			     region-ending)
X
X    (latexinfo-mode)
X
X    ;; Install a syntax table useful for scanning command operands.
X    (set-syntax-table latexinfo-format-syntax-table)
X    
X    ;; If the region includes the effective end of the data,
X    ;; discard everything after that.
X    (goto-char (point-max))
X    (if (search-backward "\\end{document}" nil t)
X	(delete-region (point) (point-max)))
X    ;; Make sure buffer ends in a newline.
X    (or (= (preceding-char) ?\n)
X	(insert "\n"))
X
X    (goto-char (point-max))
X    ;; Now convert for real.
X    (goto-char (point-min))
X    (latexinfo-format-scan-noverbatim)
X    (goto-char (point-min)))
X
X  (message "Done."))
X
X(defun latexinfo-format-scan-noverbatim ()
X  (if (re-search-forward "^\\\\begin{verbatim}\\|\\\\input{" nil t)
X      (let ((start (point-min))
X	    end
X	    str)
X	(goto-char start)
X	(while (re-search-forward "^\\\\begin{verbatim}\\|\\\\input{" nil t)
X	  (setq str (buffer-substring (match-beginning 0) (match-end 0)))
X	  ;; Handle LaTeX \input{filename} commands by inserting them now.
X	  ;; Only look at the beginning of the line to avoid \c \input{foo}
X	  (cond ((string-equal str "\\input{")
X		 (save-excursion
X		   (skip-chars-forward " 	{")
X		   (let ((file-name
X			  (buffer-substring 
X			   (point)
X			   (progn
X			     (skip-chars-forward "^ 	}\n")
X			     (point)))))
X		     (setq file-name
X			   (expand-file-name
X			    (if (file-readable-p (expand-file-name file-name))
X				file-name
X			      (concat file-name ".tex"))))
X		     (beginning-of-line 1)
X		     (delete-region (point) (progn (forward-line 1) (point)))
X		     (message "Inserting file %s..." file-name) (sit-for 1)
X		     (insert-file file-name)
X		     (message "Inserting file %s...done" file-name)
X		     )))
X		((string-equal str "\\begin{verbatim}")
X		 (delete-region (point) (progn (beginning-of-line 1) (point)))
X;;		 (message "texinfo-format-scan-noverbatim %d" (point))
X;;		 (sit-for 1)
X		 (latexinfo-format-expand-region start (point))
X		 (setq start
X		       (progn
X			 (goto-char start)
X			 (if (re-search-forward "^\\\\end{verbatim}" nil t)
X			     (progn
X			       (delete-region (point)
X					      (progn (beginning-of-line 1)
X						     (forward-char -1)
X						     (point)))
X			       (point))
X			   (error "Missing \\end{verbatim}"))))
X		 )))
X	(latexinfo-format-expand-region start (point-max))
X	)
X    (latexinfo-format-scan)))
X
X(put 'verbatim 'latexinfo-format 'latexinfo-format-verbatim)
X(defun latexinfo-format-verbatim ()
X  (error "Nested verbatim environments are not supported"))
X
X(defun latexinfo-format-scan ()
X  ;; LaTeX sometimes uses \\ to force a new-line
X  (goto-char (point-min))
X  (replace-regexp "\\\\\\\\$" "")
X  ;; Convert left and right quotes to typewriter font quotes.
X  (goto-char (point-min))
X  (while (search-forward "``" nil t)
X    (replace-match "\""))
X  (goto-char (point-min))
X  (while (search-forward "''" nil t)
X    (replace-match "\""))
X  ;; Scan for \\-commands.
X  (goto-char (point-min))
X  (while (search-forward "\\" nil t)
X    (if (looking-at "[@{}'` *%]")
X	;; Handle a few special \-followed-by-one-char commands.
X	(if (= (following-char) ?*)
X	    ;; \* has no effect, since we are not filling.
X	    (delete-region (1- (point)) (1+ (point)))
X	  ;; The other characters are simply quoted.  Delete the \.
X	  (delete-char -1)
X	  (forward-char 1))
X      ;; \ is followed by a command-word; find the end of the word.
X      (setq latexinfo-command-start (1- (point)))
X      (if (= (char-syntax (following-char)) ?w)
X	  (forward-word 1)
X	(forward-char 1))
X      (setq latexinfo-command-end (point))
X      ;; Call the handler for this command.
X      (setq latexinfo-command-name
X	    (intern (buffer-substring (1+ latexinfo-command-start)
X				      latexinfo-command-end)))
X      (let ((cmd (get latexinfo-command-name 'latexinfo-format)))
X	(if cmd (funcall cmd)
X	  (latexinfo-unsupported)))))
X  (cond (latexinfo-stack
X	 (goto-char (nth 2 (car latexinfo-stack)))
X	 (error "Unterminated \begin{%s}" (car (car latexinfo-stack))))))
X
X(put 'begin 'latexinfo-format 'latexinfo-format-begin)
X(defun latexinfo-format-begin ()
X  (latexinfo-format-begin-end 'latexinfo-format))
X
X(put 'end 'latexinfo-format 'latexinfo-format-end)
X(defun latexinfo-format-end ()
X  (latexinfo-format-begin-end 'latexinfo-end))
X
X(defun latexinfo-format-begin-end (prop)
X  (setq latexinfo-command-name (intern (latexinfo-parse-line-arg)))
X  (setq cmd (get latexinfo-command-name prop))
X  (if cmd (funcall cmd)
X    (latexinfo-unsupported)))
X
X(defun latexinfo-parse-line-arg ()
X  (goto-char latexinfo-command-end)
X  (let ((start (point)))
X    (cond ((looking-at " ")
X	   (skip-chars-forward " ")
X	   (setq start (point))
X	   (end-of-line)
X	   (setq latexinfo-command-end (1+ (point))))
X	  ((looking-at "[{\\[]")
X	   (setq start (1+ (point)))
X	   (forward-list 1)
X	   (setq latexinfo-command-end (point))
X	   (forward-char -1))
X	  (t
X	   (error "Invalid latexinfo command arg format")))
X    (prog1 (buffer-substring start (point))
X	   (if (eolp) (forward-char 1)))))
X
X(defun latexinfo-parse-expanded-arg ()
X  (goto-char latexinfo-command-end)
X  (let ((start (point))
X	marker)
X    (cond ((looking-at " ")
X	   (skip-chars-forward " ")
X	   (setq start (point))
X	   (end-of-line)
X	   (setq latexinfo-command-end (1+ (point))))
X	  ((looking-at "[{\\[]")
X	   (setq start (1+ (point)))
X	   (forward-list 1)
X	   (setq latexinfo-command-end (point))
X	   (forward-char -1))
X	  (t
X	   (error "Invalid latexinfo command arg format")))
X    (setq marker (move-marker (make-marker) latexinfo-command-end))
X    (latexinfo-format-expand-region start (point))
X    (setq latexinfo-command-end (marker-position marker))
X    (move-marker marker nil)
X    (prog1 (buffer-substring start (point))
X	   (if (eolp) (forward-char 1)))))
X
X(defun latexinfo-format-expand-region (start end)
X  (save-restriction
X    (narrow-to-region start end)
X    (let (latexinfo-command-start
X	  latexinfo-command-end
X	  latexinfo-command-name
X	  latexinfo-stack)
X      (latexinfo-format-scan))
X    (goto-char (point-max))))
X
X(defun latexinfo-parse-arg-discard ()
X  (prog1 (latexinfo-parse-line-arg)
X	 (latexinfo-discard-command)))
X
X(defun latexinfo-discard-command ()
X  (delete-region latexinfo-command-start latexinfo-command-end))
X
X(defun latexinfo-format-parse-line-args ()
X  (let ((start (1- (point)))
X	next beg end
X	args)
X    (skip-chars-forward " ")
X    (while (not (eolp))
X      (setq beg (point))
X      (re-search-forward "[\n,]")
X      (setq next (point))
X      (if (bolp) (setq next (1- next)))
X      (forward-char -1)
X      (skip-chars-backward " ")
X      (setq end (point))
X      (setq args (cons (if (> end beg) (buffer-substring beg end))
X		       args))
X      (goto-char next)
X      (skip-chars-forward " "))
X    (if (eolp) (forward-char 1))
X    (setq latexinfo-command-end (point))
X    (nreverse args)))
X
X(defun latexinfo-format-parse-args ()
X  (let ((start (1- (point)))
X	next beg end
X	args)
X    (search-forward "{")
X    (while (/= (preceding-char) ?\})
X      (skip-chars-forward " \t\n")
X      (setq beg (point))
X      (re-search-forward "[},]")
X      (setq next (point))
X      (forward-char -1)
X      (skip-chars-backward " \t\n")
X      (setq end (point))
X      (cond ((< beg end)
X	     (goto-char beg)
X	     (while (search-forward "\n" end t)
X	       (replace-match " "))))
X      (setq args (cons (if (> end beg) (buffer-substring beg end))
X		       args))
X      (goto-char next))
X    (if (eolp) (forward-char 1))
X    (setq latexinfo-command-end (point))
X    (nreverse args)))
X
X(defun latexinfo-format-parse-defun-args ()
X  (goto-char latexinfo-command-end)
X  (let ((start (point)))
X    (end-of-line)
X    (setq latexinfo-command-end (1+ (point)))
X    (let ((marker (move-marker (make-marker) latexinfo-command-end)))
X      (latexinfo-format-expand-region start (point))
X      (setq latexinfo-command-end (marker-position marker))
X      (move-marker marker nil))
X    (goto-char start)
X    (let ((args '())
X	  beg end)
X      (skip-chars-forward " ")
X      (while (not (eolp))
X	(cond ((looking-at "[{\\[]")
X	       (setq beg (1+ (point)))
X	       (forward-list 1)
X	       (setq end (1- (point))))
X	      (t
X	       (setq beg (point))
X	       (re-search-forward "[\n ]")
X	       (forward-char -1)
X	       (setq end (point))))
X	(setq args (cons (buffer-substring beg end) args))
X	(skip-chars-forward " "))
X      (forward-char 1)
X      (nreverse args))))
X
X(put 'setfilename 'latexinfo-format 'latexinfo-format-setfilename)
X(defun latexinfo-format-setfilename ()
X  (let ((arg (latexinfo-parse-arg-discard)))
X    (setq latexinfo-format-filename
X	  (file-name-nondirectory (expand-file-name arg)))
X    (insert "Info file: "
X	    latexinfo-format-filename ",    -*-Text-*-\n"
X	    "produced by latexinfo-format-buffer\nfrom "
X	    (if (buffer-file-name input-buffer)
X		(concat "file: "
X			(file-name-sans-versions
X			 (file-name-nondirectory
X			  (buffer-file-name input-buffer))))
X	      (concat "buffer " (buffer-name input-buffer)))
X	    "\n\n")))
X
X(put 'node 'latexinfo-format 'latexinfo-format-node)
X(defun latexinfo-format-node ()
X  (let* ((args (latexinfo-format-parse-line-args))
X	 (name (nth 0 args))
X	 (next (nth 1 args))
X	 (prev (nth 2 args))
X	 (up (nth 3 args)))
X    (latexinfo-discard-command)
X    (setq latexinfo-last-node name)
X    (let ((tem (downcase name)))
X      (if (assoc tem latexinfo-node-names)
X	  (error "Duplicate node name: %s" name)
X	(setq latexinfo-node-names (cons tem latexinfo-node-names))))
X    (or (bolp)
X	(insert ?\n))
X    (insert "\^_\nFile: " latexinfo-format-filename
X	    "  Node: " name)
X    (if prev
X	(insert ", Prev: " prev))
X    (if up
X	(insert ", Up: " up))
X    (if next
X	(insert ", Next: " next))
X    (insert ?\n)))
X
X(put 'menu 'latexinfo-format 'latexinfo-format-menu)
X(defun latexinfo-format-menu ()
X  (latexinfo-discard-line)
X  (insert "* Menu:\n\n"))
X
X(put 'menu 'latexinfo-end 'latexinfo-discard-command)
X(defun latexinfo-discard-line ()
X  (goto-char latexinfo-command-end)
X  (skip-chars-forward " \t")
X  (or (eolp)
X      (error "Extraneous text at end of command line."))
X  (goto-char latexinfo-command-start)
X  (or (bolp)
X      (error "Extraneous text at beginning of command line."))
X  (delete-region (point) (progn (forward-line 1) (point))))
X
X; \xref {NODE, FNAME, NAME, FILE, DOCUMENT}
X; -> *Note FNAME: (FILE)NODE
X;   If FILE is missing,
X;    *Note FNAME: NODE
X;   If FNAME is empty and NAME is present
X;    *Note NAME: Node
X;   If both NAME and FNAME are missing
X;    *Note NODE::
X;   latexinfo ignores the DOCUMENT argument.
X; -> See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
X;   If FILE is specified, (FILE)NODE is used for xrefs.
X;   If fifth argument DOCUMENT is specified, produces
X;    See section <xref to NODE> [NAME, else NODE], page <xref to NODE>
X;    of DOCUMENT
X(put 'xref 'latexinfo-format 'latexinfo-format-xref)
X(defun latexinfo-format-xref ()
X  (let ((args (latexinfo-format-parse-args)))
X    (latexinfo-discard-command)
X    (insert "*Note ")
X    (let ((fname (or (nth 1 args) (nth 2 args))))
X      (if (null (or fname (nth 3 args)))
X	  (insert (car args) "::")
X	(insert (or fname (car args)) ": ")
X	(if (nth 3 args)
X	    (insert "(" (nth 3 args) ")"))
X	(insert (car args))))))
X
X(put 'pxref 'latexinfo-format 'latexinfo-format-pxref)
X(defun latexinfo-format-pxref ()
X  (latexinfo-format-xref)
X  (or (save-excursion
X	(forward-char -2)
X	(looking-at "::"))
X      (insert ".")))
X
X;\inforef{NODE, FNAME, FILE}
X;Like \xref{NODE, FNAME,,FILE} in latexinfo.
X;In LaTeX, generates "See Info file FILE, node NODE"
X(put 'inforef 'latexinfo-format 'latexinfo-format-inforef)
X(defun latexinfo-format-inforef ()
X  (let ((args (latexinfo-format-parse-args)))
X    (latexinfo-discard-command)
X    (insert "*Note " (nth 1 args) ": (" (nth 2 args) ")" (car args))))
X
X(put 'appendix 'latexinfo-format 'latexinfo-parse-noarg)
X
X(put 'chapter 'latexinfo-format 'latexinfo-format-chapter)
X(put 'chapter* 'latexinfo-format 'latexinfo-format-chapter)
X(defun latexinfo-format-chapter ()
X  (latexinfo-format-chapter-1 ?*))
X
X(put 'section 'latexinfo-format 'latexinfo-format-section)
X(put 'section* 'latexinfo-format 'latexinfo-format-section)
X(defun latexinfo-format-section ()
X  (latexinfo-format-chapter-1 ?=))
X
X(put 'subsection 'latexinfo-format 'latexinfo-format-subsection)
X(put 'subsection* 'latexinfo-format 'latexinfo-format-subsection)
X(defun latexinfo-format-subsection ()
X  (latexinfo-format-chapter-1 ?-))
X
X(put 'subsubsection 'latexinfo-format 'latexinfo-format-subsubsection)
X(put 'subsubsection* 'latexinfo-format 'latexinfo-format-subsubsection)
X(defun latexinfo-format-subsubsection ()
X  (latexinfo-format-chapter-1 ?.))
X
X(defun latexinfo-format-chapter-1 (belowchar)
X  (let ((arg (latexinfo-parse-arg-discard)))
X    (insert ?\n arg ?\n "\\SectionPAD " belowchar ?\n)
X    (forward-line -2)))
X
X(put 'SectionPAD 'latexinfo-format 'latexinfo-format-sectionpad)
X(defun latexinfo-format-sectionpad ()
X  (let ((str (latexinfo-parse-arg-discard)))
X    (forward-char -1)
X    (let ((column (current-column)))
X      (forward-char 1)
X      (while (> column 0)
X	(insert str)
X	(setq column (1- column))))
X    (insert ?\n)))
X
X(put '\. 'latexinfo-format 'latexinfo-format-\.)
X(defun latexinfo-format-\. ()
X  (latexinfo-discard-command)
X  (insert "."))
X
X(put '\: 'latexinfo-format 'latexinfo-format-\:)
X(defun latexinfo-format-\: ()
X  (latexinfo-discard-command))
X
X
X;; \begin{itemize} pushes (itemize "COMMANDS" STARTPOS) on latexinfo-stack.
X;; \begin{enumerate} pushes (enumerate 0 STARTPOS).
X;; \item dispatches to the latexinfo-item prop of the first elt of the list.
X;; For itemize, this puts in and rescans the COMMANDS.
X;; For enumerate, this increments the number and puts it in.
X;; In either case, it puts a Backspace at the front of the line
X;; which marks it not to be indented later.
X;; All other lines get indented by 5 when the \end is reached.
X
X(defun latexinfo-push-stack (check arg)
X  (setq latexinfo-stack
X	(cons (list check arg latexinfo-command-start)
X	      latexinfo-stack)))
X
X(defun latexinfo-pop-stack (check)
X  (if (null latexinfo-stack)
X      (error "Unmatched \\end{%s}" check))
X  (if (not (eq (car (car latexinfo-stack)) check))
X      (error "\\end{%s} matches \\begin{%s}"
X	     check (car (car latexinfo-stack))))
X  (prog1 (cdr (car latexinfo-stack))
X	 (setq latexinfo-stack (cdr latexinfo-stack))))
X
X(put 'itemize 'latexinfo-format 'latexinfo-itemize)
X(defun latexinfo-itemize ()
X  (latexinfo-push-stack 'itemize "*")
X  (setq fill-column (- fill-column 5))
X  (latexinfo-discard-line))
X
X(put 'itemize 'latexinfo-end 'latexinfo-end-itemize)
X(defun latexinfo-end-itemize ()
X  (setq fill-column (+ fill-column 5))
X  (latexinfo-discard-command)
X  (let ((stacktop
X	 (latexinfo-pop-stack 'itemize)))
X    (latexinfo-do-itemize (nth 1 stacktop))))
X
X(put 'enumerate 'latexinfo-format 'latexinfo-enumerate)
X(defun latexinfo-enumerate ()
X  (latexinfo-push-stack 'enumerate 0)
X  (setq fill-column (- fill-column 5))
X  (latexinfo-discard-line))
X
X(put 'enumerate 'latexinfo-end 'latexinfo-end-enumerate)
X(defun latexinfo-end-enumerate ()
X  (setq fill-column (+ fill-column 5))
X  (latexinfo-discard-command)
X  (let ((stacktop
X	 (latexinfo-pop-stack 'enumerate)))
X    (latexinfo-do-itemize (nth 1 stacktop))))
X
X(put 'center 'latexinfo-format 'latexinfo-format-center)
X(defun latexinfo-format-center ()
X  (latexinfo-push-stack 'center 0)
X  (latexinfo-discard-line))
X
X(put 'center 'latexinfo-end 'latexinfo-end-center)
X(defun latexinfo-end-center ()
X  (latexinfo-discard-command)
X  (let ((stacktop
X	 (latexinfo-pop-stack 'center)))
X    (latexinfo-do-center (nth 1 stacktop))))
X
X(defun latexinfo-do-center (from)
X  (let ((indent-tabs-mode nil))
X    (while (progn (forward-line -1)
X		  (>= (point) from))
X      (save-excursion
X	(center-line)))))
X
X(put 'table 'latexinfo-format 'latexinfo-table)
X(defun latexinfo-table ()
X  (latexinfo-push-stack 'table (latexinfo-parse-arg-discard))
X  (setq fill-column (- fill-column 5)))
X
X(put 'ftable 'latexinfo-format 'latexinfo-ftable)
X(defun latexinfo-ftable ()
X  (latexinfo-push-stack 'table "\\code")
X  (setq fill-column (- fill-column 5))
X  (latexinfo-discard-line))
X
X(put 'description 'latexinfo-format 'latexinfo-description)
X(defun latexinfo-description ()
X  (latexinfo-push-stack 'table "\\asis")
X  (setq fill-column (- fill-column 5))
X  (latexinfo-discard-line))
X
X(put 'table 'latexinfo-end 'latexinfo-end-table)
X(put 'ftable 'latexinfo-end 'latexinfo-end-table)
X(put 'description 'latexinfo-end 'latexinfo-end-table)
X(defun latexinfo-end-table ()
X  (setq fill-column (+ fill-column 5))
X  (latexinfo-discard-command)
X  (let ((stacktop
X	 (latexinfo-pop-stack 'table)))
X    (latexinfo-do-itemize (nth 1 stacktop))))
X
X;; At the \end, indent all the lines within the construct
X;; except those marked with backspace.  FROM says where
X;; construct started.
X(defun latexinfo-do-itemize (from)
X  (save-excursion
X   (while (progn (forward-line -1)
X		 (>= (point) from))
X     (if (= (following-char) ?\b)
X	 (save-excursion
X	   (delete-char 1)
X	   (end-of-line)
X	   (delete-char 6))
X       (save-excursion (insert "     "))))))
X
X(put 'item 'latexinfo-format 'latexinfo-item)
X(defun latexinfo-item ()
X  (funcall (get (car (car latexinfo-stack)) 'latexinfo-item)))
X
X(put 'itemize 'latexinfo-item 'latexinfo-itemize-item)
X(defun latexinfo-itemize-item ()
X  (latexinfo-parse-noarg)
X  (insert "\b   " (nth 1 (car latexinfo-stack)) " \n")
X  (forward-line -1))
X
X(put 'enumerate 'latexinfo-item 'latexinfo-enumerate-item)
X(defun latexinfo-enumerate-item ()
X  (latexinfo-parse-noarg)
X  (let ((next (1+ (car (cdr (car latexinfo-stack))))))
X    (setcar (cdr (car latexinfo-stack)) next)
X    (insert ?\b (format "%3d. " next) ?\n))
X  (forward-line -1))
X
X(put 'table 'latexinfo-item 'latexinfo-table-item)
X(defun latexinfo-table-item ()
X  (let ((arg (latexinfo-parse-arg-discard))
X	(itemfont (car (cdr (car latexinfo-stack)))))
X    (insert ?\b itemfont ?\{ arg "}\n     \n"))
X  (forward-line -2))
X
X(put 'ifinfo 'latexinfo-format 'latexinfo-discard-line)
X(put 'ifinfo 'latexinfo-end 'latexinfo-discard-command)
X
X(put 'iftex 'latexinfo-format 'latexinfo-format-iftex)
X(defun latexinfo-format-iftex ()
X  (delete-region latexinfo-command-start
X		 (progn (re-search-forward "\\\\end[ {]iftex[ }\n]")
X			(point))))
X
X(put 'tex 'latexinfo-format 'latexinfo-format-tex)
X(defun latexinfo-format-tex ()
X  (delete-region latexinfo-command-start
X		 (progn (re-search-forward "\\end[ {]tex[ 	}\n]")
X			(point))))
X
X(put 'ignore 'latexinfo-format 'latexinfo-format-ignore)
X(defun latexinfo-format-ignore ()
X  (delete-region latexinfo-command-start
X		 (progn (re-search-forward "\\\\end[ {]ignore[ 	}\n]")
X			(point))))
X
X(put 'endignore 'latexinfo-format 'latexinfo-discard-line)
X
X(put 'var 'latexinfo-format 'latexinfo-format-var)
X(defun latexinfo-format-var ()
X  (insert (upcase (latexinfo-parse-arg-discard)))
X  (goto-char latexinfo-command-start))
X
X(put 'asis 'latexinfo-format 'latexinfo-format-noop)
X(put 'b 'latexinfo-format 'latexinfo-format-noop)
X(put 't 'latexinfo-format 'latexinfo-format-noop)
X(put 'i 'latexinfo-format 'latexinfo-format-noop)
X(put 'key 'latexinfo-format 'latexinfo-format-noop)
X(put 'w 'latexinfo-format 'latexinfo-format-noop)
X(defun latexinfo-format-noop ()
X  (insert (latexinfo-parse-arg-discard))
X  (goto-char latexinfo-command-start))
X
X(put 'code 'latexinfo-format 'latexinfo-format-code)
X(put 'samp 'latexinfo-format 'latexinfo-format-code)
X(put 'file 'latexinfo-format 'latexinfo-format-code)
X(put 'kbd 'latexinfo-format 'latexinfo-format-code)
X(defun latexinfo-format-code ()
X  (insert "`" (latexinfo-parse-arg-discard) "'")
X  (goto-char latexinfo-command-start))
X
X(put 'emph 'latexinfo-format 'latexinfo-format-emph)
X(put 'strong 'latexinfo-format 'latexinfo-format-emph)
X(defun latexinfo-format-emph ()
X  (insert "*" (latexinfo-parse-arg-discard) "*"))
X
X(put 'defn 'latexinfo-format 'latexinfo-format-defn)
X(put 'dfn 'latexinfo-format 'latexinfo-format-defn)
X(defun latexinfo-format-defn ()
X  (insert "\"" (latexinfo-parse-arg-discard) "\"")
X  (goto-char latexinfo-command-start))
X
X(put 'bullet 'latexinfo-format 'latexinfo-format-bullet)
X(defun latexinfo-format-bullet ()
X  (latexinfo-discard-command)
X  (insert "*"))
X
X(put 'smallexample 'latexinfo-format 'latexinfo-format-example)
X(put 'example 'latexinfo-format 'latexinfo-format-example)
X(put 'quotation 'latexinfo-format 'latexinfo-format-example)
X(put 'lisp 'latexinfo-format 'latexinfo-format-example)
X(put 'display 'latexinfo-format 'latexinfo-format-example)
X(put 'format 'latexinfo-format 'latexinfo-format-example)
X(put 'flushleft 'latexinfo-format 'latexinfo-format-example)
X(defun latexinfo-format-example ()
X  (latexinfo-push-stack 'example nil)
X  (setq fill-column (- fill-column 5))
X  (latexinfo-discard-line))
X
X(put 'smallexample 'latexinfo-end 'latexinfo-end-example)
X(put 'example 'latexinfo-end 'latexinfo-end-example)
X(put 'quotation 'latexinfo-end 'latexinfo-end-example)
X(put 'lisp 'latexinfo-end 'latexinfo-end-example)
X(put 'display 'latexinfo-end 'latexinfo-end-example)
X(put 'format 'latexinfo-end 'latexinfo-end-example)
X(put 'flushleft 'latexinfo-end 'latexinfo-end-example)
X(defun latexinfo-end-example ()
X  (setq fill-column (+ fill-column 5))
X  (latexinfo-discard-command)
X  (let ((stacktop
X	 (latexinfo-pop-stack 'example)))
X    (latexinfo-do-itemize (nth 1 stacktop))))
X
X(put 'exdent 'latexinfo-format 'latexinfo-format-exdent)
X(defun latexinfo-format-exdent ()
X  (latexinfo-discard-command)
X  (delete-region (point)
X		 (progn
X		  (skip-chars-forward " ")
X		  (point)))
X  (insert ?\b)
X  ;; Cancel out the deletion that latexinfo-do-itemize
X  ;; is going to do at the end of this line.
X  (save-excursion
X    (end-of-line)
X    (insert "\n     ")))
X
X(put 'ctrl 'latexinfo-format 'latexinfo-format-ctrl)
X(defun latexinfo-format-ctrl ()
X  (let ((str (latexinfo-parse-arg-discard)))
X    (insert "^" str)))
X    ;;    (insert (logand 31 (aref str 0)))))
X
X(put 'TeX 'latexinfo-format 'latexinfo-format-TeX)
X(defun latexinfo-format-TeX ()
X  (latexinfo-parse-noarg)
X  (insert "TeX"))
X
X(put 'copyright 'latexinfo-format 'latexinfo-format-copyright)
X(defun latexinfo-format-copyright ()
X  (latexinfo-parse-noarg)
X  (insert "(C)"))
X
X(put 'minus 'latexinfo-format 'latexinfo-format-minus)
X(defun latexinfo-format-minus ()
X  (latexinfo-parse-arg-discard)
X  (insert "-"))
X
X(put 'dots 'latexinfo-format 'latexinfo-format-dots)
X(defun latexinfo-format-dots ()
X  (latexinfo-discard-command)
X  (insert "..."))
X
X(put 'refill 'latexinfo-format 'latexinfo-format-refill)
X(defun latexinfo-format-refill ()
X  (latexinfo-discard-command)
X  (fill-paragraph nil))
X
X;; Index generation
X
X(put 'vindex 'latexinfo-format 'latexinfo-format-vindex)
X(defun latexinfo-format-vindex ()
X  (latexinfo-index 'latexinfo-vindex))
X
X(put 'cindex 'latexinfo-format 'latexinfo-format-cindex)
X(defun latexinfo-format-cindex ()
X  (latexinfo-index 'latexinfo-cindex))
X
X(put 'findex 'latexinfo-format 'latexinfo-format-findex)
X(defun latexinfo-format-findex ()
X  (latexinfo-index 'latexinfo-findex))
X
X(put 'pindex 'latexinfo-format 'latexinfo-format-pindex)
X(defun latexinfo-format-pindex ()
X  (latexinfo-index 'latexinfo-pindex))
X
X(put 'tindex 'latexinfo-format 'latexinfo-format-tindex)
X(defun latexinfo-format-tindex ()
X  (latexinfo-index 'latexinfo-tindex))
X
X(put 'kindex 'latexinfo-format 'latexinfo-format-kindex)
X(defun latexinfo-format-kindex ()
X  (latexinfo-index 'latexinfo-kindex))
X
X(defun latexinfo-index (indexvar)
X  (let ((arg (latexinfo-parse-expanded-arg)))
X    (latexinfo-discard-command)
X    (set indexvar
X	 (cons (list arg latexinfo-last-node)
X	       (symbol-value indexvar)))))
X
X(defconst latexinfo-indexvar-alist
X  '(("cp" . latexinfo-cindex)
X    ("fn" . latexinfo-findex)
X    ("vr" . latexinfo-vindex)
X    ("tp" . latexinfo-tindex)
X    ("pg" . latexinfo-pindex)
X    ("ky" . latexinfo-kindex)))
X
X(put 'printindex 'latexinfo-format 'latexinfo-format-printindex)
X(defun latexinfo-format-printindex ()
X  (let ((indexelts (symbol-value
X		    (cdr (assoc (latexinfo-parse-arg-discard)
X				latexinfo-indexvar-alist))))
X	opoint)
X    (insert "\n* Menu:\n\n")
X    (setq opoint (point))
X    (latexinfo-print-index nil indexelts)
X    (if (eq system-type 'vax-vms) 
X	(latexinfo-sort-region opoint (point))
X      (shell-command-on-region opoint (point) "sort -fd" 1))))
X
X(defun latexinfo-print-index (file indexelts)
X  (while indexelts
X    (if (stringp (car (car indexelts)))
X	(insert "* " (car (car indexelts))
X		": " (if file (concat "(" file ")") "")
X		(nth 1 (car indexelts)) ".\n")
X      ;; index entries from \include'd file
X      (latexinfo-print-index (nth 1 (car indexelts))
X			   (nth 2 (car indexelts))))
X    (setq indexelts (cdr indexelts))))
X
X
X;;;; Lisp Definitions
X
X(defun latexinfo-format-defun ()
X  (latexinfo-push-stack 'defun nil)
X  (setq fill-column (- fill-column 5))
X  (latexinfo-format-defun-1 t))
X
X(defun latexinfo-format-defunx ()
X  (latexinfo-format-defun-1 nil))
X
X(defun latexinfo-format-defun-1 (first-p)
X  (let ((args (latexinfo-format-parse-defun-args))
X	(type (get latexinfo-command-name 'latexinfo-defun-type)))
X    (latexinfo-discard-command)
X    (if (eq type 'arg)
X	(progn (setq type (car args))
X	       (setq args (cdr args))))
X    (let ((formatter (get latexinfo-command-name 'latexinfo-defun-format-type)))
X      (if formatter
X	  (setq type (funcall formatter type args))))
X    ;; Delete extra newline inserted after previous header line.
X    (if (not first-p)
X	(delete-char -1))
X    (insert "* " type ": " (car args))
X    (let ((args (cdr args)))
X      (while args
X	(insert " " (upcase (car args)))
X	(setq args (cdr args))))
X    ;; Insert extra newline so that paragraph filling does not mess
X    ;; with header line.
X    (insert "\n\n")
X    (rplaca (cdr (cdr (car latexinfo-stack))) (point))
X    (let ((indexvar (get latexinfo-command-name 'latexinfo-defun-index))
X	  (formatter (get latexinfo-command-name 'latexinfo-defun-format-index)))
X      (set indexvar
X	   (cons (list (if formatter (funcall formatter type args) (car args))
X		       latexinfo-last-node)
X		 (symbol-value indexvar))))))
X
X(defun latexinfo-end-defun ()
X  (setq fill-column (+ fill-column 5))
X  (latexinfo-discard-command)
X  (let ((start (nth 1 (latexinfo-pop-stack 'defun))))
X    (latexinfo-do-itemize start)
X    ;; Delete extra newline inserted after header.
X    (save-excursion
X      (goto-char start)
X      (delete-char -1))))
X
X(put 'deffn 'latexinfo-format 'latexinfo-format-defun)
X(put 'deffnx 'latexinfo-format 'latexinfo-format-defunx)
X(put 'deffn 'latexinfo-end 'latexinfo-end-defun)
X(put 'deffn 'latexinfo-defun-type 'arg)
X(put 'deffnx 'latexinfo-defun-type 'arg)
X(put 'deffn 'latexinfo-defun-index 'latexinfo-findex)
X(put 'deffnx 'latexinfo-defun-index 'latexinfo-findex)
X
X(put 'defun 'latexinfo-format 'latexinfo-format-defun)
X(put 'defunx 'latexinfo-format 'latexinfo-format-defunx)
X(put 'defun 'latexinfo-end 'latexinfo-end-defun)
X(put 'defun 'latexinfo-defun-type "Function")
X(put 'defunx 'latexinfo-defun-type "Function")
X(put 'defun 'latexinfo-defun-index 'latexinfo-findex)
X(put 'defunx 'latexinfo-defun-index 'latexinfo-findex)
X
X(put 'defmac 'latexinfo-format 'latexinfo-format-defun)
X(put 'defmacx 'latexinfo-format 'latexinfo-format-defunx)
X(put 'defmac 'latexinfo-end 'latexinfo-end-defun)
X(put 'defmac 'latexinfo-defun-type "Macro")
X(put 'defmacx 'latexinfo-defun-type "Macro")
X(put 'defmac 'latexinfo-defun-index 'latexinfo-findex)
X(put 'defmacx 'latexinfo-defun-index 'latexinfo-findex)
X
X(put 'defspec 'latexinfo-format 'latexinfo-format-defun)
X(put 'defspecx 'latexinfo-format 'latexinfo-format-defunx)
X(put 'defspec 'latexinfo-end 'latexinfo-end-defun)
X(put 'defspec 'latexinfo-defun-type "Special form")
X(put 'defspecx 'latexinfo-defun-type "Special form")
X(put 'defspec 'latexinfo-defun-index 'latexinfo-findex)
X(put 'defspecx 'latexinfo-defun-index 'latexinfo-findex)
X
X(put 'defvr 'latexinfo-format 'latexinfo-format-defun)
X(put 'defvrx 'latexinfo-format 'latexinfo-format-defunx)
X(put 'defvr 'latexinfo-end 'latexinfo-end-defun)
X(put 'defvr 'latexinfo-defun-type 'arg)
X(put 'defvrx 'latexinfo-defun-type 'arg)
X(put 'defvr 'latexinfo-defun-index 'latexinfo-vindex)
X(put 'defvrx 'latexinfo-defun-index 'latexinfo-vindex)
X
X(put 'defvar 'latexinfo-format 'latexinfo-format-defun)
X(put 'defvarx 'latexinfo-format 'latexinfo-format-defunx)
X(put 'defvar 'latexinfo-end 'latexinfo-end-defun)
X(put 'defvar 'latexinfo-defun-type "Variable")
X(put 'defvarx 'latexinfo-defun-type "Variable")
X(put 'defvar 'latexinfo-defun-index 'latexinfo-vindex)
X(put 'defvarx 'latexinfo-defun-index 'latexinfo-vindex)
X
X(put 'defopt 'latexinfo-format 'latexinfo-format-defun)
X(put 'defoptx 'latexinfo-format 'latexinfo-format-defunx)
X(put 'defopt 'latexinfo-end 'latexinfo-end-defun)
X(put 'defopt 'latexinfo-defun-type "User Option")
X(put 'defoptx 'latexinfo-defun-type "User Option")
X(put 'defopt 'latexinfo-defun-index 'latexinfo-vindex)
X(put 'defoptx 'latexinfo-defun-index 'latexinfo-vindex)
X
X(put 'deftp 'latexinfo-format 'latexinfo-format-defun)
X(put 'deftpx 'latexinfo-format 'latexinfo-format-defunx)
X(put 'deftp 'latexinfo-end 'latexinfo-end-defun)
X(put 'deftp 'latexinfo-defun-type 'arg)
X(put 'deftpx 'latexinfo-defun-type 'arg)
X(put 'deftp 'latexinfo-defun-index 'latexinfo-tindex)
X(put 'deftpx 'latexinfo-defun-index 'latexinfo-tindex)
X
X;;; Object-oriented stuff is a little hairier.
X
X(put 'defop 'latexinfo-format 'latexinfo-format-defun)
X(put 'defopx 'latexinfo-format 'latexinfo-format-defunx)
X(put 'defop 'latexinfo-end 'latexinfo-end-defun)
X(put 'defop 'latexinfo-defun-type 'arg)
X(put 'defopx 'latexinfo-defun-type 'arg)
X(put 'defop 'latexinfo-defun-format-type 'latexinfo-format-defop-type)
X(put 'defopx 'latexinfo-defun-format-type 'latexinfo-format-defop-type)
X(put 'defop 'latexinfo-defun-index 'latexinfo-findex)
X(put 'defopx 'latexinfo-defun-index 'latexinfo-findex)
X(put 'defop 'latexinfo-defun-format-index 'latexinfo-format-defop-index)
X(put 'defopx 'latexinfo-defun-format-index 'latexinfo-format-defop-index)
X
X(put 'defmethod 'latexinfo-format 'latexinfo-format-defun)
X(put 'defmethodx 'latexinfo-format 'latexinfo-format-defunx)
X(put 'defmethod 'latexinfo-end 'latexinfo-end-defun)
X(put 'defmethod 'latexinfo-defun-type "Operation")
X(put 'defmethodx 'latexinfo-defun-type "Operation")
X(put 'defmethod 'latexinfo-defun-format-type 'latexinfo-format-defop-type)
X(put 'defmethodx 'latexinfo-defun-format-type 'latexinfo-format-defop-type)
X(put 'defmethod 'latexinfo-defun-index 'latexinfo-findex)
X(put 'defmethodx 'latexinfo-defun-index 'latexinfo-findex)
X(put 'defmethod 'latexinfo-defun-format-index 'latexinfo-format-defop-index)
X(put 'defmethodx 'latexinfo-defun-format-index 'latexinfo-format-defop-index)
X
X(defun latexinfo-format-defop-type (type args)
X  (format "%s on %s" type (car args)))
X
X(defun latexinfo-format-defop-index (type args)
X  (format "%s on %s" (car (cdr args)) (car args)))
X
X(put 'defcv 'latexinfo-format 'latexinfo-format-defun)
X(put 'defcvx 'latexinfo-format 'latexinfo-format-defunx)
X(put 'defcv 'latexinfo-end 'latexinfo-end-defun)
X(put 'defcv 'latexinfo-defun-type 'arg)
X(put 'defcvx 'latexinfo-defun-type 'arg)
X(put 'defcv 'latexinfo-defun-format-type 'latexinfo-format-defcv-type)
X(put 'defcvx 'latexinfo-defun-format-type 'latexinfo-format-defcv-type)
X(put 'defcv 'latexinfo-defun-index 'latexinfo-vindex)
X(put 'defcvx 'latexinfo-defun-index 'latexinfo-vindex)
X(put 'defcv 'latexinfo-defun-format-index 'latexinfo-format-defcv-index)
X(put 'defcvx 'latexinfo-defun-format-index 'latexinfo-format-defcv-index)
X
X(put 'defivar 'latexinfo-format 'latexinfo-format-defun)
X(put 'defivarx 'latexinfo-format 'latexinfo-format-defunx)
X(put 'defivar 'latexinfo-end 'latexinfo-end-defun)
X(put 'defivar 'latexinfo-defun-type "Instance variable")
X(put 'defivarx 'latexinfo-defun-type "Instance variable")
X(put 'defivar 'latexinfo-defun-format-type 'latexinfo-format-defcv-type)
X(put 'defivarx 'latexinfo-defun-format-type 'latexinfo-format-defcv-type)
X(put 'defivar 'latexinfo-defun-index 'latexinfo-vindex)
X(put 'defivarx 'latexinfo-defun-index 'latexinfo-vindex)
X(put 'defivar 'latexinfo-defun-format-index 'latexinfo-format-defcv-index)
X(put 'defivarx 'latexinfo-defun-format-index 'latexinfo-format-defcv-index)
X
X(defun latexinfo-format-defcv-type (type args)
X  (format "%s of %s" type (car args)))
X
X(defun latexinfo-format-defcv-index (type args)
X  (format "%s of %s" (car (cdr args)) (car args)))
X
X;; process included files
X(put 'include 'latexinfo-format 'latexinfo-format-include)
X(defun latexinfo-format-include ()
X  (let ((filename (latexinfo-parse-arg-discard))
X	(default-directory input-directory)
X	subindex)
X    (setq subindex
X	  (save-excursion
X	    (progn (find-file
X		    (cond ((file-readable-p (concat filename ".texinfo"))
X			   (concat filename ".texinfo"))
X			  ((file-readable-p (concat filename ".tex"))
X			   (concat filename ".tex"))
X			  ((file-readable-p filename)
X			   filename)
X			  (t (error "\\include'd file %s not found"
X				    filename))))
X		   (latexinfo-format-buffer-1))))
X    (latexinfo-subindex 'latexinfo-vindex (car subindex) (nth 1 subindex))
X    (latexinfo-subindex 'latexinfo-findex (car subindex) (nth 2 subindex))
X    (latexinfo-subindex 'latexinfo-cindex (car subindex) (nth 3 subindex))
X    (latexinfo-subindex 'latexinfo-pindex (car subindex) (nth 4 subindex))
X    (latexinfo-subindex 'latexinfo-tindex (car subindex) (nth 5 subindex))
X    (latexinfo-subindex 'latexinfo-kindex (car subindex) (nth 6 subindex))))
X
X(defun latexinfo-subindex (indexvar file content)
X  (set indexvar (cons (list 'recurse file content)
X		      (symbol-value indexvar))))
X
X
X;; Lots of bolio constructs do nothing in latexinfo.
X
X(put 'c 'latexinfo-format 'latexinfo-discard-line-with-args)
X(put 'comment 'latexinfo-format 'latexinfo-discard-line-with-args)
X;;(put 'setchapternewpage 'latexinfo-format 'latexinfo-discard-line-with-args)
X(put 'nopara 'latexinfo-format 'latexinfo-discard-line-with-args)
X(put 'noindent 'latexinfo-format 'latexinfo-discard-line-with-args)
X;;(put 'setx 'latexinfo-format 'latexinfo-discard-line-with-args)
X;;(put 'setq 'latexinfo-format 'latexinfo-discard-line-with-args)
X;;(put 'settitle 'latexinfo-format 'latexinfo-discard-line-with-args)
X;;(put 'defindex 'latexinfo-format 'latexinfo-discard-line-with-args)
X(put 'synindex 'latexinfo-format 'latexinfo-discard-line-with-args)
X(put 'hsize 'latexinfo-format 'latexinfo-discard-line-with-args)
X(put 'parindent 'latexinfo-format 'latexinfo-discard-line-with-args)
X(put 'lispnarrowing 'latexinfo-format 'latexinfo-discard-line-with-args)
X(put 'itemindent 'latexinfo-format 'latexinfo-discard-line-with-args)
X(put 'headings 'latexinfo-format 'latexinfo-discard-line-with-args)
X(put 'smallbook 'latexinfo-format 'latexinfo-discard-line)
X
X(defun latexinfo-discard-line-with-args ()
X  (goto-char latexinfo-command-start)
X  (delete-region (point) (progn (forward-line 1) (point))))
X
X;; Sort an index which is in the current buffer between START and END.
X;; Used on VMS, where the `sort' utility is not available.
X(defun latexinfo-sort-region (start end)
X  (require 'sort)
X  (save-restriction
X    (narrow-to-region start end)
X    (sort-subr nil 'forward-line 'end-of-line 'latexinfo-sort-startkeyfun)))
X
X;; Subroutine for sorting an index.
X;; At start of a line, return a string to sort the line under.
X(defun latexinfo-sort-startkeyfun ()
X  (let ((line
X	 (buffer-substring (point) (save-excursion (end-of-line) (point)))))
X    ;; Canonicalize whitespace and eliminate funny chars.
X    (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line)
X      (setq line (concat (substring line 0 (match-beginning 0))
X			 " "
X			 (substring line (match-end 0) (length line)))))
X    line))
X
X;; Some cannot be handled - just ignore them and junk the line
X
X(defun latexinfo-unsupported ()
X  (latexinfo-parse-noarg)
X  )
X
X(defun batch-latexinfo-format ()
X  "Runs  latexinfo-format-buffer  on the files remaining on the command line.
XMust be used only with -batch, and kills emacs on completion.
XEach file will be processed even if an error occurred previously.
XFor example, invoke
X  \"emacs -batch -funcall batch-latexinfo-format $docs/ ~/*.tex\"."
X  (if (not noninteractive)
X      (error "batch-latexinfo-format may only be used -batch."))
X  (let ((version-control t)
X	(auto-save-default nil)
X	(find-file-run-dired nil)
X	(kept-old-versions 259259)
X	(kept-new-versions 259259))
X    (let ((error 0)
X	  file
X	  (files ()))
X      (while command-line-args-left
X	(setq file (expand-file-name (car command-line-args-left)))
X	(cond ((not (file-exists-p file))
X	       (message ">> %s does not exist!" file)
X	       (setq error 1
X		     command-line-args-left (cdr command-line-args-left)))
X	      ((file-directory-p file)
X	       (setq command-line-args-left
X		     (nconc (directory-files file)
X			    (cdr command-line-args-left))))
X	      (t
X	       (setq files (cons file files)
X		     command-line-args-left (cdr command-line-args-left)))))
X      (while files
X	(setq file (car files)
X	      files (cdr files))
X	(condition-case err
X	    (progn
X	      (if buffer-file-name (kill-buffer (current-buffer)))
X	      (find-file file)
X	      (buffer-flush-undo (current-buffer))
X	      (set-buffer-modified-p nil)
X	      (latexinfo-mode)
X	      (message "Latexinfo formatting %s..." file)
X	      (latexinfo-format-buffer nil)
X	      (if (buffer-modified-p)
X		  (progn (message "Saving modified %s" (buffer-file-name))
X			 (save-buffer))))
X	  (error
X	   (message ">> Error: %s" (prin1-to-string err))
X	   (message ">>  point at")
X	   (let ((s (buffer-substring (point)
X				      (min (+ (point) 100)
X					   (point-max))))
X		 (tem 0))
X	     (while (setq tem (string-match "\n+" s tem))
X	       (setq s (concat (substring s 0 (match-beginning 0))
X			       "\n>>  "
X			       (substring s (match-end 0)))
X		     tem (1+ tem)))
X	     (message ">>  %s" s)))
X	  (setq error 1)))
X      (kill-emacs error))))
X
X;;; LaTeX additions
X
X(defun latexinfo-run-documentstyle-hooks ()
X  (goto-char (point-min))
X  (search-forward "\\documentstyle")
X  (if (looking-at "\\[")
X      (let ((begin (1+ (point)))
X	    (end (save-excursion (search-forward "]") (point)))
X	    (options-list nil))
X	(if (null latexinfo-formats-directory)
X	    (setq latexinfo-formats-directory default-directory))
X	(while (re-search-forward ",\\|]" end t)
X	  (setq options-list (cons (buffer-substring begin (1- (point)))
X				   options-list))
X	  (setq begin (point)))
X	(setq options-list (nreverse options-list))
X	(while options-list
X	  (let ((option (car options-list))
X		(filename nil))
X	    (if (not (memq (intern option) latexinfo-known-document-styles))
X		(progn
X		  (message "Checking formatting option %s" option) (sit-for 2)
X		  (setq filename (concat 
X				  (file-name-as-directory
X				   latexinfo-formats-directory)
X				  option "-fmt"))
X		  (setq filename
X			 (cond
X			  ((file-readable-p (concat filename ".elc"))
X			   (concat filename ".elc"))
X			  ((file-readable-p (concat filename ".el"))
X			   (concat filename ".el"))
X			  (t nil)))
X		  (if filename
X		      (progn
X			(message "Loading file %s..." filename) (sit-for 1)
X			(load-file filename)
X			(let ((option-symbol
X			       (intern (concat option "-fmt-hook"))))
X			  (if (fboundp option-symbol)
X			    (progn
X			        (message
X				 (concat "Running " option
X					 "formatting hooks..."))
X				 (sit-for 1)
X				 (funcall option-symbol))))
X			(message "Done loading file %s" filename) (sit-for 1))
X		    ))))
X	  (setq options-list (cdr options-list))))))
X
X(defun latexinfo-parse-noarg ()
X   (delete-region latexinfo-command-start latexinfo-command-end)
X   (cond ((looking-at "{")
X	  (delete-region (point)
X			 (save-excursion
X			   (forward-sexp 1) (point))))
X	;; TeX gobbles the next whitespace.
X	 ((or (eolp) (looking-at "[ \t\n]"))
X	  (delete-region (point)
X			 (save-excursion
X			   (skip-chars-forward " \t\n") (point)))))
X    )
X
X(put 'back 'latexinfo-format 'latexinfo-format-backslash)
X(defun latexinfo-format-backslash ()
X  (latexinfo-discard-command)
X  ;; TeX gobbles the next whitespace.
X  (if (looking-at "[ \t\n]")
X      (delete-region (point)
X		     (save-excursion
X		       (skip-chars-forward " \t\n")
X		       (point))))
X  (insert ?\\))
X
X(put 'same 'latexinfo-format 'latexinfo-discard-command)
X(put 'same 'latexinfo-end 'latexinfo-discard-command)
X
X(put 'cite 'latexinfo-format 'latexinfo-format-cite)
X(defun latexinfo-format-cite ()
X  (if (looking-at "[\\[]")
X      (save-excursion
X	(let ((here (point)) (str nil))
X	      (forward-sexp 1)
X	      (setq str (buffer-substring (1+ here) (- (point) 1)))
X	      (delete-region here (point))
X	      (if (eolp) (delete-char 1))
X	      (insert "[" (latexinfo-parse-arg-discard) ", " str "]")))
X    (insert "[" (latexinfo-parse-arg-discard) "]"))
X  (goto-char latexinfo-command-start))
X
X(put 'hfill 'latexinfo-format 'latexinfo-format-hfill)
X(defun latexinfo-format-hfill ()
X  (latexinfo-parse-arg-discard)
X  (insert-char ?\  (- fill-column
X		      (save-excursion
X			(end-of-line 1)
X			(current-column)))))
X
X
X(put 'S 'latexinfo-format 'latexinfo-format-S)
X(defun latexinfo-format-S ()
X  (latexinfo-parse-noarg)
X  (insert "Section"))
X
X(put 'LaTeX 'latexinfo-format 'latexinfo-format-LaTeX)
X(defun latexinfo-format-LaTeX ()
X  (latexinfo-parse-noarg)
X  (insert "LaTeX"))
X
X(put 'arrow 'latexinfo-format 'latexinfo-format-arrow)
X(defun latexinfo-format-arrow ()
X  (latexinfo-parse-noarg)
X  (insert "=> "))
X
X(put 'leq 'latexinfo-format 'latexinfo-format-leq)
X(defun latexinfo-format-leq ()
X  (latexinfo-parse-noarg)
X  (insert "<="))
X
X(put 'geq 'latexinfo-format 'latexinfo-format-geq)
X(defun latexinfo-format-geq ()
X  (latexinfo-parse-noarg)
X  (insert "<="))
X
X(put 'pi 'latexinfo-format 'latexinfo-format-pi)
X(defun latexinfo-format-pi ()
X  (latexinfo-parse-noarg)
X  (insert "pi"))
X
X(put 'quad 'latexinfo-format 'latexinfo-format-quad)
X(defun latexinfo-format-quad ()
X  (latexinfo-parse-noarg)
X  (insert "    "))
X
X(put 'qquad 'latexinfo-format 'latexinfo-format-qquad)
X(defun latexinfo-format-qquad ()
X  (latexinfo-parse-noarg)
X  (insert "      "))
X
X(put 'pm 'latexinfo-format 'latexinfo-format-pm)
X(defun latexinfo-format-pm ()
X  (latexinfo-parse-noarg)
X  (insert "+/-"))
X
X(put '& 'latexinfo-format 'latexinfo-format-&)
X(defun latexinfo-format-& ()
X  (latexinfo-parse-noarg)
X  (insert "&"))
X
X;; LaTeX noops
X(put 'DOTS 'latexinfo-format 'latexinfo-format-dots)
X(put 'clearpage 'latexinfo-format 'latexinfo-discard-line-with-args)
X(put 'cleardoublepage 'latexinfo-format 'latexinfo-discard-line-with-args)
X(put 'tableofcontents 'latexinfo-format 'latexinfo-discard-line-with-args)
X(put 'protect 'latexinfo-format 'latexinfo-parse-noarg)
X(put 'vspace 'latexinfo-format 'latexinfo-format-noop)
X(put 'pagestyle 'latexinfo-format 'latexinfo-discard-line-with-args)
X(put 'pagenumbering 'latexinfo-format 'latexinfo-discard-line-with-args)
X(put 'markboth 'latexinfo-format 'latexinfo-discard-line-with-args)
X(put 'label 'latexinfo-format 'latexinfo-discard-line-with-args)
X(put 'index 'latexinfo-format 'latexinfo-format-noop)
X(put 'cpsubindex 'latexinfo-format 'latexinfo-discard-line-with-args)
X
X(provide 'latexinfo)
X
X
END_OF_FILE
if test 50239 -ne `wc -c <'latexinfo.el'`; then
    echo shar: \"'latexinfo.el'\" unpacked with wrong size!
fi
# end of 'latexinfo.el'
fi
echo shar: End of archive 9 \(of 9\).
cp /dev/null ark9isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 9 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
Mike Clarkson					mike@ists.ists.ca
Institute for Space and Terrestrial Science	uunet!attcan!ists!mike
York University, North York, Ontario,		FORTRAN - just say no. 
CANADA M3J 1P3					+1 (416) 736-5611