1 ;; reftex.el --- Minor mode for doing \label, \ref and \cite in LaTeX
3 ;; Copyright (c) 1997 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <dominik@strw.LeidenUniv.nl>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
25 ;;---------------------------------------------------------------------------
29 ;; RefTeX is a minor mode with distinct support for \ref, \label and
30 ;; \cite commands in (multi-file) LaTeX documents.
31 ;; Labels are created semi-automatically. Definition context of labels is
32 ;; provided when creating a reference. Citations are simplified with
33 ;; efficient database lookup.
35 ;; To turn RefTeX Minor Mode on and off in a particular buffer, use
38 ;; To turn on RefTeX Minor Mode for all LaTeX files, add one of the
39 ;; following lines to your .emacs file:
41 ;; (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode
42 ;; (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
44 ;; For key bindings, see further down in this documentation.
46 ;;---------------------------------------------------------------------------
50 ;; 1. USING \label AND \ref. Labels and references are one of the
51 ;; strong points of LaTeX. But, in documents with hundreds of
52 ;; equations, figures, tables etc. it becomes quickly impossible to
53 ;; find good label names and to actually remember them. Then, also
54 ;; completion of labels in not enough. One actually needs to see the
55 ;; context of the label definition to find the right one.
57 ;; - RefTeX distinguishes labels for different environments. It
58 ;; always knows if a certain label references a figure, table
59 ;; etc. You can configure RefTeX to recognize any additional
60 ;; labeled environments you might have defined yourself.
62 ;; - RefTeX defines automatically unique labels. Type `C-c ('
63 ;; (reftex-label) to insert a label at point. RefTeX will either
64 ;; - derive a label from context (default for section labels)
65 ;; - insert a simple label consisting of a prefix and a number
66 ;; (default for equations and enumerate items) or
67 ;; - prompt for a label string (figures and tables)
68 ;; Which labels are created how can be controlled with the variable
69 ;; reftex-insert-label-flags.
71 ;; - Referencing labels is a snap and I promise you'll love it.
72 ;; In order to make a reference, type `C-c )' (reftex-reference).
73 ;; This shows an outline of the documents with all labels of a
74 ;; certain type (figure, equation,...) and context of the label
75 ;; definition. Selecting one of the labels inserts a \ref macro
76 ;; into the original buffer. Online help during the selection is
77 ;; available with `?'.
79 ;; 2. CITATIONS. After typing `C-c [' (reftex-citation), RefTeX will
80 ;; let you specify a regexp to search in current BibTeX database files
81 ;; (as specified in the \bibliography command) and pull out a formatted
82 ;; list of matches for you to choose from. The list is *formatted* and
83 ;; thus much easier to read than the raw database entries. It can also
84 ;; be sorted. The text inserted into the buffer is by default just
85 ;; `\cite{KEY}', but can also contain author names and the year in a
86 ;; configurable way. See documentation of the variable
87 ;; reftex-cite-format.
89 ;; 3. TABLE OF CONTENTS. Typing `C-c =' (reftex-toc) will show
90 ;; a table of contents of the document. From that buffer, you can
91 ;; jump quickly to every part of your document. This is similar to
92 ;; imenu, only it works for entire multifile documents and uses the
93 ;; keyboard rather than the mouse. The initial version of this
94 ;; function was contributed by Stephen Eglen.
96 ;; 4. MULTIFILE DOCUMENTS are supported in the same way as by AUCTeX.
97 ;; I.e. if a source file is not a full LaTeX document by itself,
98 ;; but included by another file, you may specify the name of
99 ;; the (top level) master file in a local variable section at the
100 ;; end of the source file, like so:
102 ;; %%% Local Variables:
103 ;; %%% TeX-master: my_master.tex
106 ;; This will only take effect when you load the file next time or when
107 ;; you reset RefTeX with M-x reftex-reset-mode.
109 ;; RefTeX will also recognize the file variable tex-main-file. This
110 ;; variable is used by the Emacs TeX modes and works just like
111 ;; AUCTeX's TeX-master variable. See the documentation of your TeX/LaTeX
114 ;; RefTeX knows about all files related to a document via input and
115 ;; include. It provides functions to run regular expression searches and
116 ;; replaces over the entire document and to create a TAGS file.
118 ;; 5. DOCUMENT PARSING. RefTeX needs to parse the document in order to find
119 ;; labels and other information. It will do it automatically once, when
120 ;; you start working with a document. If you need to enforce reparsing
121 ;; later, call any of the functions reftex-citation, reftex-label,
122 ;; reftex-reference, reftex-toc with a raw C-u prefix.
124 ;;-------------------------------------------------------------------------
128 ;; RefTeX contains many configurable options which change the way it works.
130 ;; Most importantly, RefTeX needs to be configured if you use labels to
131 ;; mark non-standard environments. RefTeX always understands LaTeX section
132 ;; commands and the following environments: figure, figure*,
133 ;; sidewaysfigure, table, table*, sidewaystable, equation, eqnarray,
134 ;; enumerate. For everythings else, it needs to be configured.
136 ;; A good way to configure RefTeX is with the custom.el package by Per
137 ;; Abrahamsen, shipped with Emacs 20 and XEmacs 19.15. To do this, just
138 ;; say `M-x reftex-customize'. This will not work with older versions
141 ;; Here is a complete list of the RefTeX configuration variables with
142 ;; their default settings. You could copy this list to your .emacs file
143 ;; and change whatever is necessary. Each variable has an extensive
144 ;; documentation string. Look it up for more information!
146 ;; ;; Configuration Variables and User Options for RefTeX ------------------
147 ;; ;; Support for \label and \ref --------------------------------------
148 ;; (setq reftex-label-alist nil)
149 ;; (setq reftex-default-label-alist-entries '(Sideways LaTeX))
150 ;; (setq reftex-use-text-after-label-as-context nil)
151 ;; ;; Label insertion
152 ;; (setq reftex-insert-label-flags '("s" "sft"))
153 ;; (setq reftex-derive-label-parameters '(3 20 t 1 "-"
154 ;; ("the" "on" "in" "off" "a" "for" "by" "of" "and" "is")))
155 ;; (setq reftex-label-illegal-re "[\000-\040\177-\377\\\\#$%&~^_{}]")
156 ;; (setq reftex-abbrev-parameters '(4 2 "^saeiou" "aeiou"))
157 ;; ;; Label referencing
158 ;; (setq reftex-label-menu-flags '(t t nil nil nil nil))
159 ;; (setq reftex-guess-label-type t)
160 ;; ;; BibteX citation configuration ----------------------------------------
161 ;; (setq reftex-bibpath-environment-variables '("BIBINPUTS" "TEXBIB"))
162 ;; (setq reftex-bibfile-ignore-list nil)
163 ;; (setq reftex-sort-bibtex-matches 'reverse-year)
164 ;; (setq reftex-cite-format 'reftex-cite-format-default)
165 ;; ;; Table of contents configuration --------------------------------------
166 ;; (setq reftex-toc-follow-mode nil)
167 ;; ;; Miscellaneous configurations -----------------------------------------
168 ;; (setq reftex-extra-bindings nil)
169 ;; (setq reftex-use-fonts t)
170 ;; (setq reftex-keep-temporary-buffers t)
171 ;; (setq reftex-auto-show-entry t)
173 ;; CONFIGURATION EXAMPLES:
174 ;; =======================
176 ;; Suppose you are working with AMS-LaTeX amsmath package (with its math
177 ;; environments like `align', `multiline' etc.). Here is how you would
178 ;; configure RefTeX to recognize these environments:
180 ;; (setq reftex-label-alist '(AMSTeX))
182 ;; This is very easy since RefTeX has builtin support for AMS-LaTeX.
183 ;; Suppose, however, you are also
185 ;; - using "\newtheorem" in LaTeX in order to define two new environments
186 ;; "Theorem" and "Axiom" like this:
188 ;; \newtheorem{axiom}{Axiom}
189 ;; \newtheorem{theorem}{Theorem}
191 ;; - making your figures not directly with the figure environment, but with
194 ;; \newcommand{\myfig}[4][tbp]{
195 ;; \begin{figure}[#1]
200 ;; which would be called like
202 ;; \myfig{filename}{\label{fig:13} caption text}{1}
204 ;; Here is how to tell RefTeX to also recognize Theorem and Axiom as
205 ;; labeled environments, and that any labels defined inside the \myfig
206 ;; macro are figure labels:
208 ;; (setq reftex-label-alist
210 ;; ("axiom" ?a "ax:" "~\\ref{%s}" nil ("Axiom" "Ax."))
211 ;; ("theorem" ?h "thr:" "~\\ref{%s}" t ("Theorem" "Theor." "Th."))
212 ;; ("\\myfig" ?f "fig:" nil t)))
214 ;; The type indicator characters ?a and ?h are used for prompts when
215 ;; RefTeX queries for a label type. Note that "h" was chosen for "theorem"
216 ;; since "t" is already taken by "table". Note that also "s", "f", "e", "n"
217 ;; are taken by the standard environments.
218 ;; The automatic labels for Axioms and Theorems will look like "ax:23" or
220 ;; The "\ref{%s}" is a format string indicating how to insert references to
221 ;; these labels. The nil format in the \myfig entry means to use the same
222 ;; format as other figure labels.
223 ;; The next item indicates how to grab context of the label definition.
224 ;; - t means to get it from a default location (from the beginning of a \macro
225 ;; or after the \begin statement). t is *not* a good choice for eqnarray
226 ;; and similar environments.
227 ;; - nil means to use the text right after the label definition.
228 ;; - For more complex ways of getting context, see the docstring of
229 ;; reftex-label-alist.
230 ;; The strings at the end of each entry are used to guess the correct label
231 ;; type from the word before point when creating a reference. E.g. if you
232 ;; write: "as we have shown in Theorem" and then press `C-)', RefTeX will
233 ;; know that you are looking for a Theorem label and restrict the labels in
234 ;; the menu to only these labels without even asking.
235 ;; See also the documentation string of the variable reftex-label-alist.
237 ;; Depending on how you would like the label insertion and selection for the
238 ;; new environments to work, you might want to add the letters "a" and "h"
239 ;; to some of the flags in the following variables:
241 ;; reftex-insert-label-flags
242 ;; reftex-label-menu-flags
244 ;; The individual flags in these variables can be set to t or nil to enable or
245 ;; disable the feature for all label types. They may also contain a string of
246 ;; label type letters in order to turn on the feature for those types only.
249 ;; If you are writing in a language different from english you might want to
250 ;; add magic words for that language. Here is a German example:
252 ;; (setq reftex-label-alist
253 ;; '((nil ?s nil nil nil ("Kapitel" "Kap." "Abschnitt" "Teil"))
254 ;; (nil ?e nil nil nil ("Gleichung" "Gl."))
255 ;; (nil ?t nil nil nil ("Tabelle"))
256 ;; (nil ?f nil nil nil ("Figur" "Abbildung" "Abb."))
257 ;; (nil ?n nil nil nil ("Punkt"))))
259 ;; Using `nil' as first item in each entry makes sure that this entry does
260 ;; not replace the original entry for that label type.
264 ;; Loading reftex.el runs the hook reftex-load-hook. Turning on reftex-mode
265 ;; runs reftex-mode-hook.
267 ;;-------------------------------------------------------------------------
271 ;; All important functions of RefTeX can be reached from its menu which
272 ;; is installed in the menu bar as "Ref" menu. Only the more frequently used
273 ;; functions have key bindings.
275 ;; Here is the default set of keybindings from RefTeX.
278 ;; C-c ( reftex-label
279 ;; C-c ) reftex-reference
280 ;; C-c [ reftex-citation
281 ;; C-c & reftex-view-crossref
283 ;; I've used these bindings in order to avoid interfering with AUCTeX's
284 ;; settings. Personally, I also bind some functions in the C-c LETTER
285 ;; map for easier access:
288 ;; C-c l reftex-label
289 ;; C-c r reftex-reference
290 ;; C-c c reftex-citation
291 ;; C-c v reftex-view-crossref
292 ;; C-c s reftex-search-document
293 ;; C-c g reftex-grep-document
295 ;; If you want to copy those as well, set in your .emacs file:
297 ;; (setq reftex-extra-bindings t)
299 ;; It is possible to bind the function for viewing cross references to a
300 ;; mouse event. Something like the following in .emacs will do the trick:
302 ;; (add-hook 'reftex-load-hook
304 ;; (define-key reftex-mode-map [(alt mouse-1)]
305 ;; 'reftex-mouse-view-crossref)))
307 ;;-------------------------------------------------------------------------
313 ;; If you are writing any TeX or LaTeX documents with Emacs, you should
314 ;; have a look at AUCTeX, the definitive package to work with TeX and LaTeX.
315 ;; Information on AUCTeX can be found here:
317 ;; http://www.sunsite.auc.dk/auctex/
319 ;; AUCTeX version 9.7f and later can be configured to delegate label
320 ;; insertion to RefTeX. Do do that, say in your .emacs file
322 ;; (setq LaTeX-label-function 'reftex-label)
324 ;; RefTeX also provides functions which can replace TeX-arg-label and
325 ;; TeX-arg-cite in AUCTeX. These functions are compatible with the originals,
326 ;; but use RefTeX internals to create and select labels and citation keys.
327 ;; There are 3 functions: reftex-arg-label, reftex-arg-ref, reftex-arg-cite.
329 ;; AUCTeX can support RefTeX via style files. A style file may contain
330 ;; calls to reftex-add-to-label-alist which defines additions to
331 ;; reftex-label-alist. The argument taken by this function must have
332 ;; the same format as reftex-label-alist. E.g. the amsmath.el style file
333 ;; of AUCTeX contains the following:
335 ;; (TeX-add-style-hook "amsmath"
338 ;; (if (featurep 'reftex)
339 ;; (reftex-add-to-label-alist '(AMSTeX))))))
341 ;; while a package `myprop' defining a proposition environment with
342 ;; \newtheorem might use
344 ;; (TeX-add-style-hook "myprop"
347 ;; (if (featurep 'reftex)
348 ;; (reftex-add-to-label-alist
349 ;; '(("proposition" ?p "prop:" "~\\ref{%s}" t
350 ;; ("Proposition" "Prop."))))))))
354 ;; Once you have written a document with labels, refs and citations, it can be
355 ;; nice to read such a file like a hypertext document. RefTeX has some support
356 ;; for that (reftex-view-crossref, reftex-search-document). A more elegant
357 ;; interface with mouse support and links into Hyperbole is provided (among
358 ;; other things) by Peter S. Galbraith's bib-cite.el. There is some overlap in
359 ;; the functionalities of bib-cite and RefTeX. Bib-cite.el comes bundled with
360 ;; AUCTeX. You can also get the latest version from
362 ;; ftp://ftp.phys.ocean.dal.ca/users/rhogee/elisp/bib-cite.el
364 ;;-------------------------------------------------------------------------
366 ;; PERFORMANCE ISSUES
368 ;; 1. RefTeX will load other parts of a multifile document as well as BibTeX
369 ;; database files for lookup purposes. These buffers are kept, so that
370 ;; subsequent lookup in the same files is fast. For large documents and
371 ;; large BibTeX databases, this can use up a lot of memory. If you have
372 ;; more time than memory, try the following option, which will remove
373 ;; buffers created for lookup after use.
375 ;; (setq reftex-keep-temporary-buffers nil)
377 ;; 2. Parsing the document for labels and their context can be slow.
378 ;; Therefore, RefTeX does it just once automatically. Further parsing
379 ;; happens only on user request
380 ;; - with a raw C-u prefix arg to any of the functions reftex-label,
381 ;; reftex-reference, reftex-citation, reftex-toc.
382 ;; - with the `r' key from the label selection menu or the *toc* buffer.
384 ;; *** If you use reftex-label to create labels, the list will be updated
385 ;; *** internally, so that no extra parsing is required.
387 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
391 ;; o If you change reftex-label-alist in an editing session, you need to
392 ;; reset reftex with `M-x reftex-reset-mode' in order to make these
393 ;; changes effective. Changes introduced with the function
394 ;; reftex-add-to-label-alist as well as changes applied from the
395 ;; customization buffer automatically trigger a reset.
397 ;; o At times the short context shown by RefTeX may not be what you want.
398 ;; In particular, eqnarray environments can be difficult to
399 ;; parse. RefTeX's default behavior for eqnarrays is to scan backwards to
400 ;; either a double backslash or the beginning of the environment. If this
401 ;; gives unsatisfactory results, make it a habit to place the label
402 ;; *before* each equation
406 ;; E = \gamma m c^2 \\
408 ;; \gamma = \sqrt{1-v^2/c^2}
411 ;; and turn off parsing for context in equation and eqnarray environments
414 ;; (setq reftex-use-text-after-label-as-context "e").
416 ;; o RefTeX keeps only one global copy of the configuration variables.
417 ;; Also any additions from style files go into a global variable.
418 ;; Practically, this should not be a problem. Theoretically, it could
419 ;; give conflicts if two documents used environments with identical
420 ;; names, but different associated label types.
422 ;; o Input, include, bibliography and section statements have to be first
423 ;; on a line (except for white space) in order to be seen by reftex.
425 ;; o When the document is scanned, RefTeX creates a large buffer containing
426 ;; the entire document instead of scanning the individual files one by
427 ;; one. This is necessary since a file might not contain the context
430 ;; o If you have two identical section headings in the same file,
431 ;; reftex-toc will only let you jump to the first one because it searches
432 ;; for the section heading from the beginning of the file. You can work
433 ;; around this by changing one of the section titles in a way LaTeX does
434 ;; not see, e.g. with extra white space. RefTeX will distinguish
435 ;; \section{Introduction} from \section{ Introduction}.
437 ;; o RefTeX sees also labels in regions commented out and will refuse to
438 ;; make duplicates of such a label. This is considered to be a feature.
440 ;; o When RefTeX tries to show a window full of context from inside a
441 ;; section hidden with outline-minor-mode, it will unhide that section.
442 ;; This change will not be reversed automatically.
444 ;;---------------------------------------------------------------------------
448 ;; I think I am pretty much done with this one...
450 ;;---------------------------------------------------------------------------
454 ;; Carsten Dominik <dominik@strw.LeidenUniv.nl>
456 ;; with contributions from Stephen Eglen
458 ;; The newest version of RefTeX can be found at
460 ;; http://www.strw.leidenuniv.nl/~dominik/Tools/
461 ;; ftp://strw.leidenuniv.nl/pub/dominik/
465 ;; At least the following people have invested time to test and bug-fix
466 ;; reftex.el. Some have send patches for fixes or new features.
468 ;; Stephen Eglen <stephene@cogs.susx.ac.uk>
469 ;; F.E.Burstall <F.E.Burstall@maths.bath.ac.uk>
470 ;; Karl Eichwalder <ke@ke.Central.DE>
471 ;; Laurent Mugnier <mugnier@onera.fr>
472 ;; Rory Molinari <molinari@yunt.math.lsa.umich.edu>
473 ;; Soren Dayton <csdayton@cs.uchicago.edu>
474 ;; Daniel Polani <polani@Informatik.Uni-Mainz.DE>
475 ;; Allan Strand <astrand@trillium.NMSU.Edu>
477 ;; The view crossref feature was inspired by the similar function in
478 ;; Peter S. Galbraith's bib-cite.el.
480 ;; Finally thanks to Uwe Bolick <bolick@physik.tu-berlin.de> who first
481 ;; got me (some years ago) into supporting LaTeX labels and references
482 ;; with an Editor (which was MicroEmacs at the time).
487 ;; Stuff that needs to be there when we use defcustom
488 ;; --------------------------------------------------
492 (defvar reftex-tables-dirty t
493 "Flag showing if tables need to be re-computed.")
496 (defun reftex-set-dirty (symbol value
)
497 (setq reftex-tables-dirty t
)
500 ;;; Begin of Configuration Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
502 ;; Configuration Variables and User Options for RefTeX ------------------
505 "LaTeX label and citation support."
507 :link
'(url-link :tag
"Home Page" "http://strw.leidenuniv.nl/~dominik/Tools/")
511 (defun reftex-customize ()
512 "Call the customize function with reftex as argument."
514 (if (fboundp 'customize-group
)
515 (customize-group 'reftex
)
516 (customize 'reftex
)))
518 ;; Support for \label and \ref --------------------------------------
520 (defgroup reftex-label-support nil
521 "Support for creation, insertion and referencing of labels in LaTeX"
524 (defgroup reftex-defining-label-environments nil
525 "Definition of environments and macros to do with label"
526 :group
'reftex-label-support
)
529 (defcustom reftex-label-alist nil
530 "Alist with information on environments for \\label-\\ref use.
531 See the definition of `reftex-label-alist-builtin' for examples. This variable
532 should define additions and changes to the default. The only things you MUST
533 NOT change is that `?s' is the type indicator for section labels and SPACE is
534 for the 'any' label type. These are hard-coded at other places in the code.
536 Changes to this variable after RefTeX has been loaded only become
537 effective when RefTeX is reset with \\[reftex-reset-mode].
539 Each list entry is a list describing an environment or macro carrying a
540 label. The elements of each list entry are:
542 0. Name of the environment (like \"table\") or macro (like \"\\\\myfig\").
543 Special names: `section' for section labels, `any' to define a group
544 which contains all labels.
545 This may also be nil if this entry is only meant to change some settings
546 associated with the type indicator character (see below).
548 1. Type indicator character, like ?t.
549 The type indicator is a single character used in prompts for
550 label types. It must be a printable character. The same character
551 may occur several times in this list, to cover cases in which different
552 environments carry the same label type (like equation and eqnarray).
554 2. Label prefix string, like \"tab:\".
555 The prefix is a short string used as the start of a label. It may be the
558 3. Format string for reference insert in buffer. Each `%s' will be
559 replaced by the label (you can use more than one several `%s', so
560 that you can set this to: \"\\ref{%s} on page~\\pageref{%s}\").
561 When the format starts with `~', whitespace before point will be
562 removed so that the reference cannot be separated from the word
565 4. Indication on how to find the short context.
566 - If nil, use the text following the \\label{...} macro.
568 - text following the \\begin{...} statement of environments
569 (not a good choice in in eqnarray or enumerate environments!)
570 - the section heading for section labels.
571 - the begin of the macro for macros.
572 - If a string, use as regexp to search *backward* from the label. Context
573 is then the text following the end of the match. E.g. putting this to
574 \"\\\\\\\\caption{\" will use the beginning of the caption in a figure
575 or table environment. \"\\\\\\\\begin{eqnarray}\\\\|\\\\\\\\\\\\\\\\\"
577 - If a function, call this function with the name of the environment/macro
578 as argument. On call, point will be just after the \\label macro. The
579 function is expected to return a suitable context string. It should
580 throw an exception (error) when failing to find context.
581 Consider the following example, which would return the 10 characters
582 following the label as context:
584 (defun my-context-function (env-or-mac)
585 (if (> (point-max) (+ 10 (point)))
586 (buffer-substring (point) (+ 10 (point)))
587 (error \"Buffer too small\")))
589 Setting the variable `reftex-use-text-after-label-as-context' to t
590 overrides the setting here.
592 5. List of magic words which identify a reference to be of this type. If the
593 word before point is equal to one of these words when calling
594 `reftex-reference', the label list offered will be automatically restricted
595 to labels of the correct type.
597 If the type indicator characters of two or more entries are the same, RefTeX
599 - the first non-nil format and prefix
600 - the magic words of all involved entries.
602 Any list entry may also be a symbol. If that has an association in
603 reftex-label-alist-builtin, the cdr of that association is spliced into the
604 list. See the AMSTeX configuration example in the comment section of
606 :group
'reftex-defining-label-environments
607 :set
'reftex-set-dirty
617 :value
("" ?a nil nil t nil
)
621 ,@(mapcar (function (lambda (x)
622 (list 'const
':tag
(nth 1 x
) (car x
))))
623 reftex-label-alist-builtin
))
624 (list :tag
"Detailed custom entry"
625 (choice :tag
"Environment or \\macro "
626 (const :tag
"Ignore, just use typekey" nil
)
628 (character :tag
"Typekey character " ?a
)
629 (choice :tag
"Label prefix string "
630 (const :tag
"Copy from similar label type" nil
)
631 (string :tag
"Specify here" "lab:"))
632 (choice :tag
"Label reference format"
633 (const :tag
"Copy from similar label type" nil
)
634 (string :tag
"Specify here" "~\\ref{%s}"))
635 (choice :tag
"Grab context method "
636 (const :tag
"Default position" t
)
637 (const :tag
"After label" nil
)
638 (regexp :tag
"Regular expression" "")
639 (symbol :tag
"Function" my-context-function
))
640 (repeat :tag
"List of Magic Words" (string))))))))
641 (widget-put widget
:args args
)
644 (defcustom reftex-default-label-alist-entries
'(Sideways LaTeX
)
645 "Default label alist specifications. LaTeX should be the last entry.
646 This list describes the default label environments RefTeX should always use in
647 addition to the specifications in reftex-label-alist. It is probably a
648 mistake to remove the LaTeX symbol from this list.
651 LaTeX The standard LaTeX environments
652 Sideways The sidewaysfigure and sidewaystable environments
653 AMSTeX The math environments in the AMS_LaTeX amsmath package
654 AAS The deluxetable environment from the American Astronomical Society
656 For the full list of options, see the constant reftex-label-alist-builtin.
659 M-x customize-variable RET reftex-default-label-alist-entries RET."
660 :group
'reftex-defining-label-environments
661 :set
'reftex-set-dirty
662 :type
'(list :indent
4
671 (list 'const
':tag
(nth 1 x
) (car x
)))
672 reftex-label-alist-builtin
))))))
673 (widget-put widget
:args args
)
676 (defcustom reftex-use-text-after-label-as-context nil
677 "*t means, grab context from directly after the \\label{..} macro.
678 This is the fastest method for obtaining context of the label definition, but
679 requires discipline when placing labels. Setting this variable to t takes
680 precedence over the individual settings in reftex-label-alist.
681 This variable may be set to t, nil, or a string of label type letters
682 indicating the label types for which it should be true."
683 :group
'reftex-defining-label-environments
684 :set
'reftex-set-dirty
686 (const :tag
"on" t
) (const :tag
"off" nil
)
687 (string :tag
"Selected label types")))
691 (defgroup reftex-making-and-inserting-labels nil
692 "Options on how to create new labels"
693 :group
'reftex-label-support
)
695 (defcustom reftex-insert-label-flags
'("s" "sft")
696 "Flags governing label insertion. First flag DERIVE, second flag PROMPT.
698 If DERIVE is t, RefTeX will try to derive a sensible label from context.
699 A section label for example will be derived from the section heading.
700 The conversion of the context to a legal label is governed by the
701 specifications given in reftex-derive-label-parameters.
702 If RefTeX fails to derive a label, it will prompt the user.
704 If PROMPT is t, the user will be prompted for a label string. The prompt will
705 already contain the prefix, and (if DERIVE is t) a default label derived from
706 context. When PROMPT is nil, the default label will be inserted without
709 So the combination of DERIVE and PROMPT controls label insertion. Here is a
710 table describing all four possibilities:
713 -------------------------------------------------------------------------
714 nil nil Insert simple label, like eq:22 or sec:13. No query.
715 nil t Prompt for label
716 t nil Derive a label from context and insert without query
717 t t Derive a label from context and prompt for confirmation
719 Each flag may be set to t, nil, or a string of label type letters
720 indicating the label types for which it should be true.
721 Thus, the combination may be set differently for each label type. The
722 default settings \"s\" and \"sft\" mean: Derive section labels from headings
723 (with confirmation). Prompt for figure and table labels. Use simple labels
724 without confirmation for everything else."
725 :group
'reftex-making-and-inserting-labels
726 :type
'(list (choice :tag
"Derive label from context"
727 (const :tag
"always" t
)
728 (const :tag
"never" nil
)
729 (string :tag
"for selected label types" ""))
730 (choice :tag
"Prompt for label string "
731 :entry-format
" %b %v"
732 (const :tag
"always" t
)
733 (const :tag
"never" nil
)
734 (string :tag
"for selected label types" ""))))
736 (defcustom reftex-derive-label-parameters
'(3 20 t
1 "-" ; continue
737 ("the" "on" "in" "off" "a" "for" "by" "of" "and" "is"))
738 "Parameters for converting a string into a label.
739 NWORDS Number of words to use.
740 MAXCHAR Maximum number of characters in a label string.
741 ILLEGAL nil: Throw away any words containing characters illegal in labels.
742 t: Throw away only the illegal characters, not the whole word.
743 ABBREV nil: Never abbreviate words.
744 t: Always abbreviate words (see reftex-abbrev-parameters).
745 not t and not nil: Abbreviate words if necessary to shorten
746 label string below MAXCHAR.
747 SEPARATOR String separating different words in the label
748 IGNOREWORDS List of words which should not be part of labels"
749 :group
'reftex-making-and-inserting-labels
750 :type
'(list (integer :tag
"Number of words " 3)
751 (integer :tag
"Maximum label length " 20)
752 (choice :tag
"Illegal characters in words"
753 (const :tag
"throw away entire word" nil
)
754 (const :tag
"throw away single chars" t
))
755 (choice :tag
"Abbreviate words "
756 (const :tag
"never" nil
)
757 (const :tag
"always" t
)
758 (const :tag
"when label is too long" 1))
759 (string :tag
"Separator between words " "-")
760 (repeat :tag
"Ignore words"
761 :entry-format
" %i %d %v"
764 (defcustom reftex-label-illegal-re
"[\000-\040\177-\377\\\\#$%&~^_{}]"
765 "Regexp matching characters not legal in labels.
766 For historic reasons, this character class comes *with* the [] brackets."
767 :group
'reftex-making-and-inserting-labels
768 :type
'(regexp :tag
"Character class"))
770 (defcustom reftex-abbrev-parameters
'(4 2 "^saeiou" "aeiou")
771 "Parameters for abbreviation of words.
772 MIN-CHARS minimum number of characters remaining after abbreviation
773 MIN-KILL minimum number of characters to remove when abbreviating words
774 BEFORE character class before abbrev point in word
775 AFTER character class after abbrev point in word"
776 :group
'reftex-making-and-inserting-labels
778 (integer :tag
"Minimum chars per word" 4)
779 (integer :tag
"Shorten by at least " 2)
780 (string :tag
"cut before char class " "^saeiou")
781 (string :tag
"cut after char class " "aeiou")))
786 (defgroup reftex-referencing-labels nil
787 "Options on how to reference labels"
788 :group
'reftex-label-support
)
790 (defcustom reftex-label-menu-flags
'(t t nil nil nil nil
)
791 "*List of flags governing the label menu makeup.
794 TABLE-OF-CONTENTS Show the labels embedded in a table of context.
795 SECTION-NUMBERS Include section numbers (like 4.1.3) in table of contents.
796 COUNTERS Show counters. This just numbers the labels in the menu.
797 NO-CONTEXT Non-nil means do NOT show the short context.
798 FOLLOW follow full context in other window.
799 SHOW-COMMENTED Show labels from regions which are commented out. RefTeX
800 sees these labels, but does not normally show them.
802 Each of these flags can be set to t or nil, or to a string of type letters
803 indicating the label types for which it should be true. These strings work
804 like character classes in regular expressions. Thus, setting one of the
805 flags to \"sf\" makes the flag true for section and figure labels, nil
806 for everything else. Setting it to \"^ft\" makes it the other way round.
808 Most options can also be switched from the label menu itself - so if you
809 decide here to not have a table of contents in the label menu, you can still
810 get one interactively during selection from the label menu."
811 :group
'reftex-referencing-labels
813 (choice :tag
"Embed in table of contents "
814 (const :tag
"on" t
) (const :tag
"off" nil
)
815 (string :tag
"Selected label types"))
816 (choice :tag
"Show section numbers "
817 (const :tag
"on" t
) (const :tag
"off" nil
))
818 (choice :tag
"Show individual counters "
819 (const :tag
"on" t
) (const :tag
"off" nil
)
820 (string :tag
"Selected label types"))
821 (choice :tag
"Hide short context "
822 (const :tag
"on" t
) (const :tag
"off" nil
)
823 (string :tag
"Selected label types"))
824 (choice :tag
"Follow context in other window"
825 (const :tag
"on" t
) (const :tag
"off" nil
)
826 (string :tag
"Selected label types"))
827 (choice :tag
"Show commented labels "
828 (const :tag
"on" t
) (const :tag
"off" nil
)
829 (string :tag
"Selected label types"))))
832 (defcustom reftex-guess-label-type t
833 "*Non-nil means, reftex-reference will try to guess the label type.
834 To do that, RefTeX will look at the word before the cursor and compare it with
835 the words given in reftex-label-alist. When it finds a match, RefTeX will
836 immediately offer the correct label menu - otherwise it will prompt you for
837 a label type. If you set this variable to nil, RefTeX will always prompt."
838 :group
'reftex-referencing-labels
841 ;; BibteX citation configuration ----------------------------------------
843 (defgroup reftex-citation-support nil
844 "Support for referencing bibliographic data with BibTeX"
847 (defcustom reftex-bibpath-environment-variables
'("BIBINPUTS" "TEXBIB")
848 "*List of env vars which might contain the path to BibTeX database files."
849 :group
'reftex-citation-support
850 :set
'reftex-set-dirty
851 :type
'(repeat (string :tag
"Environment variable")))
853 (defcustom reftex-bibfile-ignore-list nil
854 "List of files in \\bibliography{..} RefTeX should *not* parse.
855 The file names have to be in the exact same form as in the bibliography
856 macro - i.e. without the .bib extension.
857 Intended for files which contain only `@string' macro definitions and the
858 like, which are ignored by RefTeX anyway."
859 :group
'reftex-citation-support
860 :set
'reftex-set-dirty
861 :type
'(repeat (string :tag
"File name")))
863 (defcustom reftex-sort-bibtex-matches
'reverse-year
864 "*Sorting of the entries found in BibTeX databases by reftex-citation.
866 nil Do not sort entries.
867 'author Sort entries by author name.
868 'year Sort entries by increasing year.
869 'reverse-year Sort entries by decreasing year."
870 :group
'reftex-citation-support
871 :type
'(choice (const :tag
"not" nil
)
872 (const :tag
"by author" author
)
873 (const :tag
"by year" year
)
874 (const :tag
"by year, reversed" reverse-year
)))
876 (defcustom reftex-cite-format
'reftex-cite-format-default
877 "Defines the format of citations to be inserted into the buffer.
878 It can be a string, a list of strings, or an alist with characters as keys
879 and a list of strings in the car. In the simplest case, this can just
880 be the string \"\\cite{KEY}\", which is also the default. See the
881 definition of the reftex-cite-format-XXXX constants for more complex
883 If reftex-cite-format is a string, it will be used as the format. In
884 the format, AUTHOR will be replaced by the last name of the
885 author, YEAR will be replaced by the year and KEY by the citation
886 key. If AUTHOR is present several times, it will be replaced with
887 successive author names.
888 See the constant reftex-cite-format-default for an example.
889 If reftex-cite-format is a list of strings, the string used will
890 depend upon the number of authors of the article. No authors means,
891 the first string will be used, 1 author means, the second string will
892 be used etc. The last string in the list will be used for all articles
893 with too many authors. See reftex-cite-format-1-author-simple for an
895 If reftex-cite-format is a list of cons cells, the car of each cell
896 needs to be a character. When a selected reference is accepted by
897 pressing that key, the cdr of the associated list will be used as
898 described above. See reftex-cite-format-2-authors for an example.
899 In order to configure this variable, you can either set
900 reftex-cite-format directly yourself or set it to the SYMBOL of one of
901 the predefined constants. E.g.:
902 (setq reftex-cite-format 'reftex-cite-format-2-authors)"
903 :group
'reftex-citation-support
906 (choice :tag
"symbolic defaults"
907 :value reftex-cite-format-default
908 (const reftex-cite-format-default
)
909 (const reftex-cite-format-1-author-simple
)
910 (const reftex-cite-format-2-authors
))
911 (string :tag
"format string" "\\cite{KEY}")
912 (repeat :tag
"list of strings"
913 :value
("\cite{KEY}" "AUTHOR \cite{KEY}" "AUTHOR and AUTHOR \cite{KEY}")
914 (string :tag
"format string" ""))
915 (repeat :tag
"key-ed lists of strings"
916 :value
((?
.
("\cite{KEY}" "AUTHOR \cite{KEY}" "AUTHOR and AUTHOR \cite{KEY}")))
917 (cons :tag
"Enter a keyed list of format strings"
918 (character :tag
"Key character " ?
)
920 (string :tag
"format string" ""))))))
922 ;; Table of contents configuration --------------------------------------
924 (defgroup reftex-table-of-contents-browser nil
925 "A multifile table of contents browser."
928 (defcustom reftex-toc-follow-mode nil
929 "Non-nil means, point in *toc* buffer will cause other window to follow.
930 The other window will show the corresponding part of the document.
931 This flag can be toggled from within the *toc* buffer with the `f' key."
932 :group
'reftex-table-of-contents-browser
935 ;; Miscellaneous configurations -----------------------------------------
937 (defgroup reftex-miscellaneous-configurations nil
938 "Collection of further configurations"
941 (defcustom reftex-extra-bindings nil
942 "Non-nil means, make additional key bindings on startup.
943 These extra bindings are located in the users C-c letter map."
944 :group
'reftex-miscellaneous-configurations
947 (defcustom reftex-use-fonts t
948 "*Non-nil means, use fonts in label menu and on-the-fly help.
949 Font-lock must be loaded as well to actually get fontified display."
950 :group
'reftex-miscellaneous-configurations
953 (defcustom reftex-keep-temporary-buffers t
954 "*Non-nil means, keep any TeX and BibTeX files loaded for lookup.
955 Nil means, kill it immediately after use unless it was already an existing
956 buffer before the lookup happened. It is faster to keep the buffers, but can
957 use a lot of memory, depending on the size of your database and document."
958 :group
'reftex-miscellaneous-configurations
961 (defcustom reftex-auto-show-entry t
962 "*Non-nil means, showing context in another window may unhide a section.
963 This is important when using outline-minor-mode. If the context to be shown
964 is in a hidden section, RefTeX will issue a \"show-entry\" command in order
965 to show it. This is not reversed when the label is selected - so the section
966 remains shown after command completion."
967 :group
'reftex-miscellaneous-configurations
971 ;;; End of Configuration Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
973 ;;;===========================================================================
975 ;;; Define the formal stuff for a minor mode named RefTeX.
978 (defvar reftex-mode nil
979 "Determines if RefTeX minor mode is active.")
980 (make-variable-buffer-local 'reftex-mode
)
982 (defvar reftex-mode-map
(make-sparse-keymap)
983 "Keymap for RefTeX minor mode.")
985 (defvar reftex-mode-menu nil
)
988 (defun turn-on-reftex ()
989 "Turn on RefTeX minor mode."
993 (defun reftex-mode (&optional arg
)
994 "Minor mode with distinct support for \\label, \\ref and \\cite in LaTeX.
996 Labels can be created with `\\[reftex-label]' and referenced with `\\[reftex-reference]'.
997 When referencing, you get a menu with all labels of a given type and
998 context of the label definition. The selected label is inserted as a
1001 Citations can be made with `\\[reftex-citation]' which will use a regular expression
1002 to pull out a *formatted* list of articles from your BibTeX
1003 database. The selected citation is inserted as a \\cite macro.
1005 A Table of Contents of the entire (multifile) document with browsing
1006 capabilities is available with `\\[reftex-toc]'.
1008 Most command have help available on the fly. This help is accessed by
1009 pressing `?' to any prompt mentioning this feature.
1012 Under X, these functions will be available also in a menu on the menu bar.
1014 ------------------------------------------------------------------------------"
1017 (setq reftex-mode
(not (or (and (null arg
) reftex-mode
)
1018 (<= (prefix-numeric-value arg
) 0))))
1020 ; Add or remove the menu, and run the hook
1023 (easy-menu-add reftex-mode-menu
)
1024 (run-hooks 'reftex-mode-hook
))
1025 (easy-menu-remove reftex-mode-menu
)))
1027 (or (assoc 'reftex-mode minor-mode-alist
)
1028 (setq minor-mode-alist
1029 (cons '(reftex-mode " Ref") minor-mode-alist
)))
1031 (or (assoc 'reftex-mode minor-mode-map-alist
)
1032 (setq minor-mode-map-alist
1033 (cons (cons 'reftex-mode reftex-mode-map
)
1034 minor-mode-map-alist
)))
1037 ;;; ===========================================================================
1039 ;;; Interfaces for other packages
1040 ;;; -----------------------------
1045 (defun reftex-arg-label (optional &optional prompt definition
)
1046 "Use reftex-label to create a label and insert it with TeX-argument-insert.
1047 This function is intended for AUCTeX macro support."
1048 (let ((label (reftex-label nil t
)))
1049 (if (and definition
(not (string-equal "" label
)))
1050 (LaTeX-add-labels label
))
1051 (TeX-argument-insert label optional optional
)))
1053 (defun reftex-arg-ref (optional &optional prompt definition
)
1054 "Use reftex-reference to select a label, insert it with TeX-argument-insert.
1055 This function is intended for AUCTeX macro support."
1056 (let ((label (reftex-reference nil t
)))
1057 (if (and definition
(not (string-equal "" label
)))
1058 (LaTeX-add-labels label
))
1059 (TeX-argument-insert label optional optional
)))
1061 (defun reftex-arg-cite (optional &optional prompt definition
)
1062 "Use reftex-citation to select a key, insert it with TeX-argument-insert.
1063 This function is intended for AUCTeX macro support."
1064 (let ((key (reftex-citation nil t
)))
1065 (TeX-argument-insert (or key
"") optional optional
)))
1067 (defvar reftex-label-alist-external-add-ons nil
1068 "List of label alist entries added with reftex-add-to-label-alist.")
1071 (defun reftex-add-to-label-alist (entry-list)
1072 "Add label environment descriptions to reftex-label-alist-external-add-ons.
1073 The format of ENTRY-LIST is exactly like reftex-label-alist. See there
1075 This function makes it possible to support RefTeX from AUCTeX style files.
1076 The entries in ENTRY-LIST will be processed after the user settings in
1077 reftex-label-alist, and before the defaults (specified in
1078 reftex-default-label-alist-entries). Any changes made to
1079 reftex-label-alist-external-add-ons will raise a flag to the effect that a
1080 mode reset is done on the next occasion."
1083 (setq entry
(car entry-list
)
1084 entry-list
(cdr entry-list
))
1085 (if (not (member entry reftex-label-alist-external-add-ons
))
1086 (setq reftex-tables-dirty t
1087 reftex-label-alist-external-add-ons
1088 (cons entry reftex-label-alist-external-add-ons
))))))
1090 ;;; ===========================================================================
1092 ;;; Multifile support
1094 ;;; Technical notes: Multifile works as follows: We keep just one list
1095 ;;; of labels for each master file - this can save a lot of memory.
1096 ;;; reftex-master-index-list is an alist which connects the true file name
1097 ;;; of each master file with the symbols holding the information on that
1098 ;;; document. Each buffer has local variables which point to these symbols.
1100 ;; List of variables which handle the multifile stuff.
1101 ;; This list is used to tie, untie, and reset these symbols.
1102 (defconst reftex-multifile-symbols
1103 '(reftex-label-numbers-symbol reftex-list-of-labels-symbol
1104 reftex-bibfile-list-symbol
))
1106 ;; Silence warnings about TeX-master, which is defined in AUCTeX.
1109 ;; Silence additional warnings.
1110 (defvar tex-main-file
)
1111 (defvar outline-minor-mode
)
1113 ;; Alist connecting master file names with the corresponding Lisp symbols.
1114 (defvar reftex-master-index-list nil
)
1116 ;; Last index used for a master file
1117 (defvar reftex-multifile-index
0)
1119 ;; Alist connecting a master file with all included files.
1120 ;; This information is not yet used, just collected.
1121 (defvar reftex-master-include-list nil
)
1123 ;; Variable holding the symbol with current value of label postfix
1124 (defvar reftex-label-numbers-symbol nil
)
1125 (make-variable-buffer-local 'reftex-label-numbers-symbol
)
1127 ;; Variable holding the symbol with the label list of the document.
1128 ;; Each element of the label list is again a list with the following elements:
1129 ;; 0: One character label type indicator
1130 ;; 1: Short context to put into label menu
1132 ;; 3: The name of the file where the label is defined
1133 (defvar reftex-list-of-labels-symbol nil
)
1134 (make-variable-buffer-local 'reftex-list-of-labels-symbol
)
1136 ;; Variable holding the symbol with a list of library files for this document
1137 (defvar reftex-bibfile-list-symbol nil
)
1138 (make-variable-buffer-local 'reftex-bibfile-list-symbol
)
1140 (defun reftex-next-multifile-index ()
1141 ;; Return the next free index for multifile symbols.
1142 (setq reftex-multifile-index
(1+ reftex-multifile-index
)))
1144 (defun reftex-tie-multifile-symbols ()
1145 ;; Tie the buffer-local symbols to globals connected with the master file.
1146 ;; If the symbols for the current master file do not exist, they are created.
1148 (let* ((master (file-truename (reftex-TeX-master-file)))
1149 (index (assoc master reftex-master-index-list
))
1150 (symlist reftex-multifile-symbols
)
1154 ;; find the correct index
1157 (setq index
(cdr index
))
1158 ;; get a new index and add info to the alist
1159 (setq index
(reftex-next-multifile-index)
1160 reftex-master-index-list
(cons
1162 reftex-master-index-list
)
1165 ;; get/create symbols and tie them
1167 (setq symbol
(car symlist
)
1168 symlist
(cdr symlist
)
1169 symname
(symbol-name symbol
))
1170 (set symbol
(intern (concat symname
"-" (int-to-string index
))))
1171 ;; initialize if new symbols
1172 (if newflag
(set (symbol-value symbol
) nil
)))
1174 ;; Return t if the symbols did already exist, nil when we've made them
1177 (defun reftex-untie-multifile-symbols ()
1178 ;; Remove ties from multifile symbols, so that next use makes new ones.
1179 (let ((symlist reftex-multifile-symbols
)
1182 (setq symbol
(car symlist
)
1183 symlist
(cdr symlist
))
1186 (defun reftex-TeX-master-file ()
1187 ;; Return the name of the master file associated with the current buffer.
1188 ;; When AUCTeX is loaded, we will use it's more sophisticated method.
1189 ;; We also support the default TeX and LaTeX modes by checking for a
1190 ;; variable tex-main-file.
1195 ((fboundp 'TeX-master-file
) ; AUCTeX is loaded. Use its mechanism.
1196 (TeX-master-file t
))
1197 ((boundp 'TeX-master
) ; The variable is defined - lets use it.
1201 ((eq TeX-master
'shared
)
1202 (setq TeX-master
(read-file-name "Master file: "
1206 (setq TeX-master
(read-file-name "Master file: "
1208 ((boundp 'tex-main-file
)
1209 ;; This is the variable from the default TeX modes
1211 ((stringp tex-main-file
)
1212 ;; ok, this must be it
1215 ;; In this case, the buffer is its own master
1216 (buffer-file-name))))
1218 ;; Know nothing about master file. Assume this is a master file.
1219 (buffer-file-name)))))
1222 (error "Need a filename for this buffer. Please save it first."))
1223 ((or (file-exists-p master
)
1224 (reftex-get-buffer-visiting master
))
1225 ;; We either see the file, or have a buffer on it. OK.
1227 ((or (file-exists-p (concat master
".tex"))
1228 (reftex-get-buffer-visiting (concat master
".tex")))
1229 ;; Ahh, an extra .tex was missing...
1230 (setq master
(concat master
".tex")))
1232 ;; Something is wrong here. Throw an exception.
1233 (error "No such master file %s" master
)))
1234 (expand-file-name master
)))
1236 (defun reftex-make-master-buffer (master-file mode
)
1237 "Make a master buffer which contains the MASTER-FILE and all includes.
1238 This is to prepare a buffer containing the entire document in correct
1239 sequence for parsing. Therefore it will even expand includes which are
1241 The function returns the number of input/include files not found."
1243 (interactive "fmaster file: ")
1244 (let ((not-found 0) file file-list tmp
(font-lock-maximum-size 1))
1245 (switch-to-buffer "*reftex-master.tex*")
1247 (if (not (eq major-mode mode
))
1249 ;; first insert the master file
1250 (if (not (file-exists-p master-file
))
1251 (error "No such master file: %s" master-file
))
1252 (reftex-insert-buffer-or-file master-file
)
1253 (subst-char-in-region (point-min) (point-max) ?
\r ?
\n t
)
1254 (setq file-list
(cons master-file file-list
))
1256 ;; remember from which file these lines came
1257 (put-text-property (point-min) (point-max) 'file
1258 (expand-file-name master-file
))
1259 ;; Now find recursively all include/input statements and expand them
1260 (while (re-search-forward
1261 "^[ \t]*\\\\\\(include\\|input\\){\\([^}\n]+\\)}" nil t
)
1262 ;; Change default directory, so that relative fine names work correctly
1263 (setq file
(reftex-no-props (match-string 2)))
1265 (cd (file-name-directory
1266 (get-text-property (match-beginning 0) 'file
)))
1267 (if (not (string-match "\\.tex$" file
))
1268 (setq file
(concat file
".tex"))))
1269 (if (file-exists-p file
)
1272 (format "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% START OF %s FILE: %s\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% END OF %s FILE: %s\n"
1273 (match-string 1) file
1274 (match-string 1) file
))
1275 (beginning-of-line 0)
1276 (narrow-to-region (point) (point))
1278 (reftex-insert-buffer-or-file file
)
1279 (subst-char-in-region (point-min) (point-max) ?
\r ?
\n t
)
1280 (setq file-list
(cons (expand-file-name file
) file-list
))
1281 ;; remember from which file these lines came
1282 (put-text-property (point-min) (point-max)
1283 'file
(expand-file-name file
))
1284 (goto-char (point-min))
1286 (message "Input/include file %s not found. Ignored. Continuing..."
1288 (setq not-found
(1+ not-found
))))
1289 (setq file-list
(nreverse file-list
))
1290 (while (setq tmp
(assoc (car file-list
) reftex-master-include-list
))
1291 (setq reftex-master-include-list
(delq tmp reftex-master-include-list
)))
1292 (setq reftex-master-include-list
(cons file-list reftex-master-include-list
))
1295 (defun reftex-insert-buffer-or-file (file)
1296 "If there is a buffer associated with FILE, insert it - otherwise the FILE."
1297 (let ((buffer (reftex-get-buffer-visiting file
)))
1299 (let (beg end beg1 end1
)
1301 ;; make sure we get the whole buffer
1303 (setq beg
(point-min) end
(point-max))
1305 (setq beg1
(point-min) end1
(point-max)))
1306 (insert-buffer-substring buffer beg1 end1
)
1309 (narrow-to-region beg end
)))
1310 (insert-file-contents file
))))
1313 (defun reftex-parse-document (&optional buffer
)
1314 "Rescan the document."
1316 (save-window-excursion
1319 (if (not (bufferp buffer
))
1320 (error "No such buffer %s" (buffer-name buffer
))
1321 (set-buffer buffer
)))
1322 (reftex-access-scan-info t
))))
1324 (defun reftex-access-scan-info (&optional rescan
)
1325 ;; Access the scanning info. When the multifile symbols are not yet tied,
1326 ;; tie them. When they are have to be created, do a buffer scan to
1329 ;; If RESCAN is non-nil, enforce document scanning
1332 (let ((rescan (or (equal rescan t
) (equal rescan
'(4)))))
1334 ;; Reset the mode if we had changes from style hooks
1335 (and reftex-tables-dirty
1336 (reftex-reset-mode))
1338 (if (eq reftex-list-of-labels-symbol nil
)
1339 ;; Symbols are not yet tied: Tie them and see if they are set
1340 (reftex-tie-multifile-symbols))
1342 (if (and (symbol-value reftex-list-of-labels-symbol
)
1344 ;; Lists do already exist and we don't need to rescan.
1345 ;; Return from here.
1348 ;; We need to rescan
1349 ;; =================
1352 (save-window-excursion
1357 (let ((label-list-symbol reftex-list-of-labels-symbol
)
1358 (label-numbers-symbol reftex-label-numbers-symbol
)
1359 (bibfile-list-symbol reftex-bibfile-list-symbol
))
1361 (message "Creating master buffer...")
1362 (reftex-make-master-buffer (reftex-TeX-master-file) major-mode
)
1364 (message "Scanning document...")
1366 (reftex-scan-buffer-for-labels
1367 label-numbers-symbol label-list-symbol
)
1369 (reftex-scan-buffer-for-bibliography-statement
1370 bibfile-list-symbol
)
1372 (message "Scanning document... done"))))
1374 (if (get-buffer "*reftex-master.tex*")
1375 (kill-buffer "*reftex-master.tex*"))))))
1377 (defun reftex-create-tags-file ()
1378 "Create TAGS file by running `etags' on the current document.
1379 The TAGS file is also immediately visited with `visit-tags-table."
1381 (reftex-access-scan-info current-prefix-arg
)
1382 (let* ((master (reftex-TeX-master-file))
1383 (files (assoc master reftex-master-include-list
))
1384 (cmd (format "etags %s" (mapconcat 'identity files
" "))))
1386 (set-buffer (reftex-get-buffer-visiting master
))
1387 (message "Running etags to create TAGS file...")
1389 (visit-tags-table "TAGS"))))
1391 ;; History of grep commands.
1392 (defvar reftex-grep-history nil
)
1393 (defvar reftex-grep-command
"grep -n "
1394 "Last grep command used in \\[reftex-grep-document]; default for next grep.")
1396 (defun reftex-grep-document (grep-cmd)
1397 "Run grep query through all files related to this document.
1398 With prefix arg, force to rescan document.
1399 This works also without an active TAGS table."
1402 (list (read-from-minibuffer "Run grep on document (like this): "
1403 reftex-grep-command nil nil
1404 'reftex-grep-history
)))
1405 (reftex-access-scan-info current-prefix-arg
)
1406 (let* ((master (reftex-TeX-master-file))
1407 (default-directory (file-name-directory master
))
1408 (re (format "\\`%s\\(.*\\)" (regexp-quote
1409 (expand-file-name default-directory
))))
1410 (files (assoc master reftex-master-include-list
))
1413 (mapconcat (function (lambda (x)
1414 (if (string-match re x
)
1420 (defun reftex-search-document (&optional regexp
)
1421 "Regexp search through all files of the current TeX document.
1422 Starts always in the master file. Stops when a match is found.
1423 To continue searching for next match, use command \\[tags-loop-continue].
1424 This works also without an active TAGS table."
1426 (let ((default (reftex-this-word)))
1428 (setq regexp
(read-string (format "Search regexp in document [%s]: "
1430 (if (string= regexp
"") (setq regexp
(regexp-quote default
)))
1432 (reftex-access-scan-info current-prefix-arg
)
1433 (tags-search regexp
(list 'assoc
(reftex-TeX-master-file)
1434 'reftex-master-include-list
))))
1436 (defun reftex-query-replace-document (&optional from to delimited
)
1437 "Run a query-replace-regexp of FROM with TO over the entire TeX document.
1438 Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
1439 If you exit (\\[keyboard-quit] or ESC), you can resume the query replace
1440 with the command \\[tags-loop-continue].
1441 This works also without an active TAGS table."
1443 (let ((default (reftex-this-word)))
1446 (setq from
(read-string (format "Replace regexp in document [%s]: "
1448 (if (string= from
"") (setq from
(regexp-quote default
)))))
1450 (setq to
(read-string (format "Replace regexp %s with: " from
))))
1451 (reftex-access-scan-info current-prefix-arg
)
1452 (tags-query-replace from to
(or delimited current-prefix-arg
)
1453 (list 'assoc
(reftex-TeX-master-file)
1454 'reftex-master-include-list
))))
1456 (defun reftex-change-label (&optional from to
)
1457 "Query replace FROM with TO in all \\label and \\ref commands.
1458 Works on the entire multifile document.
1459 If you exit (\\[keyboard-quit] or ESC), you can resume the query replace
1460 with the command \\[tags-loop-continue].
1461 This works also without an active TAGS table."
1463 (let ((default (reftex-this-word "-a-zA-Z0-9_*.:")))
1465 (setq from
(read-string (format "Replace label globally [%s]: "
1467 (if (string= from
"") (setq from default
))
1469 (setq to
(read-string (format "Replace label %s with: "
1471 (reftex-query-replace-document
1472 (concat "\\\\\\(label\\|[a-z]*ref\\){" (regexp-quote from
) "}")
1473 (format "\\\\\\1{%s}" to
))))
1475 (defun reftex-this-word (&optional class
)
1476 ;; grab the word around point
1477 (setq class
(or class
"-a-zA-Z0-9:_/.*;|"))
1479 (buffer-substring-no-properties
1480 (progn (skip-chars-backward class
) (point))
1481 (progn (skip-chars-forward class
) (point)))))
1483 ;;; ===========================================================================
1485 ;;; Functions to create and reference automatic labels
1487 ;; The following constants are derived from reftex-label-alist
1489 ;; Prompt used for label type querys directed to the user
1490 (defconst reftex-type-query-prompt nil
)
1492 ;; Help string for label type querys
1493 (defconst reftex-type-query-help nil
)
1495 ;; Alist relating label type to reference format
1496 (defconst reftex-typekey-to-format-alist nil
)
1498 ;; Alist relating label type to label affix
1499 (defconst reftex-typekey-to-prefix-alist nil
)
1501 ;; Alist relating environments or macros to label type and context regexp
1502 (defconst reftex-env-or-mac-alist nil
)
1504 ;; List of macros carrying a label
1505 (defconst reftex-label-mac-list nil
)
1507 ;; List of environments carrying a label
1508 (defconst reftex-label-env-list nil
)
1510 ;; List of all typekey letters in use
1511 (defconst reftex-typekey-list nil
)
1513 ;; Alist relating magic words to a label type
1514 (defconst reftex-words-to-typekey-alist nil
)
1516 ;; The last list-of-labels entry used in a reference
1517 (defvar reftex-last-used-reference
(list nil nil nil nil
))
1519 ;; The regular expression used to abbreviate words
1520 (defconst reftex-abbrev-regexp
1523 (make-string (nth 0 reftex-abbrev-parameters
) ?.
)
1524 "[" (nth 2 reftex-abbrev-parameters
) "]*"
1526 "[" (nth 3 reftex-abbrev-parameters
) "]"
1527 (make-string (1- (nth 1 reftex-abbrev-parameters
)) ?.
)))
1529 ;; Global variables used for communication between functions
1530 (defvar reftex-default-context-position nil
)
1531 (defvar reftex-location-start nil
)
1532 (defvar reftex-call-back-to-this-buffer nil
)
1534 ;; List of buffers created temporarily for lookup, which should be killed
1535 (defvar reftex-buffers-to-kill nil
)
1537 ;; The regexp used to find section statements
1538 (defconst reftex-section-regexp
"^[ ]*\\\\\\(part\\|chapter\\|section\\|subsection\\|subsubsection\\|paragraph\\|subparagraph\\|subsubparagraph\\)\\*?\\(\\[[^]]*\\]\\)?{")
1540 ;; LaTeX section commands and level numbers
1541 (defconst reftex-section-levels
1547 ("subsubsection" .
4)
1549 ("subparagraph" .
6)
1550 ("subsubparagraph" .
7)
1553 (defun reftex-label (&optional environment no-insert
)
1554 "Insert a unique label. Return the label.
1555 If ENVIRONMENT is given, don't bother to find out yourself.
1556 If NO-INSERT is non-nil, do not insert label into buffer.
1557 With prefix arg, force to rescan document first.
1558 The label is also inserted into the label list.
1559 This function is controlled by the settings of reftex-insert-label-flags."
1563 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4)
1564 (reftex-access-scan-info current-prefix-arg
)
1566 ;; Find out what kind of environment this is and abort if necessary
1567 (if (or (not environment
)
1568 (not (assoc environment reftex-env-or-mac-alist
)))
1569 (setq environment
(reftex-label-location)))
1570 (if (not environment
)
1571 (error "Can't figure out what kind of label should be inserted"))
1574 (let (label num typekey prefix entry cell lab valid default force-prompt
)
1575 (setq typekey
(nth 1 (assoc environment
1576 reftex-env-or-mac-alist
)))
1577 (setq prefix
(or (cdr (assoc typekey reftex-typekey-to-prefix-alist
))
1578 (concat typekey
"-")))
1580 ;; make a default label
1583 ((reftex-typekey-check typekey
(nth 0 reftex-insert-label-flags
))
1584 ;; derive a label from context
1585 (setq default
(nth 2 (reftex-label-info " ")))
1586 ;; catch the cases where the is actually no context available
1587 (if (or (string-match "NO MATCH FOR CONTEXT REGEXP" default
)
1588 (string-match "ILLEGAL VALUE OF PARSE" default
)
1589 (string-match "SECTION HEADING NOT FOUND" default
)
1590 (string-match "HOOK ERROR" default
)
1591 (string-match "^[ \t]*$" default
))
1592 (setq default prefix
1593 force-prompt t
) ; need to prompt
1594 (setq default
(concat prefix
(reftex-string-to-label default
)))
1597 (setq label default
)
1599 (while (assoc label
(symbol-value reftex-list-of-labels-symbol
))
1600 (setq label
(concat default
"-" (setq num
(1+ num
)))))
1601 (setq default label
)))
1603 ((reftex-typekey-check typekey
(nth 1 reftex-insert-label-flags
)) ; prompt
1604 ;; Minimal default: the user will be prompted
1605 (setq default prefix
))
1608 ;; make an automatic label
1610 (setq default
(concat prefix
(reftex-next-label-number typekey
)))
1611 (symbol-value reftex-list-of-labels-symbol
)))))
1613 ;; Should we ask the user?
1614 (if (or (reftex-typekey-check typekey
1615 (nth 1 reftex-insert-label-flags
)) ; prompt
1619 ;; iterate until we get a legal label
1621 (setq label
(read-string "Label: " default
))
1623 ;; Lets make sure that this is a legal label
1626 ;; Test if label contains strange characters
1627 ((string-match reftex-label-illegal-re label
)
1628 (message "Label \"%s\" contains illegal characters" label
)
1632 ;; Look it up in the label list
1633 ((setq entry
(assoc label
1634 (symbol-value reftex-list-of-labels-symbol
)))
1635 (message "Label \"%s\" exists in file %s" label
(nth 3 entry
))
1642 (setq label default
))
1646 (insert "\\label{" label
"}"))
1648 ;; Insert the label into the label list
1649 (if (symbol-value reftex-list-of-labels-symbol
)
1652 (all (symbol-value reftex-list-of-labels-symbol
))
1656 (file (buffer-file-name)))
1658 ;; find the previous label in order to know where to insert new label
1661 (if (re-search-backward "\\\\label{\\([^}]+\\)}" nil
1 2)
1662 (setq look-for
(reftex-no-props (match-string 1))))
1663 (if (or (re-search-forward
1664 "\\\\\\(include\\|input\\){[^}\n]+}" pos t
)
1665 (re-search-forward reftex-section-regexp pos t
)
1667 (setq note
"POSITION UNCERTAIN. RESCAN TO FIX.")))
1669 (set reftex-list-of-labels-symbol
1670 (cons (list label typekey text file note
)
1671 (symbol-value reftex-list-of-labels-symbol
)))
1673 (setq cell
(car all
)
1677 (if (string= lab look-for
)
1681 (symbol-value reftex-list-of-labels-symbol
))
1682 (cons (list label typekey text file note
)
1684 cnt
(symbol-value reftex-list-of-labels-symbol
))))
1685 ;; to end the loop, set all to nil
1686 (setq all nil
)))))))
1687 ;; return value of the function is the label
1690 (defun reftex-string-to-label (string)
1691 ;; Convert a string (a sentence) to a label.
1693 ;; Uses reftex-derive-label-parameters and reftex-abbrev-parameters
1696 (let* ((words0 (reftex-split "[- \t\n\r]+"
1697 (reftex-no-props string
)))
1698 (ignore-words (nth 5 reftex-derive-label-parameters
))
1701 ;; remove words from the ignore list or with funny characters
1703 (setq word
(car words0
) words0
(cdr words0
))
1705 ((member (downcase word
) ignore-words
))
1706 ((string-match reftex-label-illegal-re word
)
1707 (if (nth 2 reftex-derive-label-parameters
)
1709 (while (string-match reftex-label-illegal-re word
)
1710 (setq word
(replace-match "" nil nil word
)))
1711 (setq words
(cons word words
)))))
1713 (setq words
(cons word words
)))))
1714 (setq words
(nreverse words
))
1716 ;; restrict number of words
1717 (if (> (length words
) (nth 0 reftex-derive-label-parameters
))
1718 (setcdr (nthcdr (1- (nth 0 reftex-derive-label-parameters
)) words
) nil
))
1720 ;; First, try to use all words
1721 (setq string
(mapconcat '(lambda(w) w
) words
1722 (nth 4 reftex-derive-label-parameters
)))
1724 ;; Abbreviate words if enforced by user settings or string length
1725 (if (or (eq t
(nth 3 reftex-derive-label-parameters
))
1726 (and (nth 3 reftex-derive-label-parameters
)
1727 (> (length string
) (nth 1 reftex-derive-label-parameters
))))
1730 '(lambda (w) (if (string-match reftex-abbrev-regexp w
)
1734 string
(mapconcat '(lambda(w) w
) words
1735 (nth 4 reftex-derive-label-parameters
))))
1737 ;; Shorten if still to long
1739 (if (> (length string
) (nth 1 reftex-derive-label-parameters
))
1740 (substring string
0 (nth 1 reftex-derive-label-parameters
))
1743 ;; Delete the final punctuation, if any
1744 (if (string-match "[^a-zA-Z0-9]+$" string
)
1745 (setq string
(replace-match "" nil nil string
)))
1748 (defun reftex-label-location (&optional bound
)
1749 ;; Return the environment or macro which determines the label type at point.
1750 ;; If optional BOUND is an integer, limit backward searches to that point.
1752 (let* ((loc1 (reftex-what-macro reftex-label-mac-list bound
))
1753 (loc2 (reftex-what-environment reftex-label-env-list bound
))
1754 (p1 (or (cdr loc1
) 0))
1755 (p2 (or (cdr loc2
) 0)))
1757 (setq reftex-location-start
(max p1 p2
))
1760 (setq reftex-default-context-position p1
)
1762 (setq reftex-default-context-position
1763 (+ p2
8 (length (car loc2
))))
1764 (or (car loc2
) "section"))))
1767 (defun reftex-next-label-number (type)
1768 ;; Increment value of automatic labels in current buffer. Return new value.
1770 ;; Ensure access to scanning info
1771 (reftex-access-scan-info)
1773 (let ((n (cdr (assoc type
(symbol-value reftex-label-numbers-symbol
)))))
1774 (if (not (integerp n
))
1775 ;; oops - type not known - make one here
1777 (set reftex-label-numbers-symbol
1779 (symbol-value reftex-label-numbers-symbol
)))
1782 (setcdr (assoc type
(symbol-value reftex-label-numbers-symbol
)) n
)
1785 ;; Help string for the reference label menu
1786 (defconst reftex-reference-label-help
1787 " AVAILABLE KEYS IN REFERENCE LABEL MENU
1788 ======================================
1789 n / p Go to next/previous label (Cursor motion works as well)
1790 r / s Rescan document for labels / Switch label type
1791 t / # Toggle table of contents / Toggle counter mode
1792 c Toggle display of short context
1793 SPACE Show full context for current label in other window
1794 f Toggle follow mode: other window will follow context
1795 a / q Use last referenced label / Quit without accepting label
1796 ? / C-r Display this help message / Recursive Edit into other window
1797 RETURN Accept current label")
1799 (defun reftex-reference (&optional type no-insert
)
1800 "Make a LaTeX reference. Look only for labels of a certain TYPE.
1801 With prefix arg, force to rescan buffer for labels. This should only be
1802 necessary if you have recently entered labels yourself without using
1803 reftex-label. Rescanning of the buffer can also be requested from the
1804 label selection menu.
1805 The function returns the selected label or nil.
1806 If NO-INSERT is non-nil, do not insert \\ref command, just return label.
1807 When called with 2 C-u prefix args, disable magic word recognition."
1811 ;; check for active recursive edits
1812 (reftex-check-recursive-edit)
1814 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4)
1815 (reftex-access-scan-info current-prefix-arg
)
1818 ;; guess type from context
1819 (if (and reftex-guess-label-type
1820 (not (= 16 (prefix-numeric-value current-prefix-arg
)))
1821 (setq type
(assoc (downcase (reftex-word-before-point))
1822 reftex-words-to-typekey-alist
)))
1823 (setq type
(cdr type
))
1824 (setq type
(reftex-query-label-type))))
1827 (form (or (cdr (assoc type reftex-typekey-to-format-alist
))
1830 ;; Have the user select a label
1831 (setq pair
(reftex-offer-label-menu type
))
1832 (setq label
(car pair
))
1837 ;; do we need to remove spaces?
1838 (if (string= "~" (substring form
0 1))
1839 (while (or (= (preceding-char) ?\
)
1840 (= (preceding-char) ?\C-i
))
1841 (backward-delete-char 1)))
1842 ;; ok, insert the reference
1843 (insert (format form label label
))
1849 (defun reftex-goto-label (&optional arg
)
1850 "Go to a LaTeX label. With prefix ARG: go to label in another window."
1852 (let (type label file pair
)
1854 (setq type
(reftex-query-label-type)))
1856 (setq pair
(reftex-offer-label-menu type
)
1859 (if (and label file
(file-exists-p file
))
1862 (find-file-other-window file
)
1864 (goto-char (point-min))
1865 (if (not (search-forward (concat "\\label{" label
"}") nil t
))
1866 (error "No such label found: %s" label
)
1867 (reftex-highlight 0 (match-beginning 0) (match-end 0))
1868 (add-hook 'pre-command-hook
'reftex-highlight-shall-die
)))
1872 ;; Internal list with index numbers of labels in the selection menu
1873 (defvar reftex-label-index-list nil
)
1875 (defun reftex-offer-label-menu (typekey)
1876 ;; Offer a menu with the appropriate labels. Return (label . file).
1877 (let* ((buf (current-buffer))
1878 (near-label (reftex-find-nearby-label))
1879 (toc (reftex-typekey-check typekey reftex-label-menu-flags
0))
1880 (context (not (reftex-typekey-check
1881 typekey reftex-label-menu-flags
3)))
1882 (counter (reftex-typekey-check
1883 typekey reftex-label-menu-flags
2))
1884 (follow (reftex-typekey-check
1885 typekey reftex-label-menu-flags
4))
1886 offset rtn key cnt entry
)
1888 (setq reftex-call-back-to-this-buffer buf
)
1889 (setq entry
(cons nil nil
))
1894 (save-window-excursion
1895 (switch-to-buffer-other-window "*RefTeX Select*")
1897 (setq truncate-lines t
)
1898 (setq reftex-label-index-list
(reftex-make-and-insert-label-list
1899 typekey buf toc context counter
1901 (setq near-label
"_ ") ; turn off search for near label
1902 (setq offset
(or (car reftex-label-index-list
) offset
))
1903 ;; use only when searched
1904 (setq reftex-label-index-list
(cdr reftex-label-index-list
))
1905 ;; only this is the true list
1906 (if (not reftex-label-index-list
)
1907 (error "No labels of type \"%s\"" typekey
))
1911 "Label: [n]ext [p]rev [r]escan [t]oc [ ]context [q]uit RETURN [?]HELP+more"
1915 reftex-reference-label-help
1916 '(?r ?c ?t ?s ?
# ?a
)
1918 'reftex-select-label-callback follow
))
1922 (if (not key
) (throw 'exit nil
))
1926 (reftex-parse-document buf
))
1928 ;; toggle context mode
1929 (setq context
(not context
)))
1932 (setq typekey
(reftex-query-label-type)))
1934 ;; toggle tabel of contents display
1935 (setq toc
(not toc
)))
1937 ;; toggle counter display
1938 (setq counter
(not counter
)))
1940 ;; reuse the last referenced label again
1941 (setq entry reftex-last-used-reference
)
1945 (setq entry
(nth (nth cnt reftex-label-index-list
)
1946 (symbol-value reftex-list-of-labels-symbol
)))
1947 (setq reftex-last-used-reference entry
)
1948 (throw 'exit t
))))))
1949 (kill-buffer "*RefTeX Select*")
1950 (reftex-kill-temporary-buffers))
1951 (cons (reftex-no-props (nth 0 entry
)) (nth 3 entry
))))
1953 ;; Indentation for table of context lines in the menu
1954 (defconst reftex-toc-indent
" ")
1955 ;; Indentation for the lines containing the label
1956 (defconst reftex-label-indent
"> ")
1957 ;; Indentation for context lines
1958 (defconst reftex-context-indent
". ")
1959 ;; Indentation per section level
1960 (defvar reftex-level-indent
2
1961 "*Number of spaces to be used for indentation per section level.
1962 With more indentation, the label menu looks nicer, but shows less context.
1963 Changing this is only fully operational after the next buffer scan.")
1965 (defun reftex-make-and-insert-label-list (typekey0 buf toc context
1967 ;; Insert a menu of all labels in buffer BUF into current buffer.
1968 ;; Return the list of labels, with the index of NEAR-LABEL as extra car.
1969 (let (ins-list index-list offset
)
1973 (font (reftex-use-fonts))
1977 (toc-indent reftex-toc-indent
)
1979 (concat reftex-label-indent
1980 (if toc
(make-string (* 7 reftex-level-indent
) ?\
) "")))
1982 (concat reftex-context-indent
1983 (if toc
(make-string (* 7 reftex-level-indent
) ?\
) "")))
1984 cell text label typekey note comment
)
1986 ; Ensure access to scanning info
1987 (reftex-access-scan-info)
1989 (setq all
(symbol-value reftex-list-of-labels-symbol
))
1993 (setq index
(1+ index
)
1997 (if (null (nth 2 cell
))
1998 ;; No context yet. Quick update
2000 (setq cell
(reftex-label-info-update cell
))
2001 (setcar (nthcdr index
2002 (symbol-value reftex-list-of-labels-symbol
))
2005 ;; in the following setq we *copy* the label, since we will change
2006 ;; its properties, and we cannot have any properties in the list
2007 ;; (because of assoc searches)
2008 (setq label
(copy-sequence (nth 0 cell
))
2009 typekey
(nth 1 cell
)
2013 comment
(get-text-property 0 'in-comment text
))
2015 (if (string= label near-label
)
2016 (setq offset
(1+ cnt
)))
2019 ((and toc
(string= typekey
"toc"))
2021 (cons (concat toc-indent text
"\n")
2023 ((string= typekey
"toc"))
2024 ((and (or (string= typekey typekey0
) (string= typekey0
" "))
2025 (or (nth 5 reftex-label-menu-flags
) ; show-commented?
2028 (if comment
(setq label
(concat "% " label
)))
2034 'font-lock-comment-face
2035 'font-lock-reference-face
)
2037 (setq index-list
(cons index index-list
))
2042 (if counter
(format " (%d) " cnt
))
2043 (if comment
" LABEL IS COMMENTED OUT ")
2044 (if note
(concat " " note
) "")
2046 (if context
(concat context-indent text
"\n")))
2050 (apply 'insert
(nreverse ins-list
))
2051 (cons offset
(nreverse index-list
))))
2053 (defun reftex-query-label-type ()
2054 ;; Ask for label type
2055 (message reftex-type-query-prompt
)
2056 (let ((key (read-char)))
2059 (save-window-excursion
2060 (with-output-to-temp-buffer "*RefTeX Help*"
2061 (princ reftex-type-query-help
))
2062 (setq key
(read-char))
2063 (kill-buffer "*RefTeX Help*"))))
2064 (if (not (member (char-to-string key
) reftex-typekey-list
))
2065 (error "No such label type: %s" (char-to-string key
)))
2066 (char-to-string key
)))
2068 (defun reftex-find-nearby-label ()
2069 ;; Find a nearby label.
2071 (if (or (re-search-backward "\\\\label{\\([^}]+\\)}" nil t
)
2072 (re-search-forward "\\\\label{\\([^}]+\\)}" nil t
))
2073 (reftex-no-props (match-string 1))
2076 ;; Variable holding the vector with section numbers
2077 (defvar reftex-section-numbers
[0 0 0 0 0 0 0 0])
2079 (defun reftex-scan-buffer-for-labels (label-numbers-symbol label-list-symbol
)
2080 ;; Scan the buffer for labels and save them in a list.
2082 (let ((regexp (concat "\\\\label{\\([^}]*\\)}" "\\|"
2083 reftex-section-regexp
))
2084 (font (reftex-use-fonts))
2087 file
(level 1) start star text text1 label section-number macro find
)
2088 (set label-list-symbol nil
)
2091 ;; reset label numbers
2092 (set label-numbers-symbol
2093 (mapcar '(lambda(x) (cons x
0)) reftex-typekey-list
))
2095 ;; reset section numbers
2096 (reftex-section-number reftex-section-numbers -
1)
2098 (while (re-search-forward regexp nil t
)
2099 (setq file
(get-text-property (match-beginning 0) 'file
))
2100 (if (string= (buffer-substring (match-beginning 0)
2101 (+ 7 (match-beginning 0))) "\\label{")
2104 (setq label
(reftex-no-props (match-string 1)))
2105 (set label-list-symbol
2106 (cons (reftex-label-info label file bound
)
2107 (symbol-value label-list-symbol
))))
2110 (setq bound
(point))
2111 (setq star
(= ?
* (char-after (match-end 2))))
2112 (setq find
(buffer-substring-no-properties
2113 (1- (match-beginning 2)) (match-end 0)))
2114 (setq macro
(reftex-no-props (match-string 2)))
2115 (setq level
(cdr (assoc macro reftex-section-levels
)))
2117 (setq section-number
(reftex-section-number
2118 reftex-section-numbers level star
))
2119 (setq highest-level
(min highest-level level
))
2120 (if (= level highest-level
)
2122 "Scanning %s %s ..."
2123 (car (nth level reftex-section-levels
))
2128 (setq text1
(reftex-context-substring))
2129 (setq text
(reftex-nicify-text text1
)))
2131 (setq find
(reftex-allow-for-ctrl-m (concat find text1
)))
2133 ;; add section number and indentation
2136 (make-string (* reftex-level-indent level
) ?\
)
2137 (if (nth 1 reftex-label-menu-flags
) ; section number flag
2138 (concat section-number
" "))
2141 (if font
(put-text-property 0 (length text
)
2142 'face
'font-lock-comment-face text
))
2145 (set label-list-symbol
2146 (cons (list nil
"toc" text file find
)
2147 (symbol-value label-list-symbol
)))))
2148 (set label-list-symbol
2149 (nreverse (symbol-value label-list-symbol
))))))
2152 (defun reftex-label-info-update (cell)
2153 ;; Update information about just one label in a different file.
2154 ;; CELL contains the old info list
2155 (let* ((label (nth 0 cell
))
2156 (typekey (nth 1 cell
))
2160 (buf (reftex-get-file-buffer-force
2161 file
(not reftex-keep-temporary-buffers
))))
2163 (list label typekey
"" file
"LOST LABEL. RESCAN TO FIX.")
2170 (if (re-search-forward (concat "\\\\label{" (regexp-quote label
) "}")
2172 (append (reftex-label-info label file
) (list note
))
2173 (list label typekey
"" file
"LOST LABEL. RESCAN TO FIX.")))))))
2175 (defun reftex-label-info (label &optional file bound
)
2176 ;; Return info list on LABEL at point.
2177 (let* ((env-or-mac (reftex-label-location bound
))
2178 (typekey (nth 1 (assoc env-or-mac reftex-env-or-mac-alist
)))
2179 (file (or file
(buffer-file-name)))
2180 (parse (if (reftex-typekey-check
2181 typekey reftex-use-text-after-label-as-context
)
2183 (nth 2 (assoc env-or-mac reftex-env-or-mac-alist
))))
2184 (text (reftex-short-context env-or-mac parse reftex-location-start
)))
2185 (if (reftex-in-comment)
2186 (put-text-property 0 1 'in-comment t text
))
2187 (list label typekey text file
)))
2189 (defun reftex-in-comment ()
2191 (skip-chars-backward "^%\n\r")
2192 (= (preceding-char) ?%
)))
2194 (defun reftex-short-context (env parse
&optional bound
)
2195 ;; Get about one line of useful context for the label definition at point.
2203 (reftex-context-substring)))
2206 (if (string= env
"section")
2207 ;; special treatment for section labels
2209 (if (re-search-backward reftex-section-regexp
(point-min) t
)
2211 (goto-char (match-end 0))
2212 (reftex-context-substring))
2213 "SECTION HEADING NOT FOUND"))
2215 (goto-char reftex-default-context-position
)
2216 (reftex-context-substring))))
2220 (if (re-search-backward parse bound t
)
2222 (goto-char (match-end 0))
2223 (reftex-context-substring))
2224 "NO MATCH FOR CONTEXT REGEXP")))
2226 ;; A hook function. Call it.
2228 (condition-case error-var
2230 ('error
(format "HOOK ERROR: %s" (cdr error-var
))))))
2232 "ILLEGAL VALUE OF PARSE"))))
2234 (defun reftex-context-substring ()
2235 ;; Return up to 100 chars from point
2236 ;; When point is just after a { or [, limit string to matching parenthesis
2238 ((or (= (preceding-char) ?\
{)
2239 (= (preceding-char) ?\
[))
2240 ;; inside a list - get only the list, with modified syntax to be perfect
2243 (min (+ 100 (point))
2249 ('error
(point-max))))))
2251 ;; no list - just grab 100 characters
2252 (buffer-substring (point) (min (+ 100 (point)) (point-max))))))
2254 (defun reftex-section-number (section-numbers &optional level star
)
2255 ;; Return a string with the current section number.
2256 ;; When LEVEL is non-nil, increase section numbers on that level.
2257 (let* ((depth 6) idx n
(string ""))
2260 (if (and (> level -
1) (not star
))
2261 (aset section-numbers level
(1+ (aref section-numbers level
))))
2262 (setq idx
(1+ level
))
2263 (while (<= idx depth
)
2264 (aset section-numbers idx
0)
2265 (setq idx
(1+ idx
)))))
2267 (while (<= idx depth
)
2268 (setq n
(aref section-numbers idx
))
2269 (setq string
(concat string
(if (not (string= string
"")) "." "")
2271 (setq idx
(1+ idx
)))
2273 (if (string-match "\\`\\(0\\.\\)+" string
)
2274 (setq string
(replace-match "" nil nil string
)))
2275 (if (string-match "\\(\\.0\\)+\\'" string
)
2276 (setq string
(replace-match "" nil nil string
))))
2278 (concat (make-string (1- (length string
)) ?\
) "*")
2281 ;; A variable to remember the index of the last label context shown
2282 (defvar reftex-last-cnt
0)
2284 (defun reftex-select-label-callback (cnt)
2285 ;; Callback function called from the label selection in order to
2286 ;; show context in another window
2287 (let* ((this-window (selected-window))
2288 index entry label file buffer
)
2289 ;; pop to original buffer in order to get correct variables
2292 (set-buffer reftex-call-back-to-this-buffer
)
2293 (setq index
(nth (or cnt
1) reftex-label-index-list
)
2294 entry
(nth index
(symbol-value reftex-list-of-labels-symbol
))
2296 file
(nth 3 entry
)))
2298 ;; goto the file in another window
2299 (setq buffer
(reftex-get-file-buffer-force
2300 file
(not reftex-keep-temporary-buffers
)))
2302 ;; good - the file is available
2303 (switch-to-buffer-other-window buffer
)
2304 ;; we have got a problem here. The file does not exist.
2305 ;; Let' get out of here..
2310 ;; search for that label
2311 (if (not (and (integerp cnt
)
2312 (integerp reftex-last-cnt
)
2313 (if (> cnt reftex-last-cnt
)
2314 (search-forward (concat "\\label{" label
"}") nil t
)
2315 (search-backward (concat "\\label{" label
"}") nil t
))))
2318 (search-forward (concat "\\label{" label
"}") nil t
)))
2319 (reftex-highlight 0 (match-beginning 0) (match-end 0))
2321 (recenter (/ (window-height) 2))
2322 (select-window this-window
))))
2324 (defun reftex-pop-to-label (label file-list
&optional mark-to-kill highlight
)
2325 ;; Find LABEL in any file in FILE-LIST in another window.
2326 ;; If mark-to-kill is non-nil, mark new buffer for killing.
2327 ;; If HIGHLIGHT is non-nil, highlight the label definition.
2328 (let* ((re (concat "\\\\label{" (regexp-quote label
) "}"))
2332 (setq file
(car file-list
)
2333 file-list
(cdr file-list
))
2334 (if (not (setq buf
(reftex-get-file-buffer-force file mark-to-kill
)))
2335 (error "No such file %s" file
))
2338 (goto-char (point-min))
2339 (if (re-search-forward re nil t
)
2341 (switch-to-buffer-other-window buf
)
2342 (goto-char (match-beginning 0))
2343 (recenter (/ (window-height) 2))
2345 (reftex-highlight 0 (match-beginning 0) (match-end 0)))
2346 (throw 'exit
(selected-window)))))
2347 (error "Label %s not found" label
))))
2349 (defun reftex-find-duplicate-labels ()
2350 "Produce a list of all duplicate labels in the document."
2354 ;; Rescan the document to make sure
2355 (reftex-access-scan-info t
)
2357 (let ((master (reftex-TeX-master-file))
2364 (setq x1
(reftex-all-assoc-string
2365 (car x
) (symbol-value reftex-list-of-labels-symbol
)))
2366 (if (< 1 (length x1
))
2367 (append (list (reftex-no-props (car x
)))
2369 (abbreviate-file-name (nth 3 x
))) x1
))
2372 (reftex-uniquify (symbol-value reftex-list-of-labels-symbol
)))))
2373 (setq dlist
(reftex-uniquify dlist
))
2374 (if (null dlist
) (error "No duplicate labels in document"))
2375 (switch-to-buffer-other-window "*Duplicate Labels*")
2376 (make-local-variable 'TeX-master
)
2377 (setq TeX-master master
)
2379 (insert " MULTIPLE LABELS IN CURRENT DOCUMENT:\n")
2380 (insert " Move point to label and type `M-x reftex-change-label'\n"
2381 " This will run a query-replace on the label and its references\n")
2382 (insert " LABEL FILE\n")
2383 (insert " -------------------------------------------------------------\n")
2385 (if (and (car (car dlist
))
2388 (insert (mapconcat '(lambda(x) x
) (car dlist
) "\n ") "\n")))
2389 (setq dlist
(cdr dlist
)))
2390 (goto-char (point-min))))
2392 (defun reftex-all-assoc-string (key list
)
2393 ;; Return a list of all associations of KEY in LIST. Comparison with string=
2396 (if (string= (car (car list
)) key
)
2397 (setq rtn
(cons (car list
) rtn
)))
2398 (setq list
(cdr list
)))
2401 (defun reftex-kill-temporary-buffers ()
2402 ;; Kill all buffers in the list reftex-kill-temporary-buffers.
2403 (while reftex-buffers-to-kill
2404 (if (bufferp (car reftex-buffers-to-kill
))
2406 (and (buffer-modified-p (car reftex-buffers-to-kill
))
2407 (y-or-n-p (format "Save file %s? "
2409 (car reftex-buffers-to-kill
))))
2411 (set-buffer (car reftex-buffers-to-kill
))
2413 (kill-buffer (car reftex-buffers-to-kill
))))
2414 (setq reftex-buffers-to-kill
(cdr reftex-buffers-to-kill
))))
2416 (defun reftex-show-entry ()
2417 ;; Show entry if point is hidden by outline mode
2418 (let ((pos (point)))
2419 (if (and reftex-auto-show-entry
2420 (boundp 'outline-minor-mode
)
2422 (looking-at "[^\n\r]*\r"))
2424 (outline-back-to-heading)
2429 (defun reftex-nicify-text (text)
2430 ;; Make TEXT nice for inclusion into label menu
2431 (while (string-match "[\n\r\t]\\|[ \t][ \t]+" text
) ; remove extra whitespace
2432 (setq text
(replace-match " " nil t text
)))
2433 (if (string-match "\\\\end{.*" text
) ; nothing beyond \end{
2434 (setq text
(replace-match "" nil t text
)))
2435 (if (string-match "\\\\label{[^}]*}" text
) ; kill the label
2436 (setq text
(replace-match "" nil t text
)))
2437 (if (string-match "^ +" text
) ; leading whitespace
2438 (setq text
(replace-match "" nil t text
)))
2440 ((> (length text
) 100) ; not to long
2441 (setq text
(substring text
0 100)))
2442 ((= (length text
) 0) ; not empty
2446 (defun reftex-typekey-check (typekey conf-variable
&optional n
)
2447 ;; Check if CONF-VARIABLE is true or contains TYPEKEY
2448 (and n
(setq conf-variable
(nth n conf-variable
)))
2449 (or (equal conf-variable t
)
2450 (and (stringp conf-variable
)
2451 (string-match (concat "[" conf-variable
"]") typekey
))))
2453 ;;; ===========================================================================
2455 ;;; Table of contents (contributed from Stephen Eglen, changed by C. Dominik)
2457 ;; We keep at most one *toc* buffer - it is easy to make them
2459 (defvar reftex-last-toc-master nil
2460 "Stores the name of the tex file that `reftex-toc' was last run on.")
2462 (defvar reftex-last-toc-file nil
2463 "Stores the file name from which `reftex-toc' was called. For redo command.")
2465 (defvar reftex-toc-return-marker
(make-marker)
2466 "Marker which makes it possible to return from toc to old position.")
2468 (defun reftex-toc ()
2469 "Show the table of contents for the current document.
2470 To see the corresponding part of the LaTeX document, use within the
2473 SPC Show the corresponding section of the LaTeX document
2474 RET Goto the section and hide the *toc* buffer
2475 q Hide the *toc* window and return to position of last reftex-toc command
2476 Q Kill the *toc* buffer and return to position of last reftex-toc command
2477 f Toggle follow mode on and off
2479 When called with a raw C-u prefix, rescan the document first."
2483 (and (not (string= reftex-last-toc-master
(reftex-TeX-master-file)))
2484 (get-buffer "*toc*")
2485 (kill-buffer "*toc*"))
2487 (setq reftex-last-toc-file
(buffer-file-name))
2488 (setq reftex-last-toc-master
(reftex-TeX-master-file))
2490 (set-marker reftex-toc-return-marker
(point))
2492 ;; if follow mode is active, arrange to delay it one command
2493 (if reftex-toc-follow-mode
2494 (setq reftex-toc-follow-mode
1))
2496 (if (and current-prefix-arg
2497 (get-buffer "*toc*"))
2498 (kill-buffer "*toc*"))
2500 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4)
2501 (reftex-access-scan-info current-prefix-arg
)
2503 (let* ((all (symbol-value reftex-list-of-labels-symbol
))
2504 (where (reftex-nearest-section))
2505 toc toc1 cell label file find startpos
)
2507 (if (and (get-buffer "*toc*")
2508 (get-buffer-window (get-buffer "*toc*")))
2509 (select-window (get-buffer-window (get-buffer "*toc*")))
2510 (delete-other-windows)
2511 (switch-to-buffer-other-window (current-buffer))
2512 (switch-to-buffer-other-window (get-buffer-create "*toc*")))
2515 ;; buffer is empty - fill it with the table of contents
2516 ((= (buffer-size) 0)
2518 (local-set-key " " 'reftex-toc-view-line
)
2519 (local-set-key "\C-m" 'reftex-toc-goto-line-and-hide
)
2520 (local-set-key "r" 'reftex-toc-redo
)
2521 (local-set-key "q" 'reftex-toc-quit
)
2522 (local-set-key "Q" 'reftex-toc-quit-and-kill
)
2523 (local-set-key "f" 'reftex-toc-toggle-follow
)
2524 (setq truncate-lines t
)
2525 (make-local-hook 'post-command-hook
)
2526 (make-local-hook 'pre-command-hook
)
2527 (setq post-command-hook
'(reftex-toc-post-command-hook))
2528 (setq pre-command-hook
'(reftex-toc-pre-command-hook))
2531 "TABLE-OF-CONTENTS on %s
2532 MENU: SPC=view RET=goto [q]uit [Q]uit+kill [r]escan [f]ollow-mode on/off
2533 -------------------------------------------------------------------------------
2534 " (abbreviate-file-name reftex-last-toc-master
)))
2535 (setq startpos
(point))
2537 (if (reftex-use-fonts)
2538 (put-text-property 1 (point) 'face
'font-lock-keyword-face
))
2539 (put-text-property 1 (point) 'intangible t
)
2542 (setq cell
(car all
)
2544 (setq label
(nth 0 cell
)
2550 (setq toc1
(concat toc
"\n"))
2551 (put-text-property 0 (length toc1
)
2553 (put-text-property 0 (length toc1
)
2558 (backward-delete-char 1)
2560 (setq buffer-read-only t
))
2564 (setq startpos
(point))))
2566 ;; Find the correct section
2567 (goto-char (point-max))
2569 (while (and (> (point) startpos
)
2570 (or (not (string= (get-text-property (point) 'file
)
2572 (not (string= (get-text-property (point) 'find
)
2574 (beginning-of-line 0))))
2576 (defun reftex-nearest-section ()
2577 ;; Return (file . find) of nearest section command
2578 (let (cell label rest
)
2581 ;; Try to find a section heading
2582 ((or (re-search-backward reftex-section-regexp nil t
)
2583 (re-search-forward reftex-section-regexp nil t
))
2584 (goto-char (match-end 0))
2585 (cons (buffer-file-name)
2586 (reftex-allow-for-ctrl-m
2587 (concat (buffer-substring-no-properties
2588 (1- (match-beginning 1)) (match-end 0))
2589 (reftex-context-substring)))))
2590 ;; Try to find a label
2591 ((and (or (re-search-backward "\\\\label{\\([^}]+\\)}" nil t
)
2592 (re-search-forward "\\\\label{\\([^}]+\\)}" nil t
))
2593 (setq label
(reftex-no-props (match-string 1)))
2594 (setq cell
(assoc label
(symbol-value
2595 reftex-list-of-labels-symbol
)))
2596 (setq rest
(memq cell
(symbol-value reftex-list-of-labels-symbol
)))
2597 (setq cell
(car (memq (assoc nil rest
) rest
)))
2599 (cons (nth 3 cell
) (nth 4 cell
)))
2602 (defun reftex-toc-pre-command-hook ()
2603 ;; used as pre command hook in *toc* buffer
2604 (reftex-unhighlight 0)
2605 (reftex-unhighlight 1))
2607 (defun reftex-toc-post-command-hook ()
2608 ;; used in the post-command-hook for the *toc* buffer
2612 (progn (beginning-of-line) (point))
2613 (progn (end-of-line) (point)))))
2615 ((integerp reftex-toc-follow-mode
)
2616 ;; remove delayed action
2617 (setq reftex-toc-follow-mode t
))
2618 (reftex-toc-follow-mode
2619 ;; show context in other window
2621 (reftex-toc-visit-line)
2624 (defun reftex-toc-toggle-follow ()
2625 "Toggle toc-follow mode.
2626 (it is not really a mode, just a flag)."
2628 (setq reftex-toc-follow-mode
(not reftex-toc-follow-mode
)))
2629 (defun reftex-toc-view-line ()
2630 "View document location in other window."
2632 (reftex-toc-visit-line))
2633 (defun reftex-toc-goto-line-and-hide ()
2634 "Go to document location in other window. Hide the *toc* window."
2636 (reftex-toc-visit-line 'hide
))
2637 (defun reftex-toc-quit ()
2638 "Hide the *toc* window and do not move point."
2641 (switch-to-buffer (marker-buffer reftex-toc-return-marker
))
2642 (goto-char (marker-position reftex-toc-return-marker
)))
2643 (defun reftex-toc-quit-and-kill ()
2644 "Kill the *toc* buffer."
2646 (kill-buffer "*toc*")
2648 (switch-to-buffer (marker-buffer reftex-toc-return-marker
))
2649 (goto-char (marker-position reftex-toc-return-marker
)))
2650 (defun reftex-toc-redo ()
2651 "Regenerate the *toc* buffer. Call only from within the *toc* buffer"
2653 (switch-to-buffer (reftex-get-file-buffer-force reftex-last-toc-file
))
2654 (delete-other-windows)
2655 (setq current-prefix-arg
'(4))
2658 (defun reftex-toc-visit-line (&optional final
)
2659 ;; Visit the tex file corresponding to the toc entry on the current line.
2660 ;; If FINAL is t, stay there
2661 ;; If FINAL is 'hide, hide the *toc* window.
2662 ;; Otherwise, move cursor back into *toc* window
2664 (let (file find beg end
(toc-window (selected-window)) show-window
)
2671 ;; get the file and the search string
2672 (setq file
(get-text-property (point) 'file
))
2673 (setq find
(get-text-property (point) 'find
))
2674 (if (or (not file
) (not find
))
2675 (error "Cannot visit line"))
2677 (switch-to-buffer-other-window (reftex-get-file-buffer-force file
))
2678 (setq show-window
(selected-window))
2679 (goto-char (point-min))
2681 (if (not (re-search-forward find nil t
))
2682 (error "Cannot visit line"))
2684 (setq beg
(match-beginning 0)
2689 (reftex-highlight 0 beg end
(current-buffer))
2691 (select-window toc-window
)
2693 ;; use the `final' parameter to decide what to do next
2696 (reftex-unhighlight 0)
2697 (select-window show-window
))
2699 (reftex-unhighlight 0)
2703 ;;; ===========================================================================
2705 ;;; BibTeX citations.
2707 ;; Variables and constants
2709 ;; Define variable to silence compiler warnings
2710 (defvar reftex-found-list
)
2712 ;; Internal variable, but used from different functions
2713 (defvar reftex-cite-format1 nil
)
2715 ;; The history list of regular expressions used for citations
2716 (defvar reftex-cite-regexp-hist nil
)
2718 ;; Help string for citation selection
2719 (defconst reftex-citation-help
2720 "AVAILABLE KEYS IN MAKE CITATION MENU
2721 ---------------------------------------
2722 n / p Go to next/previous entry (Cursor motion works as well)
2723 r restrict selection with another regexp
2724 SPACE Show full database entry in other window
2725 f Toggle follow mode: Other window will follow with full db entry
2726 q Quit without inserting \\cite macro into buffer
2727 ? Display this help message
2728 C-r Recursive edit into other window
2729 RETURN ... Accept current entry and insert in format according to
2730 reftex-cite-format")
2732 (defconst reftex-cite-format-default
"\\cite{KEY}"
2733 "The default value for reftex-cite-format.
2734 Uses the string version of scitex-cite-format.")
2736 (defconst reftex-cite-format-1-author-simple
2737 '( "\\cite{KEY}" "AUTHOR \\cite{KEY}" "AUTHOR {\it et al.} \\cite{KEY}")
2738 "Value for reftex-cite format establishing a simple citation with name
2739 of the first author.
2740 Uses the list version of reftex-cite-format.")
2742 (defconst reftex-cite-format-2-authors
2744 .
( "\\cite{KEY}" "AUTHOR \\cite{KEY}"
2745 "AUTHOR \\& AUTHOR \\cite{KEY}" "AUTHOR \\etal{} \\cite{KEY}"))
2747 .
("\\cite{KEY}" "AUTHOR, \\cite{KEY}"
2748 "AUTHOR \\& AUTHOR, \\cite{KEY}" "AUTHOR \\etal{}, \\cite{KEY}"))
2750 .
("\\cite{KEY}" "AUTHOR; \\cite{KEY}"
2751 "AUTHOR \\& AUTHOR; \\cite{KEY}" "AUTHOR \\etal{}; \\cite{KEY}"))
2753 .
("\\cite{KEY}" "AUTHOR: \\cite{KEY}"
2754 "AUTHOR \\& AUTHOR: \\cite{KEY}" "AUTHOR \\etal{}: \\cite{KEY}"))
2756 .
("(\\cite{KEY})" "AUTHOR (\\cite{KEY})"
2757 "AUTHOR \\& AUTHOR (\\cite{KEY})" "AUTHOR \\etal{} (\\cite{KEY})"))
2759 .
("[\\cite{KEY}]" "AUTHOR [\\cite{KEY}]"
2760 "AUTHOR \\& AUTHOR [\\cite{KEY}]" "AUTHOR \\etal{} [\\cite{KEY}]")))
2761 "Value for reftex-cite-format that estabishes an Author/Year citation
2762 where the year is supplied from BibTeX. Depending on which character
2763 is used during selection to accept the label, an extra ,;: or pair of
2764 parenthesis will be inserted.
2765 Uses the list-of-cons-cells version of reftex-cite-format.")
2767 ;; Find bibtex files
2769 (defun reftex-get-bibfile-list ()
2770 ;; Return list of bibfiles for current document
2772 ;; Ensure access to scanning info
2773 (reftex-access-scan-info)
2775 (or (symbol-value reftex-bibfile-list-symbol
)
2776 (error "No BibTeX files to parse. Add \\bibliography statment to document and reparse.")))
2778 (defun reftex-scan-buffer-for-bibliography-statement (bib-list-symbol)
2779 ;; Scan buffer for bibliography macro and store file list in bib-list-symbol.
2780 (let (file-list dir-list
)
2783 (concat path-separator
"+")
2784 (mapconcat '(lambda(x)
2785 (if (getenv x
) (getenv x
) ""))
2786 reftex-bibpath-environment-variables
2788 (goto-char (point-min))
2789 (if (re-search-forward "^[ \t]*\\\\bibliography{[ \t]*\\([^}]+\\)" nil t
)
2792 (cons (file-name-directory
2793 (get-text-property (match-beginning 0) 'file
))
2796 (mapcar '(lambda (x) (concat x
".bib"))
2798 reftex-bibfile-ignore-list
2801 (reftex-no-props (match-string 1)))))))
2802 (message "No \\bibliography command in document."))
2803 (set bib-list-symbol
2805 (reftex-find-files-on-path file-list dir-list
2806 "While parsing \\bibliography:")
2809 (defun reftex-find-files-on-path (file-list path-list
&optional error-string
)
2810 ;; Search for all files in FILE-LIST on the PATH-LIST. Return absolute names.
2811 ;; A missing file throws an exception with the error message ERROR-STRING.
2812 (let (found-list found file
)
2814 (setq file
(car file-list
)
2815 file-list
(cdr file-list
)
2817 (if (file-name-absolute-p file
)
2818 (setq found
(expand-file-name file
))
2819 (let ((dirs path-list
))
2820 (while (and dirs
(not found
))
2821 (if (and (not (string= (car dirs
) ""))
2822 (file-exists-p (expand-file-name file
(car dirs
))))
2823 (setq found
(expand-file-name file
(car dirs
))))
2824 (setq dirs
(cdr dirs
)))))
2826 (file-exists-p found
))
2827 (add-to-list 'found-list
(expand-file-name found
))
2828 (error "%s No such file %s."
2829 (or error-string
"") file
)))
2830 (nreverse found-list
)))
2832 ;; Find a certain reference in any of the BibTeX files.
2834 (defun reftex-pop-to-bibtex-entry (key file-list
2835 &optional mark-to-kill highlight
)
2836 ;; Find BibTeX KEY in any file in FILE-LIST in another window.
2837 ;; If mark-to-kill is non-nil, mark new buffer to kill."
2839 (let* ((re (concat "@[a-zA-Z]+[ \t\n\r]*{[ \t\n\r]*" (regexp-quote key
) "[ \t\n\r,]"))
2840 (window-conf (current-window-configuration))
2843 (switch-to-buffer-other-window (current-buffer))
2845 (setq file
(car file-list
)
2846 file-list
(cdr file-list
))
2847 (if (not (setq buf
(reftex-get-file-buffer-force file mark-to-kill
)))
2848 (error "No such file %s" file
))
2849 (switch-to-buffer buf
)
2852 (if (re-search-forward re nil t
)
2854 (goto-char (match-beginning 0))
2857 (reftex-highlight 0 (match-beginning 0) (match-end 0)))
2858 (throw 'exit
(selected-window)))))
2859 (set-window-configuration window-conf
)
2861 (message "No BibTeX entry with citation key %s" key
))))
2863 ;; Parse bibtex buffers
2865 (defun reftex-extract-bib-entries (buffers &optional get-word
)
2866 ;; Extract bib entries which match regexps from BUFFERS.
2867 ;; BUFFERS is a list of buffers or file names.
2868 ;; Return list with entries."
2869 (let* (re-list first-re rest-re
2870 ;; avoid fontification of lookup buffers
2871 (lazy-lock-minimum-size 1)
2872 (buffer-list (if (listp buffers
) buffers
(list buffers
)))
2873 found-list entry buffer1 buffer alist
2874 key-point start-point end-point
)
2876 (setq re-list
(reftex-split "[ \t]*&&[ \t]*"
2877 (read-string "RegExp [ && RegExp...]: "
2878 nil
'reftex-cite-regexp-hist
)))
2880 (setq first-re
(car re-list
) ; We'll use the first re to find things,
2881 rest-re
(cdr re-list
)) ; the other to narrow down.
2882 (if (string-match "\\`[ \t]*\\'" first-re
)
2883 (error "Empty regular expression"))
2886 (save-window-excursion
2888 ;; walk through all bibtex files
2890 (setq buffer
(car buffer-list
)
2891 buffer-list
(cdr buffer-list
))
2892 (if (and (bufferp buffer
)
2893 (buffer-live-p buffer
))
2894 (setq buffer1 buffer
)
2895 (setq buffer1
(reftex-get-file-buffer-force
2896 buffer
(not reftex-keep-temporary-buffers
))))
2898 (error "Cannot find BibTeX file %s" buffer
)
2899 (message "Scanning bibliography database %s" buffer1
))
2901 (set-buffer buffer1
)
2903 (goto-char (point-min))
2904 (while (re-search-forward first-re nil t
)
2905 (catch 'search-again
2906 (setq key-point
(point))
2907 (if (not (re-search-backward
2908 "^[ \t]*@\\([a-zA-Z]+\\)[ \t\n\r]*{" nil t
))
2909 (throw 'search-again nil
))
2910 (setq start-point
(point))
2911 (goto-char (match-end 0))
2914 ('error
(goto-char key-point
)
2915 (throw 'search-again nil
)))
2916 (setq end-point
(point))
2918 ;; Ignore @string, @comment and @c entries or things
2920 (if (or (string= (downcase (match-string 1)) "string")
2921 (string= (downcase (match-string 1)) "comment")
2922 (string= (downcase (match-string 1)) "c")
2923 (< (point) key-point
)) ; this means match not in {}
2925 (goto-char key-point
)
2926 (throw 'search-again nil
)))
2928 ;; Well, we have got a match
2930 (buffer-substring start-point
(point)) "\n"))
2932 ;; Check if other regexp match as well
2933 (setq re-list rest-re
)
2935 (if (not (string-match (car re-list
) entry
))
2937 (throw 'search-again nil
))
2938 (setq re-list
(cdr re-list
)))
2940 (setq alist
(reftex-parse-bibtex-entry
2941 nil start-point end-point
))
2942 (setq alist
(cons (cons "&entry" entry
) alist
))
2944 ;; check for crossref entries
2945 (if (assoc "crossref" alist
)
2948 alist
(reftex-get-crossref-alist alist
))))
2954 (reftex-format-bib-entry alist
))
2957 ;; add it to the list
2958 (setq found-list
(cons alist found-list
)))))
2959 (reftex-kill-temporary-buffers))))
2960 (setq found-list
(nreverse found-list
))
2964 ((eq 'author reftex-sort-bibtex-matches
)
2965 (sort found-list
'reftex-bib-sort-author
))
2966 ((eq 'year reftex-sort-bibtex-matches
)
2967 (sort found-list
'reftex-bib-sort-year
))
2968 ((eq 'reverse-year reftex-sort-bibtex-matches
)
2969 (sort found-list
'reftex-bib-sort-year-reverse
))
2972 (defun reftex-bib-sort-author (e1 e2
)
2973 (let ((al1 (reftex-get-bib-authors e1
)) (al2 (reftex-get-bib-authors e2
)))
2974 (while (and al1 al2
(string= (car al1
) (car al2
)))
2977 (if (and (stringp (car al1
))
2978 (stringp (car al2
)))
2979 (string< (car al1
) (car al2
))
2980 (not (stringp (car al1
))))))
2982 (defun reftex-bib-sort-year (e1 e2
)
2983 (< (string-to-int (cdr (assoc "year" e1
)))
2984 (string-to-int (cdr (assoc "year" e2
)))))
2986 (defun reftex-bib-sort-year-reverse (e1 e2
)
2987 (> (string-to-int (or (cdr (assoc "year" e1
)) "0"))
2988 (string-to-int (or (cdr (assoc "year" e2
)) "0"))))
2990 (defun reftex-get-crossref-alist (entry)
2991 ;; return the alist from a crossref entry
2992 (let ((crkey (cdr (assoc "crossref" entry
)))
2997 (if (re-search-forward
2998 (concat "@\\w+{[ \t\n\r]*" (regexp-quote crkey
) "[ \t\n\r]*,") nil t
)
3000 (setq start
(match-beginning 0))
3004 (reftex-parse-bibtex-entry nil start
(point)))
3007 ;; Parse and format individual entries
3009 (defun reftex-get-bib-authors (entry)
3010 ;; Return a list with the author names in ENTRY
3012 (setq authors
(reftex-get-bib-field "author" entry
))
3013 (if (equal "" authors
)
3014 (setq authors
(reftex-get-bib-field "editor" entry
)))
3015 (while (string-match "\\band\\b[ \t]*" authors
)
3016 (setq authors
(replace-match "\n" nil t authors
)))
3017 (while (string-match "[\\.a-zA-Z\\-]+\\.[ \t]*\\|,.*\\|[{}]+" authors
)
3018 (setq authors
(replace-match "" nil t authors
)))
3019 (while (string-match "^[ \t]+\\|[ \t]+$" authors
)
3020 (setq authors
(replace-match "" nil t authors
)))
3021 (while (string-match "[ \t][ \t]+" authors
)
3022 (setq authors
(replace-match " " nil t authors
)))
3023 (reftex-split "\n" authors
)))
3025 (defun reftex-parse-bibtex-entry (entry &optional from to
)
3026 (let (alist key start field
)
3031 (switch-to-buffer "*RefTeX-scratch*")
3036 (narrow-to-region from to
))
3037 (goto-char (point-min))
3039 (if (re-search-forward
3040 "@\\(\\w+\\)[ \t\n\r]*{[ \t\n\r]*\\([^ \t\n\r,]+\\)" nil t
)
3043 (cons "&type" (downcase (reftex-no-props (match-string 1))))
3044 (cons "&key" (reftex-no-props (match-string 2))))))
3045 (while (re-search-forward "\\(\\w+\\)[ \t\n\r]*=[ \t\n\r]*" nil t
)
3046 (setq key
(reftex-no-props (downcase (match-string 1))))
3048 ((= (following-char) ?
{)
3050 (setq start
(point))
3054 ((= (following-char) ?
\")
3056 (setq start
(point))
3057 (while (and (search-forward "\"" nil t
)
3058 (= ?
\\ (char-after (- (point) 2))))))
3060 (setq start
(point))
3061 (re-search-forward "[ \t\n\r,}]" nil
1)))
3062 (setq field
(buffer-substring-no-properties start
(1- (point))))
3063 ;; remove extra whitesp
3064 (while (string-match "[\n\t\r]\\|[ \t][ \t]+" field
)
3065 (setq field
(replace-match " " nil t field
)))
3066 ;; remove leading garbage
3067 (if (string-match "^[ \t{]+" field
)
3068 (setq field
(replace-match "" nil t field
)))
3069 ;; remove trailing garbage
3070 (if (string-match "[ \t}]+$" field
)
3071 (setq field
(replace-match "" nil t field
)))
3072 (setq alist
(cons (cons key field
) alist
)))
3075 (defun reftex-get-bib-field (fieldname entry
)
3076 ;; Extract the field FIELDNAME from an ENTRY
3077 (or (cdr (assoc fieldname entry
))
3080 (defun reftex-format-bib-entry (entry)
3081 ;; Format a BibTeX ENTRY so that it is nice to look at
3084 (auth-list (reftex-get-bib-authors entry
))
3085 (authors (mapconcat '(lambda (x) x
) auth-list
", "))
3086 (year (reftex-get-bib-field "year" entry
))
3087 (title (reftex-get-bib-field "title" entry
))
3088 (type (reftex-get-bib-field "&type" entry
))
3089 (key (reftex-get-bib-field "&key" entry
))
3092 ((equal type
"article")
3093 (concat (reftex-get-bib-field "journal" entry
) " "
3094 (reftex-get-bib-field "volume" entry
) ", "
3095 (reftex-get-bib-field "pages" entry
)))
3096 ((equal type
"book")
3097 (concat "book (" (reftex-get-bib-field "publisher" entry
) ")"))
3098 ((equal type
"phdthesis")
3099 (concat "PhD: " (reftex-get-bib-field "school" entry
)))
3100 ((equal type
"mastersthesis")
3101 (concat "Master: " (reftex-get-bib-field "school" entry
)))
3102 ((equal type
"inbook")
3103 (concat "Chap: " (reftex-get-bib-field "chapter" entry
)
3104 ", pp. " (reftex-get-bib-field "pages" entry
)))
3105 ((or (equal type
"conference")
3106 (equal type
"incollection")
3107 (equal type
"inproceedings"))
3108 (concat "in: " (reftex-get-bib-field "booktitle" entry
)))
3111 (if (> (length authors
) 30)
3112 (concat (substring authors
0 27) "...")
3113 (format "%-30s" authors
))
3115 (if (> (length title
) 70)
3116 (concat (substring title
0 67) "...")
3117 (format "%-70s" title
))
3119 (if (> (length extra
) 40)
3120 (concat (substring extra
0 37) "...")
3121 (format "%-40s" extra
)))
3122 (if (reftex-use-fonts)
3124 (put-text-property 0 (length authors
) 'face
'font-lock-keyword-face
3126 (put-text-property 0 (length title
) 'face
'font-lock-comment-face
3128 (put-text-property 0 (length extra
) 'face
'font-lock-reference-face
3130 (setq rtn
(concat key
"\n " authors
" " year
" " extra
3131 "\n " title
"\n\n"))
3136 (defun reftex-citation (&optional arg no-insert
)
3137 "Make a citation unsing BibTeX database files.
3138 After asking for a Regular Expression, it scans the buffers with
3139 bibtex entries (taken from the \\bibliography command) and offers the
3140 matching entries for selection. The selected entry is formated according
3141 to reftex-cite-format and inserted into the buffer.
3142 If NO-INSERT is non-nil, nothing is inserted, only the selected key returned.
3143 The regular expression uses an expanded syntax: && is interpreted as 'and'.
3144 Thus, aaaa&&bbb matches entries which contain both aaaa and bbb.
3145 When this function is called with point inside the braces of a \\cite
3146 command, it will add another key, ignoring the value of reftex-cite-format.
3147 When called with a numeric prefix, that many citations will be made and all
3148 put into the same \\cite command.
3149 When called with just C-u as prefix, enforces rescan of buffer for
3150 bibliography statement (e.g. if it was changed)."
3154 ;; check for recursive edit
3155 (reftex-check-recursive-edit)
3157 ;; if there is just 1 C-u prefix arg, force to rescan buffer
3158 (if (and current-prefix-arg
3159 (listp current-prefix-arg
)
3160 (= 4 (prefix-numeric-value arg
)))
3161 (reftex-reset-scanning-information))
3163 ;; check if there is already a cite command at point and change cite format
3164 ;; in order to only add another reference in the same cite command.
3165 (let ((pos (point)))
3166 (search-backward "\\" (point-min) 1)
3167 (if (and (looking-at "\\\\[a-zA-Z]*cite\\*?\\(\\[[^]]*\\]\\)*{\\([^}]*\\)")
3168 (>= (match-end 0) pos
)
3169 (>= pos
(match-beginning 2)))
3175 (setq reftex-cite-format1
3177 (if (not (or (= (preceding-char) ?
{)
3178 (= (preceding-char) ?
,)))
3182 (if (not (or (= (following-char) ?
})
3183 (= (following-char) ?
,)))
3187 (setq reftex-cite-format1
"KEY"))))
3188 (setq reftex-cite-format1
3189 (if (symbolp reftex-cite-format
)
3190 (symbol-value reftex-cite-format
)
3191 reftex-cite-format
))
3194 (let* (key entry cnt rtn ins-string re-list re
3195 ;; scan bibtex files
3196 (lazy-lock-minimum-size 1)
3197 (reftex-found-list (reftex-extract-bib-entries
3198 (reftex-get-bibfile-list)))
3201 (if (and (listp reftex-cite-format1
)
3202 (listp (car reftex-cite-format1
)))
3203 (mapcar 'car reftex-cite-format1
)
3205 (if (not reftex-found-list
)
3206 (error "Sorry, no matches found"))
3208 ;; remember where we came from
3209 (setq reftex-call-back-to-this-buffer
(current-buffer))
3212 (save-window-excursion
3213 (switch-to-buffer-other-window "*RefTeX Select*")
3215 (mapcar '(lambda (x) (insert (cdr (assoc "&formatted" x
))))
3217 (if (= 0 (buffer-size))
3218 (error "Sorry, no matches found"))
3219 (setq truncate-lines t
)
3227 "Select: [n]ext [p]rev [r]estrict [q]uit [?]Help ||"
3230 (mapconcat 'char-to-string accept-keys
" ")
3231 (error (error "Illegal reftex-cite-format"))))
3235 reftex-citation-help
3236 (cons ?r accept-keys
)
3238 'reftex-bibtex-selection-callback nil
))
3241 (if (not key
) (throw 'exit nil
))
3244 ;; restrict with new regular expression
3246 (reftex-split "[ \t]*&&[ \t]*"
3247 (read-string "RegExp [ && RegExp...]: "
3248 nil
'reftex-cite-regexp-hist
)))
3250 (setq re
(car re-list
)
3251 re-list
(cdr re-list
))
3256 (if (string-match re
3257 (cdr (assoc "&entry" x
)))
3260 reftex-found-list
))))
3262 (setq reftex-found-list found-list-r
)
3265 (mapcar '(lambda (x) (insert (cdr (assoc "&formatted" x
))))
3268 ((or (member key accept-keys
)
3270 (equal key
'return
))
3271 (setq entry
(nth cnt reftex-found-list
))
3277 (if (not (integerp key
)) (setq key ?\C-m
))
3278 (setq ins-string
(reftex-format-citation entry key
)))
3279 (setq ins-string
"")
3281 (kill-buffer "*RefTeX Select*")
3284 (insert ins-string
))
3287 ;; Check if the prefix arg was numeric, and call reftex-citation recursively
3288 (if (and (integerp arg
)
3291 "\\\\[a-zA-Z]*cite\\*?\\(\\[[^]]*\\]\\)*{\\([^}]*\\)" nil t
))
3293 (goto-char (match-end 0))
3295 (reftex-citation arg
))
3296 (reftex-kill-temporary-buffers))
3297 ;; Return the citation key
3298 (reftex-get-bib-field "&key" entry
)))
3300 (defun reftex-format-citation (entry key
)
3301 ;; Format a citation from the info in the BibTeX ENTRY
3302 (let* ((cite-key (reftex-get-bib-field "&key" entry
))
3303 (year (reftex-get-bib-field "year" entry
))
3304 (auth-list (reftex-get-bib-authors entry
))
3305 (nauthors (length auth-list
))
3309 ;; Find the correct format
3310 (if (and (listp reftex-cite-format1
)
3311 (listp (car reftex-cite-format1
)))
3312 (if (integerp (car (car reftex-cite-format1
)))
3313 (if (assoc key reftex-cite-format1
)
3314 (setq format
(cdr (assoc key reftex-cite-format1
)))
3315 (if (or (equal key ?\C-m
)
3316 (equal key
'return
))
3317 (setq format
(cdr (car reftex-cite-format1
)))
3318 (error "Error in reftex-cite-format")))
3319 (error "Error in reftex-cite-format"))
3320 (setq format reftex-cite-format1
))
3323 (let ((nn (min nauthors
(1- (length format
)))))
3324 (while (and (> nn
0) (string= "" (nth nn format
)))
3326 (setq format
(nth nn format
))))
3327 (if (stringp format
)
3328 (setq format format
)
3329 (setq format
"\\cite{KEY}"))
3331 ;; Insert the author names
3332 (while (string-match "\\bAUTHOR\\b" format
)
3333 (setq format
(replace-match (car auth-list
) t t format
))
3334 (setq auth-list
(cdr auth-list
)))
3335 (while (string-match "\\bKEY\\b" format
)
3336 (setq format
(replace-match cite-key t t format
)))
3337 (while (string-match "\\bYEAR\\b" format
)
3338 (setq format
(replace-match year t t format
)))
3341 ;; this is slow and not recommended for follow mode
3342 (defun reftex-bibtex-selection-callback (cnt)
3343 ;; Callback function to be called from the BibTeX selection, in
3344 ;; order to display context. This function is relatively slow and not
3345 ;; recommended for follow mode, just for individual lookups.
3346 (let ((win (selected-window))
3347 (key (reftex-get-bib-field "&key" (nth cnt reftex-found-list
)))
3348 (bibfile-list (save-excursion
3349 (set-buffer reftex-call-back-to-this-buffer
)
3350 (reftex-get-bibfile-list))))
3351 (reftex-pop-to-bibtex-entry key bibfile-list
3352 (not reftex-keep-temporary-buffers
) t
)
3353 (select-window win
)))
3355 ;;; ===========================================================================
3357 ;;; Here is the routine used for selection
3359 ;; Marker for return point from recursive edit
3360 (defvar reftex-recursive-edit-marker
(make-marker))
3362 (defun reftex-check-recursive-edit ()
3363 ;; Check if we are already in a recursive edit. Abort with helpful
3365 (if (marker-position reftex-recursive-edit-marker
)
3367 (substitute-command-keys
3368 "In unfinished recursive edit. Finish (\\[exit-recursive-edit]) or abort (\\[abort-recursive-edit])."))))
3370 (defun reftex-select-item (buffer prompt next-re end-re size help-string
3371 event-list
&optional offset
3373 ;; Select an item from the buffer BUFFER. Show PROMPT to user, find
3374 ;; next item with NEXT-RE regular expression, return on any of the
3375 ;; events listed in EVENT-LIST. The function returns the event along
3376 ;; with an integer indicating which item was selected. When OFFSET is
3377 ;; specified, starts at that item in the list. When CALL-BACK is
3378 ;; given, it is a function which is called with the match of the
3379 ;; NEXT-RE match and the index of the element.
3380 (let* (key key-sq b e ev cnt cmd
3381 (offset1 (or offset
1)))
3384 (save-window-excursion
3386 (switch-to-buffer-other-window buffer
))
3387 (if (= 0 (buffer-size))
3389 (setq truncate-lines t
)
3391 (if (not (re-search-forward next-re nil t offset1
))
3392 (progn ; in case the offset is illegal
3394 (if (not (re-search-forward next-re nil t offset1
))
3395 (throw 'exit nil
))))
3396 (beginning-of-line 1)
3397 (setq cnt
(if offset1
(1- offset1
) 0))
3399 (if (and cb-flag call-back
)
3400 (funcall call-back cnt
))
3404 (re-search-forward end-re nil
1))
3406 (reftex-highlight 1 b e
)
3407 (if (or (not (pos-visible-in-window-p b
))
3408 (not (pos-visible-in-window-p e
)))
3409 (recenter (/ (window-height) 2)))
3410 (setq key-sq
(read-key-sequence prompt
))
3413 ((fboundp 'listify-key-sequence
) ; Emacs
3414 (listify-key-sequence key-sq
))
3415 ((fboundp 'event-to-character
) ; XEmacs
3416 (mapcar 'event-to-character key-sq
))
3417 (t (error "Please report this problem to dominik@strw.leidenuniv.nl")))))
3419 (setq cmd
(key-binding key-sq
))
3421 (reftex-unhighlight 0)
3427 (equal cmd
'next-line
))
3428 (if (re-search-forward next-re nil t
2)
3429 (setq cnt
(1+ cnt
)))
3430 (beginning-of-line 1))
3432 ((equal cmd
'scroll-up
)
3434 (while (and (pos-visible-in-window-p)
3435 (re-search-forward next-re nil t
))
3436 (setq cnt
(1+ cnt
)))
3437 (beginning-of-line 1)
3441 (equal cmd
'previous-line
))
3442 (if (re-search-backward next-re nil t
)
3443 (setq cnt
(1- cnt
))))
3445 ((equal cmd
'scroll-down
)
3446 (while (and (pos-visible-in-window-p)
3447 (re-search-backward next-re nil t
))
3448 (setq cnt
(1- cnt
)))
3449 (recenter (- (window-height) size
2)))
3458 ((or (equal key ?\C-m
)
3460 (equal cmd
'newline
))
3461 (throw 'exit
'return
))
3463 ((or (equal key ?C
) ; backward compatibility
3465 (setq cb-flag
(not cb-flag
)))
3468 (funcall call-back cnt
))
3471 (save-window-excursion
3472 (with-output-to-temp-buffer "*RefTeX Help*"
3473 (princ help-string
))
3474 (setq unread-command-events
3477 ((fboundp 'read-event
) ; Emacs
3479 ((fboundp 'next-command-event
) ; XEmacs
3480 (next-command-event))
3481 (t (error "Please report this problem to dominik@strw.leidenuniv.nl")))
3483 (kill-buffer "*RefTeX Help*"))
3486 ;; sje - code copied from ispell.el for
3487 ;; performing recursive edit
3488 (set-marker reftex-recursive-edit-marker
(point))
3491 (save-window-excursion
3495 (substitute-command-keys
3496 "Recursive edit. Return to selection with \\[exit-recursive-edit]"))
3498 (if (not (equal (marker-buffer
3499 reftex-recursive-edit-marker
)
3502 "Cannot continue RefTeX from this buffer."))
3503 (goto-char reftex-recursive-edit-marker
))
3504 (set-marker reftex-recursive-edit-marker nil
)))
3506 ((member key event-list
)
3513 ;;; ===========================================================================
3515 ;;; View cross references
3517 (defun reftex-view-crossref (&optional arg
)
3518 "View cross reference of \\ref or \\cite macro at point.
3519 If the macro at point is a \\ref, show the corresponding label definition.
3520 If it is a \\cite, show the BibTeX database entry.
3521 If there is no such macro at point, search forward to find one.
3522 When you call this function several times in direct successtion, point will
3523 move to view subsequent cross references further down in the buffer.
3524 With argument, actually select the window showing the cross reference."
3528 ;; See where we are.
3529 (let* ((pos (point))
3530 (re "\\\\[a-z]*\\(cite\\|ref\\)\\(\\[[^{}]*\\]\\)?{\\([^}]+\\)}")
3531 (my-window (get-buffer-window (current-buffer)))
3532 pop-window cmd args macro label entry key-start point
)
3536 (and (search-backward "\\" nil t
)
3538 (< pos
(match-end 0))))
3539 (setq macro
(match-string 1)
3540 key-start
(match-beginning 3)))
3542 (if (and macro
(eq last-command this-command
))
3543 (if (and (string= macro
"cite")
3544 (skip-chars-forward "^}, \t\n\r")
3545 (= (following-char) ?
,))
3546 (setq key-start
(1+ (point)))
3550 (if (re-search-forward re nil t
)
3551 (setq macro
(match-string 1)
3552 key-start
(match-beginning 3))
3553 (error "No further cross references in buffer")))
3555 (goto-char key-start
)
3557 ;; Ensure access to scanning info
3558 (reftex-access-scan-info)
3561 ((string= macro
"cite")
3562 (setq cmd
'reftex-pop-to-bibtex-entry
3564 (reftex-no-props (reftex-this-word "^{},"))
3565 (reftex-get-bibfile-list) nil t
)))
3566 ((string= macro
"ref")
3567 (let ((label (reftex-no-props (reftex-this-word "^{}")))
3568 (entry (assoc label
(symbol-value reftex-list-of-labels-symbol
))))
3570 (setq cmd
'reftex-pop-to-label
3571 args
(list label
(list (nth 3 entry
)) nil t
))
3572 (error "Label %s not known - reparse document might help" label
))))
3573 (t (error "This should not happen")))
3574 (setq point
(point))
3576 (setq pop-window
(selected-window))
3577 (add-hook 'pre-command-hook
'reftex-highlight-shall-die
)
3578 (select-window my-window
)
3580 (and arg
(select-window pop-window
))))
3582 (defun reftex-mouse-view-crossref (ev)
3583 "View cross reference of \\ref or \\cite macro where you click.
3584 If the macro at point is a \\ref, show the corresponding label definition.
3585 If it is a \\cite, show the BibTeX database entry.
3586 If there is no such macro at point, search forward to find one.
3587 With argument, actually select the window showing the cross reference."
3589 (mouse-set-point ev
)
3590 (reftex-view-crossref current-prefix-arg
))
3592 ;;; ===========================================================================
3594 ;;; Functions that check out the surroundings
3596 (defun reftex-what-macro (which &optional bound
)
3597 ;; Find out if point is within the arguments of any TeX-macro.
3598 ;; The return value is either (\"\\\\macro\" . (point)) or a list of them.
3600 ;; If WHICH is nil, immediately return nil.
3601 ;; If WHICH is t, return list of all macros enclosing point.
3602 ;; If WHICH is a list of macros, look only for those macros and return the
3603 ;; name of the first macro in this list found to enclose point.
3604 ;; If the optional BOUND is an integer, bound backwards directed
3605 ;; searches to this point. If it is nil, limit to nearest \\section -
3608 ;; This function is pretty stable, but can be fooled if the text contains
3609 ;; things like \\macro{aa}{bb} where \\macro is defined to take only one
3610 ;; argument. As RefTeX cannot know this, the string \"bb\" would still be
3611 ;; considered an argument of macro \\macro.
3614 (if (null which
) (throw 'exit nil
))
3615 (let ((bound (or bound
(save-excursion (re-search-backward
3616 reftex-section-regexp nil
1)
3621 (narrow-to-region (max 1 bound
) (point-max))
3622 ;; move back out of the current parenthesis
3623 (while (condition-case nil
3624 (progn (up-list -
1) t
)
3626 ;; move back over any touching sexps
3627 (while (or (= (preceding-char) ?\
])
3628 (= (preceding-char) ?\
}))
3631 (if (and (or (= (following-char) ?\
[)
3632 (= (following-char) ?\
{))
3633 (and (re-search-backward "\\(\\\\[a-zA-Z]+\\)" nil t
)
3634 (= (match-end 0) pos
)))
3636 (setq cmd
(buffer-substring-no-properties
3637 (match-beginning 0) (match-end 0)))
3639 (setq cmd-list
(cons (cons cmd
(point)) cmd-list
))
3640 (if (member cmd which
)
3641 (throw 'exit
(cons cmd
(point)))))))
3643 (nreverse cmd-list
)))))
3645 (defun reftex-what-environment (which &optional bound
)
3646 ;; Find out if point is inside a LaTeX environment.
3647 ;; The return value is (e.g.) either (\"equation\" . (point)) or a list of
3650 ;; If WHICH is nil, immediately return nil.
3651 ;; If WHICH is t, return list of all environments enclosing point.
3652 ;; If WHICH is a list of environments, look only for those environments and
3653 ;; return the name of the first environment in this list found to enclose
3656 ;; If the optional BOUND is an integer, bound backwards directed searches to
3657 ;; this point. If it is nil, limit to nearest \\section - like statement.
3661 (if (null which
) (throw 'exit nil
))
3662 (let ((bound (or bound
(save-excursion (re-search-backward
3663 reftex-section-regexp nil
1)
3665 env-list end-list env
)
3666 (while (re-search-backward "\\\\\\(begin\\|end\\){\\([^}]+\\)}"
3668 (setq env
(buffer-substring-no-properties
3669 (match-beginning 2) (match-end 2)))
3671 ((string= (match-string 1) "end")
3672 (add-to-list 'end-list env
))
3673 ((member env end-list
)
3674 (setq end-list
(delete env end-list
)))
3676 (setq env-list
(cons (cons env
(point)) env-list
)))
3678 (throw 'exit
(cons env
(point))))))
3679 (nreverse env-list
)))))
3681 (defun reftex-word-before-point ()
3682 ;; Return the word before point. Word means here:
3683 ;; Consists of [a-zA-Z0-9.:] and ends at point or whitespace.
3684 (let ((pos (point)))
3686 (re-search-backward "[^ \t\n\r]" (point-min) 1)
3687 (setq pos
(1+ (point)))
3688 (if (re-search-backward "[^a-zA-Z0-9\\\.:]" (point-min) 1)
3690 (buffer-substring-no-properties (point) pos
))))
3692 ;; ============================================================================
3694 ;; Some generally useful functions
3696 (defun reftex-no-props (string)
3697 ;; Return STRING with all text properties removed
3698 (and (stringp string
)
3699 (set-text-properties 0 (length string
) nil string
))
3702 (defun reftex-split (regexp string
)
3704 (let ((start 0) list
)
3705 (while (string-match regexp string start
)
3706 (setq list
(cons (substring string start
(match-beginning 0)) list
))
3707 (setq start
(match-end 0)))
3708 (setq list
(nreverse (cons (substring string start
) list
)))))
3710 (defun reftex-allow-for-ctrl-m (string)
3711 ;; convert STRING into a regexp, allowing ^M for \n
3713 (setq string
(regexp-quote string
))
3714 (while (setq start
(string-match "[\n\r]" string
(+ 3 start
)))
3715 (setq string
(replace-match "[\n\r]" nil t string
)))
3718 (defun reftex-delete-list (elt-list list
)
3719 ;; like delete, but with a list of things to delete
3720 ;; (original code from Rory Molinari)
3722 (setq list
(delete (car elt-list
) list
)
3723 elt-list
(cdr elt-list
)))
3726 (defun reftex-get-buffer-visiting (file)
3727 ;; return a buffer visiting FILE
3729 ((fboundp 'find-buffer-visiting
) ; Emacs
3730 (find-buffer-visiting file
))
3731 ((boundp 'find-file-compare-truenames
) ; XEmacs
3732 (let ((find-file-compare-truenames t
))
3733 (get-file-buffer file
)))
3734 (t (error "Please report this problem to dominik@strw.leidenuniv.nl"))))
3736 (defun reftex-get-file-buffer-force (file &optional mark-to-kill
)
3737 ;; Return a buffer visiting file. Make one, if necessary.
3738 ;; If neither such a buffer no the file exist, return nil.
3739 ;; If MARK-TO-KILL in non-nil, put any new buffers into the kill list."
3741 (let ((buf (reftex-get-buffer-visiting file
)))
3744 ((file-exists-p file
)
3745 (setq buf
(find-file-noselect file
))
3747 (add-to-list 'reftex-buffers-to-kill buf
))
3751 (defun reftex-splice-symbols-into-list (list alist
)
3752 ;; Splice the association in ALIST of any symbols in LIST into the list.
3756 (while (and (not (null (car list
)))
3757 (symbolp (car list
)))
3758 (setq tmp
(car list
))
3761 (setq list
(append (cdr (cdr (assoc tmp alist
))) (cdr list
))))
3763 (error "Cannot treat symbol %s in reftex-label-alist"
3764 (symbol-name tmp
)))))
3765 (setq rtn
(cons (car list
) rtn
)
3769 (defun reftex-uniquify (alist &optional keep-list
)
3770 ;; Return a list of all elements in ALIST, but each car only once
3771 ;; Elements of KEEP-LIST are not removed even if duplicate
3774 (setq elm
(car alist
)
3776 (if (or (member (car elm
) keep-list
)
3777 (not (assoc (car elm
) new
)))
3778 (setq new
(cons elm new
))))
3779 (setq new
(nreverse new
))
3782 (defun reftex-use-fonts ()
3783 ;; Return t if we can and want to use fonts
3786 (boundp 'font-lock-keyword-face
)))
3788 ;; Highlighting uses overlays. If this is for XEmacs, we need to load
3789 ;; the overlay library, available in version 19.15
3790 (and (not (fboundp 'make-overlay
))
3794 (error "RefTeX needs overlay emulation (available in XEmacs 19.15)"))))
3796 ;; We keep a vector with several different overlays to do our highlighting.
3797 (defvar reftex-highlight-overlays
[nil nil
])
3799 ;; Initialize the overlays
3800 (aset reftex-highlight-overlays
0 (make-overlay 1 1))
3801 (overlay-put (aref reftex-highlight-overlays
0) 'face
'highlight
)
3802 (aset reftex-highlight-overlays
1 (make-overlay 1 1))
3803 (overlay-put (aref reftex-highlight-overlays
1) 'face
'highlight
)
3805 ;; Two functions for activating and deactivation highlight overlays
3806 (defun reftex-highlight (index begin end
&optional buffer
)
3807 "Highlight a region with overlay INDEX."
3808 (move-overlay (aref reftex-highlight-overlays index
)
3809 begin end
(or buffer
(current-buffer))))
3810 (defun reftex-unhighlight (index)
3811 "Detatch overlay INDEX."
3812 (delete-overlay (aref reftex-highlight-overlays index
)))
3814 (defun reftex-highlight-shall-die ()
3815 ;; Function used in pre-command-hook to remove highlights
3816 (remove-hook 'pre-command-hook
'reftex-highlight-shall-die
)
3817 (reftex-unhighlight 0))
3819 ;;; ---------------------------------------------------------------------------
3821 ;;; Cursor position after insertion of forms
3823 (defun reftex-position-cursor ()
3824 ;; Search back to question mark, delete it, leave point there
3825 (if (search-backward "\?" (- (point) 100) t
)
3828 (defun reftex-item ()
3829 "Insert an \\item and provide a label if the environments supports that."
3832 (reftex-what-environment '("itemize" "enumerate" "eqnarray")))))
3834 (if (and env
(not (bolp))) (newline))
3838 ((string= env
"eqnarray")
3843 (beginning-of-line 1))
3845 ((string= env
"itemize")
3849 ((string= env
"enumerate")
3855 (error "\\item command does not make sense here...")))))
3857 ;;; ---------------------------------------------------------------------------
3858 ;;; ---------------------------------------------------------------------------
3859 ;;; ---------------------------------------------------------------------------
3861 ;;; Data Section: Definition of large constants
3864 (defconst reftex-label-alist-builtin
3867 "LaTeX default environments"
3868 ("section" ?s
"sec:" "~\\ref{%s}" t
3869 ("Part" "Chapter" "Chap." "Section" "Sec." "Sect." "Paragraph" "Par."
3870 "\\S" "Teil" "Kapitel" "Kap." "Abschnitt" ))
3872 ("enumerate" ?n
"item:" "~\\ref{%s}" "\\\\item\\(\\[[^]]*\\]\\)?"
3875 ("equation" ?e
"eq:" "~(\\ref{%s})" t
3876 ("Equation" "Eq." "Eqn." "Gleichung" "Gl."))
3877 ("eqnarray" ?e
"eq:" nil
"\\\\begin{eqnarray}\\|\\\\\\\\")
3879 ("figure" ?f
"fig:" "~\\ref{%s}" "\\\\caption\\(\\[[^]]*\\]\\)?{"
3880 ("Figure" "Fig." "Abbildung" "Abb."))
3881 ("figure*" ?f nil nil
"\\\\caption\\(\\[[^]]*\\]\\)?{")
3883 ("table" ?t
"tab:" "~\\ref{%s}" "\\\\caption\\(\\[[^]]*\\]\\)?{"
3884 ("Table" "Tab." "Tabelle"))
3885 ("table*" ?t nil nil
"\\\\caption\\(\\[[^]]*\\]\\)?{")
3887 ("any" ?\
" " "\\ref{%s}" nil
))
3890 "Sidewaysfigure and sidewaystable"
3891 ("sidewaysfigure" ?f nil nil
"\\\\caption\\(\\[[^]]*\\]\\)?{")
3892 ("sidewaystable" ?t nil nil
"\\\\caption\\(\\[[^]]*\\]\\)?{"))
3895 "Subfigure environment and macro"
3896 ("subfigure" ?f nil nil
"\\\\caption\\(\\[[^]]*\\]\\)?{")
3897 ("\\subfigure" ?f nil nil
"\\\\subfigure[[{]"))
3900 "AMS-LaTeX: amsmath package environents"
3901 ("align" ?e
"eq:" "~\\eqref{%s}" "\\\\begin{align}\\|\\\\\\\\")
3902 ("gather" ?e
"eq:" nil
"\\\\begin{gather}\\|\\\\\\\\")
3903 ("multline" ?e
"eq:" nil t
)
3904 ("flalign" ?e
"eq:" nil
"\\\\begin{flalign}\\|\\\\\\\\")
3905 ("alignat" ?e
"eq:" nil
"\\\\begin{alignat}{[0-9]*}\\|\\\\\\\\"))
3908 "AAS deluxetable environment"
3909 ("deluxetable" ?t
"tab:" nil
"\\\\caption{")))
3910 "The default label environment descriptions.")
3912 ;;; ---------------------------------------------------------------------------
3914 ;;; Functions to compile the tables, reset the mode etc.
3916 (defun reftex-reset-mode ()
3917 "Reset RefTeX Mode. Required to implement changes to some list variables.
3918 This function will compile the information in reftex-label-alist and similar
3919 variables. It is called when RefTeX is first used, and after changes to
3920 these variables via reftex-add-to-label-alist."
3923 ;; Record that we have done this
3924 (setq reftex-tables-dirty nil
)
3926 ;; Kill temporary buffers associated with RefTeX - just in case they
3927 ;; were not cleaned up properly
3928 (let ((buffer-list '("*reftex-master.tex*" "*RefTeX Help*" "*RefTeX Select*"
3929 "*Duplicate Labels*" "*toc*" "*RefTeX-scratch*")))
3931 (if (get-buffer (car buffer-list
))
3932 (kill-buffer (car buffer-list
)))
3933 (setq buffer-list
(cdr buffer-list
))))
3935 ;; To update buffer-local variables
3936 (hack-local-variables)
3937 (message "updating internal tables...")
3938 (reftex-compute-ref-cite-tables)
3939 (message "updating internal tables... done")
3940 (reftex-reset-scanning-information))
3942 (defun reftex-reset-scanning-information ()
3943 "Reset the symbols containing information from buffer scanning.
3944 This enforces rescanning the buffer on next use."
3945 (if (and (string= reftex-last-toc-master
(reftex-TeX-master-file))
3946 (get-buffer "*toc*"))
3947 (kill-buffer "*toc*"))
3948 (let ((symlist reftex-multifile-symbols
)
3951 (setq symbol
(car symlist
)
3952 symlist
(cdr symlist
))
3953 (if (and (symbolp (symbol-value symbol
))
3954 (not (null (symbol-value symbol
))))
3955 (set (symbol-value symbol
) nil
)))))
3957 (defun reftex-compute-ref-cite-tables ()
3958 ;; Update ref and cite tables
3962 ;; Compile information in reftex-label-alist
3963 (let ((tmp (reftex-uniquify (reftex-splice-symbols-into-list
3966 reftex-label-alist-external-add-ons
3967 reftex-default-label-alist-entries
)
3968 reftex-label-alist-builtin
)
3970 entry env-or-mac typekeychar typekey prefix regexp
3971 fmt wordlist cmd qh-list
)
3973 (setq reftex-words-to-typekey-alist nil
3974 reftex-typekey-list nil
3975 reftex-typekey-to-format-alist nil
3976 reftex-typekey-to-prefix-alist nil
3977 reftex-env-or-mac-alist nil
3978 reftex-label-env-list nil
3979 reftex-label-mac-list nil
)
3982 (setq entry
(car tmp
)
3983 env-or-mac
(car entry
)
3986 (if (null env-or-mac
)
3987 (setq env-or-mac
""))
3988 (if (stringp (car entry
))
3989 ;; This is before version 2.00 - convert entry to new format
3990 ;; This is just to keep old users happy
3991 (setq entry
(cons (string-to-char (car entry
))
3992 (cons (concat (car entry
) ":")
3994 (setq typekeychar
(nth 0 entry
)
3995 typekey
(char-to-string typekeychar
)
3996 prefix
(nth 1 entry
)
3998 regexp
(nth 3 entry
)
3999 wordlist
(nth 4 entry
))
4000 (if (stringp wordlist
)
4001 ;; This is before version 2.04 - convert to new format
4002 (setq wordlist
(nthcdr 4 entry
)))
4004 (add-to-list 'reftex-typekey-list typekey
))
4005 (if (and typekey prefix
)
4006 (add-to-list 'reftex-typekey-to-prefix-alist
(cons typekey prefix
)))
4008 ((string-match "\\`\\\\" env-or-mac
)
4010 (add-to-list 'reftex-label-mac-list env-or-mac
))
4012 (or (string= env-or-mac
"any")
4013 (string= env-or-mac
"")
4014 (add-to-list 'reftex-label-env-list env-or-mac
))))
4016 (not (assoc typekey reftex-typekey-to-format-alist
))
4017 (setq reftex-typekey-to-format-alist
4018 (cons (cons typekey fmt
)
4019 reftex-typekey-to-format-alist
)))
4020 (and (not (string= env-or-mac
"any"))
4021 (not (string= env-or-mac
""))
4022 (not (assoc env-or-mac reftex-env-or-mac-alist
))
4023 (setq reftex-env-or-mac-alist
4024 (cons (list env-or-mac typekey regexp
)
4025 reftex-env-or-mac-alist
)))
4026 (while (and wordlist
(stringp (car wordlist
)))
4027 (or (assoc (car wordlist
) reftex-words-to-typekey-alist
)
4028 (setq reftex-words-to-typekey-alist
4029 (cons (cons (downcase (car wordlist
)) typekey
)
4030 reftex-words-to-typekey-alist
)))
4031 (setq wordlist
(cdr wordlist
)))
4033 ((string= "" env-or-mac
) nil
)
4034 ((assoc typekey qh-list
)
4035 (setcdr (assoc typekey qh-list
)
4036 (concat (cdr (assoc typekey qh-list
)) " " env-or-mac
)))
4038 (setq qh-list
(cons (cons typekey env-or-mac
) qh-list
))))))
4040 (setq qh-list
(nreverse qh-list
))
4041 (setq reftex-typekey-to-prefix-alist
4042 (nreverse reftex-typekey-to-prefix-alist
))
4043 (setq reftex-type-query-prompt
4044 (concat "Label type: "
4045 (mapconcat '(lambda(x)
4046 (format "[%s]" (car x
)))
4049 (setq reftex-type-query-help
4050 (concat "SELECT A LABEL TYPE:\n--------------------\n"
4051 (mapconcat '(lambda(x)
4056 ;;; Keybindings --------------------------------------------------------------
4058 (define-key reftex-mode-map
"\C-c-" 'reftex-item
)
4059 (define-key reftex-mode-map
"\C-c=" 'reftex-toc
)
4060 (define-key reftex-mode-map
"\C-c(" 'reftex-label
)
4061 (define-key reftex-mode-map
"\C-c)" 'reftex-reference
)
4062 (define-key reftex-mode-map
"\C-c[" 'reftex-citation
)
4063 (define-key reftex-mode-map
"\C-c&" 'reftex-view-crossref
)
4065 ;; If the user requests so, she can have a few more bindings:
4067 (reftex-extra-bindings
4068 (define-key reftex-mode-map
"\C-ct" 'reftex-toc
)
4069 (define-key reftex-mode-map
"\C-cl" 'reftex-label
)
4070 (define-key reftex-mode-map
"\C-cr" 'reftex-reference
)
4071 (define-key reftex-mode-map
"\C-cc" 'reftex-citation
)
4072 (define-key reftex-mode-map
"\C-cv" 'reftex-view-crossref
)
4073 (define-key reftex-mode-map
"\C-cg" 'reftex-grep-document
)
4074 (define-key reftex-mode-map
"\C-cs" 'reftex-search-document
)))
4076 ;;; Menus --------------------------------------------------------------------
4078 ;; Define a menu for the menu bar if Emacs is running under X
4083 reftex-mode-menu reftex-mode-map
4084 "Menu used in RefTeX mode"
4086 ["Table of Contents" reftex-toc t
]
4088 ["\\label" reftex-label t
]
4089 ["\\ref" reftex-reference t
]
4090 ["\\cite" reftex-citation t
]
4091 ["View crossref" reftex-view-crossref t
]
4093 ("Search and Replace"
4094 ["Search whole document" reftex-search-document t
]
4095 ["Replace in document" reftex-query-replace-document t
]
4096 ["Grep on document" reftex-grep-document t
]
4098 ["Find duplicate labels" reftex-find-duplicate-labels t
]
4099 ["Change label and refs" reftex-change-label t
]
4101 ["Create TAGS file" reftex-create-tags-file t
])
4103 ["Parse document" reftex-parse-document t
]
4104 ["Reset RefTeX Mode" reftex-reset-mode t
]
4105 ["Customize RefTeX" reftex-customize t
]))
4107 ;;; Run Hook ------------------------------------------------------------------
4109 (run-hooks 'reftex-load-hook
)
4111 ;;; That's it! ----------------------------------------------------------------
4113 ; Make sure tabels are compiled
4114 (message "updating internal tables...")
4115 (reftex-compute-ref-cite-tables)
4116 (setq reftex-tables-dirty nil
)
4120 ;;;============================================================================
4122 ;;; reftex.el end here