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