;;; latex.el --- Support for LaTeX documents.
-;; Copyright (C) 1991, 1993-1997, 1999, 2000, 2003-2012
-;; Free Software Foundation, Inc.
+;; Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2003,
+;; 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
;; Maintainer: auctex-devel@gnu.org
;; Keywords: tex
(defun LaTeX-env-args (environment &rest args)
"Insert ENVIRONMENT and arguments defined by ARGS."
(LaTeX-insert-environment environment)
- (save-excursion
- (LaTeX-find-matching-begin)
- (end-of-line)
- (TeX-parse-arguments args)))
+ (let ((pos (point-marker)))
+ (end-of-line 0)
+ (TeX-parse-arguments args)
+ (goto-char pos)))
;;; Item hooks
(1 2 3) LaTeX-auto-optional)
(,(concat "\\\\\\(?:new\\|provide\\)command\\*?{?\\\\\\(" token "+\\)}?\\[\\([0-9]+\\)\\]")
(1 2) LaTeX-auto-arguments)
- (,(concat "\\\\\\(?:new\\|provide\\)command\\*?{?\\\\\\(" token "+\\)}?")
- 1 TeX-auto-symbol)
+ (,(concat "\\\\\\(?:new\\|provide\\)command\\*?{?\\\\\\(" token "+\\)}?") 1 TeX-auto-symbol)
(,(concat "\\\\newenvironment\\*?{?\\(" token "+\\)}?\\[\\([0-9]+\\)\\]\\[")
1 LaTeX-auto-environment)
(,(concat "\\\\newenvironment\\*?{?\\(" token "+\\)}?\\[\\([0-9]+\\)\\]")
(1 2) LaTeX-auto-env-args)
- (,(concat "\\\\newenvironment\\*?{?\\(" token "+\\)}?")
- 1 LaTeX-auto-environment)
+ (,(concat "\\\\newenvironment\\*?{?\\(" token "+\\)}?") 1 LaTeX-auto-environment)
(,(concat "\\\\newtheorem{\\(" token "+\\)}") 1 LaTeX-auto-environment)
("\\\\input{\\(\\.*[^#}%\\\\\\.\n\r]+\\)\\(\\.[^#}%\\\\\\.\n\r]+\\)?}"
1 TeX-auto-file)
("\\\\include{\\(\\.*[^#}%\\\\\\.\n\r]+\\)\\(\\.[^#}%\\\\\\.\n\r]+\\)?}"
1 TeX-auto-file)
- (, (concat "\\\\bibitem{\\(" token "[^, \n\r\t%\"#'()={}]*\\)}")
- 1 LaTeX-auto-bibitem)
+ (, (concat "\\\\bibitem{\\(" token "[^, \n\r\t%\"#'()={}]*\\)}") 1 LaTeX-auto-bibitem)
(, (concat "\\\\bibitem\\[[^][\n\r]+\\]{\\(" token "[^, \n\r\t%\"#'()={}]*\\)}")
1 LaTeX-auto-bibitem)
- ("\\\\bibliography{\\([^#}\\\\\n\r]+\\)}" 1 LaTeX-auto-bibliography)
- ("\\\\addbibresource\\(?:\\[[^]]+\\]\\)?{\\([^#}\\\\\n\r\.]+\\)\\..+}"
- 1 LaTeX-auto-bibliography)
- ("\\\\add\\(?:global\\|section\\)bib\\(?:\\[[^]]+\\]\\)?{\\([^#}\\\\\n\r\.]+\\)\\(?:\\..+\\)?}" 1 LaTeX-auto-bibliography)
- ("\\\\newrefsection\\[\\([^]]+\\)\\]" 1 LaTeX-split-bibs)
- ("\\\\begin{refsection}\\[\\([^]]+\\)\\]" 1 LaTeX-split-bibs)))
+ ("\\\\bibliography{\\([^#}\\\\\n\r]+\\)}" 1 LaTeX-auto-bibliography)))
LaTeX-auto-class-regexp-list
LaTeX-auto-label-regexp-list
LaTeX-auto-index-regexp-list
LaTeX-auto-minimal-regexp-list)
"List of regular expression matching common LaTeX macro definitions.")
-(defun LaTeX-split-bibs (match)
- "Extract bibliography resources from MATCH.
-Split the string at commas and remove Biber file extensions."
- (let ((bibs (TeX-split-string " *, *" (TeX-match-buffer match))))
- (dolist (bib bibs)
- (LaTeX-add-bibliographies (replace-regexp-in-string
- (concat "\\(?:\\."
- (mapconcat 'regexp-quote
- TeX-Biber-file-extensions
- "\\|\\.")
- "\\)")
- "" bib)))))
-
(defun LaTeX-auto-prepare ()
"Prepare for LaTeX parsing."
(setq LaTeX-auto-arguments nil
(defun LaTeX-listify-package-options (options)
"Return a list from a comma-separated string of package OPTIONS.
The input string may include LaTeX comments and newlines."
- ;; We jump through all those hoops and don't just use `split-string'
- ;; or the like in order to be able to deal with key=value package
- ;; options which can look like this: "pdftitle={A Perfect Day},
- ;; colorlinks=false"
- (let (opts match start)
- (with-temp-buffer
- (set-syntax-table LaTeX-mode-syntax-table)
- (insert options)
- (newline) ; So that the last entry can be found.
- (goto-char (point-min))
- (setq start (point))
- (while (re-search-forward "[{ ,%\n\r]" nil t)
- (setq match (match-string 0))
- (cond
- ;; Step over groups. (Let's hope nobody uses escaped braces.)
- ((string= match "{")
- (up-list))
- ;; Get rid of whitespace.
- ((string= match " ")
- (delete-region (1- (point))
- (save-excursion
- (skip-chars-forward " ")
- (point))))
- ;; Add entry to output.
- ((or (string= match ",") (= (point) (point-max)))
- (add-to-list 'opts (buffer-substring-no-properties
- start (1- (point))) t)
- (setq start (point)))
- ;; Get rid of comments.
- ((string= match "%")
- (delete-region (1- (point))
- (line-beginning-position 2)))
- ;; Get rid of newlines.
- ((or (string= match "\n") (string= match "\r"))
- (delete-backward-char 1)))))
+ ;; FIXME: Parse key=value options like "pdftitle={A Perfect
+ ;; Day},colorlinks=false" correctly. When this works, the check for
+ ;; "=" can be removed again.
+ (let (opts)
+ (dolist (elt (TeX-split-string "\\(,\\|%[^\n\r]*[\n\r]\\)+"
+ options))
+ (unless (string-match "=" elt)
+ ;; Strip whitespace.
+ (dolist (item (TeX-split-string "[ \t\r\n]+" elt))
+ (unless (string= item "")
+ (add-to-list 'opts item)))))
opts))
(defun LaTeX-auto-cleanup ()
"Cleanup after LaTeX parsing."
- ;; Cleanup BibTeX/Biber files
+ ;; Cleanup BibTeX files
(setq LaTeX-auto-bibliography
(apply 'append (mapcar (lambda (arg)
(TeX-split-string "," arg))
(setq LaTeX-environment-menu nil)
(setq LaTeX-environment-modify-menu nil))
-;;; Biber support
-
-(defvar LaTeX-using-Biber nil
- "Used to track whether Biber is in use.")
-(make-variable-buffer-local 'LaTeX-using-Biber)
-
;;; BibTeX
;;;###autoload
("dinbrief")
("foils")
("letter")
- ("memoir")
("minimal")
("prosper")
("report")
(defun LaTeX-arg-usepackage (optional)
"Insert arguments to usepackage.
OPTIONAL is ignored."
- (let ((TeX-file-extensions '("sty"))
- (TeX-input-file-search t))
+ (let ((TeX-file-extensions '("sty")))
(TeX-arg-input-file nil "Package")
(save-excursion
(search-backward-regexp "{\\(.*\\)}")
(mapc 'TeX-run-style-hooks (LaTeX-listify-package-options options))
(TeX-argument-insert options t))))))
-(defcustom LaTeX-search-files-type-alist
- '((texinputs "${TEXINPUTS.latex}" ("tex/generic/" "tex/latex/")
- TeX-file-extensions)
- (docs "${TEXDOCS}" ("doc/") TeX-doc-extensions)
- (graphics "${TEXINPUTS}" ("tex/") LaTeX-includegraphics-extensions)
- (bibinputs "${BIBINPUTS}" ("bibtex/bib/") BibTeX-file-extensions)
- (bstinputs "${BSTINPUTS}" ("bibtex/bst/") BibTeX-style-extensions)
- (biberinputs "${BIBINPUTS}" ("bibtex/bib/") TeX-Biber-file-extensions))
- "Alist of filetypes with locations and file extensions.
-Each element of the alist consists of a symbol expressing the
-filetype, a variable which can be expanded on kpathsea-based
-systems into the directories where files of the given type
-reside, a list of absolute directories, relative directories
-below the root of a TDS-compliant TeX tree or a list of variables
-with either type of directories as an alternative for
-non-kpathsea-based systems and a list of extensions to be matched
-upon a file search. Note that the directories have to end with a
-directory separator.
-
-Reset the mode for a change of this variable to take effect."
- :group 'TeX-file
- :type '(alist :key-type symbol
- :value-type
- (group (string :tag "Kpathsea variable")
- (choice :tag "Directories"
- (repeat :tag "TDS subdirectories" string)
- (repeat :tag "Absolute directories" directory)
- (repeat :tag "Variables" variable))
- (choice :tag "Extensions"
- variable (repeat string)))))
-
-(defcustom TeX-arg-input-file-search t
- "If `TeX-arg-input-file' should search for files.
-If the value is t, files in TeX's search path are searched for
-and provided for completion. The file name is then inserted
-without directory and extension. If the value is nil, the file
-name can be specified manually and is inserted with a path
-relative to the directory of the current buffer's file and with
-extension. If the value is `ask', you are asked for the method
-to use every time `TeX-arg-input-file' is called."
- :group 'LaTeX-macro
- :type '(choice (const t) (const nil) (const ask)))
-
(defvar TeX-global-input-files nil
"List of the non-local TeX input files.
+
Initialized once at the first time you prompt for an input file.
May be reset with `\\[universal-argument] \\[TeX-normal-mode]'.")
argument, otherwise as a mandatory one. PROMPT is the prompt,
LOCAL is a flag. If the flag is set, only complete with local
files."
- (let ((search (if (eq TeX-arg-input-file-search 'ask)
- (not (y-or-n-p "Find file yourself? "))
- TeX-arg-input-file-search))
- file style)
- (if search
- (progn
- (unless (or TeX-global-input-files local)
- (message "Searching for files...")
- (setq TeX-global-input-files
- (mapcar 'list (TeX-search-files-by-type
- 'texinputs 'global t t))))
- (setq file (completing-read
- (TeX-argument-prompt optional prompt "File")
- (TeX-delete-dups-by-car
- (append (mapcar 'list (TeX-search-files-by-type
- 'texinputs 'local t t))
- (unless local
- TeX-global-input-files))))
- style file))
- (setq file (read-file-name
- (TeX-argument-prompt optional prompt "File") nil ""))
- (unless (string-equal file "")
- (setq file (file-relative-name file)))
- (setq style (file-name-sans-extension (file-name-nondirectory file))))
- (unless (string-equal "" style)
- (TeX-run-style-hooks style))
+ (unless (or TeX-global-input-files local)
+ (message "Searching for files...")
+ (setq TeX-global-input-files
+ (mapcar 'list (TeX-search-files (append TeX-macro-private
+ TeX-macro-global)
+ TeX-file-extensions t t))))
+ (let ((file (if TeX-check-path
+ (completing-read
+ (TeX-argument-prompt optional prompt "File")
+ (TeX-delete-dups-by-car
+ (append (mapcar 'list
+ (TeX-search-files '("./")
+ TeX-file-extensions
+ t t))
+ (unless local
+ TeX-global-input-files))))
+ (read-file-name
+ (TeX-argument-prompt optional prompt "File")))))
+ (if (null file)
+ (setq file ""))
+ (if (not (string-equal "" file))
+ (TeX-run-style-hooks file))
(TeX-argument-insert file optional)))
(defvar BibTeX-global-style-files nil
(message "Searching for BibTeX styles...")
(or BibTeX-global-style-files
(setq BibTeX-global-style-files
- (mapcar 'list (TeX-search-files-by-type 'bstinputs 'global t t))))
+ (mapcar 'list
+ (TeX-search-files (append TeX-macro-private
+ TeX-macro-global)
+ BibTeX-style-extensions t t))))
+
(TeX-argument-insert
(completing-read (TeX-argument-prompt optional prompt "BibTeX style")
- (append (mapcar 'list (TeX-search-files-by-type
- 'bstinputs 'local t t))
+ (append (mapcar 'list
+ (TeX-search-files '("./")
+ BibTeX-style-extensions
+ t t))
BibTeX-global-style-files))
optional))
(defvar BibTeX-global-files nil
"Association list of BibTeX files.
-Initialized once at the first time you prompt for a BibTeX file.
-May be reset with `\\[universal-argument] \\[TeX-normal-mode]'.")
-
-(defvar TeX-Biber-global-files nil
- "Association list of Biber files.
-
-Initialized once at the first time you prompt for an Biber file.
+Initialized once at the first time you prompt for an BibTeX file.
May be reset with `\\[universal-argument] \\[TeX-normal-mode]'.")
(defun TeX-arg-bibliography (optional &optional prompt)
- "Prompt for a BibTeX or Biber database file.
+ "Prompt for a BibTeX database file.
If OPTIONAL is non-nil, insert the resulting value as an optional
argument, otherwise as a mandatory one. Use PROMPT as the prompt
string."
- (let (name files inputs styles)
- (if LaTeX-using-Biber
- (progn
- (setq name "Biber"
- files 'TeX-Biber-global-files
- inputs 'biberinputs))
- (setq name "BibTeX"
- files 'BibTeX-global-files
- inputs 'bibinputs))
- (message "Searching for %s files..." name)
- (or (symbol-value files)
- (set files (mapcar 'list (TeX-search-files-by-type
- 'biberinputs 'global t t))))
- (setq styles (multi-prompt
- "," t
- (TeX-argument-prompt optional prompt (concat name " files"))
- (append (mapcar 'list (TeX-search-files-by-type
- inputs 'local t t))
- (symbol-value files))))
+ (message "Searching for BibTeX files...")
+ (or BibTeX-global-files
+ (setq BibTeX-global-files
+ (mapcar 'list (TeX-search-files nil BibTeX-file-extensions t t))))
+
+ (let ((styles (multi-prompt
+ "," t
+ (TeX-argument-prompt optional prompt "BibTeX files")
+ (append (mapcar 'list
+ (TeX-search-files '("./")
+ BibTeX-file-extensions
+ t t))
+ BibTeX-global-files))))
(apply 'LaTeX-add-bibliographies styles)
(TeX-argument-insert (mapconcat 'identity styles ",") optional)))
key and the optional cdr should be a list with strings to be used
as values for the key."
(let ((options (multi-prompt-key-value
- (TeX-argument-prompt optional "Options (k=v)" nil)
+ (TeX-argument-prompt optional "Options" nil)
(if (symbolp key-val-alist)
(eval key-val-alist)
key-val-alist))))
(/= (point) (line-beginning-position))))))
;; Search forward for the macro end, unless we failed to find a start
(unless (bolp)
- (let* ((beg (1- (point)))
- (macro-end (match-end 0))
- ;; XXX: Here we assume we are dealing with \verb which
- ;; expects the delimiter right behind the command.
- ;; However, \lstinline can also cope with whitespace as
- ;; well as an optional argument after the command.
- (delimiter (buffer-substring-no-properties
- macro-end (1+ macro-end))))
- ;; Heuristic: If an opening brace is encountered, search for
- ;; both the opening and the closing brace as an end marker.
- ;; Like that the function should work for \verb|...| as well
- ;; as for \url{...}.
- (when (string= delimiter TeX-grop)
- (setq delimiter (concat delimiter TeX-grcl)))
- (goto-char (1+ macro-end))
- (skip-chars-forward (concat "^" delimiter))
+ (let ((beg (1- (point))))
+ (goto-char (1+ (match-end 0)))
+ (skip-chars-forward (concat "^" (buffer-substring-no-properties
+ (1- (point)) (point))))
(when (<= orig (point))
(cons beg (1+ (point)))))))))
(unless (or (bolp)
;; Comment starters and whitespace.
(TeX-looking-at-backward
- (concat "^\\([ \t]*" TeX-comment-start-regexp "+\\)*"
- "[ \t]*")
+ (concat "^\\([ \t]*" TeX-comment-start-regexp
+ "+\\)+[ \t]*")
(line-beginning-position)))
(LaTeX-fill-newline)))))
;; Leave point after final newline.
((string= match-string "$$") "$$")
(t (concat TeX-esc "]")))
(point-max) t)
- (skip-chars-forward "^ \n")
(point))
(line-beginning-position))
fill-column)))
(read-kbd-macro LaTeX-math-abbrev-prefix)
LaTeX-math-abbrev-prefix))
-(defvar LaTeX-math-keymap (make-sparse-keymap)
+(defvar LaTeX-math-keymap
+ (let ((map (make-sparse-keymap)))
+ (define-key map (LaTeX-math-abbrev-prefix) 'self-insert-command)
+ map)
"Keymap used for `LaTeX-math-mode' commands.")
(defvar LaTeX-math-menu
(list menu (vector (concat prefix value)
name t))
(vector menu name t))
- (cdr parent)))))))))
- ;; Make the math prefix char available if it has not been used as a prefix.
- (unless (lookup-key map (LaTeX-math-abbrev-prefix))
- (define-key map (LaTeX-math-abbrev-prefix) 'self-insert-command)))
+ (cdr parent))))))))))
(define-minor-mode LaTeX-math-mode
"A minor mode with easy access to TeX math macros.
:type 'hook
:group 'LaTeX)
-(TeX-abbrev-mode-setup latex-mode)
-
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.drv\\'" . latex-mode))
filladapt-mode)
(turn-off-filladapt-mode)))
-(TeX-abbrev-mode-setup doctex-mode)
-
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.dtx\\'" . doctex-mode))
"Major mode in AUCTeX for editing .dtx files derived from `LaTeX-mode'.
Runs `LaTeX-mode', sets a few variables and
runs the hooks in `docTeX-mode-hook'."
- :abbrev-table doctex-mode-abbrev-table
(setq major-mode 'doctex-mode)
(set (make-local-variable 'LaTeX-insert-into-comments) t)
(set (make-local-variable 'LaTeX-syntactic-comments) t)
(make-local-variable 'indent-line-function)
(setq indent-line-function 'LaTeX-indent-line)
- (setq local-abbrev-table latex-mode-abbrev-table)
-
;; Filling
(make-local-variable 'paragraph-ignore-fill-prefix)
(setq paragraph-ignore-fill-prefix t)
(setq TeX-verbatim-p-function 'LaTeX-verbatim-p)
(setq TeX-search-forward-comment-start-function
'LaTeX-search-forward-comment-start)
- (set (make-local-variable 'TeX-search-files-type-alist)
- LaTeX-search-files-type-alist)
(make-local-variable 'LaTeX-item-list)
(setq LaTeX-item-list '(("description" . LaTeX-item-argument)
'("nocite" TeX-arg-cite)
'("bibliographystyle" TeX-arg-bibstyle)
'("bibliography" TeX-arg-bibliography)
- '("addbibresource" TeX-arg-bibliography)
'("footnote"
(TeX-arg-conditional TeX-arg-footnote-number-p ([ "Number" ]) nil)
t)
'("setlength" TeX-arg-macro "Length")
'("addtolength" TeX-arg-macro "Length")
'("settowidth" TeX-arg-macro t)
- '("settoheight" TeX-arg-macro t)
- '("settodepth" TeX-arg-macro t)
'("\\" [ "Space" ])
'("\\*" [ "Space" ])
'("hyphenation" t)
'("include" (TeX-arg-input-file "File" t))
'("includeonly" t)
'("input" TeX-arg-input-file)
- '("addcontentsline"
- (TeX-arg-eval completing-read "File: " '(("toc") ("lof") ("lot")))
- (TeX-arg-eval completing-read "Numbering style: " LaTeX-section-list) t)
- '("addtocontents"
- (TeX-arg-eval completing-read "File: " '(("toc") ("lof") ("lot"))) t)
+ '("addcontentsline" TeX-arg-file
+ (TeX-arg-eval
+ completing-read "Numbering style: " LaTeX-section-list)
+ t)
+ '("addtocontents" TeX-arg-file t)
'("typeout" t)
'("typein" [ TeX-arg-define-macro ] t)
'("verb" TeX-arg-verb)
"clearpage" "cleardoublepage" "twocolumn" "onecolumn"
"maketitle" "tableofcontents" "listoffigures" "listoftables"
- '("tiny" -1) '("scriptsize" -1) '("footnotesize" -1) '("small" -1)
- '("normalsize" -1) '("large" -1) '("Large" -1) '("LARGE" -1) '("huge" -1)
- '("Huge" -1)
+ "tiny" "scriptsize" "footnotesize" "small"
+ "normalsize" "large" "Large" "LARGE" "huge" "Huge"
"pounds" "copyright"
"hfil" "hfill" "vfil" "vfill" "hrulefill" "dotfill"
"indent" "noindent" "today"
[ "Number of arguments" ] [ "Default value for first argument" ] t)
'("usepackage" LaTeX-arg-usepackage)
'("RequirePackage" LaTeX-arg-usepackage)
- '("ProvidesPackage" "Name" [ "Version" ])
'("documentclass" TeX-arg-document)))
(TeX-add-style-hook "latex2e"
'LaTeX-imenu-create-index-function)
(use-local-map LaTeX-mode-map)
-
;; Calling `easy-menu-add' may result in the menu filters being
;; executed which call `TeX-update-style'. So this is placed very
;; late in mode initialization to assure that all relevant variables