Fetching contributors…
Cannot retrieve contributors at this time
6569 lines (5836 sloc) 236 KB
;;; tex.el --- Support for TeX documents.
;; Copyright (C) 1985-1987, 1991, 1993-2016 Free Software Foundation, Inc.
;; Maintainer: auctex-devel@gnu.org
;; Keywords: tex
;; This file is part of AUCTeX.
;; AUCTeX is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; AUCTeX is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with AUCTeX; see the file COPYING. If not, write to the Free
;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
;; 02110-1301, USA.
;;; Commentary:
;; This file provides basic functions used by the AUCTeX modes.
;;; Code:
(when (< emacs-major-version 21)
(error "AUCTeX requires Emacs 21 or later"))
(require 'custom)
(require 'tex-site)
(require 'cl))
(defgroup TeX-file nil
"Files used by AUCTeX."
:group 'AUCTeX)
(defgroup TeX-command nil
"Calling external commands from AUCTeX."
:group 'AUCTeX)
(defgroup LaTeX nil
"LaTeX support in AUCTeX."
:tag "LaTeX"
:group 'AUCTeX
:prefix "LaTeX-")
(defgroup TeX-misc nil
"Various AUCTeX settings."
:group 'AUCTeX)
;;; Site Customization
;; The following variables are likely to need to be changed for your
;; site. You should do this with customize.
(defcustom TeX-command "tex"
"Command to run plain TeX."
:group 'TeX-command
:type 'string)
(defcustom TeX-Omega-command "omega"
"Command to run plain TeX on Omega."
:group 'TeX-command
:type '(choice (const :tag "Aleph" "aleph")
(const :tag "Omega" "omega")
(string :tag "Other command")))
(defcustom LaTeX-command "latex"
"Command to run LaTeX."
:group 'TeX-command
:type 'string)
(defcustom LaTeX-Omega-command "lambda"
"Command to run LaTeX on Omega."
:group 'TeX-command
:type '(choice (const :tag "Lamed" "lamed")
(const :tag "Lambda" "lambda")
(string :tag "Other command")))
(defcustom TeX-file-line-error t
"Whether to have TeX produce file:line:error style error messages."
:group 'TeX-command
:type 'boolean)
(defcustom ConTeXt-engine nil
"Engine to use for --engine in the texexec command.
If nil, none is specified."
:group 'TeX-command
:type '(choice (const :tag "Unspecified" nil)
(defcustom ConTeXt-Omega-engine TeX-Omega-command
"Engine to use for --engine in the texexec command in Omega mode.
If nil, none is specified."
:group 'TeX-command
:type '(choice (const :tag "Unspecified" nil)
;; At least in TeXLive 2009 ConTeXt does not support an omega option anymore.
(make-obsolete-variable 'ConTeXt-Omega-engine 'TeX-engine-alist "11.86")
(defcustom TeX-mode-hook nil
"A hook run in TeX mode buffers."
:type 'hook
:group 'TeX-misc)
(defcustom AmS-TeX-mode-hook nil
"A hook run in AmS-TeX mode buffers."
:type 'hook
:group 'TeX-misc)
;; This is the major configuration variable. Most sites will only need to
;; change the second string in each entry, which is the name of a command to
;; send to the shell. If you use other formatters like AMSLaTeX or AMSTeX, you
;; can add those to the list. See `TeX-expand-list' and
;; `TeX-expand-list-builtin' for a description of the % escapes
(defcustom TeX-command-list
'(("TeX" "%(PDF)%(tex) %(file-line-error) %(extraopts) %`%S%(PDFout)%(mode)%' %t"
TeX-run-TeX nil
(plain-tex-mode ams-tex-mode texinfo-mode) :help "Run plain TeX")
("LaTeX" "%`%l%(mode)%' %t"
TeX-run-TeX nil
(latex-mode doctex-mode) :help "Run LaTeX")
;; Not part of standard TeX.
("Makeinfo" "makeinfo %(extraopts) %t" TeX-run-compile nil
(texinfo-mode) :help "Run Makeinfo with Info output")
("Makeinfo HTML" "makeinfo %(extraopts) --html %t" TeX-run-compile nil
(texinfo-mode) :help "Run Makeinfo with HTML output")
("AmSTeX" "amstex %(PDFout) %(extraopts) %`%S%(mode)%' %t"
TeX-run-TeX nil (ams-tex-mode) :help "Run AMSTeX")
;; support for ConTeXt --pg
;; first version of ConTeXt to support nonstopmode: 2003.2.10
("ConTeXt" "%(cntxcom) --once --texutil %(extraopts) %(execopts)%t"
TeX-run-TeX nil (context-mode) :help "Run ConTeXt once")
("ConTeXt Full" "%(cntxcom) %(extraopts) %(execopts)%t"
TeX-run-TeX nil
(context-mode) :help "Run ConTeXt until completion")
("BibTeX" "bibtex %s" TeX-run-BibTeX nil t :help "Run BibTeX")
("Biber" "biber %s" TeX-run-Biber nil t :help "Run Biber")
("View" "%V" TeX-run-discard-or-function t t :help "Run Viewer")
("Print" "%p" TeX-run-command t t :help "Print the file")
("Queue" "%q" TeX-run-background nil t :help "View the printer queue"
:visible TeX-queue-command)
("File" "%(o?)dvips %d -o %f " TeX-run-dvips t t
:help "Generate PostScript file")
("Dvips" "%(o?)dvips %d -o %f " TeX-run-dvips nil t
:help "Convert DVI file to PostScript")
("Dvipdfmx" "dvipdfmx %d" TeX-run-dvipdfmx nil t
:help "Convert DVI file to PDF with dvipdfmx")
("Ps2pdf" "ps2pdf %f" TeX-run-ps2pdf nil t
:help "Convert PostScript file to PDF")
("Index" "makeindex %s" TeX-run-index nil t
:help "Run makeindex to create index file")
("Xindy" "texindy %s" TeX-run-command nil t
:help "Run xindy to create index file")
("Check" "lacheck %s" TeX-run-compile nil (latex-mode)
:help "Check LaTeX file for correctness")
("ChkTeX" "chktex -v6 %s" TeX-run-compile nil (latex-mode)
:help "Check LaTeX file for common mistakes")
("Spell" "(TeX-ispell-document \"\")" TeX-run-function nil t
:help "Spell-check the document")
("Clean" "TeX-clean" TeX-run-function nil t
:help "Delete generated intermediate files")
("Clean All" "(TeX-clean t)" TeX-run-function nil t
:help "Delete generated intermediate and output files")
("Other" "" TeX-run-command t t :help "Run an arbitrary command"))
"List of commands to execute on the current document.
Each element is a list, whose first element is the name of the command
as it will be presented to the user.
The second element is the string handed to the shell after being
expanded. The expansion is done using the information found in
The third element is the function which actually start the process.
Several such hooks has been defined:
TeX-run-command: Start up the process and show the output in a
separate buffer. Check that there is not two commands running for the
same file. Return the process object.
TeX-run-format: As `TeX-run-command', but assume the output is created
by a TeX macro package. Return the process object.
TeX-run-TeX: For TeX output.
TeX-run-interactive: Run TeX or LaTeX interactively.
TeX-run-BibTeX: For BibTeX output.
TeX-run-Biber: For Biber output.
TeX-run-compile: Use `compile' to run the process.
TeX-run-shell: Use `shell-command' to run the process.
TeX-run-discard: Start the process in the background, discarding its
TeX-run-background: Start the process in the background, show output
in other window.
TeX-run-silent: Start the process in the background.
TeX-run-discard-foreground: Start the process in the foreground,
discarding its output.
TeX-run-function: Execute the Lisp function or function call
specified by the string in the second element. Consequently,
this hook does not start a process.
TeX-run-discard-or-function: If the command is a Lisp function,
execute it as such, otherwise start the command as a process,
discarding its output.
To create your own hook, define a function taking three arguments: The
name of the command, the command string, and the name of the file to
process. It might be useful to use `TeX-run-command' in order to
create an asynchronous process.
If the fourth element is non-nil, the user will get a chance to
modify the expanded string.
The fifth element indicates in which mode(s) the command should be
present in the Command menu. Use t if it should be active in any
mode. If it should only be present in some modes, specify a list with
the respective mode names.
Any additional elements get just transferred to the respective menu entries."
:group 'TeX-command
:type '(repeat (group :value ("" "" TeX-run-command nil t)
(string :tag "Name")
(string :tag "Command")
(choice :tag "How"
:value TeX-run-command
(function-item TeX-run-command)
(function-item TeX-run-format)
(function-item TeX-run-TeX)
(function-item TeX-run-interactive)
(function-item TeX-run-BibTeX)
(function-item TeX-run-Biber)
(function-item TeX-run-compile)
(function-item TeX-run-shell)
(function-item TeX-run-discard)
(function-item TeX-run-background)
(function-item TeX-run-silent)
(function-item TeX-run-discard-foreground)
(function-item TeX-run-function)
(function-item TeX-run-discard-or-function)
(function :tag "Other"))
(boolean :tag "Prompt")
(choice :tag "Modes"
(const :tag "All" t)
(set (const :tag "Plain TeX" plain-tex-mode)
(const :tag "LaTeX" latex-mode)
(const :tag "DocTeX" doctex-mode)
(const :tag "ConTeXt" context-mode)
(const :tag "Texinfo" texinfo-mode)
(const :tag "AmSTeX" ams-tex-mode)))
(repeat :tag "Menu elements" :inline t sexp))))
(defcustom TeX-command-output-list
; Add the following line if you want to use htlatex (tex4ht)
; ("\\`htlatex" ("html"))
"List of regexps and file extensions.
Each element is a list, whose first element is a regular expression to
match against the name of the command that will be used to process the TeX
The second element is either a string or a list with a string as element.
If it is a string this is the default file extension that will be expected
for output files that are produced by commands that match the first
element. The real file extension will be obtained from the logging output
if possible, defaulting to the given string.
If it is a list, the element of the list will be the fixed extension used
without looking at the logging output.
If this list does not yield an extension, the default is either \"dvi\"
or \"pdf\", depending on the setting of `TeX-PDF-mode'.
Extensions must be given without the \".\"."
:group 'TeX-command
:type '(repeat (group (regexp :tag "Command Regexp")
(choice (string :tag "Default Extension")
(group (string :tag "Fixed Extension"))))))
;; You may want to change the default LaTeX version for your site.
(defcustom LaTeX-version "2e"
"Default LaTeX version. Currently recognized is \"2\" and \"2e\"."
:group 'LaTeX
:type '(radio (const :format "%v\n%h"
:doc "\
The executable `latex' is LaTeX version 2."
(const :format "%v\n%h"
:doc "\
The executable `latex' is LaTeX version 2e."
(string :tag "Other")))
;; Use different compilation commands depending on style.
;; Only works if parsing is enabled.
(defcustom LaTeX-command-style
;; They have all been combined in LaTeX 2e.
'(("" "%(PDF)%(latex) %(file-line-error) %(extraopts) %S%(PDFout)"))
"List of style options and LaTeX commands.
If the first element (a regular expression) matches the name of one of
the style files, any occurrence of the string `%l' in a command in
`TeX-command-list' will be replaced with the second element. The first
match is used, if no match is found the `%l' is replaced with the empty
:group 'TeX-command
:type '(repeat (group :value ("" "")
regexp (string :tag "Style"))))
;; Printing: If you want to print, TeX-print-command must be non-nil
;; (if it is nil, you'll get a complaint when using the print menu).
;; If you want to view the queue, TeX-queue-command needs to be
;; non-nil (if it is nil, it won't get mentioned in the menu). If
;; TeX-printer-list is nil, nothing else gets asked: the menu entries
;; lead directly to the respective commands. If those commands
;; contain %p, the value of TeX-printer-default gets inserted there,
;; no questions asked. Now if TeX-printer-list is non-nil, you'll
;; always get asked which printer you want to use. You can enter a
;; configured printer from TeX-printer-list, or an unknown one. The
;; respective menus will show all configured printers. Since you can
;; enter unknown printers, the printer name _must_ be set with %p in
;; TeX-print-command.
(defcustom TeX-print-command
"{ test -e %s.dvi && %(o?)dvips -P%p %r %s; } || lpr -P%p %o"
"Command used to print a file.
First `%p' is expanded to the printer name, then ordinary expansion is
performed as specified in `TeX-expand-list'. If it is nil,
then customization is requested."
:group 'TeX-command
:type '(choice (string :tag "Print command")
(const :tag "No print command customized" nil)))
(defcustom TeX-queue-command "lpq -P%p"
"Command used to show the status of a printer queue.
First `%p' is expanded to the printer name, then ordinary expansion is
performed as specified in `TeX-expand-list'. If this is nil,
the printer has no corresponding command."
:group 'TeX-command
:type '(choice (string :tag "Queue check command")
(const :tag "No such command" nil)))
;; Enter the names of the printers available at your site, or nil if
;; you only have one printer.
(defcustom TeX-printer-list
;; Print to the (unnamed) default printer. If there is a DVI
;; file print via Dvips. If not, pass the output file (which
;; should then be a Postscript or PDF file) directly to lpr.
"{ test -e %s.dvi && %(o?)dvips -f %r %s | lpr; } || lpr %o"
;; Show the queue for the (unnamed) default printer.
"List of available printers.
The first element of each entry is the printer name.
The second element is the command used to print to this
printer. It defaults to the value of `TeX-print-command' when nil.
The third element is the command used to examine the print queue for
this printer. It defaults to the value of `TeX-queue-command' similarly.
Any occurrence of `%p' in the second or third element is expanded to
the printer name given in the first element, then ordinary expansion
is performed as specified in `TeX-expand-list'.
If this list is empty, only `TeX-print-command' and `TeX-queue-command'
get consulted."
:group 'TeX-command
:type '(repeat (group (string :tag "Name")
(option (group :inline t
:extra-offset -4
(choice :tag "Print"
(const :tag "default")
(string :format "%v"))
(option (choice :tag "Queue"
(const :tag "default")
:format "%v"))))))))
;; The name of the most used printer.
(defcustom TeX-printer-default (or (getenv "PRINTER")
(and TeX-printer-list
(car (car TeX-printer-list)))
"Default printer to use with `TeX-command'."
:group 'TeX-command
:type 'string)
(defcustom TeX-print-style '(("^landscape$" "-t landscape"))
"List of style options and print options.
If the first element (a regular expression) matches the name of one of
the style files, any occurrence of the string `%r' in a command in
`TeX-command-list' will be replaced with the second element. The first
match is used, if no match is found the `%r' is replaced with the empty
:group 'TeX-command
:type '(repeat (group regexp (string :tag "Command"))))
(defcustom TeX-command-extra-options ""
"String with the extra options to be given to the TeX processor."
:type 'string)
(make-variable-buffer-local 'TeX-command-extra-options)
;; This is the list of expansion for the commands in
;; TeX-command-list. Not likely to be changed, but you may e.g. want
;; to handle .ps files.
(defvar TeX-expand-list-builtin
'(("%q" (lambda ()
(TeX-printer-query t)))
("%V" (lambda ()
("%vv" (lambda ()
(TeX-output-style-check TeX-output-view-style)))
("%v" (lambda ()
(TeX-style-check TeX-view-style)))
("%r" (lambda ()
(TeX-style-check TeX-print-style)))
("%l" (lambda ()
(TeX-style-check LaTeX-command-style)))
("%(PDF)" (lambda ()
(if (and (eq TeX-engine 'default)
(if TeX-PDF-mode
(not (TeX-PDF-from-DVI))
("%(PDFout)" (lambda ()
(cond ((eq major-mode 'ams-tex-mode)
(if TeX-PDF-mode
" -output-format=pdf"
" -output-format=dvi"))
((and (eq TeX-engine 'xetex)
(not TeX-PDF-mode))
" -no-pdf")
((and (eq TeX-engine 'luatex)
(not TeX-PDF-mode))
" --output-format=dvi")
((and (eq TeX-engine 'default)
(not TeX-PDF-mode)
" \"\\pdfoutput=0 \"")
(t ""))))
("%(mode)" (lambda ()
(if TeX-interactive-mode
" -interaction=nonstopmode")))
(lambda () (if TeX-file-line-error " -file-line-error" "")))
("%(o?)" (lambda () (if (eq TeX-engine 'omega) "o" "")))
("%(tex)" (lambda () (eval (nth 2 (assq TeX-engine (TeX-engine-alist))))))
("%(latex)" (lambda () (eval (nth 3 (assq TeX-engine (TeX-engine-alist))))))
("%(cntxcom)" ConTeXt-expand-command)
("%(execopts)" ConTeXt-expand-options)
("%(extraopts)" (lambda () TeX-command-extra-options))
("%S" TeX-source-correlate-expand-options)
("%dS" TeX-source-specials-view-expand-options)
("%cS" TeX-source-specials-view-expand-client)
("%(outpage)" (lambda ()
;; When `TeX-source-correlate-output-page-function' is nil
;; and we are using synctex, fallback on
;; `TeX-synctex-output-page'.
(and TeX-source-correlate-mode
(null TeX-source-correlate-output-page-function)
(eq (TeX-source-correlate-method-active) 'synctex)
(setq TeX-source-correlate-output-page-function
(or (if TeX-source-correlate-output-page-function
(funcall TeX-source-correlate-output-page-function))
;; `file' means to call `TeX-master-file' or `TeX-region-file'
("%s" file nil t)
("%t" file t t)
("%`" (lambda nil
(setq TeX-command-pos t TeX-command-text "")))
(" \"\\" (lambda nil
(if (eq TeX-command-pos t)
(setq TeX-command-pos pos
pos (+ 3 pos))
(setq pos (1+ pos)))))
("\"" (lambda nil (if (numberp TeX-command-pos)
(setq TeX-command-text
(substring command
(1+ pos)))
(substring command
(substring command
(1+ pos)))
pos TeX-command-pos
TeX-command-pos t)
(setq pos (1+ pos)))))
("%'" (lambda nil
(if (stringp TeX-command-text)
(setq pos (+ pos (length TeX-command-text) 9)
(and (string-match " "
(funcall file t t))
(concat TeX-command-text " \"\\input\""))
(setq TeX-command-pos nil)
(setq TeX-command-text nil))))
("%n" TeX-current-line)
("%d" file "dvi" t)
("%f" file "ps" t)
("%o" (lambda nil (funcall file (TeX-output-extension) t)))
;; for source specials the file name generated for the xdvi
;; command needs to be relative to the master file, just in
;; case the file is in a different subdirectory
("%b" TeX-current-file-name-master-relative)
;; Okular forward PDF search requires absolute path.
("%a" (lambda nil (prin1-to-string (expand-file-name (buffer-file-name)))))
;; the following is for preview-latex.
("%m" preview-create-subdirectory))
"List of built-in expansion strings for TeX command names.
This should not be changed by the user who can use
`TeX-expand-list' variable. The latter variable also contains a
description of the data format.
Programs should not use these variables directly but the function
(defcustom TeX-expand-list nil
"List of expansion strings for TeX command names defined by the user.
Each entry is a list with two or more elements. The first
element is the string to be expanded. The second element is the
name of a function returning the expanded string when called with
the remaining elements as arguments. The special value `file'
will be expanded to the name of the file being processed, with an
optional extension.
Built-in expansions provided in `TeX-expand-list-builtin' can be
overwritten by defining expansions strings with the same
expander. Only \"%p\" expander cannot be overwritten.
Programs should not use these variables directly but the function
:group 'TeX-command
:type '(repeat (group (string :tag "Key")
(sexp :tag "Expander")
(repeat :inline t
:tag "Arguments"
(sexp :format "%v")))))
(defun TeX-expand-list ()
"Complete list of expansion strings for TeX command names.
Concatenate `TeX-expand-list' and `TeX-expand-list-bultin' making
sure \"%p\" is the first entry."
;; %p must be the first entry, see `TeX-print-command'.
'(("%p" TeX-printer-query))
;; The following dependencies are not done with autoload cookies since
;; they are only useful when tex.el is loaded, anyway. tex-buf.el
;; should remain unloaded as long as one is only editing files, so
;; requiring it here would be wrong.
(autoload 'TeX-region-create "tex-buf" nil nil)
(autoload 'TeX-save-document "tex-buf" nil t)
(autoload 'TeX-home-buffer "tex-buf" nil t)
(autoload 'TeX-pin-region "tex-buf" nil t)
(autoload 'TeX-command-region "tex-buf" nil t)
(autoload 'TeX-command-buffer "tex-buf" nil t)
(autoload 'TeX-command-master "tex-buf" nil t)
(autoload 'LaTeX-command-section "tex-buf" nil t)
(autoload 'TeX-command-run-all "tex-buf" nil t)
(autoload 'TeX-command-run-all-region "tex-buf" nil t)
(autoload 'LaTeX-command-run-all-section "tex-buf" nil t)
(autoload 'TeX-command "tex-buf" nil nil)
(autoload 'TeX-kill-job "tex-buf" nil t)
(autoload 'TeX-recenter-output-buffer "tex-buf" nil t)
(autoload 'TeX-next-error "tex-buf" nil t)
(autoload 'TeX-error-overview "tex-buf" nil t)
(autoload 'TeX-region-file "tex-buf" nil nil)
(autoload 'TeX-current-offset "tex-buf" nil nil)
(autoload 'TeX-process-set-variable "tex-buf" nil nil)
(autoload 'TeX-view "tex-buf" nil t)
;;; Portability.
(defmacro TeX--if-macro-fboundp (name then &rest else)
"Execute THEN if macro NAME is bound and ELSE otherwise.
(TeX--if-macro-fboundp name then else...)
is equivalent to
(if (fboundp 'name) then else...)
but takes care of byte-compilation issues where the byte-code for
the latter could signal an error if it has been compiled with
emacs 24.1 and is then later run by emacs 24.5."
(declare (indent 2) (debug (symbolp form)))
(if (fboundp name) ;If macro exists at compile-time, just use it.
`(if (fboundp ',name) ;Else, check if it exists at run-time.
(eval ',then) ;If it does, then run the then code.
,@else))) ;Otherwise, run the else code.
(require 'easymenu)
(if (featurep 'xemacs)
(defun TeX-maybe-remove-help (menu)
"Removes :help entries from menus, since XEmacs does not like them.
Also does other stuff."
(cond ((consp menu)
(cond ((eq (car menu) :help)
(TeX-maybe-remove-help (cddr menu)))
((eq (car menu) :visible)
(cons :included
(cons (cadr menu)
(TeX-maybe-remove-help (cddr menu)))))
(t (cons (TeX-maybe-remove-help (car menu))
(TeX-maybe-remove-help (cdr menu))))))
((vectorp menu)
(vconcat (TeX-maybe-remove-help (append menu nil))))
(t menu)))
(defun TeX-maybe-remove-help (menu)
"Compatibility function that would remove :help entries if on XEmacs,
but does nothing in Emacs."
(defmacro TeX-menu-with-help (menu)
"Compatibility macro that removes :help entries if on XEmacs.
Also does other stuff."
(TeX-maybe-remove-help menu)))
(defalias 'TeX-assoc-string
(symbol-function (if (featurep 'xemacs) 'assoc 'assoc-string)))
;;; Documentation for Info-goto-emacs-command-node and similar
(eval-after-load 'info '(dolist (elt '("TeX" "LaTeX" "ConTeXt" "Texinfo"
(add-to-list 'Info-file-list-for-emacs
(cons elt "AUCTeX"))))
(defadvice hack-one-local-variable (after TeX-hack-one-local-variable-after
"Call minor mode function if minor mode variable is found."
(let ((var (ad-get-arg 0))
(val (ad-get-arg 1)))
;; Instead of checking for each mode explicitely `minor-mode-list'
;; could be used. But this may make the byte compiler pop up.
(when (memq var '(TeX-PDF-mode
TeX-source-correlate-mode TeX-interactive-mode
TeX-fold-mode LaTeX-math-mode))
(if (symbol-value val) (funcall var 1) (funcall var 0)))))
(defvar TeX-overlay-priority-step 16
"Numerical difference of priorities between nested overlays.
The step should be big enough to allow setting a priority for new
overlays between two existing ones.")
;;; Special support for XEmacs
(when (featurep 'xemacs)
(defun TeX-read-string
(prompt &optional initial-input history default-value)
(condition-case nil
(read-string prompt initial-input history default-value t)
(read-string prompt initial-input history default-value))))
(defun TeX-mark-active ()
;; In Lucid (mark) returns nil when not active.
(if zmacs-regions
(mark t)))
(defun TeX-active-mark ()
(and zmacs-regions (mark)))
(fset 'TeX-activate-region (symbol-function 'zmacs-activate-region))
;; I am aware that this counteracts coding conventions but I am sick
;; of it.
(unless (fboundp 'line-beginning-position)
(defalias 'line-beginning-position 'point-at-bol))
(unless (fboundp 'line-end-position)
(defalias 'line-end-position 'point-at-eol))
(defun TeX-overlay-prioritize (start end)
"Calculate a priority for an overlay extending from START to END.
The calculated priority is lower than the minimum of priorities
of surrounding overlays and higher than the maximum of enclosed
(let (inner-priority outer-priority
(prios (cons nil nil)))
#'(lambda (ov prios)
(or (eq (extent-property ov 'category) 'TeX-fold)
(extent-property ov 'preview-state))
(setcar prios
(max (or (car prios) 0)
(extent-property ov 'priority))))
nil start end prios 'start-and-end-in-region 'priority)
#'(lambda (ov prios)
(or (eq (extent-property ov 'category) 'TeX-fold)
(extent-property ov 'preview-state))
(setcdr prios
(min (or (cdr prios) most-positive-fixnum)
(extent-property ov 'priority))))
nil start end prios
'(start-and-end-in-region negate-in-region) 'priority)
(setq inner-priority (car prios) outer-priority (cdr prios))
(cond ((and inner-priority (not outer-priority))
(+ inner-priority TeX-overlay-priority-step))
((and (not inner-priority) outer-priority)
(/ outer-priority 2))
((and inner-priority outer-priority)
(+ (/ (- outer-priority inner-priority) 2) inner-priority))
(t TeX-overlay-priority-step)))) )
;; require crm here, because we often do
;; (let ((crm-separator ","))
;; (TeX-completing-read-multiple ...))
;; which results in a void-variable error if crm hasn't been loaded before.
;; XEmacs 21.4 `require' doesn't have the third NOERROR argument, thus we handle
;; the file-error signal with a `condition-case' also in GNU Emacs.
(condition-case nil
(require 'crm)
(error "AUCTeX requires crm.el which is included in Emacs and
edit-utils >= 2.32 for XEmacs.")))
(if (fboundp 'completing-read-multiple)
(if (or (and (= emacs-major-version 24) (>= emacs-minor-version 4))
(>= emacs-major-version 25))
;; For GNU Emacs 24.4 or later, based on `completing-read-multiple' of
;; git commit b14abca9476cba2f500b5eda89441d593dd0f12b
;; 2013-01-10 * lisp/emacs-lisp/crm.el: Allow any regexp for separators.
(defun TeX-completing-read-multiple
(prompt table &optional predicate require-match initial-input
hist def inherit-input-method)
"Like `completing-read-multiple' which see.
Retain zero-length substrings but ensure that empty input results
in nil across different emacs versions."
(add-hook 'choose-completion-string-functions
(let* ((minibuffer-completion-table #'crm--collection-fn)
(minibuffer-completion-predicate predicate)
;; see completing_read in src/minibuf.c
(unless (eq require-match t) require-match))
(crm-completion-table table)
(map (if require-match
;; If the user enters empty input, `read-from-minibuffer'
;; returns the empty string, not DEF.
(input (read-from-minibuffer
prompt initial-input map
nil hist def inherit-input-method))
(and def (string-equal input "") (setq input def))
(if (equal (setq result (split-string input crm-separator))
(remove-hook 'choose-completion-string-functions
;; For GNU Emacs <= 24.3.
(defun TeX-completing-read-multiple
(prompt table &optional predicate require-match initial-input
hist def inherit-input-method)
"Like `completing-read-multiple' which see.
Ensures that empty input results in nil across different emacs versions."
(let ((result (completing-read-multiple prompt table predicate
require-match initial-input
hist def inherit-input-method)))
(if (equal result '("")) nil result))))
;; For XEmacs.
(defun TeX-completing-read-multiple
(prompt table &optional predicate require-match initial-input
hist def inherit-input-method)
"Poor mans implementation of Emacs' `completing-read-multiple' for XEmacs.
The XEmacs package edit-utils-2.32 includes `crm.el'."
(multi-prompt (if (boundp 'crm-separator) crm-separator ",") nil prompt
table predicate require-match initial-input hist)))
(if (fboundp 'line-number-at-pos)
(defalias 'TeX-line-number-at-pos 'line-number-at-pos)
;; `line-number-at-pos' from `simple.el' in Emacs CVS (2006-06-07)
(defun TeX-line-number-at-pos (&optional pos)
"Return (narrowed) buffer line number at position POS.
If POS is nil, use current buffer location."
(let ((opoint (or pos (point))) start)
(goto-char (point-min))
(setq start (point))
(goto-char opoint)
(forward-line 0)
(1+ (count-lines start (point)))))))
;;; Special support for GNU Emacs
(unless (featurep 'xemacs)
(defun TeX-read-string (prompt &optional initial-input history default-value)
(read-string prompt initial-input history default-value t))
(defun TeX-mark-active ()
;; In FSF 19 mark-active indicates if mark is active.
(defun TeX-active-mark ()
(and transient-mark-mode mark-active))
(defun TeX-activate-region ()
(setq deactivate-mark nil)
(if (fboundp 'activate-mark)
;; COMPATIBILITY for Emacs <= 22
;; This part is adopted from `activate-mark' of Emacs 24.5.
(when (mark t)
(unless (and transient-mark-mode mark-active
(force-mode-line-update) ;Refresh toolbar (bug#16382).
(setq mark-active t)
(unless transient-mark-mode
(setq transient-mark-mode 'lambda))
(if (boundp 'activate-mark-hook)
(run-hooks 'activate-mark-hook))))))
(defun TeX-overlay-prioritize (start end)
"Calculate a priority for an overlay extending from START to END.
The calculated priority is lower than the minimum of priorities
of surrounding overlays and higher than the maximum of enclosed
(let (outer-priority inner-priority ov-priority)
(dolist (ov (overlays-in start end))
(when (or (eq (overlay-get ov 'category) 'TeX-fold)
(overlay-get ov 'preview-state))
(setq ov-priority (overlay-get ov 'priority))
(if (>= (overlay-start ov) start)
(setq inner-priority (max ov-priority (or inner-priority
(setq outer-priority (min ov-priority (or outer-priority
(cond ((and inner-priority (not outer-priority))
(+ inner-priority TeX-overlay-priority-step))
((and (not inner-priority) outer-priority)
(/ outer-priority 2))
((and inner-priority outer-priority)
(+ (/ (- outer-priority inner-priority) 2) inner-priority))
(t TeX-overlay-priority-step)))) )
(defun TeX-delete-dups-by-car (alist &optional keep-list)
"Return a list of all elements in ALIST, but each car only once.
Elements of KEEP-LIST are not removed even if duplicate."
;; Copy of `reftex-uniquify-by-car' (written by David Kastrup).
(setq keep-list (sort (copy-sequence keep-list) #'string<))
(setq alist (sort (copy-sequence alist)
(lambda (a b)
(string< (car a) (car b)))))
(let ((new alist) elt)
(while new
(setq elt (caar new))
(while (and keep-list (string< (car keep-list) elt))
(setq keep-list (cdr keep-list)))
(unless (and keep-list (string= elt (car keep-list)))
(while (string= elt (car (cadr new)))
(setcdr new (cddr new))))
(setq new (cdr new))))
(defun TeX-delete-duplicate-strings (list)
"Return a list of all strings in LIST, but each only once."
(setq list (TeX-sort-strings list))
(let ((new list) elt)
(while new
(setq elt (car new))
(while (string= elt (cadr new))
(setcdr new (cddr new)))
(setq new (cdr new))))
(defun TeX-sort-strings (list)
"Return sorted list of all strings in LIST."
(sort (copy-sequence list) #'string<))
;;; Buffer
(defgroup TeX-output nil
"Parsing TeX output."
:prefix "TeX-"
:group 'AUCTeX)
(defcustom TeX-display-help t
"Control type of help display when stepping through errors with \\[TeX-next-error].
If t display help buffer. If nil display message about error in
echo area. If `expert' display output buffer with raw processor output."
:group 'TeX-output
:type '(choice (const :tag "Help buffer" t)
(const :tag "Echo area" nil)
(const :tag "Output buffer" expert)))
(defcustom TeX-debug-bad-boxes nil
"Non-nil means also find overfull/underfull box warnings with \\[TeX-next-error]."
:group 'TeX-output
:type 'boolean)
(defcustom TeX-debug-warnings nil
"Non-nil means also find LaTeX or package warnings with \\[TeX-next-error]."
:group 'TeX-output
:type 'boolean)
(defcustom TeX-ignore-warnings nil
"Controls which warnings are to be ignored.
It can be either a regexp matching warnings to be ignored, or a
symbol with the name of a custom function taking as arguments all
the information of the warning listed in `TeX-error-list', except
the last one about whether to ignore the warning.
If you want to use the custom function, see how it is used in the
code of `TeX-warning'."
:group 'TeX-command
:type '(choice (const :tag "Do not ignore anything" nil)
(string :tag "Regexp")
(symbol :tag "Function name")))
(defcustom TeX-suppress-ignored-warnings nil
"Whether to actually show ignored warnings.
Note that `TeX-debug-warnings' always takes the precedence."
:group 'TeX-command
:type 'boolean)
(defun TeX-toggle-debug-bad-boxes ()
"Toggle if the debugger should display \"bad boxes\" too."
(setq TeX-debug-bad-boxes (not TeX-debug-bad-boxes))
(message (concat "TeX-debug-bad-boxes: "
(if TeX-debug-bad-boxes "on" "off"))))
(defun TeX-toggle-debug-warnings ()
"Toggle if the debugger should display warnings too."
(setq TeX-debug-warnings (not TeX-debug-warnings))
(message (concat "TeX-debug-warnings: "
(if TeX-debug-warnings "on" "off"))))
(defun TeX-toggle-suppress-ignored-warnings ()
"Toggle if the debugger should display ignored warnings too.
See `TeX-suppress-ignored-warnings' and `TeX-ignore-warnings' for
more details."
(setq TeX-suppress-ignored-warnings (not TeX-suppress-ignored-warnings))
(message (concat "TeX-suppress-ignored-warnings: "
(if TeX-suppress-ignored-warnings "on" "off"))))
;;; Mode names.
(defvar TeX-base-mode-name nil
"Base name of mode.")
(make-variable-buffer-local 'TeX-base-mode-name)
(defun TeX-set-mode-name (&optional changed local reset)
"Build and set the mode name.
The base mode name will be concatenated with indicators for
helper modes where appropriate.
If CHANGED is non-nil, it indicates which global mode
may have changed so that all corresponding buffers
without a local value might get their name updated.
A value of t will thus update all buffer names.
If LOCAL is non-nil and CHANGED is buffer-local, only
a local change has been performed and only the local
name is to be updated.
If RESET is non-nil, `TeX-command-next' is reset to
`TeX-command-default' in updated buffers."
(if (and changed
(not (and local (local-variable-p changed (current-buffer)))))
(dolist (buffer (buffer-list))
(and (local-variable-p 'TeX-mode-p buffer)
(not (local-variable-p changed buffer))
(with-current-buffer buffer (TeX-set-mode-name nil nil reset))))
(if TeX-mode-p
(let ((trailing-flags
(and (boundp 'TeX-fold-mode) TeX-fold-mode "F")
(and (boundp 'LaTeX-math-mode) LaTeX-math-mode "M")
(and TeX-PDF-mode "P")
(and TeX-interactive-mode "I")
(and TeX-source-correlate-mode "S"))))
(setq mode-name (concat TeX-base-mode-name
(when (> (length trailing-flags) 0)
(concat "/" trailing-flags))))
(when reset
(TeX-process-set-variable (TeX-master-file)
'TeX-command-next TeX-command-default)
(TeX-process-set-variable (TeX-region-file)
'TeX-command-next TeX-command-default))
(set-buffer-modified-p (buffer-modified-p))))))
(defun TeX-mode-prefix (&optional mode)
"Return the prefix for the symbol MODE as string.
If no mode is given the current major mode is used."
(cdr (assoc (or mode major-mode) '((plain-tex-mode . "plain-TeX")
(latex-mode . "LaTeX")
(doctex-mode . "docTeX")
(texinfo-mode . "Texinfo")
(context-mode . "ConTeXt")))))
;;; Viewing
(defgroup TeX-view nil
"Calling viewers from AUCTeX."
:group 'TeX-command)
(defcustom TeX-view-style
"^" (regexp-opt '("a4paper" "a4dutch" "a4wide" "sem-a4")) "$")
"%(o?)xdvi %dS -paper a4 %d")
(,(concat "^" (regexp-opt '("a5paper" "a5comb")) "$")
"%(o?)xdvi %dS -paper a5 %d")
("^b5paper$" "%(o?)xdvi %dS -paper b5 %d")
("^letterpaper$" "%(o?)xdvi %dS -paper us %d")
("^legalpaper$" "%(o?)xdvi %dS -paper legal %d")
("^executivepaper$" "%(o?)xdvi %dS -paper 7.25x10.5in %d")
("^landscape$" "%(o?)xdvi %dS -paper a4r -s 0 %d")
;; The latest xdvi can show embedded postscript. If you don't
;; have that, uncomment next line.
;; ("^epsf$" "ghostview %f")
("." "%(o?)xdvi %dS %d"))
"List of style options and view options.
If the first element (a regular expression) matches the name of
one of the style files, any occurrence of the string `%v' in a
command in `TeX-command-list' will be replaced with the second
element. The first match is used, if no match is found the `%v'
is replaced with the empty string.
As a default, the \"View\" command in `TeX-command-list' is set
to `%V'. This means that `TeX-output-view-style' will be
consulted before `TeX-view-style'. Only if no match is found in
`TeX-output-view-style' the settings in `TeX-view-style' will be
considered. If you want to bypass `TeX-output-view-style', which
is not recommended because it is more powerful than
`TeX-view-style', use `%v' in the \"View\" command."
:group 'TeX-view
:type '(repeat (group regexp (string :tag "Command"))))
(defcustom TeX-output-view-style
`(("^dvi$" ("^landscape$" "^pstricks$\\|^pst-\\|^psfrag$")
"%(o?)dvips -t landscape %d -o && gv %f")
("^dvi$" "^pstricks$\\|^pst-\\|^psfrag$" "%(o?)dvips %d -o && gv %f")
("^dvi$" (,(concat
"^" (regexp-opt '("a4paper" "a4dutch" "a4wide" "sem-a4")) "$")
"%(o?)xdvi %dS -paper a4r -s 0 %d")
("^dvi$" ,(concat
"^" (regexp-opt '("a4paper" "a4dutch" "a4wide" "sem-a4")) "$")
"%(o?)xdvi %dS -paper a4 %d")
("^dvi$" (,(concat "^" (regexp-opt '("a5paper" "a5comb")) "$")
"%(o?)xdvi %dS -paper a5r -s 0 %d")
("^dvi$" ,(concat "^" (regexp-opt '("a5paper" "a5comb")) "$")
"%(o?)xdvi %dS -paper a5 %d")
("^dvi$" "^b5paper$" "%(o?)xdvi %dS -paper b5 %d")
("^dvi$" "^letterpaper$" "%(o?)xdvi %dS -paper us %d")
("^dvi$" "^legalpaper$" "%(o?)xdvi %dS -paper legal %d")
("^dvi$" "^executivepaper$" "%(o?)xdvi %dS -paper 7.25x10.5in %d")
("^dvi$" "." "%(o?)xdvi %dS %d")
("^pdf$" "." "xpdf -remote %s -raise %o %(outpage)")
("^html?$" "." "netscape %o"))
"List of output file extensions and view options.
If the first element (a regular expression) matches the output
file extension, and the second element (a regular expression)
matches the name of one of the style options, any occurrence of
the string `%V' in a command in `TeX-command-list' will be
replaced with the third element. The first match is used; if no
match is found the `%V' is replaced with `%v'. The outcome of `%v'
is determined by the settings in `TeX-view-style' which therefore
serves as a fallback for `TeX-output-view-style'. The second
element may also be a list of regular expressions, in which case
all the regular expressions must match for the element to apply."
:group 'TeX-view
:type '(repeat (group
(regexp :tag "Extension")
(choice regexp (repeat :tag "List" regexp))
(string :tag "Command"))))
;;; Viewing (new implementation)
(defvar TeX-view-predicate-list-builtin
(string-match "dvi" (TeX-output-extension)))
(string-match "pdf" (TeX-output-extension)))
(string-match "html" (TeX-output-extension)))
;; Compatibility for Emacs <= 22: older Emacsen don't have FRAME argument
;; to `getenv', later versions have the `display-graphic-p' function.
(not (if (< emacs-major-version 23)
(or window-system (getenv "DISPLAY"))
(TeX-match-style "^pstricks$\\|^pst-\\|^psfrag$"))
(eq TeX-engine 'omega))
(eq TeX-engine 'xetex))
(TeX-match-style "\\`landscape\\'"))
(not (TeX-match-style "\\`landscape\\'")))
(TeX-match-style "\\`a4paper\\|a4dutch\\|a4wide\\|sem-a4\\'"))
(TeX-match-style "\\`a5paper\\|a5comb\\'"))
(TeX-match-style "\\`b5paper\\'"))
(TeX-match-style "\\`letterpaper\\'"))
(TeX-match-style "\\`legalpaper\\'"))
(TeX-match-style "\\`executivepaper\\'")))
"Alist of built-in predicates for viewer selection and invocation.
See the doc string of `TeX-view-predicate-list' for a short
description of each predicate.")
(defcustom TeX-view-predicate-list nil
"Alist of predicates for viewer selection and invocation.
The key of each list item is a symbol and the value a Lisp form
to be evaluated. The form should return nil if the predicate is
not fulfilled.
Built-in predicates provided in `TeX-view-predicate-list-builtin'
can be overwritten by defining predicates with the same symbol.
The following built-in predicates are available:
`output-dvi': The output is a DVI file.
`output-pdf': The output is a PDF file.
`output-html': The output is an HTML file.
`style-pstricks': The document loads a PSTricks package.
`engine-omega': The Omega engine is used for typesetting.
`engine-xetex': The XeTeX engine is used for typesetting.
`mode-io-correlate': TeX Source Correlate mode is active.
`paper-landscape': The document is typeset in landscape orientation.
`paper-portrait': The document is not typeset in landscape orientation.
`paper-a4': The paper format is A4.
`paper-a5': The paper format is A5.
`paper-b5': The paper format is B5.
`paper-letter': The paper format is letter.
`paper-legal': The paper format is legal.
`paper-executive': The paper format is executive."
:group 'TeX-view
:type '(alist :key-type symbol :value-type (group sexp)))
;; XXX: Atril is a fork of Evince and shares an almost identical interface with
;; it. Instead of having different functions for each program, we keep the
;; original *-evince-* functions and make them accept arguments to specify the
;; actual name of the program and the desktop environment, that will be used to
;; set up DBUS communication.
;; Require dbus at compile time to prevent errors due to `dbus-ignore-errors'
;; not being defined.
(eval-when-compile (and (featurep 'dbusbind)
(require 'dbus nil :no-error)))
(defun TeX-evince-dbus-p (de app &rest options)
"Return non-nil, if atril or evince are installed and accessible via DBUS.
Additional OPTIONS may be given to extend the check. If none are
given, only the minimal requirements needed by backward search
are checked. If OPTIONS include `:forward', which is currently
the only option, then additional requirements needed by forward
search are checked, too.
DE is the name of the desktop environment, either \"gnome\" or
\"mate\", APP is the name of viewer, either \"evince\" or
(let ((dbus-debug nil))
(and (featurep 'dbusbind)
(require 'dbus nil :no-error)
(dbus-ignore-errors (dbus-get-unique-name :session))
(dbus-ping :session (format "org.%s.%s.Daemon" de app))
(executable-find app)
(or (not (memq :forward options))
(let ((spec (dbus-introspect-get-method
:session (format "org.%s.%s.Daemon" de app)
(format "/org/%s/%s/Daemon" de app)
(format "org.%s.%s.Daemon" de app)
;; FindDocument must exist, and its signature must be (String,
;; Boolean, String). Evince versions between 2.30 and 2.91.x
;; didn't have the Boolean spawn argument we need to start evince
;; initially.
(and spec
(equal '("s" "b" "s")
(delq nil (mapcar (lambda (elem)
(when (and (listp elem)
(eq (car elem) 'arg))
(cdr (caar (cdr elem)))))
(defun TeX-pdf-tools-sync-view ()
"Focus the focused page/paragraph in `pdf-view-mode'.
If `TeX-source-correlate-mode' is disabled, only find and pop to
the output PDF file. Used by default for the PDF Tools viewer
entry in `TeX-view-program-list-builtin'."
(unless (featurep 'pdf-tools)
(error "PDF Tools are not installed"))
(unless TeX-PDF-mode
(error "PDF Tools only work with PDF output"))
(add-hook 'pdf-sync-backward-redirect-functions
(if (and TeX-source-correlate-mode
(fboundp 'pdf-sync-forward-search))
(with-current-buffer (or (when TeX-current-process-region-p
(get-file-buffer (TeX-region-file t)))
(let ((pdf (concat file "." (TeX-output-extension))))
(pop-to-buffer (or (find-buffer-visiting pdf)
(find-file-noselect pdf))))))
(defvar url-unreserved-chars)
(defun TeX-evince-sync-view-1 (de app)
"Focus the focused page/paragraph in Evince with the position
of point in emacs by using Evince's DBUS API. Used by default
for the Atril or Evince entries in
`TeX-view-program-list-builtin' if the requirements are met.
DE is the name of the desktop environment, either \"gnome\" or
\"mate\", APP is the name of viewer, either \"evince\" or
(require 'url-util)
(let* ((uri (concat "file://" (url-encode-url
(concat file "." (TeX-output-extension))))))
(owner (dbus-call-method
:session (format "org.%s.%s.Daemon" de app)
(format "/org/%s/%s/Daemon" de app)
(format "org.%s.%s.Daemon" de app)
(if owner
(with-current-buffer (or (when TeX-current-process-region-p
(get-file-buffer (TeX-region-file t)))
:session owner
(format "/org/%s/%s/Window/0" de app)
(format "org.%s.%s.Window" de app)
(list :struct :int32 (line-number-at-pos)
:int32 (1+ (current-column)))
:uint32 0))
(error "Couldn't find the %s instance for %s" (capitalize app) uri))))
(defun TeX-atril-sync-view ()
"Run `TeX-evince-sync-view-1', which see, set up for Atril."
(TeX-evince-sync-view-1 "mate" "atril"))
(defun TeX-evince-sync-view ()
"Run `TeX-evince-sync-view-1', which see, set up for Evince."
(TeX-evince-sync-view-1 "gnome" "evince"))
(defun TeX-view-program-select-evince (de app)
"Select how to call the Evince-like viewer.
DE is the name of the desktop environment, either \"gnome\" or
\"mate\", APP is the name of viewer, either \"evince\" or
(if (TeX-evince-dbus-p de app :forward)
(intern (format "TeX-%s-sync-view" app))
`(,app (mode-io-correlate
;; With evince 3, -p N opens the page *labeled* N,
;; and -i,--page-index the physical page N.
,(if (string-match "--page-index"
(shell-command-to-string (concat app " --help")))
" -i %(outpage)"
" -p %(outpage)")) " %o")))
(defvar TeX-view-program-list-builtin
((eq system-type 'windows-nt)
'(("Yap" ("yap -1" (mode-io-correlate " -s %n%b") " %o") "yap")
("dviout" ("dviout -1 "
((paper-a4 paper-portrait) "-y=A4 ")
((paper-a4 paper-landscape) "-y=A4L ")
((paper-a5 paper-portrait) "-y=A5 ")
((paper-a5 paper-landscape) "-y=A5L ")
((paper-b5 paper-portrait) "-y=E5 ")
((paper-b5 paper-landscape) "-y=E5L ")
((paper-b4jis paper-portrait) "-y=B4 ")
((paper-b4jis paper-landscape) "-y=B4L ")
((paper-b5jis paper-portrait) "-y=B5 ")
((paper-b5jis paper-landscape) "-y=B5L ")
(paper-legal "-y=Legal ")
(paper-letter "-y=Letter ")
(paper-executive "-y=Executive ")
"%d" (mode-io-correlate " \"# %n '%b'\"")) "dviout")
("SumatraPDF -reuse-instance"
(mode-io-correlate " -forward-search \"%b\" %n") " %o")
("dvips and start" "dvips %d -o && start \"\" %f" "dvips")
("start" "start \"\" %o")))
((eq system-type 'darwin)
'(("Preview.app" "open -a Preview.app %o" "open")
("Skim" "open -a Skim.app %o" "open")
("displayline" "displayline %n %o %b" "displayline")
("open" "open %o" "open")))
`(("dvi2tty" ("dvi2tty -q -w 132 %o"))
("xdvi" ("%(o?)xdvi"
(mode-io-correlate " -sourceposition \"%n %b\" -editor \"%cS\"")
((paper-a4 paper-portrait) " -paper a4")
((paper-a4 paper-landscape) " -paper a4r")
((paper-a5 paper-portrait) " -paper a5")
((paper-a5 paper-landscape) " -paper a5r")
(paper-b5 " -paper b5")
(paper-letter " -paper us")
(paper-legal " -paper legal")
(paper-executive " -paper 7.25x10.5in")
" %d") "%(o?)xdvi")
("dvips and gv" "%(o?)dvips %d -o && gv %f" ,(list "%(o?)dvips" "gv"))
("gv" "gv %o" "gv")
("xpdf" ("xpdf -remote %s -raise %o" (mode-io-correlate " %(outpage)")) "xpdf")
("Evince" ,(TeX-view-program-select-evince "gnome" "evince") "evince")
("Atril" ,(TeX-view-program-select-evince "mate" "atril") "atril")
("Okular" ("okular --unique %o" (mode-io-correlate "#src:%n%a")) "okular")
("xdg-open" "xdg-open %o" "xdg-open")
("PDF Tools" TeX-pdf-tools-sync-view)
("zathura %o"
" --synctex-forward %n:0:%b -x \"emacsclient +%{line} %{input}\""))
"Alist of built-in viewer specifications.
This variable should not be changed by the user who can use
`TeX-view-program-list' to add new viewers or overwrite the
definition of built-in ones. The latter variable also contains a
description of the data format.")
(defcustom TeX-view-program-list nil
"List of viewer specifications.
This variable can be used to specify how a viewer is to be
invoked and thereby add new viewers on top of the built-in list
of viewers defined in `TeX-view-program-list-builtin' or override
entries in the latter.
The car of each item is a string with a user-readable name. The
second element can be a command line to be run as a process or a
Lisp function to be executed. The command line can either be
specified as a single string or a list of strings and two-part
lists. The first element of the two-part lists is a symbol or a
list of symbols referring to one or more of the predicates in
`TeX-view-predicate-list' or `TeX-view-predicate-list-builtin'.
The second part of the two-part lists is a command line part.
The command line for the viewer is constructed by concatenating
the command line parts. Parts with a predicate are only
considered if the predicate was evaluated with a positive result.
Note that the command line can contain placeholders as defined in
`TeX-expand-list' which are expanded before the viewer is called.
The third element of the item is optional and is a string, or a
list of strings, with the name of the executable, or executables,
needed to open the output file in the viewer. Placeholders
defined in `TeX-expand-list' can be used here. This element is
used to check whether the viewer is actually available on the
The use of a function as the second element only works if the
View command in `TeX-command-list' makes use of the hook
Note: Predicates defined in the current Emacs session will only
show up in the customization interface for this variable after
restarting Emacs."
:group 'TeX-view
(string :tag "Name")
(group :tag "Command" (string :tag "Command"))
(group :inline t :tag "Command parts"
:tag "Command parts"
(string :tag "Command part")
(list :tag "Predicate and command part"
,(let (list)
;; Build the list of available predicates.
(mapc (lambda (spec)
(add-to-list 'list `(const ,(car spec))))
(append TeX-view-predicate-list
;; Sort the list alphabetically.
(setq list (sort list
(lambda (a b)
(downcase (symbol-name (cadr a)))
(downcase (symbol-name (cadr b)))))))
(choice :tag "Predicate" ,@list)
(repeat :tag "List of predicates"
(choice :tag "Predicate" ,@list))))
(string :tag "Command part")))))
(group :tag "Function" function))
(choice :tag "Viewer executable(s)"
(string :tag "One executable")
(repeat :tag "List of executables" (string :tag "Name"))
(const :tag "No executable" nil)))))
(defcustom TeX-view-program-selection
((eq system-type 'windows-nt)
'(((output-dvi style-pstricks) "dvips and start")
(output-dvi "Yap")
(output-pdf "start")
(output-html "start")))
((eq system-type 'darwin)
'((output-dvi "open")
(output-pdf "open")
(output-html "open")))
'(((output-dvi has-no-display-manager) "dvi2tty")
((output-dvi style-pstricks) "dvips and gv")
(output-dvi "xdvi")
(output-pdf "Evince")
(output-html "xdg-open"))))
"Alist of predicates and viewers.
Each entry consists of a list with two elements. The first
element is a symbol or list of symbols referring to predicates as
defined in `TeX-view-predicate-list' or
`TeX-view-predicate-list-builtin'. The second element is a
string referring to the name of a viewer as defined in
`TeX-view-program-list' or `TeX-view-program-list-builtin'.
\(Note: Viewers added to `TeX-view-program-list' in the current
Emacs session will not show up in the customization interface of
`TeX-view-program-selection' until you restart Emacs.)
When a viewer is called for, the entries are evaluated in turn
and the viewer related to the first entry all predicates of which
are evaluated positively is chosen."
:group 'TeX-view
:type `(alist :key-type
;; Offer list of defined predicates.
,(let (list)
(mapc (lambda (spec)
(add-to-list 'list `(const ,(car spec))))
(append TeX-view-predicate-list
(setq list (sort list
(lambda (a b)
(downcase (symbol-name (cadr a)))
(downcase (symbol-name (cadr b)))))))
`(choice (choice :tag "Single predicate" ,@list)
(repeat :tag "Multiple predicates"
(choice ,@list))))
;; Offer list of defined viewers.
(group (choice :tag "Viewer"
,@(let (list)
(mapc (lambda (spec)
(add-to-list 'list
`(const ,(car spec))))
(append TeX-view-program-list
(sort list
(lambda (a b)
(string< (downcase (cadr a))
(downcase (cadr b))))))))))
(defun TeX-match-style (regexp)
"Check if a style matching REGEXP is active."
(TeX-member regexp (TeX-style-list) 'string-match))
(defun TeX-view-match-predicate (predicate)
"Check if PREDICATE is true.
PREDICATE can be a symbol or a list of symbols defined in
`TeX-view-predicate-list-builtin' or `TeX-view-predicate-list'.
In case of a single symbol, return t if the predicate is true,
nil otherwise. In case of a list of symbols, return t if all
predicates are true, nil otherwise."
(let ((pred-symbols (if (listp predicate) predicate (list predicate)))
(pred-defs (append TeX-view-predicate-list
(result t)
(while (and (setq elt (pop pred-symbols)) result)
(unless (eval (cadr (assq elt pred-defs)))
(setq result nil)))
(defun TeX-view-command-raw ()
"Choose a viewer and return its unexpanded command string."
(let ((selection TeX-view-program-selection)
entry viewer item executable spec command)
;; Find the appropriate viewer.
(while (and (setq entry (pop selection)) (not viewer))
(when (TeX-view-match-predicate (car entry))
(setq viewer (cadr entry))))
(unless viewer
(error "No matching viewer found"))
(setq item (assoc viewer (append TeX-view-program-list
;; Get the command line or function spec.
spec (cadr item)
;; Get the name of the executable(s) associated to the viewer.
executable (nth 2 item))
;; Check the executable exists.
(unless (or (null executable)
((stringp executable)
(executable-find (TeX-command-expand executable nil)))
((listp executable)
(catch 'notfound
(dolist (exec executable t)
(unless (executable-find (TeX-command-expand exec nil))
(throw 'notfound nil)))))))
(error (format "Cannot find %S viewer. \
Select another one in `TeX-view-program-selection'" viewer)))
(cond ((functionp spec)
;; Converting the function call to a string is ugly, but
;; the backend currently only supports strings.
(prin1-to-string spec))
((stringp spec)
((null spec)
(format "Unknown %S viewer. \
Check the `TeX-view-program-selection' variable" viewer)))
;; Build the unexpanded command line. Pieces with predicates are
;; only added if the predicate is evaluated positively.
(dolist (elt spec)
(cond ((stringp elt)
(setq command (concat command elt)))
((listp elt)
(when (TeX-view-match-predicate (car elt))
(setq command (concat command (cadr elt)))))))
(if (stringp command)
;; Signal an error if `command' isn't a string. This prevents an
;; infinite loop in `TeX-command-expand' if `command' is nil.
(error "Wrong viewer specification in `TeX-view-program-list'"))))))
;;; Engine
(defvar TeX-engine-alist-builtin
'((default "Default" TeX-command LaTeX-command ConTeXt-engine)
(xetex "XeTeX" "xetex" "xelatex" "xetex")
;; Some lualatex versions before 0.71 would use "texput" as file
;; name if --jobname were not supplied
(luatex "LuaTeX" "luatex" "lualatex --jobname=%s" "luatex")
(omega "Omega" TeX-Omega-command LaTeX-Omega-command ConTeXt-Omega-engine))
"Alist of built-in TeX engines and associated commands.
For a description of the format see `TeX-engine-alist'.")
(defcustom TeX-engine-alist nil
"Alist of TeX engines and associated commands.
Each entry is a list with a maximum of five elements. The first
element is a symbol used to identify the engine. The second is a
string describing the engine. The third is the command to be
used for plain TeX. The fourth is the command to be used for
LaTeX. The fifth is the command to be used for the --engine
parameter of ConTeXt's texexec program. Each command can either
be a variable or a string. An empty string or nil means there is
no command available.
You can override a built-in engine defined in the variable
`TeX-engine-alist-builtin' by adding an entry beginning with the
same symbol as the built-in entry to `TeX-engine-alist'."
:group 'TeX-command
:type '(repeat (group symbol
(string :tag "Name")
(choice :tag "Plain TeX command" string variable)
(choice :tag "LaTeX command" string variable)
(choice :tag "ConTeXt command" string variable))))
(defun TeX-engine-alist ()
"Return an alist of TeX engines.
The function appends the built-in engine specs from
`TeX-engine-alist-builtin' and the user-defined engines from
`TeX-engine-alist' and deletes any entries from the built-in part
where an entry with the same car exists in the user-defined part."
(TeX-delete-dups-by-car (append TeX-engine-alist TeX-engine-alist-builtin)))
(defcustom TeX-engine 'default
(concat "Type of TeX engine to use.
It should be one of the following symbols:\n\n"
(mapconcat (lambda (x) (format "* `%s'" (car x)))
(TeX-engine-alist) "\n"))
:group 'TeX-command
:type `(choice ,@(mapcar (lambda (x)
`(const :tag ,(nth 1 x) ,(car x)))
(make-variable-buffer-local 'TeX-engine)
(put 'TeX-engine 'safe-local-variable
(lambda (arg) (memq arg (mapcar 'car TeX-engine-alist-builtin))))
(defun TeX-engine-set (type)
"Set TeX engine to TYPE.
For available TYPEs, see variable `TeX-engine'."
(interactive (list (completing-read "Engine: "
(mapcar (lambda (x)
(symbol-name (car x)))
nil t)))
(when (stringp type)
(setq type (intern type)))
(setq TeX-engine type)
;; Automatically enable or disable TeX PDF mode as a convenience
(cond ((eq type 'xetex) (TeX-PDF-mode 1))
((eq type 'omega) (TeX-PDF-mode 0))))
(define-minor-mode TeX-Omega-mode
"Minor mode for using the Omega engine."
nil nil nil
:group 'TeX-command
(TeX-engine-set (if TeX-Omega-mode 'omega 'default)))
(defalias 'tex-omega-mode 'TeX-Omega-mode)
(make-obsolete 'TeX-Omega-mode 'TeX-engine-set "11.86")
(make-obsolete-variable 'TeX-Omega-mode 'TeX-engine "11.86")
;;; Forward and inverse search
(defcustom TeX-source-correlate-method
'((dvi . source-specials) (pdf . synctex))
"Method to use for enabling forward and inverse search.
This can be `source-specials' if source specials should be used,
`synctex' if SyncTeX should be used, or `auto' if AUCTeX should
The previous values determine the variable for both DVI and PDF
mode. This variable can also be an alist of the kind
((dvi . <source-specials or synctex>)
(pdf . <source-specials or synctex>))
in which the CDR of each entry is a symbol specifying the method
to be used in the corresponding mode.
Programs should not use this variable directly but the function
`TeX-source-correlate-method-active' which returns the method
actually used for forward and inverse search."
:type '(choice (const auto)
(const synctex)
(const source-specials)
(list :tag "Different method for DVI and PDF"
(cons (const dvi)
(choice :tag "Method for DVI mode"
(const synctex)
(const source-specials)))
(cons (const pdf)
(choice :tag "Method for PDF mode"
(const synctex)
(const source-specials)))))
:group 'TeX-view)
(defvar TeX-source-correlate-output-page-function nil
"Symbol of function returning an output page relating to buffer position.
The function should take no arguments and return the page numer
as a string.")
(make-variable-buffer-local 'TeX-source-correlate-output-page-function)
(defcustom TeX-source-correlate-start-server 'ask
"Control if server should be started for inverse search."
:type '(choice (const :tag "Always" t)
(const :tag "Never" nil)
(const :tag "Ask" ask))
:group 'TeX-view)
(when (fboundp 'defvaralias)
(defvaralias 'TeX-source-specials-view-start-server
(defvar TeX-source-correlate-start-server-asked nil
"Keep track if question about server start search was asked.")
(defvar TeX-source-correlate-start-server-flag nil
"If non-nil, `TeX-source-correlate-start-server-maybe' will start a server.
Code related to features requiring a server, e.g. for inverse
search, can set the variable.")
(defun TeX-source-correlate-gnuserv-p ()
"Guess whether to use gnuserv when a server is requested."
(cond ((and (boundp 'gnuserv-process)
(processp gnuserv-process)))
((and (boundp 'server-process)
(processp server-process))
((featurep 'xemacs))))
(defun TeX-source-correlate-server-enabled-p ()
"Return non-nil if Emacs server or gnuserv is enabled."
(let* ((gnuserv-p (TeX-source-correlate-gnuserv-p))
(process (if gnuserv-p 'gnuserv-process 'server-process)))
(and (boundp process) (processp (symbol-value process)))))
(defun TeX-source-correlate-start-server-maybe ()
"Start Emacs server or gnuserv if a feature using it is enabled.
This is the case if `TeX-source-correlate-start-server-flag' is non-nil."
(when (and TeX-source-correlate-start-server-flag
(not (TeX-source-correlate-server-enabled-p)))
(let* ((gnuserv-p (TeX-source-correlate-gnuserv-p))
(start (if gnuserv-p 'gnuserv-start 'server-start)))
;; Server should be started unconditionally
((eq TeX-source-correlate-start-server t)
(funcall start))
;; Ask user if server is to be started
((and (eq TeX-source-correlate-start-server 'ask)
(not TeX-source-correlate-start-server-asked)
(y-or-n-p (format "Start %s for inverse search in viewer? "
(if gnuserv-p
"Emacs server")))
(setq TeX-source-correlate-start-server-asked t)))
(funcall start))))))
(defun TeX-source-correlate-determine-method ()
"Determine which method is available for forward and inverse search."
(let ((help (condition-case nil
(call-process LaTeX-command
nil (list standard-output nil) nil "--help"))
(error ""))))
(if (string-match "^[ ]*-?-synctex" help)
(defun TeX-source-correlate-method-active ()
"Return the method actually used for forward and inverse search."
((eq TeX-source-correlate-method 'auto)
((listp TeX-source-correlate-method)
(if TeX-PDF-mode
(cdr (assoc 'pdf TeX-source-correlate-method))
(cdr (assoc 'dvi TeX-source-correlate-method))))
(defun TeX-source-correlate-expand-options ()
"Return TeX engine command line option for forward search facilities.
The return value depends on the value of `TeX-source-correlate-mode'.
If this is nil, an empty string will be returned."
(if TeX-source-correlate-mode
(if (eq (TeX-source-correlate-method-active) 'source-specials)
(concat TeX-source-specials-tex-flags
(if TeX-source-specials-places
;; -src-specials=WHERE: insert source specials
;; in certain places of the DVI file. WHERE is a
;; comma-separated value list: cr display hbox
;; math par parend vbox
(concat "=" (mapconcat 'identity
TeX-source-specials-places ","))))
(defvar TeX-source-correlate-map
(let ((map (make-sparse-keymap)))
;; (if (featurep 'xemacs)
;; (define-key map [(control button1)] #'TeX-view-mouse)
;; (define-key map [C-down-mouse-1] #'TeX-view-mouse))
"Keymap for `TeX-source-correlate-mode'.
You could use this for unusual mouse bindings.")
(defun TeX-source-correlate-handle-TeX-region (file line col)
"Translate backward search info with respect to `TeX-region'.
That is, if FILE is `TeX-region', update FILE to the real tex
file and LINE to (+ LINE offset-of-region). Else, return nil."
(when (string-equal TeX-region (file-name-sans-extension
(file-name-nondirectory file)))
(with-current-buffer (or (find-buffer-visiting file)
(find-file-noselect file))
(goto-char 0)
;; Same regexp used in `preview-parse-messages'. XXX: XEmacs doesn't
;; support regexp classes, so we can't use "[:digit:]" here.
(when (re-search-forward "!offset(\\([---0-9]+\\))" nil t)
(let ((offset (string-to-int (match-string-no-properties 1))))
(when TeX-region-orig-buffer
(list (expand-file-name (buffer-file-name TeX-region-orig-buffer))
(+ line offset) col)))))))
(defun TeX-source-correlate-sync-source (file linecol &rest ignored)
"Show TeX FILE with point at LINECOL.
This function is called when emacs receives a SyncSource signal
emitted from the Evince document viewer. IGNORED absorbs an
unused id field accompanying the DBUS signal sent by Evince-3.0.0
or newer."
;; FILE may be given as relative path to the TeX-master root document or as
;; absolute file:// URL. In the former case, the tex file has to be already
;; opened.
(let* ((file (condition-case nil
(require 'url-parse)
(require 'url-util)
(url-unhex-string (aref (url-generic-parse-url file) 6)))
;; For Emacs 21 compatibility, which doesn't have the
;; url package.
(file-error (replace-regexp-in-string "^file://" "" file))))
(flc (or (apply #'TeX-source-correlate-handle-TeX-region file linecol)
(apply #'list file linecol)))
(file (car flc))
(line (cadr flc))
(col (nth 2 flc)))
(pop-to-buffer (or (find-buffer-visiting file)
(find-file-noselect file)))
(push-mark nil 'nomsg)
(let ((pos
(when (> line 0)
(goto-char 1)
(forward-line (1- line))
(when (> col 0)
(forward-char (1- col)))
(when pos
(when (or (< pos (point-min))
(> pos (point-max)))
(goto-char pos)))))
(define-minor-mode TeX-source-correlate-mode
"Minor mode for forward and inverse search.
If enabled, the viewer can be advised to show the output page
corresponding to the point in the source and vice versa.
The method to be used can be controlled with the variable
`TeX-source-correlate-method'. Currently source specials or
SyncTeX are recognized."
:group 'TeX-view
;; Since this is a global minor mode and we don't want to require
;; tex.el when the mode variable is set, the mode function is called
;; explicitely (if necessary) in `VirTeX-common-initialization'. We
;; do it there because otherwise `kill-all-local-variables' would
;; reset `TeX-source-correlate-output-page-function' which is
;; buffer-local.
:global t
(set-keymap-parent TeX-mode-map (and TeX-source-correlate-mode
(TeX-set-mode-name 'TeX-source-correlate-mode t t)
(setq TeX-source-correlate-start-server-flag TeX-source-correlate-mode)
;; Register Emacs for the SyncSource DBUS signal emitted by Evince or Atril.
(dolist (de-app '(("gnome" "evince") ("mate" "atril")))
(when (TeX-evince-dbus-p (car de-app) (cadr de-app))
:session nil (format "/org/%s/%s/Window/0" (car de-app) (cadr de-app))
(format "org.%s.%s.Window" (car de-app) (cadr de-app))
(defalias 'TeX-source-specials-mode 'TeX-source-correlate-mode)
(make-obsolete 'TeX-source-specials-mode 'TeX-source-correlate-mode "11.86")
(defalias 'tex-source-correlate-mode 'TeX-source-correlate-mode)
(put 'TeX-source-correlate-mode 'safe-local-variable 'TeX-booleanp)
;; We do not want the custom variable to require tex.el. This is only
;; necessary if AUCTeX was compiled with Emacs 21.
(put 'TeX-source-correlate-mode 'custom-requests nil)
(setq minor-mode-map-alist
(delq (assq 'TeX-source-correlate-mode minor-mode-map-alist)
;;; Source Specials
(defcustom TeX-source-specials-tex-flags "-src-specials"
"Extra flags to pass to TeX commands to generate source specials."
:group 'TeX-view
:type 'string)
(defcustom TeX-source-specials-places nil
"List of places where to insert source specials into the DVI file.
If nil, use (La)TeX's defaults."
:group 'TeX-view
:type '(list (set :inline t
;; :tag "Options known to work"
;; cr display hbox math par parend vbox
(const "cr")
(const "display")
(const "hbox")
(const "math")
(const "par")
(const "parend")
(const "vbox"))
(repeat :inline t
:tag "Other options"
(defcustom TeX-source-specials-view-position-flags
"-sourceposition \"%n %b\""
"Flags to pass to the DVI viewer commands for the position in the source."
:group 'TeX-view
:type 'string)
(defcustom TeX-source-specials-view-editor-flags
"-editor \"%cS\""
"Flags to pass to DVI viewer commands for inverse search."
:group 'TeX-view
:type 'string)
(defcustom TeX-source-specials-view-gnuclient-flags
"-q +%%l %%f"
"Flags to pass to gnuclient for inverse search."
:group 'TeX-view
:type 'string)
(defcustom TeX-source-specials-view-emacsclient-flags
"--no-wait +%%l %%f"
"Flags to emacsclient for inverse search."
:group 'TeX-view
:type 'string)
;; FIXME: Make client binaries configurable.
(defun TeX-source-specials-view-expand-client ()
"Return gnuclient or emacslient executable with options.
Return the full path to the executable if possible."
(let* ((gnuserv-p (TeX-source-correlate-gnuserv-p))
(client-base (if gnuserv-p
(client-full (and invocation-directory
(expand-file-name client-base
(options (if gnuserv-p
(if (and client-full (file-executable-p client-full))
(concat client-full " " options)
(concat client-base " " options))))
(defun TeX-source-specials-view-expand-options (&optional viewer)
"Return source specials command line option for viewer command.
The return value depends on the values of
`TeX-source-correlate-mode' and
`TeX-source-correlate-method-active'. If those are nil or not
`source-specials' respectively, an empty string will be
(if (and TeX-source-correlate-mode
(eq (TeX-source-correlate-method-active) 'source-specials))
(concat TeX-source-specials-view-position-flags
(when (TeX-source-correlate-server-enabled-p)
(concat " " TeX-source-specials-view-editor-flags)))
;;; SyncTeX
(defvar TeX-synctex-tex-flags "--synctex=1"
"Extra flags to pass to TeX commands to enable SyncTeX.")
(defun TeX-synctex-output-page-1 (file)
"Return the page corresponding to the current position in FILE.
This method assumes that the document was compiled with SyncTeX
enabled and the `synctex' binary is available."
(let ((synctex-output
(call-process "synctex" nil (list standard-output nil) nil "view"
"-i" (format "%s:%s:%s" (line-number-at-pos)
"-o" (TeX-active-master (TeX-output-extension))))))
(when (string-match "Page:\\([0-9]+\\)" synctex-output)
(match-string 1 synctex-output))))
(defun TeX-synctex-output-page ()
"Return the page corresponding to the position in the current buffer.
This method assumes that the document was compiled with SyncTeX
enabled and the `synctex' binary is available."
(let* ((file (file-relative-name (buffer-file-name)
(abs-file (concat (expand-file-name (or (file-name-directory (TeX-active-master))
(file-name-directory (buffer-file-name))))
"./" file)))
;; It's known that depending on synctex version one of
;; /absolute/path/./foo/bar.tex, foo/bar.tex, or ./foo/bar.tex (relative to
;; TeX-master, and the "." in the absolute path is important) are needed.
;; So try all variants before falling back to page 1.
(or (TeX-synctex-output-page-1 abs-file)
(TeX-synctex-output-page-1 file)
(TeX-synctex-output-page-1 (concat "./" file))
;;; Miscellaneous minor modes
(defvar TeX-mode-p nil
"This indicates a TeX mode being active.")
(make-variable-buffer-local 'TeX-mode-p)
(defun TeX-mode-set (var value)
(set-default var value)
(TeX-set-mode-name var nil t))
(defcustom TeX-PDF-mode t nil
:group 'TeX-command
:set 'TeX-mode-set
:type 'boolean)
(put 'TeX-PDF-mode 'safe-local-variable 'TeX-booleanp)
(define-minor-mode TeX-PDF-mode
"Minor mode for using PDFTeX.
If enabled, PDFTeX will be used as an executable by default.
You can customize an initial value, and you can use the
function `TeX-global-PDF-mode' for toggling this value."
:group 'TeX-command
(when (eq TeX-engine 'omega)
(setq TeX-PDF-mode nil))
(setq TeX-PDF-mode-parsed nil)
(TeX-set-mode-name nil nil t)
(setq TeX-output-extension
(if TeX-PDF-mode "pdf" "dvi")))
(add-to-list 'minor-mode-alist '(TeX-PDF-mode ""))
(defun TeX-global-PDF-mode (&optional arg)
"Toggle default for `TeX-PDF-mode'."
(interactive "P")
(setq-default TeX-PDF-mode
(if arg (> (prefix-numeric-value arg) 0)
(not (default-value 'TeX-PDF-mode))))
(TeX-set-mode-name 'TeX-PDF-mode nil t)))
(defalias 'tex-pdf-mode 'TeX-PDF-mode)
(defvar TeX-PDF-mode-parsed nil
"Set if `TeX-PDF-mode' has come about by parsing.")
(make-variable-buffer-local 'TeX-PDF-mode-parsed)
(defun TeX-PDF-mode-parsed (arg)
"Change `TeX-PDF-mode' to ARG based on parsing.
If this conflicts with previous parsed settings,
just use the default. If an explicit setting is
already established, don't do anything."
;; Basically we have the following situations:
;; TeX-PDF-mode-parsed (local-variable-p 'TeX-PDF-mode):
;; nil nil : virgin state
;; nil t : stably set state (possibly because of conflicting parse info)
;; t t : non-conflicting parsed info
(if TeX-PDF-mode-parsed
(unless (eq TeX-PDF-mode arg)
(TeX-PDF-mode (if (default-value 'TeX-PDF-mode) 1 0)))
(unless (local-variable-p 'TeX-PDF-mode (current-buffer))
(TeX-PDF-mode (if arg 1 0))
(setq TeX-PDF-mode-parsed t))))
(defun TeX-PDF-mode-on ()
"Use only from parsing routines."
(TeX-PDF-mode-parsed t))
(defun TeX-PDF-mode-off ()
"Use only from parsing routines."
(TeX-PDF-mode-parsed nil))
(defcustom TeX-DVI-via-PDFTeX nil
"Whether to use PDFTeX also for producing DVI files."
:group 'TeX-command
:type 'boolean)
(defcustom TeX-PDF-from-DVI nil
"Specify if and how to produce PDF output from a DVI file.
If non-nil, the default compiler produces DVI output. The value
should be the name of the command used to convert the DVI file to
PDF or to an intermediate type.
Possible values are
* \"Dvips\": the DVI file is converted to PS with dvips. After
successfully running it, ps2pdf will be the default command to
convert the PS file to PDF
* \"Dvipdfmx\": the PDF is produced with dvipdfmx
Programs should not use this variable directly but the function
`TeX-PDF-from-DVI' which handles now obsolete variable
:group 'TeX-command
:type '(choice
(const :tag "No DVI to PDF conversion" nil)
(const :tag "dvips - ps2pdf sequence" "Dvips")
(const :tag "dvipdfmx" "Dvipdfmx")))
;; If you plan to support new values of `TeX-PDF-from-DVI' remember to update
;; `TeX-command-default' accordingly.
(make-variable-buffer-local 'TeX-PDF-from-DVI)
(put 'TeX-PDF-from-DVI 'safe-local-variable
(lambda (x) (or (stringp x) (null x))))
(defcustom TeX-PDF-via-dvips-ps2pdf nil
"Whether to produce PDF output through the (La)TeX - dvips - ps2pdf sequence."
:group 'TeX-command
:type 'boolean)
(make-variable-buffer-local 'TeX-PDF-via-dvips-ps2pdf)
(put 'TeX-PDF-via-dvips-ps2pdf 'safe-local-variable 'TeX-booleanp)
(make-obsolete-variable 'TeX-PDF-via-dvips-ps2pdf 'TeX-PDF-from-DVI "11.90")
(defun TeX-PDF-from-DVI ()
"Return the value of variable `TeX-PDF-from-DVI'.
If `TeX-PDF-from-DVI' is not set and obsolete option
`TeX-PDF-via-dvips-ps2pdf' is non-nil, return \"dvips-ps2pdf\"
for backward compatibility."
(define-minor-mode TeX-interactive-mode
"Minor mode for interactive runs of TeX."
nil nil nil
:group 'TeX-command
(TeX-set-mode-name 'TeX-interactive-mode t t))
(defalias 'tex-interactive-mode 'TeX-interactive-mode)
(add-to-list 'minor-mode-alist '(TeX-interactive-mode ""))
;;; Commands
(defgroup TeX-command-name nil
"Names for external commands in AUCTeX."
:group 'TeX-command)
(defcustom TeX-command-BibTeX "BibTeX"
"*The name of the BibTeX entry in `TeX-command-list'."
:group 'TeX-command-name
:type 'string)
(make-variable-buffer-local 'TeX-command-BibTeX)
(defcustom TeX-command-Biber "Biber"
"*The name of the Biber entry in `TeX-command-list'."
:group 'TeX-command-name
:type 'string)
(make-variable-buffer-local 'TeX-command-Biber)
(defcustom TeX-command-Show "View"
"*The default command to show (view or print) a TeX file.
Must be the car of an entry in `TeX-command-list'."
:group 'TeX-command-name
:type 'string)
(make-variable-buffer-local 'TeX-command-Show)
(defcustom TeX-command-Print "Print"
"The name of the Print entry in `TeX-command-Print'."
:group 'TeX-command-name
:type 'string)
(defcustom TeX-command-Queue "Queue"
"The name of the Queue entry in `TeX-command-Queue'."
:group 'TeX-command-name
:type 'string)
(defvar TeX-trailer-start nil
"Regular expression delimiting start of trailer in a TeX file.")
(make-variable-buffer-local 'TeX-trailer-start)
(defvar TeX-header-end nil
"Regular expression delimiting end of header in a TeX file.")
(make-variable-buffer-local 'TeX-header-end)
(defvar TeX-command-default nil
"The default command for `TeX-command' in the current major mode.")
(make-variable-buffer-local 'TeX-command-default)
(put 'TeX-command-default 'safe-local-variable 'stringp)
(defvar TeX-clean-default-intermediate-suffixes
'("\\.aux" "\\.bbl" "\\.blg" "\\.brf" "\\.fot"
"\\.glo" "\\.gls" "\\.idx" "\\.ilg" "\\.ind"
"\\.lof" "\\.log" "\\.lot" "\\.nav" "\\.out"
"\\.snm" "\\.toc" "\\.url" "\\.synctex\\.gz"
"\\.bcf" "\\.run\\.xml" "\\.fls" "-blx\\.bib")
"List of regexps matching suffixes of files to be cleaned.
Used as a default in TeX, LaTeX and docTeX mode.")
(defvar TeX-clean-default-output-suffixes
'("\\.dvi" "\\.pdf" "\\.ps" "\\.xdv")
"List of regexps matching suffixes of files to be cleaned.
Used as a default in TeX, LaTeX and docTeX mode.")
(defcustom TeX-clean-confirm t
"If non-nil, ask before deleting files."
:type 'boolean
:group 'TeX-command)
(autoload 'dired-mark-pop-up "dired")
(defun TeX-clean (&optional arg)
"Delete generated files associated with current master and region files.
If prefix ARG is non-nil, not only remove intermediate but also
output files."
(interactive "P")
(let* ((mode-prefix (TeX-mode-prefix))
(suffixes (append (symbol-value
(intern (concat mode-prefix
(when arg
(intern (concat mode-prefix
(master (TeX-active-master))
(master-dir (file-name-directory master))
(regexp (concat "\\("
(regexp-quote (file-name-nondirectory master)) "\\|"
(regexp-quote (TeX-region-file nil t))
(mapconcat 'identity suffixes "\\|")
"\\|" (regexp-quote (TeX-region-file t t))))
(files (when regexp
(directory-files (or master-dir ".") nil regexp))))
(if files
(when (or (not TeX-clean-confirm)
(condition-case nil
(dired-mark-pop-up " *Deletions*" 'delete
(if (> (length files) 1)
(cons t files))
'y-or-n-p "Delete files? ")
(wrong-type-argument ; e.g. with Emacs 21
(y-or-n-p (format "Delete %S? " (car files))))))
(dolist (file files)
(delete-file (concat master-dir file))))
(message "No files to be deleted"))))
;;; Master File
(defcustom TeX-master t
"*The master file associated with the current buffer.
If the file being edited is actually included from another file, you
can tell AUCTeX the name of the master file by setting this variable.
If there are multiple levels of nesting, specify the top level file.
If this variable is nil, AUCTeX will query you for the name.
If the variable is t, AUCTeX will assume the file is a master file
If the variable is 'shared, AUCTeX will query for the name, but not
change the file.
If the variable is 'dwim, AUCTeX will try to avoid querying by
attempting to `do what I mean'; and then change the file.
It is suggested that you use the File Variables (see the info node in
the Emacs manual) to set this variable permanently for each file."
:group 'TeX-command
:group 'TeX-parse
:type '(choice (const :tag "Query" nil)
(const :tag "This file" t)
(const :tag "Shared" shared)
(const :tag "Dwim" dwim)
(string :format "%v")))
(make-variable-buffer-local 'TeX-master)
(put 'TeX-master 'safe-local-variable
'(lambda (x)
(or (stringp x)
(member x (quote (t nil shared dwim))))))
(defcustom TeX-one-master "\\.\\(texi?\\|dtx\\)$"
"*Regular expression matching ordinary TeX files.
You should set this variable to match the name of all files, where
automatically adding a file variable with the name of the master file
is a good idea. When AUCTeX adds the name of the master file as a
file variable, it does not need to ask next time you edit the file.
If you dislike AUCTeX automatically modifying your files, you can set
this variable to \"<none>\"."
:group 'TeX-command
:type 'regexp)
;; Can be let-bound temporarily in order to inhibit the master file question
;; by using its value instead in case `TeX-master' is nil or 'shared.
(defvar TeX-transient-master nil)
(defun TeX-dwim-master ()
"Find a likely `TeX-master'."
(let ((dir default-directory))
(dolist (buf (buffer-list))
(when (with-current-buffer buf
(and (equal dir default-directory)
(stringp TeX-master)))
(return (with-current-buffer buf TeX-master))))))
(defun TeX-master-file-ask ()
"Ask for master file, set `TeX-master' and add local variables."
(if (TeX-local-master-p)
(error "Master file already set")
(let* ((default (TeX-dwim-master))
(name (or (and (eq 'dwim TeX-master) default)
(condition-case nil
(read-file-name (format "Master file: (default %s) "
(or default "this file"))
nil default)
(quit "<quit>")))))
(cond ((string= name "<quit>")
(setq TeX-master t))
((string= name default)
(setq TeX-master default)
;; Default `read-file-name' proposes and buffer visits a file.
(string= (expand-file-name name) (buffer-file-name))
;; Default of `read-file-name' and buffer does not visit a file.
(string= name default-directory)
;; User typed <RET> in an empty minibuffer.
(string= name ""))
(setq TeX-master t)
(setq TeX-master (TeX-strip-extension (file-relative-name name)
(list TeX-default-extension)
(defun TeX-master-file (&optional extension nondirectory ask)
"Set and return the name of the master file for the current document.
If optional argument EXTENSION is non-nil, add that file extension to
the name. Special value t means use `TeX-default-extension'.
If optional second argument NONDIRECTORY is non-nil, do not include
the directory.
If optional third argument ASK is non-nil, ask the user for the
name of master file if it cannot be determined otherwise."
(if (eq extension t)
(setq extension TeX-default-extension))
(let ((my-name (if (buffer-file-name)
(TeX-strip-extension nil (list TeX-default-extension) t)
(goto-char (point-min))
((and TeX-transient-master
(or (not TeX-master) (eq TeX-master 'shared)))
(setq TeX-master TeX-transient-master))
;; Special value 't means it is own master (a free file).
((equal TeX-master my-name)
(setq TeX-master t))
;; For files shared between many documents.
((and (eq 'shared TeX-master) ask)
(setq TeX-master
(let* ((default (TeX-dwim-master))
(name (read-file-name
(format "Master file: (default %s) "
(or default "this file"))
nil default)))
(cond ((string= name default)
;; Default `read-file-name' proposes and
;; buffer visits a file.
(string= (expand-file-name name)
;; Default of `read-file-name' and
;; buffer does not visit a file.
(string= name default-directory)
;; User typed <RET> in an empty minibuffer.
(string= name ""))
name (list TeX-default-extension) 'path))))))
;; We might already know the name.
((or (eq TeX-master t) (stringp TeX-master)) TeX-master)
;; Ask the user (but add it as a local variable).
(ask (TeX-master-file-ask)))))
(let ((name (if (stringp TeX-master)
(if (TeX-match-extension name)
;; If it already has an extension...
(if (equal extension TeX-default-extension)
;; Use instead of the default extension
(setq extension nil)
;; Otherwise drop it.
(setq name (TeX-strip-extension name))))
;; Remove directory if needed.
(if nondirectory
(setq name (file-name-nondirectory name)))
(if extension
(concat name "." extension)
(defun TeX-master-directory ()
"Directory of master file."
(let ((dir (file-name-directory (TeX-master-file))))
(if dir (directory-file-name dir) "."))
(and buffer-file-name
(file-name-directory buffer-file-name)))))))
(defun TeX-add-local-master ()
"Add local variable for `TeX-master'."
(when (and (buffer-file-name)
(string-match TeX-one-master
(file-name-nondirectory (buffer-file-name)))
(not buffer-read-only))
(goto-char (point-max))
(if (re-search-backward "^\\([^\n]+\\)Local Variables:"
(- (point-max) 3000) t)
(let ((prefix (TeX-match-buffer 1)))
(re-search-forward (regexp-quote (concat prefix
(beginning-of-line 1)
(insert prefix "TeX-master: " (prin1-to-string TeX-master) "\n"))
(let ((comment-prefix (cond ((eq major-mode 'texinfo-mode) "@c ")
((eq major-mode 'doctex-mode) "% ")
(t "%%% ")))
(mode (concat (and (boundp 'japanese-TeX-mode) japanese-TeX-mode
(substring (symbol-name major-mode) 0 -5))))
(when (eq major-mode 'doctex-mode)
(insert comment-prefix TeX-esc "endinput\n"))
comment-prefix "Local Variables:\n"
comment-prefix "mode: " mode "\n"
comment-prefix "TeX-master: " (prin1-to-string TeX-master) "\n"
comment-prefix "End:\n")))))
(defun TeX-local-master-p ()
"Return non-nil if there is a `TeX-master' entry in local variables spec.
Return nil otherwise."
;; XXX: Checking -*- line necessary as well?
(goto-char (point-max))
(search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
(re-search-forward "^%+ *TeX-master:" nil t)))
;;; Style Paths
(defcustom TeX-style-global (expand-file-name "style" TeX-data-directory)
"*Directory containing hand generated TeX information.
These correspond to TeX macros shared by all users of a site."
:group 'TeX-file
:type 'directory)
(defcustom TeX-auto-local "auto"
"*Directory containing automatically generated TeX information.
This correspond to TeX macros found in the current directory, and must
be relative to that."
:group 'TeX-file
:type 'string)
(defcustom TeX-style-local "style"
"*Directory containing hand generated TeX information.
These correspond to TeX macros found in the current directory, and must
be relative to that."
:group 'TeX-file
:type 'string)
(defun TeX-split-string (regexp string)
"Return a list of strings.
Given REGEXP the STRING is split into sections which in string was
seperated by REGEXP.
(TeX-split-string \"\:\" \"abc:def:ghi\")
-> (\"abc\" \"def\" \"ghi\")
(TeX-split-string \" +\" \"dvips -Plw -p3 -c4 testfile.dvi\")
-> (\"dvips\" \"-Plw\" \"-p3\" \"-c4\" \"testfile.dvi\")
If REGEXP is nil, or \"\", an error will occur."
(let ((start 0) result match)
(while (setq match (string-match regexp string start))
(push (substring string start match) result)
(setq start (match-end 0)))
(push (substring string start) result)
(nreverse result)))
(defun TeX-parse-path (env)
"Return a list if private TeX directories found in environment variable ENV."
(let* ((value (getenv env))
(entries (and value
(if (string-match ";" value) ";" ":")
(while entries
(setq entry (car entries))
(setq entries (cdr entries))
(setq entry (file-name-as-directory
(if (string-match "/?/?\\'" entry)
(substring entry 0 (match-beginning 0))
(or (not (file-name-absolute-p entry))
(member entry (append '("/" "\\") TeX-macro-global))
(setq answers (cons entry answers))))
(defun TeX-tree-expand (vars program &optional subdirs)
"Return directories corresponding to the kpathsea variables VARS.
This is done calling `kpsewhich --expand-path' for the variables.
PROGRAM is passed as the parameter for --progname. SUBDIRS are
subdirectories which are appended to the directories of the TeX
trees. Only existing directories are returned."
;; FIXME: The GNU convention only uses "path" to mean "list of directories"
;; and uses "filename" for the name of a file even if it contains possibly
;; several elements separated by "/".
(let* ((exit-status 1)
(path-list (ignore-errors
(setq exit-status
"kpsewhich" nil
(list standard-output nil) nil
"--progname" program
(mapconcat #'identity vars
(if (eq system-type 'windows-nt)
";" ":"))))))))
(when (zerop exit-status)
(let ((separators (if (string-match "^[A-Za-z]:" path-list)
path input-dir-list)
(dolist (item (condition-case nil
(split-string path-list separators t)
;; COMPATIBILITY for XEmacs <= 21.4.15
(error (delete "" (split-string path-list separators)))))
(if subdirs
(dolist (subdir subdirs)
(setq path (file-name-as-directory (concat item subdir)))
(when (file-exists-p path)
(pushnew path input-dir-list :test #'equal)))
(setq path (file-name-as-directory item))
(when (file-exists-p path)
(pushnew path input-dir-list :test #'equal))))
(nreverse input-dir-list)))))
(defun TeX-macro-global ()
"Return directories containing the site's TeX macro and style files."
"latex" '("/tex/" "/bibtex/bst/"))
'("/usr/share/texmf/tex/" "/usr/share/texmf/bibtex/bst/")))
(defun TeX-macro-private ()
"Return directories containing the user's TeX macro and style files."
(TeX-tree-expand '("$TEXMFHOME") "latex" '("/tex/" "/bibtex/bst/")))
(defcustom TeX-macro-global (TeX-macro-global)
"Directories containing the site's TeX macro and style files."
:group 'TeX-file
:type '(repeat (directory :format "%v")))
(defcustom TeX-macro-private (or (append (TeX-parse-path "TEXINPUTS")
(TeX-parse-path "BIBINPUTS"))
"Directories where you store your personal TeX macros."
:group 'TeX-file
:type '(repeat (file :format "%v")))
(defcustom TeX-auto-private
(list (expand-file-name TeX-auto-local
(or (and (boundp 'user-emacs-directory)
(concat user-emacs-directory "auctex/"))
"List of directories containing automatically generated AUCTeX style files.
These correspond to the personal TeX macros."
:group 'TeX-file
:type '(repeat (file :format "%v")))
(if (stringp TeX-auto-private) ;Backward compatibility
(setq TeX-auto-private (list TeX-auto-private)))
(defcustom TeX-style-private
(list (expand-file-name TeX-style-local
(or (and (boundp 'user-emacs-directory)
(concat user-emacs-directory "auctex/"))
"List of directories containing hand-generated AUCTeX style files.
These correspond to the personal TeX macros."
:group 'TeX-file
:type '(repeat (file :format "%v")))
(if (stringp TeX-style-private) ;Backward compatibility
(setq TeX-style-private (list TeX-style-private)))
(defcustom TeX-style-path
(let ((path))
;; Put directories in an order where the more local files can
;; override the more global ones.
(mapc (lambda (file)
(when (and file (not (member file path)))
(setq path (cons file path))))
(append (list TeX-auto-global TeX-style-global)
TeX-auto-private TeX-style-private
(list TeX-auto-local TeX-style-local)))
(nreverse path))
"List of directories to search for AUCTeX style files.
Per default the list is built from the values of the variables
`TeX-auto-global', `TeX-style-global', `TeX-auto-private',
`TeX-style-private', `TeX-auto-local', and `TeX-style-local'."
:group 'TeX-file
:type '(repeat (file :format "%v")))
(defcustom TeX-check-path
(append (list ".") TeX-macro-private TeX-macro-global)
"Directory path to search for dependencies.
If nil, just check the current file.
Used when checking if any files have changed."
:group 'TeX-file
:type '(repeat (file :format "%v")))
;;; Style Files
(defvar TeX-style-hook-list nil
"List of TeX style hooks currently loaded.
Each entry is a list:
where the first element STYLE is the name of the style, and the
remaining elements HOOKN, if any, are hooks to be run when that
style is active.
A hook HOOKN may be a hook function HOOK-FUN to be run in
all TeX dialects (LaTeX, Texinfo, etc.), or a vector like:
where HOOK-FUN is the hook function to be run, and DIALECT-SET is
a non-empty set of dialects in which the hook function may be
This set is instantiated by function `TeX-add-style-hook' through
functions manipulating style hook dialect expression named with a
`TeX-shdex-' prefix.
For supported dialects, see variables `TeX-style-hook-dialect'.")
(defvar TeX-style-hook-dialect :latex
"Dialect for running hooks locally to the considered file.
Supported values are described below:
* `:bibtex' for files in BibTeX mode.
* `:context' for files in ConTeXt mode.
* `:latex' for files in LaTeX mode, or any mode derived
* `:plain-tex' for files in plain-TeX mode.
* `:texinfo' for Texinfo files.
Purpose is notably to prevent non-Texinfo hooks to be run in
Texinfo files, due to ambiguous style name, as this may cause bad
side effect e.g. on variable `TeX-font-list'.")
(defcustom TeX-byte-compile nil
"*Not nil means try to byte compile auto files before loading."
:group 'TeX-parse
:type 'boolean)
(defun TeX-bibtex-set-BibTeX-dialect ()
"Set `TeX-style-hook-dialect' to `:bibtex' locally to BibTeX buffers."
(set (make-local-variable 'TeX-style-hook-dialect) :bibtex))
(defun TeX-load-style (style)
"Search for and load each definition for STYLE in `TeX-style-path'."
(cond ((assoc style TeX-style-hook-list)) ; We already found it
((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-relative-name TeX-master))
(TeX-style-path (append (list (expand-file-name
TeX-auto-local dir)
TeX-auto-local master-dir)
TeX-style-local dir)
TeX-style-local master-dir))
(TeX-load-style style)))
(t ;Relative path
;; Insert empty list to mark the fact that we have searched.
(setq TeX-style-hook-list (cons (list style) TeX-style-hook-list))
;; Now check each element of the path
(dolist (name TeX-style-path)
(TeX-load-style-file (expand-file-name style name))))))
(defun TeX-load-style-file (file)
"Load FILE checking for a Lisp extensions."
(let ((el (concat file ".el"))
(elc (concat file ".elc")))
(cond ((file-newer-than-file-p el elc)
(if (file-readable-p el)
(if (and TeX-byte-compile
(file-writable-p elc)
;; `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)
(load-file el)))))
(defconst TeX-style-hook-dialect-weight-alist
'((:latex . 1) (:texinfo . 2) (:bibtex . 4) (:plain-tex . 8) (:context . 16))
"Association list to map dialects to binary weight, in order to
implement dialect sets as bitmaps." )
(defun TeX-shdex-eval (dialect-expr)
"Evaluate a style hook dialect expression DIALECT-EXPR."
((symbolp dialect-expr)
(let ((cell (assq dialect-expr TeX-style-hook-dialect-weight-alist)))
(if cell (cdr cell)
(error "Invalid dialect expression : %S." dialect-expr))))
((and (consp dialect-expr)
(memq (car dialect-expr) '(or not and nor)))
(apply (intern
(concat "TeX-shdex-" (symbol-name (car dialect-expr))))
(cdr dialect-expr)))
(error "Invalid dialect expression : %S." dialect-expr))))
(defsubst TeX-shdex-or (&rest args)
"OR operator for style hook dialect expressions."
(apply 'logior (mapcar 'TeX-shdex-eval args)))
(defsubst TeX-shdex-and (&rest args)
"AND operator for style hook dialect expressions."
(apply 'logand (mapcar 'TeX-shdex-eval args)))
(defsubst TeX-shdex-nor (&rest args)
"NOR operator for style hook dialect expressions."
(lognot (apply 'TeX-shdex-or args)))
(defsubst TeX-shdex-not (arg)
"NOT operator for style hook dialect expressions."
(lognot (TeX-shdex-eval arg)))
(defsubst TeX-shdex-in-p (dialect dialect-set)
"Test whether dialect DIALECT is in dialect set DIALECT-SET."
(let ((cell (assq dialect TeX-style-hook-dialect-weight-alist)))
(if cell
(/= 0 (logand (cdr cell) dialect-set))
(error "Invalid dialect %S" dialect))))
(defsubst TeX-shdex-listify (dialect-set)
"Converts a dialect set DIALECT-SET to a list of all dialect
comprised in this set, where dialects are symbols"
(let (ret)
(dolist (c dialect-set)
(when (/= 0 (logand (cdr c) dialect-set))
(push (car c) ret)))
(defun TeX-add-style-hook (style hook &optional dialect-expr)
"Give STYLE yet another HOOK to run.
DIALECT-EXPR serves the purpose of marking the hook to be run only in
that dicontext.
DIALECT-EXPR may be a single symbol defining the dialect, see
variable `TeX-style-hook-dialect' for supported dialects.
DIALECT-EXPR can also be an expression like one of the following:
* (or DIALECT1 DIALECT2 ...)
* (nor DIALECT1 DIALECT2 ...)
* (and DIALECT1 DIALECT2 ...)
* (not DIALECT )
When omitted DIALECT-EXPR is equivalent to `(nor )', ie all
dialected are allowed."
(let ((entry (TeX-assoc-string style TeX-style-hook-list)))
(and dialect-expr (setq hook (vector 'TeX-style-hook hook
(TeX-shdex-eval dialect-expr))))
(cond ((null entry)
;; New style, add entry.
(setq TeX-style-hook-list (cons (list style hook)
((member hook entry)
;; Old style, hook already there, do nothing.
;; Old style, new hook.
(setcdr entry (cons hook (cdr entry)))))))
(defun TeX-keep-hooks-in-dialect (hooks dialect-list)
"Scan HOOKS for all hooks the associated dialect of which is
found in DIALECT-LIST and return the list thereof."
(let (ret dialect-list-1)
(dolist (hook hooks)
(setq dialect-list-1 (and (vectorp hook) (eq (aref hook 0) 'TeX-style-hook)
(TeX-shdex-listify (aref hook 2))))
(while dialect-list-1
(when (memq (pop dialect-list-1) dialect-list)
(push hook ret)
(setq dialect-list-1 nil)))
(defun TeX-unload-style (style &optional dialect-list)
"Forget that we once loaded STYLE. If DIALECT-LIST is provided
the STYLE is only removed for those dialects in DIALECT-LIST.
See variable `TeX-style-hook-dialect' for supported dialects."
(let ((style-data (TeX-assoc-string style TeX-style-hook-list)))
(if style-data
(let ((hooks (and dialect-list (TeX-keep-hooks-in-dialect (cdr style-data) dialect-list))))
(if hooks
(setcdr style-data hooks)
(setq TeX-style-hook-list (delq style-data TeX-style-hook-list)))))))
(defcustom TeX-virgin-style (if (and TeX-auto-global
(file-directory-p TeX-auto-global))
"Style all documents use."
:group 'TeX-parse
:type 'string)
(defvar TeX-active-styles nil
"List of styles currently active in the document.")
(make-variable-buffer-local 'TeX-active-styles)
(defun TeX-run-style-hooks (&rest styles)
"Run the TeX style hooks STYLES."
(mapcar (lambda (style)
;; Avoid recursion.
(unless (TeX-member style TeX-active-styles 'string-equal)
(setq TeX-active-styles
(cons style TeX-active-styles))
(TeX-load-style style)
(let ((default-directory default-directory))
;; Complex path.
(when (string-match "\\`\\(.+[/\\]\\)\\([^/\\]*\\)\\'" style)
;; Set `default-directory' to directory of master
;; file since style files not stored in the fixed
;; style directories are usually located there.
(setq default-directory (save-match-data
style (substring style
(match-beginning 2) (match-end 2))))
(condition-case nil
(mapcar (lambda (hook)
((functionp hook)
(funcall hook))
((and (vectorp hook)
(eq (aref hook 0) 'TeX-style-hook))
(and (TeX-shdex-in-p TeX-style-hook-dialect (aref hook 2))
(funcall (aref hook 1))))
(t (error "Invalid style hook %S" hook))))
;; Reverse the list of style hooks in order to run
;; styles in the order global, private, local
;; (assuming TeX-style-path has that ordering,
;; too).
(reverse (cdr-safe (TeX-assoc-string style TeX-style-hook-list))))
;; This happens in case some style added a new parser, and
;; now the style isn't used anymore (user deleted
;; \usepackage{style}). Then we're left over with, e.g.,
;; (LaTeX-add-siunitx-units "\\parsec"), but the function is
;; defined in a style siunitx.el that's not loaded anymore.
(void-function nil)))))
(defcustom TeX-parse-self nil
"Parse file after loading it if no style hook is found for it."
:group 'TeX-parse
:type 'boolean)
(defvar TeX-style-hook-applied-p nil
"Nil, unless the style specific hooks have been applied.")
(make-variable-buffer-local 'TeX-style-hook-applied-p)
(defvar TeX-update-style-hook nil
"Hook run as soon as style specific hooks were applied.")
(defun TeX-update-style (&optional force)
"Run style specific hooks for the current document.
Only do this if it has not been done before, or if optional argument
FORCE is not nil."
(unless (or (and (boundp 'TeX-auto-update)
(eq TeX-auto-update 'BibTeX)) ; Not a real TeX buffer
(and (not force)
(setq TeX-style-hook-applied-p t)
(message "Applying style hooks...")
(TeX-run-style-hooks (TeX-strip-extension nil nil t))
;; Run parent style hooks if it has a single parent that isn't itself.
(if (or (not (memq TeX-master '(nil t)))
(and (buffer-file-name)
(string-match TeX-one-master
(file-name-nondirectory (buffer-file-name)))))
(TeX-run-style-hooks (TeX-master-file)))
(if (and TeX-parse-self
(null (cdr-safe (assoc (TeX-strip-extension nil nil t)
(run-hooks 'TeX-update-style-hook)
(message "Applying style hooks... done")))
(defvar TeX-remove-style-hook nil
"List of hooks to call when we remove the style specific information.")
(make-variable-buffer-local 'TeX-remove-style-hook)
(defun TeX-remove-style ()
"Remove all style specific information."
(setq TeX-style-hook-applied-p nil)
(run-hooks 'TeX-remove-style-hook)
(setq TeX-active-styles (list TeX-virgin-style)))
(defun TeX-style-list ()
"Return a list of all styles (subfiles) used by the current document."
;;; Special Characters
(defvar TeX-esc "\\" "The TeX escape character.")
(make-variable-buffer-local 'TeX-esc)
(defvar TeX-grop "{" "The TeX group opening character.")
(make-variable-buffer-local 'TeX-grop)
(defvar TeX-grcl "}" "The TeX group closing character.")
(make-variable-buffer-local 'TeX-grcl)
;;; Symbols
;; Must be before keymaps.
(defgroup TeX-macro nil
"Support for TeX macros in AUCTeX."
:prefix "TeX-"
:group 'AUCTeX)
(defcustom TeX-complete-word 'ispell-complete-word
"*Function to call for completing non-macros in `tex-mode'."
:group 'TeX-macro)
(defcustom TeX-complete-expert-commands nil
"Complete macros and environments marked as expert commands.
Possible values are nil, t, or a list of style names.
- nil Don't complete expert commands (default).
- t Always complete expert commands.
- (STYLES ...) Only complete expert commands of STYLES."
:group 'TeX-macro
:type '(choice (const :tag "Don't complete expert commands" nil)
(const :tag "Always complete expert commands" t)
(repeat :tag "Complete expert commands of certain styles" string)))
(defmacro TeX-complete-make-expert-command-functions (thing list-var prefix)
(let* ((plural (concat thing "s"))
(upcase (upcase thing))
(upcase-plural (upcase plural)))
(defvar ,(intern (format "%s-expert-%s-table" prefix thing))
(make-hash-table :test 'equal)
,(format "A hash-table mapping %s names to the style name providing it.
A %s occuring in this table is considered an expert %s and
treated specially in the completion." thing thing thing))
(defun ,(intern (format "%s-declare-expert-%s" prefix plural)) (style &rest ,(intern plural))
,(format "Declare %s as expert %s of STYLE.
Expert %s are completed depending on `TeX-complete-expert-commands'."
upcase-plural plural plural)
(dolist (x ,(intern plural))
(if (null style)
(remhash x TeX-expert-macro-table)
(puthash x style TeX-expert-macro-table))))
(defun ,(intern (format "%s-filtered" list-var)) ()
,(format "Return (%s) filtered depending on `TeX-complete-expert-commands'."
(delq nil
(lambda (entry)
(if (eq t TeX-complete-expert-commands)
(let* ((cmd (car entry))
(style (gethash cmd TeX-expert-macro-table)))
(when (or (null style)
(member style TeX-complete-expert-commands))
(TeX-complete-make-expert-command-functions "macro" TeX-symbol-list "TeX")
(TeX-complete-make-expert-command-functions "environment" LaTeX-environment-list "LaTeX")
(defvar TeX-complete-list nil
"List of ways to complete the preceding text.
Each entry is a list with the following elements:
0. Regexp matching the preceding text.
1. A number indicating the subgroup in the regexp containing the text.
2. A function returning an alist of possible completions.
3. Text to append after a succesful completion.
Or alternatively:
0. Regexp matching the preceding text.
1. Function to do the actual completion.")
(defun TeX-complete-symbol ()
"Perform completion on TeX/LaTeX symbol preceding point."
(interactive "*")
(let ((list TeX-complete-list)
(while list
(setq entry (car list)
list (cdr list))
(if (TeX-looking-at-backward (car entry) 250)
(setq list nil)))
(if (numberp (nth 1 entry))
(let* ((sub (nth 1 entry))
(close (nth 3 entry))
(begin (match-beginning sub))
(end (match-end sub))
(pattern (TeX-match-buffer 0))
(symbol (buffer-substring begin end))
(list (funcall (nth 2 entry)))
(completion (try-completion symbol list))
(buf-name "*Completions*"))
(cond ((eq completion t)
(and close
(not (looking-at (regexp-quote close)))
(insert close))
(let ((window (get-buffer-window buf-name)))
(when window (delete-window window))))
((null completion)
(error "Can't find completion for \"%s\"" pattern))
((not (string-equal symbol completion))
(delete-region begin end)
(insert completion)
(and close
(eq (try-completion completion list) t)
(not (looking-at (regexp-quote close)))
(insert close))
(let ((window (get-buffer-window buf-name)))
(when window (delete-window window))))
(if (fboundp 'completion-in-region)
(completion-in-region begin end
(all-completions symbol list nil))
(message "Making completion list...")
(let ((list (all-completions symbol list nil)))
(with-output-to-temp-buffer buf-name
(display-completion-list list)))
(set-window-dedicated-p (get-buffer-window buf-name) 'soft)
(message "Making completion list...done")))))
(funcall (nth 1 entry)))))
(defcustom TeX-default-macro "ref"
"*The default macro when creating new ones with `TeX-insert-macro'."
:group 'TeX-macro
:type 'string)
(make-variable-buffer-local 'TeX-default-macro)
(defcustom TeX-insert-braces t
"*If non-nil, append a empty pair of braces after inserting a macro.
See also `TeX-insert-braces-alist'."
:group 'TeX-macro
:type 'boolean)
(defcustom TeX-insert-braces-alist nil
"Alist of macros to which braces should or should not be appended.
Each element is a cons cell, whose CAR is the macro name, and the
CDR is non-nil or nil, depending on whether a pair of braces
should be, respectively, appended or not to the macro.
If a macro has an element in this variable, `TeX-parse-macro'
will use its value to decided what to do, whatever the value of
the variable `TeX-insert-braces'."
:group 'TeX-macro
:type '(repeat (cons (string :tag "Macro name")
(boolean :tag "Append braces?"))))
(make-variable-buffer-local 'TeX-insert-braces-alist)
(defcustom TeX-insert-macro-default-style 'show-optional-args
"Specifies whether `TeX-insert-macro' will ask for all optional arguments.
If set to the symbol `show-optional-args', `TeX-insert-macro'
asks for optional arguments of TeX marcos, unless the previous
optional argument has been rejected. If set to
`show-all-optional-args', `TeX-insert-macro' asks for all
optional arguments. If set to `mandatory-args-only',
`TeX-insert-macro' asks only for mandatory argument.
When `TeX-insert-macro' is called with \\[universal-argument], it's the other
way round.
Note that for some macros, there are special mechanisms, see e.g.
`LaTeX-includegraphics-options-alist' and `TeX-arg-cite-note-p'."
:group 'TeX-macro
:type '(choice (const mandatory-args-only)
(const show-optional-args)
(const show-all-optional-args)))
(defvar TeX-arg-opening-brace nil
"String used as an opening brace for argument insertion.
The variable will be temporarily let-bound with the necessary value.")
(defvar TeX-arg-closing-brace nil
"String used as a closing brace for argument insertion.
The variable will be temporarily let-bound with the necessary value.")
(defvar TeX-after-insert-macro-hook nil
"A hook run after `TeX-insert-macro'.")
(defvar TeX-macro-history nil)
(defun TeX-insert-macro (symbol)
"Insert TeX macro SYMBOL with completion.
AUCTeX knows of some macros and may query for extra arguments, depending on
the value of `TeX-insert-macro-default-style' and whether `TeX-insert-macro'
is called with \\[universal-argument]."
;; When called with a prefix (C-u), only ask for mandatory arguments,
;; i.e. all optional arguments are skipped. See `TeX-parse-arguments' for
;; details. Note that this behavior may be changed in favor of a more
;; flexible solution in the future, therefore we don't document it at the
;; moment.
(interactive (list (completing-read (concat "Macro (default "
"): "
(TeX-symbol-list-filtered) nil nil nil
'TeX-macro-history TeX-default-macro)))
(when (interactive-p)
(setq TeX-default-macro symbol))
(TeX-parse-macro symbol (cdr-safe (assoc symbol (TeX-symbol-list))))
(run-hooks 'TeX-after-insert-macro-hook))
(defvar TeX-electric-macro-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map minibuffer-local-completion-map)
(define-key map " " 'minibuffer-complete-and-exit)
(defun TeX-electric-macro ()
"Insert TeX macro with completion.
AUCTeX knows of some macros, and may query for extra arguments.
Space will complete and exit."
(cond ((eq (preceding-char) ?\\)
(call-interactively 'self-insert-command))
((eq (preceding-char) ?.)
(let ((TeX-default-macro " ")
(minibuffer-local-completion-map TeX-electric-macro-map))
(call-interactively 'TeX-insert-macro)))
(let ((minibuffer-local-completion-map TeX-electric-macro-map))
(call-interactively 'TeX-insert-macro)))))
(defun TeX-parse-macro (symbol args)
"How to parse TeX macros which takes one or more arguments.
First argument SYMBOL is the name of the macro.
If ARGS is nil, insert macro with point inside braces.
Otherwise, each element in ARGS should match an argument to the
TeX macro. What is done depend on the type of the element:
string: Use the string as a prompt to prompt for the argument.
number: Insert that many braces, leave point inside the first.
nil: Insert empty braces.
t: Insert empty braces, leave point between the braces.
other symbols: Call the symbol as a function. You can define
your own hook, or use one of the predefined argument hooks. If
you add new hooks, you can assume that point is placed directly
after the previous argument, or after the macro name if this is
the first argument. Please leave point located after the
argument you are inserting. If you want point to be located
somewhere else after all hooks have been processed, set the value
of `exit-mark'. It will point nowhere, until the argument hook
set it. By convention, these hooks all start with `TeX-arg-'.
list: If the car is a string, insert it as a prompt and the next
element as initial input. Otherwise, call the car of the list
with the remaining elements as arguments.
vector: Optional argument. If it has more than one element,
parse it as a list, otherwise parse the only element as above.
Use square brackets instead of curly braces, and is not inserted
on empty user input."
(let ((TeX-grop (if (and (or (atom args) (= (length args) 1))
(fboundp 'LaTeX-verbatim-macros-with-delims)
(member symbol (LaTeX-verbatim-macros-with-delims)))
(TeX-grcl (if (and (or (atom args) (= (length args) 1))
(fboundp 'LaTeX-verbatim-macros-with-delims)
(member symbol (LaTeX-verbatim-macros-with-delims)))
(if (and (TeX-active-mark)
(> (point) (mark)))
(insert TeX-esc symbol)
(let ((exit-mark (make-marker))
(position (point)))
(TeX-parse-arguments args)
(cond ((marker-position exit-mark)
(goto-char (marker-position exit-mark))
(set-marker exit-mark nil))
((let ((element (assoc symbol TeX-insert-braces-alist)))
;; If in `TeX-insert-braces-alist' there is an element associated
;; to the current macro, use its value to decide whether inserting
;; a pair of braces, otherwise use the standard criterion.
(if element
(cdr element)
(and TeX-insert-braces
;; Do not add braces if the argument is 0 or -1.
(not (and (= (safe-length args) 1)
(numberp (car args))
(<= (car args) 0)))
(equal position (point))
(string-match "[a-zA-Z]+" symbol))))
(if (texmathp)
(when (TeX-active-mark)
(insert TeX-grop)
(insert TeX-grcl))
(insert TeX-grop)
(if (TeX-active-mark)
(insert TeX-grcl))
(insert TeX-grcl)
(defun TeX-arg-string (optional &optional prompt initial-input)
"Prompt for a string.
If OPTIONAL is not nil then the PROMPT will start with ``(Optional) ''.
INITIAL-INPUT is a string to insert before reading input."
(if (and (not optional) (TeX-active-mark))
(let ((TeX-argument (buffer-substring (point) (mark))))
(delete-region (point) (mark))
(TeX-read-string (TeX-argument-prompt optional prompt "Text") initial-input))
(defun TeX-parse-arguments (args)
"Parse TeX macro arguments ARGS.
See `TeX-parse-macro' for details."
(let ((last-optional-rejected nil))
(while args
(if (vectorp (car args))
;; Maybe get rid of all optional arguments. See `TeX-insert-macro'
;; for more comments. See `TeX-insert-macro-default-style'.
(unless (if (eq TeX-insert-macro-default-style 'show-all-optional-args)
(equal current-prefix-arg '(4))
(and (eq TeX-insert-macro-default-style 'show-optional-args)
(equal current-prefix-arg '(4)))
(and (eq TeX-insert-macro-default-style 'mandatory-args-only)
(null (equal current-prefix-arg '(4))))
(let ((TeX-arg-opening-brace LaTeX-optop)
(TeX-arg-closing-brace LaTeX-optcl))
(TeX-parse-argument t (if (equal (length (car args)) 1)
(aref (car args) 0)
(append (car args) nil)))))
(let ((TeX-arg-opening-brace TeX-grop)
(TeX-arg-closing-brace TeX-grcl))
(setq last-optional-rejected nil)
(TeX-parse-argument nil (car args))))
(setq args (cdr args)))))
(defun TeX-parse-argument (optional arg)
"Depending on OPTIONAL, insert TeX macro argument ARG.
If OPTIONAL is set, only insert if there is anything to insert, and
then use square brackets instead of curly braces.
See `TeX-parse-macro' for details."
(let (insert-flag)
(cond ((stringp arg)
(TeX-arg-string optional arg)
(setq insert-flag t))
((numberp arg)
(cond ((< arg 0)
(when (TeX-active-mark)
;; Put both the macro and the marked region in a TeX group.
(let ((beg (min (point) (mark)))
(end (set-marker (make-marker) (max (point) (mark)))))
(insert " ")
(goto-char beg)
(skip-chars-backward "^\\\\")
(insert TeX-arg-opening-brace)
(goto-char (marker-position end))
(insert TeX-arg-closing-brace)
(setq insert-flag t))))
((= arg 0)) ; nop for clarity
((> arg 0)
(TeX-parse-argument optional t)
(while (> arg 1)
(TeX-parse-argument optional nil)
(setq arg (- arg 1))))))
((null arg)
(insert TeX-arg-opening-brace)
(when (and (not optional) (TeX-active-mark))
(insert TeX-arg-closing-brace)
(setq insert-flag t))
((eq arg t)
(insert TeX-arg-opening-brace)
(if (and (not optional) (TeX-active-mark))
(set-marker exit-mark (point)))
(insert TeX-arg-closing-brace)
(setq insert-flag t))
((symbolp arg)
(funcall arg optional))
((listp arg)
(let ((head (car arg))
(tail (cdr arg)))
(cond ((stringp head)
(apply 'TeX-arg-string optional arg))
((symbolp head)
(apply head optional tail))
(t (error "Unknown list argument type %s"
(prin1-to-string head))))))
(t (error "Unknown argument type %s" (prin1-to-string arg))))
(when (and insert-flag (not optional) (TeX-active-mark))
(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 square brackets.
If PREFIX is given, insert it before NAME."
(if (and optional (string-equal name ""))
(setq last-optional-rejected t)
(insert TeX-arg-opening-brace)
(if prefix
(insert prefix))
(if (and (string-equal name "")
(null (marker-position exit-mark)))
(set-marker exit-mark (point))
(insert name))
(insert TeX-arg-closing-brace)))
(defun TeX-argument-prompt (optional prompt default &optional complete)
"Return a argument prompt.
If OPTIONAL is not nil then the prompt will start with ``(Optional) ''.
PROMPT will be used if not nil, otherwise use DEFAULT.
Unless optional argument COMPLETE is non-nil, ``: '' will be appended."
(concat (if optional "(Optional) " "")
(if prompt prompt default)
(if complete "" ": ")))
(defun TeX-string-divide-number-unit (string)
"Divide number and unit in STRING and return a list (number unit)."
(if (string-match "[0-9]*\\.?[0-9]+" string)
(list (substring string 0 (string-match "[^.0-9]" string))
(substring string (if (string-match "[^.0-9]" string)
(string-match "[^.0-9]" string)
(length string))))
(list "" string)))
(defcustom TeX-default-unit-for-image "cm"
"Default unit when prompting for an image size."
:group 'TeX-macro
:type '(choice (const "cm")
(const "in")
(const "\\linewidth")
(string :tag "Other")))
(defun TeX-arg-maybe (symbol list form)
"Evaluates FORM, if SYMBOL is an element of LIST."
(when (memq symbol list)
(eval form)))
(defun TeX-arg-free (optional &rest args)
"Parse its arguments but use no braces when they are inserted."
(let ((TeX-arg-opening-brace "")
(TeX-arg-closing-brace ""))
(if (equal (length args) 1)
(TeX-parse-argument optional (car args))
(TeX-parse-argument optional args))))
(defun TeX-arg-literal (optional &rest args)
"Insert its arguments ARGS into the buffer.
Used for specifying extra syntax for a macro. The compatibility
argument OPTION is ignored."
(apply 'insert args))
;;; Font Locking
(defcustom TeX-install-font-lock 'font-latex-setup
"Function to call to install font lock support.
Choose `ignore' if you don't want AUCTeX to install support for font locking."
:group 'TeX-misc
:type '(radio (function-item font-latex-setup)
(function-item tex-font-setup)
(function-item ignore)
(function :tag "Other")))
;;; The Mode
(defvar TeX-format-list
'(("JLATEX" japanese-latex-mode
("JTEX" japanese-plain-tex-mode
"-- string likely in Japanese TeX --")
("AMSTEX" ams-tex-mode
("CONTEXT" context-mode
("LATEX" latex-mode
("TEX" plain-tex-mode "."))
"*List of format packages to consider when choosing a TeX mode.
A list with an entry for each format package available at the site.
Each entry is a list with three elements.
1. The name of the format package.
2. The name of the major mode.
3. A regexp typically matched in the beginning of the file.
When entering `tex-mode', each regexp is tried in turn in order to find
the major mode to be used.")
(defcustom TeX-default-mode 'latex-mode
"*Mode to enter for a new file when it can't be determined otherwise."
:group 'TeX-misc
:type '(radio (function-item latex-mode)
(function-item plain-tex-mode)
(function :tag "Other")))
(defcustom TeX-force-default-mode nil
"*If set to nil, try to infer the mode of the file from its content."
:group 'TeX-misc
:type 'boolean)
(defun TeX-tex-mode ()
"Major mode in AUCTeX for editing TeX or LaTeX files.
Tries to guess whether this file is for plain TeX or LaTeX.
The algorithm is as follows:
1) if the file is empty or `TeX-force-default-mode' is not set to nil,
`TeX-default-mode' is chosen
2) If \\documentstyle or \\begin{, \\section{, \\part{ or \\chapter{ is
found, `latex-mode' is selected.
3) Otherwise, use `plain-tex-mode'"
(funcall (if (or (equal (buffer-size) 0)
(goto-char (point-min))
(let ((comment-start-skip ;Used by TeX-in-comment
(regexp-quote TeX-esc)
(regexp-quote TeX-esc)
"\\)*\\)\\(%+ *\\)"))
(entry TeX-format-list)
answer case-fold-search)
(while (and entry (not answer))
(if (re-search-forward (nth 2 (car entry))
10000 t)
(if (not (TeX-in-comment))