1 ;;; latex.el --- Support for LaTeX documents.
3 ;; Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2003,
4 ;; 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
7 ;; Maintainer: auctex-devel@gnu.org
10 ;; This file is part of AUCTeX.
12 ;; AUCTeX is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; AUCTeX is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with AUCTeX; see the file COPYING. If not, write to the Free
24 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
29 ;; This file provides AUCTeX support for LaTeX.
38 (defvar LaTeX-optop "["
39 "The LaTeX optional argument opening character.")
41 (defvar LaTeX-optcl "]"
42 "The LaTeX optional argument closeing character.")
46 (defcustom LaTeX-default-style "article"
47 "*Default when creating new documents."
48 :group 'LaTeX-environment
51 (defcustom LaTeX-default-options nil
52 "Default options to documentstyle.
54 :group 'LaTeX-environment
55 :type '(repeat (string :format "%v")))
57 (make-variable-buffer-local 'LaTeX-default-options)
59 (defcustom LaTeX-insert-into-comments t
60 "*Whether insertion commands stay in comments.
61 This allows using the insertion commands even when
62 the lines are outcommented, like in dtx files."
63 :group 'LaTeX-environment
66 (defun LaTeX-newline ()
67 "Start a new line potentially staying within comments.
68 This depends on `LaTeX-insert-into-comments'."
69 (if LaTeX-insert-into-comments
70 (cond ((and (save-excursion (skip-chars-backward " \t") (bolp))
72 (skip-chars-forward " \t")
73 (looking-at (concat TeX-comment-start-regexp "+"))))
75 (insert (buffer-substring-no-properties
76 (line-beginning-position) (match-end 0)))
80 (skip-chars-forward " \t") (not (TeX-escaped-p)))
82 (concat "[ \t]*" TeX-comment-start-regexp "+[ \t]*")))
83 (delete-region (match-beginning 0) (match-end 0))
84 (indent-new-comment-line))
86 (indent-new-comment-line)))
92 (defvar LaTeX-mode-syntax-table (copy-syntax-table TeX-mode-syntax-table)
93 "Syntax table used in LaTeX mode.")
95 (progn ; set [] to match for LaTeX.
96 (modify-syntax-entry (string-to-char LaTeX-optop)
97 (concat "(" LaTeX-optcl)
98 LaTeX-mode-syntax-table)
99 (modify-syntax-entry (string-to-char LaTeX-optcl)
100 (concat ")" LaTeX-optop)
101 LaTeX-mode-syntax-table))
105 (defun LaTeX-section (arg)
106 "Insert a template for a LaTeX section.
107 Determine the type of section to be inserted, by the argument ARG.
109 If ARG is nil or missing, use the current level.
110 If ARG is a list (selected by \\[universal-argument]), go downward one level.
111 If ARG is negative, go up that many levels.
112 If ARG is positive or zero, use absolute level:
122 The following variables can be set to customize:
124 `LaTeX-section-hook' Hooks to run when inserting a section.
125 `LaTeX-section-label' Prefix to all section labels."
128 (let* ((val (prefix-numeric-value arg))
129 (level (cond ((null arg)
130 (LaTeX-current-section))
132 (LaTeX-down-section))
134 (LaTeX-up-section (- val)))
136 (name (LaTeX-section-name level))
138 (title (if (TeX-active-mark)
139 (buffer-substring (region-beginning)
142 (done-mark (make-marker)))
143 (run-hooks 'LaTeX-section-hook)
145 (if (marker-position done-mark)
146 (goto-char (marker-position done-mark)))
147 (set-marker done-mark nil)))
149 (defun LaTeX-current-section ()
150 "Return the level of the section that contain point.
151 See also `LaTeX-section' for description of levels."
153 (max (LaTeX-largest-level)
154 (if (re-search-backward (LaTeX-outline-regexp) nil t)
155 (- (LaTeX-outline-level) (LaTeX-outline-offset))
156 (LaTeX-largest-level)))))
158 (defun LaTeX-down-section ()
159 "Return the value of a section one level under the current.
160 Tries to find what kind of section that have been used earlier in the
161 text, if this fail, it will just return one less than the current
164 (let ((current (LaTeX-current-section))
166 (regexp (LaTeX-outline-regexp)))
167 (if (not (re-search-backward regexp nil t))
171 ((eq (LaTeX-current-section) current)
172 (if (re-search-forward regexp nil t)
173 (if (<= (setq next (LaTeX-current-section)) current) ;Wow!
174 (setq next (1+ current)))
175 (setq next (1+ current))))
176 ((not (re-search-backward regexp nil t))
177 (setq next (1+ current)))))
180 (defun LaTeX-up-section (arg)
181 "Return the value of the section ARG levels above this one."
184 (LaTeX-current-section)
185 (let ((current (LaTeX-current-section)))
186 (while (and (>= (LaTeX-current-section) current)
187 (re-search-backward (LaTeX-outline-regexp)
189 (LaTeX-up-section (1- arg))))))
191 (defvar LaTeX-section-list '(("part" 0)
198 "List which elements is the names of the sections used by LaTeX.")
200 (defun LaTeX-section-list-add-locally (sections &optional clean)
201 "Add SECTIONS to `LaTeX-section-list'.
202 SECTIONS can be a single list containing the section macro name
203 as a string and the the level as an integer or a list of such
206 If optional argument CLEAN is non-nil, remove any existing
207 entries from `LaTeX-section-list' before adding the new ones.
209 The function will make `LaTeX-section-list' buffer-local and
210 invalidate the section submenu in order to let the menu filter
211 regenerate it. It is mainly a convenience function which can be
212 used in style files."
213 (when (stringp (car sections))
214 (setq sections (list sections)))
215 (make-local-variable 'LaTeX-section-list)
216 (when clean (setq LaTeX-section-list nil))
217 (dolist (elt sections) (add-to-list 'LaTeX-section-list elt t))
218 (setq LaTeX-section-list
219 (sort (copy-sequence LaTeX-section-list)
220 (lambda (a b) (< (nth 1 a) (nth 1 b)))))
221 (setq LaTeX-section-menu nil))
223 (defun LaTeX-section-name (level)
224 "Return the name of the section corresponding to LEVEL."
225 (let ((entry (TeX-member level LaTeX-section-list
226 (lambda (a b) (equal a (nth 1 b))))))
231 (defun LaTeX-section-level (name)
232 "Return the level of the section NAME."
233 (let ((entry (TeX-member name LaTeX-section-list
234 (lambda (a b) (equal a (nth 0 b))))))
240 (defcustom TeX-outline-extra nil
241 "List of extra TeX outline levels.
243 Each element is a list with two entries. The first entry is the
244 regular expression matching a header, and the second is the level of
245 the header. See `LaTeX-section-list' for existing header levels."
247 :type '(repeat (group (regexp :tag "Match")
248 (integer :tag "Level"))))
250 (defun LaTeX-outline-regexp (&optional anywhere)
251 "Return regexp for LaTeX sections.
253 If optional argument ANYWHERE is not nil, do not require that the
254 header is at the start of a line."
255 (concat (if anywhere "" "^")
257 (regexp-quote TeX-esc)
258 "\\(appendix\\|documentstyle\\|documentclass\\|"
259 (mapconcat 'car LaTeX-section-list "\\|")
261 (if TeX-outline-extra
264 (mapconcat 'car TeX-outline-extra "\\|")
266 "\\|" TeX-trailer-start))
268 (defvar LaTeX-largest-level nil
269 "Largest sectioning level with current document class.")
271 (make-variable-buffer-local 'LaTeX-largest-level)
273 (defun LaTeX-largest-level ()
274 "Return largest sectioning level with current document class.
275 Run style hooks before it has not been done."
279 (defun LaTeX-largest-level-set (section)
280 "Set `LaTeX-largest-level' to the level of SECTION.
281 SECTION has to be a string contained in `LaTeX-section-list'.
282 Additionally the function will invalidate the section submenu in
283 order to let the menu filter regenerate it."
284 (setq LaTeX-largest-level (LaTeX-section-level section))
285 (setq LaTeX-section-menu nil))
287 (defun LaTeX-outline-offset ()
288 "Offset to add to `LaTeX-section-list' levels to get outline level."
289 (- 2 (LaTeX-largest-level)))
291 (defun TeX-look-at (list)
292 "Check if we are looking at the first element of a member of LIST.
293 If so, return the second element, otherwise return nil."
295 (not (looking-at (nth 0 (car list)))))
296 (setq list (cdr list)))
301 (defun LaTeX-outline-level ()
302 "Find the level of current outline heading in an LaTeX document."
303 (cond ((looking-at LaTeX-header-end) 1)
304 ((looking-at LaTeX-trailer-start) 1)
305 ((TeX-look-at TeX-outline-extra)
306 (max 1 (+ (TeX-look-at TeX-outline-extra)
307 (LaTeX-outline-offset))))
310 (skip-chars-forward " \t")
312 (cond ((looking-at "appendix") 1)
313 ((looking-at "documentstyle") 1)
314 ((looking-at "documentclass") 1)
315 ((TeX-look-at LaTeX-section-list)
316 (max 1 (+ (TeX-look-at LaTeX-section-list)
317 (LaTeX-outline-offset))))
319 (error "Unrecognized header")))))))
321 (defun LaTeX-outline-name ()
322 "Guess a name for the current header line."
324 (if (re-search-forward "{\\([^\}]*\\)}" (+ (point) fill-column 10) t)
326 (buffer-substring (point) (min (point-max) (+ 20 (point)))))))
328 (add-hook 'TeX-remove-style-hook
329 (lambda () (setq LaTeX-largest-level nil)))
331 (defcustom LaTeX-section-hook
332 '(LaTeX-section-heading
334 ;; LaTeX-section-toc ; Most people won't want this
335 LaTeX-section-section
337 "List of hooks to run when a new section is inserted.
339 The following variables are set before the hooks are run
341 level - numeric section level, see the documentation of `LaTeX-section'.
342 name - name of the sectioning command, derived from `level'.
343 title - The title of the section, default to an empty string.
344 toc - Entry for the table of contents list, default nil.
345 done-mark - Position of point afterwards, default nil (meaning end).
347 The following standard hook exist -
349 LaTeX-section-heading: Query the user about the name of the
350 sectioning command. Modifies `level' and `name'.
352 LaTeX-section-title: Query the user about the title of the
353 section. Modifies `title'.
355 LaTeX-section-toc: Query the user for the toc entry. Modifies
358 LaTeX-section-section: Insert LaTeX section command according to
359 `name', `title', and `toc'. If `toc' is nil, no toc entry is
360 inserted. If `toc' or `title' are empty strings, `done-mark' will be
361 placed at the point they should be inserted.
363 LaTeX-section-label: Insert a label after the section command.
364 Controled by the variable `LaTeX-section-label'.
366 To get a full featured `LaTeX-section' command, insert
368 (setq LaTeX-section-hook
369 '(LaTeX-section-heading
372 LaTeX-section-section
373 LaTeX-section-label))
375 in your .emacs file."
378 :options '(LaTeX-section-heading
381 LaTeX-section-section
382 LaTeX-section-label))
385 (defcustom LaTeX-section-label
387 ("chapter" . "chap:")
389 ("subsection" . "sec:")
390 ("subsubsection" . "sec:"))
391 "Default prefix when asking for a label.
393 Some LaTeX packages \(such as `fancyref'\) look at the prefix to generate some
394 text around cross-references automatically. When using those packages, you
395 should not change this variable.
397 If it is a string, it it used unchanged for all kinds of sections.
398 If it is nil, no label is inserted.
399 If it is a list, the list is searched for a member whose car is equal
400 to the name of the sectioning command being inserted. The cdr is then
401 used as the prefix. If the name is not found, or if the cdr is nil,
402 no label is inserted."
404 :type '(choice (const :tag "none" nil)
405 (string :format "%v" :tag "Common")
406 (repeat :menu-tag "Level specific"
410 (choice :tag "Prefix"
411 (const :tag "none" nil)
412 (string :format "%v"))))))
416 (defun LaTeX-section-heading ()
417 "Hook to prompt for LaTeX section name.
418 Insert this hook into `LaTeX-section-hook' to allow the user to change
419 the name of the sectioning command inserted with `\\[LaTeX-section]'."
420 (let ((string (completing-read
421 (concat "Level: (default " name ") ")
425 (if (not (zerop (length string)))
428 (setq level (LaTeX-section-level name))))
430 (defun LaTeX-section-title ()
431 "Hook to prompt for LaTeX section title.
432 Insert this hook into `LaTeX-section-hook' to allow the user to change
433 the title of the section inserted with `\\[LaTeX-section]."
434 (setq title (read-string "Title: " title))
435 (let ((region (and (TeX-active-mark)
436 (cons (region-beginning) (region-end)))))
437 (when region (delete-region (car region) (cdr region)))))
439 (defun LaTeX-section-toc ()
440 "Hook to prompt for the LaTeX section entry in the table of content .
441 Insert this hook into `LaTeX-section-hook' to allow the user to insert
442 a different entry for the section in the table of content."
443 (setq toc (read-string "Toc Entry: "))
444 (if (zerop (length toc))
447 (defun LaTeX-section-section ()
448 "Hook to insert LaTeX section command into the file.
449 Insert this hook into `LaTeX-section-hook' after those hooks that set
450 the `name', `title', and `toc' variables, but before those hooks that
451 assume that the section is already inserted."
452 ;; insert a new line if the current line and the previous line are
453 ;; not empty (except for whitespace), with one exception: do not
454 ;; insert a new line if the previous (or current, sigh) line starts
455 ;; an environment (i.e., starts with `[optional whitespace]\begin')
456 (unless (save-excursion
458 (concat "^\\s-*\n\\s-*\\=\\|^\\s-*" (regexp-quote TeX-esc)
460 (line-beginning-position 0) t))
462 (insert TeX-esc name)
464 ((zerop (length toc))
466 (set-marker done-mark (point))
467 (insert LaTeX-optcl))
469 (insert LaTeX-optop toc LaTeX-optcl)))
471 (if (zerop (length title))
472 (set-marker done-mark (point)))
473 (insert title TeX-grcl)
475 ;; If RefTeX is available, tell it that we've just made a new section
476 (and (fboundp 'reftex-notice-new-section)
477 (reftex-notice-new-section)))
479 (defun LaTeX-section-label ()
480 "Hook to insert a label after the sectioning command.
481 Insert this hook into `LaTeX-section-hook' to prompt for a label to be
482 inserted after the sectioning command.
484 The behaviour of this hook is controlled by variable `LaTeX-section-label'."
485 (and (LaTeX-label name)
490 (defgroup LaTeX-environment nil
491 "Environments in AUCTeX."
494 (defcustom LaTeX-default-environment "itemize"
495 "*The default environment when creating new ones with `LaTeX-environment'."
496 :group 'LaTeX-environment
498 (make-variable-buffer-local 'LaTeX-default-environment)
500 (defvar LaTeX-environment-history nil)
502 ;; Variable used to cache the current environment, e.g. for repeated
503 ;; tasks in an environment, like indenting each line in a paragraph to
504 ;; be filled. It must not have a non-nil value in general. That
505 ;; means it is usually let-bound for such operations.
506 (defvar LaTeX-current-environment nil)
508 (defun LaTeX-environment (arg)
509 "Make LaTeX environment (\\begin{...}-\\end{...} pair).
510 With optional ARG, modify current environment.
512 It may be customized with the following variables:
514 `LaTeX-default-environment' Your favorite environment.
515 `LaTeX-default-style' Your favorite document class.
516 `LaTeX-default-options' Your favorite document class options.
517 `LaTeX-float' Where you want figures and tables to float.
518 `LaTeX-table-label' Your prefix to labels in tables.
519 `LaTeX-figure-label' Your prefix to labels in figures.
520 `LaTeX-default-format' Format for array and tabular.
521 `LaTeX-default-width' Width for minipage and tabular*.
522 `LaTeX-default-position' Position for array and tabular."
525 (let ((environment (completing-read (concat "Environment type: (default "
528 LaTeX-default-environment)
530 (LaTeX-environment-list)
532 'LaTeX-environment-history)))
534 (cond ((and (zerop (length environment))
536 (setq environment "document"))
537 ((zerop (length environment))
538 (setq environment LaTeX-default-environment))
540 (setq LaTeX-default-environment environment)))
542 (let ((entry (assoc environment (LaTeX-environment-list))))
544 (LaTeX-add-environments (list environment)))
547 (LaTeX-modify-environment environment)
548 (LaTeX-environment-menu environment)))))
550 (defun LaTeX-environment-menu (environment)
551 "Insert ENVIRONMENT around point or region."
552 (let ((entry (assoc environment (LaTeX-environment-list))))
553 (cond ((not (and entry (nth 1 entry)))
554 (LaTeX-insert-environment environment))
555 ((numberp (nth 1 entry))
556 (let ((count (nth 1 entry))
559 (setq args (concat args TeX-grop TeX-grcl))
560 (setq count (- count 1)))
561 (LaTeX-insert-environment environment args)))
562 ((or (stringp (nth 1 entry)) (vectorp (nth 1 entry)))
563 (let ((prompts (cdr entry))
565 (dolist (elt prompts)
566 (let* ((optional (vectorp elt))
567 (elt (if optional (elt elt 0) elt))
568 (arg (read-string (concat (when optional "(Optional) ")
570 (setq args (concat args
571 (cond ((and optional (> (length arg) 0))
572 (concat LaTeX-optop arg LaTeX-optcl))
574 (concat TeX-grop arg TeX-grcl)))))))
575 (LaTeX-insert-environment environment args)))
577 (apply (nth 1 entry) environment (nthcdr 2 entry))))))
579 (defun LaTeX-close-environment (&optional reopen)
580 "Create an \\end{...} to match the current environment.
581 With prefix-argument, reopen environment afterwards."
586 (when LaTeX-insert-into-comments
587 (if (looking-at comment-start-skip)
588 (goto-char (match-end 0))))
589 (skip-chars-forward " \t")
592 (let ((environment (LaTeX-current-environment 1)) marker)
593 (insert "\\end{" environment "}")
594 (indent-according-to-mode)
595 (if (or (not (looking-at "[ \t]*$"))
596 (and (TeX-in-commented-line)
597 (save-excursion (beginning-of-line 2)
598 (not (TeX-in-commented-line)))))
600 (let ((next-line-add-newlines t))
602 (beginning-of-line)))
603 (indent-according-to-mode)
606 (setq marker (point-marker))
607 (set-marker-insertion-type marker t)
608 (LaTeX-environment-menu environment)
609 (delete-region (point)
610 (if (save-excursion (goto-char marker)
614 (move-marker marker nil)))))
616 (defvar LaTeX-after-insert-env-hooks nil
617 "List of functions to be run at the end of `LaTeX-insert-environment'.
618 Each function is called with three arguments: the name of the
619 environment just inserted, the buffer position just before
620 \\begin and the position just before \\end.")
622 (defun LaTeX-insert-environment (environment &optional extra)
623 "Insert LaTeX ENVIRONMENT with optional argument EXTRA."
624 (let ((active-mark (and (TeX-active-mark) (not (eq (mark) (point)))))
625 prefix content-start env-start env-end)
626 (when (and active-mark (< (mark) (point))) (exchange-point-and-mark))
627 ;; Compute the prefix.
628 (when (and LaTeX-insert-into-comments (TeX-in-commented-line))
632 (concat "^\\([ \t]*" TeX-comment-start-regexp "+\\)+[ \t]*"))
633 (setq prefix (match-string 0))))
634 ;; What to do with the line containing point.
635 (cond ((save-excursion (beginning-of-line)
636 (looking-at (concat prefix "[ \t]*$")))
637 (delete-region (match-beginning 0) (match-end 0)))
638 ((TeX-looking-at-backward (concat "^" prefix "[ \t]*")
639 (line-beginning-position))
642 (beginning-of-line 0))
644 (delete-horizontal-space)
646 (beginning-of-line 0))
648 (delete-horizontal-space)
650 (when prefix (insert prefix))
651 (beginning-of-line 0)))
652 ;; What to do with the line containing mark.
656 (cond ((save-excursion (beginning-of-line)
657 (or (looking-at (concat prefix "[ \t]*$"))
658 (looking-at "[ \t]*$")))
659 (delete-region (match-beginning 0) (match-end 0)))
660 ((TeX-looking-at-backward (concat "^" prefix "[ \t]*")
661 (line-beginning-position))
664 (beginning-of-line 0))
666 (delete-horizontal-space)
667 (insert-before-markers "\n")
669 (when prefix (insert prefix))))))
670 ;; Now insert the environment.
671 (when prefix (insert prefix))
672 (setq env-start (point))
673 (insert TeX-esc "begin" TeX-grop environment TeX-grcl)
674 (indent-according-to-mode)
675 (when extra (insert extra))
676 (setq content-start (line-beginning-position 2))
679 (when prefix (insert prefix))
681 (when active-mark (goto-char (mark)))
682 (when prefix (insert prefix))
683 (setq env-end (point))
684 (insert TeX-esc "end" TeX-grop environment TeX-grcl)
688 (or (assoc environment LaTeX-indent-environment-list)
689 (LaTeX-fill-region content-start (line-beginning-position 2)))
690 (set-mark content-start))
691 (indent-according-to-mode))
692 (save-excursion (beginning-of-line 2) (indent-according-to-mode))
693 (TeX-math-input-method-off)
694 (run-hook-with-args 'LaTeX-after-insert-env-hooks
695 environment env-start env-end)))
697 (defun LaTeX-modify-environment (environment)
698 "Modify current ENVIRONMENT."
700 (LaTeX-find-matching-end)
701 (re-search-backward (concat (regexp-quote TeX-esc)
703 (regexp-quote TeX-grop)
705 (regexp-quote TeX-grcl))
706 (save-excursion (beginning-of-line 1) (point)))
707 (replace-match (concat TeX-esc "end" TeX-grop environment TeX-grcl) t t)
708 (beginning-of-line 1)
709 (LaTeX-find-matching-begin)
710 (re-search-forward (concat (regexp-quote TeX-esc)
712 (regexp-quote TeX-grop)
714 (regexp-quote TeX-grcl))
715 (save-excursion (end-of-line 1) (point)))
716 (replace-match (concat TeX-esc "begin" TeX-grop environment TeX-grcl) t t)))
718 (defun LaTeX-current-environment (&optional arg)
719 "Return the name (a string) of the enclosing LaTeX environment.
720 With optional ARG>=1, find that outer level.
722 If function is called inside a comment and
723 `LaTeX-syntactic-comments' is enabled, try to find the
724 environment in commented regions with the same comment prefix.
726 The functions `LaTeX-find-matching-begin' and `LaTeX-find-matching-end'
728 (setq arg (if arg (if (< arg 1) 1 arg) 1))
729 (let* ((in-comment (TeX-in-commented-line))
730 (comment-prefix (and in-comment (TeX-comment-prefix))))
732 (while (and (/= arg 0)
734 "\\\\\\(begin\\|end\\) *{ *\\([A-Za-z*]+\\) *}" nil t))
735 (when (or (and LaTeX-syntactic-comments
736 (eq in-comment (TeX-in-commented-line))
738 ;; Consider only matching prefixes in the
740 (string= comment-prefix (TeX-comment-prefix))))
741 (and (not LaTeX-syntactic-comments)
742 (not (TeX-in-commented-line))))
743 (setq arg (if (string= (match-string 1) "end") (1+ arg) (1- arg)))))
746 (match-string-no-properties 2)))))
748 (defun docTeX-in-macrocode-p ()
749 "Determine if point is inside a macrocode environment."
752 (concat "^% " (regexp-quote TeX-esc)
753 "\\(begin\\|end\\)[ \t]*{macrocode\\*?}") nil 'move)
755 (= (char-after (match-beginning 1)) ?e)))))
758 ;;; Environment Hooks
760 (defvar LaTeX-document-style-hook nil
761 "List of hooks to run when inserting a document environment.
763 To insert a hook here, you must insert it in the appropiate style file.")
765 (defun LaTeX-env-document (&optional ignore)
766 "Create new LaTeX document.
767 The compatibility argument IGNORE is ignored."
768 (TeX-insert-macro "documentclass")
773 (LaTeX-insert-environment "document")
774 (run-hooks 'LaTeX-document-style-hook)
775 (setq LaTeX-document-style-hook nil))
777 (defcustom LaTeX-float ""
778 "Default float position for figures and tables.
779 If nil, act like the empty string is given, but do not prompt.
780 \(The standard LaTeX classes use [tbp] as float position if the
781 optional argument is omitted.)"
782 :group 'LaTeX-environment
783 :type '(choice (const :tag "Do not prompt" nil)
784 (const :tag "Empty" "")
785 (string :format "%v")))
786 (make-variable-buffer-local 'LaTeX-float)
788 (defcustom LaTeX-top-caption-list nil
789 "*List of float environments with top caption."
790 :group 'LaTeX-environment
791 :type '(repeat (string :format "%v")))
793 (defgroup LaTeX-label nil
794 "Adding labels for LaTeX commands in AUCTeX."
797 (defcustom LaTeX-label-function nil
798 "*A function inserting a label at point.
799 Sole argument of the function is the environment. The function has to return
800 the label inserted, or nil if no label was inserted."
804 (defcustom LaTeX-figure-label "fig:"
805 "*Default prefix to figure labels."
807 :group 'LaTeX-environment
810 (defcustom LaTeX-table-label "tab:"
811 "*Default prefix to table labels."
813 :group 'LaTeX-environment
816 (defcustom LaTeX-default-format ""
817 "Default format for array and tabular environments."
818 :group 'LaTeX-environment
820 (make-variable-buffer-local 'LaTeX-default-format)
822 (defcustom LaTeX-default-width "1.0\\linewidth"
823 "Default width for minipage and tabular* environments."
824 :group 'LaTeX-environment
826 (make-variable-buffer-local 'LaTeX-default-width)
828 (defcustom LaTeX-default-position ""
829 "Default position for array and tabular environments.
830 If nil, act like the empty string is given, but do not prompt."
831 :group 'LaTeX-environment
832 :type '(choice (const :tag "Do not prompt" nil)
833 (const :tag "Empty" "")
835 (make-variable-buffer-local 'LaTeX-default-position)
837 (defcustom LaTeX-equation-label "eq:"
838 "*Default prefix to equation labels."
842 (defcustom LaTeX-eqnarray-label LaTeX-equation-label
843 "*Default prefix to eqnarray labels."
847 (defun LaTeX-env-item (environment)
848 "Insert ENVIRONMENT and the first item."
849 (LaTeX-insert-environment environment)
850 (if (TeX-active-mark)
852 (LaTeX-find-matching-begin)
856 (when (looking-at (concat "^[ \t]+$\\|"
857 "^[ \t]*" TeX-comment-start-regexp "+[ \t]*$"))
858 (delete-region (point) (line-end-position)))
859 (delete-horizontal-space)
860 ;; Deactivate the mark here in order to prevent `TeX-parse-macro'
861 ;; from swapping point and mark and the \item ending up right after
863 (TeX-deactivate-mark)
865 ;; The inserted \item may have outdented the first line to the
866 ;; right. Fill it, if appropriate.
867 (when (and (not (looking-at "$"))
868 (not (assoc environment LaTeX-indent-environment-list))
869 (> (- (line-end-position) (line-beginning-position))
870 (current-fill-column)))
871 (LaTeX-fill-paragraph nil)))
873 (defcustom LaTeX-label-alist
874 '(("figure" . LaTeX-figure-label)
875 ("table" . LaTeX-table-label)
876 ("figure*" . LaTeX-figure-label)
877 ("table*" . LaTeX-table-label)
878 ("equation" . LaTeX-equation-label)
879 ("eqnarray" . LaTeX-eqnarray-label))
880 "Lookup prefixes for labels.
881 An alist where the CAR is the environment name, and the CDR
882 either the prefix or a symbol referring to one."
884 :type '(repeat (cons (string :tag "Environment")
885 (choice (string :tag "Label prefix")
886 (symbol :tag "Label prefix symbol")))))
888 (make-variable-buffer-local 'LaTeX-label-alist)
890 (defun LaTeX-label (environment)
891 "Insert a label for ENVIRONMENT at point.
892 If `LaTeX-label-function' is a valid function, LaTeX label will transfer the
893 job to this function."
895 (if (and (boundp 'LaTeX-label-function)
897 (fboundp LaTeX-label-function))
899 (setq label (funcall LaTeX-label-function environment))
901 (or (cdr (assoc environment LaTeX-label-alist))
902 (if (assoc environment LaTeX-section-list)
903 (if (stringp LaTeX-section-label)
905 (and (listp LaTeX-section-label)
906 (cdr (assoc environment LaTeX-section-label))))
909 (when (symbolp prefix)
910 (setq prefix (symbol-value prefix)))
911 ;; Use completing-read as we do with `C-c C-m \label RET'
912 (setq label (completing-read
913 (TeX-argument-prompt t nil "What label")
914 (LaTeX-label-list) nil nil prefix))
915 ;; No label or empty string entered?
916 (if (or (string= prefix label)
919 (insert TeX-esc "label" TeX-grop label TeX-grcl))))
922 (LaTeX-add-labels label)
926 (defun LaTeX-env-figure (environment)
927 "Create ENVIRONMENT with \\caption and \\label commands."
928 (let ((float (and LaTeX-float ; LaTeX-float can be nil, i.e.
930 (read-string "(Optional) Float position: " LaTeX-float)))
931 (caption (read-string "Caption: "))
932 (center (y-or-n-p "Center? "))
933 (active-mark (and (TeX-active-mark)
934 (not (eq (mark) (point)))))
935 start-marker end-marker)
937 (if (< (mark) (point))
938 (exchange-point-and-mark))
939 (setq start-marker (point-marker))
940 (set-marker-insertion-type start-marker t)
941 (setq end-marker (copy-marker (mark))))
942 (setq LaTeX-float float)
943 (LaTeX-insert-environment environment
944 (unless (zerop (length float))
945 (concat LaTeX-optop float
947 (when active-mark (goto-char start-marker))
949 (insert TeX-esc "centering")
950 (indent-according-to-mode)
952 (if (member environment LaTeX-top-caption-list)
953 ;; top caption -- do nothing if user skips caption
954 (unless (zerop (length caption))
955 (insert TeX-esc "caption" TeX-grop caption TeX-grcl)
957 (indent-according-to-mode)
958 ;; ask for a label and insert a new line only if a label is
960 (when (LaTeX-label environment)
962 (indent-according-to-mode)))
963 ;; bottom caption (default) -- do nothing if user skips caption
964 (unless (zerop (length caption))
965 (when active-mark (goto-char end-marker))
967 (indent-according-to-mode)
968 (insert TeX-esc "caption" TeX-grop caption TeX-grcl)
970 (indent-according-to-mode)
971 ;; ask for a label -- if user skips label, remove the last new
973 (if (LaTeX-label environment)
975 (unless (looking-at "[ \t]*$")
980 ;; if there is a caption or a label, move point upwards again
981 ;; so that it is placed above the caption or the label (or
982 ;; both) -- search the current line (even long captions are
983 ;; inserted on a single line, even if auto-fill is turned on,
984 ;; so it is enough to search the current line) for \label or
985 ;; \caption and go one line upwards if any of them is found
986 (while (re-search-backward
987 (concat "^\\s-*" (regexp-quote TeX-esc)
988 "\\(label\\|caption\\)")
989 (line-beginning-position) t)
991 (indent-according-to-mode))))
992 (when (and (member environment '("table" "table*"))
993 ;; Suppose an existing tabular environment should just
994 ;; be wrapped into a table if there is an active region.
996 (LaTeX-env-array "tabular"))))
998 (defun LaTeX-env-array (environment)
999 "Insert ENVIRONMENT with position and column specifications.
1000 Just like array and tabular."
1001 (let ((pos (and LaTeX-default-position ; LaTeX-default-position can
1002 ; be nil, i.e. do not prompt
1003 (read-string "(Optional) Position: " LaTeX-default-position)))
1004 (fmt (read-string "Format: " LaTeX-default-format)))
1005 (setq LaTeX-default-position pos)
1006 (setq LaTeX-default-format fmt)
1007 (LaTeX-insert-environment environment
1009 (unless (zerop (length pos))
1010 (concat LaTeX-optop pos LaTeX-optcl))
1011 (concat TeX-grop fmt TeX-grcl)))))
1013 (defun LaTeX-env-label (environment)
1014 "Insert ENVIRONMENT and prompt for label."
1015 (LaTeX-insert-environment environment)
1016 (when (LaTeX-label environment)
1018 (indent-according-to-mode)))
1020 (defun LaTeX-env-list (environment)
1021 "Insert ENVIRONMENT and the first item."
1022 (let ((label (read-string "Default Label: ")))
1023 (LaTeX-insert-environment environment
1024 (format "{%s}{}" label))
1027 (delete-horizontal-space))
1028 (LaTeX-insert-item))
1030 (defun LaTeX-env-minipage (environment)
1031 "Create new LaTeX minipage or minipage-like ENVIRONMENT."
1032 (let ((pos (and LaTeX-default-position ; LaTeX-default-position can
1033 ; be nil, i.e. do not prompt
1034 (read-string "(Optional) Position: " LaTeX-default-position)))
1035 (width (read-string "Width: " LaTeX-default-width)))
1036 (setq LaTeX-default-position pos)
1037 (setq LaTeX-default-width width)
1038 (LaTeX-insert-environment environment
1040 (unless (zerop (length pos))
1041 (concat LaTeX-optop pos LaTeX-optcl))
1042 (concat TeX-grop width TeX-grcl)))))
1044 (defun LaTeX-env-tabular* (environment)
1045 "Insert ENVIRONMENT with width, position and column specifications."
1046 (let ((width (read-string "Width: " LaTeX-default-width))
1047 (pos (and LaTeX-default-position ; LaTeX-default-position can
1048 ; be nil, i.e. do not prompt
1049 (read-string "(Optional) Position: " LaTeX-default-position)))
1050 (fmt (read-string "Format: " LaTeX-default-format)))
1051 (setq LaTeX-default-width width)
1052 (setq LaTeX-default-position pos)
1053 (setq LaTeX-default-format fmt)
1054 (LaTeX-insert-environment environment
1056 (concat TeX-grop width TeX-grcl) ;; not optional!
1057 (unless (zerop (length pos))
1058 (concat LaTeX-optop pos LaTeX-optcl))
1059 (concat TeX-grop fmt TeX-grcl)))))
1061 (defun LaTeX-env-picture (environment)
1062 "Insert ENVIRONMENT with width, height specifications."
1063 (let ((width (read-string "Width: "))
1064 (height (read-string "Height: "))
1065 (x-offset (read-string "X Offset: "))
1066 (y-offset (read-string "Y Offset: ")))
1067 (if (zerop (length x-offset))
1068 (setq x-offset "0"))
1069 (if (zerop (length y-offset))
1070 (setq y-offset "0"))
1071 (LaTeX-insert-environment environment
1073 (format "(%s,%s)" width height)
1074 (if (not (and (string= x-offset "0")
1075 (string= y-offset "0")))
1076 (format "(%s,%s)" x-offset y-offset))))))
1078 (defun LaTeX-env-bib (environment)
1079 "Insert ENVIRONMENT with label for bibitem."
1080 (LaTeX-insert-environment environment
1082 (read-string "Label for BibItem: " "99")
1086 (delete-horizontal-space)
1087 (LaTeX-insert-item))
1089 (defun LaTeX-env-contents (environment)
1090 "Insert ENVIRONMENT with filename for contents."
1092 (when (re-search-backward "^\\\\documentclass.*{" nil t)
1093 (error "Put %s environment before \\documentclass" environment)))
1094 (LaTeX-insert-environment environment
1096 (read-string "File: ")
1098 (delete-horizontal-space))
1100 (defun LaTeX-env-args (environment &rest args)
1101 "Insert ENVIRONMENT and arguments defined by ARGS."
1102 (LaTeX-insert-environment environment)
1104 (LaTeX-find-matching-begin)
1106 (TeX-parse-arguments args)))
1110 (defvar LaTeX-item-list nil
1111 "A list of environments where items have a special syntax.
1112 The cdr is the name of the function, used to insert this kind of items.")
1114 (defun LaTeX-insert-item ()
1115 "Insert a new item in an environment.
1116 You may use `LaTeX-item-list' to change the routines used to insert the item."
1118 (let ((environment (LaTeX-current-environment)))
1119 (when (and (TeX-active-mark)
1121 (exchange-point-and-mark))
1122 (unless (bolp) (LaTeX-newline))
1123 (if (assoc environment LaTeX-item-list)
1124 (funcall (cdr (assoc environment LaTeX-item-list)))
1125 (TeX-insert-macro "item"))
1126 (indent-according-to-mode)))
1128 (defun LaTeX-item-argument ()
1129 "Insert a new item with an optional argument."
1130 (let ((TeX-arg-item-label-p t))
1131 (TeX-insert-macro "item")))
1133 (defun LaTeX-item-bib ()
1134 "Insert a new bibitem."
1135 (TeX-insert-macro "bibitem"))
1139 (defvar LaTeX-auto-minimal-regexp-list
1140 '(("\\\\document\\(style\\|class\\)\
1141 \\(\\[\\(\\([^#\\%]\\|%[^\n\r]*[\n\r]\\)*\\)\\]\\)?\
1142 {\\([^#\\.\n\r]+?\\)}"
1143 (3 5 1) LaTeX-auto-style)
1144 ("\\\\use\\(package\\)\\(\\[\\([^\]\\]*\\)\\]\\)?\
1145 {\\(\\([^#}\\.%]\\|%[^\n\r]*[\n\r]\\)+?\\)}"
1146 (3 4 1) LaTeX-auto-style))
1147 "Minimal list of regular expressions matching LaTeX macro definitions.")
1149 (defvar LaTeX-auto-label-regexp-list
1150 '(("\\\\label{\\([^\n\r%\\{}]+\\)}" 1 LaTeX-auto-label))
1151 "List of regular expression matching LaTeX labels only.")
1153 (defvar LaTeX-auto-index-regexp-list
1154 '(("\\\\\\(index\\|glossary\\){\\([^}{]*\\({[^}{]*\\({[^}{]*\\({[^}{]*}[^}{]*\\)*}[^}{]*\\)*}[^}{]*\\)*\\)}"
1155 2 LaTeX-auto-index-entry))
1156 "List of regular expression matching LaTeX index/glossary entries only.
1157 Regexp allows for up to 3 levels of parenthesis inside the index argument.
1158 This is necessary since index entries may contain commands and stuff.")
1160 (defvar LaTeX-auto-class-regexp-list
1161 '(;; \RequirePackage[<options>]{<package>}[<date>]
1162 ("\\\\Require\\(Package\\)\\(\\[\\([^#\\.%]*?\\)\\]\\)?\
1163 {\\([^#\\.\n\r]+?\\)}"
1164 (3 4 1) LaTeX-auto-style)
1165 ;; \RequirePackageWithOptions{<package>}[<date>],
1166 ("\\\\Require\\(Package\\)WithOptions\\(\\){\\([^#\\.\n\r]+?\\)}"
1167 (2 3 1) LaTeX-auto-style)
1168 ;; \LoadClass[<options>]{<package>}[<date>]
1169 ("\\\\Load\\(Class\\)\\(\\[\\([^#\\.%]*?\\)\\]\\)?{\\([^#\\.\n\r]+?\\)}"
1170 (3 4 1) LaTeX-auto-style)
1171 ;; \LoadClassWithOptions{<package>}[<date>]
1172 ("\\\\Load\\(Class\\)WithOptions\\(\\){\\([^#\\.\n\r]+?\\)}"
1173 (2 3 1) LaTeX-auto-style)
1174 ;; \DeclareRobustCommand{<cmd>}[<num>][<default>]{<definition>},
1175 ;; \DeclareRobustCommand*{<cmd>}[<num>][<default>]{<definition>}
1176 ("\\\\DeclareRobustCommand\\*?{?\\\\\\([A-Za-z]+\\)}?\
1177 \\[\\([0-9]+\\)\\]\\[\\([^\n\r]*?\\)\\]"
1178 (1 2 3) LaTeX-auto-optional)
1179 ("\\\\DeclareRobustCommand\\*?{?\\\\\\([A-Za-z]+\\)}?\\[\\([0-9]+\\)\\]"
1180 (1 2) LaTeX-auto-arguments)
1181 ("\\\\DeclareRobustCommand\\*?{?\\\\\\([A-Za-z]+\\)}?"
1183 ;; Patterns for commands described in "LaTeX2e font selection" (fntguide)
1184 ("\\\\DeclareMath\\(?:Symbol\\|Delimiter\\|Accent\\|Radical\\)\
1185 {?\\\\\\([A-Za-z]+\\)}?"
1187 ("\\\\\\(Declare\\|Provide\\)Text\
1188 \\(?:Command\\|Symbol\\|Accent\\|Composite\\){?\\\\\\([A-Za-z]+\\)}?"
1190 ("\\\\Declare\\(?:Text\\|Old\\)FontCommand{?\\\\\\([A-Za-z]+\\)}?"
1192 "List of regular expressions matching macros in LaTeX classes and packages.")
1194 (defvar LaTeX-auto-regexp-list
1196 (let ((token TeX-token-char))
1197 `((,(concat "\\\\\\(?:new\\|provide\\)command\\*?{?\\\\\\(" token "+\\)}?\\[\\([0-9]+\\)\\]\\[\\([^\n\r]*\\)\\]")
1198 (1 2 3) LaTeX-auto-optional)
1199 (,(concat "\\\\\\(?:new\\|provide\\)command\\*?{?\\\\\\(" token "+\\)}?\\[\\([0-9]+\\)\\]")
1200 (1 2) LaTeX-auto-arguments)
1201 (,(concat "\\\\\\(?:new\\|provide\\)command\\*?{?\\\\\\(" token "+\\)}?")
1203 (,(concat "\\\\newenvironment\\*?{?\\(" token "+\\)}?\\[\\([0-9]+\\)\\]\\[")
1204 1 LaTeX-auto-environment)
1205 (,(concat "\\\\newenvironment\\*?{?\\(" token "+\\)}?\\[\\([0-9]+\\)\\]")
1206 (1 2) LaTeX-auto-env-args)
1207 (,(concat "\\\\newenvironment\\*?{?\\(" token "+\\)}?")
1208 1 LaTeX-auto-environment)
1209 (,(concat "\\\\newtheorem{\\(" token "+\\)}") 1 LaTeX-auto-environment)
1210 ("\\\\input{\\(\\.*[^#}%\\\\\\.\n\r]+\\)\\(\\.[^#}%\\\\\\.\n\r]+\\)?}"
1212 ("\\\\include{\\(\\.*[^#}%\\\\\\.\n\r]+\\)\\(\\.[^#}%\\\\\\.\n\r]+\\)?}"
1214 (, (concat "\\\\bibitem{\\(" token "[^, \n\r\t%\"#'()={}]*\\)}")
1215 1 LaTeX-auto-bibitem)
1216 (, (concat "\\\\bibitem\\[[^][\n\r]+\\]{\\(" token "[^, \n\r\t%\"#'()={}]*\\)}")
1217 1 LaTeX-auto-bibitem)
1218 ("\\\\bibliography{\\([^#}\\\\\n\r]+\\)}" 1 LaTeX-auto-bibliography)
1219 ("\\\\addbibresource\\(?:\\[[^]]+\\]\\)?{\\([^#}\\\\\n\r\.]+\\)\\..+}"
1220 1 LaTeX-auto-bibliography)
1221 ("\\\\add\\(?:global\\|section\\)bib\\(?:\\[[^]]+\\]\\)?{\\([^#}\\\\\n\r\.]+\\)\\(?:\\..+\\)?}" 1 LaTeX-auto-bibliography)
1222 ("\\\\newrefsection\\[\\([^]]+\\)\\]" 1 LaTeX-split-bibs)
1223 ("\\\\begin{refsection}\\[\\([^]]+\\)\\]" 1 LaTeX-split-bibs)))
1224 LaTeX-auto-class-regexp-list
1225 LaTeX-auto-label-regexp-list
1226 LaTeX-auto-index-regexp-list
1227 LaTeX-auto-minimal-regexp-list)
1228 "List of regular expression matching common LaTeX macro definitions.")
1230 (defun LaTeX-split-bibs (match)
1231 "Extract bibliography resources from MATCH.
1232 Split the string at commas and remove Biber file extensions."
1233 (let ((bibs (TeX-split-string " *, *" (TeX-match-buffer match))))
1235 (LaTeX-add-bibliographies (replace-regexp-in-string
1237 (mapconcat 'regexp-quote
1238 TeX-Biber-file-extensions
1243 (defun LaTeX-auto-prepare ()
1244 "Prepare for LaTeX parsing."
1245 (setq LaTeX-auto-arguments nil
1246 LaTeX-auto-optional nil
1247 LaTeX-auto-env-args nil
1248 LaTeX-auto-style nil
1249 LaTeX-auto-end-symbol nil))
1251 (add-hook 'TeX-auto-prepare-hook 'LaTeX-auto-prepare)
1253 (defun LaTeX-listify-package-options (options)
1254 "Return a list from a comma-separated string of package OPTIONS.
1255 The input string may include LaTeX comments and newlines."
1256 ;; We jump through all those hoops and don't just use `split-string'
1257 ;; or the like in order to be able to deal with key=value package
1258 ;; options which can look like this: "pdftitle={A Perfect Day},
1259 ;; colorlinks=false"
1260 (let (opts match start)
1262 (set-syntax-table LaTeX-mode-syntax-table)
1264 (newline) ; So that the last entry can be found.
1265 (goto-char (point-min))
1266 (setq start (point))
1267 (while (re-search-forward "[{ ,%\n\r]" nil t)
1268 (setq match (match-string 0))
1270 ;; Step over groups. (Let's hope nobody uses escaped braces.)
1271 ((string= match "{")
1273 ;; Get rid of whitespace.
1274 ((string= match " ")
1275 (delete-region (1- (point))
1277 (skip-chars-forward " ")
1279 ;; Add entry to output.
1280 ((or (string= match ",") (= (point) (point-max)))
1281 (add-to-list 'opts (buffer-substring-no-properties
1282 start (1- (point))) t)
1283 (setq start (point)))
1284 ;; Get rid of comments.
1285 ((string= match "%")
1286 (delete-region (1- (point))
1287 (line-beginning-position 2)))
1288 ;; Get rid of newlines.
1289 ((or (string= match "\n") (string= match "\r"))
1290 (delete-backward-char 1)))))
1293 (defun LaTeX-auto-cleanup ()
1294 "Cleanup after LaTeX parsing."
1296 ;; Cleanup BibTeX/Biber files
1297 (setq LaTeX-auto-bibliography
1298 (apply 'append (mapcar (lambda (arg)
1299 (TeX-split-string "," arg))
1300 LaTeX-auto-bibliography)))
1302 ;; Cleanup document classes and packages
1303 (unless (null LaTeX-auto-style)
1304 (while LaTeX-auto-style
1305 (let* ((entry (car LaTeX-auto-style))
1306 (options (nth 0 entry))
1307 (style (nth 1 entry))
1308 (class (nth 2 entry)))
1310 ;; Next document style.
1311 (setq LaTeX-auto-style (cdr LaTeX-auto-style))
1314 (setq options (LaTeX-listify-package-options options))
1316 ;; Add them, to the style list.
1317 (dolist (elt options)
1318 (add-to-list 'TeX-auto-file elt))
1320 ;; Treat documentclass/documentstyle specially.
1321 (if (or (string-equal "package" class)
1322 (string-equal "Package" class))
1323 (dolist (elt (TeX-split-string
1324 "\\([ \t\r\n]\\|%[^\n\r]*[\n\r]\\|,\\)+" style))
1325 (add-to-list 'TeX-auto-file elt))
1326 ;; And a special "art10" style file combining style and size.
1327 (add-to-list 'TeX-auto-file style)
1328 (add-to-list 'TeX-auto-file
1330 (cond ((string-equal "article" style)
1332 ((string-equal "book" style)
1334 ((string-equal "report" style)
1336 ((string-equal "jarticle" style)
1338 ((string-equal "jbook" style)
1340 ((string-equal "jreport" style)
1342 ((string-equal "j-article" style)
1344 ((string-equal "j-book" style)
1346 ((string-equal "j-report" style )
1349 (cond ((member "11pt" options)
1351 ((member "12pt" options)
1356 ;; The third argument if "class" indicates LaTeX2e features.
1357 (cond ((equal class "class")
1358 (add-to-list 'TeX-auto-file "latex2e"))
1359 ((equal class "style")
1360 (add-to-list 'TeX-auto-file "latex2"))))))
1362 ;; Cleanup optional arguments
1363 (mapc (lambda (entry)
1364 (add-to-list 'TeX-auto-symbol
1366 (string-to-number (nth 1 entry)))))
1367 LaTeX-auto-arguments)
1369 ;; Cleanup default optional arguments
1370 (mapc (lambda (entry)
1371 (add-to-list 'TeX-auto-symbol
1374 (1- (string-to-number (nth 1 entry))))))
1375 LaTeX-auto-optional)
1377 ;; Cleanup environments arguments
1378 (mapc (lambda (entry)
1379 (add-to-list 'LaTeX-auto-environment
1381 (string-to-number (nth 1 entry)))))
1382 LaTeX-auto-env-args)
1384 ;; Cleanup use of def to add environments
1385 ;; NOTE: This uses an O(N^2) algorithm, while an O(N log N)
1386 ;; algorithm is possible.
1387 (mapc (lambda (symbol)
1388 (if (not (TeX-member symbol TeX-auto-symbol 'equal))
1389 ;; No matching symbol, insert in list
1390 (add-to-list 'TeX-auto-symbol (concat "end" symbol))
1391 ;; Matching symbol found, remove from list
1392 (if (equal (car TeX-auto-symbol) symbol)
1393 ;; Is it the first symbol?
1394 (setq TeX-auto-symbol (cdr TeX-auto-symbol))
1395 ;; Nope! Travel the list
1396 (let ((list TeX-auto-symbol))
1397 (while (consp (cdr list))
1398 ;; Until we find it.
1399 (if (equal (car (cdr list)) symbol)
1401 (setcdr list (cdr (cdr list))))
1402 (setq list (cdr list)))))
1403 ;; and add the symbol as an environment.
1404 (add-to-list 'LaTeX-auto-environment symbol)))
1405 LaTeX-auto-end-symbol))
1407 (add-hook 'TeX-auto-cleanup-hook 'LaTeX-auto-cleanup)
1409 (TeX-auto-add-type "label" "LaTeX")
1410 (TeX-auto-add-type "bibitem" "LaTeX")
1411 (TeX-auto-add-type "environment" "LaTeX")
1412 (TeX-auto-add-type "bibliography" "LaTeX" "bibliographies")
1413 (TeX-auto-add-type "index-entry" "LaTeX" "index-entries")
1415 (fset 'LaTeX-add-bibliographies-auto
1416 (symbol-function 'LaTeX-add-bibliographies))
1417 (defun LaTeX-add-bibliographies (&rest bibliographies)
1418 "Add BIBLIOGRAPHIES to the list of known bibliographies and style files."
1419 (apply 'LaTeX-add-bibliographies-auto bibliographies)
1420 (apply 'TeX-run-style-hooks bibliographies))
1422 (fset 'LaTeX-add-environments-auto
1423 (symbol-function 'LaTeX-add-environments))
1424 (defun LaTeX-add-environments (&rest environments)
1425 "Add ENVIRONMENTS to the list of known environments.
1426 Additionally invalidate the environment submenus to let them be
1427 regenerated by the respective menu filter."
1428 (apply 'LaTeX-add-environments-auto environments)
1429 (setq LaTeX-environment-menu nil)
1430 (setq LaTeX-environment-modify-menu nil))
1434 (defvar LaTeX-using-Biber nil
1435 "Used to track whether Biber is in use.")
1436 (make-variable-buffer-local 'LaTeX-using-Biber)
1441 (defun BibTeX-auto-store ()
1442 "This function should be called from `bibtex-mode-hook'.
1443 It will setup BibTeX to store keys in an auto file."
1444 ;; We want this to be early in the list, so we do not
1445 ;; add it before we enter BibTeX mode the first time.
1446 (if (boundp 'local-write-file-hooks)
1447 (add-hook 'local-write-file-hooks 'TeX-safe-auto-write)
1448 (add-hook 'write-file-hooks 'TeX-safe-auto-write))
1449 (make-local-variable 'TeX-auto-update)
1450 (setq TeX-auto-update 'BibTeX)
1451 (make-local-variable 'TeX-auto-untabify)
1452 (setq TeX-auto-untabify nil)
1453 (make-local-variable 'TeX-auto-parse-length)
1454 (setq TeX-auto-parse-length 999999)
1455 (make-local-variable 'TeX-auto-regexp-list)
1456 (setq TeX-auto-regexp-list BibTeX-auto-regexp-list)
1457 (make-local-variable 'TeX-master)
1458 (setq TeX-master t))
1460 (defvar BibTeX-auto-regexp-list
1461 `(("@[Ss][Tt][Rr][Ii][Nn][Gg]" 1 ignore)
1462 (,(concat "@[a-zA-Z]+[{(][ \t]*\\(" TeX-token-char "[^, \n\r\t%\"#'()={}]*\\)")
1463 1 LaTeX-auto-bibitem))
1464 "List of regexp-list expressions matching BibTeX items.")
1466 ;;; Macro Argument Hooks
1468 (defun TeX-arg-conditional (optional expr then else)
1469 "Implement if EXPR THEN ELSE.
1471 If OPTIONAL is non-nil, insert the resulting value as an optional
1472 argument, otherwise as a mandatory one.
1474 If EXPR evaluate to true, parse THEN as an argument list, else parse
1475 ELSE as an argument list."
1476 (TeX-parse-arguments (if (eval expr) then else)))
1478 (defun TeX-arg-eval (optional &rest args)
1479 "Evaluate ARGS and insert value in buffer.
1480 If OPTIONAL is non-nil, insert the resulting value as an optional
1481 argument, otherwise as a mandatory one."
1482 (TeX-argument-insert (eval args) optional))
1484 (defun TeX-arg-label (optional &optional prompt definition)
1485 "Prompt for a label completing with known labels.
1486 If OPTIONAL is non-nil, insert the resulting value as an optional
1487 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1488 string. If DEFINITION is non-nil, add the chosen label to the
1489 list of defined labels."
1490 (let ((label (completing-read (TeX-argument-prompt optional prompt "Key")
1491 (LaTeX-label-list))))
1492 (if (and definition (not (string-equal "" label)))
1493 (LaTeX-add-labels label))
1494 (TeX-argument-insert label optional optional)))
1496 (defalias 'TeX-arg-ref 'TeX-arg-label)
1498 (defun TeX-arg-index-tag (optional &optional prompt &rest args)
1499 "Prompt for an index tag.
1500 This is the name of an index, not the entry.
1502 If OPTIONAL is non-nil, insert the resulting value as an optional
1503 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1504 string. ARGS is unused."
1506 (setq prompt (concat (if optional "(Optional) " "")
1507 (if prompt prompt "Index tag")
1508 ": (default none) "))
1509 (setq tag (read-string prompt))
1510 (TeX-argument-insert tag optional)))
1512 (defun TeX-arg-index (optional &optional prompt &rest args)
1513 "Prompt for an index entry completing with known entries.
1514 If OPTIONAL is non-nil, insert the resulting value as an optional
1515 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1516 string. ARGS is unused."
1517 (let ((entry (completing-read (TeX-argument-prompt optional prompt "Key")
1518 (LaTeX-index-entry-list))))
1519 (if (and (not (string-equal "" entry))
1520 (not (member (list entry) (LaTeX-index-entry-list))))
1521 (LaTeX-add-index-entries entry))
1522 (TeX-argument-insert entry optional optional)))
1524 (defalias 'TeX-arg-define-index 'TeX-arg-index)
1526 (defun TeX-arg-macro (optional &optional prompt definition)
1527 "Prompt for a TeX macro with completion.
1528 If OPTIONAL is non-nil, insert the resulting value as an optional
1529 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1530 string. If DEFINITION is non-nil, add the chosen macro to the
1531 list of defined macros."
1532 (let ((macro (completing-read (TeX-argument-prompt optional prompt
1536 (TeX-symbol-list))))
1537 (if (and definition (not (string-equal "" macro)))
1538 (TeX-add-symbols macro))
1539 (TeX-argument-insert macro optional TeX-esc)))
1541 (defun TeX-arg-environment (optional &optional prompt definition)
1542 "Prompt for a LaTeX environment with completion.
1543 If OPTIONAL is non-nil, insert the resulting value as an optional
1544 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1545 string. If DEFINITION is non-nil, add the chosen environment to
1546 the list of defined environments."
1547 (let ((environment (completing-read (TeX-argument-prompt optional prompt
1549 (TeX-symbol-list))))
1550 (if (and definition (not (string-equal "" environment)))
1551 (LaTeX-add-environments environment))
1553 (TeX-argument-insert environment optional)))
1555 ;; Why is DEFINITION unused?
1556 (defun TeX-arg-cite (optional &optional prompt definition)
1557 "Prompt for a BibTeX citation with completion.
1558 If OPTIONAL is non-nil, insert the resulting value as an optional
1559 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1560 string. DEFINITION is unused."
1561 (setq prompt (concat (if optional "(Optional) " "")
1562 (if prompt prompt "Add key")
1563 ": (default none) "))
1564 (let ((items (multi-prompt "," t prompt (LaTeX-bibitem-list))))
1565 (apply 'LaTeX-add-bibitems items)
1566 (TeX-argument-insert (mapconcat 'identity items ",") optional optional)))
1568 ;; Why is DEFINITION unused?
1569 (defun TeX-arg-counter (optional &optional prompt definition)
1570 "Prompt for a LaTeX counter.
1571 If OPTIONAL is non-nil, insert the resulting value as an optional
1572 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1573 string. DEFINITION is unused."
1574 ;; Completion not implemented yet.
1575 (TeX-argument-insert
1576 (read-string (TeX-argument-prompt optional prompt "Counter"))
1579 ;; Why is DEFINITION unused?
1580 (defun TeX-arg-savebox (optional &optional prompt definition)
1581 "Prompt for a LaTeX savebox.
1582 If OPTIONAL is non-nil, insert the resulting value as an optional
1583 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1584 string. DEFINITION is unused."
1585 ;; Completion not implemented yet.
1586 (TeX-argument-insert
1587 (read-string (TeX-argument-prompt optional prompt
1588 (concat "Savebox: " TeX-esc)
1592 (defun TeX-arg-file (optional &optional prompt)
1593 "Prompt for a filename in the current directory.
1594 If OPTIONAL is non-nil, insert the resulting value as an optional
1595 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1597 (TeX-argument-insert (read-file-name (TeX-argument-prompt optional
1602 (defun TeX-arg-define-label (optional &optional prompt)
1603 "Prompt for a label completing with known labels.
1604 If OPTIONAL is non-nil, insert the resulting value as an optional
1605 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1607 (TeX-arg-label optional prompt t))
1609 (defun TeX-arg-define-macro (optional &optional prompt)
1610 "Prompt for a TeX macro with completion.
1611 If OPTIONAL is non-nil, insert the resulting value as an optional
1612 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1614 (TeX-arg-macro optional prompt t))
1616 (defun TeX-arg-define-environment (optional &optional prompt)
1617 "Prompt for a LaTeX environment with completion.
1618 If OPTIONAL is non-nil, insert the resulting value as an optional
1619 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1621 (TeX-arg-environment optional prompt t))
1623 (defun TeX-arg-define-cite (optional &optional prompt)
1624 "Prompt for a BibTeX citation.
1625 If OPTIONAL is non-nil, insert the resulting value as an optional
1626 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1628 (TeX-arg-cite optional prompt t))
1630 (defun TeX-arg-define-counter (optional &optional prompt)
1631 "Prompt for a LaTeX counter.
1632 If OPTIONAL is non-nil, insert the resulting value as an optional
1633 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1635 (TeX-arg-counter optional prompt t))
1637 (defun TeX-arg-define-savebox (optional &optional prompt)
1638 "Prompt for a LaTeX savebox.
1639 If OPTIONAL is non-nil, insert the resulting value as an optional
1640 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1642 (TeX-arg-savebox optional prompt t))
1644 (defcustom LaTeX-style-list '(("amsart")
1661 "List of document classes offered when inserting a document environment."
1662 :group 'LaTeX-environment
1663 :type '(repeat (group (string :format "%v"))))
1665 (defun TeX-arg-document (optional &optional ignore)
1666 "Insert arguments to documentclass.
1667 OPTIONAL and IGNORE are ignored."
1668 (let ((style (completing-read
1669 (concat "Document class: (default " LaTeX-default-style ") ")
1671 (options (read-string "Options: "
1672 (if (stringp LaTeX-default-options)
1673 LaTeX-default-options
1674 (mapconcat 'identity
1675 LaTeX-default-options
1677 (if (zerop (length style))
1678 (setq style LaTeX-default-style))
1679 (if (not (zerop (length options)))
1680 (insert LaTeX-optop options LaTeX-optcl))
1681 (insert TeX-grop style TeX-grcl))
1683 ;; remove old information
1686 ;; defined in individual style hooks
1689 (defun LaTeX-arg-usepackage (optional)
1690 "Insert arguments to usepackage.
1691 OPTIONAL is ignored."
1692 (let ((TeX-file-extensions '("sty"))
1693 (TeX-input-file-search t))
1694 (TeX-arg-input-file nil "Package")
1696 (search-backward-regexp "{\\(.*\\)}")
1697 (let* ((package (match-string 1))
1698 (var (intern (format "LaTeX-%s-package-options" package)))
1700 (TeX-arg-opening-brace LaTeX-optop)
1701 (TeX-arg-closing-brace LaTeX-optcl)
1703 (if (or (and (boundp var)
1704 (listp (symbol-value var)))
1707 (setq options (funcall var))
1708 (when (symbol-value var)
1710 (mapconcat 'identity
1711 (TeX-completing-read-multiple
1712 "Options: " (mapcar 'list (symbol-value var)))
1714 (setq options (read-string "Options: ")))
1716 ;; XXX: The following statement will add the options
1717 ;; supplied to the LaTeX package to the style list. This is
1718 ;; consistent with the way the parser works (see
1719 ;; `LaTeX-auto-cleanup'). But in a revamped style system
1720 ;; such options should be associated with their LaTeX
1721 ;; package to avoid confusion. For example a `german' entry
1722 ;; in the style list can come from documentclass options and
1723 ;; does not necessarily mean that the babel-related
1724 ;; extensions should be activated.
1725 (mapc 'TeX-run-style-hooks (LaTeX-listify-package-options options))
1726 (TeX-argument-insert options t))))))
1728 (defcustom LaTeX-search-files-type-alist
1729 '((texinputs "${TEXINPUTS.latex}" ("tex/generic/" "tex/latex/")
1730 TeX-file-extensions)
1731 (docs "${TEXDOCS}" ("doc/") TeX-doc-extensions)
1732 (graphics "${TEXINPUTS}" ("tex/") LaTeX-includegraphics-extensions)
1733 (bibinputs "${BIBINPUTS}" ("bibtex/bib/") BibTeX-file-extensions)
1734 (bstinputs "${BSTINPUTS}" ("bibtex/bst/") BibTeX-style-extensions)
1735 (biberinputs "${BIBINPUTS}" ("bibtex/bib/") TeX-Biber-file-extensions))
1736 "Alist of filetypes with locations and file extensions.
1737 Each element of the alist consists of a symbol expressing the
1738 filetype, a variable which can be expanded on kpathsea-based
1739 systems into the directories where files of the given type
1740 reside, a list of absolute directories, relative directories
1741 below the root of a TDS-compliant TeX tree or a list of variables
1742 with either type of directories as an alternative for
1743 non-kpathsea-based systems and a list of extensions to be matched
1744 upon a file search. Note that the directories have to end with a
1745 directory separator.
1747 Reset the mode for a change of this variable to take effect."
1749 :type '(alist :key-type symbol
1751 (group (string :tag "Kpathsea variable")
1752 (choice :tag "Directories"
1753 (repeat :tag "TDS subdirectories" string)
1754 (repeat :tag "Absolute directories" directory)
1755 (repeat :tag "Variables" variable))
1756 (choice :tag "Extensions"
1757 variable (repeat string)))))
1759 (defcustom TeX-arg-input-file-search t
1760 "If `TeX-arg-input-file' should search for files.
1761 If the value is t, files in TeX's search path are searched for
1762 and provided for completion. The file name is then inserted
1763 without directory and extension. If the value is nil, the file
1764 name can be specified manually and is inserted with a path
1765 relative to the directory of the current buffer's file and with
1766 extension. If the value is `ask', you are asked for the method
1767 to use every time `TeX-arg-input-file' is called."
1769 :type '(choice (const t) (const nil) (const ask)))
1771 (defvar TeX-global-input-files nil
1772 "List of the non-local TeX input files.
1773 Initialized once at the first time you prompt for an input file.
1774 May be reset with `\\[universal-argument] \\[TeX-normal-mode]'.")
1776 (defun TeX-arg-input-file (optional &optional prompt local)
1777 "Prompt for a tex or sty file.
1778 If OPTIONAL is non-nil, insert the resulting value as an optional
1779 argument, otherwise as a mandatory one. PROMPT is the prompt,
1780 LOCAL is a flag. If the flag is set, only complete with local
1782 (let ((search (if (eq TeX-arg-input-file-search 'ask)
1783 (not (y-or-n-p "Find file yourself? "))
1784 TeX-arg-input-file-search))
1788 (unless (or TeX-global-input-files local)
1789 (message "Searching for files...")
1790 (setq TeX-global-input-files
1791 (mapcar 'list (TeX-search-files-by-type
1792 'texinputs 'global t t))))
1793 (setq file (completing-read
1794 (TeX-argument-prompt optional prompt "File")
1795 (TeX-delete-dups-by-car
1796 (append (mapcar 'list (TeX-search-files-by-type
1797 'texinputs 'local t t))
1799 TeX-global-input-files))))
1801 (setq file (read-file-name
1802 (TeX-argument-prompt optional prompt "File") nil ""))
1803 (unless (string-equal file "")
1804 (setq file (file-relative-name file)))
1805 (setq style (file-name-sans-extension (file-name-nondirectory file))))
1806 (unless (string-equal "" style)
1807 (TeX-run-style-hooks style))
1808 (TeX-argument-insert file optional)))
1810 (defvar BibTeX-global-style-files nil
1811 "Association list of BibTeX style files.
1813 Initialized once at the first time you prompt for an input file.
1814 May be reset with `\\[universal-argument] \\[TeX-normal-mode]'.")
1816 (defun TeX-arg-bibstyle (optional &optional prompt)
1817 "Prompt for a BibTeX style file.
1818 If OPTIONAL is non-nil, insert the resulting value as an optional
1819 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1821 (message "Searching for BibTeX styles...")
1822 (or BibTeX-global-style-files
1823 (setq BibTeX-global-style-files
1824 (mapcar 'list (TeX-search-files-by-type 'bstinputs 'global t t))))
1825 (TeX-argument-insert
1826 (completing-read (TeX-argument-prompt optional prompt "BibTeX style")
1827 (append (mapcar 'list (TeX-search-files-by-type
1828 'bstinputs 'local t t))
1829 BibTeX-global-style-files))
1832 (defvar BibTeX-global-files nil
1833 "Association list of BibTeX files.
1835 Initialized once at the first time you prompt for a BibTeX file.
1836 May be reset with `\\[universal-argument] \\[TeX-normal-mode]'.")
1838 (defvar TeX-Biber-global-files nil
1839 "Association list of Biber files.
1841 Initialized once at the first time you prompt for an Biber file.
1842 May be reset with `\\[universal-argument] \\[TeX-normal-mode]'.")
1844 (defun TeX-arg-bibliography (optional &optional prompt)
1845 "Prompt for a BibTeX or Biber database file.
1846 If OPTIONAL is non-nil, insert the resulting value as an optional
1847 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1849 (let (name files inputs styles)
1850 (if LaTeX-using-Biber
1853 files 'TeX-Biber-global-files
1854 inputs 'biberinputs))
1856 files 'BibTeX-global-files
1858 (message "Searching for %s files..." name)
1859 (or (symbol-value files)
1860 (set files (mapcar 'list (TeX-search-files-by-type
1861 'biberinputs 'global t t))))
1862 (setq styles (multi-prompt
1864 (TeX-argument-prompt optional prompt (concat name " files"))
1865 (append (mapcar 'list (TeX-search-files-by-type
1867 (symbol-value files))))
1868 (apply 'LaTeX-add-bibliographies styles)
1869 (TeX-argument-insert (mapconcat 'identity styles ",") optional)))
1871 (defun TeX-arg-corner (optional &optional prompt)
1872 "Prompt for a LaTeX side or corner position with completion.
1873 If OPTIONAL is non-nil, insert the resulting value as an optional
1874 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1876 (TeX-argument-insert
1877 (completing-read (TeX-argument-prompt optional prompt "Position")
1878 '(("") ("l") ("r") ("t") ("b") ("tl") ("tr") ("bl") ("br"))
1882 (defun TeX-arg-lr (optional &optional prompt)
1883 "Prompt for a LaTeX side with completion.
1884 If OPTIONAL is non-nil, insert the resulting value as an optional
1885 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1887 (TeX-argument-insert
1888 (completing-read (TeX-argument-prompt optional prompt "Position")
1893 (defun TeX-arg-tb (optional &optional prompt)
1894 "Prompt for a LaTeX side with completion.
1895 If OPTIONAL is non-nil, insert the resulting value as an optional
1896 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1898 (TeX-argument-insert
1899 (completing-read (TeX-argument-prompt optional prompt "Position")
1904 (defun TeX-arg-pagestyle (optional &optional prompt)
1905 "Prompt for a LaTeX pagestyle with completion.
1906 If OPTIONAL is non-nil, insert the resulting value as an optional
1907 argument, otherwise as a mandatory one. Use PROMPT as the prompt
1909 (TeX-argument-insert
1910 (completing-read (TeX-argument-prompt optional prompt "Pagestyle")
1911 '(("plain") ("empty") ("headings") ("myheadings")))
1914 (defcustom LaTeX-default-verb-delimiter ?|
1915 "Default delimiter for `\\verb' macros."
1919 (defun TeX-arg-verb (optional &optional ignore)
1920 "Prompt for delimiter and text.
1921 If OPTIONAL is non-nil, insert the resulting value as an optional
1922 argument, otherwise as a mandatory one. IGNORE is ignored."
1923 (let ((del (read-quoted-char
1924 (concat "Delimiter: (default "
1925 (char-to-string LaTeX-default-verb-delimiter) ") "))))
1926 (when (<= del ?\ ) (setq del LaTeX-default-verb-delimiter))
1927 (if (TeX-active-mark)
1932 (insert del (read-from-minibuffer "Text: ") del))
1933 (setq LaTeX-default-verb-delimiter del)))
1935 (defun TeX-arg-pair (optional first second)
1936 "Insert a pair of number, prompted by FIRST and SECOND.
1938 The numbers are surounded by parenthesizes and separated with a
1941 If OPTIONAL is non-nil, insert the resulting value as an optional
1942 argument, otherwise as a mandatory one."
1943 (insert "(" (read-string (concat first ": ")) ","
1944 (read-string (concat second ": ")) ")"))
1946 (defun TeX-arg-size (optional)
1947 "Insert width and height as a pair.
1948 If OPTIONAL is non-nil, insert the resulting value as an optional
1949 argument, otherwise as a mandatory one."
1950 (TeX-arg-pair optional "Width" "Height"))
1952 (defun TeX-arg-coordinate (optional)
1953 "Insert x and y coordinate as a pair.
1954 If OPTIONAL is non-nil, insert the resulting value as an optional
1955 argument, otherwise as a mandatory one."
1956 (TeX-arg-pair optional "X position" "Y position"))
1958 (defconst TeX-braces-default-association
1965 ("\\backslash" . "\\backslash")
1966 ("\\lfloor" . "\\rfloor")
1967 ("\\lceil" . "\\rceil")
1968 ("\\langle" . "\\rangle")))
1970 (defcustom TeX-braces-user-association nil
1971 "A list of your personal association of brace symbols.
1972 These are used for \\left and \\right.
1974 The car of each entry is the brace used with \\left,
1975 the cdr is the brace used with \\right."
1978 :type '(repeat (cons :format "%v"
1979 (string :tag "Left")
1980 (string :tag "Right"))))
1982 (defvar TeX-braces-association
1983 (append TeX-braces-user-association
1984 TeX-braces-default-association)
1985 "A list of association of brace symbols for \\left and \\right.
1986 The car of each entry is the brace used with \\left,
1987 the cdr is the brace used with \\right.")
1989 (defvar TeX-left-right-braces
1990 '(("[") ("]") ("\\{") ("\\}") ("(") (")") ("|") ("\\|")
1991 ("/") ("\\backslash") ("\\lfloor") ("\\rfloor")
1992 ("\\lceil") ("\\rceil") ("\\langle") ("\\rangle")
1993 ("\\uparrow") ("\\Uparrow") ("\\downarrow") ("\\Downarrow")
1994 ("\\updownarrow") ("\\Updownarrow") ("."))
1995 "List of symbols which can follow the \\left or \\right command.")
1997 (defun TeX-arg-insert-braces (optional &optional prompt)
1998 "Prompt for a brace for \\left and insert the corresponding \\right.
1999 If OPTIONAL is non-nil, insert the resulting value as an optional
2000 argument, otherwise as a mandatory one. Use PROMPT as the prompt
2006 (indent-according-to-mode)
2007 (beginning-of-line 0)
2008 (if (looking-at "^[ \t]*$")
2009 (progn (delete-horizontal-space)
2011 (let ((left-brace (completing-read
2012 (TeX-argument-prompt optional prompt "Which brace")
2013 TeX-left-right-braces)))
2016 (indent-according-to-mode)
2018 (let ((right-brace (cdr (assoc left-brace
2019 TeX-braces-association))))
2021 (insert TeX-esc "right")
2022 (if (and TeX-arg-right-insert-p
2024 (insert right-brace)
2025 (insert (completing-read
2026 (TeX-argument-prompt optional prompt "Which brace")
2027 TeX-left-right-braces)))
2028 (indent-according-to-mode)))))
2030 (defun TeX-arg-key-val (optional key-val-alist)
2031 "Prompt for keys and values in KEY-VAL-ALIST.
2032 Insert the given value as a TeX macro argument. If OPTIONAL is
2033 non-nil, insert it as an optional argument. KEY-VAL-ALIST is an
2034 alist. The car of each element should be a string representing a
2035 key and the optional cdr should be a list with strings to be used
2036 as values for the key."
2037 (let ((options (multi-prompt-key-value
2038 (TeX-argument-prompt optional "Options (k=v)" nil)
2039 (if (symbolp key-val-alist)
2040 (eval key-val-alist)
2042 (TeX-argument-insert options optional)))
2045 ;;; Verbatim constructs
2047 (defcustom LaTeX-verbatim-macros-with-delims
2049 "Macros for inline verbatim with arguments in delimiters, like \\foo|...|.
2051 Programs should not use this variable directly but the function
2052 `LaTeX-verbatim-macros-with-delims' which returns a value
2053 including buffer-local keyword additions via
2054 `LaTeX-verbatim-macros-with-delims-local' as well."
2056 :type '(repeat (string)))
2058 (defvar LaTeX-verbatim-macros-with-delims-local nil
2059 "Buffer-local variable for inline verbatim with args in delimiters.
2061 Style files should add constructs to this variable and not to
2062 `LaTeX-verbatim-macros-with-delims'.
2064 Programs should not use this variable directly but the function
2065 `LaTeX-verbatim-macros-with-delims' which returns a value
2066 including values of the variable
2067 `LaTeX-verbatim-macros-with-delims' as well.")
2068 (make-variable-buffer-local 'LaTeX-verbatim-macros-with-delims-local)
2070 (defcustom LaTeX-verbatim-macros-with-braces nil
2071 "Macros for inline verbatim with arguments in braces, like \\foo{...}.
2073 Programs should not use this variable directly but the function
2074 `LaTeX-verbatim-macros-with-braces' which returns a value
2075 including buffer-local keyword additions via
2076 `LaTeX-verbatim-macros-with-braces-local' as well."
2078 :type '(repeat (string)))
2080 (defvar LaTeX-verbatim-macros-with-braces-local nil
2081 "Buffer-local variable for inline verbatim with args in braces.
2083 Style files should add constructs to this variable and not to
2084 `LaTeX-verbatim-macros-with-braces'.
2086 Programs should not use this variable directly but the function
2087 `LaTeX-verbatim-macros-with-braces' which returns a value
2088 including values of the variable
2089 `LaTeX-verbatim-macros-with-braces' as well.")
2090 (make-variable-buffer-local 'LaTeX-verbatim-macros-with-braces-local)
2092 (defcustom LaTeX-verbatim-environments
2093 '("verbatim" "verbatim*")
2094 "Verbatim environments.
2096 Programs should not use this variable directly but the function
2097 `LaTeX-verbatim-environments' which returns a value including
2098 buffer-local keyword additions via
2099 `LaTeX-verbatim-environments-local' as well."
2100 :group 'LaTeX-environment
2101 :type '(repeat (string)))
2103 (defvar LaTeX-verbatim-environments-local nil
2104 "Buffer-local variable for inline verbatim environments.
2106 Style files should add constructs to this variable and not to
2107 `LaTeX-verbatim-environments'.
2109 Programs should not use this variable directly but the function
2110 `LaTeX-verbatim-environments' which returns a value including
2111 values of the variable `LaTeX-verbatim-environments' as well.")
2112 (make-variable-buffer-local 'LaTeX-verbatim-environments-local)
2114 (defun LaTeX-verbatim-macros-with-delims ()
2115 "Return list of verbatim macros with delimiters."
2116 (append LaTeX-verbatim-macros-with-delims
2117 LaTeX-verbatim-macros-with-delims-local))
2119 (defun LaTeX-verbatim-macros-with-braces ()
2120 "Return list of verbatim macros with braces."
2121 (append LaTeX-verbatim-macros-with-braces
2122 LaTeX-verbatim-macros-with-braces-local))
2124 (defun LaTeX-verbatim-environments ()
2125 "Return list of verbatim environments."
2126 (append LaTeX-verbatim-environments
2127 LaTeX-verbatim-environments-local))
2129 (defun LaTeX-verbatim-macro-boundaries ()
2130 "Return boundaries of verbatim macro.
2131 Boundaries are returned as a cons cell where the car is the macro
2132 start and the cdr the macro end.
2134 Only macros which enclose their arguments with special
2135 non-parenthetical delimiters, like \\verb+foo+, are recognized."
2137 (let ((orig (point))
2138 (verbatim-regexp (regexp-opt (LaTeX-verbatim-macros-with-delims) t)))
2139 ;; Search backwards for the macro start, unless we are facing one
2140 (unless (looking-at (concat (regexp-quote TeX-esc) verbatim-regexp))
2143 (skip-chars-backward (concat "^\n" (regexp-quote TeX-esc))
2144 (line-beginning-position))
2145 (when (looking-at verbatim-regexp) (throw 'found nil))
2146 (or (bobp) (forward-char -1))
2147 (/= (point) (line-beginning-position))))))
2148 ;; Search forward for the macro end, unless we failed to find a start
2150 (let* ((beg (1- (point)))
2151 (macro-end (match-end 0))
2152 ;; XXX: Here we assume we are dealing with \verb which
2153 ;; expects the delimiter right behind the command.
2154 ;; However, \lstinline can also cope with whitespace as
2155 ;; well as an optional argument after the command.
2156 (delimiter (buffer-substring-no-properties
2157 macro-end (1+ macro-end))))
2158 ;; Heuristic: If an opening brace is encountered, search for
2159 ;; both the opening and the closing brace as an end marker.
2160 ;; Like that the function should work for \verb|...| as well
2161 ;; as for \url{...}.
2162 (when (string= delimiter TeX-grop)
2163 (setq delimiter (concat delimiter TeX-grcl)))
2164 (goto-char (1+ macro-end))
2165 (skip-chars-forward (concat "^" delimiter))
2166 (when (<= orig (point))
2167 (cons beg (1+ (point)))))))))
2169 (defun LaTeX-current-verbatim-macro ()
2170 "Return name of verbatim macro containing point, nil if none is present."
2171 (let ((macro-boundaries (LaTeX-verbatim-macro-boundaries)))
2172 (when macro-boundaries
2174 (goto-char (car macro-boundaries))
2175 (forward-char (length TeX-esc))
2176 (buffer-substring-no-properties
2177 (point) (progn (skip-chars-forward "@A-Za-z") (point)))))))
2179 (defun LaTeX-verbatim-p (&optional pos)
2180 "Return non-nil if position POS is in a verbatim-like construct."
2181 (when pos (goto-char pos))
2183 (or (when (fboundp 'font-latex-faces-present-p)
2184 (font-latex-faces-present-p 'font-latex-verbatim-face))
2185 (member (LaTeX-current-verbatim-macro)
2186 (LaTeX-verbatim-macros-with-delims))
2187 (member (TeX-current-macro) (LaTeX-verbatim-macros-with-braces))
2188 (member (LaTeX-current-environment) (LaTeX-verbatim-environments)))))
2193 (defcustom LaTeX-syntactic-comments t
2194 "If non-nil comments will be handled according to LaTeX syntax.
2195 This variable influences, among others, the behavior of
2196 indentation and filling which will take LaTeX syntax into
2197 consideration just as is in the non-commented source code."
2204 ;; We are distinguishing two different types of comments:
2206 ;; 1) Comments starting in column one (line comments)
2208 ;; 2) Comments starting after column one with only whitespace
2211 ;; (There is actually a third type: Comments preceded not only by
2212 ;; whitespace but by some code as well; so-called code comments. But
2213 ;; they are not relevant for the following explanations.)
2215 ;; Additionally we are distinguishing two different types of
2218 ;; a) Outer indentation: Indentation before the comment character(s).
2220 ;; b) Inner indentation: Indentation after the comment character(s)
2221 ;; (taking into account possible comment padding).
2223 ;; Comments can be filled syntax-aware or not.
2225 ;; In `doctex-mode' line comments should always be indented
2226 ;; syntax-aware and the comment character has to be anchored at the
2227 ;; first column (unless the appear in a macrocode environment). Other
2228 ;; comments not in the documentation parts always start after the
2229 ;; first column and can be indented syntax-aware or not. If they are
2230 ;; indented syntax-aware both the indentation before and after the
2231 ;; comment character(s) have to be checked and adjusted. Indentation
2232 ;; should not move the comment character(s) to the first column. With
2233 ;; `LaTeX-syntactic-comments' disabled, line comments should still be
2234 ;; indented syntax-aware.
2236 ;; In `latex-mode' comments starting in different columns don't have
2237 ;; to be handled differently. They don't have to be anchored in
2238 ;; column one. That means that in any case indentation before and
2239 ;; after the comment characters has to be checked and adjusted.
2241 (defgroup LaTeX-indentation nil
2242 "Indentation of LaTeX code in AUCTeX"
2244 :group 'TeX-indentation)
2246 (defcustom LaTeX-indent-level 2
2247 "*Indentation of begin-end blocks in LaTeX."
2248 :group 'LaTeX-indentation
2251 (defcustom LaTeX-item-indent (- LaTeX-indent-level)
2252 "*Extra indentation for lines beginning with an item."
2253 :group 'LaTeX-indentation
2256 (defcustom LaTeX-item-regexp "\\(bib\\)?item\\b"
2257 "*Regular expression matching macros considered items."
2258 :group 'LaTeX-indentation
2261 (defcustom LaTeX-indent-environment-list
2262 '(("verbatim" current-indentation)
2263 ("verbatim*" current-indentation)
2264 ;; The following should have there own, smart indentation function.
2278 "Alist of environments with special indentation.
2279 The second element in each entry is the function to calculate the
2280 indentation level in columns."
2281 :group 'LaTeX-indentation
2282 :type '(repeat (list (string :tag "Environment")
2283 (option function))))
2285 (defcustom LaTeX-indent-environment-check t
2286 "*If non-nil, check for any special environments."
2287 :group 'LaTeX-indentation
2290 (defcustom LaTeX-document-regexp "document"
2291 "Regexp matching environments in which the indentation starts at col 0."
2292 :group 'LaTeX-indentation
2295 (defcustom LaTeX-verbatim-regexp "verbatim\\*?"
2296 "*Regexp matching environments with indentation at col 0 for begin/end."
2297 :group 'LaTeX-indentation
2300 (defcustom LaTeX-begin-regexp "begin\\b"
2301 "*Regexp matching macros considered begins."
2302 :group 'LaTeX-indentation
2305 (defcustom LaTeX-end-regexp "end\\b"
2306 "*Regexp matching macros considered ends."
2307 :group 'LaTeX-indentation
2310 (defcustom LaTeX-left-right-indent-level LaTeX-indent-level
2311 "*The level of indentation produced by a \\left macro."
2312 :group 'LaTeX-indentation
2315 (defcustom LaTeX-indent-comment-start-regexp "%"
2316 "*Regexp matching comments ending the indent level count.
2317 This means, we just count the LaTeX tokens \\left, \\right, \\begin,
2318 and \\end up to the first occurence of text matching this regexp.
2319 Thus, the default \"%\" stops counting the tokens at a comment. A
2320 value of \"%[^>]\" would allow you to alter the indentation with
2321 comments, e.g. with comment `%> \\begin'.
2322 Lines which start with `%' are not considered at all, regardless if this
2324 :group 'LaTeX-indentation
2327 (defvar docTeX-indent-inner-fixed
2328 `((,(concat (regexp-quote TeX-esc)
2329 "\\(begin\\|end\\)[ \t]*{macrocode\\*?}") 4 t)
2330 (,(concat (regexp-quote TeX-esc)
2331 "\\(begin\\|end\\)[ \t]*{\\(macro\\|environment\\)\\*?}") 0 nil))
2332 "List of items which should have a fixed inner indentation.
2333 The items consist of three parts. The first is a regular
2334 expression which should match the respective string. The second
2335 is the amount of spaces to be used for indentation. The third
2336 toggles if comment padding is relevant or not. If t padding is
2337 part of the amount given, if nil the amount of spaces will be
2338 inserted after potential padding.")
2340 (defun LaTeX-indent-line ()
2341 "Indent the line containing point, as LaTeX source.
2342 Add `LaTeX-indent-level' indentation in each \\begin{ - \\end{ block.
2343 Lines starting with an item is given an extra indentation of
2344 `LaTeX-item-indent'."
2346 (let* ((case-fold-search nil)
2347 ;; Compute a fill prefix. Whitespace after the comment
2348 ;; characters will be disregarded and replaced by
2349 ;; `comment-padding'.
2351 (and (TeX-in-commented-line)
2355 (concat "\\([ \t]*" TeX-comment-start-regexp "+\\)+"))
2356 (concat (match-string 0) (TeX-comment-padding-string)))))
2357 (overlays (when (featurep 'xemacs)
2358 ;; Isn't that fun? In Emacs an `(overlays-at
2359 ;; (line-beginning-position))' would do the
2360 ;; trick. How boring.
2362 nil (line-beginning-position) (line-beginning-position)
2363 'all-extents-closed-open 'overlay)))
2365 ;; XEmacs' `indent-to' function (at least in version 21.4.15) has
2366 ;; a bug which leads to the insertion of whitespace in front of an
2367 ;; invisible overlay. So during indentation we temporarily remove
2368 ;; the 'invisible property.
2369 (dolist (ol overlays)
2370 (when (extent-property ol 'invisible)
2371 (add-to-list 'ol-specs (list ol (extent-property ol 'invisible)))
2372 (set-extent-property ol 'invisible nil)))
2374 (cond ((and fill-prefix
2375 (TeX-in-line-comment)
2376 (eq major-mode 'doctex-mode))
2377 ;; If point is in a line comment in `doctex-mode' we only
2378 ;; consider the inner indentation.
2379 (let ((inner-indent (LaTeX-indent-calculate 'inner)))
2380 (when (/= (LaTeX-current-indentation 'inner) inner-indent)
2381 (LaTeX-indent-inner-do inner-indent))))
2383 LaTeX-syntactic-comments)
2384 ;; In any other case of a comment we have to consider
2385 ;; outer and inner indentation if we do syntax-aware
2387 (let ((inner-indent (LaTeX-indent-calculate 'inner))
2388 (outer-indent (LaTeX-indent-calculate 'outer)))
2389 (when (/= (LaTeX-current-indentation 'inner) inner-indent)
2390 (LaTeX-indent-inner-do inner-indent))
2391 (when (/= (LaTeX-current-indentation 'outer) outer-indent)
2392 (LaTeX-indent-outer-do outer-indent))))
2394 ;; The default is to adapt whitespace before any
2395 ;; non-whitespace character, i.e. to do outer
2397 (let ((outer-indent (LaTeX-indent-calculate 'outer)))
2398 (when (/= (LaTeX-current-indentation 'outer) outer-indent)
2399 (LaTeX-indent-outer-do outer-indent))))))
2400 ;; Make the overlays invisible again.
2401 (dolist (ol-spec ol-specs)
2402 (set-extent-property (car ol-spec) 'invisible (cadr ol-spec)))
2403 (when (< (current-column) (save-excursion
2404 (LaTeX-back-to-indentation) (current-column)))
2405 (LaTeX-back-to-indentation))))
2407 (defun LaTeX-indent-inner-do (inner-indent)
2408 ;; Small helper function for `LaTeX-indent-line' to perform
2409 ;; indentation after a comment character. It requires that
2410 ;; `LaTeX-indent-line' already set the appropriate variables and
2411 ;; should not be used outside of `LaTeX-indent-line'.
2412 (move-to-left-margin)
2413 (TeX-re-search-forward-unescaped
2414 (concat "\\(" TeX-comment-start-regexp "+[ \t]*\\)+") (line-end-position) t)
2415 (delete-region (line-beginning-position) (point))
2416 (insert fill-prefix)
2417 (indent-to (+ inner-indent (length fill-prefix))))
2419 (defun LaTeX-indent-outer-do (outer-indent)
2420 ;; Small helper function for `LaTeX-indent-line' to perform
2421 ;; indentation of normal lines or before a comment character in a
2422 ;; commented line. It requires that `LaTeX-indent-line' already set
2423 ;; the appropriate variables and should not be used outside of
2424 ;; `LaTeX-indent-line'.
2425 (back-to-indentation)
2426 (delete-region (line-beginning-position) (point))
2427 (indent-to outer-indent))
2429 (defun LaTeX-indent-calculate (&optional force-type)
2430 "Return the indentation of a line of LaTeX source.
2431 FORCE-TYPE can be used to force the calculation of an inner or
2432 outer indentation in case of a commented line. The symbols
2433 'inner and 'outer are recognized."
2435 (LaTeX-back-to-indentation force-type)
2437 (list-length (safe-length docTeX-indent-inner-fixed))
2440 (cond ((save-excursion (beginning-of-line) (bobp)) 0)
2441 ((and (eq major-mode 'doctex-mode)
2443 (TeX-in-line-comment)
2445 (while (and (< i list-length)
2447 (setq entry (nth i docTeX-indent-inner-fixed))
2448 (when (looking-at (nth 0 entry))
2453 (- (nth 1 entry) (if (integerp comment-padding)
2455 (length comment-padding)))
2457 ((looking-at (concat (regexp-quote TeX-esc)
2458 "\\(begin\\|end\\){\\("
2459 LaTeX-verbatim-regexp
2461 ;; \end{verbatim} must be flush left, otherwise an unwanted
2462 ;; empty line appears in LaTeX's output.
2464 ((and LaTeX-indent-environment-check
2465 ;; Special environments.
2466 (let ((entry (assoc (or LaTeX-current-environment
2467 (LaTeX-current-environment))
2468 LaTeX-indent-environment-list)))
2471 (funcall (nth 1 entry))))))
2472 ((looking-at (concat (regexp-quote TeX-esc)
2476 ;; Backindent at \end.
2477 (- (LaTeX-indent-calculate-last force-type) LaTeX-indent-level))
2478 ((looking-at (concat (regexp-quote TeX-esc) "right\\b"))
2479 ;; Backindent at \right.
2480 (- (LaTeX-indent-calculate-last force-type)
2481 LaTeX-left-right-indent-level))
2482 ((looking-at (concat (regexp-quote TeX-esc)
2487 (+ (LaTeX-indent-calculate-last force-type) LaTeX-item-indent))
2489 ;; End brace in the start of the line.
2490 (- (LaTeX-indent-calculate-last force-type)
2491 TeX-brace-indent-level))
2492 (t (LaTeX-indent-calculate-last force-type))))))
2494 (defun LaTeX-indent-level-count ()
2495 "Count indentation change caused by all \\left, \\right, \\begin, and
2496 \\end commands in the current line."
2500 (narrow-to-region (point)
2503 (concat "[^" TeX-esc "]"
2504 "\\(" LaTeX-indent-comment-start-regexp
2508 (while (search-forward TeX-esc nil t)
2510 ((looking-at "left\\b")
2511 (setq count (+ count LaTeX-left-right-indent-level)))
2512 ((looking-at "right\\b")
2513 (setq count (- count LaTeX-left-right-indent-level)))
2514 ((looking-at LaTeX-begin-regexp)
2515 (setq count (+ count LaTeX-indent-level)))
2516 ((looking-at LaTeX-end-regexp)
2517 (setq count (- count LaTeX-indent-level)))
2518 ((looking-at (regexp-quote TeX-esc))
2522 (defun LaTeX-indent-calculate-last (&optional force-type)
2523 "Return the correct indentation of a normal line of text.
2524 The point is supposed to be at the beginning of the current line.
2525 FORCE-TYPE can be used to force the calculation of an inner or
2526 outer indentation in case of a commented line. The symbols
2527 'inner and 'outer are recognized."
2528 (let (line-comment-current-flag
2529 line-comment-last-flag
2530 comment-current-flag
2533 (setq line-comment-current-flag (TeX-in-line-comment)
2534 comment-current-flag (TeX-in-commented-line))
2535 (if comment-current-flag
2536 (skip-chars-backward "%\n\t ")
2537 (skip-chars-backward "\n\t "))
2539 ;; If we are called in a non-comment line, skip over comment
2540 ;; lines. The computation of indentation should in this case
2541 ;; rather take the last non-comment line into account.
2542 ;; Otherwise there might arise problems with e.g. multi-line
2543 ;; code comments. This behavior is not enabled in docTeX mode
2544 ;; where large amounts of line comments may have to be skipped
2545 ;; and indentation should not be influenced by unrelated code in
2546 ;; other macrocode environments.
2547 (while (and (not (eq major-mode 'doctex-mode))
2548 (not comment-current-flag)
2549 (TeX-in-commented-line)
2551 (skip-chars-backward "\n\t ")
2552 (beginning-of-line))
2553 (setq line-comment-last-flag (TeX-in-line-comment)
2554 comment-last-flag (TeX-in-commented-line))
2555 (LaTeX-back-to-indentation force-type)
2556 ;; Separate line comments and other stuff (normal text/code and
2557 ;; code comments). Additionally we don't want to compute inner
2558 ;; indentation when a commented and a non-commented line are
2560 (cond ((or (and (eq major-mode 'doctex-mode)
2561 (or (and line-comment-current-flag
2562 (not line-comment-last-flag))
2563 (and (not line-comment-current-flag)
2564 line-comment-last-flag)))
2566 (eq force-type 'inner)
2567 (or (and comment-current-flag
2568 (not comment-last-flag))
2569 (and (not comment-current-flag)
2570 comment-last-flag))))
2572 ((looking-at (concat (regexp-quote TeX-esc)
2574 LaTeX-document-regexp
2576 ;; I dislike having all of the document indented...
2577 (+ (LaTeX-current-indentation force-type)
2578 ;; Some people have opening braces at the end of the
2579 ;; line, e.g. in case of `\begin{letter}{%'.
2580 (TeX-brace-count-line)))
2581 ((and (eq major-mode 'doctex-mode)
2582 (looking-at (concat (regexp-quote TeX-esc)
2583 "end[ \t]*{macrocode\\*?}"))
2585 (TeX-in-line-comment))
2586 ;; Reset indentation to zero after a macrocode
2589 ((looking-at (concat (regexp-quote TeX-esc)
2591 LaTeX-verbatim-regexp
2594 ((looking-at (concat (regexp-quote TeX-esc)
2596 LaTeX-verbatim-regexp
2598 ;; If I see an \end{verbatim} in the previous line I skip
2599 ;; back to the preceding \begin{verbatim}.
2601 (if (re-search-backward (concat (regexp-quote TeX-esc)
2603 LaTeX-verbatim-regexp
2605 (LaTeX-indent-calculate-last force-type)
2607 (t (+ (LaTeX-current-indentation force-type)
2608 (if (not (and force-type
2609 (eq force-type 'outer)
2610 (TeX-in-commented-line)))
2611 (+ (LaTeX-indent-level-count)
2612 (TeX-brace-count-line))
2614 (cond ((looking-at (concat (regexp-quote TeX-esc)
2620 (concat (regexp-quote TeX-esc) "right\\b"))
2621 LaTeX-left-right-indent-level)
2622 ((looking-at (concat (regexp-quote TeX-esc)
2626 (- LaTeX-item-indent))
2628 TeX-brace-indent-level)
2631 (defun LaTeX-current-indentation (&optional force-type)
2632 "Return the indentation of a line.
2633 FORCE-TYPE can be used to force the calculation of an inner or
2634 outer indentation in case of a commented line. The symbols
2635 'inner and 'outer are recognized."
2636 (if (and fill-prefix
2638 (eq force-type 'inner))
2639 (and (not force-type)
2641 ;; If `LaTeX-syntactic-comments' is not enabled,
2642 ;; do conventional indentation
2643 LaTeX-syntactic-comments
2644 ;; Line comments in `doctex-mode' are always
2645 ;; indented syntax-aware so we need their inner
2647 (and (TeX-in-line-comment)
2648 (eq major-mode 'doctex-mode))))))
2649 ;; INNER indentation
2652 (looking-at (concat "\\(?:[ \t]*" TeX-comment-start-regexp "+\\)+"
2654 (- (length (match-string 1)) (length (TeX-comment-padding-string))))
2655 ;; OUTER indentation
2656 (current-indentation)))
2658 (defun LaTeX-back-to-indentation (&optional force-type)
2659 "Move point to the first non-whitespace character on this line.
2660 If it is commented and comments are formatted syntax-aware move
2661 point to the first non-whitespace character after the comment
2662 character(s). The optional argument FORCE-TYPE can be used to
2663 force point being moved to the inner or outer indentation in case
2664 of a commented line. The symbols 'inner and 'outer are
2666 (if (or (and force-type
2667 (eq force-type 'inner))
2668 (and (not force-type)
2669 (or (and (TeX-in-line-comment)
2670 (eq major-mode 'doctex-mode))
2671 (and (TeX-in-commented-line)
2672 LaTeX-syntactic-comments))))
2675 ;; Should this be anchored at the start of the line?
2676 (TeX-re-search-forward-unescaped
2677 (concat "\\(?:" TeX-comment-start-regexp "+[ \t]*\\)+")
2678 (line-end-position) t))
2679 (back-to-indentation)))
2684 (defcustom LaTeX-fill-break-at-separators nil
2685 "List of separators before or after which respectively a line
2686 break will be inserted if they do not fit into one line."
2688 :type '(set :tag "Contents"
2689 (const :tag "Opening Brace" \{)
2690 (const :tag "Closing Brace" \})
2691 (const :tag "Opening Bracket" \[)
2692 (const :tag "Opening Inline Math Switches" \\\()
2693 (const :tag "Closing Inline Math Switches" \\\))
2694 (const :tag "Opening Display Math Switch" \\\[)
2695 (const :tag "Closing Display Math Switch" \\\])))
2697 (defcustom LaTeX-fill-break-before-code-comments t
2698 "If non-nil, a line with some code followed by a comment will
2699 be broken before the last non-comment word in case the comment
2700 does not fit into the line."
2704 (defvar LaTeX-nospace-between-char-regexp
2705 (if (featurep 'xemacs)
2706 (if (and (boundp 'word-across-newline) word-across-newline)
2708 ;; NOTE: Ensure not to have a value of nil for such a rare case that
2709 ;; somebody removes the mule test in `LaTeX-fill-delete-newlines' so that
2710 ;; it could match only "\n" and this could lead to problem. XEmacs does
2711 ;; not have a category `\c|' and `\ct' means `Chinese Taiwan' in XEmacs.
2712 "\\(\\cj\\|\\cc\\|\\ct\\)")
2714 "Regexp matching a character where no interword space is necessary.
2715 Words formed by such characters can be broken across newlines.")
2717 (defvar LaTeX-fill-newline-hook nil
2718 "Hook run after `LaTeX-fill-newline' inserted and indented a new line.")
2720 (defun LaTeX-fill-region-as-paragraph (from to &optional justify-flag)
2721 "Fill region as one paragraph.
2722 Break lines to fit `fill-column', but leave all lines ending with
2723 \\\\ \(plus its optional argument) alone. Lines with code
2724 comments and lines ending with `\par' are included in filling but
2725 act as boundaries. Prefix arg means justify too. From program,
2726 pass args FROM, TO and JUSTIFY-FLAG."
2727 (interactive "*r\nP")
2728 (let ((end-marker (save-excursion (goto-char to) (point-marker))))
2729 (if (or (assoc (LaTeX-current-environment) LaTeX-indent-environment-list)
2730 ;; This could be generalized, if there are more cases where
2731 ;; a special string at the start of a region to fill should
2733 (progn (save-excursion (goto-char from)
2734 (looking-at (concat TeX-comment-start-regexp
2736 "Local Variables:")))))
2737 ;; Filling disabled, only do indentation.
2738 (indent-region from to nil)
2741 (while (< (point) end-marker)
2742 (if (re-search-forward
2745 "[^\r\n%\\]\\([ \t]\\|\\\\\\\\\\)*"
2746 TeX-comment-start-regexp
2748 ;; Lines ending with `\par'.
2749 "\\(\\=\\|[^" TeX-esc "\n]\\)\\("
2750 (regexp-quote (concat TeX-esc TeX-esc))
2752 (regexp-quote TeX-esc) "par[ \t]*"
2753 "\\({[ \t]*}\\)?[ \t]*$"
2755 ;; Lines ending with `\\'.
2756 (regexp-quote TeX-esc)
2757 (regexp-quote TeX-esc)
2759 "\\(\\s-*\\[[^]]*\\]\\)?"
2763 (goto-char (line-end-position))
2764 (delete-horizontal-space)
2765 ;; I doubt very much if we want justify -
2766 ;; this is a line with \\
2767 ;; if you think otherwise - uncomment the next line
2768 ;; (and justify-flag (justify-current-line))
2770 ;; keep our position in a buffer
2772 ;; Code comments and lines ending with `\par' are
2773 ;; included in filling. Lines ending with `\\' are
2775 (if (match-string 1)
2776 (LaTeX-fill-region-as-para-do from (point) justify-flag)
2777 (LaTeX-fill-region-as-para-do
2778 from (line-beginning-position 0) justify-flag)
2779 ;; At least indent the line ending with `\\'.
2780 (indent-according-to-mode)))
2781 (setq from (point)))
2782 ;; ELSE part follows - loop termination relies on a fact
2783 ;; that (LaTeX-fill-region-as-para-do) moves point past
2784 ;; the filled region
2785 (LaTeX-fill-region-as-para-do from end-marker justify-flag)))))))
2787 ;; The content of `LaTeX-fill-region-as-para-do' was copied from the
2788 ;; function `fill-region-as-paragraph' in `fill.el' (CVS Emacs,
2789 ;; January 2004) and adapted to the needs of AUCTeX.
2791 (defun LaTeX-fill-region-as-para-do (from to &optional justify
2792 nosqueeze squeeze-after)
2793 "Fill the region defined by FROM and TO as one paragraph.
2794 It removes any paragraph breaks in the region and extra newlines at the end,
2795 indents and fills lines between the margins given by the
2796 `current-left-margin' and `current-fill-column' functions.
2797 \(In most cases, the variable `fill-column' controls the width.)
2798 It leaves point at the beginning of the line following the paragraph.
2800 Normally performs justification according to the `current-justification'
2801 function, but with a prefix arg, does full justification instead.
2803 From a program, optional third arg JUSTIFY can specify any type of
2804 justification. Fourth arg NOSQUEEZE non-nil means not to make spaces
2805 between words canonical before filling. Fifth arg SQUEEZE-AFTER, if non-nil,
2806 means don't canonicalize spaces before that position.
2808 Return the `fill-prefix' used for filling.
2810 If `sentence-end-double-space' is non-nil, then period followed by one
2811 space does not end a sentence, so don't break a line there."
2813 (barf-if-buffer-read-only)
2814 (list (region-beginning) (region-end)
2815 (if current-prefix-arg 'full))))
2816 (unless (memq justify '(t nil none full center left right))
2817 (setq justify 'full))
2819 ;; Make sure "to" is the endpoint.
2820 (goto-char (min from to))
2821 (setq to (max from to))
2822 ;; Ignore blank lines at beginning of region.
2823 (skip-chars-forward " \t\n")
2825 (let ((from-plus-indent (point))
2831 ;; Delete all but one soft newline at end of region.
2832 ;; And leave TO before that one.
2834 (while (and (> (point) from) (eq ?\n (char-after (1- (point)))))
2836 (not (and use-hard-newlines
2837 (get-text-property (1- (point)) 'hard))))
2838 (delete-backward-char 1)
2841 (setq to (copy-marker (point) t))
2842 (goto-char from-plus-indent))
2844 (if (not (> to (point)))
2845 nil ;; There is no paragraph, only whitespace: exit now.
2847 (or justify (setq justify (current-justification)))
2849 ;; Don't let Adaptive Fill mode alter the fill prefix permanently.
2850 (let ((fill-prefix fill-prefix))
2851 ;; Figure out how this paragraph is indented, if desired.
2852 (when (and adaptive-fill-mode
2853 (or (null fill-prefix) (string= fill-prefix "")))
2854 (setq fill-prefix (fill-context-prefix from to))
2855 ;; Ignore a white-space only fill-prefix
2856 ;; if we indent-according-to-mode.
2857 (when (and fill-prefix fill-indent-according-to-mode
2858 (string-match "\\`[ \t]*\\'" fill-prefix))
2859 (setq fill-prefix nil)))
2864 (if (not justify) ; filling disabled: just check indentation
2867 (while (< (point) to)
2868 (if (and (not (eolp))
2869 (< (LaTeX-current-indentation) (current-left-margin)))
2870 (fill-indent-to-left-margin))
2873 (when use-hard-newlines
2874 (remove-text-properties from to '(hard nil)))
2875 ;; Make sure first line is indented (at least) to left margin...
2876 (indent-according-to-mode)
2877 ;; COMPATIBILITY for Emacs <= 21.1
2878 (if (fboundp 'fill-delete-prefix)
2879 ;; Delete the fill-prefix from every line.
2880 (fill-delete-prefix from to fill-prefix)
2881 ;; Delete the comment prefix and any whitespace from every
2882 ;; line of the region in concern except the first. (The
2883 ;; implementation is heuristic to a certain degree.)
2887 (when (< (point) to)
2888 (while (re-search-forward (concat "^[ \t]+\\|^[ \t]*"
2889 TeX-comment-start-regexp
2891 (delete-region (match-beginning 0) (match-end 0))))))
2895 ;; FROM, and point, are now before the text to fill,
2896 ;; but after any fill prefix on the first line.
2898 (LaTeX-fill-delete-newlines from to justify nosqueeze squeeze-after)
2900 ;; This is the actual FILLING LOOP.
2903 (code-comment-start (save-excursion
2904 (LaTeX-back-to-indentation)
2905 (TeX-search-forward-comment-start
2906 (line-end-position))))
2907 (end-marker (save-excursion
2908 (goto-char (or code-comment-start to))
2910 (LaTeX-current-environment (LaTeX-current-environment)))
2911 ;; Fill until point is greater than the end point. If there
2912 ;; is a code comment, use the code comment's start as a
2914 (while (and (< (point) (marker-position end-marker))
2915 (or (not code-comment-start)
2916 (and code-comment-start
2917 (> (- (marker-position end-marker)
2918 (line-beginning-position))
2920 (setq linebeg (point))
2921 (move-to-column (current-fill-column))
2922 (if (when (< (point) (marker-position end-marker))
2923 ;; Find the position where we'll break the line.
2924 (forward-char 1) ; Use an immediately following
2926 (LaTeX-fill-move-to-break-point linebeg)
2928 ;; Check again to see if we got to the end of
2930 (skip-chars-forward " \t")
2931 (< (point) (marker-position end-marker)))
2932 ;; Found a place to cut.
2934 (LaTeX-fill-newline)
2936 ;; Justify the line just ended, if desired.
2939 (justify-current-line justify nil t))))
2941 (goto-char end-marker)
2942 ;; Justify this last line, if desired.
2943 (if justify (justify-current-line justify t t))))
2945 ;; Fill a code comment if necessary. (Enable this code if
2946 ;; you want the comment part in lines with code comments to
2947 ;; be filled. Originally it was disabled because the
2948 ;; indentation code indented the lines following the line
2949 ;; with the code comment to the column of the comment
2950 ;; starters. That means, it would have looked like this:
2951 ;; | code code code % comment
2954 ;; This now (2005-07-29) is not the case anymore. But as
2955 ;; filling code comments like this would split a single
2956 ;; paragraph into two separate ones, we still leave it
2957 ;; disabled. I leave the code here in case it is useful for
2959 ;; (when (and code-comment-start
2960 ;; (> (- (line-end-position) (line-beginning-position))
2962 ;; (LaTeX-fill-code-comment justify))
2964 ;; The following is an alternative strategy to minimize the
2965 ;; occurence of overfull lines with code comments. A line
2966 ;; will be broken before the last non-comment word if the
2967 ;; code comment does not fit into the line.
2968 (when (and LaTeX-fill-break-before-code-comments
2970 (> (- (line-end-position) (line-beginning-position))
2973 (goto-char end-marker)
2974 (while (not (looking-at TeX-comment-start-regexp)) (forward-char))
2975 (skip-chars-backward " \t")
2976 (skip-chars-backward "^ \t\n")
2978 ;; Comment starters and whitespace.
2979 (TeX-looking-at-backward
2980 (concat "^\\([ \t]*" TeX-comment-start-regexp "+\\)*"
2982 (line-beginning-position)))
2983 (LaTeX-fill-newline)))))
2984 ;; Leave point after final newline.
2986 (unless (eobp) (forward-char 1))
2987 ;; Return the fill-prefix we used
2990 ;; Following lines are copied from `fill.el' (CVS Emacs, March 2005).
2991 ;; The `fill-space' property carries the string with which a newline should be
2992 ;; replaced when unbreaking a line (in fill-delete-newlines). It is added to
2993 ;; newline characters by fill-newline when the default behavior of
2994 ;; fill-delete-newlines is not what we want.
2995 (unless (featurep 'xemacs)
2996 ;; COMPATIBILITY for Emacs < 22.1
2997 (add-to-list 'text-property-default-nonsticky '(fill-space . t)))
2999 (defun LaTeX-fill-delete-newlines (from to justify nosqueeze squeeze-after)
3000 ;; COMPATIBILITY for Emacs < 22.1 and XEmacs
3001 (if (fboundp 'fill-delete-newlines)
3002 (fill-delete-newlines from to justify nosqueeze squeeze-after)
3003 (if (featurep 'xemacs)
3004 (when (featurep 'mule)
3006 (let ((unwished-newline (concat LaTeX-nospace-between-char-regexp "\n"
3007 LaTeX-nospace-between-char-regexp)))
3008 (while (re-search-forward unwished-newline to t)
3009 (skip-chars-backward "^\n")
3011 ;; This else-sentence was copied from the function `fill-delete-newlines'
3012 ;; in `fill.el' (CVS Emacs, 2005-02-17) and adapted accordingly.
3013 (while (search-forward "\n" to t)
3014 (if (get-text-property (match-beginning 0) 'fill-space)
3015 (replace-match (get-text-property (match-beginning 0) 'fill-space))
3016 (let ((prev (char-before (match-beginning 0)))
3017 (next (following-char)))
3018 (when (or (aref (char-category-set next) ?|)
3019 (aref (char-category-set prev) ?|))
3020 (delete-char -1))))))
3022 ;; Make sure sentences ending at end of line get an extra space.
3023 (if (or (not (boundp 'sentence-end-double-space))
3024 sentence-end-double-space)
3027 (while (re-search-forward "[.?!][]})\"']*$" to t)
3029 ;; Then change all newlines to spaces.
3030 (let ((point-max (progn
3032 (skip-chars-backward "\n")
3034 (subst-char-in-region from point-max ?\n ?\ ))
3036 (skip-chars-forward " \t")
3037 ;; Remove extra spaces between words.
3038 (unless (and nosqueeze (not (eq justify 'full)))
3039 (canonically-space-region (or squeeze-after (point)) to)
3040 ;; Remove trailing whitespace.
3041 (goto-char (line-end-position))
3042 (delete-char (- (skip-chars-backward " \t"))))))
3044 (defun LaTeX-fill-move-to-break-point (linebeg)
3045 "Move to the position where the line should be broken."
3046 ;; COMPATIBILITY for Emacs < 22.1 and XEmacs
3047 (if (fboundp 'fill-move-to-break-point)
3048 (fill-move-to-break-point linebeg)
3049 (if (featurep 'mule)
3050 (if (TeX-looking-at-backward
3051 (concat LaTeX-nospace-between-char-regexp ".?") 2)
3052 ;; Cancel `forward-char' which is called just before
3053 ;; `LaTeX-fill-move-to-break-point' if the char before point matches
3054 ;; `LaTeX-nospace-between-char-regexp'.
3056 (when (re-search-backward
3057 (concat " \\|\n\\|" LaTeX-nospace-between-char-regexp)
3060 (skip-chars-backward "^ \n"))
3061 ;; Prevent infinite loops: If we cannot find a place to break
3062 ;; while searching backward, search forward again.
3063 (when (save-excursion
3064 (skip-chars-backward " \t%")
3066 (skip-chars-forward "^ \n" (point-max)))
3067 ;; This code was copied from the function `fill-move-to-break-point'
3068 ;; in `fill.el' (CVS Emacs, 2005-02-22) and adapted accordingly.
3069 (when (and (< linebeg (point))
3070 ;; If we are going to break the line after or
3071 ;; before a non-ascii character, we may have to
3072 ;; run a special function for the charset of the
3073 ;; character to find the correct break point.
3074 (boundp 'enable-multibyte-characters)
3075 enable-multibyte-characters
3076 (fboundp 'charset-after) ; Non-MULE XEmacsen don't have this.
3077 (not (and (eq (charset-after (1- (point))) 'ascii)
3078 (eq (charset-after (point)) 'ascii))))
3079 ;; Make sure we take SOMETHING after the fill prefix if any.
3080 (if (fboundp 'fill-find-break-point)
3081 (fill-find-break-point linebeg)
3082 (when (fboundp 'kinsoku-process) ;XEmacs
3083 (kinsoku-process)))))
3084 ;; Prevent line break between 2-byte char and 1-byte char.
3085 (when (and (featurep 'mule)
3086 enable-multibyte-characters
3087 (or (and (not (looking-at LaTeX-nospace-between-char-regexp))
3088 (TeX-looking-at-backward
3089 LaTeX-nospace-between-char-regexp 1))
3090 (and (not (TeX-looking-at-backward
3091 LaTeX-nospace-between-char-regexp 1))
3092 (looking-at LaTeX-nospace-between-char-regexp)))
3094 (concat LaTeX-nospace-between-char-regexp
3095 LaTeX-nospace-between-char-regexp
3096 LaTeX-nospace-between-char-regexp
3098 ".\\ca\\s +\\ca") linebeg t))
3099 (if (looking-at "..\\c>")
3102 ;; Cater for Japanese Macro
3103 (when (and (boundp 'japanese-TeX-mode) japanese-TeX-mode
3104 (aref (char-category-set (char-after)) ?j)
3105 (TeX-looking-at-backward (concat (regexp-quote TeX-esc) TeX-token-char "*")
3106 (1- (- (point) linebeg)))
3107 (not (TeX-escaped-p (match-beginning 0))))
3108 (goto-char (match-beginning 0)))
3109 ;; Cater for \verb|...| (and similar) contructs which should not be
3110 ;; broken. (FIXME: Make it work with shortvrb.sty (also loaded by
3111 ;; doc.sty) where |...| is allowed. Arbitrary delimiters may be
3112 ;; chosen with \MakeShortVerb{<char>}.) This could probably be
3113 ;; handled with `fill-nobreak-predicate', but this is not available
3115 (let ((final-breakpoint (point))
3116 (verb-macros (regexp-opt (append (LaTeX-verbatim-macros-with-delims)
3117 (LaTeX-verbatim-macros-with-braces)))))
3119 ;; Look for the start of a verbatim macro in the current line.
3120 (when (re-search-backward (concat (regexp-quote TeX-esc)
3121 "\\(?:" verb-macros "\\)\\([^a-z@*]\\)")
3122 (line-beginning-position) t)
3123 ;; Determine start and end of verbatim macro.
3125 (end (if (not (string-match "[ [{]" (match-string 1)))
3126 (cdr (LaTeX-verbatim-macro-boundaries))
3127 (TeX-find-macro-end))))
3128 ;; Determine if macro end is behind fill column.
3130 (> (- end (line-beginning-position))
3131 (current-fill-column))
3132 (> end final-breakpoint))
3133 ;; Search backwards for place to break before the macro.
3135 (skip-chars-backward "^ \n")
3136 ;; Determine if point ended up at the beginning of the line.
3137 (when (save-excursion (skip-chars-backward " \t%") (bolp))
3138 ;; Search forward for a place to break after the macro.
3140 (skip-chars-forward "^ \n" (point-max)))
3141 (setq final-breakpoint (point))))))
3142 (goto-char final-breakpoint))
3143 (when LaTeX-fill-break-at-separators
3144 (let ((orig-breakpoint (point))
3145 (final-breakpoint (point))
3150 (LaTeX-back-to-indentation)
3151 (setq start-point (point))
3152 ;; Find occurences of [, $, {, }, \(, \), \[, \] or $$.
3153 (while (and (= final-breakpoint orig-breakpoint)
3154 (TeX-re-search-forward-unescaped
3155 (concat "[[{}]\\|\\$\\$?\\|"
3156 (regexp-quote TeX-esc) "[][()]")
3158 (let ((match-string (match-string 0)))
3160 ;; [ (opening bracket) (The closing bracket should
3161 ;; already be handled implicitely by the code for the
3164 (and (memq '\[ LaTeX-fill-break-at-separators)
3165 (string= match-string "[")
3166 (TeX-re-search-forward-unescaped (concat "\\][ \t]*{")
3167 (line-end-position) t)
3168 (> (- (or (TeX-find-closing-brace)
3169 (line-end-position))
3170 (line-beginning-position))
3173 (skip-chars-backward "^ \n")
3174 (when (> (point) start-point)
3175 (setq final-breakpoint (point)))))
3176 ;; { (opening brace)
3178 (and (memq '\{ LaTeX-fill-break-at-separators)
3179 (string= match-string "{")
3180 (> (- (save-excursion
3181 ;; `TeX-find-closing-brace' is not enough
3182 ;; if there is no breakpoint in form of
3183 ;; whitespace after the brace.
3184 (goto-char (or (TeX-find-closing-brace)
3185 (line-end-position)))
3186 (skip-chars-forward "^ \t\n")
3188 (line-beginning-position))
3191 (skip-chars-backward "^ \n")
3192 ;; The following is a primitive and error-prone method
3193 ;; to cope with point probably being inside square
3194 ;; brackets. A better way would be to use functions
3195 ;; to determine if point is inside an optional
3196 ;; argument and to jump to the start and end brackets.
3197 (when (save-excursion
3198 (TeX-re-search-forward-unescaped
3199 (concat "\\][ \t]*{") orig-breakpoint t))
3200 (TeX-search-backward-unescaped "["
3201 (line-beginning-position) t)
3202 (skip-chars-backward "^ \n"))
3203 (when (> (point) start-point)
3204 (setq final-breakpoint (point)))))
3205 ;; } (closing brace)
3207 (and (memq '\} LaTeX-fill-break-at-separators)
3208 (string= match-string "}")
3211 (not (TeX-find-opening-brace
3212 nil (line-beginning-position))))))
3214 (skip-chars-forward "^ \n")
3215 (when (> (point) start-point)
3216 (setq final-breakpoint (point)))))
3217 ;; $ or \( or \[ or $$ (opening math)
3219 (and (or (and (memq '\\\( LaTeX-fill-break-at-separators)
3220 (or (and (string= match-string "$")
3222 (string= match-string "\\(")))
3223 (and (memq '\\\[ LaTeX-fill-break-at-separators)
3224 (or (string= match-string "\\[")
3225 (and (string= match-string "$$")
3227 (> (- (save-excursion
3228 (TeX-search-forward-unescaped
3229 (cond ((string= match-string "\\(")
3230 (concat TeX-esc ")"))
3231 ((string= match-string "$") "$")
3232 ((string= match-string "$$") "$$")
3233 (t (concat TeX-esc "]")))
3235 (skip-chars-forward "^ \n")
3237 (line-beginning-position))
3240 (skip-chars-backward "^ \n")
3241 (when (> (point) start-point)
3242 (setq final-breakpoint (point)))))
3243 ;; $ or \) or \] or $$ (closing math)
3245 (and (or (and (memq '\\\) LaTeX-fill-break-at-separators)
3246 (or (and (string= match-string "$")
3248 (string= match-string "\\)")))
3249 (and (memq '\\\] LaTeX-fill-break-at-separators)
3250 (or (string= match-string "\\]")
3251 (and (string= match-string "$$")
3252 (not (texmathp))))))
3253 (if (member match-string '("$" "$$"))
3255 (skip-chars-backward "$")
3256 (not (TeX-search-backward-unescaped
3257 match-string (line-beginning-position) t)))
3258 (texmathp-match-switch (line-beginning-position)))))
3260 (skip-chars-forward "^ \n")
3261 (when (> (point) start-point)
3262 (setq final-breakpoint (point)))))))))
3263 (goto-char final-breakpoint))))
3265 ;; The content of `LaTeX-fill-newline' was copied from the function
3266 ;; `fill-newline' in `fill.el' (CVS Emacs, January 2004) and adapted
3267 ;; to the needs of AUCTeX.
3268 (defun LaTeX-fill-newline ()
3269 "Replace whitespace here with one newline and indent the line."
3270 (skip-chars-backward " \t")
3272 ;; COMPATIBILITY for XEmacs
3273 (unless (featurep 'xemacs)
3274 ;; Give newline the properties of the space(s) it replaces
3275 (set-text-properties (1- (point)) (point)
3276 (text-properties-at (point)))
3277 (and (looking-at "\\( [ \t]*\\)\\(\\c|\\)?")
3278 (or (aref (char-category-set (or (char-before (1- (point))) ?\000)) ?|)
3280 ;; When refilling later on, this newline would normally not
3281 ;; be replaced by a space, so we need to mark it specially to
3282 ;; re-install the space when we unfill.
3283 (put-text-property (1- (point)) (point) 'fill-space (match-string 1)))
3284 ;; COMPATIBILITY for Emacs <= 21.3
3285 (when (boundp 'fill-nobreak-invisible)
3286 ;; If we don't want breaks in invisible text, don't insert
3287 ;; an invisible newline.
3288 (if fill-nobreak-invisible
3289 (remove-text-properties (1- (point)) (point)
3291 ;; Insert the fill prefix.
3292 (and fill-prefix (not (equal fill-prefix ""))
3293 ;; Markers that were after the whitespace are now at point: insert
3294 ;; before them so they don't get stuck before the prefix.
3295 (insert-before-markers-and-inherit fill-prefix))
3296 (indent-according-to-mode)
3297 (run-hooks 'LaTeX-fill-newline-hook))
3299 (defun LaTeX-fill-paragraph (&optional justify)
3300 "Like `fill-paragraph', but handle LaTeX comments.
3301 If any of the current line is a comment, fill the comment or the
3302 paragraph of it that point is in. Code comments, i.e. comments
3303 with uncommented code preceding them in the same line, will not
3304 be filled unless the cursor is placed on the line with the
3307 If LaTeX syntax is taken into consideration during filling
3308 depends on the value of `LaTeX-syntactic-comments'."
3312 (looking-at (concat TeX-comment-start-regexp "*[ \t]*$")))
3313 ;; Don't do anything if we look at an empty line and let
3314 ;; `fill-paragraph' think we successfully filled the paragraph.
3316 (let (;; Non-nil if the current line contains a comment.
3318 ;; Non-nil if the current line contains code and a comment.
3319 has-code-and-comment
3321 ;; If has-comment, the appropriate fill-prefix for the comment.
3322 comment-fill-prefix)
3324 ;; Figure out what kind of comment we are looking at.
3326 ;; A line only with potential whitespace followed by a
3330 (looking-at (concat "^[ \t]*" TeX-comment-start-regexp
3331 "\\(" TeX-comment-start-regexp "\\|[ \t]\\)*")))
3333 comment-fill-prefix (TeX-match-buffer 0)))
3334 ;; A line with some code, followed by a comment?
3335 ((and (setq code-comment-start (save-excursion
3337 (TeX-search-forward-comment-start
3338 (line-end-position))))
3339 (> (point) code-comment-start)
3340 (not (TeX-in-commented-line))
3342 (goto-char code-comment-start)
3343 ;; See if there is at least one non-whitespace character
3344 ;; before the comment starts.
3345 (re-search-backward "[^ \t\n]" (line-beginning-position) t)))
3347 has-code-and-comment t)))
3351 (has-code-and-comment
3353 (when (>= (- code-comment-start (line-beginning-position))
3355 ;; If start of code comment is beyond fill column, fill it as a
3356 ;; regular paragraph before it is filled as a code comment.
3357 (let ((end-marker (save-excursion (end-of-line) (point-marker))))
3358 (LaTeX-fill-region-as-paragraph (line-beginning-position)
3359 (line-beginning-position 2)
3361 (goto-char end-marker)
3362 (beginning-of-line)))
3363 (LaTeX-fill-code-comment justify)))
3364 ;; Syntax-aware filling:
3365 ;; * `LaTeX-syntactic-comments' enabled: Everything.
3366 ;; * `LaTeX-syntactic-comments' disabled: Uncommented code and
3367 ;; line comments in `doctex-mode'.
3368 ((or (or LaTeX-syntactic-comments
3369 (and (not LaTeX-syntactic-comments)
3371 (and (eq major-mode 'doctex-mode)
3372 (TeX-in-line-comment)))
3373 (let ((fill-prefix comment-fill-prefix))
3375 (let* ((end (progn (LaTeX-forward-paragraph)
3376 (or (bolp) (newline 1))
3377 (and (eobp) (not (bolp)) (open-line 1))
3381 (LaTeX-backward-paragraph)
3382 (while (and (looking-at
3383 (concat "$\\|[ \t]+$\\|"
3384 "[ \t]*" TeX-comment-start-regexp
3389 (LaTeX-fill-region-as-paragraph start end justify)))))
3390 ;; Non-syntax-aware filling.
3396 ;; Find the first line we should include in the region to fill.
3398 (while (and (zerop (forward-line -1))
3399 (looking-at (concat "^[ \t]*"
3400 TeX-comment-start-regexp))))
3401 ;; We may have gone too far. Go forward again.
3402 (or (looking-at (concat ".*" TeX-comment-start-regexp))
3405 ;; Find the beginning of the first line past the region to fill.
3407 (while (progn (forward-line 1)
3408 (looking-at (concat "^[ \t]*"
3409 TeX-comment-start-regexp))))
3411 ;; The definitions of `paragraph-start' and
3412 ;; `paragraph-separate' will still make
3413 ;; `forward-paragraph' and `backward-paragraph' stop at
3414 ;; the respective (La)TeX commands. If these should be
3415 ;; disregarded, the definitions would have to be changed
3416 ;; accordingly. (Lines with only `%' characters on them
3417 ;; can be paragraph boundaries.)
3418 (let* ((paragraph-start
3419 (concat paragraph-start "\\|"
3420 "\\(" TeX-comment-start-regexp "\\|[ \t]\\)*$"))
3422 (concat paragraph-separate "\\|"
3423 "\\(" TeX-comment-start-regexp "\\|[ \t]\\)*$"))
3424 (fill-prefix comment-fill-prefix)
3425 (end (progn (forward-paragraph)
3426 (or (bolp) (newline 1))
3428 (beg (progn (backward-paragraph)
3430 (fill-region-as-paragraph
3435 (if (looking-at fill-prefix)
3437 (re-search-forward comment-start-skip nil t)
3441 (defun LaTeX-fill-code-comment (&optional justify-flag)
3442 "Fill a line including code followed by a comment."
3443 (let ((beg (line-beginning-position))
3444 fill-prefix code-comment-start)
3445 (indent-according-to-mode)
3446 (when (when (setq code-comment-start (save-excursion
3448 (TeX-search-forward-comment-start
3449 (line-end-position))))
3450 (goto-char code-comment-start)
3451 (while (not (looking-at TeX-comment-start-regexp)) (forward-char))
3452 ;; See if there is at least one non-whitespace character
3453 ;; before the comment starts.
3455 (re-search-backward "[^ \t\n]" (line-beginning-position) t)))
3458 (if indent-tabs-mode
3459 (concat (make-string (/ (current-column) tab-width) ?\t)
3460 (make-string (% (current-column) tab-width) ?\ ))
3461 (make-string (current-column) ?\ ))
3463 (looking-at (concat TeX-comment-start-regexp "+[ \t]*"))
3464 (TeX-match-buffer 0))))
3465 (fill-region-as-paragraph beg (line-beginning-position 2)
3469 (if (looking-at fill-prefix)
3471 (re-search-forward comment-start-skip nil t)
3474 (defun LaTeX-fill-region (from to &optional justify what)
3475 "Fill and indent the text in region from FROM to TO as LaTeX text.
3476 Prefix arg (non-nil third arg JUSTIFY, if called from program)
3477 means justify as well. Fourth arg WHAT is a word to be displayed when
3479 (interactive "*r\nP")
3481 (let ((to (set-marker (make-marker) to))
3482 (next-par (make-marker)))
3486 (catch 'end-of-buffer
3487 (while (and (< (point) to))
3488 (message "Formatting%s ... %d%%"
3490 (/ (* 100 (- (point) from)) (- to from)))
3491 (save-excursion (LaTeX-fill-paragraph justify))
3492 (if (marker-position next-par)
3493 (goto-char (marker-position next-par))
3494 (LaTeX-forward-paragraph))
3495 (when (eobp) (throw 'end-of-buffer t))
3496 (LaTeX-forward-paragraph)
3497 (set-marker next-par (point))
3498 (LaTeX-backward-paragraph)
3499 (while (and (not (eobp))
3501 (concat "^\\($\\|[ \t]+$\\|[ \t]*"
3502 TeX-comment-start-regexp "+[ \t]*$\\)")))
3504 (set-marker to nil)))
3505 (message "Finished"))
3507 (defun LaTeX-find-matching-end ()
3508 "Move point to the \\end of the current environment.
3510 If function is called inside a comment and
3511 `LaTeX-syntactic-comments' is enabled, try to find the
3512 environment in commented regions with the same comment prefix."
3514 (let* ((regexp (concat (regexp-quote TeX-esc) "\\(begin\\|end\\)\\b"))
3516 (in-comment (TeX-in-commented-line))
3517 (comment-prefix (and in-comment (TeX-comment-prefix))))
3519 (skip-chars-backward "a-zA-Z \t{")
3522 (and (looking-at regexp)
3523 (char-equal (char-after (1+ (match-beginning 0))) ?e)
3525 (while (and (> level 0) (re-search-forward regexp nil t))
3526 (when (or (and LaTeX-syntactic-comments
3527 (eq in-comment (TeX-in-commented-line))
3528 ;; If we are in a commented line, check if the
3529 ;; prefix matches the one we started out with.
3530 (or (not in-comment)
3531 (string= comment-prefix (TeX-comment-prefix))))
3532 (and (not LaTeX-syntactic-comments)
3533 (not (TeX-in-commented-line))))
3534 (if (= (char-after (1+ (match-beginning 0))) ?b) ;;begin
3535 (setq level (1+ level))
3536 (setq level (1- level)))))
3538 (search-forward "}")
3539 (error "Can't locate end of current environment"))))
3541 (defun LaTeX-find-matching-begin ()
3542 "Move point to the \\begin of the current environment.
3544 If function is called inside a comment and
3545 `LaTeX-syntactic-comments' is enabled, try to find the
3546 environment in commented regions with the same comment prefix."
3548 (let* ((regexp (concat (regexp-quote TeX-esc) "\\(begin\\|end\\)\\b"))
3550 (in-comment (TeX-in-commented-line))
3551 (comment-prefix (and in-comment (TeX-comment-prefix))))
3552 (skip-chars-backward "a-zA-Z \t{")
3555 (and (looking-at regexp)
3556 (char-equal (char-after (1+ (match-beginning 0))) ?b)
3558 (while (and (> level 0) (re-search-backward regexp nil t))
3559 (when (or (and LaTeX-syntactic-comments
3560 (eq in-comment (TeX-in-commented-line))
3561 ;; If we are in a commented line, check if the
3562 ;; prefix matches the one we started out with.
3563 (or (not in-comment)
3564 (string= comment-prefix (TeX-comment-prefix))))
3565 (and (not LaTeX-syntactic-comments)
3566 (not (TeX-in-commented-line))))
3567 (if (= (char-after (1+ (match-beginning 0))) ?e) ;;end
3568 (setq level (1+ level))
3569 (setq level (1- level)))))
3571 (error "Can't locate beginning of current environment"))))
3573 (defun LaTeX-mark-environment (&optional count)
3574 "Set mark to end of current environment and point to the matching begin.
3575 If prefix argument COUNT is given, mark the respective number of
3576 enclosing environments. The command will not work properly if
3577 there are unbalanced begin-end pairs in comments and verbatim
3580 (setq count (if count (abs count) 1))
3581 (let ((cur (point)) beg end)
3582 ;; Only change point and mark after beginning and end were found.
3583 ;; Point should not end up in the middle of nowhere if the search fails.
3585 (dotimes (c count) (LaTeX-find-matching-end))
3586 (setq end (line-beginning-position 2))
3588 (dotimes (c count) (LaTeX-find-matching-begin))
3592 (TeX-activate-region)))
3594 (defun LaTeX-fill-environment (justify)
3595 "Fill and indent current environment as LaTeX text."
3598 (LaTeX-mark-environment)
3599 (re-search-forward "{\\([^}]+\\)}")
3600 (LaTeX-fill-region (region-beginning) (region-end) justify
3601 (concat " environment " (TeX-match-buffer 1)))))
3603 (defun LaTeX-fill-section (justify)
3604 "Fill and indent current logical section as LaTeX text."
3607 (LaTeX-mark-section)
3608 (re-search-forward "{\\([^}]+\\)}")
3609 (LaTeX-fill-region (region-beginning) (region-end) justify
3610 (concat " section " (TeX-match-buffer 1)))))
3612 (defun LaTeX-mark-section (&optional no-subsections)
3613 "Set mark at end of current logical section, and point at top.
3614 If optional argument NO-SUBSECTIONS is non-nil, mark only the
3615 region from the current section start to the next sectioning
3616 command. Thereby subsections are not being marked.
3618 If the function `outline-mark-subtree' is not available,
3619 `LaTeX-mark-section' always behaves like this regardless of the
3620 value of NO-SUBSECTIONS."
3622 (if (or no-subsections
3623 (not (fboundp 'outline-mark-subtree)))
3625 (re-search-forward (concat "\\(" (LaTeX-outline-regexp)
3628 (push-mark (point) nil t)
3629 (re-search-backward (concat "\\(" (LaTeX-outline-regexp)
3631 (outline-mark-subtree)
3632 (when (and (boundp 'transient-mark-mode)
3634 (boundp 'mark-active)
3636 (setq mark-active t)
3637 (run-hooks 'activate-mark-hook)))
3638 (TeX-activate-region))
3640 (defun LaTeX-fill-buffer (justify)
3641 "Fill and indent current buffer as LaTeX text."
3648 (concat " buffer " (buffer-name)))))
3653 (defvar LaTeX-paragraph-commands-internal
3654 '("[" "]" ; display math
3655 "appendix" "begin" "caption" "chapter" "end" "include" "includeonly"
3656 "label" "maketitle" "noindent" "par" "paragraph" "part" "section"
3657 "subsection" "subsubsection" "tableofcontents")
3658 "Internal list of LaTeX macros that should have their own line.")
3660 (defun LaTeX-paragraph-commands-regexp-make ()
3661 "Return a regular expression matching defined paragraph commands."
3662 (concat (regexp-quote TeX-esc) "\\("
3663 (regexp-opt (append LaTeX-paragraph-commands
3664 LaTeX-paragraph-commands-internal)) "\\)"))
3666 (defcustom LaTeX-paragraph-commands nil
3667 "List of LaTeX macros that should have their own line.
3668 The list should contain macro names without the leading backslash."
3670 :type '(repeat (string))
3671 :set (lambda (symbol value)
3672 (set-default symbol value)
3673 (setq LaTeX-paragraph-commands-regexp
3674 (LaTeX-paragraph-commands-regexp-make))))
3676 (defvar LaTeX-paragraph-commands-regexp (LaTeX-paragraph-commands-regexp-make)
3677 "Regular expression matching LaTeX macros that should have their own line.")
3679 (defun LaTeX-set-paragraph-start ()
3680 "Set `paragraph-start'."
3681 (setq paragraph-start
3684 LaTeX-paragraph-commands-regexp "\\|"
3685 (regexp-quote TeX-esc) "\\(" LaTeX-item-regexp "\\)\\|"
3686 "\\$\\$\\|" ; Plain TeX display math (Some people actually
3687 ; use this with LaTeX. Yuck.)
3690 (defun LaTeX-paragraph-commands-add-locally (commands)
3691 "Make COMMANDS be recognized as paragraph commands.
3692 COMMANDS can be a single string or a list of strings which will
3693 be added to `LaTeX-paragraph-commands-internal'. Additionally
3694 `LaTeX-paragraph-commands-regexp' will be updated and both
3695 variables will be made buffer-local. This is mainly a
3696 convenience function which can be used in style files."
3697 (make-local-variable 'LaTeX-paragraph-commands-internal)
3698 (make-local-variable 'LaTeX-paragraph-commands-regexp)
3699 (unless (listp commands) (setq commands (list commands)))
3700 (dolist (elt commands)
3701 (add-to-list 'LaTeX-paragraph-commands-internal elt))
3702 (setq LaTeX-paragraph-commands-regexp (LaTeX-paragraph-commands-regexp-make))
3703 (LaTeX-set-paragraph-start))
3705 (defun LaTeX-forward-paragraph (&optional count)
3706 "Move forward to end of paragraph.
3707 If COUNT is non-nil, do it COUNT times."
3708 (or count (setq count 1))
3710 (let* ((macro-start (TeX-find-macro-start))
3711 (paragraph-command-start
3713 ;; Point is inside of a paragraph command.
3716 (goto-char macro-start)
3717 (looking-at LaTeX-paragraph-commands-regexp)))
3718 (match-beginning 0))
3719 ;; Point is before a paragraph command in the same line.
3721 (concat "[ \t]*\\(?:" TeX-comment-start-regexp
3722 "\\(?:" TeX-comment-start-regexp "\\|[ \t]\\)*\\)?"
3723 "\\(" LaTeX-paragraph-commands-regexp "\\)"))
3724 (match-beginning 1))))
3726 ;; If a paragraph command is encountered there are two cases to be
3728 ;; 1) If the end of the paragraph command coincides (apart from
3729 ;; potential whitespace) with the end of the line, is only
3730 ;; followed by a comment or is directly followed by a macro,
3731 ;; it is assumed that it should be handled separately.
3732 ;; 2) If the end of the paragraph command is followed by other
3733 ;; code, it is assumed that it should be included with the rest
3734 ;; of the paragraph.
3735 (if (and paragraph-command-start
3737 (goto-char paragraph-command-start)
3738 (setq macro-end (goto-char (TeX-find-macro-end)))
3739 (looking-at (concat (regexp-quote TeX-esc) "[@A-Za-z]+\\|"
3741 TeX-comment-start-regexp "\\)"))))
3743 (goto-char macro-end)
3744 ;; If the paragraph command is followed directly by
3745 ;; another macro, regard the latter as part of the
3746 ;; paragraph command's paragraph.
3747 (when (looking-at (concat (regexp-quote TeX-esc) "[@A-Za-z]+"))
3748 (goto-char (TeX-find-macro-end)))
3751 (goto-char (min (save-excursion
3753 (setq limit (point)))
3755 (TeX-forward-comment-skip 1 limit)
3758 (defun LaTeX-backward-paragraph (&optional count)
3759 "Move backward to beginning of paragraph.
3760 If COUNT is non-nil, do it COUNT times."
3761 (or count (setq count 1))
3763 (let* ((macro-start (TeX-find-macro-start)))
3764 (if (and macro-start
3765 ;; Point really has to be inside of the macro, not before it.
3766 (not (= macro-start (point)))
3768 (goto-char macro-start)
3769 (looking-at LaTeX-paragraph-commands-regexp)))
3770 ;; Point is inside of a paragraph command.
3772 (goto-char macro-start)
3773 (beginning-of-line))
3775 (start (line-beginning-position)))
3777 (max (save-excursion
3778 (backward-paragraph)
3779 (setq limit (point)))
3780 ;; Search for possible transitions from commented to
3781 ;; uncommented regions and vice versa.
3783 (TeX-backward-comment-skip 1 limit)
3785 ;; Search for paragraph commands.
3787 (let ((end-point 0) macro-bol)
3788 (when (setq macro-bol
3790 (format "^[ \t]*%s*[ \t]*\\(%s\\)"
3791 TeX-comment-start-regexp
3792 LaTeX-paragraph-commands-regexp)
3794 (if (and (string= (match-string 1) "\\begin")
3796 (goto-char (match-end 1))
3797 (skip-chars-forward "{ \t")
3798 (member (buffer-substring-no-properties
3799 (point) (progn (skip-chars-forward
3800 "A-Za-z*") (point)))
3801 LaTeX-verbatim-environments)))
3802 ;; If inside a verbatim environment, just
3803 ;; use the next line. In such environments
3804 ;; `TeX-find-macro-end' could otherwise
3805 ;; think brackets or braces belong to the
3807 (setq end-point (line-beginning-position 2))
3808 ;; Jump to the macro end otherwise.
3809 (goto-char (match-beginning 1))
3810 (goto-char (TeX-find-macro-end))
3811 ;; For an explanation of this distinction see
3812 ;; `LaTeX-forward-paragraph'.
3813 (if (looking-at (concat (regexp-quote TeX-esc)
3814 "[@A-Za-z]+\\|[ \t]*\\($\\|"
3815 TeX-comment-start-regexp "\\)"))
3817 (when (string= (buffer-substring-no-properties
3821 (goto-char (TeX-find-macro-end)))
3823 (when (< (point) start)
3824 (setq end-point (point))))
3825 (setq end-point macro-bol))))
3828 (defun LaTeX-search-forward-comment-start (&optional limit)
3829 "Search forward for a comment start from current position till LIMIT.
3830 If LIMIT is omitted, search till the end of the buffer.
3832 This function makes sure that any comment starters found inside
3833 of verbatim constructs are not considered."
3834 (setq limit (or limit (point-max)))
3839 (when (and (TeX-re-search-forward-unescaped
3840 TeX-comment-start-regexp limit 'move)
3841 (not (LaTeX-verbatim-p)))
3842 (setq start (match-beginning 0))
3844 (< (point) limit))))
3850 (defgroup LaTeX-math nil
3851 "Mathematics in AUCTeX."
3852 :group 'LaTeX-macro)
3854 (defcustom LaTeX-math-list nil
3855 "Alist of your personal LaTeX math symbols.
3857 Each entry should be a list with up to four elements, KEY, VALUE,
3860 KEY is the key (after `LaTeX-math-abbrev-prefix') to be redefined
3861 in math minor mode. If KEY is nil, the symbol has no associated
3862 keystroke \(it is available in the menu, though\).
3864 VALUE can be a string with the name of the macro to be inserted,
3865 or a function to be called. The macro must be given without the
3868 The third element MENU is the name of the submenu where the
3869 command should be added. MENU can be either a string
3870 \(e.g. \"greek\"\), a list (e.g. \(\"AMS\" \"Delimiters\"\)\) or
3871 nil. If MENU is nil, no menu item will be created.
3873 The fourth element CHARACTER is a Unicode character position for
3874 menu display. When nil, no character is shown.
3876 See also `LaTeX-math-menu'."
3878 :type '(repeat (group (choice :tag "Key"
3879 (const :tag "none" nil)
3881 (string :tag "Key sequence")))
3882 (choice :tag "Value"
3883 (string :tag "Macro")
3886 (string :tag "Top level menu" )
3887 (repeat :tag "Submenu"
3888 (string :tag "Menu")))
3889 (choice :tag "Unicode character"
3890 (const :tag "none" nil)
3891 (integer :tag "Number")))))
3893 (defconst LaTeX-math-default
3894 '((?a "alpha" "Greek Lowercase" 945) ;; #X03B1
3895 (?b "beta" "Greek Lowercase" 946) ;; #X03B2
3896 (?g "gamma" "Greek Lowercase" 947) ;; #X03B3
3897 (?d "delta" "Greek Lowercase" 948) ;; #X03B4
3898 (?e "epsilon" "Greek Lowercase" 1013) ;; #X03F5
3899 (?z "zeta" "Greek Lowercase" 950) ;; #X03B6
3900 (?h "eta" "Greek Lowercase" 951) ;; #X03B7
3901 (?j "theta" "Greek Lowercase" 952) ;; #X03B8
3902 (nil "iota" "Greek Lowercase" 953) ;; #X03B9
3903 (?k "kappa" "Greek Lowercase" 954) ;; #X03BA
3904 (?l "lambda" "Greek Lowercase" 955) ;; #X03BB
3905 (?m "mu" "Greek Lowercase" 956) ;; #X03BC
3906 (?n "nu" "Greek Lowercase" 957) ;; #X03BD
3907 (?x "xi" "Greek Lowercase" 958) ;; #X03BE
3908 (?p "pi" "Greek Lowercase" 960) ;; #X03C0
3909 (?r "rho" "Greek Lowercase" 961) ;; #X03C1
3910 (?s "sigma" "Greek Lowercase" 963) ;; #X03C3
3911 (?t "tau" "Greek Lowercase" 964) ;; #X03C4
3912 (?u "upsilon" "Greek Lowercase" 965) ;; #X03C5
3913 (?f "phi" "Greek Lowercase" 981) ;; #X03D5
3914 (?q "chi" "Greek Lowercase" 967) ;; #X03C7
3915 (?y "psi" "Greek Lowercase" 968) ;; #X03C8
3916 (?w "omega" "Greek Lowercase" 969) ;; #X03C9
3917 ("v e" "varepsilon" "Greek Lowercase" 949) ;; #X03B5
3918 ("v j" "vartheta" "Greek Lowercase" 977) ;; #X03D1
3919 ("v p" "varpi" "Greek Lowercase" 982) ;; #X03D6
3920 ("v r" "varrho" "Greek Lowercase" 1009) ;; #X03F1
3921 ("v s" "varsigma" "Greek Lowercase" 962) ;; #X03C2
3922 ("v f" "varphi" "Greek Lowercase" 966) ;; #X03C6
3923 (?G "Gamma" "Greek Uppercase" 915) ;; #X0393
3924 (?D "Delta" "Greek Uppercase" 916) ;; #X0394
3925 (?J "Theta" "Greek Uppercase" 920) ;; #X0398
3926 (?L "Lambda" "Greek Uppercase" 923) ;; #X039B
3927 (?X "Xi" "Greek Uppercase" 926) ;; #X039E
3928 (?P "Pi" "Greek Uppercase" 928) ;; #X03A0
3929 (?S "Sigma" "Greek Uppercase" 931) ;; #X03A3
3930 (?U "Upsilon" "Greek Uppercase" 978) ;; #X03D2
3931 (?F "Phi" "Greek Uppercase" 934) ;; #X03A6
3932 (?Y "Psi" "Greek Uppercase" 936) ;; #X03A8
3933 (?W "Omega" "Greek Uppercase" 937) ;; #X03A9
3934 (?c LaTeX-math-cal "Cal-whatever")
3935 (nil "pm" "Binary Op" 177) ;; #X00B1
3936 (nil "mp" "Binary Op" 8723) ;; #X2213
3937 (?* "times" "Binary Op" 215) ;; #X00D7
3938 (nil "div" "Binary Op" 247) ;; #X00F7
3939 (nil "ast" "Binary Op" 8727) ;; #X2217
3940 (nil "star" "Binary Op" 8902) ;; #X22C6
3941 (nil "circ" "Binary Op" 8728) ;; #X2218
3942 (nil "bullet" "Binary Op" 8729) ;; #X2219
3943 (?. "cdot" "Binary Op" 8901) ;; #X22C5
3944 (?- "cap" "Binary Op" 8745) ;; #X2229
3945 (?+ "cup" "Binary Op" 8746) ;; #X222A
3946 (nil "uplus" "Binary Op" 8846) ;; #X228E
3947 (nil "sqcap" "Binary Op" 8851) ;; #X2293
3948 (?| "vee" "Binary Op" 8744) ;; #X2228
3949 (?& "wedge" "Binary Op" 8743) ;; #X2227
3950 (?\\ "setminus" "Binary Op" 8726) ;; #X2216
3951 (nil "wr" "Binary Op" 8768) ;; #X2240
3952 (nil "diamond" "Binary Op" 8900) ;; #X22C4
3953 (nil "bigtriangleup" "Binary Op" 9651) ;; #X25B3
3954 (nil "bigtriangledown" "Binary Op" 9661) ;; #X25BD
3955 (nil "triangleleft" "Binary Op" 9665) ;; #X25C1
3956 (nil "triangleright" "Binary Op" 9655) ;; #X25B7
3957 (nil "lhd" "Binary Op")
3958 (nil "rhd" "Binary Op")
3959 (nil "unlhd" "Binary Op")
3960 (nil "unrhd" "Binary Op")
3961 (nil "oplus" "Binary Op" 8853) ;; #X2295
3962 (nil "ominus" "Binary Op" 8854) ;; #X2296
3963 (nil "otimes" "Binary Op" 8855) ;; #X2297
3964 (nil "oslash" "Binary Op" 8709) ;; #X2205
3965 (nil "odot" "Binary Op" 8857) ;; #X2299
3966 (nil "bigcirc" "Binary Op" 9675) ;; #X25CB
3967 (nil "dagger" "Binary Op" 8224) ;; #X2020
3968 (nil "ddagger" "Binary Op" 8225) ;; #X2021
3969 (nil "amalg" "Binary Op" 10815) ;; #X2A3F
3970 (?< "leq" "Relational" 8804) ;; #X2264
3971 (?> "geq" "Relational" 8805) ;; #X2265
3972 (nil "qed" "Relational" 8718) ;; #X220E
3973 (nil "equiv" "Relational" 8801) ;; #X2261
3974 (nil "models" "Relational" 8871) ;; #X22A7
3975 (nil "prec" "Relational" 8826) ;; #X227A
3976 (nil "succ" "Relational" 8827) ;; #X227B
3977 (nil "sim" "Relational" 8764) ;; #X223C
3978 (nil "perp" "Relational" 10178) ;; #X27C2
3979 (nil "preceq" "Relational" 10927) ;; #X2AAF
3980 (nil "succeq" "Relational" 10928) ;; #X2AB0
3981 (nil "simeq" "Relational" 8771) ;; #X2243
3982 (nil "mid" "Relational" 8739) ;; #X2223
3983 (nil "ll" "Relational" 8810) ;; #X226A
3984 (nil "gg" "Relational" 8811) ;; #X226B
3985 (nil "asymp" "Relational" 8781) ;; #X224D
3986 (nil "parallel" "Relational" 8741) ;; #X2225
3987 (?\{ "subset" "Relational" 8834) ;; #X2282
3988 (?\} "supset" "Relational" 8835) ;; #X2283
3989 (nil "approx" "Relational" 8776) ;; #X2248
3990 (nil "bowtie" "Relational" 8904) ;; #X22C8
3991 (?\[ "subseteq" "Relational" 8838) ;; #X2286
3992 (?\] "supseteq" "Relational" 8839) ;; #X2287
3993 (nil "cong" "Relational" 8773) ;; #X2245
3994 (nil "Join" "Relational" 10781) ;; #X2A1D
3995 (nil "sqsubset" "Relational" 8847) ;; #X228F
3996 (nil "sqsupset" "Relational" 8848) ;; #X2290
3997 (nil "neq" "Relational" 8800) ;; #X2260
3998 (nil "smile" "Relational" 8995) ;; #X2323
3999 (nil "sqsubseteq" "Relational" 8849) ;; #X2291
4000 (nil "sqsupseteq" "Relational" 8850) ;; #X2292
4001 (nil "doteq" "Relational" 8784) ;; #X2250
4002 (nil "frown" "Relational" 8994) ;; #X2322
4003 (?i "in" "Relational" 8712) ;; #X2208
4004 (nil "ni" "Relational" 8715) ;; #X220B
4005 (nil "propto" "Relational" 8733) ;; #X221D
4006 (nil "vdash" "Relational" 8866) ;; #X22A2
4007 (nil "dashv" "Relational" 8867) ;; #X22A3
4008 (?\C-b "leftarrow" "Arrows" 8592) ;; #X2190
4009 (nil "Leftarrow" "Arrows" 8656) ;; #X21D0
4010 (?\C-f "rightarrow" "Arrows" 8594) ;; #X2192
4011 (nil "Rightarrow" "Arrows" 8658) ;; #X21D2
4012 (nil "leftrightarrow" "Arrows" 8596) ;; #X2194
4013 (nil "Leftrightarrow" "Arrows" 8660) ;; #X21D4
4014 (nil "mapsto" "Arrows" 8614) ;; #X21A6
4015 (nil "hookleftarrow" "Arrows" 8617) ;; #X21A9
4016 (nil "leftharpoonup" "Arrows" 8636) ;; #X21BC
4017 (nil "leftharpoondown" "Arrows" 8637) ;; #X21BD
4018 (nil "longleftarrow" "Arrows" 10229) ;; #X27F5
4019 (nil "Longleftarrow" "Arrows" 10232) ;; #X27F8
4020 (nil "longrightarrow" "Arrows" 10230) ;; #X27F6
4021 (nil "Longrightarrow" "Arrows" 10233) ;; #X27F9
4022 (nil "longleftrightarrow" "Arrows" 10231) ;; #X27F7
4023 (nil "Longleftrightarrow" "Arrows" 10234) ;; #X27FA
4024 (nil "longmapsto" "Arrows" 10236) ;; #X27FC
4025 (nil "hookrightarrow" "Arrows" 8618) ;; #X21AA
4026 (nil "rightharpoonup" "Arrows" 8640) ;; #X21C0
4027 (nil "rightharpoondown" "Arrows" 8641) ;; #X21C1
4028 (?\C-p "uparrow" "Arrows" 8593) ;; #X2191
4029 (nil "Uparrow" "Arrows" 8657) ;; #X21D1
4030 (?\C-n "downarrow" "Arrows" 8595) ;; #X2193
4031 (nil "Downarrow" "Arrows" 8659) ;; #X21D3
4032 (nil "updownarrow" "Arrows" 8597) ;; #X2195
4033 (nil "Updownarrow" "Arrows" 8661) ;; #X21D5
4034 (nil "nearrow" "Arrows" 8599) ;; #X2197
4035 (nil "searrow" "Arrows" 8600) ;; #X2198
4036 (nil "swarrow" "Arrows" 8601) ;; #X2199
4037 (nil "nwarrow" "Arrows" 8598) ;; #X2196
4038 (nil "ldots" "Punctuation" 8230) ;; #X2026
4039 (nil "cdots" "Punctuation" 8943) ;; #X22EF
4040 (nil "vdots" "Punctuation" 8942) ;; #X22EE
4041 (nil "ddots" "Punctuation" 8945) ;; #X22F1
4042 (?: "colon" "Punctuation" 58) ;; #X003A
4043 (?N "nabla" "Misc Symbol" 8711) ;; #X2207
4044 (nil "aleph" "Misc Symbol" 8501) ;; #X2135
4045 (nil "prime" "Misc Symbol" 8242) ;; #X2032
4046 (?A "forall" "Misc Symbol" 8704) ;; #X2200
4047 (?I "infty" "Misc Symbol" 8734) ;; #X221E
4048 (nil "hbar" "Misc Symbol" 8463) ;; #X210F
4049 (?0 "emptyset" "Misc Symbol" 8709) ;; #X2205
4050 (?E "exists" "Misc Symbol" 8707) ;; #X2203
4051 (nil "surd" "Misc Symbol" 8730) ;; #X221A
4052 (nil "Box" "Misc Symbol")
4053 (nil "triangle" "Misc Symbol" 9651) ;; #X25B3
4054 (nil "Diamond" "Misc Symbol")
4055 (nil "imath" "Misc Symbol" 305) ;; #X0131
4056 (nil "jmath" "Misc Symbol" 120485) ;; #X1D6A5
4057 (nil "ell" "Misc Symbol" 8467) ;; #X2113
4058 (nil "neg" "Misc Symbol" 172) ;; #X00AC
4059 (?/ "not" "Misc Symbol" 824) ;; #X0338
4060 (nil "top" "Misc Symbol" 8868) ;; #X22A4
4061 (nil "flat" "Misc Symbol" 9837) ;; #X266D
4062 (nil "natural" "Misc Symbol" 9838) ;; #X266E
4063 (nil "sharp" "Misc Symbol" 9839) ;; #X266F
4064 (nil "wp" "Misc Symbol" 8472) ;; #X2118
4065 (nil "bot" "Misc Symbol" 8869) ;; #X22A5
4066 (nil "clubsuit" "Misc Symbol" 9827) ;; #X2663
4067 (nil "diamondsuit" "Misc Symbol" 9826) ;; #X2662
4068 (nil "heartsuit" "Misc Symbol" 9825) ;; #X2661
4069 (nil "spadesuit" "Misc Symbol" 9824) ;; #X2660
4070 (nil "mho" "Misc Symbol" 8487) ;; #X2127
4071 (nil "Re" "Misc Symbol" 8476) ;; #X211C
4072 (nil "Im" "Misc Symbol" 8465) ;; #X2111
4073 (nil "angle" "Misc Symbol" 8736) ;; #X2220
4074 (nil "partial" "Misc Symbol" 8706) ;; #X2202
4075 (nil "sum" "Var Symbol" 8721) ;; #X2211
4076 (nil "prod" "Var Symbol" 8719) ;; #X220F
4077 (nil "coprod" "Var Symbol" 8720) ;; #X2210
4078 (nil "int" "Var Symbol" 8747) ;; #X222B
4079 (nil "oint" "Var Symbol" 8750) ;; #X222E
4080 (nil "bigcap" "Var Symbol" 8898) ;; #X22C2
4081 (nil "bigcup" "Var Symbol" 8899) ;; #X22C3
4082 (nil "bigsqcup" "Var Symbol" 10758) ;; #X2A06
4083 (nil "bigvee" "Var Symbol" 8897) ;; #X22C1
4084 (nil "bigwedge" "Var Symbol" 8896) ;; #X22C0
4085 (nil "bigodot" "Var Symbol" 10752) ;; #X2A00
4086 (nil "bigotimes" "Var Symbol" 10754) ;; #X2A02
4087 (nil "bigoplus" "Var Symbol" 10753) ;; #X2A01
4088 (nil "biguplus" "Var Symbol" 10756) ;; #X2A04
4089 (nil "arccos" "Log-like")
4090 (nil "arcsin" "Log-like")
4091 (nil "arctan" "Log-like")
4092 (nil "arg" "Log-like")
4093 (?\C-c "cos" "Log-like")
4094 (nil "cosh" "Log-like")
4095 (nil "cot" "Log-like")
4096 (nil "coth" "Log-like")
4097 (nil "csc" "Log-like")
4098 (nil "deg" "Log-like")
4099 (?\C-d "det" "Log-like")
4100 (nil "dim" "Log-like")
4101 (?\C-e "exp" "Log-like")
4102 (nil "gcd" "Log-like")
4103 (nil "hom" "Log-like")
4104 (?\C-_ "inf" "Log-like")
4105 (nil "ker" "Log-like")
4106 (nil "lg" "Log-like")
4107 (?\C-l "lim" "Log-like")
4108 (nil "liminf" "Log-like")
4109 (nil "limsup" "Log-like")
4110 (nil "ln" "Log-like")
4111 (nil "log" "Log-like")
4112 (nil "max" "Log-like")
4113 (nil "min" "Log-like")
4114 (nil "Pr" "Log-like")
4115 (nil "sec" "Log-like")
4116 (?\C-s "sin" "Log-like")
4117 (nil "sinh" "Log-like")
4118 (?\C-^ "sup" "Log-like")
4119 (?\C-t "tan" "Log-like")
4120 (nil "tanh" "Log-like")
4121 (nil "{" "Delimiters")
4122 (nil "}" "Delimiters")
4123 (nil "lfloor" "Delimiters" 8970) ;; #X230A
4124 (nil "rfloor" "Delimiters" 8971) ;; #X230B
4125 (nil "lceil" "Delimiters" 8968) ;; #X2308
4126 (nil "rceil" "Delimiters" 8969) ;; #X2309
4127 (?\( "langle" "Delimiters" 10216) ;; #X27E8
4128 (?\) "rangle" "Delimiters" 10217) ;; #X27E9
4129 (nil "rmoustache" "Delimiters" 9137) ;; #X23B1
4130 (nil "lmoustache" "Delimiters" 9136) ;; #X23B0
4131 (nil "rgroup" "Delimiters")
4132 (nil "lgroup" "Delimiters")
4133 (nil "backslash" "Delimiters" 92) ;; #X005C
4134 (nil "|" "Delimiters")
4135 (nil "arrowvert" "Delimiters")
4136 (nil "Arrowvert" "Delimiters")
4137 (nil "bracevert" "Delimiters")
4138 (nil "widetilde" "Constructs" 771) ;; #X0303
4139 (nil "widehat" "Constructs" 770) ;; #X0302
4140 (nil "overleftarrow" "Constructs" 8406) ;; #X20D6
4141 (nil "overrightarrow" "Constructs")
4142 (nil "overline" "Constructs")
4143 (nil "underline" "Constructs")
4144 (nil "overbrace" "Constructs" 65079) ;; #XFE37
4145 (nil "underbrace" "Constructs" 65080) ;; #XFE38
4146 (nil "sqrt" "Constructs" 8730) ;; #X221A
4147 (nil "frac" "Constructs")
4148 (?^ "hat" "Accents" 770) ;; #X0302
4149 (nil "acute" "Accents" 769) ;; #X0301
4150 (nil "bar" "Accents" 772) ;; #X0304
4151 (nil "dot" "Accents" 775) ;; #X0307
4152 (nil "breve" "Accents" 774) ;; #X0306
4153 (nil "check" "Accents" 780) ;; #X030C
4154 (nil "grave" "Accents" 768) ;; #X0300
4155 (nil "vec" "Accents" 8407) ;; #X20D7
4156 (nil "ddot" "Accents" 776) ;; #X0308
4157 (?~ "tilde" "Accents" 771) ;; #X0303
4158 (nil "digamma" ("AMS" "Hebrew") 989) ;; #X03DD
4159 (nil "varkappa" ("AMS" "Hebrew") 1008) ;; #X03F0
4160 (nil "beth" ("AMS" "Hebrew") 8502) ;; #X2136
4161 (nil "daleth" ("AMS" "Hebrew") 8504) ;; #X2138
4162 (nil "gimel" ("AMS" "Hebrew") 8503) ;; #X2137
4163 ("v G" "varGamma" ("AMS" "Greek Uppercase"))
4164 ("v D" "varDelta" ("AMS" "Greek Uppercase"))
4165 ("v J" "varTheta" ("AMS" "Greek Uppercase"))
4166 ("v L" "varLambda" ("AMS" "Greek Uppercase"))
4167 ("v X" "varXi" ("AMS" "Greek Uppercase"))
4168 ("v P" "varPi" ("AMS" "Greek Uppercase"))
4169 ("v S" "varSigma" ("AMS" "Greek Uppercase"))
4170 ("v U" "varUpsilon" ("AMS" "Greek Uppercase"))
4171 ("v F" "varPhi" ("AMS" "Greek Uppercase"))
4172 ("v Y" "varPsi" ("AMS" "Greek Uppercase"))
4173 ("v W" "varOmega" ("AMS" "Greek Uppercase"))
4174 (nil "dashrightarrow" ("AMS" "Arrows"))
4175 (nil "dashleftarrow" ("AMS" "Arrows"))
4176 (nil "leftleftarrows" ("AMS" "Arrows") 8647) ;; #X21C7
4177 (nil "leftrightarrows" ("AMS" "Arrows") 8646) ;; #X21C6
4178 (nil "Lleftarrow" ("AMS" "Arrows") 8666) ;; #X21DA
4179 (nil "twoheadleftarrow" ("AMS" "Arrows") 8606) ;; #X219E
4180 (nil "leftarrowtail" ("AMS" "Arrows") 8610) ;; #X21A2
4181 (nil "looparrowleft" ("AMS" "Arrows") 8619) ;; #X21AB
4182 (nil "leftrightharpoons" ("AMS" "Arrows") 8651) ;; #X21CB
4183 (nil "curvearrowleft" ("AMS" "Arrows") 8630) ;; #X21B6
4184 (nil "circlearrowleft" ("AMS" "Arrows"))
4185 (nil "Lsh" ("AMS" "Arrows") 8624) ;; #X21B0
4186 (nil "upuparrows" ("AMS" "Arrows") 8648) ;; #X21C8
4187 (nil "upharpoonleft" ("AMS" "Arrows") 8639) ;; #X21BF
4188 (nil "downharpoonleft" ("AMS" "Arrows") 8643) ;; #X21C3
4189 (nil "multimap" ("AMS" "Arrows") 8888) ;; #X22B8
4190 (nil "leftrightsquigarrow" ("AMS" "Arrows") 8621) ;; #X21AD
4191 (nil "looparrowright" ("AMS" "Arrows") 8620) ;; #X21AC
4192 (nil "rightleftharpoons" ("AMS" "Arrows") 8652) ;; #X21CC
4193 (nil "curvearrowright" ("AMS" "Arrows") 8631) ;; #X21B7
4194 (nil "circlearrowright" ("AMS" "Arrows"))
4195 (nil "Rsh" ("AMS" "Arrows") 8625) ;; #X21B1
4196 (nil "downdownarrows" ("AMS" "Arrows") 8650) ;; #X21CA
4197 (nil "upharpoonright" ("AMS" "Arrows") 8638) ;; #X21BE
4198 (nil "downharpoonright" ("AMS" "Arrows") 8642) ;; #X21C2
4199 (nil "rightsquigarrow" ("AMS" "Arrows") 8605) ;; #X219D
4200 (nil "nleftarrow" ("AMS" "Neg Arrows") 8602) ;; #X219A
4201 (nil "nrightarrow" ("AMS" "Neg Arrows") 8603) ;; #X219B
4202 (nil "nLeftarrow" ("AMS" "Neg Arrows") 8653) ;; #X21CD
4203 (nil "nRightarrow" ("AMS" "Neg Arrows") 8655) ;; #X21CF
4204 (nil "nleftrightarrow" ("AMS" "Neg Arrows") 8622) ;; #X21AE
4205 (nil "nLeftrightarrow" ("AMS" "Neg Arrows") 8654) ;; #X21CE
4206 (nil "leqq" ("AMS" "Relational I") 8806) ;; #X2266
4207 (nil "leqslant" ("AMS" "Relational I") 10877) ;; #X2A7D
4208 (nil "eqslantless" ("AMS" "Relational I") 10901) ;; #X2A95
4209 (nil "lesssim" ("AMS" "Relational I") 8818) ;; #X2272
4210 (nil "lessapprox" ("AMS" "Relational I") 10885) ;; #X2A85
4211 (nil "approxeq" ("AMS" "Relational I") 8778) ;; #X224A
4212 (nil "lessdot" ("AMS" "Relational I") 8918) ;; #X22D6
4213 (nil "lll" ("AMS" "Relational I") 8920) ;; #X22D8
4214 (nil "lessgtr" ("AMS" "Relational I") 8822) ;; #X2276
4215 (nil "lesseqgtr" ("AMS" "Relational I") 8922) ;; #X22DA
4216 (nil "lesseqqgtr" ("AMS" "Relational I") 10891) ;; #X2A8B
4217 (nil "doteqdot" ("AMS" "Relational I"))
4218 (nil "risingdotseq" ("AMS" "Relational I") 8787) ;; #X2253
4219 (nil "fallingdotseq" ("AMS" "Relational I") 8786) ;; #X2252
4220 (nil "backsim" ("AMS" "Relational I") 8765) ;; #X223D
4221 (nil "backsimeq" ("AMS" "Relational I") 8909) ;; #X22CD
4222 (nil "subseteqq" ("AMS" "Relational I") 10949) ;; #X2AC5
4223 (nil "Subset" ("AMS" "Relational I") 8912) ;; #X22D0
4224 (nil "sqsubset" ("AMS" "Relational I") 8847) ;; #X228F
4225 (nil "preccurlyeq" ("AMS" "Relational I") 8828) ;; #X227C
4226 (nil "curlyeqprec" ("AMS" "Relational I") 8926) ;; #X22DE
4227 (nil "precsim" ("AMS" "Relational I") 8830) ;; #X227E
4228 (nil "precapprox" ("AMS" "Relational I") 10935) ;; #X2AB7
4229 (nil "vartriangleleft" ("AMS" "Relational I") 8882) ;; #X22B2
4230 (nil "trianglelefteq" ("AMS" "Relational I") 8884) ;; #X22B4
4231 (nil "vDash" ("AMS" "Relational I") 8872) ;; #X22A8
4232 (nil "Vvdash" ("AMS" "Relational I") 8874) ;; #X22AA
4233 (nil "smallsmile" ("AMS" "Relational I") 8995) ;; #X2323
4234 (nil "smallfrown" ("AMS" "Relational I") 8994) ;; #X2322
4235 (nil "bumpeq" ("AMS" "Relational I") 8783) ;; #X224F
4236 (nil "Bumpeq" ("AMS" "Relational I") 8782) ;; #X224E
4237 (nil "geqq" ("AMS" "Relational II") 8807) ;; #X2267
4238 (nil "geqslant" ("AMS" "Relational II") 10878) ;; #X2A7E
4239 (nil "eqslantgtr" ("AMS" "Relational II") 10902) ;; #X2A96
4240 (nil "gtrsim" ("AMS" "Relational II") 8819) ;; #X2273
4241 (nil "gtrapprox" ("AMS" "Relational II") 10886) ;; #X2A86
4242 (nil "gtrdot" ("AMS" "Relational II") 8919) ;; #X22D7
4243 (nil "ggg" ("AMS" "Relational II") 8921) ;; #X22D9
4244 (nil "gtrless" ("AMS" "Relational II") 8823) ;; #X2277
4245 (nil "gtreqless" ("AMS" "Relational II") 8923) ;; #X22DB
4246 (nil "gtreqqless" ("AMS" "Relational II") 10892) ;; #X2A8C
4247 (nil "eqcirc" ("AMS" "Relational II") 8790) ;; #X2256
4248 (nil "circeq" ("AMS" "Relational II") 8791) ;; #X2257
4249 (nil "triangleq" ("AMS" "Relational II") 8796) ;; #X225C
4250 (nil "thicksim" ("AMS" "Relational II") 8764) ;; #X223C
4251 (nil "thickapprox" ("AMS" "Relational II") 8776) ;; #X2248
4252 (nil "supseteqq" ("AMS" "Relational II") 10950) ;; #X2AC6
4253 (nil "Supset" ("AMS" "Relational II") 8913) ;; #X22D1
4254 (nil "sqsupset" ("AMS" "Relational II") 8848) ;; #X2290
4255 (nil "succcurlyeq" ("AMS" "Relational II") 8829) ;; #X227D
4256 (nil "curlyeqsucc" ("AMS" "Relational II") 8927) ;; #X22DF
4257 (nil "succsim" ("AMS" "Relational II") 8831) ;; #X227F
4258 (nil "succapprox" ("AMS" "Relational II") 10936) ;; #X2AB8
4259 (nil "vartriangleright" ("AMS" "Relational II") 8883) ;; #X22B3
4260 (nil "trianglerighteq" ("AMS" "Relational II") 8885) ;; #X22B5
4261 (nil "Vdash" ("AMS" "Relational II") 8873) ;; #X22A9
4262 (nil "shortmid" ("AMS" "Relational II") 8739) ;; #X2223
4263 (nil "shortparallel" ("AMS" "Relational II") 8741) ;; #X2225
4264 (nil "between" ("AMS" "Relational II") 8812) ;; #X226C
4265 (nil "pitchfork" ("AMS" "Relational II") 8916) ;; #X22D4
4266 (nil "varpropto" ("AMS" "Relational II") 8733) ;; #X221D
4267 (nil "blacktriangleleft" ("AMS" "Relational II") 9664) ;; #X25C0
4268 (nil "therefore" ("AMS" "Relational II") 8756) ;; #X2234
4269 (nil "backepsilon" ("AMS" "Relational II") 1014) ;; #X03F6
4270 (nil "blacktriangleright" ("AMS" "Relational II") 9654) ;; #X25B6
4271 (nil "because" ("AMS" "Relational II") 8757) ;; #X2235
4272 (nil "nless" ("AMS" "Neg Rel I") 8814) ;; #X226E
4273 (nil "nleq" ("AMS" "Neg Rel I") 8816) ;; #X2270
4274 (nil "nleqslant" ("AMS" "Neg Rel I"))
4275 (nil "nleqq" ("AMS" "Neg Rel I"))
4276 (nil "lneq" ("AMS" "Neg Rel I") 10887) ;; #X2A87
4277 (nil "lneqq" ("AMS" "Neg Rel I") 8808) ;; #X2268
4278 (nil "lvertneqq" ("AMS" "Neg Rel I"))
4279 (nil "lnsim" ("AMS" "Neg Rel I") 8934) ;; #X22E6
4280 (nil "lnapprox" ("AMS" "Neg Rel I") 10889) ;; #X2A89
4281 (nil "nprec" ("AMS" "Neg Rel I") 8832) ;; #X2280
4282 (nil "npreceq" ("AMS" "Neg Rel I"))
4283 (nil "precnsim" ("AMS" "Neg Rel I") 8936) ;; #X22E8
4284 (nil "precnapprox" ("AMS" "Neg Rel I") 10937) ;; #X2AB9
4285 (nil "nsim" ("AMS" "Neg Rel I") 8769) ;; #X2241
4286 (nil "nshortmid" ("AMS" "Neg Rel I") 8740) ;; #X2224
4287 (nil "nmid" ("AMS" "Neg Rel I") 8740) ;; #X2224
4288 (nil "nvdash" ("AMS" "Neg Rel I") 8876) ;; #X22AC
4289 (nil "nvDash" ("AMS" "Neg Rel I") 8877) ;; #X22AD
4290 (nil "ntriangleleft" ("AMS" "Neg Rel I") 8938) ;; #X22EA
4291 (nil "ntrianglelefteq" ("AMS" "Neg Rel I") 8940) ;; #X22EC
4292 (nil "nsubseteq" ("AMS" "Neg Rel I") 8840) ;; #X2288
4293 (nil "subsetneq" ("AMS" "Neg Rel I") 8842) ;; #X228A
4294 (nil "varsubsetneq" ("AMS" "Neg Rel I"))
4295 (nil "subsetneqq" ("AMS" "Neg Rel I") 10955) ;; #X2ACB
4296 (nil "varsubsetneqq" ("AMS" "Neg Rel I"))
4297 (nil "ngtr" ("AMS" "Neg Rel II") 8815) ;; #X226F
4298 (nil "ngeq" ("AMS" "Neg Rel II") 8817) ;; #X2271
4299 (nil "ngeqslant" ("AMS" "Neg Rel II"))
4300 (nil "ngeqq" ("AMS" "Neg Rel II"))
4301 (nil "gneq" ("AMS" "Neg Rel II") 10888) ;; #X2A88
4302 (nil "gneqq" ("AMS" "Neg Rel II") 8809) ;; #X2269
4303 (nil "gvertneqq" ("AMS" "Neg Rel II"))
4304 (nil "gnsim" ("AMS" "Neg Rel II") 8935) ;; #X22E7
4305 (nil "gnapprox" ("AMS" "Neg Rel II") 10890) ;; #X2A8A
4306 (nil "nsucc" ("AMS" "Neg Rel II") 8833) ;; #X2281
4307 (nil "nsucceq" ("AMS" "Neg Rel II"))
4308 (nil "succnsim" ("AMS" "Neg Rel II") 8937) ;; #X22E9
4309 (nil "succnapprox" ("AMS" "Neg Rel II") 10938) ;; #X2ABA
4310 (nil "ncong" ("AMS" "Neg Rel II") 8775) ;; #X2247
4311 (nil "nshortparallel" ("AMS" "Neg Rel II") 8742) ;; #X2226
4312 (nil "nparallel" ("AMS" "Neg Rel II") 8742) ;; #X2226
4313 (nil "nvDash" ("AMS" "Neg Rel II") 8877) ;; #X22AD
4314 (nil "nVDash" ("AMS" "Neg Rel II") 8879) ;; #X22AF
4315 (nil "ntriangleright" ("AMS" "Neg Rel II") 8939) ;; #X22EB
4316 (nil "ntrianglerighteq" ("AMS" "Neg Rel II") 8941) ;; #X22ED
4317 (nil "nsupseteq" ("AMS" "Neg Rel II") 8841) ;; #X2289
4318 (nil "nsupseteqq" ("AMS" "Neg Rel II"))
4319 (nil "supsetneq" ("AMS" "Neg Rel II") 8843) ;; #X228B
4320 (nil "varsupsetneq" ("AMS" "Neg Rel II"))
4321 (nil "supsetneqq" ("AMS" "Neg Rel II") 10956) ;; #X2ACC
4322 (nil "varsupsetneqq" ("AMS" "Neg Rel II"))
4323 (nil "dotplus" ("AMS" "Binary Op") 8724) ;; #X2214
4324 (nil "smallsetminus" ("AMS" "Binary Op") 8726) ;; #X2216
4325 (nil "Cap" ("AMS" "Binary Op") 8914) ;; #X22D2
4326 (nil "Cup" ("AMS" "Binary Op") 8915) ;; #X22D3
4327 (nil "barwedge" ("AMS" "Binary Op") 8892) ;; #X22BC
4328 (nil "veebar" ("AMS" "Binary Op") 8891) ;; #X22BB
4329 (nil "doublebarwedge" ("AMS" "Binary Op") 8966) ;; #X2306
4330 (nil "boxminus" ("AMS" "Binary Op") 8863) ;; #X229F
4331 (nil "boxtimes" ("AMS" "Binary Op") 8864) ;; #X22A0
4332 (nil "boxdot" ("AMS" "Binary Op") 8865) ;; #X22A1
4333 (nil "boxplus" ("AMS" "Binary Op") 8862) ;; #X229E
4334 (nil "divideontimes" ("AMS" "Binary Op") 8903) ;; #X22C7
4335 (nil "ltimes" ("AMS" "Binary Op") 8905) ;; #X22C9
4336 (nil "rtimes" ("AMS" "Binary Op") 8906) ;; #X22CA
4337 (nil "leftthreetimes" ("AMS" "Binary Op") 8907) ;; #X22CB
4338 (nil "rightthreetimes" ("AMS" "Binary Op") 8908) ;; #X22CC
4339 (nil "curlywedge" ("AMS" "Binary Op") 8911) ;; #X22CF
4340 (nil "curlyvee" ("AMS" "Binary Op") 8910) ;; #X22CE
4341 (nil "circleddash" ("AMS" "Binary Op") 8861) ;; #X229D
4342 (nil "circledast" ("AMS" "Binary Op") 8859) ;; #X229B
4343 (nil "circledcirc" ("AMS" "Binary Op") 8858) ;; #X229A
4344 (nil "centerdot" ("AMS" "Binary Op"))
4345 (nil "intercal" ("AMS" "Binary Op") 8890) ;; #X22BA
4346 (nil "hbar" ("AMS" "Misc") 8463) ;; #X210F
4347 (nil "hslash" ("AMS" "Misc") 8463) ;; #X210F
4348 (nil "vartriangle" ("AMS" "Misc") 9653) ;; #X25B5
4349 (nil "triangledown" ("AMS" "Misc") 9663) ;; #X25BF
4350 (nil "square" ("AMS" "Misc") 9633) ;; #X25A1
4351 (nil "lozenge" ("AMS" "Misc") 9674) ;; #X25CA
4352 (nil "circledS" ("AMS" "Misc") 9416) ;; #X24C8
4353 (nil "angle" ("AMS" "Misc") 8736) ;; #X2220
4354 (nil "measuredangle" ("AMS" "Misc") 8737) ;; #X2221
4355 (nil "nexists" ("AMS" "Misc") 8708) ;; #X2204
4356 (nil "mho" ("AMS" "Misc") 8487) ;; #X2127
4357 (nil "Finv" ("AMS" "Misc") 8498) ;; #X2132
4358 (nil "Game" ("AMS" "Misc") 8513) ;; #X2141
4359 (nil "Bbbk" ("AMS" "Misc") 120156) ;; #X1D55C
4360 (nil "backprime" ("AMS" "Misc") 8245) ;; #X2035
4361 (nil "varnothing" ("AMS" "Misc") 8709) ;; #X2205
4362 (nil "blacktriangle" ("AMS" "Misc") 9652) ;; #X25B4
4363 (nil "blacktriangledown" ("AMS" "Misc") 9662) ;; #X25BE
4364 (nil "blacksquare" ("AMS" "Misc") 9632) ;; #X25A0
4365 (nil "blacklozenge" ("AMS" "Misc") 10731) ;; #X29EB
4366 (nil "bigstar" ("AMS" "Misc") 9733) ;; #X2605
4367 (nil "sphericalangle" ("AMS" "Misc") 8738) ;; #X2222
4368 (nil "complement" ("AMS" "Misc") 8705) ;; #X2201
4369 (nil "eth" ("AMS" "Misc") 240) ;; #X00F0
4370 (nil "diagup" ("AMS" "Misc") 9585) ;; #X2571
4371 (nil "diagdown" ("AMS" "Misc") 9586) ;; #X2572
4372 (nil "dddot" ("AMS" "Accents") 8411) ;; #X20DB
4373 (nil "ddddot" ("AMS" "Accents") 8412) ;; #X20DC
4374 (nil "bigl" ("AMS" "Delimiters"))
4375 (nil "bigr" ("AMS" "Delimiters"))
4376 (nil "Bigl" ("AMS" "Delimiters"))
4377 (nil "Bigr" ("AMS" "Delimiters"))
4378 (nil "biggl" ("AMS" "Delimiters"))
4379 (nil "biggr" ("AMS" "Delimiters"))
4380 (nil "Biggl" ("AMS" "Delimiters"))
4381 (nil "Biggr" ("AMS" "Delimiters"))
4382 (nil "lvert" ("AMS" "Delimiters"))
4383 (nil "rvert" ("AMS" "Delimiters"))
4384 (nil "lVert" ("AMS" "Delimiters"))
4385 (nil "rVert" ("AMS" "Delimiters"))
4386 (nil "ulcorner" ("AMS" "Delimiters") 8988) ;; #X231C
4387 (nil "urcorner" ("AMS" "Delimiters") 8989) ;; #X231D
4388 (nil "llcorner" ("AMS" "Delimiters") 8990) ;; #X231E
4389 (nil "lrcorner" ("AMS" "Delimiters") 8991) ;; #X231F
4390 (nil "nobreakdash" ("AMS" "Special"))
4391 (nil "leftroot" ("AMS" "Special"))
4392 (nil "uproot" ("AMS" "Special"))
4393 (nil "accentedsymbol" ("AMS" "Special"))
4394 (nil "xleftarrow" ("AMS" "Special"))
4395 (nil "xrightarrow" ("AMS" "Special"))
4396 (nil "overset" ("AMS" "Special"))
4397 (nil "underset" ("AMS" "Special"))
4398 (nil "dfrac" ("AMS" "Special"))
4399 (nil "genfrac" ("AMS" "Special"))
4400 (nil "tfrac" ("AMS" "Special"))
4401 (nil "binom" ("AMS" "Special"))
4402 (nil "dbinom" ("AMS" "Special"))
4403 (nil "tbinom" ("AMS" "Special"))
4404 (nil "smash" ("AMS" "Special"))
4405 (nil "eucal" ("AMS" "Special"))
4406 (nil "boldsymbol" ("AMS" "Special"))
4407 (nil "text" ("AMS" "Special"))
4408 (nil "intertext" ("AMS" "Special"))
4409 (nil "substack" ("AMS" "Special"))
4410 (nil "subarray" ("AMS" "Special"))
4411 (nil "sideset" ("AMS" "Special")))
4412 "Alist of LaTeX math symbols.
4414 Each entry should be a list with upto four elements, KEY, VALUE,
4415 MENU and CHARACTER, see `LaTeX-math-list' for details.")
4417 (defcustom LaTeX-math-abbrev-prefix "`"
4418 "Prefix key for use in `LaTeX-math-mode'.
4419 This has to be a string representing a key sequence in a format
4420 understood by the `kbd' macro. This corresponds to the syntax
4421 usually used in the Emacs and Elisp manuals.
4423 Setting this variable directly does not take effect;
4426 :initialize 'custom-initialize-default
4427 :set '(lambda (symbol value)
4428 (define-key LaTeX-math-mode-map (LaTeX-math-abbrev-prefix) t)
4429 (set-default symbol value)
4430 (define-key LaTeX-math-mode-map
4431 (LaTeX-math-abbrev-prefix) LaTeX-math-keymap))
4432 :type '(string :tag "Key sequence"))
4434 (defun LaTeX-math-abbrev-prefix ()
4435 "Make a key definition from the variable `LaTeX-math-abbrev-prefix'."
4436 (if (stringp LaTeX-math-abbrev-prefix)
4437 (read-kbd-macro LaTeX-math-abbrev-prefix)
4438 LaTeX-math-abbrev-prefix))
4440 (defvar LaTeX-math-keymap (make-sparse-keymap)
4441 "Keymap used for `LaTeX-math-mode' commands.")
4443 (defvar LaTeX-math-menu
4445 ("Greek Uppercase") ("Greek Lowercase") ("Binary Op") ("Relational")
4446 ("Arrows") ("Punctuation") ("Misc Symbol") ("Var Symbol") ("Log-like")
4447 ("Delimiters") ("Constructs") ("Accents") ("AMS"))
4448 "Menu containing LaTeX math commands.
4449 The menu entries will be generated dynamically, but you can specify
4450 the sequence by initializing this variable.")
4452 (defcustom LaTeX-math-menu-unicode
4453 (and (string-match "\\<GTK\\>" (emacs-version)) t)
4454 "Whether the LaTeX menu should try using Unicode for effect."
4458 (let ((math (reverse (append LaTeX-math-list LaTeX-math-default)))
4459 (map LaTeX-math-keymap)
4460 (unicode (and LaTeX-math-menu-unicode (fboundp 'decode-char))))
4462 (let* ((entry (car math))
4468 (setq math (cdr math))
4470 (setq prefix (decode-char 'ucs (nth 3 entry))))
4471 (setq prefix (concat (string prefix) " \\"))
4473 (if (listp (cdr entry))
4474 (setq value (nth 1 entry)
4476 (setq value (cdr entry)
4480 (setq name (intern (concat "LaTeX-math-" value)))
4481 (fset name (list 'lambda (list 'arg) (list 'interactive "*P")
4482 (list 'LaTeX-math-insert value 'arg))))
4486 (setq key (cond ((numberp key) (char-to-string key))
4487 ((stringp key) (read-kbd-macro key))
4489 (define-key map key name)))
4491 (let ((parent LaTeX-math-menu))
4495 (let ((sub (assoc (car menu) LaTeX-math-menu)))
4498 (setcdr parent (cons (list (car menu)) (cdr parent))))
4499 (setq menu (cdr menu))))
4500 (setq menu (car menu))))
4501 (let ((sub (assoc menu parent)))
4504 (setcdr sub (cons (vector (concat prefix value)
4507 (error "Cannot have multiple special math menu items"))
4509 (cons (if (stringp value)
4510 (list menu (vector (concat prefix value)
4512 (vector menu name t))
4513 (cdr parent)))))))))
4514 ;; Make the math prefix char available if it has not been used as a prefix.
4515 (unless (lookup-key map (LaTeX-math-abbrev-prefix))
4516 (define-key map (LaTeX-math-abbrev-prefix) 'self-insert-command)))
4518 (define-minor-mode LaTeX-math-mode
4519 "A minor mode with easy access to TeX math macros.
4521 Easy insertion of LaTeX math symbols. If you give a prefix argument,
4522 the symbols will be surrounded by dollar signs. The following
4523 commands are defined:
4525 \\{LaTeX-math-mode-map}"
4526 nil nil (list (cons (LaTeX-math-abbrev-prefix) LaTeX-math-keymap))
4528 (easy-menu-add LaTeX-math-mode-menu LaTeX-math-mode-map)
4529 (easy-menu-remove LaTeX-math-mode-menu))
4530 (TeX-set-mode-name))
4531 (defalias 'latex-math-mode 'LaTeX-math-mode)
4533 (easy-menu-define LaTeX-math-mode-menu
4535 "Menu used in math minor mode."
4538 (defcustom LaTeX-math-insert-function 'TeX-insert-macro
4539 "Function called with argument STRING to insert \\STRING."
4543 (defun LaTeX-math-insert (string dollar)
4544 "Insert \\STRING{}. If DOLLAR is non-nil, put $'s around it."
4545 (if dollar (insert "$"))
4546 (funcall LaTeX-math-insert-function string)
4547 (if dollar (insert "$")))
4549 (defun LaTeX-math-cal (char dollar)
4550 "Insert a {\\cal CHAR}. If DOLLAR is non-nil, put $'s around it."
4551 (interactive "*c\nP")
4552 (if dollar (insert "$"))
4553 (if (member "latex2e" (TeX-style-list))
4554 (insert "\\mathcal{" (char-to-string char) "}")
4555 (insert "{\\cal " (char-to-string char) "}"))
4556 (if dollar (insert "$")))
4561 (defcustom LaTeX-fold-macro-spec-list nil
4562 "List of display strings and macros to fold in LaTeX mode."
4563 :type '(repeat (group (choice (string :tag "Display String")
4564 (integer :tag "Number of argument" :value 1))
4565 (repeat :tag "Macros" (string))))
4568 (defcustom LaTeX-fold-env-spec-list nil
4569 "List of display strings and environments to fold in LaTeX mode."
4570 :type '(repeat (group (choice (string :tag "Display String")
4571 (integer :tag "Number of argument" :value 1))
4572 (repeat :tag "Environments" (string))))
4575 (defcustom LaTeX-fold-math-spec-list
4577 (mapcar (lambda (elt)
4578 (let ((tex-token (nth 1 elt))
4579 (submenu (nth 2 elt))
4580 (unicode (nth 3 elt))
4582 (when (and (fboundp 'decode-char) (integerp unicode))
4583 (setq uchar (decode-char 'ucs unicode)))
4584 (when (listp submenu) (setq submenu (nth 1 submenu)))
4587 (concat "^" (regexp-opt '("Constructs"
4590 (when (and (stringp tex-token) (integerp uchar) noargp)
4591 `(,(char-to-string uchar) (,tex-token)))))
4592 `((nil "to" "" 8594)
4593 (nil "gets" "" 8592)
4594 ,@LaTeX-math-default)))
4595 "List of display strings and math macros to fold in LaTeX mode."
4596 :type '(repeat (group (choice (string :tag "Display String")
4597 (integer :tag "Number of argument" :value 1))
4598 (repeat :tag "Math Macros" (string))))
4604 (defvar LaTeX-mode-map
4605 (let ((map (make-sparse-keymap)))
4606 (set-keymap-parent map TeX-mode-map)
4609 (define-key map "\n" 'reindent-then-newline-and-indent)
4612 ;; We now set `fill-paragraph-function' instead.
4613 ;; (define-key map "\eq" 'LaTeX-fill-paragraph) ;*** Alias
4614 ;; This key is now used by Emacs for face settings.
4615 ;; (define-key map "\eg" 'LaTeX-fill-region) ;*** Alias
4616 (define-key map "\e\C-e" 'LaTeX-find-matching-end)
4617 (define-key map "\e\C-a" 'LaTeX-find-matching-begin)
4619 (define-key map "\C-c\C-q\C-p" 'LaTeX-fill-paragraph)
4620 (define-key map "\C-c\C-q\C-r" 'LaTeX-fill-region)
4621 (define-key map "\C-c\C-q\C-s" 'LaTeX-fill-section)
4622 (define-key map "\C-c\C-q\C-e" 'LaTeX-fill-environment)
4624 (define-key map "\C-c." 'LaTeX-mark-environment) ;*** Dubious
4625 (define-key map "\C-c*" 'LaTeX-mark-section) ;*** Dubious
4627 (define-key map "\C-c\C-e" 'LaTeX-environment)
4628 (define-key map "\C-c\n" 'LaTeX-insert-item)
4629 (or (key-binding "\e\r")
4630 (define-key map "\e\r" 'LaTeX-insert-item)) ;*** Alias
4631 (define-key map "\C-c]" 'LaTeX-close-environment)
4632 (define-key map "\C-c\C-s" 'LaTeX-section)
4634 (define-key map "\C-c~" 'LaTeX-math-mode) ;*** Dubious
4636 (define-key map "-" 'LaTeX-babel-insert-hyphen)
4638 "Keymap used in `LaTeX-mode'.")
4640 (defvar LaTeX-environment-menu-name "Insert Environment (C-c C-e)")
4642 (defun LaTeX-environment-menu-entry (entry)
4643 "Create an entry for the environment menu."
4644 (vector (car entry) (list 'LaTeX-environment-menu (car entry)) t))
4646 (defvar LaTeX-environment-modify-menu-name "Change Environment (C-u C-c C-e)")
4648 (defun LaTeX-environment-modify-menu-entry (entry)
4649 "Create an entry for the change environment menu."
4650 (vector (car entry) (list 'LaTeX-modify-environment (car entry)) t))
4652 (defun LaTeX-section-enable-symbol (LEVEL)
4653 "Symbol used to enable section LEVEL in the menu bar."
4654 (intern (concat "LaTeX-section-" (int-to-string (nth 1 entry)) "-enable")))
4656 (defun LaTeX-section-enable (entry)
4657 "Enable or disable section ENTRY from `LaTeX-section-list'."
4658 (let* ((level (nth 1 entry))
4659 (symbol (LaTeX-section-enable-symbol level)))
4660 (set symbol (or (= level 0) (>= level LaTeX-largest-level)))
4661 (make-variable-buffer-local symbol)))
4663 (defun LaTeX-section-menu (level)
4664 "Insert section from menu."
4665 (let ((LaTeX-section-hook (delq 'LaTeX-section-heading
4666 (copy-sequence LaTeX-section-hook))))
4667 (LaTeX-section level)))
4669 (defun LaTeX-section-menu-entry (entry)
4670 "Create an ENTRY for the section menu."
4671 (let ((enable (LaTeX-section-enable-symbol (nth 1 entry))))
4672 (vector (car entry) (list 'LaTeX-section-menu (nth 1 entry)) enable)))
4674 (defcustom LaTeX-menu-max-items 25
4675 "*Maximum number of items in the menu for LaTeX environments.
4676 If number of entries in a menu is larger than this value, split menu
4677 into submenus of nearly equal length. If nil, never split menu into
4679 :group 'LaTeX-environment
4680 :type '(choice (const :tag "no submenus" nil)
4683 (defcustom LaTeX-submenu-name-format "%-12.12s ... %.12s"
4684 "*Format specification of the submenu name.
4685 Used by `LaTeX-split-long-menu' if the number of entries in a menu is
4686 larger than `LaTeX-menu-max-items'.
4687 This string should contain one %s for the name of the first entry and
4688 one %s for the name of the last entry in the submenu.
4689 If the value is a function, it should return the submenu name. The
4690 function is called with two arguments, the names of the first and
4691 the last entry in the menu."
4692 :group 'LaTeX-environment
4693 :type '(choice (string :tag "Format string")
4696 (defun LaTeX-split-long-menu (menu)
4697 "Split MENU according to `LaTeX-menu-max-items'."
4698 (let ((len (length menu)))
4699 (if (or (null LaTeX-menu-max-items)
4700 (null (featurep 'lisp-float-type))
4701 (<= len LaTeX-menu-max-items))
4703 ;; Submenu is max 2 entries longer than menu, never shorter, number of
4704 ;; entries in submenus differ by at most one (with longer submenus first)
4705 (let* ((outer (floor (sqrt len)))
4706 (inner (/ len outer))
4707 (rest (% len outer))
4709 (setq menu (reverse menu))
4716 sub (cons (car menu) sub)
4719 (cons (cons (if (stringp LaTeX-submenu-name-format)
4720 (format LaTeX-submenu-name-format
4721 (aref (car sub) 0) (aref to 0))
4722 (funcall LaTeX-submenu-name-format
4723 (aref (car sub) 0) (aref to 0)))
4727 (if (= rest outer) (setq inner (1+ inner)))))
4730 (defvar LaTeX-section-menu nil)
4731 (make-variable-buffer-local 'LaTeX-section-menu)
4732 (defun LaTeX-section-menu-filter (ignored)
4733 "Filter function for the section submenu in the mode menu.
4734 The argument IGNORED is not used in any way."
4736 (or LaTeX-section-menu
4738 (setq LaTeX-section-list-changed nil)
4739 (mapc 'LaTeX-section-enable LaTeX-section-list)
4740 (setq LaTeX-section-menu
4741 (mapcar 'LaTeX-section-menu-entry LaTeX-section-list)))))
4743 (defvar LaTeX-environment-menu nil)
4744 (make-variable-buffer-local 'LaTeX-environment-menu)
4745 (defvar LaTeX-environment-modify-menu nil)
4746 (make-variable-buffer-local 'LaTeX-environment-modify-menu)
4747 (defun LaTeX-environment-menu-filter (menu)
4748 "Filter function for the environment submenus in the mode menu.
4749 The argument MENU is the name of the submenu in concern and
4750 corresponds to the variables `LaTeX-environment-menu-name' and
4751 `LaTeX-environment-modify-menu-name'."
4754 ((string= menu LaTeX-environment-menu-name)
4755 (or LaTeX-environment-menu
4756 (setq LaTeX-environment-menu
4757 (LaTeX-split-long-menu
4758 (mapcar 'LaTeX-environment-menu-entry
4759 (LaTeX-environment-list))))))
4760 ((string= menu LaTeX-environment-modify-menu-name)
4761 (or LaTeX-environment-modify-menu
4762 (setq LaTeX-environment-modify-menu
4763 (LaTeX-split-long-menu
4764 (mapcar 'LaTeX-environment-modify-menu-entry
4765 (LaTeX-environment-list))))))))
4767 (easy-menu-define LaTeX-mode-command-menu
4769 "Command menu used in LaTeX mode."
4770 (TeX-mode-specific-command-menu 'latex-mode))
4772 (easy-menu-define LaTeX-mode-menu
4774 "Menu used in LaTeX mode."
4777 ("Section (C-c C-s)" :filter LaTeX-section-menu-filter)
4778 ["Macro..." TeX-insert-macro
4779 :help "Insert a macro and possibly arguments"]
4780 ["Complete Macro" TeX-complete-symbol
4781 :help "Complete the current macro or environment name"]
4782 ,(list LaTeX-environment-menu-name
4783 :filter (lambda (ignored) (LaTeX-environment-menu-filter
4784 LaTeX-environment-menu-name)))
4785 ,(list LaTeX-environment-modify-menu-name
4786 :filter (lambda (ignored) (LaTeX-environment-menu-filter
4787 LaTeX-environment-modify-menu-name)))
4788 ["Close Environment" LaTeX-close-environment
4789 :help "Insert the \\end part of the current environment"]
4790 ["Item" LaTeX-insert-item
4791 :help "Insert a new \\item into current environment"]
4794 ["Emphasize" (TeX-font nil ?\C-e) :keys "C-c C-f C-e"]
4795 ["Bold" (TeX-font nil ?\C-b) :keys "C-c C-f C-b"]
4796 ["Typewriter" (TeX-font nil ?\C-t) :keys "C-c C-f C-t"]
4797 ["Small Caps" (TeX-font nil ?\C-c) :keys "C-c C-f C-c"]
4798 ["Sans Serif" (TeX-font nil ?\C-f) :keys "C-c C-f C-f"]
4799 ["Italic" (TeX-font nil ?\C-i) :keys "C-c C-f C-i"]
4800 ["Slanted" (TeX-font nil ?\C-s) :keys "C-c C-f C-s"]
4801 ["Roman" (TeX-font nil ?\C-r) :keys "C-c C-f C-r"]
4802 ["Calligraphic" (TeX-font nil ?\C-a) :keys "C-c C-f C-a"])
4804 ["Emphasize" (TeX-font t ?\C-e) :keys "C-u C-c C-f C-e"]
4805 ["Bold" (TeX-font t ?\C-b) :keys "C-u C-c C-f C-b"]
4806 ["Typewriter" (TeX-font t ?\C-t) :keys "C-u C-c C-f C-t"]
4807 ["Small Caps" (TeX-font t ?\C-c) :keys "C-u C-c C-f C-c"]
4808 ["Sans Serif" (TeX-font t ?\C-f) :keys "C-u C-c C-f C-f"]
4809 ["Italic" (TeX-font t ?\C-i) :keys "C-u C-c C-f C-i"]
4810 ["Slanted" (TeX-font t ?\C-s) :keys "C-u C-c C-f C-s"]
4811 ["Roman" (TeX-font t ?\C-r) :keys "C-u C-c C-f C-r"]
4812 ["Calligraphic" (TeX-font t ?\C-a) :keys "C-u C-c C-f C-a"])
4813 ["Delete Font" (TeX-font t ?\C-d) :keys "C-c C-f C-d"]
4815 ["Comment or Uncomment Region"
4816 TeX-comment-or-uncomment-region
4817 :help "Make the selected region outcommented or active again"]
4818 ["Comment or Uncomment Paragraph"
4819 TeX-comment-or-uncomment-paragraph
4820 :help "Make the current paragraph outcommented or active again"]
4821 ("Formatting and Marking"
4822 ["Format Environment" LaTeX-fill-environment
4823 :help "Fill and indent the current environment"]
4824 ["Format Paragraph" LaTeX-fill-paragraph
4825 :help "Fill and ident the current paragraph"]
4826 ["Format Region" LaTeX-fill-region
4827 :help "Fill and indent the currently selected region"]
4828 ["Format Section" LaTeX-fill-section
4829 :help "Fill and indent the current section"]
4831 ["Mark Environment" LaTeX-mark-environment
4832 :help "Mark the current environment"]
4833 ["Mark Section" LaTeX-mark-section
4834 :help "Mark the current section"]
4836 ["Beginning of Environment" LaTeX-find-matching-begin
4837 :help "Move point to the beginning of the current environment"]
4838 ["End of Environment" LaTeX-find-matching-end
4839 :help "Move point to the end of the current environment"])
4841 ["Math Mode" LaTeX-math-mode
4842 :style toggle :selected LaTeX-math-mode
4843 :help "Toggle math mode"]
4845 [ "Convert 209 to 2e" LaTeX-209-to-2e
4846 :visible (member "latex2" (TeX-style-list)) ]
4847 . ,TeX-common-menu-entries)))
4849 (defcustom LaTeX-font-list
4850 '((?\C-a "" "" "\\mathcal{" "}")
4851 (?\C-b "\\textbf{" "}" "\\mathbf{" "}")
4852 (?\C-c "\\textsc{" "}")
4853 (?\C-e "\\emph{" "}")
4854 (?\C-f "\\textsf{" "}" "\\mathsf{" "}")
4855 (?\C-i "\\textit{" "}" "\\mathit{" "}")
4856 (?\C-m "\\textmd{" "}")
4857 (?\C-n "\\textnormal{" "}" "\\mathnormal{" "}")
4858 (?\C-r "\\textrm{" "}" "\\mathrm{" "}")
4859 (?\C-s "\\textsl{" "}" "\\mathbb{" "}")
4860 (?\C-t "\\texttt{" "}" "\\mathtt{" "}")
4861 (?\C-u "\\textup{" "}")
4863 "Font commands used with LaTeX2e. See `TeX-font-list'."
4867 :value (?\C-a "" "")
4868 (character :tag "Key")
4869 (string :tag "Prefix")
4870 (string :tag "Suffix")
4873 (string :tag "Math Prefix")
4874 (string :tag "Math Suffix")))
4875 (option (sexp :format "Replace\n" :value t)))))
4880 (defcustom LaTeX-babel-hyphen "\"="
4881 "String to be used when typing `-'.
4882 This usually is a hyphen alternative or hyphenation aid, like
4883 \"=, \"~ or \"-, provided by babel and the related language style
4886 Set it to an empty string or nil in order to disable this
4887 feature. Alter `LaTeX-babel-hyphen-language-alist' in case you
4888 want to change the behavior for a specific language only."
4892 (defcustom LaTeX-babel-hyphen-after-hyphen t
4893 "Control insertion of hyphen strings.
4894 If non-nil insert normal hyphen on first key press and swap it
4895 with the language-specific hyphen string specified in the
4896 variable `LaTeX-babel-hyphen' on second key press. If nil do it
4897 the other way round."
4901 (defcustom LaTeX-babel-hyphen-language-alist nil
4902 "Alist controlling hyphen insertion for specific languages.
4903 It may be used to override the defaults given by `LaTeX-babel-hyphen'
4904 and `LaTeX-babel-hyphen-after-hyphen' respectively. The first item
4905 in each element is a string specifying the language as set by the
4906 language-specific style file. The second item is the string to be
4907 used instead of `LaTeX-babel-hyphen'. The third element is the
4908 value overriding `LaTeX-bybel-hyphen-after-hyphen'."
4910 :type '(alist :key-type (string :tag "Language")
4911 :value-type (group (string :tag "Hyphen string")
4912 (boolean :tag "Insert plain hyphen first"
4915 (defvar LaTeX-babel-hyphen-language nil
4916 "String determining language-specific behavior of hyphen insertion.
4917 It serves as an indicator that the babel hyphenation string
4918 should be used and as a means to find a potential customization
4919 in `LaTeX-babel-hyphen-language-alist' related to the active
4920 language. It is usually set by language-related style files.")
4921 (make-variable-buffer-local 'LaTeX-babel-hyphen-language)
4923 (defun LaTeX-babel-insert-hyphen (force)
4924 "Insert a hyphen string.
4925 The string can be either a normal hyphen or the string specified
4926 in `LaTeX-babel-hyphen'. Wether one or the other is chosen
4927 depends on the value of `LaTeX-babel-hyphen-after-hyphen' and
4929 If prefix argument FORCE is non-nil, always insert a regular hyphen."
4932 (zerop (length LaTeX-babel-hyphen))
4933 (not LaTeX-babel-hyphen-language)
4934 ;; FIXME: It would be nice to check for verbatim constructs in the
4935 ;; non-font-locking case, but things like `LaTeX-current-environment'
4936 ;; are rather expensive in large buffers.
4937 (and (fboundp 'font-latex-faces-present-p)
4938 (font-latex-faces-present-p '(font-latex-verbatim-face
4939 font-latex-math-face
4940 font-lock-comment-face)))
4943 (call-interactively 'self-insert-command)
4944 (let* ((lang (assoc LaTeX-babel-hyphen-language
4945 LaTeX-babel-hyphen-language-alist))
4946 (hyphen (if lang (nth 1 lang) LaTeX-babel-hyphen))
4947 (h-after-h (if lang (nth 2 lang) LaTeX-babel-hyphen-after-hyphen))
4948 (hyphen-length (length hyphen)))
4951 ((string= (buffer-substring (max (- (point) hyphen-length) (point-min))
4955 (progn (delete-backward-char hyphen-length)
4957 (delete-backward-char hyphen-length)
4958 (call-interactively 'self-insert-command)))
4960 ((string= (buffer-substring (max (- (point) 2) (point-min))
4963 (call-interactively 'self-insert-command))
4965 ((eq (char-before) ?-)
4967 (progn (delete-backward-char 1)
4969 (call-interactively 'self-insert-command)))
4971 (call-interactively 'self-insert-command))
4972 (t (insert hyphen))))))
4973 ;; Cater for Delete Selection mode
4974 (put 'LaTeX-babel-insert-hyphen 'delete-selection t)
4976 (defcustom LaTeX-enable-toolbar t
4977 "Enable LaTeX tool bar."
4978 :group 'TeX-tool-bar
4981 (defun LaTeX-maybe-install-toolbar ()
4982 "Conditionally install tool bar buttons for LaTeX mode.
4983 Install tool bar if `LaTeX-enable-toolbar' is non-nil."
4984 (when LaTeX-enable-toolbar
4985 ;; Defined in `tex-bar.el':
4986 (LaTeX-install-toolbar)))
4990 (defgroup LaTeX-macro nil
4991 "Special support for LaTeX macros in AUCTeX."
4996 (defcustom TeX-arg-cite-note-p nil
4997 "*If non-nil, ask for optional note in citations."
4999 :group 'LaTeX-macro)
5001 (defcustom TeX-arg-footnote-number-p nil
5002 "*If non-nil, ask for optional number in footnotes."
5004 :group 'LaTeX-macro)
5006 (defcustom TeX-arg-item-label-p nil
5007 "*If non-nil, always ask for optional label in items.
5008 Otherwise, only ask in description environments."
5010 :group 'LaTeX-macro)
5012 (defcustom TeX-arg-right-insert-p t
5013 "*If non-nil, always insert automatically the corresponding \\right.
5014 This happens when \\left is inserted."
5016 :group 'LaTeX-macro)
5018 (defcustom LaTeX-mode-hook nil
5019 "A hook run in LaTeX mode buffers."
5023 (TeX-abbrev-mode-setup latex-mode)
5026 (add-to-list 'auto-mode-alist '("\\.drv\\'" . latex-mode))
5029 (defun TeX-latex-mode ()
5030 "Major mode in AUCTeX for editing LaTeX files.
5031 See info under AUCTeX for full documentation.
5036 Entering LaTeX mode calls the value of `text-mode-hook',
5037 then the value of `TeX-mode-hook', and then the value
5038 of `LaTeX-mode-hook'."
5040 (LaTeX-common-initialization)
5041 (setq TeX-base-mode-name "LaTeX")
5042 (setq major-mode 'latex-mode)
5043 (setq TeX-command-default "LaTeX")
5044 (setq TeX-sentinel-default-function 'TeX-LaTeX-sentinel)
5045 (add-hook 'tool-bar-mode-on-hook 'LaTeX-maybe-install-toolbar nil t)
5046 (when (if (featurep 'xemacs)
5048 (and (boundp 'tool-bar-mode) tool-bar-mode))
5049 (LaTeX-maybe-install-toolbar))
5050 (TeX-run-mode-hooks 'text-mode-hook 'TeX-mode-hook 'LaTeX-mode-hook)
5053 (if (and (boundp 'filladapt-mode)
5055 (turn-off-filladapt-mode)))
5057 (TeX-abbrev-mode-setup doctex-mode)
5060 (add-to-list 'auto-mode-alist '("\\.dtx\\'" . doctex-mode))
5063 (define-derived-mode docTeX-mode TeX-latex-mode "docTeX"
5064 "Major mode in AUCTeX for editing .dtx files derived from `LaTeX-mode'.
5065 Runs `LaTeX-mode', sets a few variables and
5066 runs the hooks in `docTeX-mode-hook'."
5067 :abbrev-table doctex-mode-abbrev-table
5068 (setq major-mode 'doctex-mode)
5069 (set (make-local-variable 'LaTeX-insert-into-comments) t)
5070 (set (make-local-variable 'LaTeX-syntactic-comments) t)
5071 (setq TeX-default-extension docTeX-default-extension)
5072 ;; Make filling and indentation aware of DocStrip guards.
5073 (setq paragraph-start (concat paragraph-start "\\|%<")
5074 paragraph-separate (concat paragraph-separate "\\|%<")
5075 TeX-comment-start-regexp "\\(?:%\\(?:<[^>]+>\\)?\\)")
5076 (setq TeX-base-mode-name "docTeX")
5078 (funcall TeX-install-font-lock))
5080 ;;This is actually a mess: to fit the scheme properly, our derived
5081 ;;mode definition would have had to be made for TeX-doctex-mode in the
5082 ;;first place, but then we could not have used define-derived-mode, or
5083 ;;all mode-specific variables would have gotten non-AUCTeX names.
5084 ;;This solution has the advantage that documentation strings are
5085 ;;provided in the autoloads, and has the disadvantage that docTeX-mode
5086 ;;is not aliased to doctex-mode (not even when the AUCTeX version is
5087 ;;disabled) as would be normal for our scheme.
5090 (defalias 'TeX-doctex-mode 'docTeX-mode)
5092 (defcustom docTeX-clean-intermediate-suffixes
5093 TeX-clean-default-intermediate-suffixes
5094 "List of regexps matching suffixes of files to be deleted.
5095 The regexps will be anchored at the end of the file name to be matched,
5096 i.e. you do _not_ have to cater for this yourself by adding \\\\' or $."
5097 :type '(repeat regexp)
5098 :group 'TeX-command)
5100 (defcustom docTeX-clean-output-suffixes TeX-clean-default-output-suffixes
5101 "List of regexps matching suffixes of files to be deleted.
5102 The regexps will be anchored at the end of the file name to be matched,
5103 i.e. you do _not_ have to cater for this yourself by adding \\\\' or $."
5104 :type '(repeat regexp)
5105 :group 'TeX-command)
5107 (defvar LaTeX-header-end
5108 (concat "^[^%\n]*" (regexp-quote TeX-esc) "begin *"
5109 TeX-grop "document" TeX-grcl)
5110 "Default end of header marker for LaTeX documents.")
5112 (defvar LaTeX-trailer-start
5113 (concat "^[^%\n]*" (regexp-quote TeX-esc) "end *"
5114 TeX-grop "document" TeX-grcl)
5115 "Default start of trailer marker for LaTeX documents.")
5117 (defcustom LaTeX-clean-intermediate-suffixes
5118 TeX-clean-default-intermediate-suffixes
5119 "List of regexps matching suffixes of files to be deleted.
5120 The regexps will be anchored at the end of the file name to be matched,
5121 i.e. you do _not_ have to cater for this yourself by adding \\\\' or $."
5122 :type '(repeat regexp)
5123 :group 'TeX-command)
5125 (defcustom LaTeX-clean-output-suffixes TeX-clean-default-output-suffixes
5126 "List of regexps matching suffixes of files to be deleted.
5127 The regexps will be anchored at the end of the file name to be matched,
5128 i.e. you do _not_ have to cater for this yourself by adding \\\\' or $."
5129 :type '(repeat regexp)
5130 :group 'TeX-command)
5132 (defun LaTeX-common-initialization ()
5133 "Common initialization for LaTeX derived modes."
5134 (VirTeX-common-initialization)
5135 (set-syntax-table LaTeX-mode-syntax-table)
5136 (make-local-variable 'indent-line-function)
5137 (setq indent-line-function 'LaTeX-indent-line)
5139 (setq local-abbrev-table latex-mode-abbrev-table)
5142 (make-local-variable 'paragraph-ignore-fill-prefix)
5143 (setq paragraph-ignore-fill-prefix t)
5144 (make-local-variable 'fill-paragraph-function)
5145 (setq fill-paragraph-function 'LaTeX-fill-paragraph)
5146 (make-local-variable 'adaptive-fill-mode)
5147 (setq adaptive-fill-mode nil)
5149 (or LaTeX-largest-level
5150 (setq LaTeX-largest-level (LaTeX-section-level "section")))
5152 (setq TeX-header-end LaTeX-header-end
5153 TeX-trailer-start LaTeX-trailer-start)
5156 (make-local-variable 'outline-level)
5157 (setq outline-level 'LaTeX-outline-level)
5158 (make-local-variable 'outline-regexp)
5159 (setq outline-regexp (LaTeX-outline-regexp t))
5160 (when (boundp 'outline-heading-alist)
5161 (setq outline-heading-alist
5163 (cons (concat "\\" (nth 0 x)) (nth 1 x)))
5164 LaTeX-section-list)))
5166 (make-local-variable 'TeX-auto-full-regexp-list)
5167 (setq TeX-auto-full-regexp-list
5168 (append LaTeX-auto-regexp-list plain-TeX-auto-regexp-list))
5170 (LaTeX-set-paragraph-start)
5171 (setq paragraph-separate
5174 "\\$\\$" ; Plain TeX display math
5177 (setq TeX-verbatim-p-function 'LaTeX-verbatim-p)
5178 (setq TeX-search-forward-comment-start-function
5179 'LaTeX-search-forward-comment-start)
5180 (set (make-local-variable 'TeX-search-files-type-alist)
5181 LaTeX-search-files-type-alist)
5183 (make-local-variable 'LaTeX-item-list)
5184 (setq LaTeX-item-list '(("description" . LaTeX-item-argument)
5185 ("thebibliography" . LaTeX-item-bib)))
5187 (setq TeX-complete-list
5188 (append '(("\\\\cite\\[[^]\n\r\\%]*\\]{\\([^{}\n\r\\%,]*\\)"
5189 1 LaTeX-bibitem-list "}")
5190 ("\\\\cite{\\([^{}\n\r\\%,]*\\)" 1 LaTeX-bibitem-list "}")
5191 ("\\\\cite{\\([^{}\n\r\\%]*,\\)\\([^{}\n\r\\%,]*\\)"
5192 2 LaTeX-bibitem-list)
5193 ("\\\\nocite{\\([^{}\n\r\\%,]*\\)" 1 LaTeX-bibitem-list "}")
5194 ("\\\\nocite{\\([^{}\n\r\\%]*,\\)\\([^{}\n\r\\%,]*\\)"
5195 2 LaTeX-bibitem-list)
5196 ("\\\\ref{\\([^{}\n\r\\%,]*\\)" 1 LaTeX-label-list "}")
5197 ("\\\\eqref{\\([^{}\n\r\\%,]*\\)" 1 LaTeX-label-list "}")
5198 ("\\\\pageref{\\([^{}\n\r\\%,]*\\)" 1 LaTeX-label-list "}")
5199 ("\\\\\\(index\\|glossary\\){\\([^{}\n\r\\%]*\\)"
5200 2 LaTeX-index-entry-list "}")
5201 ("\\\\begin{\\([A-Za-z]*\\)" 1 LaTeX-environment-list "}")
5202 ("\\\\end{\\([A-Za-z]*\\)" 1 LaTeX-environment-list "}")
5203 ("\\\\renewcommand\\*?{\\\\\\([A-Za-z]*\\)"
5204 1 LaTeX-symbol-list "}")
5205 ("\\\\renewenvironment\\*?{\\([A-Za-z]*\\)"
5206 1 LaTeX-environment-list "}"))
5209 (LaTeX-add-environments
5210 '("document" LaTeX-env-document)
5211 '("enumerate" LaTeX-env-item)
5212 '("itemize" LaTeX-env-item)
5213 '("list" LaTeX-env-list)
5214 '("trivlist" LaTeX-env-item)
5215 '("picture" LaTeX-env-picture)
5216 '("tabular" LaTeX-env-array)
5217 '("tabular*" LaTeX-env-tabular*)
5218 '("array" LaTeX-env-array)
5219 '("eqnarray" LaTeX-env-label)
5220 '("equation" LaTeX-env-label)
5221 '("minipage" LaTeX-env-minipage)
5223 ;; The following have no special support, but are included in
5224 ;; case the auto files are missing.
5226 "sloppypar" "picture" "tabbing" "verbatim" "verbatim*"
5227 "flushright" "flushleft" "displaymath" "math" "quote" "quotation"
5228 "abstract" "center" "titlepage" "verse" "eqnarray*"
5230 ;; The following are not defined in latex.el, but in a number of
5231 ;; other style files. I'm to lazy to copy them to all the
5232 ;; corresponding .el files right now.
5234 ;; This means that AUCTeX will complete e.g.
5235 ;; ``thebibliography'' in a letter, but I guess we can live with
5238 '("description" LaTeX-env-item)
5239 '("figure" LaTeX-env-figure)
5240 '("figure*" LaTeX-env-figure)
5241 '("table" LaTeX-env-figure)
5242 '("table*" LaTeX-env-figure)
5243 '("thebibliography" LaTeX-env-bib)
5244 '("theindex" LaTeX-env-item))
5247 '("addtocounter" TeX-arg-counter "Value")
5248 '("alph" TeX-arg-counter)
5249 '("arabic" TeX-arg-counter)
5250 '("fnsymbol" TeX-arg-counter)
5251 '("newcounter" TeX-arg-define-counter
5252 [ TeX-arg-counter "Within counter" ])
5253 '("roman" TeX-arg-counter)
5254 '("setcounter" TeX-arg-counter "Value")
5255 '("usecounter" TeX-arg-counter)
5256 '("value" TeX-arg-counter)
5257 '("stepcounter" TeX-arg-counter)
5258 '("refstepcounter" TeX-arg-counter)
5259 '("label" TeX-arg-define-label)
5260 '("pageref" TeX-arg-ref)
5261 '("ref" TeX-arg-ref)
5262 '("newcommand" TeX-arg-define-macro [ "Number of arguments" ] t)
5263 '("renewcommand" TeX-arg-macro [ "Number of arguments" ] t)
5264 '("newenvironment" TeX-arg-define-environment
5265 [ "Number of arguments"] t t)
5266 '("renewenvironment" TeX-arg-environment
5267 [ "Number of arguments"] t t)
5268 '("providecommand" TeX-arg-define-macro [ "Number of arguments" ] t)
5269 '("providecommand*" TeX-arg-define-macro [ "Number of arguments" ] t)
5270 '("newcommand*" TeX-arg-define-macro [ "Number of arguments" ] t)
5271 '("renewcommand*" TeX-arg-macro [ "Number of arguments" ] t)
5272 '("newenvironment*" TeX-arg-define-environment
5273 [ "Number of arguments"] t t)
5274 '("renewenvironment*" TeX-arg-environment
5275 [ "Number of arguments"] t t)
5276 '("newtheorem" TeX-arg-define-environment
5277 [ TeX-arg-environment "Numbered like" ]
5278 t [ (TeX-arg-eval progn (if (eq (save-excursion
5280 (preceding-char)) ?\])
5282 (TeX-arg-counter t "Within counter"))
5284 '("newfont" TeX-arg-define-macro t)
5285 '("circle" "Diameter")
5286 '("circle*" "Diameter")
5287 '("dashbox" "Dash Length" TeX-arg-size
5288 [ TeX-arg-corner ] t)
5290 '("framebox" (TeX-arg-conditional
5291 (string-equal (LaTeX-current-environment) "picture")
5292 (TeX-arg-size [ TeX-arg-corner ] t)
5293 ([ "Length" ] [ TeX-arg-lr ] t)))
5294 '("line" (TeX-arg-pair "X slope" "Y slope") "Length")
5295 '("linethickness" "Dimension")
5296 '("makebox" (TeX-arg-conditional
5297 (string-equal (LaTeX-current-environment) "picture")
5298 (TeX-arg-size [ TeX-arg-corner ] t)
5299 ([ "Length" ] [ TeX-arg-lr ] t)))
5302 (TeX-arg-pair "X delta" "Y delta")
5305 '("oval" TeX-arg-size [ TeX-arg-corner "Portion" ])
5306 '("put" TeX-arg-coordinate t)
5307 '("savebox" TeX-arg-savebox
5308 (TeX-arg-conditional
5309 (string-equal (LaTeX-current-environment) "picture")
5310 (TeX-arg-size [ TeX-arg-corner ] t)
5311 ([ "Length" ] [ TeX-arg-lr ] t)))
5312 '("shortstack" [ TeX-arg-lr ] t)
5313 '("vector" (TeX-arg-pair "X slope" "Y slope") "Length")
5314 '("cline" "Span `i-j'")
5315 '("multicolumn" "Columns" "Format" t)
5317 (TeX-arg-conditional (or TeX-arg-item-label-p
5318 (string-equal (LaTeX-current-environment)
5322 (TeX-arg-literal " "))
5323 '("bibitem" [ "Bibitem label" ] TeX-arg-define-cite)
5325 (TeX-arg-conditional TeX-arg-cite-note-p ([ "Note" ]) ())
5327 '("nocite" TeX-arg-cite)
5328 '("bibliographystyle" TeX-arg-bibstyle)
5329 '("bibliography" TeX-arg-bibliography)
5330 '("addbibresource" TeX-arg-bibliography)
5332 (TeX-arg-conditional TeX-arg-footnote-number-p ([ "Number" ]) nil)
5335 (TeX-arg-conditional TeX-arg-footnote-number-p ([ "Number" ]) nil)
5338 (TeX-arg-conditional TeX-arg-footnote-number-p ([ "Number" ]) nil))
5339 '("newlength" TeX-arg-define-macro)
5340 '("setlength" TeX-arg-macro "Length")
5341 '("addtolength" TeX-arg-macro "Length")
5342 '("settowidth" TeX-arg-macro t)
5343 '("settoheight" TeX-arg-macro t)
5344 '("settodepth" TeX-arg-macro t)
5346 '("\\*" [ "Space" ])
5348 '("linebreak" [ "How much [0 - 4]" ])
5349 '("nolinebreak" [ "How much [0 - 4]" ])
5350 '("nopagebreak" [ "How much [0 - 4]" ])
5351 '("pagebreak" [ "How much [0 - 4]" ])
5357 '("overleftarrow" t)
5358 '("overrightarrow" t)
5359 '("sqrt" [ "Root" ] t)
5366 '("pagenumbering" (TeX-arg-eval
5367 completing-read "Numbering style: "
5368 '(("arabic") ("roman") ("Roman") ("alph") ("Alph"))))
5369 '("pagestyle" TeX-arg-pagestyle)
5372 '("thispagestyle" TeX-arg-pagestyle)
5373 '("addvspace" "Length")
5375 '("hspace*" "Length")
5376 '("hspace" "Length")
5378 '("newsavebox" TeX-arg-define-savebox)
5379 '("parbox" [ TeX-arg-tb ] [ "Height" ] [ TeX-arg-tb "Inner position" ]
5381 '("raisebox" "Raise" [ "Height above" ] [ "Depth below" ] t)
5382 '("rule" [ "Raise" ] "Width" "Thickness")
5383 '("sbox" TeX-arg-savebox t)
5384 '("usebox" TeX-arg-savebox)
5385 '("vspace*" "Length")
5386 '("vspace" "Length")
5387 '("documentstyle" TeX-arg-document)
5388 '("include" (TeX-arg-input-file "File" t))
5390 '("input" TeX-arg-input-file)
5392 (TeX-arg-eval completing-read "File: " '(("toc") ("lof") ("lot")))
5393 (TeX-arg-eval completing-read "Numbering style: " LaTeX-section-list) t)
5395 (TeX-arg-eval completing-read "File: " '(("toc") ("lof") ("lot"))) t)
5397 '("typein" [ TeX-arg-define-macro ] t)
5398 '("verb" TeX-arg-verb)
5399 '("verb*" TeX-arg-verb)
5401 '("index" TeX-arg-index)
5402 '("glossary" TeX-arg-index)
5403 '("numberline" "Section number" "Heading")
5405 '("marginpar" [ "Left margin text" ] "Text")
5406 '("left" TeX-arg-insert-braces)
5408 ;; These have no special support, but are included in case the
5409 ;; auto files are missing.
5412 "samepage" "newline"
5413 "smallskip" "medskip" "bigskip" "fill" "stretch"
5414 "thinspace" "negthinspace" "enspace" "enskip" "quad" "qquad"
5415 "nonumber" "centering" "raggedright"
5416 "raggedleft" "kill" "pushtabs" "poptabs" "protect" "arraystretch"
5417 "hline" "vline" "cline" "thinlines" "thicklines" "and" "makeindex"
5418 "makeglossary" "reversemarginpar" "normalmarginpar"
5419 "raggedbottom" "flushbottom" "sloppy" "fussy" "newpage"
5420 "clearpage" "cleardoublepage" "twocolumn" "onecolumn"
5422 "maketitle" "tableofcontents" "listoffigures" "listoftables"
5423 '("tiny" -1) '("scriptsize" -1) '("footnotesize" -1) '("small" -1)
5424 '("normalsize" -1) '("large" -1) '("Large" -1) '("LARGE" -1) '("huge" -1)
5426 "pounds" "copyright"
5427 "hfil" "hfill" "vfil" "vfill" "hrulefill" "dotfill"
5428 "indent" "noindent" "today"
5432 (when (string-equal LaTeX-version "2e")
5433 (LaTeX-add-environments
5434 '("filecontents" LaTeX-env-contents)
5435 '("filecontents*" LaTeX-env-contents))
5438 '("enlargethispage" "Length")
5439 '("enlargethispage*" "Length")
5440 '("tabularnewline" [ "Length" ])
5441 '("suppressfloats" [ TeX-arg-tb "Suppress floats position" ])
5442 '("ensuremath" "Math commands")
5443 '("textsuperscript" "Text")
5444 '("textcircled" "Text")
5447 "listfiles" "frontmatter" "mainmatter" "backmatter"
5448 "textcompwordmark" "textvisiblespace" "textemdash" "textendash"
5449 "textexclamdown" "textquestiondown" "textquotedblleft"
5450 "textquotedblright" "textquoteleft" "textquoteright"
5451 "textbullet" "textperiodcentered"
5452 "textbackslash" "textbar" "textless" "textgreater"
5453 "textasciicircum" "textasciitilde"
5454 "textregistered" "texttrademark"
5455 "rmfamily" "sffamily" "ttfamily" "mdseries" "bfseries"
5456 "itshape" "slshape" "upshape" "scshape"))
5458 (TeX-run-style-hooks "LATEX")
5460 (make-local-variable 'TeX-font-list)
5461 (make-local-variable 'TeX-font-replace-function)
5462 (if (string-equal LaTeX-version "2")
5464 (setq TeX-font-list LaTeX-font-list)
5465 (setq TeX-font-replace-function 'TeX-font-replace-macro)
5467 '("newcommand" TeX-arg-define-macro
5468 [ "Number of arguments" ] [ "Default value for first argument" ] t)
5469 '("renewcommand" TeX-arg-macro
5470 [ "Number of arguments" ] [ "Default value for first argument" ] t)
5471 '("providecommand" TeX-arg-define-macro
5472 [ "Number of arguments" ] [ "Default value for first argument" ] t)
5473 '("providecommand*" TeX-arg-define-macro
5474 [ "Number of arguments" ] [ "Default value for first argument" ] t)
5475 '("newcommand*" TeX-arg-define-macro
5476 [ "Number of arguments" ] [ "Default value for first argument" ] t)
5477 '("renewcommand*" TeX-arg-macro
5478 [ "Number of arguments" ] [ "Default value for first argument" ] t)
5479 '("usepackage" LaTeX-arg-usepackage)
5480 '("RequirePackage" LaTeX-arg-usepackage)
5481 '("ProvidesPackage" "Name" [ "Version" ])
5482 '("documentclass" TeX-arg-document)))
5484 (TeX-add-style-hook "latex2e"
5485 ;; Use new fonts for `\documentclass' documents.
5487 (setq TeX-font-list LaTeX-font-list)
5488 (setq TeX-font-replace-function 'TeX-font-replace-macro)
5489 (run-hooks 'LaTeX2e-hook)))
5491 (TeX-add-style-hook "latex2"
5492 ;; Use old fonts for `\documentstyle' documents.
5494 (setq TeX-font-list (default-value 'TeX-font-list))
5495 (setq TeX-font-replace-function
5496 (default-value 'TeX-font-replace-function))
5497 (run-hooks 'LaTeX2-hook)))
5499 ;; There must be something better-suited, but I don't understand the
5500 ;; parsing properly. -- dak
5501 (TeX-add-style-hook "pdftex" 'TeX-PDF-mode-on)
5502 (TeX-add-style-hook "pdftricks" 'TeX-PDF-mode-on)
5503 (TeX-add-style-hook "pst-pdf" 'TeX-PDF-mode-on)
5504 (TeX-add-style-hook "dvips" 'TeX-PDF-mode-off)
5505 ;; This is now done in style/pstricks.el because it prevents other
5506 ;; pstricks style files from being loaded.
5507 ;; (TeX-add-style-hook "pstricks" 'TeX-PDF-mode-off)
5508 (TeX-add-style-hook "psfrag" 'TeX-PDF-mode-off)
5509 (TeX-add-style-hook "dvipdf" 'TeX-PDF-mode-off)
5510 (TeX-add-style-hook "dvipdfm" 'TeX-PDF-mode-off)
5511 ;; (TeX-add-style-hook "DVIoutput" 'TeX-PDF-mode-off)
5513 ;; Well, DVIoutput indicates that we want to run PDFTeX and expect to
5514 ;; get DVI output. Ugh.
5515 (TeX-add-style-hook "ifpdf" (lambda ()
5517 (TeX-PDF-mode-off)))
5518 ;; ifpdf indicates that we cater for either. So calling both
5519 ;; functions will make sure that the default will get used unless the
5520 ;; user overrode it.
5522 (set (make-local-variable 'imenu-create-index-function)
5523 'LaTeX-imenu-create-index-function)
5525 (use-local-map LaTeX-mode-map)
5527 ;; Calling `easy-menu-add' may result in the menu filters being
5528 ;; executed which call `TeX-update-style'. So this is placed very
5529 ;; late in mode initialization to assure that all relevant variables
5530 ;; are properly initialized before style files try to alter them.
5531 (easy-menu-add LaTeX-mode-menu LaTeX-mode-map)
5532 (easy-menu-add LaTeX-mode-command-menu LaTeX-mode-map))
5534 (defun LaTeX-imenu-create-index-function ()
5535 "Imenu support function for LaTeX."
5538 (regexp (LaTeX-outline-regexp)))
5539 (goto-char (point-max))
5540 (while (re-search-backward regexp nil t)
5541 (let* ((name (LaTeX-outline-name))
5542 (level (make-string (1- (LaTeX-outline-level)) ?\ ))
5543 (label (concat level level name))
5544 (mark (make-marker)))
5545 (set-marker mark (point))
5546 (set-text-properties 0 (length label) nil label)
5547 (setq entries (cons (cons label mark) entries))))
5550 (defvar LaTeX-builtin-opts
5551 '("12pt" "11pt" "10pt" "twocolumn" "twoside" "draft")
5552 "Built in options for LaTeX standard styles.")
5554 (defun LaTeX-209-to-2e ()
5555 "Make a stab at changing 2.09 doc header to 2e style."
5558 (let (optstr optlist 2eoptlist 2epackages docline docstyle)
5559 (goto-char (point-min))
5561 (search-forward-regexp
5562 "\\documentstyle\\[\\([^]]*\\)\\]{\\([^}]*\\)}"
5564 (setq optstr (TeX-match-buffer 1)
5565 docstyle (TeX-match-buffer 2)
5566 optlist (TeX-split-string "," optstr))
5567 (if (search-forward-regexp
5568 "\\documentstyle{\\([^}]*\\)}"
5570 (setq docstyle (TeX-match-buffer 1))
5571 (error "No documentstyle defined")))
5572 (beginning-of-line 1)
5573 (setq docline (point))
5576 (if (member (car optlist) LaTeX-builtin-opts)
5577 (setq 2eoptlist (cons (car optlist) 2eoptlist))
5578 (setq 2epackages (cons (car optlist) 2epackages)))
5579 (setq optlist (cdr optlist)))
5580 ;;(message (format "%S %S" 2eoptlist 2epackages))
5583 (insert "\\documentclass")
5586 (mapconcat (lambda (x) x)
5587 (nreverse 2eoptlist) ",") "]"))
5588 (insert "{" docstyle "}\n")
5590 (insert "\\usepackage{"
5591 (mapconcat (lambda (x) x)
5592 (nreverse 2epackages) "}\n\\usepackage{") "}\n"))
5593 (if (equal docstyle "slides")
5595 (goto-char (point-min))
5596 (while (re-search-forward "\\\\blackandwhite{" nil t)
5597 (replace-match "\\\\input{" nil nil)))))
5598 (TeX-normal-mode nil))
5602 ;;; latex.el ends here