Commits

Anonymous committed 3cb9427

Update to AucTeX 9.9p.

  • Participants
  • Parent commits f89afa5

Comments (0)

Files changed (14)

-News in 9.8
+News in 9.9
 ===========
 
-   * Added `natbib.el' to support natbib.sty by Patrick W. Daly.
-     Submitted by Berwin A. Turlach `<berwin.turlach@anu.edu.au>'.
+   * Bug fix in JLATEX recognition.  Patch by Tsutomu OKUMURA
+     <oku@nml.t.u-tokyo.ac.jp>.
 
-   * More LaTeX2e support by Jan Vroonhof `<vroonhof@math.ethz.ch>'.
+   * Bug fix in foils package sypport.  Suggested by Bernt
+     Guldbrandtsen <bernt@jupiter.ansci.iastate.edu>.
 
-   * Make `TeX-master' a local variable in BibTeX mode and set it to
-     true.  This seems to be necessary to enable auto-parsing of a .bib
-     file.  Patch by Berwin A. Turlach `<berwin.turlach@anu.edu.au>'.
+   * Made `make install-contrib' compile the contributed lisp files.
+     Suggested by Nils Ackermann <Nils.Ackermann@math.uni-giessen.de>.
 
-   * Support for Harvard style updated by Berwin A. Turlach
-     `<berwin.turlach@anu.edu.au>'.
+   * In `texinfo-mode', `C-c C-f C-d' now deletes the current font,
+     while `C-u C-c C-f KEY' changes it.  `@dfn' moved to `C-c C-f d'.
+     Suggested by Christoph Wedler <wedler@fmi.uni-passau.de>.
 
-   * Support for `natbib' package.  By Berwin Turlach
-     `<berwin.turlach@anu.edu.au>'.
+   * Fixed some custom types.  Patch by Markus Rost
+     <markus.rost@mathematik.uni-regensburg.de>.
 
-   * Finer control of automatic parsing of TeX files: new variables
-     `TeX-auto-x-parse-length' and `TeX-auto-x-regexp-list'.  By
-     Christoph Wedler `<wedler@fmi.uni-passau.de>'.
+   * Support loading byte compiled files, even if `TeX-byte-compile' is
+     nil.  Patch by Christoph Wedler  <wedler@fmi.uni-passau.de>.
 
-   * Finer control of indentation: new variables
-     `LaTeX-document-regexp', `LaTeX-verbatim-regexp',
-     `LaTeX-begin-regexp', `LaTeX-end-regexp' and
-     `LaTeX-indent-comment-start-regexp'.  By Christoph Wedler
-     `<wedler@fmi.uni-passau.de>'.
+   * The command to replace a LaTeX2e font should work more reliably
+     now.  Patch by Christoph Wedler  <wedler@fmi.uni-passau.de>.
 
-   * When running LaTeX on a region, do not complain about undefined
-     citations.  See variable `TeX-region-extra'.  By Christoph Wedler
-     `<wedler@fmi.uni-passau.de>'.
+   * Minor XEmacs packaging changes.  Patch by Christoph Wedler
+     <wedler@fmi.uni-passau.de>.
 
-   * Split menu for LaTeX environments into submenus if number of
-     environments is larger than the value of the new variable
-     `LaTeX-menu-max-items'.  By Christoph Wedler
-     `<wedler@fmi.uni-passau.de>'.
+   * `TeX-file-recurse' now accepts an integer value, max depth of
+     recursion.  Patch by Alastair Burt  <burt@dfki.bde>.
 
-   * More reftex support with new `TeX-arg-ref' function.  By Soren
-     Dayton `<csdayton@cs.uchicago.edu>', with `amsmath' support by
-     Carsten Dominik `<dominik@strw.LeidenUniv.nl>'.
+   * Simple imenu support for LaTeX.
 
-   * Minimal parser now recognize `usepackage'.  By Carsten Dominik
-     `<dominik@strw.LeidenUniv.nl>'.
+   * Workaround for 20.3 bugs.
 
-   * More amstex styles recognized.  By Carsten Dominik
-     `<dominik@strw.LeidenUniv.nl>'.
+   * The `Spell' command now works on all open buffers in the document.
+     Patch by Jason Stewart <jasons@cs.unm.edu>.
 
-   * Czech and Slovak support.  By Milan Zamazal `<pdm@fi.muni.cz>'.
+   * `C-c C-m' now puts content of region inside first empty brackets
+     in the macro, if any.  Patch by Peter Thiemann <pjt@cs.nott.ac.uk>.
 
+   * Update of `natbib.el' style file by Carsten Dominik
+     <dominik@strw.LeidenUniv.nl>.
+
+   * Much better detection of TeX math mode.  Patch by Carsten Dominik
+     <dominik@strw.LeidenUniv.nl>.
+
+   * New `%n' escape in `TeX-command-list' for entering the current
+     line number.  Suggested by "Lee, Sang-Min"
+     <smagus@acorn.snu.ac.kr>.
+
+   * Doc fixes in manual.  Patch by Gustavo Chaves
+     <gustavo@cpqd.com.br>.
+
+   * Better reftex support for sections.  Patch by Carsten Dominik
+     <dominik@strw.LeidenUniv.nl>.
+
+   * Bug fixes in math card.  Reported by "Ron Smith"
+     <rsmith@eel.ufl.edu>.
+
+   * Better multifile support.  Patch by Soren Dayton
+     <csdayton@cs.uchicago.edu>.
+
+   * Don't expand abbreviations when `abbrev-mode' is nil.  Suggested
+     by Alastair Burt <alastair.burt@dfki.de>.
+
+   * `direntry' support in manual, by SL Baur <steve@altair.xemacs.org>.
+
      Directories containing the site's TeX style files.
 
    Normally, AUC TeX will only allow you to complete a short list of
-build-in macros and environments and on the macros you define yourself.
+built-in macros and environments and on the macros you define yourself.
 If you issue the `M-x TeX-auto-generate-global' command after loading
 AUC TeX, you will be able to complete on all macros available in the
 standard style files used by your document.  To do this, you must set
 # remove the MULE_ELCS line for building without Mule.
 
 VERSION = 1.18
-AUTHOR_VERSION = 9.7p
+AUTHOR_VERSION = 9.9p
 MAINTAINER = XEmacs Development Team <xemacs-beta@xemacs.org>
 PACKAGE = auctex
 PKG_TYPE = regular
 CATEGORY = wp
 
 ELCS = auc-old.elc bib-cite.elc font-latex.elc latex.elc \
-	multi-prompt.elc tex-buf.elc tex-info.elc tex.elc
+	multi-prompt.elc tex-buf.elc tex-info.elc tex.elc texmathp.elc
 
 EXTRA_SOURCES = CHANGES PROBLEMS README tex-site.el
 
 GENERATED += custom-load.elc
 
 ifeq ($(BUILD_MULE),t)
-MULE_ELCS = tex-jp.elc
-else
-MULE_ELCS =
+ELCS += tex-jp.elc
 endif
 
-all:: $(ELCS) $(MULE_ELCS) $(ETC_ELCS) auto-autoloads.elc custom-load.elc texi
-
-auto-autoloads.el: $(ELCS:.elc=.el) $(MULE_ELCS:.elc=.el) _pkg.el
-	$(XEMACS) $(VANILLA) -batch \
-		-eval "(setq autoload-package-name \"$(PACKAGE)\")" \
-		-eval "(setq generated-autoload-file \"./auto-autoloads.el\")" \
-		-l autoload -f batch-update-autoloads $^
+all:: $(ELCS) $(ETC_ELCS) auto-autoloads.elc custom-load.elc texi
 
 clean::
 	rm -f texi/*.info*
 # Makefile - for the AUC TeX distribution.
 #
 # Maintainer: Per Abrahamsen <auc-tex@sunsite.auc.dk>
-# Version: 9.7p
+# Version: 9.9p
 #
 # Edit the makefile, type `make', and follow the instructions.
 
 
 MINMAPSRC = auc-menu.el maniac.el outln-18.el all.el multi-prompt.el
 
-## MULE_ELC is set by update-elc.sh if bytecompiling for XEmacs/Mule
-CONTRIB = bib-cite.el $(MULE_EL) font-latex.el custom-load.el
-CONTRIBELC = bib-cite.elc $(MULE_ELC) font-latex.elc custom-load.elc
+CONTRIB = hilit-LaTeX.el bib-cite.el tex-jp.el font-latex.el
+CONTRIBELC = bib-cite.elc font-latex.elc
 
-AUCSRC = auc-old.el tex.el tex-buf.el latex.el tex-info.el multi-prompt.el
+AUCSRC = auc-old.el tex.el tex-buf.el latex.el tex-info.el \
+	texmathp.el multi-prompt.el
 AUCELC = auc-old.elc tex.elc tex-buf.elc latex.elc tex-info.elc \
-	multi-prompt.elc
+	texmathp.elc multi-prompt.elc
 
 
-STYLESRC = ../../etc/auctex/style/slides.el    ../../etc/auctex/style/foils.el    ../../etc/auctex/style/amstex.el \
-	   ../../etc/auctex/style/article.el   ../../etc/auctex/style/book.el     ../../etc/auctex/style/letter.el \
-	   ../../etc/auctex/style/report.el    ../../etc/auctex/style/amsart.el   ../../etc/auctex/style/amsbook.el \
-	   ../../etc/auctex/style/epsf.el      ../../etc/auctex/style/psfig.el    ../../etc/auctex/style/latexinfo.el \
-	   ../../etc/auctex/style/dutch.el     ../../etc/auctex/style/german.el   ../../etc/auctex/style/dk.el \
-	   ../../etc/auctex/style/j-article.el ../../etc/auctex/style/j-book.el   ../../etc/auctex/style/j-report.el \
-	   ../../etc/auctex/style/jarticle.el  ../../etc/auctex/style/jbook.el    ../../etc/auctex/style/jreport.el \
-	   ../../etc/auctex/style/dinbrief.el  ../../etc/auctex/style/virtex.el   ../../etc/auctex/style/plfonts.el \
-	   ../../etc/auctex/style/plhb.el      ../../etc/auctex/style/harvard.el	../../etc/auctex/style/swedish.el \
-	   ../../etc/auctex/style/danish.el
+STYLESRC = style/slides.el    style/foils.el    style/amstex.el \
+	   style/article.el   style/book.el     style/letter.el \
+	   style/report.el    style/amsart.el   style/amsbook.el \
+	   style/epsf.el      style/psfig.el    style/latexinfo.el \
+	   style/dutch.el     style/german.el   style/dk.el \
+	   style/j-article.el style/j-book.el   style/j-report.el \
+	   style/jarticle.el  style/jbook.el    style/jreport.el \
+	   style/dinbrief.el  style/virtex.el   style/plfonts.el \
+	   style/plhb.el      style/harvard.el	style/swedish.el \
+	   style/danish.el    style/slovak.el   style/czech.el \
+	   style/amsmath.el   style/amstext.el  style/amsbsy.el \
+	   style/amsopn.el    style/amsthm.el	style/natbib.el
 
 DOCFILES = doc/Makefile doc/auc-tex.texi doc/intro.texi doc/install.texi \
 	doc/changes.texi doc/tex-ref.tex doc/math-ref.tex doc/history.texi
 
 all:	lisp
 
-.IGNORE: some
+lisp:
+	$(ELC) $(AUCSRC) $(STYLESRC)
 
-lisp:
-	$(ELC) $(AUCSRC) $(STYLESRC) $(CONTRIB)
-
-some:	$(AUCELC) $(CONTRIBELC) $(STYLESRC:.el=.elc)
+some:	$(AUCELC) $(STYLESRC:.el=.elc)
 
 install:	install-lisp
 
 	    echo "Leaving compiled files in place."; \
 	fi
 
-install-contrib:
+install-contrib:	$(CONTRIBELC)
 	$(MV) $(CONTRIBELC) $(aucdir)
 	$(CP) $(CONTRIB) $(aucdir)
 
 	perl -pi.bak -e "s/Version: $(OLD)/Version: $(TAG)/" \
 	    $(AUCSRC) $(EXTRAFILES)
 	mv ChangeLog ChangeLog.old
-	echo `date "+%a %b %d %T %Y "` \
+	echo `date "+%Y-%m-%d "` \
 	     " Per Abrahamsen  <abraham@dina.kvl.dk>" > ChangeLog
 	echo >> ChangeLog
 	echo "	* Version" $(TAG) released. >> ChangeLog
 	-cvs add $(MINMAPSRC) 
 	cvs commit -m "Update"
 	cp $(MINMAPSRC) doc/math-ref.tex $(FTPDIR) 
-
-autoloads: auto-autoloads.el
-
-auto-autoloads.el: $(AUCSRC) $(CONTRIB)
-	$(EMACS) -batch -q -no-site-file \
-		-eval '(setq autoload-target-directory "'`pwd`'/")' \
-		-l autoload \
-		-f batch-update-autoloads $?
 It has a special outline feature, which can greatly help you `getting an
 overview' of a document.
 
-   Apart from these special features, AUC TeX provides an large range of
+   Apart from these special features, AUC TeX provides a large range of
 handy Emacs macros, which in several different ways can help you write
-your LaTeX documents fast and painless.
+your LaTeX documents fast and painlessly.
 
    All features of AUC TeX are documented using the GNU Emacs online
 documentation system.  That is, documentation for any command is just a
 License' and may therefore almost freely be copied and redistributed.
 
    The next sections are a short introduction to some `actual' features.
-For further information, refer to the build-in online documentation of
+For further information, refer to the built-in online documentation of
 AUC TeX.
 
 Indentation and formatting
 Completion
 ==========
 
-   By studying your `\documentstyle' command (in the top of your
+   By studying your `\documentclass' command (in the top of your
 document), and consulting a precompiled list of (La)TeX symbols from a
 large number of TeX and LaTeX files, AUC TeX is aware of the LaTeX
-commands you should able to use in this particular document.  This
+commands you should be able to use in this particular document.  This
 `knowledge' of AUC TeX is used for two purposes.
 
   1. To make you able to `complete' partly written LaTeX commands. You
 
    A number of more or less intelligent keyboard macros have been
 defined to aid you editing your document.  The most important are
-listed here below.
+listed below.
 
 `LaTeX-environment'
      (`C-c C-e') Insert a `\begin{}' -- `\end{}' pair as described
 
 `TeX-font'
      (`C-c C-f C-r', `C-c C-f C-i', `C-c C-f C-b') Insert one of
-     `{\textrm }'), `{\textit \/}' `{\textbf }' etc.
+     `\textrm{ }'), `\textit{ \/}' `\textbf{ }' etc.
 
    A number of additional functions are available.  But it would be far
 too much to write about here.  Refer to the rest of the AUC TeX
 Running LaTeX
 =============
 
-   When invoking on of the commands `TeX-command-master' (`C-c C-c') or
-`TeX-command-region' (`C-c C-r') LaTeX is run on either the entire
+   When invoking one of the commands `TeX-command-master' (`C-c C-c')
+or `TeX-command-region' (`C-c C-r') LaTeX is run on either the entire
 current document or a given region of it.  The Emacs view is split in
 two, and the output of TeX is printed in the second half of the screen,
 as you may simultaneously continue editing your document.  In case TeX
-found any errors when processing your input you can call the function
+find any errors when processing your input you can call the function
 `TeX-next-error' (`C-c `') which will move the cursor to the first
 given error, and display a short explanatory text along with the
 message TeX gave.  This procedure may be repeated until all errors have
 
    If you want to contact the AUC TeX mailing list, send mail to
 `<auc-tex-request@iesd.auc.dk>' in order to join.  Articles should be
-send to `<auc-tex@iesd.auc.dk>'.
+sent to `<auc-tex@iesd.auc.dk>'.
 
-   To contact the current maintainers of auc-TeX directly, email
+   To contact the current maintainers of AUC TeX directly, email
 `<auc-tex_mgr@iesd.auc.dk>'.
 
              AUC TeX development
 ;;; auc-old.el - Compatibility with AUC TeX 6.*
 ;;
 ;; Maintainer: Per Abrahamsen <auc-tex@sunsite.auc.dk>
-;; Version: 9.8l
+;; Version: 9.9p
 ;;
 ;; Copyright (C) 1991 Kresten Krab Thorup 
 ;; Copyright (C) 1993 Per Abrahamsen 
 
 ;; Copyright (C) 1994, 1995, 1996, 1997 Peter S. Galbraith
  
-;; Author:    Peter S. Galbraith <galbraith@mixing.qc.dfo.ca>
+;; Author:    Peter S. Galbraith <GalbraithP@dfo-mpo.gc.ca>
 ;; Created:   06 July 1994
-;; Version:   3.07 (20 Nov 97)
+;; Version:   3.12 (10 Dec 98)
 ;; Keywords:  bibtex, cite, auctex, emacs, xemacs
 
 ;; RCS $Id$
 ;;      distribution fee considered a charge.
 
 ;; LCD Archive Entry:
-;; bib-cite|Peter Galbraith|galbraith@mixing.qc.dfo.ca|
+;; bib-cite|Peter Galbraith|GalbraithP@dfo-mpo.gc.ca|
 ;; Display \cite, \ref or \label / Extract refs from BiBTeX file.|
 ;; 21-May-1997|3.01|~/misc/bib-cite.el.gz|
 
 ;; Description:
 ;; ~~~~~~~~~~~
 ;; This package is used in various TeX modes to display or edit references
-;; associated with \cite commands, or matching \ref and \label commands.
-;; (so I actually overstep BiBTeX bounds here...)
+;; associated with \cite commands, or matching \eqref, \ref and \label 
+;; commands  (so I actually overstep BiBTeX bounds here...).
+;;
 ;; These are the functions:
 ;;    
 ;;    bib-display bib-display-mouse
 ;;                           - Display citation, \ref or \label under point
 ;;    bib-find    bib-find-mouse
 ;;                           - Edit citation, \ref or \label under point
+;;    bib-find-next          - Find next occurrence of a \ref or \eqref
 ;;    bib-make-bibliography  - Make BiBTeX file containing only cite keys used.
 ;;    bib-apropos            - Search BiBTeX source files for keywords.
 ;;    bib-etags              - Refreshes (or builds) the TAGS files for 
 ;;    first occurrance within a document (using a TAGS file).  If point is
 ;;    moved within the same buffer, mark is set before the move and a message
 ;;    stating so is given.  If point is moved to another file, this is done in
-;;    a new window using tag functions.  Within a plain file, the search
-;;    pattern is set for another similar \ref command (since TAGS file are not
-;;    used).  Within a multi-file document the following tag functions are
-;;    appropriately setup:
-;;
-;;     C-u M-.     Find next alternate definition of last tag specified.
-;;
-;;     C-u - M-.   Go back to previous tag found.
-;;
+;;    a new window using tag functions.  
+;;    
+;;    The next occurrence of a \ref or \eqref command may be found by invoking
+;;    bib-find-next, usually bound to `C-c b n'. 
 ;;
 ;;    For multi-file documents, you must be using auctex (so that bib-cite can
 ;;    find the master file) and all \input and \include commands must be first
 ;;  variant "etags -o ", but users have reported differently.  So while the
 ;;  unix notation is used here, you can reset it if you need to like so:
 ;;
-;;    (setq bib-etags-command        "etags /o=")
-;;    (setq bib-etags-append-command "etags /a /o=")
+;;    (setq bib-etags-command        "etags  /r='/.*\\eqref.*/' /o=")
+;;    (setq bib-etags-append-command "etags  /r='/.*\\eqref.*/' /a /o=")
 ;;  ---
 ;;  For multi-file documents, a TAGS file is generated by etags.  
 ;;  By default, its name is TAGS.  You can change this like so:
 
 ;; ----------------------------------------------------------------------------
 ;;; Change log:
+;; V3.12 Dec 10 98 - Bruce Ravel <bruce.ravel@nist.gov> (RCS V1.30)
+;;    Fixed bib-label-help. 
+;; V3.11 Oct 06 98 - PSG (RCS V1.29) 
+;;    Quote \ character fot replace-match; 
+;;    Applies to: @String{JGR = "J. Geophys.\ Res."}
+;; V3.10 Sep 21 98 - Matt Hodges <mph1002@cam.ac.uk> (RCS V1.28)
+;;    Removed instance of expand-file-name due to new behaviour in Emacs-20.3.
+;; V3.09 Sep 09 98 - PSG (RCS V1.27)
+;;    Added support for \eqref; Added bib-find-next.
+;; V3.08 Aug 20 98 - PSG (RCS V1.26)
+;;    Fixed imenu bug (prev-pos (point-max))
 ;; V3.07 Nov 20 97 - Christoph Wedler <wedler@fmi.uni-passau.de>  (RCS V1.24)
 ;;    bib-ext-list variable made permanent-local, otherwise VC registration 
 ;;    would use two extents for each reference etc. This was not a visible bug.
 (You can change the environment variable which is searched by setting the 
 elisp variable bib-bibtex-env-variable)")
 
-(defvar bib-etags-command "etags -o "
+(defvar bib-etags-command "etags -r '/.*\\eqref.*/' -o "
   "*Variable for the etags command and its output option.
-In unix, this is usually \"etags -o \"
-In DOS and OS/2, this *may* be \"etags /o=\"  If so, set it this variable.")
+In unix, this is usually \"etags -r '/.*\\eqref.*/' -o \" 
+(we use the -r option to tell etags to list AMS-LaTeX's \\eqref command.)
+In DOS and OS/2, this *may* be different, e.g. using slashes like \"etags /o=\"
+If so, set it this variable.")
 
-(defvar bib-etags-append-command "etags -a -o "
+(defvar bib-etags-append-command 
+  "etags -r '/.*\\eqref.*/' -a -o "
   "*Variable for the etags command and its append and output option.
-In unix, this is usually \"etags -a -o \"
+In unix, this is usually \"etags -r '/.*\\eqref.*/' -a -o \"
 In DOS and OS/2, this *may* be \"etags /a /o=\"  If so, set it this variable.")
 
 (defvar bib-etags-filename "TAGS"
     (define-key map "\C-cbd" 'bib-display)
     (define-key map "\C-cbe" 'bib-etags)
     (define-key map "\C-cbf" 'bib-find)
+    (define-key map "\C-cbn" 'bib-find-next)
     (define-key map "\C-cbh" 'bib-highlight-mouse)
     map)
   "bib-cite minor-mode keymap")
     (save-excursion
       (if (not (looking-at "\\\\"))
           (search-backward "\\" nil t))
-      (if (looking-at "\\\\ref{") 
+      (if (looking-at "\\\\\\(eq\\)?ref{")
           (setq ref t)
         (if (looking-at "\\\\label{")
             (setq label t)              
     (save-excursion
       (if (not (looking-at "\\\\"))
           (search-backward "\\" nil t))
-      (if (looking-at "\\\\ref{") 
+      (if (looking-at "\\\\\\(eq\\)?ref{") 
           (setq ref t)
         (if (looking-at "\\\\label{")
             (setq label t)              
      (t
       (bib-find-label)))))
 
+(defvar bib-cite-search-ring nil
+  "Bib-cite intenal variable to hold last \\ref or \\eqref find.")
+
+(defun bib-find-next (&optional prev-p)
+  "Find next occurrence of a \ref or \eqref.
+This is made necessary because we now use a regexp to find tags in multi-file
+documents, and the Emacs command `find-tag' doesn't allow to interactively
+find the next occurrence of a regexp."
+  (interactive "P")
+  (if (bib-master-file)                 ;Multi-file document
+      (if prev-p 
+          (find-tag t '- t)
+        (find-tag t t t))
+    (if bib-cite-search-ring
+        ;;FIXME: Should first make sure I move off initial \ref{}.
+        (let ((regexp (concat "\\\\\\(eq\\)?ref{" bib-cite-search-ring "}")))
+          (if prev-p
+              (if (not (re-search-backward regexp nil t))
+                  (message "No previous occurrence of reference %s" 
+                           bib-cite-search-ring))
+            (if (not (re-search-forward regexp nil t))
+                (message "No next occurrence of reference %s" 
+                         bib-cite-search-ring))))
+      (message "Sorry, no previous reference to find.  Use bib-find?"))))
+
 (defun bib-display-mouse (EVENT)
   "Display BibTeX citation or matching \\ref or \\label command under mouse.
 See bib-display."
       (goto-char (point-min))
       (while 
           (re-search-forward 
-           "\\\\\\(ref\\|label\\|[A-Za-z]*cite[A-Za-z]*\\(\\[.*\\]\\)?\\){[^}]*}"
+           "\\\\\\(\\(eq\\)?ref\\|label\\|[A-Za-z]*cite[A-Za-z]*\\(\\[.*\\]\\)?\\){[^}]*}"
            nil t)
         (setq s (match-beginning 0))
         (setq e (match-end 0))
       (bib-label-help object bib-label-help-echo-format)))
 
 ;;; Balloon-help callback. Anders Stenman <stenman@isy.liu.se>
+;;;             Patched by Bruce Ravel <bruce.ravel@nist.gov>
 (defun bib-label-help (object &optional format)
   (or format (setq format "Use mouse button 2 to find the %s.
 Use mouse button 3 to display the %s."))
   (save-match-data
     (let* ((string (extent-string object))
-	   (type (cond ((string-match "^\\\\cite" string) "citation")
-		       ((string-match "^\\\\ref" string) "\\label{}")
+	   (type (cond ((string-match "^\\\\[A-Za-z]*cite[A-Za-z]*" string) "citation")
+		       ((string-match "^\\\\\\(eq\\)?ref" string) "\\label{}")
 		       ((string-match "^\\\\label" string) "\\ref{}")
-		       (t "bullshit"))))
+		       (t "this (unknown) reference"))))
       (format format type type))))
 
 ;;----------------------------------------------------------------------------
 ;;user is prompted is nothing suitable is found.  The first prompt is for a
 ;;label. If you answer with an empty string, a second prompt for a ref will
 ;;be given."
-  (let ((the-name (bib-guess-or-prompt-for-label)))
-    (if (not the-name)
+  (let ((the-regexp (bib-guess-or-prompt-for-label)))
+    (if (not the-regexp)
         (message "No name given")
-      (bib-display-or-find-label the-name t))))
+      (bib-display-or-find-label the-regexp t))))
 
 (defun bib-find-label ()
   "Move to a label, or the first occurance of a ref.
 ;;  You can search for next occurrances of a ref command with tag commands:
 ;;     C-u M-.     Find next alternate definition of last tag specified.
 ;;     C-u - M-.   Go back to previous tag found."
-  (let ((the-name (bib-guess-or-prompt-for-label)))
-    (if (not the-name)
+  (let ((the-regexp (bib-guess-or-prompt-for-label)))
+    (if (not the-regexp)
         (message "No name given")
-      (bib-display-or-find-label the-name nil))))
+      (bib-display-or-find-label the-regexp nil))))
 
 ;;--------------------------------------------------------------------------
 ;; Functions for Displaying or moving to matching \ref or \label command
 
-(defun bib-display-or-find-label (the-name displayf)
+(defun bib-display-or-find-label (the-regexp displayf)
 ;; work horse for bib-find-label and bib-display-label
   (let* ((masterfile (bib-master-file))
          (masterdir (and masterfile
        (masterfile                   ;Multi-file document
         (cond 
          (displayf                  ;Display only
-          (set-buffer (bib-etags-find-noselect the-name masterdir))
-          (re-search-forward (regexp-quote the-name) nil t) 
+          (set-buffer (bib-etags-find-noselect the-regexp masterdir))
+          (re-search-forward the-regexp nil t) 
           ;; ...because tags puts point on beginning of line
-          (if (string-match "^\\\\label" the-name)
+          (if (string-match "^\\\\\\\\label" the-regexp)
               (bib-display-this-environment) ;display the label's environment
             (bib-display-this-ref)))    ;     display the ref's context
          (t                         ;Move to it
-          (setq new-buffer (bib-etags-find-noselect the-name masterdir))
+          (setq new-buffer (bib-etags-find-noselect the-regexp masterdir))
           (if bib-novice
               (message
                (substitute-command-keys
-                (concat "Use C-u \\[find-tag] to find the next occurrence; "
-                        "Use C-u - \\[find-tag] to find the previous."))))
+                (concat "Use \\[bib-find-next] to find the next occurrence "
+                        "and C-u \\[bib-find-next] to find previous."))))
           (if (equal new-buffer (current-buffer))
-              (setq new-point (point))) ;Moving with the same buffer
-          (and (string-match "^\\\\ref" the-name)
-               (setq search-ring (cons the-name search-ring))))))
+              (setq new-point (point)))))) ;Moving with the same buffer
        (t                           ;Single-file document
         (goto-char (point-min))
-        (if (search-forward the-name nil t)
-            (if displayf
-                (if (string-match "^\\\\label" the-name)
-                    (bib-display-this-environment)   ;Display the environment
-                  (bib-display-this-ref)) ;           display the ref's context
-              (setq new-point (match-beginning 0))  ;or move there
-              (if bib-novice
-                  (message
-                   (substitute-command-keys
-                    (concat 
-                     "Use \\[isearch-forward] \\[isearch-forward] to find the "
-                     "next occurrence; Use C-x C-x to go back."))))
-              (if (string-match "^\\\\ref" the-name)
-                  (setq search-ring (cons the-name search-ring))
-                (setq search-ring (cons (concat "\\ref" (substring the-name 6))
-                                        search-ring))))
-          (message "Sorry, cannot find %s" the-name)))))
+        (cond 
+         ((re-search-forward the-regexp nil t)
+          (if displayf
+              (if (string-match "^\\\\label" the-regexp)
+                  (bib-display-this-environment) ;Display the environment
+                (bib-display-this-ref)) ;         display the ref's context
+            (setq new-point (match-beginning 0))  ;or move there
+            (if (string-match "{\\(.*\\)}" the-regexp)
+                (setq bib-cite-search-ring (match-string 1 the-regexp)))
+            (if bib-novice
+                (message
+                 (substitute-command-keys
+                  (concat "Use \\[bib-find-next] to find the next occurrence "
+                          "and C-u \\[bib-find-next] to find previous."))))))
+         (t
+          (message "Sorry, cannot find it (%s)" the-regexp))))))
     (if new-point
         (progn
           (push-mark (point) t nil)   ;We've moving there... push mark
           (goto-char new-point))
       (if new-buffer                    ;We've changing buffer
-;;         (switch-to-buffer new-buffer)
-           (funcall bib-switch-to-buffer-function new-buffer)))
+          ;;(switch-to-buffer new-buffer)
+          (funcall bib-switch-to-buffer-function new-buffer)))
     (if (bib-Is-hidden)
         (save-excursion
           (beginning-of-line)
                                  (save-excursion (beginning-of-line)(point)) 
                                  t))
     (cond
-     ((looking-at "\\\\ref{")           ;On \ref, looking for matching \label
+     ((looking-at "\\\\\\(eq\\)?ref{")   ;On \ref, looking for matching \label
       (let ((b (progn (search-forward "{" nil t)(forward-char -1)(point)))
             (e (progn (forward-sexp 1)(point))))
-        (concat "\\label" (buffer-substring b e))))
+        (concat "\\\\label" (regexp-quote (buffer-substring b e)))))
      ((looking-at "\\\\label{")         ;On \label, looking for matching \ref
       (let ((b (progn (search-forward "{" nil t)(forward-char -1)(point)))
             (e (progn (forward-sexp 1)(point))))
-        (concat "\\ref" (buffer-substring b e))))
+        (concat "\\\\\\(eq\\)?ref" (regexp-quote (buffer-substring b e)))))
      (t                                 ;Prompt the user
       (let* ((minibuffer-local-completion-map bib-label-prompt-map)
 	     (the-alist (create-alist-from-list 
                 (completing-read "Label: " the-alist nil nil nil 
                                  'LaTeX-find-label-hist-alist))))
         (if (not (equal the-name ""))
-            (concat "\\label{" the-name "}")
+            (concat "\\\\label{" (regexp-quote the-name) "}")
           ;; else try to get a \ref
           (if (string-equal "18" (substring emacs-version 0 2))
               (setq the-name (completing-read "Ref: " the-alist nil nil nil))
             (setq the-name (completing-read "Ref: " the-alist nil nil nil 
                                             'LaTeX-find-label-hist-alist)))
           (if (not (equal the-name ""))
-              (concat "\\ref{" the-name "}")
+              (concat "\\\\\\(eq\\)?ref{" (regexp-quote the-name) "}")
             nil)))))))
 
 (defun bib-display-this-ref ()
                                string-alist
                                (list 
                                 (cons (symbol-name string-key) 
-                                      (regexp-quote
+                                      ;(regexp-quote
                                        (buffer-substring the-string-start
-                                                         the-string-end))))))
+                                                         the-string-end)))));)
                       ;;Collect the strings command themseves
                       (setq the-text
                             (concat the-text 
           (if substitute
               (while string-alist
                 (goto-char 1)
-                (let ((the-key (car (car string-alist)))
-                      (the-string (cdr (car string-alist))))
+                (let* ((the-key (car (car string-alist)))
+                       (the-string (cdr (car string-alist)))
+                       (slashed-string  ; "J. of Geo.\" -> "J. of Geo.\\\\"
+                        (dired-replace-in-string 
+                         "\\\\" "\\\\" the-string)))
+                  
                   (while (re-search-forward 
                           (concat "\\(^[, \t]*[a-zA-Z]+[ \t]*=[ \t]*\\)" 
                                   (regexp-quote the-key) 
                                   "\\([, \t\n]\\)")
                           nil t)
-                    (replace-match (concat "\\1" the-string "\\2") t)))
+                    (replace-match (concat "\\1" slashed-string "\\2") t nil)))
                 (setq string-alist (cdr string-alist)))
             ;; substitute is nil; Simply insert text of @string commands
             (goto-char 1)
         (visit-tags-table the-tags-file-name)) 
     ;; find-tag-noselect should set the TAGS file for the new buffer
     ;; that's what C-h f visit-tags-table says...
-    (if (string-match "XEmacs\\|Lucid" emacs-version)
-        (progn
-          (find-tag tag)
-          (setq new-buffer (current-buffer))
-          (set-buffer the-buffer))
-      (setq new-buffer (find-tag-noselect tag)) ;Seems to set buffer to TAGS
+    (cond 
+     ((string-match "XEmacs\\|Lucid" emacs-version)
+      (find-tag tag)
+      (setq new-buffer (current-buffer))
       (set-buffer the-buffer))
+     (t
+      (setq new-buffer (find-tag-noselect tag nil t)) 
+                                        ; -> Seems to set buffer to TAGS
+      (set-buffer the-buffer)))
     new-buffer))
 
 ;;---------------------------------------------------------------------------
     (let ((tex-buffer (get-buffer-create "*imenu-tex*"))
           (index-alist '())
           (index-label-alist '())
-          (prev-pos))
+          (prev-pos (point-max)))
       (save-excursion
         (set-buffer tex-buffer)
         ;; set its directory so relative includes work without expanding
     ;; For non-multi-file documents.
     (let ((index-alist '())
           (index-label-alist '())
-          prev-pos)
+          (prev-pos (point-max)))
       (setq bib-imenu-document-counter -99) ;IDs menu entries starting at -100
       (goto-char (point-max))
       (imenu-progress-message prev-pos 0 t)
       (if (not (string-match "\\.bib$" the-name))
           (setq the-name (concat the-name ".bib")))
       (setq the-file
-            (or
-             (and (file-readable-p (expand-file-name (concat "./" the-name)))
-                  (expand-file-name (concat "./" the-name)))
-             (psg-checkfor-file-list the-name 
-                                     (psg-list-env bib-bibtex-env-variable))
-             ;; Check for BIBINPUT env variable as well (by popular demand!)
-             (psg-checkfor-file-list the-name (psg-list-env "BIBINPUT"))
-             (and (boundp 'TeX-check-path)
-                  (psg-checkfor-file-list the-name TeX-check-path))))
+            (or (and (file-readable-p the-name) the-name)
+                (psg-checkfor-file-list 
+                 the-name (psg-list-env bib-bibtex-env-variable))
+                ;; Check for BIBINPUT env variable as well (by popular demand!)
+                (psg-checkfor-file-list the-name (psg-list-env "BIBINPUT"))
+                (and (boundp 'TeX-check-path)
+                     (psg-checkfor-file-list the-name TeX-check-path))))
       (if the-file
           (progn 
             (save-excursion
 ;;; latex.el --- Support for LaTeX documents.
 ;; 
 ;; Maintainer: Per Abrahamsen <auc-tex@sunsite.auc.dk>
-;; Version: 9.8l
+;; Version: 9.9p
 ;; Keywords: wp
 ;; X-URL: http://sunsite.auc.dk/auctex
 
 
 (defun LaTeX-current-section ()
   "Return the level of the section that contain point.
-See also LaTeX-section for description of levels."
+See also `LaTeX-section' for description of levels."
   (save-excursion
     (max (LaTeX-largest-level)
 	 (if (re-search-backward (LaTeX-outline-regexp) nil t)
 
 Each element is a list with two entries.  The first entry is the
 regular expression matching a header, and the second is the level of
-the header.  See LaTeX-section-list for existing header levels."
+the header.  See `LaTeX-section-list' for existing header levels."
   :group 'LaTeX
   :type '(repeat (group (regexp :tag "Match")
 			(integer :tag "Level"))))
 	  "\\|" TeX-trailer-start))
 
 (defvar LaTeX-largest-level nil
-  "Largest sectioning level with current document style")
+  "Largest sectioning level with current document style.")
 
 (make-variable-buffer-local 'LaTeX-largest-level)
 
   LaTeX-largest-level)
 
 (defun LaTeX-outline-offset ()
-  "Offset to add to LaTeX-section-list levels to get outline level."
+  "Offset to add to `LaTeX-section-list' levels to get outline level."
   (- 2 (LaTeX-largest-level)))
 
 (defun TeX-look-at (list)
 		(t
 		 (error "Unrecognized header")))))))
 
+(defun LaTeX-outline-name ()
+  "Guess a name for the current header line."
+  (save-excursion
+    (if (re-search-forward "\\{\\([^\}]*\\)\\}" (+ (point) 50) t)
+	(match-string 1)
+      (buffer-substring (point) (+ 20 (point))))))
+
 (add-hook 'TeX-remove-style-hook
 	  (function (lambda () (setq LaTeX-largest-level nil))))
 
 LaTeX-section-label: Insert a label after the section command.
 Controled by the variable `LaTeX-section-label'.
 
-To get a full featured LaTeX-section command, insert 
+To get a full featured `LaTeX-section' command, insert 
 
  (setq LaTeX-section-hook
        '(LaTeX-section-heading
 
 (defun LaTeX-section-heading ()
   "Hook to prompt for LaTeX section name.
-Insert this hook into LaTeX-section-hook to allow the user to change
+Insert this hook into `LaTeX-section-hook' to allow the user to change
 the name of the sectioning command inserted with `\\[LaTeX-section]'."
   (let ((string (completing-read
 		 (concat "Select level: (default " name ") ")
 
 (defun LaTeX-section-title ()
   "Hook to prompt for LaTeX section title.
-Insert this hook into LaTeX-section-hook to allow the user to change
+Insert this hook into `LaTeX-section-hook' to allow the user to change
 the title of the section inserted with `\\[LaTeX-section]."
   (setq title (read-string "What title: ")))
 
 (defun LaTeX-section-toc ()
   "Hook to prompt for the LaTeX section entry in the table of content .
-Insert this hook into LaTeX-section-hook to allow the user to insert
+Insert this hook into `LaTeX-section-hook' to allow the user to insert
 a different entry for the section in the table of content."
   (setq toc (read-string "Toc Entry: "))
   (if (zerop (length toc))
 
 (defun LaTeX-section-section ()
   "Hook to insert LaTeX section command into the file.
-Insert this hook into LaTeX-section-hook after those hooks which sets
+Insert this hook into `LaTeX-section-hook' after those hooks which sets
 the `name', `title', and `toc' variables, but before those hooks which
 assumes the section already is inserted."
     (insert TeX-esc name)
     (if (zerop (length title))
 	(set-marker done-mark (point)))
     (insert title TeX-grcl)
-    (newline))
+    (newline)
+    ;; If RefTeX is available, tell it that we've just made a new section
+    (and (fboundp 'reftex-notice-new-section)
+	 (reftex-notice-new-section)))
 
 (defun LaTeX-section-label ()
   "Hook to insert a label after the sectioning command.
-Insert this hook into LaTeX-section-hook to prompt for a label to be
+Insert this hook into `LaTeX-section-hook' to prompt for a label to be
 inserted after the sectioning command.
 
-The beaviour of this hook is controled by LaTeX-section-label."
+The beaviour of this hook is controled by `LaTeX-section-label'."
   (and (LaTeX-label name)
        (newline)))
 
   :group 'LaTeX-macro)
 
 (defcustom LaTeX-default-environment "itemize"
-  "*The default environment when creating new ones with LaTeX-environment."
+  "*The default environment when creating new ones with `LaTeX-environment'."
   :group 'LaTeX-environment
   :type 'string)
  (make-variable-buffer-local 'LaTeX-default-environment)
  
 It may be customized with the following variables:
  
-LaTeX-default-environment       Your favorite environment.
-LaTeX-default-style             Your favorite document style.
-LaTeX-default-options           Your favorite document style options.
-LaTeX-float                     Where you want figures and tables to float.
-LaTeX-table-label               Your prefix to labels in tables.
-LaTeX-figure-label              Your prefix to labels in figures.
-LaTeX-default-format            Format for array and tabular.
-LaTeX-default-position          Position for array and tabular."
+`LaTeX-default-environment'       Your favorite environment.
+`LaTeX-default-style'             Your favorite document style.
+`LaTeX-default-options'           Your favorite document style options.
+`LaTeX-float'                     Where you want figures and tables to float.
+`LaTeX-table-label'               Your prefix to labels in tables.
+`LaTeX-figure-label'              Your prefix to labels in figures.
+`LaTeX-default-format'            Format for array and tabular.
+`LaTeX-default-position'          Position for array and tabular."
  
   (interactive "*P")
   (let ((environment (completing-read (concat "Environment type: (default "
 	   (apply (nth 1 entry) environment (nthcdr 2 entry))))))
 
 (defun LaTeX-close-environment ()
-  "Creates an \\end{...} to match the current environment."
+  "Create an \\end{...} to match the current environment."
   (interactive "*")
   (if (> (point)
 	 (save-excursion
 
 (defun LaTeX-insert-item ()
   "Insert a new item in an environment.
-You may use LaTeX-item-list to change the routines used to insert the item."
+You may use `LaTeX-item-list' to change the routines used to insert the item."
   (interactive "*")
   (let ((environment (LaTeX-current-environment)))
     (newline)
   '(("\\\\label{\\([^\n\r%\\{}]+\\)}" 1 LaTeX-auto-label))
   "List of regular expression matching LaTeX labels only.")
 
+(defvar LaTeX-auto-index-regexp-list
+  '(("\\\\index{\\([^}{]*\\({[^}{]*\\({[^}{]*\\({[^}{]*}[^}{]*\\)*}[^}{]*\\)*}[^}{]*\\)*\\)}"
+	1 LaTeX-auto-index-entry))
+  "List of regular expression matching LaTeX index entries only.
+Regexp allows for up to 3 levels of parenthesis inside the index argument.
+This is necessary since index entries may contain commands and stuff.")
+
 (defvar LaTeX-auto-regexp-list 
   (append
-   '(("\\\\\\(new\\|provide\\)command\\*?{?\\\\\\([a-zA-Z]+\\)}?\\[\\([0-9]+\\)\\]\\\[\\([^\]\\\\\n\r]+\\)\\]"
+   '(("\\\\\\(new\\|provide\\)command\\*?{?\\\\\\([a-zA-Z]+\\)}?\\[\\([0-9]+\\)\\]\\[\\([^\n\r]*\\)\\]"
       (2 3 4) LaTeX-auto-optional)
      ("\\\\\\(new\\|provide\\)command\\*?{?\\\\\\([a-zA-Z]+\\)}?\\[\\([0-9]+\\)\\]"
       (2 3) LaTeX-auto-arguments)
      ("\\\\newenvironment\\*?{?\\([a-zA-Z]+\\)}?\\[\\([0-9]+\\)\\]"
       (1 2) LaTeX-auto-env-args)
      ("\\\\newenvironment\\*?{?\\([a-zA-Z]+\\)}?" 1 LaTeX-auto-environment)
-     ("\\\\\\(new\\|provide\\)command\\*{?\\\\\\([a-zA-Z]+\\)}?\\[\\([0-9]+\\)\\]\\\[\\([^\]\\\\\n\r]+\\)\\]"
-      (2 3 4) LaTeX-auto-optional)
      ("\\\\newtheorem{\\([a-zA-Z]+\\)}" 1 LaTeX-auto-environment)
      ("\\\\input{\\(\\.*[^#}%\\\\\\.\n\r]+\\)\\(\\.[^#}%\\\\\\.\n\r]+\\)?}"
       1 TeX-auto-file)
       1 LaTeX-auto-bibitem)
      ("\\\\bibliography{\\([^#}\\\\\n\r]+\\)}" 1 LaTeX-auto-bibliography))
    LaTeX-auto-label-regexp-list
+   LaTeX-auto-index-regexp-list
    LaTeX-auto-minimal-regexp-list)
   "List of regular expression matching common LaTeX macro definitions.")
 
 (TeX-auto-add-type "bibitem" "LaTeX")
 (TeX-auto-add-type "environment" "LaTeX")
 (TeX-auto-add-type "bibliography" "LaTeX" "bibliographies")
+(TeX-auto-add-type "index-entry" "LaTeX" "index-entries")
 
 (fset 'LaTeX-add-bibliographies-auto
       (symbol-function 'LaTeX-add-bibliographies))
 
 ;;;###autoload
 (defun BibTeX-auto-store ()
-  "This function should be called from bibtex-mode-hook.
+  "This function should be called from `bibtex-mode-hook'.
 It will setup BibTeX to store keys in an auto file."
   ;; We want this to be early in the list, so we do not
   ;; add it before we enter BibTeX mode the first time. 
 
 (defalias 'TeX-arg-ref 'TeX-arg-label)
 
+(defun TeX-arg-define-index (optional &optional prompt definition)
+  (TeX-arg-index optional prompt t))
+(defun TeX-arg-index (optional &optional prompt definition)
+  "Prompt for an index entry completing with known entries."
+  (let ((entry (completing-read (TeX-argument-prompt optional prompt "Key")
+				(LaTeX-index-entry-list))))
+    (if (and definition (not (string-equal "" entry)))
+	(LaTeX-add-index-entries entry))
+    (TeX-argument-insert entry optional optional)))
+
 (defun TeX-arg-macro (optional &optional prompt definition)
   "Prompt for a TeX macro with completion."
   (let ((macro (completing-read (TeX-argument-prompt optional prompt
     ("\\lceil") ("\\rceil") ("\\langle") ("\\rangle")
     ("\\uparrow") ("\\Uparrow") ("\\downarrow") ("\\Downarrow")
     ("\\updownarrow") ("\\Updownarrow") ("."))
-  "List of symbols which can follow the \\left or \\right command")
+  "List of symbols which can follow the \\left or \\right command.")
 
 (defun TeX-arg-insert-braces (optional &optional prompt)
   (save-excursion
 
 (defun LaTeX-indent-line ()
   "Indent the line containing point, as LaTeX source.
-Add LaTeX-indent-level indentation in each \\begin{ - \\end{ block.
+Add `LaTeX-indent-level' indentation in each \\begin{ - \\end{ block.
 Lines starting with an item is given an extra indentation of
-LaTeX-item-indent."
+`LaTeX-item-indent'."
   (interactive)
   (let* ((case-fold-search nil)
 	 (indent (LaTeX-indent-calculate)))
 
 (defun LaTeX-fill-region-as-paragraph (from to &optional justify-flag)
   "Fill region as one paragraph.
-Break lines to fit fill-column, but leave all lines ending with \\\\
+Break lines to fit `fill-column', but leave all lines ending with \\\\
 \(plus its optional argument) alone. Prefix arg means justify too.
 From program, pass args FROM, TO and JUSTIFY-FLAG."
   (interactive "*r\nP")
 	  (LaTeX-indent-line)))))
 
 (defun LaTeX-fill-region-as-para-do (from to justify-flag)
-  "Fill region as one paragraph: break lines to fit fill-column."
+  "Fill region as one paragraph: break lines to fit `fill-column'."
   (if (< from to)
       (progn
 	;; (save-restriction) here is likely not needed because
     (message "Finished")))
 
 (defun LaTeX-find-matching-end ()
-  "Move point to the \\end of the current environment"
+  "Move point to the \\end of the current environment."
   (interactive)
   (let ((regexp (concat (regexp-quote TeX-esc) "\\(begin\\|end\\)\\b"))
 	(level 1))
       (error "Can't locate end of current environment"))))
 
 (defun LaTeX-find-matching-begin ()
-  "Move point to the \\begin of the current environment"
+  "Move point to the \\begin of the current environment."
   (interactive)
   (let ((regexp (concat (regexp-quote TeX-esc) "\\(begin\\|end\\)\\b"))
 	(level 1))
   :type 'string)
 
 (defvar LaTeX-math-keymap (make-sparse-keymap)
-  "Keymap used for LaTeX-math-mode commands.")
+  "Keymap used for `LaTeX-math-mode' commands.")
 
 (defvar LaTeX-math-menu
   '("Math"
   (if dollar (insert "$")))
 
 (defun LaTeX-math-cal (char dollar)
-  "Inserts a {\\cal CHAR}.  If DOLLAR is non-nil, put $'s around it."
+  "Insert a {\\cal CHAR}.  If DOLLAR is non-nil, put $'s around it."
   (interactive "*c\nP")
   (if dollar (insert "$"))
   (if (member "latex2e" (TeX-style-list))
     (define-key map "\C-c~"    'LaTeX-math-mode) ;*** Dubious
     
     map)
-  "Keymap used in LaTeX-mode.")
+  "Keymap used in `LaTeX-mode'.")
 
 (defvar LaTeX-environment-menu-name "Insert Environment  (C-c C-e)")
 
 	      ["Sans Serif" (TeX-font nil ?\C-f) :keys "C-c C-f C-f"]
 	      ["Italic"     (TeX-font nil ?\C-i) :keys "C-c C-f C-i"]
 	      ["Slanted"    (TeX-font nil ?\C-s) :keys "C-c C-f C-s"]
-	      ["Roman"      (TeX-font nil ?\C-r) :keys "C-c C-f C-r"])
+	      ["Roman"      (TeX-font nil ?\C-r) :keys "C-c C-f C-r"]
+	      ["Calligraphic" (TeX-font nil ?\C-a) :keys "C-c C-f C-a"])
 	(list "Change Font"
 	      ["Emphasize"  (TeX-font t ?\C-e) :keys "C-u C-c C-f C-e"]
 	      ["Bold"       (TeX-font t ?\C-b) :keys "C-u C-c C-f C-b"]
 	      ["Sans Serif" (TeX-font t ?\C-f) :keys "C-u C-c C-f C-f"]
 	      ["Italic"     (TeX-font t ?\C-i) :keys "C-u C-c C-f C-i"]
 	      ["Slanted"    (TeX-font t ?\C-s) :keys "C-u C-c C-f C-s"]
-	      ["Roman"      (TeX-font t ?\C-r) :keys "C-u C-c C-f C-r"])
+	      ["Roman"      (TeX-font t ?\C-r) :keys "C-u C-c C-f C-r"]
+	      ["Calligraphic" (TeX-font t ?\C-a) :keys "C-u C-c C-f C-a"])
 	["Delete Font" (TeX-font t ?\C-d) :keys "C-c C-f C-d"]
 	"-"
 	["Next Error" TeX-next-error t]
 	      ["Reset AUC TeX" (TeX-normal-mode t) :keys "C-u C-c C-n"])))
 
 (defcustom LaTeX-font-list
-  '((?\C-b "\\textbf{" "}")
-    (?\C-c "\\textsc{" "}")
-    (?\C-e "\\emph{" "}")
-    (?\C-f "\\textsf{" "}")
-    (?\C-i "\\textit{" "}")
-    (?\C-m "\\textmd{" "}")
-    (?\C-n "\\textnormal{" "}")
-    (?\C-r "\\textrm{" "}")
-    (?\C-s "\\textsl{" "}")
-    (?\C-t "\\texttt{" "}")
-    (?\C-u "\\textup{" "}")
+  '((?\C-a ""              ""  "\\mathcal{"    "}")
+    (?\C-b "\\textbf{"     "}" "\\mathbf{"     "}")
+    (?\C-c "\\textsc{"     "}")
+    (?\C-e "\\emph{"       "}")
+    (?\C-f "\\textsf{"     "}" "\\mathsf{"     "}")
+    (?\C-i "\\textit{"     "}" "\\mathit{"     "}")
+    (?\C-m "\\textmd{"     "}")
+    (?\C-n "\\textnormal{" "}" "\\mathnormal{" "}")
+    (?\C-r "\\textrm{"     "}" "\\mathrm{"     "}")
+    (?\C-s "\\textsl{"     "}")
+    (?\C-t "\\texttt{"     "}" "\\mathtt{"     "}")
+    (?\C-u "\\textup{"     "}")
     (?\C-d "" "" t))
   "Font commands used with LaTeX2e.  See `TeX-font-list'."
   :group 'LaTeX-macro
-  :type '(repeat (group (character :tag "Key")
-			(string :tag "Prefix")
-			(string :tag "Suffix")
-			(option (sexp :format "Replace\n" 
-				      :value t)))))
-
+  :type '(repeat 
+	   (group 
+	    :value (?\C-a "" "")
+	    (character :tag "Key")
+	    (string :tag "Prefix")
+	    (string :tag "Suffix")
+	    (option (group
+		     :inline t
+		     (string :tag "Math Prefix")
+		     (string :tag "Math Suffix")))
+	    (option (sexp :format "Replace\n" :value t)))))
 ;;; Mode
 
 (defgroup LaTeX-macro nil
   (concat (regexp-quote TeX-esc) "end *" TeX-grop "document" TeX-grcl)
   "Default start of trailer marker for LaTeX documents.")
 
-(defun LaTeX2e-font-replace (start end)
-  "Replace LaTeX2e font specification around point with START and END."
-  (save-excursion
-    (catch 'done
-      (while t
-	(if (/= ?\\ (following-char))
-	    (skip-chars-backward "a-zA-Z "))
-	(skip-chars-backward "\\\\")
-	(if (looking-at "\\\\\\(emph\\|text[a-z]+\\){")
-	    (throw 'done t)
-	  (up-list -1))))
-    (forward-sexp 2)
-    (save-excursion
-      (replace-match start t t))
-    (delete-backward-char 1)
-    (insert end)))
-
 (defun LaTeX-common-initialization ()
   ;; Common initialization for LaTeX derived modes.
   (VirTeX-common-initialization)
    '("verb" TeX-arg-verb)
    '("verb*" TeX-arg-verb)
    '("extracolsep" t)
-   '("index" t)
+   '("index" TeX-arg-define-index)
    '("glossary" t)
    '("numberline" "Section number" "Heading")
    '("caption" t)
   (if (string-equal LaTeX-version "2")
       ()
     (setq TeX-font-list LaTeX-font-list)
-    (setq TeX-font-replace-function 'LaTeX2e-font-replace)
+    (setq TeX-font-replace-function 'TeX-font-replace-macro)
     (TeX-add-symbols
      '("newcommand" TeX-arg-define-macro
        [ "Number of arguments" ] [ "Default value for first argument" ] t)
    ;; Use new fonts for `\documentclass' documents.
    (function (lambda ()
      (setq TeX-font-list LaTeX-font-list)
-     (setq TeX-font-replace-function 'LaTeX2e-font-replace)
+     (setq TeX-font-replace-function 'TeX-font-replace-macro)
      (if (equal LaTeX-version "2")
 	 (setq TeX-command-default "LaTeX2e"))
      (run-hooks 'LaTeX2e-hook))))
      (setq TeX-font-list (default-value 'TeX-font-list))
      (setq TeX-font-replace-function
 	   (default-value 'TeX-font-replace-function))
-     (run-hooks 'LaTeX2-hook)))))
+     (run-hooks 'LaTeX2-hook))))
+
+  (set (make-local-variable 'imenu-create-index-function)
+       'LaTeX-imenu-create-index-function))
+
+(defun LaTeX-imenu-create-index-function ()
+  "Imenu support function for LaTeX."
+  (TeX-update-style)
+  (let (entries level
+	(regexp (LaTeX-outline-regexp)))
+    (goto-char (point-max))
+    (while (re-search-backward regexp nil t)
+      (let ((name (LaTeX-outline-name))
+	    (level (make-string (1- (LaTeX-outline-level)) ?\ ))
+	    (mark (make-marker)))
+	(set-marker mark (point))
+	(setq entries (cons (cons (concat level level name) mark)
+			    entries))))
+    entries))
 
 (defvar LaTeX-builtin-opts 
   '("12pt" "11pt" "10pt" "twocolumn" "twoside" "draft")
-  "Built in options for LaTeX standard styles")
+  "Built in options for LaTeX standard styles.")
 
 (defun LaTeX-209-to-2e ()
   "Make a stab at changing 2.09 doc header to 2e style."
 ;;; tex-buf.el - External commands for AUC TeX.
 ;;
 ;; Maintainer: Per Abrahamsen <auc-tex@sunsite.auc.dk>
-;; Version: 9.8l
+;; Version: 9.9p
 
 ;; Copyright (C) 1991 Kresten Krab Thorup
 ;; Copyright (C) 1993, 1996 Per Abrahamsen 
 		  (setq found t))))))
     found))
 
+(defun TeX-run-ispell-on-document (command ignored name)
+  "Run ispell on  all files belonging to the current document."
+  (interactive)
+  (TeX-ispell-document ""))
+
+(defun TeX-ispell-document (name)
+  "Run ispell on  all files belonging to the current document."
+  (interactive (list (TeX-master-file)))
+  (if (string-equal name "")
+      (setq name (TeX-master-file)))
+  
+  (let ((found nil)
+	(regexp (concat "\\`\\("
+			(mapconcat (function (lambda (dir)
+				      (regexp-quote (expand-file-name dir))))
+				   TeX-check-path "\\|")
+			"\\).*\\("
+			(mapconcat 'regexp-quote (cons name (TeX-style-list)) "\\|")
+			"\\)\\.\\("
+			(mapconcat 'regexp-quote TeX-file-extensions "\\|")
+			"\\)\\'"))
+	(buffers (buffer-list)))
+    (while buffers
+      (let* ((buffer (car buffers))
+	     (name (buffer-file-name buffer)))
+	(setq buffers (cdr buffers))
+	(if (and name (string-match regexp name))
+	    (progn
+	      (save-excursion (switch-to-buffer buffer) (ispell-buffer))
+	      (setq found t)))))))
+
 (defcustom TeX-save-query t
   "*If non-nil, ask user for permission to save files before starting TeX."
   :group 'TeX-commands
     (setq TeX-command-buffer (current-buffer))
     (with-output-to-temp-buffer buffer)
     (set-buffer buffer)
+    (setq buffer-read-only nil)
     (if dir (cd dir))
     (insert "Running `" name "' on `" file "' with ``" command "''\n")
     (comint-exec buffer name TeX-shell nil
 ;;; tex-info.el - Support for editing TeXinfo source.
 ;;
 ;; Maintainer: Per Abrahamsen <auc-tex@sunsite.auc.dk>
-;; Version: 9.8l
+;; Version: 9.9p
 
 ;; Copyright (C) 1993, 1994, 1997 Per Abrahamsen 
 ;; 
     (?\C-t "@t{" "}")
     (?s    "@strong{" "}")
     (?\C-f "@file{" "}")
-    (?\C-d "@dfn{" "}")
+    (?d "@dfn{" "}")
     (?\C-v "@var{" "}")
     (?k    "@key{" "}")
     (?\C-k "@kbd{" "}")
     (?c    "@code{" "}")
-    (?C    "@cite{" "}"))
+    (?C    "@cite{" "}")
+    (?\C-d "" "" t))
   "Font commands used in TeXinfo mode.  See `TeX-font-list'.")
   
 ;;; Mode:
 
   (make-local-variable 'TeX-font-list)
   (setq TeX-font-list TeXinfo-font-list)
+  (make-local-variable 'TeX-font-replace-function)
+  (setq TeX-font-replace-function 'TeX-font-replace-macro)
   
   (TeX-add-symbols
    '("appendix" "Title")
 
 (setq TeX-format-list
       (append '(("JLATEX" japanese-latex-mode
-		 "\\\\\\(\\\\documentstyle[^%\n]*{j\\|\\\\documentclass[^%\n]*{j\\)")
+		 "\\\\\\(documentstyle[^%\n]*{j\\|documentclass[^%\n]*{j\\)")
 		("JTEX" japanese-plain-tex-mode
 		 "-- string likely in Japanese TeX --"))
 	      TeX-format-list))
     ;; modified by  S.Tomura 88-Jun-21
     ;;(subst-char-in-region from (point-max) ?\n ?\ )
     ;; modified by K.Handa 92-Mar-2
-    ;; Spacing is not necessary for characters of no word-separator.
+    ;; Spacing is not necessary for charcters of no word-separater.
     ;; The regexp word-across-newline is used for this check.
     (if (not (stringp word-across-newline))
 	(subst-char-in-region from (point-max) ?\n ?\ )
     ;; bug fixed by S.Tomura 88-May-25
     ;; modified by  S.Tomura 88-Jun-21
     ;; modified by K.Handa 92-Mar-2
-    ;; Spacing is not necessary for characters of no word-separator.
+    ;; Spacing is not necessary for charcters of no word-separater.
     ;; The regexp word-across-newline is used for this check.
     (if (not (stringp word-across-newline))
 	(subst-char-in-region from (point-max) ?\n ?\ )
-;;; tex-site.el - Select AUC TeX as your tex mode.
+;;; tex-site.el - Site specific variables.
 
 ;; Copyright (C) 1991 Kresten Krab Thorup 
 ;; Copyright (C) 1993, 1994, 1997 Per Abrahamsen 
 
-;; Author: Per Abrahamsen <abraham@iesd.auc.dk>
+;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
 ;; Maintainer: Per Abrahamsen <auc-tex@sunsite.auc.dk>
-;; Version: 9.8l (XEmacs)
+;; Version: 9.9p
 ;; Keywords: wp
 
 ;; This program is free software; you can redistribute it and/or modify
 ;; Copy variables you need to change from the start of `tex.el' and
 ;; insert them here.
 
+(defvar TeX-lisp-directory "@AUCDIR"
+  "*The directory where the AUC TeX lisp files are located.")
+
 ;;; Autoloads:
 
+(or (assoc TeX-lisp-directory (mapcar 'list load-path))	;No `member' yet.
+    (assoc (substring TeX-lisp-directory 0 -1) ;Without trailing slash.
+	   (mapcar 'list load-path))
+    (setq load-path (cons TeX-lisp-directory load-path)))
+
 ;; This hook will store bibitems when you save a BibTeX buffer.
-(add-hook 'bibtex-mode-hook 'BibTeX-auto-store)
+(defvar bibtex-mode-hook nil)
+(or (memq 'BibTeX-auto-store bibtex-mode-hook) ;No `add-hook' yet.
+    (setq bibtex-mode-hook (cons 'BibTeX-auto-store bibtex-mode-hook)))
 
-;; Load from AUC TeX files instead of standard files.
+(autoload 'BibTeX-auto-store "latex" no-doc t)
+
 (autoload 'tex-mode "tex" no-doc t)
 (autoload 'plain-tex-mode "tex" no-doc t)
-(autoload 'tex-insert-quote "tex" no-doc t)
+(autoload 'ams-tex-mode "tex" no-doc t)
+(autoload 'TeX-auto-generate "tex" no-doc t)
+(autoload 'TeX-auto-generate-global "tex" no-doc t)
+(autoload 'TeX-insert-quote "tex" no-doc t)
+(autoload 'TeX-submit-bug-report "tex" no-doc t)
+(autoload 'japanese-plain-tex-mode "tex-jp" no-doc t)
+(autoload 'japanese-latex-mode "tex-jp" no-doc t)
+(autoload 'japanese-slitex-mode "tex-jp" no-doc t)
 (autoload 'texinfo-mode "tex-info" no-doc t)
 (autoload 'latex-mode "latex" no-doc t)
 
 ;;; tex.el --- Support for TeX documents.
 
 ;; Maintainer: Per Abrahamsen <auc-tex@sunsite.auc.dk>
-;; Version: 9.8l
+;; Version: 9.9p
 ;; Keywords: wp
 ;; X-URL: http://sunsite.auc.dk/auctex
 
 ;; file, but instead copy those definitions you need to change to
 ;; `tex-site.el'. 
 
-(defcustom TeX-lisp-directory (if (fboundp 'locate-data-directory)
-				  (locate-data-directory "auctex")
-				(concat data-directory "auctex/"))
-  "*The directory where the AUC TeX lisp files are located."
+(defcustom TeX-lisp-directory (or (and (fboundp 'locate-data-directory)
+				       (locate-data-directory "auctex"))
+				  (concat data-directory "auctex/"))
+  "The directory where the AUC TeX lisp files are located."
   :group 'TeX-file
   :type 'directory)
 
 ;; Change this to point to the place where the TeX macros are stored
-;; at yourt site.  [Ignore when bundled with XEmacs]
-(defcustom TeX-macro-global '("/usr/lib/texmf/tex/")
-  "*Directories containing the sites TeX macro files and style files.
+;; at yourt site.
+(defcustom TeX-macro-global '("/usr/local/lib/texmf/tex/")
+  "Directories containing the sites TeX macro files and style files.
 The directory names *must* end with a slash."
   :group 'TeX-file
   :type '(repeat (directory :format "%v")))
 	;; Uncomment the above line and comment out the next line to
 	;; use `chktex' instead of `lacheck'. 
 	(list "Check" "lacheck %s" 'TeX-run-compile nil t)
-	(list "Spell" "<ignored>" 'TeX-run-ispell nil nil)
+	(list "Spell" "<ignored>" 'TeX-run-ispell-on-document nil nil)
 	(list "Other" "" 'TeX-run-command t t)
 	;; Not part of standard TeX.
 	(list "Makeinfo" "makeinfo %t" 'TeX-run-compile nil t)
 	(list "%l" 'TeX-style-check LaTeX-command-style)
 	(list "%s" 'file nil t)
 	(list "%t" 'file 't t)
+	(list "%n" 'TeX-current-line)
 	(list "%d" 'file "dvi" t)
 	(list "%f" 'file "ps" t))
   "List of expansion strings for TeX command names.
 
 ;;; Import
 
-(or (assoc TeX-lisp-directory (mapcar 'list load-path))	;No `member' yet.
-    (setq load-path (cons TeX-lisp-directory load-path)))
+;;(or (assoc TeX-lisp-directory (mapcar 'list load-path))	;No `member' yet.
+;;    (setq load-path (cons TeX-lisp-directory load-path)))
 
 (defvar no-doc
   "This function is part of AUC TeX, but has not yet been loaded.
 (autoload 'latex-mode "latex" no-doc t)
 
 (autoload 'multi-prompt "multi-prompt" no-doc nil)
+(autoload 'texmathp "texmathp" no-doc nil)
 
 ;;; Portability.
 
 ;; These two variables are automatically updated with "make dist", so
 ;; be careful before changing anything.
 
-(defconst AUC-TeX-version "9.8l"
+(defconst AUC-TeX-version "9.9p"
   "AUC TeX version number")
 
-(defconst AUC-TeX-date "Fri Feb 20 14:57:08 MET 1998"
+(defconst AUC-TeX-date "Thu Feb 11 11:19:02 MET 1999"
   "AUC TeX release date")
 
 ;;; Buffer
 	((string-match "\\`\\(.+/\\)\\([^/]*\\)\\'" style) ;Complex path
 	 (let* ((dir (substring style (match-beginning 1) (match-end 1)))
 		(style (substring style (match-beginning 2) (match-end 2)))
+		(master-dir (if (stringp TeX-master)
+				(file-name-directory
+				 (file-relative-name TeX-master))
+			      "./"))
 		(TeX-style-path (append (list (concat dir TeX-auto-local)
-					      (concat dir TeX-style-local))
+					      (concat master-dir
+						      TeX-auto-local)  
+					      (concat dir TeX-style-local)  
+					      (concat master-dir
+						      TeX-style-local))
 					TeX-style-path)))
 	   (TeX-load-style style)))
 	(t				;Relative path
   ;; Load FILE checking for a lisp extensions.
   (let ((el (concat file ".el"))
 	(elc (concat file ".elc")))
-    (cond ((and (null TeX-byte-compile)
-		(file-readable-p el))
-	   (load-file el))
-	  ((file-newer-than-file-p el elc)
-	   (if (not (file-writable-p elc))
-	       (load-file el)
-	     (byte-compile-file el)
-	     (load-file elc)))
+    (cond ((file-newer-than-file-p el elc)
+	   (if (file-readable-p el)
+	       (if (and TeX-byte-compile
+			(file-writable-p elc)
+			(save-excursion
+			  ;; `byte-compile-file' switches buffer in Emacs 20.3.
+			  (byte-compile-file el))
+			(file-readable-p elc))
+		   (load-file elc)
+		 (load-file el))))
 	  ((file-readable-p elc)
 	   (load-file elc))
 	  ((file-readable-p el)
 (defcustom TeX-insert-braces t
   "*If non-nil, append a empty pair of braces after inserting a macro."
   :group 'TeX-macro
-  :type 'string)
-
-(defun TeX-math-mode-p ()
-  "Are we in TeX math mode?"
-  ;; This should check for dollar signs, but thats to hard for now.
-  (and (boundp 'LaTeX-math-mode) LaTeX-math-mode))
+  :type 'boolean)
 
 (defun TeX-insert-macro (symbol)
   "Insert TeX macro with completion.
   ;; Use square brackets instead of curly braces, and is not inserted
   ;; on empty user input.
 
+  (if (and (TeX-active-mark)
+	   (> (point) (mark)))
+      (exchange-point-and-mark))
   (insert TeX-esc symbol)
   (let ((exit-mark (make-marker))
 	(position (point)))
 	  ((and TeX-insert-braces
 		(equal position (point))
 		(string-match "[a-zA-Z]+" symbol)
-		(not (TeX-math-mode-p)))
-	   (insert TeX-grop TeX-grcl)))))
+		(not (texmathp)))
+	   (insert TeX-grop)
+ 	   (if (TeX-active-mark)
+ 	       (progn
+ 		 (exchange-point-and-mark)
+ 		 (insert TeX-grcl))
+ 	     (insert TeX-grcl)
+ 	     (backward-char))))))
 
 (defun TeX-arg-string (optional &optional prompt input)
   "Prompt for a string."
   (TeX-argument-insert
-   (read-string (TeX-argument-prompt optional prompt "Text") input)
+   (if (and (not optional) (TeX-active-mark))
+       (let ((TeX-argument (buffer-substring (point) (mark))))
+ 	 (delete-region (point) (mark))
+ 	 TeX-argument)
+     (read-string (TeX-argument-prompt optional prompt "Text") input))
    optional))
 
 (defun TeX-parse-arguments (args)
 (defun TeX-parse-argument (optional arg)
   "Depending on OPTIONAL, insert TeX macro argument ARG in curly braces.
 If OPTIONAL is set, only insert if there is anything to insert, and
-then use scare brackets.
+then use square brackets.
 
 See TeX-parse-macro for details."
   
 	     (TeX-parse-argument optional nil)
 	     (setq arg (- arg 1)))))
 	((null arg)
-	 (insert < >))
+	 (insert <)
+	 (if (and (not optional) (TeX-active-mark))
+	     (exchange-point-and-mark))
+	 (insert >))
 	((eq arg t)
 	 (insert  < )
-	 (set-marker exit-mark (point))
+	 (if (and (not optional) (TeX-active-mark))
+	     (exchange-point-and-mark)
+	   (set-marker exit-mark (point)))
 	 (insert >))
 	((symbolp arg)
 	 (funcall arg optional))
 (defun TeX-argument-insert (name optional &optional prefix)
   "Insert NAME surrounded by curly braces.
 
-If OPTIONAL, only insert it if not empty, and then use scuare brackets."
+If OPTIONAL, only insert it if not empty, and then use square brackets."
   (if (and optional (string-equal name ""))
       (setq last-optional-rejected t)
     (insert <)
                            (expand-file-name (read-file-name
                                               "AUTO lisp directory: "
                                               TeX-auto-default
-                                              TeX-auto-default 'confirm)))))
+                                              TeX-auto-default
+                                              'confirm)))))
+  (TeX-auto-generate-1 tex auto
+		       (cond 
+			((and (numberp TeX-file-recurse)
+			      (> TeX-file-recurse 0))
+			 TeX-file-recurse)
+			((null TeX-file-recurse) 1)
+			(t -1))))
+
+(defun TeX-auto-generate-1 (tex auto recursion-depth) 
   (cond ((not (file-readable-p tex)))
 	((string-match TeX-ignore-file tex))
-        ((file-directory-p tex)
-         (let ((files (directory-files tex))
-               (default-directory (concat (if (TeX-directory-absolute-p tex)
-                                              ""
-                                            default-directory)
-                                          (if (string-match "/$" tex)
-                                              tex
-                                            (concat tex "/")))))
-           (mapcar (function (lambda (file)
-		      (if (or TeX-file-recurse
-			      (not (file-directory-p file)))
-			  (TeX-auto-generate file auto))))
-                   files)))
-        ((not (file-newer-than-file-p tex
-                   (concat auto (if (string-match "/$" auto) "" "/")
-                      (TeX-strip-extension tex TeX-all-extensions t) ".el"))))
-        ((TeX-match-extension tex (append TeX-file-extensions
+	((and (file-directory-p tex)
+	      (not (eq recursion-depth 0)))
+
+	 (let ((files (directory-files tex))
+	       (default-directory
+		 (concat (if (TeX-directory-absolute-p tex)
+			     ""
+			   default-directory)
+			 (if (string-match "/$" tex)
+			     tex
+			   (concat tex "/")))))
+	   (mapcar (function (lambda (file)
+			       (TeX-auto-generate-1 file auto 
+						    (1- recursion-depth))))
+		   files)))
+	((not (file-newer-than-file-p
+	       tex
+	       (concat auto (if (string-match "/$" auto) "" "/")
+		       (TeX-strip-extension tex TeX-all-extensions t)
+		       ".el"))))
+	((TeX-match-extension tex (append TeX-file-extensions
 					  BibTeX-file-extensions))
-         (save-excursion
-           (set-buffer (find-file-noselect tex))
-           (message "Parsing %s..." tex)
-           (TeX-auto-store (concat auto
-                                   (if (string-match "/$" auto) "" "/")
-                                   (TeX-strip-extension tex
+	 (save-excursion
+	   (set-buffer (find-file-noselect tex))
+	   (message "Parsing %s..." tex)
+	   (TeX-auto-store (concat auto
+				   (if (string-match "/$" auto) "" "/")
+				   (TeX-strip-extension tex
 							TeX-all-extensions
 							t)
-                                   ".el"))
-           (kill-buffer (current-buffer))
-           (message "Parsing %s... done" tex)))))
+				   ".el"))
+	   (kill-buffer (current-buffer))
+	   (message "Parsing %s... done" tex)))))
 
 ;;;###autoload
 (defun TeX-auto-generate-global ()
     ("\\\\let\\\\\\([a-zA-Z]+\\)[^a-zA-Z@]" 1 TeX-auto-symbol-check)
     ("\\\\font\\\\\\([a-zA-Z]+\\)[^a-zA-Z@]" 1 TeX-auto-symbol)
     ("\\\\chardef\\\\\\([a-zA-Z]+\\)[^a-zA-Z@]" 1 TeX-auto-symbol)
-    ("\\\\new\\(count|dimen|muskip|skip\\)\\\\\\([a-z]+\\)[^a-zA-Z@]"
+    ("\\\\new\\(count\\|dimen\\|muskip\\|skip\\)\\\\\\([a-z]+\\)[^a-zA-Z@]"
      2 TeX-auto-symbol)
     ("\\\\newfont{?\\\\\\([a-zA-Z]+\\)}?" 1 TeX-auto-symbol)
     ("\\\\typein\\[\\\\\\([a-zA-Z]+\\)\\]" 1 TeX-auto-symbol)
   :type 'regexp)
 
 (defcustom TeX-file-recurse t
-  "*If not nil, search TeX directories recursivly."
+  "*Whether to search TeX directories recursively: 'nil' means do not
+recurse, a positive integer means go that far deep in the directory
+hierarchy, 't' means recurse indefinitely."  
   :group 'TeX-parse
-  :type 'boolean)
+  :type '(choice (const :tag "On" t)
+		 (const :tag "Off" nil)
+		 (integer :tag "Depth" :value 1)))
 
 (defun TeX-match-extension (file &optional extensions)
   "Return non-nil if FILE has an one of EXTENSIONS.
 
   (let ((regexp (concat "\\.\\("
                         (mapconcat 'identity extensions "\\|")
-                        "\\)$")))
+                        "\\)$"))
+	(case-fold-search t))
     (string-match regexp file)))
 
 (defun TeX-strip-extension (&optional string extensions nodir nostrip)
 If optional argument DIRECTORIES is set, search in those directories. 
 Otherwise, search in all TeX macro directories.
 If optional argument EXTENSIONS is not set, use TeX-file-extensions"
-
   (if (null extensions)
       (setq extensions TeX-file-extensions))
-  
   (if (null directories)
       (setq directories
 	    (cons "./" (append TeX-macro-private TeX-macro-global))))
-  
-  (let (match)
-    
-    (while directories
-      (let* ((directory (car directories))
-             (content (and directory
-			   (file-readable-p directory)
-			   (file-directory-p directory)
-			   (directory-files directory))))
-        
-        (setq directories (cdr directories))
-	
-        (while content
-          (let ((file (concat directory (car content))))
-	    
-            (setq content (cdr content))
-            (cond ((string-match TeX-ignore-file file))
-		  ((not (file-readable-p file)))
-                  ((file-directory-p file)
-		   (if TeX-file-recurse
-		       (setq directories
-			     (cons (concat file "/") directories))))
-                  ((TeX-match-extension file extensions)
-                   (setq match (cons (TeX-strip-extension file
-							  extensions
-							  nodir
-							  (not strip))
-                                     match))))))))
-    
-    match))
+  (mapcar (function
+	   (lambda (dir)
+	     (TeX-search-files-1 dir extensions nodir strip
+			      (cond 
+			       ((and (numberp TeX-file-recurse)
+				     (> TeX-file-recurse 0))
+				TeX-file-recurse)
+			       ((null TeX-file-recurse) 1)
+			       (t -1)))))
+	  directories))
+
+(defun TeX-search-files-1 (directory extensions nodir strip
+				     recursion-depth) 
+  (unless (eq recursion-depth 0)
+    (let* ((content (and directory
+			 (file-readable-p directory)
+			 (file-directory-p directory)
+			 (directory-files directory)))
+	   match)
+      (while content
+	(let ((file (concat directory (car content))))
+	  
+	  (setq content (cdr content))
+	  (cond ((string-match TeX-ignore-file file))
+		((not (file-readable-p file)))
+		((file-directory-p file)
+		 (setq match
+		       (nconc match
+			       (TeX-search-files-1 (concat file "/")
+						   extensions
+						   nodir strip
+						   (1- recursion-depth)))))
+		((TeX-match-extension file extensions)
+		 (setq match (cons (TeX-strip-extension file
+							extensions
+							nodir
+							(not strip))
+				   match))))))
+
+    match)))
 
 (defun TeX-car-string-lessp (a b)
   (string-lessp (car a) (car b)))
 			       t)
 	   (eq (match-end 0) pos)))))
 
+(defun TeX-current-line ()
+  "The current line number."
+  (count-lines (point-min) (point)))
+
 ;;; Syntax Table
 
 (defvar TeX-mode-syntax-table (make-syntax-table)
 			   (?\C-d "" "" t))
   "List of fonts used by TeX-font.
 
-Each entry is a list with three elements.  The first element is the
-key to active the font.  The second element is the string to insert
-before point, and the third element is the string to insert after
-point.  An optional fourth element means always replace if not nil."
+Each entry is a list.
+The first element is the key to activate the font.
+The second element is the string to insert before point, and the third
+element is the string to insert after point.
+If the fourth and fifth element are strings, they specify the prefix and
+suffix to be used in math mode.
+An optional fourth (or sixth) element means always replace if t."
   :group 'TeX-macro
-  :type '(repeat (group (character :tag "Key")
-			(string :tag "Prefix")
-			(string :tag "Suffix")
-			(option (sexp :format "Replace\n" 
-				      :value t)))))
+  :type '(repeat 
+	   (group 
+	    :value (?\C-a "" "")
+	    (character :tag "Key")
+	    (string :tag "Prefix")
+	    (string :tag "Suffix")
+	    (option (group
+		     :inline t
+		     (string :tag "Math Prefix")
+		     (string :tag "Math Suffix")))
+	    (option (sexp :format "Replace\n" :value t)))))
 
 (defvar TeX-font-replace-function 'TeX-font-replace
   "Determines the function which is called when a font should be replaced.")
 
 (defun TeX-describe-font-entry (entry)
   ;; A textual description of an ENTRY in TeX-font-list.
-  (concat (format "%8s\t" (key-description (char-to-string (nth 0 entry))))
-	  (if (nth 3 entry)
+  (concat (format "%16s  " (key-description (char-to-string (nth 0 entry))))
+	  (if (or (eq t (nth 3 entry)) (eq t (nth 5 entry)))
 	      "-- delete font"
-	    (format "%10s %s" (nth 1 entry) (nth 2 entry)))))
-  
+	    (format "%14s %-3s %14s %-3s"
+		    (nth 1 entry) (nth 2 entry)
+		    (if (stringp (nth 3 entry)) (nth 3 entry) "")
+		    (if (stringp (nth 4 entry)) (nth 4 entry) "")))))
+
 (defun TeX-font (replace what)
   "Insert template for font change command.
 If REPLACE is not nil, replace current font.  WHAT determines the font
 to use, as specified by TeX-font-list."
   (interactive "*P\nc")
   (TeX-update-style)
-  (let* ((entry (assoc what TeX-font-list)))
-    (setq replace (or replace (nth 3 entry)))
+  (let* ((entry (assoc what TeX-font-list))
+	 (in-math (texmathp))
+	 (before (nth 1 entry))
+	 (after (nth 2 entry)))
+    (setq replace (or replace (eq t (nth 3 entry)) (eq t (nth 5 entry))))
+    (if (and in-math (stringp (nth 3 entry)))
+	(setq before (nth 3 entry)
+	      after (nth 4 entry)))
     (cond ((null entry)
-	   (let ((help (concat "Font list:\n\n"
-			       (mapconcat 'TeX-describe-font-entry
-					  TeX-font-list "\n"))))
+	   (let ((help (concat 
+			"Font list:   "
+			"KEY        TEXTFONT           MATHFONT\n\n"
+			(mapconcat 'TeX-describe-font-entry
+				   TeX-font-list "\n"))))
 	     (with-output-to-temp-buffer "*Help*"
 	       (set-buffer "*Help*")
 	       (insert help))))
 	  (replace
-	   (funcall TeX-font-replace-function (nth 1 entry) (nth 2 entry)))
+	   (funcall TeX-font-replace-function before after))
 	  ((TeX-active-mark)
 	   (save-excursion
 	     (cond ((> (mark) (point))
-		    (insert (nth 1 entry))
+		    (insert before)
 		    (goto-char (mark))
-		    (insert (nth 2 entry)))
+		    (insert after))
 		   (t
-		    (insert (nth 2 entry))
+		    (insert after)
 		    (goto-char (mark))
-		    (insert (nth 1 entry))))))
+		    (insert before)))))
 	  (t
-	   (insert (nth 1 entry))
+	   (insert before)
 	   (save-excursion
-	     (insert (nth 2 entry)))))))
+	     (insert after))))))
 
 (defun TeX-font-replace (start end)
-  "Replace font specification around point with START and END."
+  "Replace font specification around point with START and END.
+For modes with font specifications like `{\\font text}'.
+See also `TeX-font-replace-macro' and `TeX-font-replace-function'."
   (save-excursion
     (while (not (looking-at "{\\\\[a-zA-Z]+ "))
       (up-list -1))
 	(delete-backward-char 1))
     (insert end)))
 
+(defun TeX-font-replace-macro (start end)
+  "Replace font specification around point with START and END.
+For modes with font specifications like `\\font{text}'.
+See also `TeX-font-replace' and `TeX-font-replace-function'."
+  (let ((font-list TeX-font-list)
+	cmds strings regexp)
+    (while font-list
+      (setq strings (cdr (car font-list))
+	    font-list (cdr font-list))
+      (and (stringp (car strings)) (null (string= (car strings) ""))
+	   (setq cmds (cons (car strings) cmds)))
+      (setq strings (cdr (cdr strings)))
+      (and (stringp (car strings)) (null (string= (car strings) ""))
+	   (setq cmds (cons (car strings) cmds))))
+    (setq regexp (mapconcat 'regexp-quote cmds "\\|"))
+    (save-excursion
+      (catch 'done
+	(while t
+	  (if (/= ?\\ (following-char))
+	      (skip-chars-backward "a-zA-Z "))
+	  (skip-chars-backward (regexp-quote TeX-esc))
+	  (if (looking-at regexp)
+	      (throw 'done t)
+	    (up-list -1))))
+      (forward-sexp 2)
+      (save-excursion
+	(replace-match start t t))
+      (delete-backward-char 1)
+      (insert end))))
+
 ;;; Dollars
 ;;
-;; Originally stolen from VorTeX.
-;; Copyright (C) 1986, 1987, 1988 Pehong Chen (phc@renoir.berkeley.edu)
-
+;; Rewritten from scratch with use of `texmathp' by 
+;; Carsten Dominik <dominik@strw.leidenuniv.nl>
+
+(defvar TeX-symbol-marker nil)
+
+(defvar TeX-symbol-marker-pos 0)
+
+;; The following constants are no longer used, but kept in case some
+;; foreign code uses any of them.
 (defvar TeX-dollar-sign ?$
-  "*Character user to enter and leaver math mode in TeX.")
-
+  "*Character used to enter and leave math mode in TeX.")
 (defconst TeX-dollar-string (char-to-string TeX-dollar-sign))
-
 (defconst TeX-dollar-regexp 
   (concat "^" (regexp-quote TeX-dollar-string) "\\|[^" TeX-esc "]"
 	  (regexp-quote TeX-dollar-string)))
-  
-(defvar TeX-dollar-list nil)
-  (make-variable-buffer-local 'TeX-match-dollar-on)
-
-(defvar TeX-par-start nil)
-  (make-variable-buffer-local 'TeX-par-start)
-
-(defvar TeX-par-end nil)
-  (make-variable-buffer-local 'TeX-par-end)
-
-(defvar TeX-symbol-marker nil)
-
-(defvar TeX-symbol-marker-pos 0)
-
-(defun TeX-bouncing-point (m)
-  (save-excursion
-    (if (pos-visible-in-window-p)
-	(sit-for 1)
-      (let* ((pos1 (point))
-             (pos2 (+ pos1 m))
-             (sym (buffer-substring pos1 pos2))
-             (msg1 (progn (beginning-of-line) (buffer-substring (point) pos1)))
-             (msg2 (progn (end-of-line) (buffer-substring pos2 (point)))))
-        (message "%s`%s'%s" msg1 sym msg2)))))
-
-(defun TeX-locate-delimiter (pos sym symlst)
-  (let ((marker nil)
-        (marker-pos 0)
-        (pair t)
-        (head nil))
-    (catch 'loop
-      (while symlst
-        (setq marker (car symlst))
-        (setq marker-pos (1- (marker-position marker)))
-        (if (and (/= pos marker-pos) (= (char-after marker-pos) sym))
-	    (if (> pos marker-pos)
-		(progn
-		  (setq TeX-symbol-marker-pos marker-pos)
-		  (setq TeX-symbol-marker marker) 
-		  (setq head (cons marker head))
-		  (setq pair (not pair)))
-	      (if pair (setq TeX-symbol-marker nil))
-	      (throw 'loop (append (reverse head)
-				   (cons (set-marker (make-marker) (1+ pos)) 
-					 symlst)))))
-        (setq symlst (cdr symlst)))
-      (if pair (setq TeX-symbol-marker nil))
-      (reverse (cons (set-marker (make-marker) (1+ pos)) head)))))
-
-(defun TeX-dollar-verify ()
-  ;; Verify if the current paragraph is the same as last.
-  ;; If so, do nothing, otherwise reset TeX-par-start and TeX-par-end and
-  ;; reconstruct the symbol-list.
-  (let ((start (save-excursion
-                 (if (re-search-backward paragraph-separate nil t)
-		     (point)
-                   1)))
-        (end (save-excursion
-               (if (re-search-forward paragraph-separate nil t)
-		   (1+ (point))
-                 (1+ (point-max)))))
-        (init nil))
-    (if (null TeX-par-start)
-	(setq TeX-par-start (set-marker (make-marker) 1)))
-    (if (/= (marker-position TeX-par-start) start)
-	(progn
-	  (set-marker TeX-par-start start)
-	  (setq init t)))
-    (if (null TeX-par-end)
-	(setq TeX-par-end (set-marker (make-marker) 1)))
-    (if (/= (marker-position TeX-par-end) end)
-	(progn
-	  (set-marker TeX-par-end end)
-	  (setq init t)))
-    (if init
-	(save-excursion
-	  (setq TeX-dollar-list nil)
-	  (goto-char start)
-	  (while (re-search-forward TeX-dollar-regexp end t)
-	    (setq TeX-dollar-list
-		  (append TeX-dollar-list
-			  (list (set-marker (make-marker)
-					    (if (= (following-char)
-						   TeX-dollar-sign)
-						(progn
-						  (forward-char 1)
-						  (point))
-					      (point)))))))))))
 
 (defun TeX-insert-dollar (&optional arg)
-  "Insert dollar sign.  
-
-Show matching dollar sign if this dollar sign end the TeX math mode.  
+  "Insert dollar sign.
+
+If current math mode was not entered with a dollar, refuse to insert one.
+Show matching dollar sign if this dollar sign ends the TeX math mode.  
 Ensure double dollar signs match up correctly by inserting extra
 dollar signs when needed.
 
+With raw C-u prefix, insert exactly one dollar sign.
 With optional ARG, insert that many dollar signs."
   (interactive "P")
-  (if arg
-      (let ((count (prefix-numeric-value arg)))
-	(if (listp arg)
-	    (self-insert-command 1)	;C-u always inserts just one
-	  (self-insert-command count)))
-    (let ((pc (preceding-char))
-	  (pos (point))
-	  (pt (point))
-	  (single t))
-      (TeX-dollar-verify)
-      (if (= pc (string-to-char TeX-esc))
-	  (insert TeX-dollar-sign)
-	(if (and (= pc TeX-dollar-sign)
-		  (/= (char-after (- (point) 2)) (string-to-char TeX-esc)))
-	    (progn
-	      (setq single nil)
-	      (if (and (> pos 2) (= (char-after (- pos 2)) TeX-dollar-sign))
-		  (setq pt (1- pos))	; Doesn't echo 3rd $, if $$ already
-		(backward-char 1) 
-		(insert TeX-dollar-sign)
-		(goto-char (1+ pos))))
-	  (insert TeX-dollar-sign))
-	(setq TeX-dollar-list
-	      (TeX-locate-delimiter pt TeX-dollar-sign TeX-dollar-list))
-	(if TeX-symbol-marker
-	    (save-excursion
-	      (goto-char TeX-symbol-marker-pos)
-	      (if (and (= (preceding-char) TeX-dollar-sign)
-		       (/= (char-after (- (point) 2)) TeX-dollar-sign))
-		  (progn
-		    (backward-char 1)
-		    (if single
-			(save-excursion
-			  (goto-char pos)
-			  (insert TeX-dollar-sign))))	; $$foo$`$'
-		(if (not single)
-		    (progn
-		      (insert TeX-dollar-sign) ; `$'$foo$$
-		      (backward-char 1))))
-	      (TeX-bouncing-point (if single 1 2))))))))
+  (cond
+   ((and arg (listp arg))
+    ;; C-u always inserts one
+    (insert "$"))
+   (arg
+    ;; Numerical arg inserts that many
+    (insert (make-string (prefix-numeric-value arg) ?\$)))
+   ((TeX-point-is-escaped)
+    ;; This is escaped with `\', so just insert one.
+    (insert "$"))
+   ((texmathp)
+    ;; We are inside math mode
+    (if (and (stringp (car texmathp-why))
+	     (string-equal (substring (car texmathp-why) 0 1) "\$"))
+	;; Math mode was turned on with $ or $$ - so finish it accordingly.
+	(progn
+	  (insert (car texmathp-why))
+	  (save-excursion
+	    (goto-c