1992-05-30 20:24:49 +00:00
|
|
|
|
;;; tex-mode.el --- TeX, LaTeX, and SliTeX mode commands.
|
|
|
|
|
|
1997-04-13 07:28:48 +00:00
|
|
|
|
;; Copyright (C) 1985, 86, 89, 92, 94, 95, 96, 1997
|
|
|
|
|
;; Free Software Foundation, Inc.
|
1992-07-22 02:58:21 +00:00
|
|
|
|
|
1994-12-22 22:05:52 +00:00
|
|
|
|
;; Maintainer: FSF
|
1992-07-17 20:24:00 +00:00
|
|
|
|
;; Keywords: tex
|
1992-07-16 21:47:34 +00:00
|
|
|
|
|
1992-07-04 16:51:02 +00:00
|
|
|
|
;; Contributions over the years by William F. Schelter, Dick King,
|
1994-12-22 22:05:52 +00:00
|
|
|
|
;; Stephen Gildea, Michael Prange, Jacob Gore, and Edward M. Reingold.
|
1992-07-04 16:51:02 +00:00
|
|
|
|
|
1990-08-28 08:01:56 +00:00
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
1992-07-16 21:47:34 +00:00
|
|
|
|
;; the Free Software Foundation; either version 2, or (at your option)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
;; any later version.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
1996-01-26 19:57:45 +00:00
|
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
|
|
|
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
;; Boston, MA 02111-1307, USA.
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1992-07-16 21:47:34 +00:00
|
|
|
|
;;; Code:
|
|
|
|
|
|
1994-04-01 16:57:56 +00:00
|
|
|
|
(require 'shell)
|
1993-04-25 06:14:10 +00:00
|
|
|
|
(require 'compile)
|
1992-07-04 16:51:02 +00:00
|
|
|
|
|
1997-04-13 07:28:48 +00:00
|
|
|
|
(defgroup tex-file nil
|
|
|
|
|
"TeX files and directories"
|
|
|
|
|
:prefix "tex-"
|
|
|
|
|
:group 'tex)
|
|
|
|
|
|
|
|
|
|
(defgroup tex-run nil
|
|
|
|
|
"Running external commands from TeX mode"
|
|
|
|
|
:prefix "tex-"
|
|
|
|
|
:group 'tex)
|
|
|
|
|
|
|
|
|
|
(defgroup tex-view nil
|
|
|
|
|
"Viewing and printing TeX files"
|
|
|
|
|
:prefix "tex-"
|
|
|
|
|
:group 'tex)
|
|
|
|
|
|
1992-08-12 12:50:10 +00:00
|
|
|
|
;;;###autoload
|
1997-04-13 07:28:48 +00:00
|
|
|
|
(defcustom tex-shell-file-name nil
|
|
|
|
|
"*If non-nil, the shell file name to run in the subshell used to run TeX."
|
|
|
|
|
:type '(choice (const :tag "None" nil)
|
|
|
|
|
string)
|
|
|
|
|
:group 'tex-run)
|
1992-07-04 16:51:02 +00:00
|
|
|
|
|
1992-08-12 12:50:10 +00:00
|
|
|
|
;;;###autoload
|
1997-04-13 07:28:48 +00:00
|
|
|
|
(defcustom tex-directory "."
|
1996-08-25 01:25:07 +00:00
|
|
|
|
"*Directory in which temporary files are written.
|
1994-05-02 22:26:50 +00:00
|
|
|
|
You can make this `/tmp' if your TEXINPUTS has no relative directories in it
|
1992-07-04 16:51:02 +00:00
|
|
|
|
and you don't try to apply \\[tex-region] or \\[tex-buffer] when there are
|
1997-04-13 07:28:48 +00:00
|
|
|
|
`\\input' commands with relative directories."
|
|
|
|
|
:type 'directory
|
|
|
|
|
:group 'tex-file)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1996-12-29 19:41:52 +00:00
|
|
|
|
;;;###autoload
|
1997-04-13 07:28:48 +00:00
|
|
|
|
(defcustom tex-first-line-header-regexp nil
|
1996-12-29 19:41:52 +00:00
|
|
|
|
"Regexp for matching a first line which `tex-region' should include.
|
|
|
|
|
If this is non-nil, it should be a regular expression string;
|
|
|
|
|
if it matches the first line of the file,
|
1997-04-13 07:28:48 +00:00
|
|
|
|
`tex-region' always includes the first line in the TeX run."
|
|
|
|
|
:type '(choice (const :tag "None" nil)
|
|
|
|
|
regexp)
|
|
|
|
|
:group 'tex-file)
|
1996-12-29 19:41:52 +00:00
|
|
|
|
|
1996-08-25 01:25:07 +00:00
|
|
|
|
;;;###autoload
|
1997-04-13 07:28:48 +00:00
|
|
|
|
(defcustom tex-main-file nil
|
1996-08-25 01:25:07 +00:00
|
|
|
|
"*The main TeX source file which includes this buffer's file.
|
1997-04-13 07:28:48 +00:00
|
|
|
|
The command `tex-buffer' runs TeX on `tex-main-file'if that is non-nil."
|
|
|
|
|
:type '(choice (const :tag "None" nil)
|
|
|
|
|
file)
|
|
|
|
|
:group 'tex-file)
|
1996-08-25 01:25:07 +00:00
|
|
|
|
|
1992-08-12 12:50:10 +00:00
|
|
|
|
;;;###autoload
|
1997-04-13 07:28:48 +00:00
|
|
|
|
(defcustom tex-offer-save t
|
|
|
|
|
"*If non-nil, ask about saving modified buffers before \\[tex-file] is run."
|
|
|
|
|
:type 'boolean
|
|
|
|
|
:group 'tex-file)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1992-08-12 12:50:10 +00:00
|
|
|
|
;;;###autoload
|
1997-04-13 07:28:48 +00:00
|
|
|
|
(defcustom tex-run-command "tex"
|
1990-08-28 08:01:56 +00:00
|
|
|
|
"*Command used to run TeX subjob.
|
1994-05-02 22:26:50 +00:00
|
|
|
|
If this string contains an asterisk (`*'), that is replaced by the file name;
|
1997-04-13 07:28:48 +00:00
|
|
|
|
otherwise, the file name, preceded by blank, is added at the end."
|
|
|
|
|
:type 'string
|
|
|
|
|
:group 'tex-run)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1992-08-12 12:50:10 +00:00
|
|
|
|
;;;###autoload
|
1997-04-13 07:28:48 +00:00
|
|
|
|
(defcustom latex-run-command "latex"
|
1990-08-28 08:01:56 +00:00
|
|
|
|
"*Command used to run LaTeX subjob.
|
1994-05-02 22:26:50 +00:00
|
|
|
|
If this string contains an asterisk (`*'), that is replaced by the file name;
|
1997-04-13 07:28:48 +00:00
|
|
|
|
otherwise, the file name, preceded by blank, is added at the end."
|
|
|
|
|
:type 'string
|
|
|
|
|
:group 'tex-run)
|
1992-07-04 16:51:02 +00:00
|
|
|
|
|
|
|
|
|
(defvar standard-latex-block-names
|
|
|
|
|
'("abstract" "array" "center" "description"
|
|
|
|
|
"displaymath" "document" "enumerate" "eqnarray"
|
|
|
|
|
"eqnarray*" "equation" "figure" "figure*"
|
|
|
|
|
"flushleft" "flushright" "itemize" "letter"
|
|
|
|
|
"list" "minipage" "picture" "quotation"
|
|
|
|
|
"quote" "slide" "sloppypar" "tabbing"
|
|
|
|
|
"table" "table*" "tabular" "tabular*"
|
|
|
|
|
"thebibliography" "theindex*" "titlepage" "trivlist"
|
|
|
|
|
"verbatim" "verbatim*" "verse")
|
|
|
|
|
"Standard LaTeX block names.")
|
|
|
|
|
|
1992-08-12 12:50:10 +00:00
|
|
|
|
;;;###autoload
|
1997-04-13 07:28:48 +00:00
|
|
|
|
(defcustom latex-block-names nil
|
1992-07-04 16:51:02 +00:00
|
|
|
|
"*User defined LaTeX block names.
|
1997-04-13 07:28:48 +00:00
|
|
|
|
Combined with `standard-latex-block-names' for minibuffer completion."
|
|
|
|
|
:type '(repeat string)
|
|
|
|
|
:group 'tex-run)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1992-08-12 12:50:10 +00:00
|
|
|
|
;;;###autoload
|
1997-04-13 07:28:48 +00:00
|
|
|
|
(defcustom slitex-run-command "slitex"
|
1990-08-28 08:01:56 +00:00
|
|
|
|
"*Command used to run SliTeX subjob.
|
1994-05-02 22:26:50 +00:00
|
|
|
|
If this string contains an asterisk (`*'), that is replaced by the file name;
|
1997-04-13 07:28:48 +00:00
|
|
|
|
otherwise, the file name, preceded by blank, is added at the end."
|
|
|
|
|
:type 'string
|
|
|
|
|
:group 'tex-run)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1992-08-12 12:50:10 +00:00
|
|
|
|
;;;###autoload
|
1997-04-13 07:28:48 +00:00
|
|
|
|
(defcustom tex-bibtex-command "bibtex"
|
1992-07-04 16:51:02 +00:00
|
|
|
|
"*Command used by `tex-bibtex-file' to gather bibliographic data.
|
1994-05-02 22:26:50 +00:00
|
|
|
|
If this string contains an asterisk (`*'), that is replaced by the file name;
|
1997-04-13 07:28:48 +00:00
|
|
|
|
otherwise, the file name, preceded by blank, is added at the end."
|
|
|
|
|
:type 'string
|
|
|
|
|
:group 'tex-run)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1992-08-12 12:50:10 +00:00
|
|
|
|
;;;###autoload
|
1997-04-13 07:28:48 +00:00
|
|
|
|
(defcustom tex-dvi-print-command "lpr -d"
|
1992-07-04 16:51:02 +00:00
|
|
|
|
"*Command used by \\[tex-print] to print a .dvi file.
|
1994-05-02 22:26:50 +00:00
|
|
|
|
If this string contains an asterisk (`*'), that is replaced by the file name;
|
1997-04-13 07:28:48 +00:00
|
|
|
|
otherwise, the file name, preceded by blank, is added at the end."
|
|
|
|
|
:type 'string
|
|
|
|
|
:group 'tex-view)
|
1992-07-04 16:51:02 +00:00
|
|
|
|
|
1992-08-12 12:50:10 +00:00
|
|
|
|
;;;###autoload
|
1997-04-13 07:28:48 +00:00
|
|
|
|
(defcustom tex-alt-dvi-print-command "lpr -d"
|
1992-07-04 16:51:02 +00:00
|
|
|
|
"*Command used by \\[tex-print] with a prefix arg to print a .dvi file.
|
1994-05-02 22:26:50 +00:00
|
|
|
|
If this string contains an asterisk (`*'), that is replaced by the file name;
|
|
|
|
|
otherwise, the file name, preceded by blank, is added at the end.
|
1992-07-04 16:51:02 +00:00
|
|
|
|
|
1994-05-02 22:26:50 +00:00
|
|
|
|
If two printers are not enough of a choice, you can set the variable
|
|
|
|
|
`tex-alt-dvi-print-command' to an expression that asks what you want;
|
1992-07-04 16:51:02 +00:00
|
|
|
|
for example,
|
|
|
|
|
|
|
|
|
|
(setq tex-alt-dvi-print-command
|
|
|
|
|
'(format \"lpr -P%s\" (read-string \"Use printer: \")))
|
|
|
|
|
|
|
|
|
|
would tell \\[tex-print] with a prefix argument to ask you which printer to
|
1997-04-13 07:28:48 +00:00
|
|
|
|
use."
|
|
|
|
|
:type '(choice (string :tag "Command")
|
|
|
|
|
(sexp :tag "Expression"))
|
|
|
|
|
:group 'tex-view)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1992-08-12 12:50:10 +00:00
|
|
|
|
;;;###autoload
|
1997-04-13 07:28:48 +00:00
|
|
|
|
(defcustom tex-dvi-view-command nil
|
1994-05-02 22:26:50 +00:00
|
|
|
|
"*Command used by \\[tex-view] to display a `.dvi' file.
|
|
|
|
|
If this string contains an asterisk (`*'), that is replaced by the file name;
|
|
|
|
|
otherwise, the file name, preceded by blank, is added at the end.
|
1992-07-04 16:51:02 +00:00
|
|
|
|
|
|
|
|
|
This can be set conditionally so that the previewer used is suitable for the
|
|
|
|
|
window system being used. For example,
|
|
|
|
|
|
|
|
|
|
(setq tex-dvi-view-command
|
|
|
|
|
(if (eq window-system 'x) \"xdvi\" \"dvi2tty * | cat -s\"))
|
|
|
|
|
|
1994-05-02 22:26:50 +00:00
|
|
|
|
would tell \\[tex-view] to use xdvi under X windows and to use dvi2tty
|
1997-04-13 07:28:48 +00:00
|
|
|
|
otherwise."
|
|
|
|
|
:type '(choice (const nil) string)
|
|
|
|
|
:group 'tex-view)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1992-08-12 12:50:10 +00:00
|
|
|
|
;;;###autoload
|
1997-04-13 07:28:48 +00:00
|
|
|
|
(defcustom tex-show-queue-command "lpq"
|
1992-07-04 16:51:02 +00:00
|
|
|
|
"*Command used by \\[tex-show-print-queue] to show the print queue.
|
1997-04-13 07:28:48 +00:00
|
|
|
|
Should show the queue(s) that \\[tex-print] puts jobs on."
|
|
|
|
|
:type 'string
|
|
|
|
|
:group 'tex-view)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1992-08-12 12:50:10 +00:00
|
|
|
|
;;;###autoload
|
1997-04-13 07:28:48 +00:00
|
|
|
|
(defcustom tex-default-mode 'plain-tex-mode
|
1990-08-28 08:01:56 +00:00
|
|
|
|
"*Mode to enter for a new file that might be either TeX or LaTeX.
|
|
|
|
|
This variable is used when it can't be determined whether the file
|
|
|
|
|
is plain TeX or LaTeX or what because the file contains no commands.
|
1997-04-13 07:28:48 +00:00
|
|
|
|
Normally set to either `plain-tex-mode' or `latex-mode'."
|
|
|
|
|
:type 'function
|
|
|
|
|
:group 'tex)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1992-08-12 12:50:10 +00:00
|
|
|
|
;;;###autoload
|
1997-04-13 07:28:48 +00:00
|
|
|
|
(defcustom tex-open-quote "``"
|
|
|
|
|
"*String inserted by typing \\[tex-insert-quote] to open a quotation."
|
|
|
|
|
:type 'string
|
|
|
|
|
:group 'tex)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1992-08-12 12:50:10 +00:00
|
|
|
|
;;;###autoload
|
1997-04-13 07:28:48 +00:00
|
|
|
|
(defcustom tex-close-quote "''"
|
|
|
|
|
"*String inserted by typing \\[tex-insert-quote] to close a quotation."
|
|
|
|
|
:type 'string
|
|
|
|
|
:group 'tex)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(defvar tex-last-temp-file nil
|
|
|
|
|
"Latest temporary file generated by \\[tex-region] and \\[tex-buffer].
|
|
|
|
|
Deleted when the \\[tex-region] or \\[tex-buffer] is next run, or when the
|
1994-05-02 22:26:50 +00:00
|
|
|
|
tex shell terminates.")
|
1992-07-04 16:51:02 +00:00
|
|
|
|
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(defvar tex-command nil
|
|
|
|
|
"Command to run TeX.
|
1992-07-04 16:51:02 +00:00
|
|
|
|
The name of the file, preceded by a blank, will be added to this string.")
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
|
|
|
|
(defvar tex-trailer nil
|
|
|
|
|
"String appended after the end of a region sent to TeX by \\[tex-region].")
|
|
|
|
|
|
|
|
|
|
(defvar tex-start-of-header nil
|
1995-10-19 00:48:12 +00:00
|
|
|
|
"Regular expression used by \\[tex-region] to find start of file's header.")
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
|
|
|
|
(defvar tex-end-of-header nil
|
1995-10-19 00:48:12 +00:00
|
|
|
|
"Regular expression used by \\[tex-region] to find end of file's header.")
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
|
|
|
|
(defvar tex-shell-cd-command "cd"
|
|
|
|
|
"Command to give to shell running TeX to change directory.
|
1994-05-02 22:26:50 +00:00
|
|
|
|
The value of `tex-directory' is appended to this, separated by a space.")
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
|
|
|
|
(defvar tex-zap-file nil
|
|
|
|
|
"Temporary file name used for text being sent as input to TeX.
|
|
|
|
|
Should be a simple file name with no extension or directory specification.")
|
|
|
|
|
|
|
|
|
|
(defvar tex-last-buffer-texed nil
|
|
|
|
|
"Buffer which was last TeXed.")
|
|
|
|
|
|
|
|
|
|
(defvar tex-print-file nil
|
|
|
|
|
"File name that \\[tex-print] prints.
|
|
|
|
|
Set by \\[tex-region], \\[tex-buffer], and \\[tex-file].")
|
|
|
|
|
|
|
|
|
|
(defvar tex-mode-syntax-table nil
|
|
|
|
|
"Syntax table used while in TeX mode.")
|
|
|
|
|
|
1997-06-23 00:30:48 +00:00
|
|
|
|
(defcustom latex-imenu-indent-string "."
|
|
|
|
|
"*String to add repeated in front of nested sectional units for Imenu.
|
|
|
|
|
An alternative value is \" . \", if you use a font with a narrow period."
|
|
|
|
|
:type 'string
|
|
|
|
|
:group 'tex)
|
|
|
|
|
|
1996-05-15 15:17:41 +00:00
|
|
|
|
(defun latex-imenu-create-index ()
|
|
|
|
|
"Generates an alist for imenu from a LaTeX buffer."
|
1997-06-23 00:30:48 +00:00
|
|
|
|
(let (i0 menu case-fold-search)
|
|
|
|
|
(save-excursion
|
|
|
|
|
;; Find the top-most level in this file but don't allow it to be
|
|
|
|
|
;; any deeper than "section" (which is top-level in an article).
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(if (search-forward-regexp "\\\\part\\*?[ \t]*{" nil t)
|
|
|
|
|
(setq i0 0)
|
|
|
|
|
(if (search-forward-regexp "\\\\chapter\\*?[ \t]*{" nil t)
|
|
|
|
|
(setq i0 1)
|
|
|
|
|
(setq i0 2)))
|
|
|
|
|
|
|
|
|
|
;; Look for chapters and sections.
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(while (search-forward-regexp
|
|
|
|
|
"\\\\\\(part\\|chapter\\|section\\|subsection\\|\
|
|
|
|
|
subsubsection\\|paragraph\\|subparagraph\\)\\*?[ \t]*{" nil t)
|
|
|
|
|
(let ((start (match-beginning 0))
|
|
|
|
|
(here (point))
|
|
|
|
|
(i (cdr (assoc (buffer-substring-no-properties
|
|
|
|
|
(match-beginning 1)
|
|
|
|
|
(match-end 1))
|
|
|
|
|
'(("part" . 0) ("chapter" . 1)
|
|
|
|
|
("section" . 2) ("subsection" . 3)
|
|
|
|
|
("subsubsection" . 4)
|
|
|
|
|
("paragraph" . 5) ("subparagraph" . 6))))))
|
|
|
|
|
(backward-char 1)
|
|
|
|
|
(condition-case err
|
|
|
|
|
(progn
|
|
|
|
|
;; Using sexps allows some use of matching {...} inside
|
|
|
|
|
;; titles.
|
|
|
|
|
(forward-sexp 1)
|
|
|
|
|
(setq menu
|
|
|
|
|
(cons (cons (concat (apply 'concat
|
|
|
|
|
(make-list
|
|
|
|
|
(max 0 (- i i0))
|
|
|
|
|
latex-imenu-indent-string))
|
|
|
|
|
(buffer-substring-no-properties
|
|
|
|
|
here (1- (point))))
|
|
|
|
|
start)
|
|
|
|
|
menu))
|
|
|
|
|
)
|
|
|
|
|
(error nil))))
|
|
|
|
|
|
|
|
|
|
;; Look for included material.
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(while (search-forward-regexp
|
|
|
|
|
"\\\\\\(include\\|input\\|verbatiminput\\|bibliography\\)\
|
|
|
|
|
[ \t]*{\\([^}\n]+\\)}"
|
|
|
|
|
nil t)
|
|
|
|
|
(setq menu
|
|
|
|
|
(cons (cons (concat "<<" (buffer-substring-no-properties
|
|
|
|
|
(match-beginning 2)
|
|
|
|
|
(match-end 2))
|
|
|
|
|
(if (= (char-after (match-beginning 1)) ?b)
|
|
|
|
|
".bbl"
|
|
|
|
|
".tex"))
|
|
|
|
|
(match-beginning 0))
|
|
|
|
|
menu)))
|
|
|
|
|
|
|
|
|
|
;; Look for \frontmatter, \mainmatter, \backmatter, and \appendix.
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(while (search-forward-regexp
|
|
|
|
|
"\\\\\\(frontmatter\\|mainmatter\\|backmatter\\|appendix\\)\\b"
|
|
|
|
|
nil t)
|
|
|
|
|
(setq menu
|
|
|
|
|
(cons (cons "--" (match-beginning 0))
|
|
|
|
|
menu)))
|
|
|
|
|
|
|
|
|
|
;; Sort in increasing buffer position order.
|
|
|
|
|
(sort menu (function (lambda (a b) (< (cdr a) (cdr b))))))))
|
1995-07-28 00:26:37 +00:00
|
|
|
|
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(defun tex-define-common-keys (keymap)
|
1994-05-02 22:26:50 +00:00
|
|
|
|
"Define the keys that we want defined both in TeX mode and in the TeX shell."
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(define-key keymap "\C-c\C-k" 'tex-kill-job)
|
|
|
|
|
(define-key keymap "\C-c\C-l" 'tex-recenter-output-buffer)
|
|
|
|
|
(define-key keymap "\C-c\C-q" 'tex-show-print-queue)
|
|
|
|
|
(define-key keymap "\C-c\C-p" 'tex-print)
|
|
|
|
|
(define-key keymap "\C-c\C-v" 'tex-view)
|
1993-10-27 21:33:12 +00:00
|
|
|
|
|
|
|
|
|
(define-key keymap [menu-bar tex] (cons "TeX" (make-sparse-keymap "TeX")))
|
|
|
|
|
|
|
|
|
|
(define-key keymap [menu-bar tex tex-kill-job] '("Tex Kill" . tex-kill-job))
|
1993-11-06 05:56:11 +00:00
|
|
|
|
(define-key keymap [menu-bar tex tex-recenter-output-buffer]
|
|
|
|
|
'("Tex Recenter" . tex-recenter-output-buffer))
|
1993-10-27 21:33:12 +00:00
|
|
|
|
(define-key keymap [menu-bar tex tex-show-print-queue]
|
|
|
|
|
'("Show Print Queue" . tex-show-print-queue))
|
1993-11-06 05:56:11 +00:00
|
|
|
|
(define-key keymap [menu-bar tex tex-alt-print]
|
|
|
|
|
'("Tex Print (alt printer)" . tex-alt-print))
|
1993-10-27 21:33:12 +00:00
|
|
|
|
(define-key keymap [menu-bar tex tex-print] '("Tex Print" . tex-print))
|
1993-11-06 05:56:11 +00:00
|
|
|
|
(define-key keymap [menu-bar tex tex-view] '("Tex View" . tex-view))
|
1990-08-28 08:01:56 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
(defvar tex-mode-map nil "Keymap for TeX mode.")
|
|
|
|
|
|
|
|
|
|
(if tex-mode-map
|
|
|
|
|
nil
|
|
|
|
|
(setq tex-mode-map (make-sparse-keymap))
|
|
|
|
|
(tex-define-common-keys tex-mode-map)
|
|
|
|
|
(define-key tex-mode-map "\"" 'tex-insert-quote)
|
|
|
|
|
(define-key tex-mode-map "\n" 'tex-terminate-paragraph)
|
|
|
|
|
(define-key tex-mode-map "\C-c}" 'up-list)
|
|
|
|
|
(define-key tex-mode-map "\C-c{" 'tex-insert-braces)
|
|
|
|
|
(define-key tex-mode-map "\C-c\C-r" 'tex-region)
|
|
|
|
|
(define-key tex-mode-map "\C-c\C-b" 'tex-buffer)
|
|
|
|
|
(define-key tex-mode-map "\C-c\C-f" 'tex-file)
|
|
|
|
|
(define-key tex-mode-map "\C-c\C-i" 'tex-bibtex-file)
|
|
|
|
|
(define-key tex-mode-map "\C-c\C-o" 'tex-latex-block)
|
1993-11-06 05:56:11 +00:00
|
|
|
|
(define-key tex-mode-map "\C-c\C-e" 'tex-close-latex-block)
|
1994-05-03 21:15:27 +00:00
|
|
|
|
(define-key tex-mode-map "\C-c\C-u" 'tex-goto-last-unclosed-latex-block)
|
1994-12-30 23:02:43 +00:00
|
|
|
|
(define-key tex-mode-map [menu-bar tex tex-bibtex-file]
|
|
|
|
|
'("BibTeX File" . tex-bibtex-file))
|
1993-11-06 05:56:11 +00:00
|
|
|
|
(define-key tex-mode-map [menu-bar tex tex-validate-region]
|
|
|
|
|
'("Validate Region" . tex-validate-region))
|
|
|
|
|
(define-key tex-mode-map [menu-bar tex validate-tex-buffer]
|
|
|
|
|
'("Validate Buffer" . validate-tex-buffer))
|
|
|
|
|
(define-key tex-mode-map [menu-bar tex tex-region]
|
1994-12-30 23:02:43 +00:00
|
|
|
|
'("TeX Region" . tex-region))
|
1993-11-06 05:56:11 +00:00
|
|
|
|
(define-key tex-mode-map [menu-bar tex tex-buffer]
|
1994-12-30 23:02:43 +00:00
|
|
|
|
'("TeX Buffer" . tex-buffer))
|
|
|
|
|
(define-key tex-mode-map [menu-bar tex tex-file] '("TeX File" . tex-file)))
|
1993-11-06 05:56:11 +00:00
|
|
|
|
|
|
|
|
|
(put 'tex-region 'menu-enable 'mark-active)
|
|
|
|
|
(put 'tex-validate-region 'menu-enable 'mark-active)
|
|
|
|
|
(put 'tex-print 'menu-enable '(stringp tex-print-file))
|
|
|
|
|
(put 'tex-alt-print 'menu-enable '(stringp tex-print-file))
|
|
|
|
|
(put 'tex-view 'menu-enable '(stringp tex-print-file))
|
|
|
|
|
(put 'tex-recenter-output-buffer 'menu-enable '(get-buffer "*tex-shell*"))
|
|
|
|
|
(put 'tex-kill-job 'menu-enable '(tex-shell-running))
|
|
|
|
|
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
|
|
|
|
(defvar tex-shell-map nil
|
1994-05-02 22:26:50 +00:00
|
|
|
|
"Keymap for the TeX shell.
|
1994-12-21 15:54:30 +00:00
|
|
|
|
Inherits `shell-mode-map' with a few additions.")
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1996-01-26 19:57:45 +00:00
|
|
|
|
(defvar tex-face-alist
|
|
|
|
|
'((bold . "{\\bf ")
|
|
|
|
|
(italic . "{\\it ")
|
|
|
|
|
(bold-italic . "{\\bi ") ; hypothetical
|
|
|
|
|
(underline . "\\underline{")
|
|
|
|
|
(default . "{\\rm "))
|
|
|
|
|
"Alist of face and TeX font name for facemenu.")
|
|
|
|
|
|
|
|
|
|
(defvar tex-latex-face-alist
|
|
|
|
|
`((italic . "{\\em ")
|
|
|
|
|
,@tex-face-alist)
|
|
|
|
|
"Alist of face and LaTeX font name for facemenu.")
|
|
|
|
|
|
|
|
|
|
|
1994-10-11 18:51:29 +00:00
|
|
|
|
(defvar compare-windows-whitespace) ; Pacify the byte-compiler
|
1993-04-26 05:15:08 +00:00
|
|
|
|
|
1990-08-28 08:01:56 +00:00
|
|
|
|
;;; This would be a lot simpler if we just used a regexp search,
|
|
|
|
|
;;; but then it would be too slow.
|
1991-05-09 21:50:34 +00:00
|
|
|
|
;;;###autoload
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(defun tex-mode ()
|
|
|
|
|
"Major mode for editing files of input for TeX, LaTeX, or SliTeX.
|
|
|
|
|
Tries to determine (by looking at the beginning of the file) whether
|
1994-05-02 22:26:50 +00:00
|
|
|
|
this file is for plain TeX, LaTeX, or SliTeX and calls `plain-tex-mode',
|
|
|
|
|
`latex-mode', or `slitex-mode', respectively. If it cannot be determined,
|
|
|
|
|
such as if there are no commands in the file, the value of `tex-default-mode'
|
|
|
|
|
says which mode to use."
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(let (mode slash comment)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(while (and (setq slash (search-forward "\\" nil t))
|
|
|
|
|
(setq comment (let ((search-end (point)))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(search-forward "%" search-end t))))))
|
|
|
|
|
(if (and slash (not comment))
|
1995-01-03 22:28:50 +00:00
|
|
|
|
(setq mode (if (looking-at "documentstyle\\|documentclass\\|begin\\b\\|NeedsTeXFormat{LaTeX")
|
1994-08-17 20:30:22 +00:00
|
|
|
|
(if (looking-at
|
|
|
|
|
"document\\(style\\|class\\)\\(\\[.*\\]\\)?{slides}")
|
1990-08-28 08:01:56 +00:00
|
|
|
|
'slitex-mode
|
|
|
|
|
'latex-mode)
|
|
|
|
|
'plain-tex-mode))))
|
|
|
|
|
(if mode (funcall mode)
|
|
|
|
|
(funcall tex-default-mode))))
|
1993-04-28 17:08:14 +00:00
|
|
|
|
|
1991-05-13 22:05:14 +00:00
|
|
|
|
;;;###autoload
|
1993-04-23 06:51:44 +00:00
|
|
|
|
(defalias 'TeX-mode 'tex-mode)
|
1991-05-13 22:05:14 +00:00
|
|
|
|
;;;###autoload
|
1993-04-23 06:51:44 +00:00
|
|
|
|
(defalias 'LaTeX-mode 'latex-mode)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1991-05-09 21:50:34 +00:00
|
|
|
|
;;;###autoload
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(defun plain-tex-mode ()
|
|
|
|
|
"Major mode for editing files of input for plain TeX.
|
|
|
|
|
Makes $ and } display the characters they match.
|
|
|
|
|
Makes \" insert `` when it seems to be the beginning of a quotation,
|
|
|
|
|
and '' when it appears to be the end; it inserts \" only after a \\.
|
|
|
|
|
|
|
|
|
|
Use \\[tex-region] to run TeX on the current region, plus a \"header\"
|
|
|
|
|
copied from the top of the file (containing macro definitions, etc.),
|
|
|
|
|
running TeX under a special subshell. \\[tex-buffer] does the whole buffer.
|
|
|
|
|
\\[tex-file] saves the buffer and then processes the file.
|
|
|
|
|
\\[tex-print] prints the .dvi file made by any of these.
|
|
|
|
|
\\[tex-view] previews the .dvi file made by any of these.
|
|
|
|
|
\\[tex-bibtex-file] runs bibtex on the file of the current buffer.
|
|
|
|
|
|
|
|
|
|
Use \\[validate-tex-buffer] to check buffer for paragraphs containing
|
|
|
|
|
mismatched $'s or braces.
|
|
|
|
|
|
|
|
|
|
Special commands:
|
|
|
|
|
\\{tex-mode-map}
|
|
|
|
|
|
|
|
|
|
Mode variables:
|
|
|
|
|
tex-run-command
|
|
|
|
|
Command string used by \\[tex-region] or \\[tex-buffer].
|
|
|
|
|
tex-directory
|
|
|
|
|
Directory in which to create temporary files for TeX jobs
|
|
|
|
|
run by \\[tex-region] or \\[tex-buffer].
|
|
|
|
|
tex-dvi-print-command
|
|
|
|
|
Command string used by \\[tex-print] to print a .dvi file.
|
1992-07-04 16:51:02 +00:00
|
|
|
|
tex-alt-dvi-print-command
|
|
|
|
|
Alternative command string used by \\[tex-print] (when given a prefix
|
|
|
|
|
argument) to print a .dvi file.
|
1990-08-28 08:01:56 +00:00
|
|
|
|
tex-dvi-view-command
|
|
|
|
|
Command string used by \\[tex-view] to preview a .dvi file.
|
|
|
|
|
tex-show-queue-command
|
|
|
|
|
Command string used by \\[tex-show-print-queue] to show the print
|
|
|
|
|
queue that \\[tex-print] put your job on.
|
|
|
|
|
|
1994-05-02 22:26:50 +00:00
|
|
|
|
Entering Plain-tex mode runs the hook `text-mode-hook', then the hook
|
|
|
|
|
`tex-mode-hook', and finally the hook `plain-tex-mode-hook'. When the
|
|
|
|
|
special subshell is initiated, the hook `tex-shell-hook' is run."
|
1993-04-26 05:15:08 +00:00
|
|
|
|
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(tex-common-initialization)
|
|
|
|
|
(setq mode-name "TeX")
|
|
|
|
|
(setq major-mode 'plain-tex-mode)
|
|
|
|
|
(setq tex-command tex-run-command)
|
1995-10-19 00:48:12 +00:00
|
|
|
|
(setq tex-start-of-header "%\\*\\*start of header")
|
|
|
|
|
(setq tex-end-of-header "%\\*\\*end of header")
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(setq tex-trailer "\\bye\n")
|
|
|
|
|
(run-hooks 'text-mode-hook 'tex-mode-hook 'plain-tex-mode-hook))
|
1991-05-13 22:05:14 +00:00
|
|
|
|
;;;###autoload
|
1993-04-23 06:51:44 +00:00
|
|
|
|
(defalias 'plain-TeX-mode 'plain-tex-mode)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1991-05-09 21:50:34 +00:00
|
|
|
|
;;;###autoload
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(defun latex-mode ()
|
|
|
|
|
"Major mode for editing files of input for LaTeX.
|
|
|
|
|
Makes $ and } display the characters they match.
|
|
|
|
|
Makes \" insert `` when it seems to be the beginning of a quotation,
|
|
|
|
|
and '' when it appears to be the end; it inserts \" only after a \\.
|
|
|
|
|
|
|
|
|
|
Use \\[tex-region] to run LaTeX on the current region, plus the preamble
|
|
|
|
|
copied from the top of the file (containing \\documentstyle, etc.),
|
|
|
|
|
running LaTeX under a special subshell. \\[tex-buffer] does the whole buffer.
|
|
|
|
|
\\[tex-file] saves the buffer and then processes the file.
|
|
|
|
|
\\[tex-print] prints the .dvi file made by any of these.
|
|
|
|
|
\\[tex-view] previews the .dvi file made by any of these.
|
|
|
|
|
\\[tex-bibtex-file] runs bibtex on the file of the current buffer.
|
|
|
|
|
|
|
|
|
|
Use \\[validate-tex-buffer] to check buffer for paragraphs containing
|
|
|
|
|
mismatched $'s or braces.
|
|
|
|
|
|
|
|
|
|
Special commands:
|
|
|
|
|
\\{tex-mode-map}
|
|
|
|
|
|
|
|
|
|
Mode variables:
|
|
|
|
|
latex-run-command
|
|
|
|
|
Command string used by \\[tex-region] or \\[tex-buffer].
|
|
|
|
|
tex-directory
|
|
|
|
|
Directory in which to create temporary files for LaTeX jobs
|
|
|
|
|
run by \\[tex-region] or \\[tex-buffer].
|
|
|
|
|
tex-dvi-print-command
|
|
|
|
|
Command string used by \\[tex-print] to print a .dvi file.
|
1992-07-04 16:51:02 +00:00
|
|
|
|
tex-alt-dvi-print-command
|
|
|
|
|
Alternative command string used by \\[tex-print] (when given a prefix
|
|
|
|
|
argument) to print a .dvi file.
|
1990-08-28 08:01:56 +00:00
|
|
|
|
tex-dvi-view-command
|
|
|
|
|
Command string used by \\[tex-view] to preview a .dvi file.
|
|
|
|
|
tex-show-queue-command
|
|
|
|
|
Command string used by \\[tex-show-print-queue] to show the print
|
|
|
|
|
queue that \\[tex-print] put your job on.
|
|
|
|
|
|
1994-05-02 22:26:50 +00:00
|
|
|
|
Entering Latex mode runs the hook `text-mode-hook', then
|
|
|
|
|
`tex-mode-hook', and finally `latex-mode-hook'. When the special
|
|
|
|
|
subshell is initiated, `tex-shell-hook' is run."
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(tex-common-initialization)
|
|
|
|
|
(setq mode-name "LaTeX")
|
|
|
|
|
(setq major-mode 'latex-mode)
|
|
|
|
|
(setq tex-command latex-run-command)
|
1995-10-19 00:48:12 +00:00
|
|
|
|
(setq tex-start-of-header "\\\\documentstyle\\|\\\\documentclass")
|
|
|
|
|
(setq tex-end-of-header "\\\\begin{document}")
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(setq tex-trailer "\\end{document}\n")
|
1994-01-03 11:36:14 +00:00
|
|
|
|
;; A line containing just $$ is treated as a paragraph separator.
|
|
|
|
|
;; A line starting with $$ starts a paragraph,
|
|
|
|
|
;; but does not separate paragraphs if it has more stuff on it.
|
1995-03-02 15:52:37 +00:00
|
|
|
|
(setq paragraph-start "[ \t]*$\\|[\f%]\\|[ \t]*\\$\\$\\|\
|
|
|
|
|
\\\\begin\\>\\|\\\\label\\>\\|\\\\end\\>\\|\\\\\\[\\|\\\\\\]\\|\
|
|
|
|
|
\\\\chapter\\>\\|\\\\section\\>\\|\
|
|
|
|
|
\\\\subsection\\>\\|\\\\subsubsection\\>\\|\
|
|
|
|
|
\\\\paragraph\\>\\|\\\\subparagraph\\>\\|\
|
|
|
|
|
\\\\item\\>\\|\\\\bibitem\\>\\|\\\\newline\\>\\|\\\\noindent\\>\\|\
|
|
|
|
|
\\\\[a-z]*space\\>\\|\\\\[a-z]*skip\\>\\|\
|
|
|
|
|
\\\\newpage\\>\\|\\\\[a-z]*page\\|\\\\footnote\\>\\|\
|
|
|
|
|
\\\\marginpar\\>\\|\\\\parbox\\>\\|\\\\caption\\>")
|
|
|
|
|
(setq paragraph-separate "[ \t]*$\\|[\f%]\\|[ \t]*\\$\\$[ \t]*$\\|\
|
|
|
|
|
\\\\begin\\>\\|\\\\label\\>\\|\\\\end\\>\\|\\\\\\[\\|\\\\\\]\\|\
|
|
|
|
|
\\\\chapter\\>\\|\\\\section\\>\\|\
|
|
|
|
|
\\\\subsection\\>\\|\\\\subsubsection\\>\\|\
|
|
|
|
|
\\\\paragraph\\>\\|\\\\subparagraph\\>\\|\
|
|
|
|
|
\\(\\\\item\\|\\\\bibitem\\|\\\\newline\\|\\\\noindent\\|\
|
|
|
|
|
\\\\[a-z]*space\\|\\\\[a-z]*skip\\|\
|
|
|
|
|
\\\\newpage\\|\\\\[a-z]*page[a-z]*\\|\\\\footnote\\|\
|
|
|
|
|
\\\\marginpar\\|\\\\parbox\\|\\\\caption\\)[ \t]*\\($\\|%\\)")
|
1996-05-15 15:17:41 +00:00
|
|
|
|
(make-local-variable 'imenu-create-index-function)
|
|
|
|
|
(setq imenu-create-index-function 'latex-imenu-create-index)
|
1996-01-26 19:57:45 +00:00
|
|
|
|
(make-local-variable 'tex-face-alist)
|
|
|
|
|
(setq tex-face-alist tex-latex-face-alist)
|
1998-03-09 06:36:25 +00:00
|
|
|
|
(make-local-variable 'fill-nobreak-predicate)
|
|
|
|
|
(setq fill-nobreak-predicate 'latex-fill-nobreak-predicate)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(run-hooks 'text-mode-hook 'tex-mode-hook 'latex-mode-hook))
|
|
|
|
|
|
1993-09-21 07:48:37 +00:00
|
|
|
|
;;;###autoload
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(defun slitex-mode ()
|
|
|
|
|
"Major mode for editing files of input for SliTeX.
|
|
|
|
|
Makes $ and } display the characters they match.
|
|
|
|
|
Makes \" insert `` when it seems to be the beginning of a quotation,
|
|
|
|
|
and '' when it appears to be the end; it inserts \" only after a \\.
|
|
|
|
|
|
|
|
|
|
Use \\[tex-region] to run SliTeX on the current region, plus the preamble
|
|
|
|
|
copied from the top of the file (containing \\documentstyle, etc.),
|
|
|
|
|
running SliTeX under a special subshell. \\[tex-buffer] does the whole buffer.
|
|
|
|
|
\\[tex-file] saves the buffer and then processes the file.
|
|
|
|
|
\\[tex-print] prints the .dvi file made by any of these.
|
|
|
|
|
\\[tex-view] previews the .dvi file made by any of these.
|
|
|
|
|
\\[tex-bibtex-file] runs bibtex on the file of the current buffer.
|
|
|
|
|
|
|
|
|
|
Use \\[validate-tex-buffer] to check buffer for paragraphs containing
|
|
|
|
|
mismatched $'s or braces.
|
|
|
|
|
|
|
|
|
|
Special commands:
|
|
|
|
|
\\{tex-mode-map}
|
|
|
|
|
|
|
|
|
|
Mode variables:
|
|
|
|
|
slitex-run-command
|
|
|
|
|
Command string used by \\[tex-region] or \\[tex-buffer].
|
|
|
|
|
tex-directory
|
|
|
|
|
Directory in which to create temporary files for SliTeX jobs
|
|
|
|
|
run by \\[tex-region] or \\[tex-buffer].
|
|
|
|
|
tex-dvi-print-command
|
|
|
|
|
Command string used by \\[tex-print] to print a .dvi file.
|
1992-07-04 16:51:02 +00:00
|
|
|
|
tex-alt-dvi-print-command
|
|
|
|
|
Alternative command string used by \\[tex-print] (when given a prefix
|
|
|
|
|
argument) to print a .dvi file.
|
1990-08-28 08:01:56 +00:00
|
|
|
|
tex-dvi-view-command
|
|
|
|
|
Command string used by \\[tex-view] to preview a .dvi file.
|
|
|
|
|
tex-show-queue-command
|
|
|
|
|
Command string used by \\[tex-show-print-queue] to show the print
|
|
|
|
|
queue that \\[tex-print] put your job on.
|
|
|
|
|
|
1994-05-02 22:26:50 +00:00
|
|
|
|
Entering SliTeX mode runs the hook `text-mode-hook', then the hook
|
|
|
|
|
`tex-mode-hook', then the hook `latex-mode-hook', and finally the hook
|
|
|
|
|
`slitex-mode-hook'. When the special subshell is initiated, the hook
|
|
|
|
|
`tex-shell-hook' is run."
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(tex-common-initialization)
|
|
|
|
|
(setq mode-name "SliTeX")
|
|
|
|
|
(setq major-mode 'slitex-mode)
|
|
|
|
|
(setq tex-command slitex-run-command)
|
1996-01-26 19:57:45 +00:00
|
|
|
|
(setq tex-start-of-header "\\\\documentstyle{slides}\\|\\\\documentclass{slides}")
|
1995-10-19 00:48:12 +00:00
|
|
|
|
(setq tex-end-of-header "\\\\begin{document}")
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(setq tex-trailer "\\end{document}\n")
|
1994-01-03 11:36:14 +00:00
|
|
|
|
;; A line containing just $$ is treated as a paragraph separator.
|
|
|
|
|
;; A line starting with $$ starts a paragraph,
|
|
|
|
|
;; but does not separate paragraphs if it has more stuff on it.
|
1995-03-02 15:52:37 +00:00
|
|
|
|
(setq paragraph-start "[ \t]*$\\|[\f%]\\|[ \t]*\\$\\$\\|\
|
|
|
|
|
\\\\begin\\>\\|\\\\label\\>\\|\\\\end\\>\\|\\\\\\[\\|\\\\\\]\\|\
|
|
|
|
|
\\\\chapter\\>\\|\\\\section\\>\\|\
|
|
|
|
|
\\\\subsection\\>\\|\\\\subsubsection\\>\\|\
|
|
|
|
|
\\\\paragraph\\>\\|\\\\subparagraph\\>\\|\
|
|
|
|
|
\\\\item\\>\\|\\\\bibitem\\>\\|\\\\newline\\>\\|\\\\noindent\\>\\|\
|
|
|
|
|
\\\\[a-z]*space\\>\\|\\\\[a-z]*skip\\>\\|\
|
|
|
|
|
\\\\newpage\\>\\|\\\\[a-z]*page\\|\\\\footnote\\>\\|\
|
|
|
|
|
\\\\marginpar\\>\\|\\\\parbox\\>\\|\\\\caption\\>")
|
|
|
|
|
(setq paragraph-separate "[ \t]*$\\|[\f%]\\|[ \t]*\\$\\$[ \t]*$\\|\
|
|
|
|
|
\\\\begin\\>\\|\\\\label\\>\\|\\\\end\\>\\|\\\\\\[\\|\\\\\\]\\|\
|
|
|
|
|
\\\\chapter\\>\\|\\\\section\\>\\|\
|
|
|
|
|
\\\\subsection\\>\\|\\\\subsubsection\\>\\|\
|
|
|
|
|
\\\\paragraph\\>\\|\\\\subparagraph\\>\\|\
|
|
|
|
|
\\\\item[ \t]*$\\|\\\\bibitem[ \t]*$\\|\\\\newline[ \t]*$\\|\\\\noindent[ \t]*$\\|\
|
|
|
|
|
\\\\[a-z]*space[ \t]*$\\|\\\\[a-z]*skip[ \t]*$\\|\
|
|
|
|
|
\\\\newpage[ \t]*$\\|\\\\[a-z]*page[a-z]*[ \t]*$\\|\\\\footnote[ \t]*$\\|\
|
|
|
|
|
\\\\marginpar[ \t]*$\\|\\\\parbox[ \t]*$\\|\\\\caption[ \t]*$")
|
1998-03-09 06:36:25 +00:00
|
|
|
|
(make-local-variable 'imenu-create-index-function)
|
|
|
|
|
(setq imenu-create-index-function 'latex-imenu-create-index)
|
|
|
|
|
(make-local-variable 'tex-face-alist)
|
|
|
|
|
(setq tex-face-alist tex-latex-face-alist)
|
|
|
|
|
(make-local-variable 'fill-nobreak-predicate)
|
|
|
|
|
(setq fill-nobreak-predicate 'latex-fill-nobreak-predicate)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(run-hooks
|
|
|
|
|
'text-mode-hook 'tex-mode-hook 'latex-mode-hook 'slitex-mode-hook))
|
|
|
|
|
|
|
|
|
|
(defun tex-common-initialization ()
|
|
|
|
|
(kill-all-local-variables)
|
|
|
|
|
(use-local-map tex-mode-map)
|
|
|
|
|
(setq local-abbrev-table text-mode-abbrev-table)
|
|
|
|
|
(if (null tex-mode-syntax-table)
|
|
|
|
|
(let ((char 0))
|
|
|
|
|
(setq tex-mode-syntax-table (make-syntax-table))
|
|
|
|
|
(set-syntax-table tex-mode-syntax-table)
|
|
|
|
|
(while (< char ? )
|
|
|
|
|
(modify-syntax-entry char ".")
|
|
|
|
|
(setq char (1+ char)))
|
|
|
|
|
(modify-syntax-entry ?\C-@ "w")
|
|
|
|
|
(modify-syntax-entry ?\t " ")
|
|
|
|
|
(modify-syntax-entry ?\n ">")
|
|
|
|
|
(modify-syntax-entry ?\f ">")
|
|
|
|
|
(modify-syntax-entry ?$ "$$")
|
|
|
|
|
(modify-syntax-entry ?% "<")
|
|
|
|
|
(modify-syntax-entry ?\\ "/")
|
|
|
|
|
(modify-syntax-entry ?\" ".")
|
|
|
|
|
(modify-syntax-entry ?& ".")
|
|
|
|
|
(modify-syntax-entry ?_ ".")
|
|
|
|
|
(modify-syntax-entry ?@ "_")
|
|
|
|
|
(modify-syntax-entry ?~ " ")
|
|
|
|
|
(modify-syntax-entry ?' "w"))
|
|
|
|
|
(set-syntax-table tex-mode-syntax-table))
|
1997-07-04 04:41:46 +00:00
|
|
|
|
;; Regexp isearch should accept newline and formfeed as whitespace.
|
|
|
|
|
(make-local-variable 'search-whitespace-regexp)
|
|
|
|
|
(setq search-whitespace-regexp "[ \t\r\n\f]+")
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(make-local-variable 'paragraph-start)
|
1993-12-23 02:48:56 +00:00
|
|
|
|
;; A line containing just $$ is treated as a paragraph separator.
|
1995-03-02 15:52:37 +00:00
|
|
|
|
(setq paragraph-start "[ \t]*$\\|[\f\\\\%]\\|[ \t]*\\$\\$")
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(make-local-variable 'paragraph-separate)
|
1994-01-03 11:36:14 +00:00
|
|
|
|
;; A line starting with $$ starts a paragraph,
|
|
|
|
|
;; but does not separate paragraphs if it has more stuff on it.
|
1995-03-02 15:52:37 +00:00
|
|
|
|
(setq paragraph-separate "[ \t]*$\\|[\f\\\\%]\\|[ \t]*\\$\\$[ \t]*$")
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(make-local-variable 'comment-start)
|
|
|
|
|
(setq comment-start "%")
|
|
|
|
|
(make-local-variable 'comment-start-skip)
|
|
|
|
|
(setq comment-start-skip "\\(\\(^\\|[^\\]\\)\\(\\\\\\\\\\)*\\)\\(%+ *\\)")
|
1993-03-22 03:27:18 +00:00
|
|
|
|
(make-local-variable 'comment-indent-function)
|
|
|
|
|
(setq comment-indent-function 'tex-comment-indent)
|
1994-01-03 20:06:28 +00:00
|
|
|
|
(make-local-variable 'parse-sexp-ignore-comments)
|
|
|
|
|
(setq parse-sexp-ignore-comments t)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(make-local-variable 'compare-windows-whitespace)
|
|
|
|
|
(setq compare-windows-whitespace 'tex-categorize-whitespace)
|
1996-06-25 22:44:10 +00:00
|
|
|
|
(make-local-variable 'skeleton-further-elements)
|
|
|
|
|
(setq skeleton-further-elements
|
|
|
|
|
'((indent-line-function 'indent-relative-maybe)))
|
1996-01-26 19:57:45 +00:00
|
|
|
|
(make-local-variable 'facemenu-add-face-function)
|
|
|
|
|
(make-local-variable 'facemenu-end-add-face)
|
|
|
|
|
(make-local-variable 'facemenu-remove-face-function)
|
|
|
|
|
(setq facemenu-add-face-function
|
|
|
|
|
(lambda (face end)
|
|
|
|
|
(let ((face-text (cdr (assq face tex-face-alist))))
|
|
|
|
|
(if face-text
|
|
|
|
|
face-text
|
|
|
|
|
(error "Face %s not configured for %s mode" face mode-name))))
|
|
|
|
|
facemenu-end-add-face "}"
|
|
|
|
|
facemenu-remove-face-function t)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(make-local-variable 'tex-command)
|
|
|
|
|
(make-local-variable 'tex-start-of-header)
|
|
|
|
|
(make-local-variable 'tex-end-of-header)
|
|
|
|
|
(make-local-variable 'tex-trailer))
|
|
|
|
|
|
|
|
|
|
(defun tex-comment-indent ()
|
|
|
|
|
(if (looking-at "%%%")
|
|
|
|
|
(current-column)
|
|
|
|
|
(skip-chars-backward " \t")
|
|
|
|
|
(max (if (bolp) 0 (1+ (current-column)))
|
|
|
|
|
comment-column)))
|
|
|
|
|
|
|
|
|
|
(defun tex-categorize-whitespace (backward-limit)
|
|
|
|
|
;; compare-windows-whitespace is set to this.
|
|
|
|
|
;; This is basically a finite-state machine.
|
|
|
|
|
;; Returns a symbol telling how TeX would treat
|
|
|
|
|
;; the whitespace we are looking at: null, space, or par.
|
|
|
|
|
(let ((category 'null)
|
|
|
|
|
(not-finished t))
|
|
|
|
|
(skip-chars-backward " \t\n\f" backward-limit)
|
|
|
|
|
(while not-finished
|
|
|
|
|
(cond ((looking-at "[ \t]+")
|
|
|
|
|
(goto-char (match-end 0))
|
1997-07-24 04:21:34 +00:00
|
|
|
|
(if (eq category 'null)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(setq category 'space)))
|
|
|
|
|
((looking-at "\n")
|
1997-07-24 04:21:34 +00:00
|
|
|
|
(cond ((eq category 'newline)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(setq category 'par)
|
|
|
|
|
(setq not-finished nil))
|
|
|
|
|
(t
|
|
|
|
|
(setq category 'newline) ;a strictly internal state
|
|
|
|
|
(goto-char (match-end 0)))))
|
|
|
|
|
((looking-at "\f+")
|
|
|
|
|
(setq category 'par)
|
|
|
|
|
(setq not-finished nil))
|
|
|
|
|
(t
|
|
|
|
|
(setq not-finished nil))))
|
|
|
|
|
(skip-chars-forward " \t\n\f")
|
1997-07-24 04:21:34 +00:00
|
|
|
|
(if (eq category 'newline)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
'space ;TeX doesn't distinguish
|
|
|
|
|
category)))
|
|
|
|
|
|
|
|
|
|
(defun tex-insert-quote (arg)
|
|
|
|
|
"Insert the appropriate quote marks for TeX.
|
1993-05-16 21:15:09 +00:00
|
|
|
|
Inserts the value of `tex-open-quote' (normally ``) or `tex-close-quote'
|
|
|
|
|
\(normally '') depending on the context. With prefix argument, always
|
1990-08-28 08:01:56 +00:00
|
|
|
|
inserts \" characters."
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(interactive "*P")
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(if arg
|
|
|
|
|
(self-insert-command (prefix-numeric-value arg))
|
|
|
|
|
(insert
|
|
|
|
|
(cond ((or (bobp)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(forward-char -1)
|
|
|
|
|
(looking-at "\\s(\\|\\s \\|\\s>")))
|
|
|
|
|
tex-open-quote)
|
|
|
|
|
((= (preceding-char) ?\\)
|
|
|
|
|
?\")
|
|
|
|
|
(t
|
|
|
|
|
tex-close-quote)))))
|
|
|
|
|
|
|
|
|
|
(defun validate-tex-buffer ()
|
1993-04-26 05:15:08 +00:00
|
|
|
|
"Check current buffer for paragraphs containing mismatched $s.
|
1993-07-31 07:33:02 +00:00
|
|
|
|
Their positions are recorded in the buffer `*Occur*'.
|
|
|
|
|
To find a particular invalidity from `*Occur*',
|
|
|
|
|
switch to to that buffer and type C-c C-c on the line
|
|
|
|
|
for the invalidity you want to see."
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(interactive)
|
1993-07-31 07:33:02 +00:00
|
|
|
|
(let ((buffer (current-buffer))
|
|
|
|
|
(prevpos (point-min))
|
|
|
|
|
(linenum nil))
|
|
|
|
|
(with-output-to-temp-buffer "*Occur*"
|
|
|
|
|
(princ "Mismatches:\n")
|
|
|
|
|
(save-excursion
|
|
|
|
|
(set-buffer standard-output)
|
|
|
|
|
(occur-mode)
|
|
|
|
|
(setq occur-buffer buffer)
|
|
|
|
|
(setq occur-nlines 0)
|
|
|
|
|
(setq occur-pos-list nil))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (point-max))
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(while (and (not (input-pending-p)) (not (bobp)))
|
1996-07-11 23:55:01 +00:00
|
|
|
|
(let ((end (point))
|
|
|
|
|
prev-end)
|
1993-07-31 07:33:02 +00:00
|
|
|
|
;; Scan the previous paragraph for invalidities.
|
1996-07-11 23:55:01 +00:00
|
|
|
|
(if (search-backward "\n\n" nil t)
|
|
|
|
|
(progn
|
|
|
|
|
(setq prev-end (point))
|
|
|
|
|
(forward-char 2))
|
|
|
|
|
(goto-char (setq prev-end (point-min))))
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(or (tex-validate-region (point) end)
|
1996-07-11 23:55:01 +00:00
|
|
|
|
(let* ((oend end)
|
|
|
|
|
(end (save-excursion (forward-line 1) (point)))
|
1993-07-31 07:33:02 +00:00
|
|
|
|
start tem)
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(setq start (point))
|
|
|
|
|
;; Keep track of line number as we scan,
|
|
|
|
|
;; in a cumulative fashion.
|
|
|
|
|
(if linenum
|
|
|
|
|
(setq linenum (- linenum (count-lines prevpos (point))))
|
|
|
|
|
(setq linenum (1+ (count-lines 1 start))))
|
|
|
|
|
(setq prevpos (point))
|
|
|
|
|
;; Mention this mismatch in *Occur*.
|
|
|
|
|
;; Since we scan from end of buffer to beginning,
|
|
|
|
|
;; add each mismatch at the beginning of *Occur*
|
|
|
|
|
;; and at the beginning of occur-pos-list.
|
|
|
|
|
(save-excursion
|
|
|
|
|
(setq tem (point-marker))
|
|
|
|
|
(set-buffer standard-output)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
;; Skip "Mismatches:" header line.
|
|
|
|
|
(forward-line 1)
|
|
|
|
|
(setq occur-pos-list (cons tem occur-pos-list))
|
|
|
|
|
(insert-buffer-substring buffer start end)
|
|
|
|
|
(forward-char (- start end))
|
1996-07-11 23:55:01 +00:00
|
|
|
|
(insert (format "%3d: " linenum)))))
|
|
|
|
|
(goto-char prev-end))))
|
1993-07-31 07:33:02 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(set-buffer standard-output)
|
|
|
|
|
(if (null occur-pos-list)
|
|
|
|
|
(insert "None!\n"))
|
|
|
|
|
(if (interactive-p)
|
|
|
|
|
(message "%d mismatches found" (length occur-pos-list)))))))
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
|
|
|
|
(defun tex-validate-region (start end)
|
|
|
|
|
"Check for mismatched braces or $'s in region.
|
|
|
|
|
Returns t if no mismatches. Returns nil and moves point to suspect
|
|
|
|
|
area if a mismatch is found."
|
|
|
|
|
(interactive "r")
|
|
|
|
|
(let ((failure-point nil) (max-possible-sexps (- end start)))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(condition-case ()
|
|
|
|
|
(save-restriction
|
|
|
|
|
(narrow-to-region start end)
|
1997-10-31 23:03:30 +00:00
|
|
|
|
;; First check that the open and close parens balance in numbers.
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(goto-char start)
|
|
|
|
|
(while (< 0 (setq max-possible-sexps (1- max-possible-sexps)))
|
1997-10-31 23:03:30 +00:00
|
|
|
|
(forward-sexp 1))
|
|
|
|
|
;; Now check that like matches like.
|
|
|
|
|
(goto-char start)
|
|
|
|
|
(while (progn (skip-syntax-forward "^(")
|
|
|
|
|
(not (eobp)))
|
|
|
|
|
(let ((match (matching-paren (following-char))))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(forward-sexp 1)
|
|
|
|
|
(or (= (preceding-char) match)
|
|
|
|
|
(error "Mismatched parentheses"))))
|
|
|
|
|
(forward-char 1)))
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(error
|
1996-07-11 23:55:01 +00:00
|
|
|
|
(skip-syntax-forward " .>")
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(setq failure-point (point)))))
|
|
|
|
|
(if failure-point
|
|
|
|
|
(progn
|
|
|
|
|
(goto-char failure-point)
|
|
|
|
|
nil)
|
|
|
|
|
t)))
|
|
|
|
|
|
|
|
|
|
(defun tex-terminate-paragraph (inhibit-validation)
|
|
|
|
|
"Insert two newlines, breaking a paragraph for TeX.
|
1994-05-02 22:26:50 +00:00
|
|
|
|
Check for mismatched braces or $s in paragraph being terminated.
|
1990-08-28 08:01:56 +00:00
|
|
|
|
A prefix arg inhibits the checking."
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(interactive "*P")
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(or inhibit-validation
|
|
|
|
|
(save-excursion
|
|
|
|
|
(tex-validate-region
|
|
|
|
|
(save-excursion
|
|
|
|
|
(search-backward "\n\n" nil 'move)
|
|
|
|
|
(point))
|
|
|
|
|
(point)))
|
|
|
|
|
(message "Paragraph being closed appears to contain a mismatch"))
|
|
|
|
|
(insert "\n\n"))
|
|
|
|
|
|
|
|
|
|
(defun tex-insert-braces ()
|
|
|
|
|
"Make a pair of braces and be poised to type inside of them."
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(interactive "*")
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(insert ?\{)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(insert ?})))
|
|
|
|
|
|
1998-03-09 06:36:25 +00:00
|
|
|
|
;; This function is used as the value of fill-nobreak-predicate
|
|
|
|
|
;; in LaTeX mode. Its job is to prevent line-breaking inside
|
|
|
|
|
;; of a \verb construct.
|
|
|
|
|
(defun latex-fill-nobreak-predicate ()
|
|
|
|
|
(let ((opoint (point))
|
|
|
|
|
inside)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(save-restriction
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(narrow-to-region (point) opoint)
|
|
|
|
|
(while (re-search-forward "\\\\verb\\(.\\)" nil t)
|
|
|
|
|
(unless (re-search-forward (regexp-quote (match-string 1)) nil t)
|
|
|
|
|
(setq inside t)))))
|
|
|
|
|
inside))
|
|
|
|
|
|
1990-08-28 08:01:56 +00:00
|
|
|
|
;;; Like tex-insert-braces, but for LaTeX.
|
1996-06-25 22:44:10 +00:00
|
|
|
|
(define-skeleton tex-latex-block
|
|
|
|
|
"Create a matching pair of lines \\begin[OPT]{NAME} and \\end{NAME} at point.
|
1990-08-28 08:01:56 +00:00
|
|
|
|
Puts point on a blank line between them."
|
1996-06-25 22:44:10 +00:00
|
|
|
|
(completing-read "LaTeX block name: "
|
|
|
|
|
(mapcar 'list
|
|
|
|
|
(append standard-latex-block-names
|
|
|
|
|
latex-block-names)))
|
|
|
|
|
"\\begin["
|
|
|
|
|
(skeleton-read "[options]: ") & ?\] | -1
|
|
|
|
|
?\{
|
|
|
|
|
str
|
|
|
|
|
?\} \n
|
|
|
|
|
_ \n
|
|
|
|
|
"\\end{" str ?\})
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
|
|
|
|
(defun tex-last-unended-begin ()
|
1994-05-02 22:26:50 +00:00
|
|
|
|
"Leave point at the beginning of the last `\\begin{...}' that is unended."
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(while (and (re-search-backward "\\(\\\\begin\\s *{\\)\\|\\(\\\\end\\s *{\\)")
|
|
|
|
|
(looking-at "\\\\end{"))
|
|
|
|
|
(tex-last-unended-begin)))
|
|
|
|
|
|
1994-05-03 21:15:27 +00:00
|
|
|
|
(defun tex-goto-last-unclosed-latex-block ()
|
|
|
|
|
"Move point to the last unclosed \\begin{...}.
|
|
|
|
|
Mark is left at original location."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((spot))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(condition-case nil
|
|
|
|
|
(tex-last-unended-begin)
|
|
|
|
|
(error (error "Couldn't find unended \\begin")))
|
|
|
|
|
(setq spot (point)))
|
|
|
|
|
(push-mark)
|
|
|
|
|
(goto-char spot)))
|
|
|
|
|
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(defun tex-close-latex-block ()
|
|
|
|
|
"Creates an \\end{...} to match the last unclosed \\begin{...}."
|
|
|
|
|
(interactive "*")
|
|
|
|
|
(let ((new-line-needed (bolp))
|
|
|
|
|
text indentation)
|
|
|
|
|
(save-excursion
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(condition-case nil
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(tex-last-unended-begin)
|
|
|
|
|
(error (error "Couldn't find unended \\begin")))
|
|
|
|
|
(setq indentation (current-column))
|
|
|
|
|
(re-search-forward "\\\\begin\\(\\s *{[^}\n]*}\\)")
|
|
|
|
|
(setq text (buffer-substring (match-beginning 1) (match-end 1))))
|
|
|
|
|
(indent-to indentation)
|
|
|
|
|
(insert "\\end" text)
|
|
|
|
|
(if new-line-needed (insert ?\n))))
|
|
|
|
|
|
1993-04-25 06:14:10 +00:00
|
|
|
|
(defun tex-compilation-parse-errors ()
|
|
|
|
|
"Parse the current buffer as error messages.
|
|
|
|
|
This makes a list of error descriptors, compilation-error-list.
|
|
|
|
|
For each source-file, line-number pair in the buffer,
|
|
|
|
|
the source file is read in, and the text location is saved in
|
1993-04-26 05:15:08 +00:00
|
|
|
|
compilation-error-list. The function `next-error', assigned to
|
1993-04-25 06:14:10 +00:00
|
|
|
|
\\[next-error], takes the next error off the list and visits its location.
|
|
|
|
|
|
|
|
|
|
This function works on TeX compilations only. It is necessary for
|
|
|
|
|
that purpose, since TeX does not put file names on the same line as
|
|
|
|
|
line numbers for the errors."
|
|
|
|
|
(setq compilation-error-list nil)
|
|
|
|
|
(message "Parsing error messages...")
|
|
|
|
|
(modify-syntax-entry ?\{ "_")
|
|
|
|
|
(modify-syntax-entry ?\} "_")
|
|
|
|
|
(modify-syntax-entry ?\[ "_")
|
|
|
|
|
(modify-syntax-entry ?\] "_")
|
|
|
|
|
(let (text-buffer
|
|
|
|
|
last-filename last-linenum)
|
|
|
|
|
;; Don't reparse messages already seen at last parse.
|
|
|
|
|
(goto-char compilation-parsing-end)
|
|
|
|
|
;; Don't parse the first two lines as error messages.
|
|
|
|
|
;; This matters for grep.
|
|
|
|
|
(if (bobp)
|
|
|
|
|
(forward-line 2))
|
1993-04-26 05:15:08 +00:00
|
|
|
|
(while (re-search-forward "^l\.[0-9]+ " nil t)
|
1993-04-25 06:14:10 +00:00
|
|
|
|
(let (linenum filename
|
|
|
|
|
error-marker text-marker)
|
|
|
|
|
;; Extract file name and line number from error message.
|
|
|
|
|
;; Line number is 2 away from beginning of line: "l.23"
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(goto-char (+ (point) 2))
|
|
|
|
|
(setq linenum (read (current-buffer)))
|
|
|
|
|
;; The file is the one that was opened last and is still open.
|
|
|
|
|
;; We need to find the last open parenthesis.
|
|
|
|
|
(insert ?\))
|
|
|
|
|
(backward-sexp)
|
|
|
|
|
(forward-char)
|
1993-04-26 05:15:08 +00:00
|
|
|
|
(setq filename (current-word))
|
1993-04-25 06:14:10 +00:00
|
|
|
|
;; Locate the erring file and line.
|
|
|
|
|
(if (and (equal filename last-filename)
|
|
|
|
|
(= linenum last-linenum))
|
|
|
|
|
nil
|
|
|
|
|
(skip-chars-backward "^(")
|
|
|
|
|
(backward-char)
|
|
|
|
|
(forward-sexp)
|
|
|
|
|
(backward-delete-char 1)
|
|
|
|
|
(setq error-marker (point-marker))
|
|
|
|
|
;; text-buffer gets the buffer containing this error's file.
|
|
|
|
|
(if (not (equal filename last-filename))
|
|
|
|
|
(setq text-buffer
|
|
|
|
|
(and (file-exists-p (setq last-filename filename))
|
|
|
|
|
(find-file-noselect filename))
|
|
|
|
|
last-linenum 0))
|
|
|
|
|
(if text-buffer
|
|
|
|
|
;; Go to that buffer and find the erring line.
|
|
|
|
|
(save-excursion
|
|
|
|
|
(set-buffer text-buffer)
|
|
|
|
|
(if (zerop last-linenum)
|
|
|
|
|
(progn
|
|
|
|
|
(goto-char 1)
|
|
|
|
|
(setq last-linenum 1)))
|
|
|
|
|
(forward-line (- linenum last-linenum))
|
|
|
|
|
(setq last-linenum linenum)
|
|
|
|
|
(setq text-marker (point-marker))
|
|
|
|
|
(setq compilation-error-list
|
|
|
|
|
(cons (list error-marker text-marker)
|
|
|
|
|
compilation-error-list)))))
|
|
|
|
|
(forward-line 1)))
|
|
|
|
|
(setq compilation-parsing-end (point-max)))
|
|
|
|
|
(message "Parsing error messages...done")
|
|
|
|
|
(setq compilation-error-list (nreverse compilation-error-list)))
|
|
|
|
|
|
1990-08-28 08:01:56 +00:00
|
|
|
|
;;; Invoking TeX in an inferior shell.
|
|
|
|
|
|
|
|
|
|
;;; Why use a shell instead of running TeX directly? Because if TeX
|
|
|
|
|
;;; gets stuck, the user can switch to the shell window and type at it.
|
|
|
|
|
|
|
|
|
|
;;; The utility functions:
|
|
|
|
|
|
1994-06-10 20:28:52 +00:00
|
|
|
|
;;;###autoload
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(defun tex-start-shell ()
|
|
|
|
|
(save-excursion
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(set-buffer
|
|
|
|
|
(make-comint
|
|
|
|
|
"tex-shell"
|
|
|
|
|
(or tex-shell-file-name (getenv "ESHELL") (getenv "SHELL") "/bin/sh")
|
1993-11-20 22:00:55 +00:00
|
|
|
|
nil))
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(let ((proc (get-process "tex-shell")))
|
|
|
|
|
(set-process-sentinel proc 'tex-shell-sentinel)
|
|
|
|
|
(process-kill-without-query proc)
|
1994-12-19 19:09:39 +00:00
|
|
|
|
(setq comint-prompt-regexp shell-prompt-pattern)
|
1994-12-21 20:08:17 +00:00
|
|
|
|
(setq tex-shell-map (nconc (make-sparse-keymap) shell-mode-map))
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(tex-define-common-keys tex-shell-map)
|
|
|
|
|
(use-local-map tex-shell-map)
|
|
|
|
|
(run-hooks 'tex-shell-hook)
|
|
|
|
|
(while (zerop (buffer-size))
|
1995-01-27 23:08:49 +00:00
|
|
|
|
(sleep-for 1)))))
|
|
|
|
|
|
|
|
|
|
(defun tex-display-shell ()
|
|
|
|
|
"Make the TeX shell buffer visible in a window."
|
|
|
|
|
(display-buffer (process-buffer (get-process "tex-shell")))
|
|
|
|
|
(tex-recenter-output-buffer nil))
|
1992-07-04 16:51:02 +00:00
|
|
|
|
|
|
|
|
|
(defun tex-shell-sentinel (proc msg)
|
|
|
|
|
(cond ((null (buffer-name (process-buffer proc)))
|
|
|
|
|
;; buffer killed
|
|
|
|
|
(set-process-buffer proc nil)
|
|
|
|
|
(tex-delete-last-temp-files))
|
|
|
|
|
((memq (process-status proc) '(signal exit))
|
|
|
|
|
(tex-delete-last-temp-files))))
|
|
|
|
|
|
|
|
|
|
(defun tex-set-buffer-directory (buffer directory)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
"Set BUFFER's default directory to be DIRECTORY."
|
|
|
|
|
(setq directory (file-name-as-directory (expand-file-name directory)))
|
|
|
|
|
(if (not (file-directory-p directory))
|
|
|
|
|
(error "%s is not a directory" directory)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(set-buffer buffer)
|
|
|
|
|
(setq default-directory directory))))
|
|
|
|
|
|
1993-11-20 22:21:30 +00:00
|
|
|
|
(defvar tex-send-command-modified-tick 0)
|
|
|
|
|
(make-variable-buffer-local 'tex-send-command-modified-tick)
|
|
|
|
|
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(defun tex-send-command (command &optional file background)
|
1993-11-20 22:00:55 +00:00
|
|
|
|
"Send COMMAND to TeX shell process, substituting optional FILE for *.
|
1993-04-26 05:15:08 +00:00
|
|
|
|
Do this in background if optional BACKGROUND is t. If COMMAND has no *,
|
|
|
|
|
FILE will be appended, preceded by a blank, to COMMAND. If FILE is nil, no
|
|
|
|
|
substitution will be made in COMMAND. COMMAND can be any expression that
|
|
|
|
|
evaluates to a command string."
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(let* ((cmd (eval command))
|
1995-11-04 00:39:25 +00:00
|
|
|
|
(proc (or (get-process "tex-shell") (error "No TeX subprocess")))
|
1993-12-23 02:48:56 +00:00
|
|
|
|
(buf (process-buffer proc))
|
1993-03-19 17:38:48 +00:00
|
|
|
|
(star (string-match "\\*" cmd))
|
1993-11-20 22:00:55 +00:00
|
|
|
|
(string
|
|
|
|
|
(concat
|
|
|
|
|
(if file
|
|
|
|
|
(if star (concat (substring cmd 0 star)
|
|
|
|
|
file (substring cmd (1+ star)))
|
|
|
|
|
(concat cmd " " file))
|
|
|
|
|
cmd)
|
|
|
|
|
(if background "&" ""))))
|
1993-12-23 02:48:56 +00:00
|
|
|
|
;; Switch to buffer before checking for subproc output in it.
|
|
|
|
|
(set-buffer buf)
|
1993-11-20 22:21:30 +00:00
|
|
|
|
;; If text is unchanged since previous tex-send-command,
|
|
|
|
|
;; we haven't got any output. So wait for output now.
|
1993-12-23 02:48:56 +00:00
|
|
|
|
(if (= (buffer-modified-tick buf) tex-send-command-modified-tick)
|
1993-11-20 22:21:30 +00:00
|
|
|
|
(accept-process-output proc))
|
1993-11-20 22:00:55 +00:00
|
|
|
|
(goto-char (process-mark proc))
|
|
|
|
|
(insert string)
|
1993-11-20 22:21:30 +00:00
|
|
|
|
(comint-send-input)
|
1993-12-23 02:48:56 +00:00
|
|
|
|
(setq tex-send-command-modified-tick (buffer-modified-tick buf)))))
|
1992-07-04 16:51:02 +00:00
|
|
|
|
|
1994-03-23 18:19:20 +00:00
|
|
|
|
(defun tex-delete-last-temp-files (&optional not-all)
|
|
|
|
|
"Delete any junk files from last temp file.
|
|
|
|
|
If NOT-ALL is non-nil, save the `.dvi' file."
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(if tex-last-temp-file
|
|
|
|
|
(let* ((dir (file-name-directory tex-last-temp-file))
|
1994-05-18 01:13:09 +00:00
|
|
|
|
(list (and (file-directory-p dir)
|
|
|
|
|
(file-name-all-completions
|
|
|
|
|
(file-name-nondirectory tex-last-temp-file) dir))))
|
|
|
|
|
(while list
|
1994-03-23 18:19:20 +00:00
|
|
|
|
(if not-all
|
|
|
|
|
(and
|
|
|
|
|
;; If arg is non-nil, don't delete the .dvi file.
|
|
|
|
|
(not (string-match "\\.dvi$" (car list)))
|
|
|
|
|
(delete-file (concat dir (car list))))
|
|
|
|
|
(delete-file (concat dir (car list))))
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(setq list (cdr list))))))
|
|
|
|
|
|
1992-07-05 20:52:00 +00:00
|
|
|
|
(add-hook 'kill-emacs-hook 'tex-delete-last-temp-files)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1992-07-04 16:51:02 +00:00
|
|
|
|
;;; The commands:
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
|
|
|
|
(defun tex-region (beg end)
|
|
|
|
|
"Run TeX on the current region, via a temporary file.
|
|
|
|
|
The file's name comes from the variable `tex-zap-file' and the
|
|
|
|
|
variable `tex-directory' says where to put it.
|
|
|
|
|
|
|
|
|
|
If the buffer has a header, the header is given to TeX before the
|
|
|
|
|
region itself. The buffer's header is all lines between the strings
|
|
|
|
|
defined by `tex-start-of-header' and `tex-end-of-header' inclusive.
|
|
|
|
|
The header must start in the first 100 lines of the buffer.
|
|
|
|
|
|
|
|
|
|
The value of `tex-trailer' is given to TeX as input after the region.
|
|
|
|
|
|
|
|
|
|
The value of `tex-command' specifies the command to use to run TeX."
|
|
|
|
|
(interactive "r")
|
|
|
|
|
(if (tex-shell-running)
|
|
|
|
|
(tex-kill-job)
|
|
|
|
|
(tex-start-shell))
|
|
|
|
|
(or tex-zap-file
|
|
|
|
|
(setq tex-zap-file (tex-generate-zap-file-name)))
|
1997-01-02 01:30:36 +00:00
|
|
|
|
;; Temp file will be written and TeX will be run in zap-directory.
|
|
|
|
|
;; If the TEXINPUTS file has relative directories or if the region has
|
|
|
|
|
;; \input of files, this must be the same directory as the file for
|
|
|
|
|
;; TeX to access the correct inputs. That's why it's safest if
|
|
|
|
|
;; tex-directory is ".".
|
|
|
|
|
(let* ((zap-directory
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(file-name-as-directory (expand-file-name tex-directory)))
|
1997-01-02 01:30:36 +00:00
|
|
|
|
(tex-out-file (concat zap-directory tex-zap-file ".tex")))
|
1994-10-11 18:51:29 +00:00
|
|
|
|
;; Don't delete temp files if we do the same buffer twice in a row.
|
|
|
|
|
(or (eq (current-buffer) tex-last-buffer-texed)
|
|
|
|
|
(tex-delete-last-temp-files t))
|
1990-08-28 08:01:56 +00:00
|
|
|
|
;; Write the new temp file.
|
|
|
|
|
(save-excursion
|
|
|
|
|
(save-restriction
|
|
|
|
|
(widen)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(forward-line 100)
|
|
|
|
|
(let ((search-end (point))
|
1997-01-02 01:30:36 +00:00
|
|
|
|
(default-directory zap-directory)
|
|
|
|
|
(already-output 0))
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(goto-char (point-min))
|
1997-01-02 01:30:36 +00:00
|
|
|
|
|
1996-12-29 19:41:52 +00:00
|
|
|
|
;; Maybe copy first line, such as `\input texinfo', to temp file.
|
|
|
|
|
(and tex-first-line-header-regexp
|
|
|
|
|
(looking-at tex-first-line-header-regexp)
|
|
|
|
|
(write-region (point)
|
1997-01-02 01:30:36 +00:00
|
|
|
|
(progn (forward-line 1)
|
|
|
|
|
(setq already-output (point)))
|
1996-12-29 19:41:52 +00:00
|
|
|
|
tex-out-file nil nil))
|
|
|
|
|
|
1997-01-02 01:30:36 +00:00
|
|
|
|
;; Write out the header, if there is one,
|
|
|
|
|
;; and any of the specified region which extends before it.
|
|
|
|
|
;; But don't repeat anything already written.
|
1995-10-19 00:48:12 +00:00
|
|
|
|
(if (re-search-forward tex-start-of-header search-end t)
|
1997-01-02 01:30:36 +00:00
|
|
|
|
(let (hbeg)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(setq hbeg (point)) ;mark beginning of header
|
1995-10-19 00:48:12 +00:00
|
|
|
|
(if (re-search-forward tex-end-of-header nil t)
|
1997-01-02 01:30:36 +00:00
|
|
|
|
(let (hend)
|
|
|
|
|
(forward-line 1)
|
|
|
|
|
(setq hend (point)) ;mark end of header
|
|
|
|
|
(write-region (max (min hbeg beg) already-output)
|
|
|
|
|
hend
|
|
|
|
|
tex-out-file
|
|
|
|
|
(not (zerop already-output)) nil)
|
|
|
|
|
(setq already-output hend)))))
|
|
|
|
|
|
|
|
|
|
;; Write out the specified region
|
|
|
|
|
;; (but don't repeat anything already written).
|
|
|
|
|
(write-region (max beg already-output) end
|
|
|
|
|
tex-out-file
|
|
|
|
|
(not (zerop already-output)) nil))
|
|
|
|
|
;; Write the trailer, if any.
|
|
|
|
|
;; Precede it with a newline to make sure it
|
|
|
|
|
;; is not hidden in a comment.
|
|
|
|
|
(if tex-trailer
|
|
|
|
|
(write-region (concat "\n" tex-trailer) nil
|
|
|
|
|
tex-out-file t nil))))
|
1992-07-04 16:51:02 +00:00
|
|
|
|
;; Record the file name to be deleted afterward.
|
|
|
|
|
(setq tex-last-temp-file tex-out-file)
|
|
|
|
|
(tex-send-command tex-shell-cd-command zap-directory)
|
|
|
|
|
(tex-send-command tex-command tex-out-file)
|
1995-01-27 23:08:49 +00:00
|
|
|
|
(tex-display-shell)
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(setq tex-print-file tex-out-file)
|
|
|
|
|
(setq tex-last-buffer-texed (current-buffer))))
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
|
|
|
|
(defun tex-buffer ()
|
|
|
|
|
"Run TeX on current buffer. See \\[tex-region] for more information.
|
1992-07-04 16:51:02 +00:00
|
|
|
|
Does not save the buffer, so it's useful for trying experimental versions.
|
|
|
|
|
See \\[tex-file] for an alternative."
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(tex-region (point-min) (point-max)))
|
|
|
|
|
|
|
|
|
|
(defun tex-file ()
|
|
|
|
|
"Prompt to save all buffers and run TeX (or LaTeX) on current buffer's file.
|
|
|
|
|
This function is more useful than \\[tex-buffer] when you need the
|
|
|
|
|
`.aux' file of LaTeX to have the correct name."
|
|
|
|
|
(interactive)
|
1996-08-25 01:25:07 +00:00
|
|
|
|
(let ((source-file
|
|
|
|
|
(or tex-main-file
|
|
|
|
|
(if (buffer-file-name)
|
|
|
|
|
(file-name-nondirectory (buffer-file-name))
|
|
|
|
|
(error "Buffer does not seem to be associated with any file"))))
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(file-dir (file-name-directory (buffer-file-name))))
|
1992-07-10 22:19:56 +00:00
|
|
|
|
(if tex-offer-save
|
1992-07-05 20:52:00 +00:00
|
|
|
|
(save-some-buffers))
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(if (tex-shell-running)
|
|
|
|
|
(tex-kill-job)
|
|
|
|
|
(tex-start-shell))
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(tex-send-command tex-shell-cd-command file-dir)
|
1996-10-31 23:50:02 +00:00
|
|
|
|
(tex-send-command tex-command source-file)
|
|
|
|
|
(tex-display-shell)
|
|
|
|
|
(setq tex-last-buffer-texed (current-buffer))
|
|
|
|
|
(setq tex-print-file source-file)))
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
|
|
|
|
(defun tex-generate-zap-file-name ()
|
|
|
|
|
"Generate a unique name suitable for use as a file name."
|
|
|
|
|
;; Include the shell process number and host name
|
|
|
|
|
;; in case there are multiple shells (for same or different user).
|
|
|
|
|
(format "#tz%d%s"
|
|
|
|
|
(process-id (get-buffer-process "*tex-shell*"))
|
|
|
|
|
(tex-strip-dots (system-name))))
|
|
|
|
|
|
|
|
|
|
(defun tex-strip-dots (s)
|
|
|
|
|
(setq s (copy-sequence s))
|
|
|
|
|
(while (string-match "\\." s)
|
|
|
|
|
(aset s (match-beginning 0) ?-))
|
|
|
|
|
s)
|
|
|
|
|
|
|
|
|
|
;; This will perhaps be useful for modifying TEXINPUTS.
|
|
|
|
|
;; Expand each file name, separated by colons, in the string S.
|
|
|
|
|
(defun tex-expand-files (s)
|
|
|
|
|
(let (elts (start 0))
|
|
|
|
|
(while (string-match ":" s start)
|
|
|
|
|
(setq elts (cons (substring s start (match-beginning 0)) elts))
|
|
|
|
|
(setq start (match-end 0)))
|
|
|
|
|
(or (= start 0)
|
|
|
|
|
(setq elts (cons (substring s start) elts)))
|
|
|
|
|
(mapconcat 'expand-file-name (nreverse elts) ":")))
|
|
|
|
|
|
|
|
|
|
(defun tex-shell-running ()
|
|
|
|
|
(and (get-process "tex-shell")
|
|
|
|
|
(eq (process-status (get-process "tex-shell")) 'run)))
|
|
|
|
|
|
|
|
|
|
(defun tex-kill-job ()
|
|
|
|
|
"Kill the currently running TeX job."
|
|
|
|
|
(interactive)
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(quit-process (get-process "tex-shell") t))
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
|
|
|
|
(defun tex-recenter-output-buffer (linenum)
|
|
|
|
|
"Redisplay buffer of TeX job output so that most recent output can be seen.
|
|
|
|
|
The last line of the buffer is displayed on
|
|
|
|
|
line LINE of the window, or centered if LINE is nil."
|
|
|
|
|
(interactive "P")
|
|
|
|
|
(let ((tex-shell (get-buffer "*tex-shell*"))
|
1996-10-31 23:50:02 +00:00
|
|
|
|
(old-buffer (current-buffer))
|
|
|
|
|
(window))
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(if (null tex-shell)
|
|
|
|
|
(message "No TeX output buffer")
|
1996-10-31 23:50:02 +00:00
|
|
|
|
(setq window (display-buffer tex-shell))
|
|
|
|
|
(save-selected-window
|
|
|
|
|
(select-window window)
|
|
|
|
|
(bury-buffer tex-shell)
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(recenter (if linenum
|
|
|
|
|
(prefix-numeric-value linenum)
|
|
|
|
|
(/ (window-height) 2)))))))
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(defun tex-print (&optional alt)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
"Print the .dvi file made by \\[tex-region], \\[tex-buffer] or \\[tex-file].
|
1992-11-10 20:01:10 +00:00
|
|
|
|
Runs the shell command defined by `tex-dvi-print-command'. If prefix argument
|
|
|
|
|
is provided, use the alternative command, `tex-alt-dvi-print-command'."
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(interactive "P")
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(let ((print-file-name-dvi (tex-append tex-print-file ".dvi"))
|
|
|
|
|
test-name)
|
|
|
|
|
(if (and (not (equal (current-buffer) tex-last-buffer-texed))
|
1995-01-05 00:23:50 +00:00
|
|
|
|
(buffer-file-name)
|
|
|
|
|
;; Check that this buffer's printed file is up to date.
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(file-newer-than-file-p
|
|
|
|
|
(setq test-name (tex-append (buffer-file-name) ".dvi"))
|
1995-01-05 00:23:50 +00:00
|
|
|
|
(buffer-file-name)))
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(setq print-file-name-dvi test-name))
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(if (not (file-exists-p print-file-name-dvi))
|
|
|
|
|
(error "No appropriate `.dvi' file could be found")
|
|
|
|
|
(tex-send-command
|
|
|
|
|
(if alt tex-alt-dvi-print-command tex-dvi-print-command)
|
|
|
|
|
print-file-name-dvi t))))
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1993-11-06 05:56:11 +00:00
|
|
|
|
(defun tex-alt-print ()
|
|
|
|
|
"Print the .dvi file made by \\[tex-region], \\[tex-buffer] or \\[tex-file].
|
1994-12-30 23:02:43 +00:00
|
|
|
|
Runs the shell command defined by `tex-alt-dvi-print-command'."
|
1993-11-06 05:56:11 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(tex-print t))
|
|
|
|
|
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(defun tex-view ()
|
|
|
|
|
"Preview the last `.dvi' file made by running TeX under Emacs.
|
|
|
|
|
This means, made using \\[tex-region], \\[tex-buffer] or \\[tex-file].
|
1995-04-29 16:32:03 +00:00
|
|
|
|
The variable `tex-dvi-view-command' specifies the shell command for preview.
|
|
|
|
|
You must set that variable yourself before using this command,
|
|
|
|
|
because there is no standard value that would generally work."
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(interactive)
|
1995-04-29 16:32:03 +00:00
|
|
|
|
(or tex-dvi-view-command
|
|
|
|
|
(error "You must set `tex-dvi-view-command'"))
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(let ((tex-dvi-print-command tex-dvi-view-command))
|
|
|
|
|
(tex-print)))
|
|
|
|
|
|
|
|
|
|
(defun tex-append (file-name suffix)
|
|
|
|
|
"Append to FILENAME the suffix SUFFIX, using same algorithm TeX uses.
|
1993-11-06 05:56:11 +00:00
|
|
|
|
Pascal-based TeX scans for the first period, C TeX uses the last.
|
1990-08-28 08:01:56 +00:00
|
|
|
|
No period is retained immediately before SUFFIX,
|
|
|
|
|
so normally SUFFIX starts with one."
|
|
|
|
|
(if (stringp file-name)
|
1993-11-06 05:56:11 +00:00
|
|
|
|
(let ((file (file-name-nondirectory file-name))
|
|
|
|
|
trial-name)
|
1996-01-26 19:57:45 +00:00
|
|
|
|
;; Try splitting on last period.
|
1995-02-17 23:25:17 +00:00
|
|
|
|
;; The first-period split can get fooled when two files
|
|
|
|
|
;; named a.tex and a.b.tex are both tex'd;
|
|
|
|
|
;; the last-period split must be right if it matches at all.
|
1993-11-06 05:56:11 +00:00
|
|
|
|
(setq trial-name
|
|
|
|
|
(concat (file-name-directory file-name)
|
|
|
|
|
(substring file 0
|
1995-02-17 23:25:17 +00:00
|
|
|
|
(string-match "\\.[^.]*$" file))
|
1993-11-06 05:56:11 +00:00
|
|
|
|
suffix))
|
|
|
|
|
(if (or (file-exists-p trial-name)
|
|
|
|
|
(file-exists-p (concat trial-name ".aux"))) ;for BibTeX files
|
|
|
|
|
trial-name
|
1995-02-17 23:25:17 +00:00
|
|
|
|
;; Not found, so split on first period.
|
1993-11-06 05:56:11 +00:00
|
|
|
|
(concat (file-name-directory file-name)
|
|
|
|
|
(substring file 0
|
1995-02-17 23:25:17 +00:00
|
|
|
|
(string-match "\\." file))
|
1993-11-06 05:56:11 +00:00
|
|
|
|
suffix)))
|
1990-08-28 08:01:56 +00:00
|
|
|
|
" "))
|
|
|
|
|
|
|
|
|
|
(defun tex-show-print-queue ()
|
|
|
|
|
"Show the print queue that \\[tex-print] put your job on.
|
1992-11-10 20:01:10 +00:00
|
|
|
|
Runs the shell command defined by `tex-show-queue-command'."
|
1990-08-28 08:01:56 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(if (tex-shell-running)
|
|
|
|
|
(tex-kill-job)
|
|
|
|
|
(tex-start-shell))
|
1995-01-27 23:08:49 +00:00
|
|
|
|
(tex-send-command tex-show-queue-command)
|
|
|
|
|
(tex-display-shell))
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
|
|
|
|
(defun tex-bibtex-file ()
|
|
|
|
|
"Run BibTeX on the current buffer's file."
|
|
|
|
|
(interactive)
|
|
|
|
|
(if (tex-shell-running)
|
|
|
|
|
(tex-kill-job)
|
|
|
|
|
(tex-start-shell))
|
|
|
|
|
(let ((tex-out-file
|
|
|
|
|
(tex-append (file-name-nondirectory (buffer-file-name)) ""))
|
|
|
|
|
(file-dir (file-name-directory (buffer-file-name))))
|
1992-07-04 16:51:02 +00:00
|
|
|
|
(tex-send-command tex-shell-cd-command file-dir)
|
1995-01-27 23:08:49 +00:00
|
|
|
|
(tex-send-command tex-bibtex-command tex-out-file))
|
|
|
|
|
(tex-display-shell))
|
1992-07-04 16:51:02 +00:00
|
|
|
|
|
|
|
|
|
(run-hooks 'tex-mode-load-hook)
|
1990-08-28 08:01:56 +00:00
|
|
|
|
|
1992-03-16 20:39:07 +00:00
|
|
|
|
(provide 'tex-mode)
|
|
|
|
|
|
1992-05-30 20:24:49 +00:00
|
|
|
|
;;; tex-mode.el ends here
|
1992-07-05 20:52:00 +00:00
|
|
|
|
|