| [Top] | [Contents] | [Index] | [ ? ] |
RefTeX is a package for managing Labels, References, Citations and index entries with GNU Emacs.
This manual documents RefTeX version 4.32 from 2007-04-10.
Don't be discouraged by the size of this manual, which covers RefTeX in great depth. All you need to know to use RefTeX can be summarized on two pages (see section RefTeX in a Nutshell). You can go back later to other parts of this document when needed.
| 1. Introduction | Quick-Start information. | |
| 2. Table of Contents | A Tool to move around quickly. | |
| 3. Labels and References | Creating and referencing labels. | |
| 4. Citations | Creating Citations. | |
| 5. Index Support | Creating and Checking Index Entries. | |
| 6. Viewing Cross–References | Who references or cites what? | |
| 6.1 RefTeX's Menu | The Ref menu in the menubar. | |
| 6.2 Default Key Bindings | The default key bindings. | |
| 6.3 Faces | Fontification of RefTeX's buffers. | |
| 6.4 Multifile Documents | Document spread over many files. | |
| 6.5 Language Support | How to support other languages. | |
| 6.6 Finding Files | Included TeX files and BibTeX .bib files. | |
| 6.8 AUCTeX | Cooperation with AUCTeX. | |
| 6.7 Optimizations | When RefTeX is too slow. | |
| 6.9 Problems and Work-arounds | First Aid. | |
| 6.10 Imprint | Author, Web-site, Thanks | |
| 7. Commands | Which are the available commands. | |
| 8. Options, Keymaps, Hooks | How to extend and configure RefTeX. | |
| 8.12 Keymaps and Hooks | For customization. | |
| 9. Changes | A List of recent changes to RefTeX. | |
The Index | ||
| Index | The full index. | |
Introduction | ||
| 1.1 Installation | How to install and activate RefTeX. | |
| 1.2 RefTeX in a Nutshell | A brief summary and quick guide. | |
Labels and References | ||
| 3.1 Creating Labels | ||
| 3.2 Referencing Labels | ||
| 3.3 Builtin Label Environments | The environments RefTeX knows about. | |
| 3.4 Defining Label Environments | ... and environments it doesn't. | |
| 3.5 Reference Info | View the label corresponding to a \ref. | |
3.6 xr: Cross-Document References | References to external documents. | |
3.7 varioref: Variable Page References | How to create \vref instead of \ref. | |
3.8 fancyref: Fancy Cross References | How to create \fref instead of \ref. | |
Defining Label Environments | ||
| 3.4.1 Theorem and Axiom Environments | Defined with \newenvironment.
| |
| 3.4.2 Quick Equation Macro | When a macro sets the label type. | |
| 3.4.3 Figure Wrapping Macro | When a macro argument is a label. | |
| 3.4.4 Adding Magic Words | Other words for other languages. | |
3.4.5 Using \eqref | How to switch to this AMS-LaTeX macro. | |
| 3.4.6 Non-standard Environments | Environments without \begin and \end | |
| 3.4.7 Putting it all together | How to combine many entries. | |
Citations | ||
| 4.1 Creating Citations | How to create them. | |
| 4.2 Citation Styles | Natbib, Harvard, Chicago and Co. | |
| 4.3 Citation Info | View the corresponding database entry. | |
| 4.4 Chapterbib and Bibunits | Multiple bibliographies in a Document. | |
| 4.5 Citations outside LaTeX | How to make citations in Emails etc. | |
| 4.6 Database Subsets | Extract parts of a big database. | |
Index Support | ||
| 5.1 Creating Index Entries | Macros and completion of entries. | |
| 5.2 The Index Phrases File | A special file for global indexing. | |
| 5.3 Displaying and Editing the Index | The index editor. | |
| 5.4 Builtin Index Macros | The index macros RefTeX knows about. | |
| 5.5 Defining Index Macros | ... and macros it doesn't. | |
The Index Phrases File | ||
| 5.2.1 Collecting Phrases | Collecting from document or external. | |
| 5.2.2 Consistency Checks | Check for duplicates etc. | |
| 5.2.3 Global Indexing | The interactive indexing process. | |
AUCTeX | ||
| 6.8.1 The AUCTeX-RefTeX Interface | How both packages work together | |
| 6.8.2 Style Files | AUCTeX's style files can support RefTeX | |
| 6.8.3 Bib-Cite | Hypertext reading of a document | |
Options, Keymaps, Hooks | ||
| 8.1 Table of Contents | ||
| 8.2 Defining Label Environments | ||
| 8.3 Creating Labels | ||
| 8.4 Referencing Labels | ||
| 8.5 Creating Citations | ||
| 8.6 Index Support | ||
| 8.7 Viewing Cross-References | ||
| 8.8 Finding Files | ||
| 8.9 Optimizations | ||
| 8.10 Fontification | ||
| 8.11 Miscellaneous | ||
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
RefTeX is a specialized package for support of labels,
references, citations, and the index in LaTeX. RefTeX wraps
itself round 4 LaTeX macros: \label, \ref, \cite,
and \index. Using these macros usually requires looking up
different parts of the document and searching through BibTeX database
files. RefTeX automates these time–consuming tasks almost
entirely. It also provides functions to display the structure of a
document and to move around in this structure quickly.
See section Imprint, for information about who to contact for help, bug reports or suggestions.
| 1.1 Installation | How to install and activate RefTeX. | |
| 1.2 RefTeX in a Nutshell | A brief summary and quick guide. |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
RefTeX has been bundled and pre-installed with Emacs since version 20.2. It has also been bundled and pre-installed with XEmacs 19.16–20.x. XEmacs 21.x users want to install the corresponding plug-in package which is available from the XEmacs FTP site. See the XEmacs 21.x documentation on package installation for details.
Users of earlier Emacs distributions (including Emacs 19) or people craving for new features and bugs can get a copy of the RefTeX distribution from the maintainer's web page. See section Imprint, for more information. The following instructions will guide you through the process of installing such a distribution.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Note: Currently installation is supported for Emacs only. XEmacs users might want to refer to the RefTeX package available through the package system of XEmacs.
In order to install RefTeX, unpack the distribution and edit the header of the Makefile. Basically, you need to change the path specifications for Emacs Lisp files and info files. Also, enter the name of your Emacs executable (usually either ‘emacs’ or ‘xemacs’).
Then, type
make make install |
to compile and install the code and documentation.
Per default RefTeX is installed in its own subdirectory which might not be on your load path. In this case, add it to load path with a command like the following, replacing the sample directory with the one where RefTeX is installed in your case.
(add-to-list 'load-path "/path/to/reftex") |
Put this command into your init file.
If you don't have ‘make’ available, you can let install.el handle installation. Stefan Monnier has written this neat little file for installing all sorts of Emacs extensions as a package. You can get it from http://www.iro.umontreal.ca/~monnier/elisp/install.el. Follow the instructions in the file in order to install RefTeX with it. Note that the file is still experimental, so handle with caution.
If you want to get your hands dirty, there is also the possibility to install by manually copying files.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In order to make the most important functions for entering RefTeX mode available add the following line to your init file.
(require 'reftex) |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
To turn RefTeX Mode on and off in a particular buffer, use M-x reftex-mode <RET>. To turn on RefTeX Mode for all LaTeX files, add the following lines to your ‘.emacs’ file:
(add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode |
That's all!
To get started, read the documentation, in particular the summary. (see section RefTeX in a Nutshell)
In order to produce a printed version of the documentation, use
make pdf to produce a reftex.pdf file. Analogously you can use
the dvi, ps, or html targets to create DVI,
PostScript or HTML files.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
RefTeX needs to access all files which are part of a multifile
document, and the BibTeX database files requested by the
\bibliography command. To find these files, RefTeX will
require a search path, i.e. a list of directories to check. Normally
this list is stored in the environment variables TEXINPUTS and
BIBINPUTS which are also used by RefTeX. However, on some
systems these variables do not contain the full search path. If
RefTeX does not work for you because it cannot find some files,
See section Finding Files.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
reftex-toc) will show
a table of contents of the document. This buffer can display sections,
labels and index entries defined in the document. From the buffer, you
can jump quickly to every part of your document. Press ? to get
help.
reftex-label-alist).
reftex-label) to insert a label at point.
RefTeX will either
Which labels are created how is configurable with the variable
reftex-insert-label-flags.
reftex-reference). This shows an outline of the document with
all labels of a certain type (figure, equation,...) and some label
context. Selecting a label inserts a \ref{label} macro
into the original buffer.
reftex-citation) will let you specify a
regular expression to search in current BibTeX database files (as
specified in the \bibliography command) and pull out a list of
matches for you to choose from. The list is formatted and
sorted. The selected article is referenced as ‘\cite{key}’
(see the variable reftex-cite-format if you want to insert
different macros).
reftex-index-macros). Multiple indices
are supported.
reftex-index-selection-or-word). The default macro
reftex-index-default-macro will be used. For a more complex entry
type C-c < (reftex-index), select any of the index macros
and enter the arguments with completion.
reftex-index-phrase-selection-or-word) to add
the current word or selection to a special index phrase file.
RefTeX can later search the document for occurrences of these
phrases and let you interactively index the matches.
reftex-display-index). From that buffer you can check and edit
all entries.
\label, \ref, \cite, \bibitem,
\index, and variations) or inside a BibTeX database entry, you
can press C-c & (reftex-view-crossref) to display
corresponding locations in the document and associated BibTeX database
files. \cite or \ref and no other
message occupies the echo area, information about the citation or label
will automatically be displayed in the echo area.
TeX-master or tex-main-file pointing to the
master file. RefTeX provides cross-referencing information from
all parts of the document, and across document borders
(‘xr.sty’).
reftex-label and
reftex-index are used. To enforce reparsing, call any of the
commands described above with a raw C-u prefix, or press the
r key in the label selection buffer, the table of contents
buffer, or the index buffer.
reftex-plug-into-AUCTeX). AUCTeX
contains style files which trigger appropriate settings in
RefTeX, so that for many of the popular LaTeX packages no
additional customizations will be necessary.
(setq reftex-plug-into-AUCTeX t) |
To make your own LaTeX macro definitions known to RefTeX, customize the variables
|
If you have a large number of macros defined, you may want to write an AUCTeX style file to support them with both AUCTeX and RefTeX.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Pressing the keys C-c = pops up a buffer showing the table of contents of the document. By default, this ‘*toc*’ buffer shows only the sections of a document. Using the l and i keys you can display all labels and index entries defined in the document as well.
With the cursor in any of the lines denoting a location in the document, simple key strokes will display the corresponding part in another window, jump to that location, or perform other actions.
Here is a list of special commands in the ‘*toc*’ buffer. A summary of this information is always available by pressing ?.
Display a summary of commands.
Prefix argument.
Goto next entry in the table of context.
Goto previous entry in the table of context.
Goto next section heading. Useful when many labels and index entries separate section headings.
Goto previous section heading.
Jump to section N, using the prefix arg. For example, 3 z jumps to section 3.
Show the corresponding location in another window. This command does not select that other window.
Goto the location in another window.
Go to the location and hide the ‘*toc*’ buffer. This will restore
the window configuration before reftex-toc (C-c =) was
called.
Clicking with mouse button 2 on a line has the same effect as <RET>.
See also variable reftex-highlight-selection, Fontification.
Toggle follow mode. When follow mode is active, the other window will
always show the location corresponding to the line at point in the
‘*toc*’ buffer. This is similar to pressing <SPC> after each
cursor motion. The default for this flag can be set with the variable
reftex-toc-follow-mode. Note that only context in files already
visited is shown. RefTeX will not visit a file just for follow
mode. See, however, the variable
reftex-revisit-to-follow.
Show calling point in another window. This is the point from where
reftex-toc was last called.
Promote the current section. This will convert \section to
\chapter, \subsection to \section etc. If there is
an active region, all sections in the region will be promoted, including
the one at point. To avoid mistakes, RefTeX requires a fresh
document scan before executing this command - if necessary, it will
automatically do this scan and ask the user to repeat the promotion
command.
Demote the current section. This is the opposite of promotion. It will
convert \chapter to \section etc. If there is an active
region, all sections in the region will be demoted, including the one at
point.
Rename the label at point. While generally not recommended, this can be useful when a package like ‘fancyref’ is used where the label prefix determines the wording of a reference. After a promotion/demotion it may be necessary to change a few labels from ‘sec:xyz’ to ‘cha:xyz’ or vice versa. This command can be used to do this - it launches a query replace to rename the definition and all references of a label.
Hide the ‘*toc*’ buffer, return to the position where
reftex-toc was last called.
Kill the ‘*toc*’ buffer, return to the position where
reftex-toc was last called.
Switch to the ‘*Index*’ buffer of this document. With prefix ‘2’, restrict the index to the section at point in the ‘*toc*’ buffer.
Change the maximum level of toc entries displayed in the ‘*toc*’
buffer. Without prefix arg, all levels will be included. With prefix
arg (e.g 3 t), ignore all toc entries with level greater than
arg (3 in this case). Chapters are level 1, sections are level 2.
The mode line ‘T<>’ indicator shows the current value. The default
depth can be configured with the variable
reftex-toc-max-level.
Toggle the display of the file borders of a multifile document in the
‘*toc*’ buffer. The default for this flag can be set with the
variable reftex-toc-include-file-boundaries.
Toggle the display of labels in the ‘*toc*’ buffer. The default
for this flag can be set with the variable
reftex-toc-include-labels. When called with a prefix argument,
RefTeX will prompt for a label type and include only labels of
the selected type in the ‘*toc*’ buffer. The mode line ‘L<>’
indicator shows which labels are included.
Toggle the display of index entries in the ‘*toc*’ buffer. The
default for this flag can be set with the variable
reftex-toc-include-index-entries. When called with a prefix
argument, RefTeX will prompt for a specific index and include
only entries in the selected index in the ‘*toc*’ buffer. The mode
line ‘I<>’ indicator shows which index is used.
Toggle the display of label and index context in the ‘*toc*’
buffer. The default for this flag can be set with the variable
reftex-toc-include-context.
Rebuild the ‘*toc*’ buffer. This does not rescan the document.
Reparse the LaTeX document and rebuild the ‘*toc*’ buffer. When
reftex-enable-partial-scans is non-nil, rescan only the file this
location is defined in, not the entire document.
Reparse the entire LaTeX document and rebuild the ‘*toc*’ buffer.
Switch to the ‘*toc*’ buffer of an external document. When the
current document is using the xr package (see section xr: Cross-Document References), RefTeX will switch to one of the external
documents.
Toggle the display of a dedicated frame displaying just the ‘*toc*’ buffer. Follow mode and visiting locations will not work that frame, but automatic recentering will make this frame always show your current editing location in the document (see below).
Toggle the automatic recentering of the ‘*toc*’ buffer. When this
option is on, moving around in the document will cause the ‘*toc*’
to always highlight the current section. By default, this option is
active while the dedicated ‘*TOC*’ frame exists. See also the
variable reftex-auto-recenter-toc.
In order to define additional commands for the ‘*toc*’ buffer, the
keymap reftex-toc-map may be used.
If you call reftex-toc while the ‘*toc*’ buffer already
exists, the cursor will immediately jump to the right place, i.e. the
section from which reftex-toc was called will be highlighted.
The command C-c - (reftex-toc-recenter) will only redisplay
the ‘*toc*’ buffer and highlight the correct line without actually
selecting the ‘*toc*’ window. This can be useful to quickly find
out where in the document you currently are. You can also automate this
by asking RefTeX to keep track of your current editing position in the
TOC. The TOC window will then be updated whenever you stop typing for
more than reftex-idle-time seconds. By default this works only
with the dedicated ‘*TOC*’ frame. But you can also force automatic
recentering of the TOC window on the current frame with
(setq reftex-auto-recenter-toc t) |
The section macros recognized by RefTeX are all LaTeX section
macros (from \part to \subsubparagraph) and the commands
\addchap and \addsec from the KOMA-Script classes.
Additional macros can be configured with the variable
reftex-section-levels. It is also possible to add certain LaTeX
environments to the table of contents. This is probably only useful for
theorem-like environments. See section Defining Label Environments, for an
example.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
LaTeX provides a powerful mechanism to deal with cross–references in a document. When writing a document, any part of it can be marked with a label, like ‘\label{mark}’. LaTeX records the current value of a certain counter when a label is defined. Later references to this label (like ‘\ref{mark}’) will produce the recorded value of the counter.
Labels can be used to mark sections, figures, tables, equations, footnotes, items in enumerate lists etc. LaTeX is context sensitive in doing this: A label defined in a figure environment automatically records the figure counter, not the section counter.
Several different environments can share a common counter and therefore
a common label category. E.g. labels in both equation and
eqnarray environments record the value of the same counter - the
equation counter.
| 3.1 Creating Labels | ||
| 3.2 Referencing Labels | ||
| 3.3 Builtin Label Environments | The environments RefTeX knows about. | |
| 3.4 Defining Label Environments | ... and environments it doesn't. | |
| 3.5 Reference Info | View the label corresponding to a \ref. | |
3.6 xr: Cross-Document References | References to external documents. | |
3.7 varioref: Variable Page References | How to create \vref instead of \ref. | |
3.8 fancyref: Fancy Cross References | How to create \fref instead of \ref. |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In order to create a label in a LaTeX document, press C-c (
(reftex-label). Just like LaTeX, RefTeX is context sensitive
and will figure out the environment it currently is in and adapt the
label to that environment. A label usually consists of a short prefix
indicating the type of the label and a unique mark. RefTeX has
3 different modes to create this mark.
reftex-label
anyway is that RefTeX will know that a new label has been defined.
It will then not be necessary to rescan the document in order to access
this label later.
If you want to change the way certain labels are created, check out the
variable reftex-insert-label-flags (see section Creating Labels).
If you are using AUCTeX to write your LaTeX documents, you can set it up to delegate the creation of labels to RefTeX. See section AUCTeX, for more information.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
RefTeX scans the document in order to find all labels. To make
referencing labels easier, it assigns to each label a category, the
label type (for example section, table, figure, equation, etc.).
In order to determine the label type, RefTeX parses around each label
to see in what kind of environments it is located. You can speed up
the parsing by using type-specific prefixes for labels and configuring
the variable reftex-trust-label-prefix.
Referencing Labels is really at the heart of RefTeX. Press C-c ) in order to reference a label (reftex-reference). This will start a selection process and finally insert the complete ‘\ref{label}’ into the buffer.
First, RefTeX will determine the label category which is required. Often that can be figured out from context. For example, if you write ‘As shown in eq.’ and the press C-c ), RefTeX knows that an equation label is going to be referenced. If it cannot figure out what label category is needed, it will query for one.
You will then be presented with a label selection menu. This is a special buffer which contains an outline of the document along with all labels of the given label category. In addition, next to the label there will be one line of context of the label definition, which is some text in the buffer near the label definition. Usually this is sufficient to identify the label. If you are unsure about a certain label, pressing <SPC> will show the label definition point in another window.
In order to reference a label, move to cursor to the correct label and
press <RET>. You can also reference several labels with a single
call to reftex-reference by marking entries with the m
key (see below).
Here is a list of special commands in the selection buffer. A summary of this information is always available from the selection process by pressing ?.
Show a summary of available commands.
Prefix argument.
Go to next label.
Go to previous label.
Jump back to the position where you last left the selection buffer. Normally this should get you back to the last referenced label.
Goto next section heading.
Goto previous section heading.
Jump to section N, using the prefix arg. For example 3 z jumps to section 3.
Show the surroundings of the definition of the current label in another window. See also the f key.
Toggle follow mode. When follow mode is active, the other window will
always display the full context of the current label. This is similar
to pressing <SPC> after each cursor motion. Note that only context
in files already visited is shown. RefTeX will not visit a file
just for follow mode. See, however, the variable
reftex-revisit-to-follow.
Show insertion point in another window. This is the point from where you
called reftex-reference.
Insert a reference to the label at point into the buffer from which the selection process was started. When entries have been marked, <RET> references all marked labels.
Clicking with mouse button 2 on a label will accept it like <RET>
would. See also variable reftex-highlight-selection, Miscellaneous.
Mark the current entry. When several entries have been marked, pressing
RET will accept all of them and place them into several
\ref macros. The special markers ‘,-+’ also store a
separator to be inserted before the corresponding reference. So marking
six entries with the keys ‘m , , - , +’ will give a reference list
like this (see the variable reftex-multiref-punctuation)
In eqs. (1), (2), (3)--(4), (5) and (6) |
Unmark a marked entry.
Accept the marked entries and put all labels as a comma-separated list
into one single \ref macro. Some packages like
‘saferef.sty’ support multiple references in this way.
Use the last referenced label(s) again. This is equivalent to moving to that label and pressing <RET>.
Enter a label with completion. This may also be a label which does not yet exist in the document.
Toggle between \ref and \vref macro for references. The
\vref macro is defined in the varioref LaTeX package.
With this key you can force RefTeX to insert a \vref
macro. The current state of this flag is displayed by the ‘S<>’
indicator in the mode line of the selection buffer.
Cycle between \ref, \fref and \Fref. The
\fref and \Fref macros are defined in the fancyref
LaTeX package. With this key you can force RefTeX to insert a
\fref or \Fref macro. The current state of this flag is
displayed by the ‘S<>’ indicator in the mode line of the
selection buffer.
Exit the selection process without inserting any reference into the buffer.
The defaults for the following flags can be configured with the variable
reftex-label-menu-flags (see section Referencing Labels).
Toggle the display of the one-line label definition context in the selection buffer.
Toggle the display of the file borders of a multifile document in the selection buffer.
Toggle the display of the table of contents in the selection buffer. With prefix arg, change the maximum level of toc entries displayed to arg. Chapters are level 1, section are level 2.
Toggle the display of a label counter in the selection buffer.
Toggle the display of labels hidden in comments in the selection buffers. Sometimes, you may have commented out parts of your document. If these parts contain label definitions, RefTeX can still display and reference these labels.
Update the menu. This will rebuilt the menu from the internal label list, but not reparse the document (see r).
Reparse the document to update the information on all labels and rebuild
the menu. If the variable reftex-enable-partial-scans is
non-nil and your document is a multifile document, this will
reparse only a part of the document (the file in which the label at
point was defined).
Reparse the entire document.
Switch the label category. After prompting for another label category, a menu for that category will be shown.
Reference a label from an external document. With the LaTeX package
xr it is possible to reference labels defined in another
document. This key will switch to the label menu of an external
document and let you select a label from there (see section xr).
In order to define additional commands for the selection process, the
keymap reftex-select-label-map may be used.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
RefTeX needs to be aware of the environments which can be referenced with a label (i.e. which carry their own counters). By default, RefTeX recognizes all labeled environments and macros discussed in The LaTeX Companion by Goossens, Mittelbach & Samarin, Addison-Wesley 1994.. These are:
figure, figure*, table, table*, equation,
eqnarray, enumerate, the \footnote macro (this is
the LaTeX core stuff)
align, gather, multline, flalign,
alignat, xalignat, xxalignat, subequations
(from AMS-LaTeX's ‘amsmath.sty’ package)
\endnote macro (from ‘endnotes.sty’)
Beqnarray (‘fancybox.sty’)
floatingfig (‘floatfig.sty’)
longtable (‘longtable.sty’)
figwindow, tabwindow (‘picinpar.sty’)
SCfigure, SCtable (‘sidecap.sty’)
sidewaysfigure, sidewaystable (‘rotating.sty’)
subfigure, subfigure*, the \subfigure macro
(‘subfigure.sty’)
supertabular (‘supertab.sty’)
wrapfigure (‘wrapfig.sty’)
If you want to use other labeled environments, defined with
\newtheorem, RefTeX needs to be configured to recognize
them (see section Defining Label Environments).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
RefTeX can be configured to recognize additional labeled
environments and macros. This is done with the variable
reftex-label-alist (see section Defining Label Environments). If you are not familiar with Lisp, you can use the
custom library to configure this rather complex variable. To do
this, use
M-x customize-variable <RET> reftex-label-alist <RET> |
Here we will discuss a few examples, in order to make things clearer.
It can also be instructive to look at the constant
reftex-label-alist-builtin which contains the entries for
all the builtin environments and macros (see section Builtin Label Environments).
| 3.4.1 Theorem and Axiom Environments | Defined with \newenvironment.
| |
| 3.4.2 Quick Equation Macro | When a macro sets the label type. | |
| 3.4.3 Figure Wrapping Macro | When a macro argument is a label. | |
| 3.4.4 Adding Magic Words | Other words for other languages. | |
3.4.5 Using \eqref | How to switch to this AMS-LaTeX macro. | |
| 3.4.6 Non-standard Environments | Environments without \begin and \end | |
| 3.4.7 Putting it all together | How to combine many entries. |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Suppose you are using \newtheorem in LaTeX in order to define two
new environments, theorem and axiom
\newtheorem{axiom}{Axiom}
\newtheorem{theorem}{Theorem}
|
to be used like this:
\begin{axiom}
\label{ax:first}
....
\end{axiom}
|
So we need to tell RefTeX that theorem and axiom are new
labeled environments which define their own label categories. We can
either use Lisp to do this (e.g. in ‘.emacs’) or use the custom
library. With Lisp it would look like this
(setq reftex-label-alist
'(("axiom" ?a "ax:" "~\\ref{%s}" nil ("axiom" "ax.") -2)
("theorem" ?h "thr:" "~\\ref{%s}" t ("theorem" "th.") -3)))
|
The type indicator characters ?a and ?h are used for
prompts when RefTeX queries for a label type. ?h
was chosen for theorem since ?t is already taken by
table. Note that also ?s, ?f, ?e,
?i, ?n are already used for standard environments.
The labels for Axioms and Theorems will have the prefixes ‘ax:’ and ‘thr:’, respectively. See section AUCTeX, for information on how AUCTeX can use RefTeX to automatically create labels when a new environment is inserted into a buffer. Additionally, the following needs to be added to one's .emacs file before AUCTeX will automatically create labels for the new environments.
(add-hook 'LaTeX-mode-hook
(lambda ()
(LaTeX-add-environments
'("axiom" LaTeX-env-label)
'("theorem" LaTeX-env-label))))
|
The ‘~\ref{%s}’ is a format string indicating how to insert references to these labels.
The next item indicates how to grab context of the label definition.
t means to get it from a default location (from the beginning of
a \macro or after the \begin statement). t is
not a good choice for eqnarray and similar environments.
nil means to use the text right after the label definition.
reftex-label-alist (Defining Label Environments).
The following list of strings is used to guess the correct label type from the word before point when creating a reference. E.g. if you write: ‘As we have shown in Theorem’ and then press C-c ), RefTeX will know that you are looking for a theorem label and restrict the menu to only these labels without even asking.
The final item in each entry is the level at which the environment
should produce entries in the table of context buffer. If the number is
positive, the environment will produce numbered entries (like
\section), if it is negative the entries will be unnumbered (like
\section*). Use this only for environments which structure the
document similar to sectioning commands. For everything else, omit the
item.
To do the same configuration with customize, you need to click on
the [INS] button twice to create two templates and fill them in
like this:
Reftex Label Alist: [Hide]
[INS] [DEL] Package or Detailed : [Value Menu] Detailed:
Environment or \macro : [Value Menu] String: axiom
Type specification : [Value Menu] Char : a
Label prefix string : [Value Menu] String: ax:
Label reference format: [Value Menu] String: ~\ref{%s}
Context method : [Value Menu] After label
Magic words:
[INS] [DEL] String: axiom
[INS] [DEL] String: ax.
[INS]
[X] Make TOC entry : [Value Menu] Level: -2
[INS] [DEL] Package or Detailed : [Value Menu] Detailed:
Environment or \macro : [Value Menu] String: theorem
Type specification : [Value Menu] Char : h
Label prefix string : [Value Menu] String: thr:
Label reference format: [Value Menu] String: ~\ref{%s}
Context method : [Value Menu] Default position
Magic words:
[INS] [DEL] String: theorem
[INS] [DEL] String: theor.
[INS] [DEL] String: th.
[INS]
[X] Make TOC entry : [Value Menu] Level: -3
|
Depending on how you would like the label insertion and selection for
the new environments to work, you might want to add the letters ‘a’
and ‘h’ to some of the flags in the variables
reftex-insert-label-flags (see section Creating Labels)
and reftex-label-menu-flags (see section Referencing Labels).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Suppose you would like to have a macro for quick equations. It could be defined like this:
\newcommand{\quickeq}[1]{\begin{equation} #1 \end{equation}}
|
and used like this:
Einstein's equation is \quickeq{E=mc^2 \label{eq:einstein}}.
|
We need to tell RefTeX that any label defined in the argument of the
\quickeq is an equation label. Here is how to do this with lisp:
(setq reftex-label-alist '(("\\quickeq{}" ?e nil nil 1 nil)))
|
The first element in this list is now the macro with empty braces as an
image of the macro arguments. ?e indicates that this is
an equation label, the different nil elements indicate to use the
default values for equations. The ‘1’ as the fifth element
indicates that the context of the label definition should be the 1st
argument of the macro.
Here is again how this would look in the customization buffer:
Reftex Label Alist: [Hide]
[INS] [DEL] Package or Detailed : [Value Menu] Detailed:
Environment or \macro : [Value Menu] String: \quickeq{}
Type specification : [Value Menu] Char : e
Label prefix string : [Value Menu] Default
Label reference format: [Value Menu] Default
Context method : [Value Menu] Macro arg nr: 1
Magic words:
[INS]
[ ] Make TOC entry : [Value Menu] No entry
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Suppose you want to make figures not directly with the figure environment, but with a macro like
\newcommand{\myfig}[5][tbp]{%
\begin{figure}[#1]
\epsimp[#5]{#2}
\caption{#3}
\label{#4}
\end{figure}}
|
which would be called like
\myfig[htp]{filename}{caption text}{label}{1}
|
Now we need to tell RefTeX that the 4th argument of the
\myfig macro is itself a figure label, and where to find
the context.
(setq reftex-label-alist
'(("\\myfig[]{}{}{*}{}" ?f nil nil 3)))
|
The empty pairs of brackets indicate the different arguments of the
\myfig macro. The ‘*’ marks the label argument. ?f
indicates that this is a figure label which will be listed together with
labels from normal figure environments. The nil entries for
prefix and reference format mean to use the defaults for figure labels.
The ‘3’ for the context method means to grab the 3rd macro argument
- the caption.
As a side effect of this configuration, reftex-label will now
insert the required naked label (without the \label macro) when
point is directly after the opening parenthesis of a \myfig macro
argument.
Again, here the configuration in the customization buffer:
[INS] [DEL] Package or Detailed : [Value Menu] Detailed:
Environment or \macro : [Value Menu] String: \myfig[]{}{}{*}{}
Type specification : [Value Menu] Char : f
Label prefix string : [Value Menu] Default
Label reference format: [Value Menu] Default
Context method : [Value Menu] Macro arg nr: 3
Magic words:
[INS]
[ ] Make TOC entry : [Value Menu] No entry
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Sometimes you don't want to define a new label environment or macro, but
just change the information associated with a label category. Maybe you
want to add some magic words, for another language. Changing only the
information associated with a label category is done by giving
nil for the environment name and then specify the items you want
to define. Here is an example which adds German magic words to all
predefined label categories.
(setq reftex-label-alist
'((nil ?s nil nil nil ("Kapitel" "Kap." "Abschnitt" "Teil"))
(nil ?e nil nil nil ("Gleichung" "Gl."))
(nil ?t nil nil nil ("Tabelle"))
(nil ?f nil nil nil ("Figur" "Abbildung" "Abb."))
(nil ?n nil nil nil ("Anmerkung" "Anm."))
(nil ?i nil nil nil ("Punkt"))))
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
\eqref Another case where one only wants to change the information associated
with the label category is to change the macro which is used for
referencing the label. When working with the AMS-LaTeX stuff, you might
prefer \eqref for doing equation references. Here is how to
do this:
(setq reftex-label-alist '((nil ?e nil "~\\eqref{%s}" nil nil)))
|
RefTeX has also a predefined symbol for this special purpose. The following is equivalent to the line above.
(setq reftex-label-alist '(AMSTeX)) |
Note that this is automatically done by the ‘amsmath.el’ style file of AUCTeX (see section Style Files) - so if you use AUCTeX, this configuration will not be necessary.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Some LaTeX packages define environment-like structures without using the
standard ‘\begin..\end’ structure. RefTeX cannot parse
these directly, but you can write your own special-purpose parser and
use it instead of the name of an environment in an entry for
reftex-label-alist. The function should check if point is
currently in the special environment it was written to detect. If so,
it must return a buffer position indicating the start of this
environment. The return value must be nil on failure to detect
the environment. The function is called with one argument bound.
If non-nil, bound is a boundary for backwards searches
which should be observed. We will discuss two examples.
Some people define abbreviations for
environments, like \be for \begin{equation}, and
\ee for \end{equation}. The parser function would have
to search backward for these macros. When the first match is
\ee, point is not in this environment. When the first match is
\be, point is in this environment and the function must return
the beginning of the match. To avoid scanning too far, we can also look
for empty lines which cannot occur inside an equation environment.
Here is the setup:
;; Setup entry in reftex-label-alist, using all defaults for equations
(setq reftex-label-alist '((detect-be-ee ?e nil nil nil nil)))
(defun detect-be-ee (bound)
;; Search backward for the macros or an empty line
(if (re-search-backward
"\\(^[ \t]*\n\\|\\\\ee\\>\\)\\|\\(\\\\be\\>\\)" bound t)
(if (match-beginning 2)
(match-beginning 2) ; Return start of environment
nil) ; Return nil because env is closed
nil)) ; Return nil for not found
|
A more complex example is the ‘linguex.sty’ package which defines list macros ‘\ex.’, ‘\a.’, ‘\b.’ etc. for lists which are terminated by ‘\z.’ or by an empty line.
\ex. \label{ex:12} Some text in an exotic language ...
\a. \label{ex:13} more stuff
\b. \label{ex:14} still more stuff
\a. List on a deeper level
\b. Another item
\b. and the third one
\z.
\b. Third item on this level.
... text after the empty line terminating all lists
|
The difficulty is that the ‘\a.’ lists can nest and that an empty line terminates all list levels in one go. So we have to count nesting levels between ‘\a.’ and ‘\z.’. Here is the implementation for RefTeX.
(setq reftex-label-alist
'((detect-linguex ?x "ex:" "~\\ref{%s}" nil ("Example" "Ex."))))
(defun detect-linguex (bound)
(let ((cnt 0))
(catch 'exit
(while
;; Search backward for all possible delimiters
(re-search-backward
(concat "\\(^[ \t]*\n\\)\\|\\(\\\\z\\.\\)\\|"
"\\(\\ex[ig]?\\.\\)\\|\\(\\\\a\\.\\)")
nil t)
;; Check which delimiter was matched.
(cond
((match-beginning 1)
;; empty line terminates all - return nil
(throw 'exit nil))
((match-beginning 2)
;; \z. terminates one list level - decrease nesting count
(decf cnt))
((match-beginning 3)
;; \ex. : return match unless there was a \z. on this level
(throw 'exit (if (>= cnt 0) (match-beginning 3) nil)))
((match-beginning 4)
;; \a. : return match when on level 0, otherwise
;; increment nesting count
(if (>= cnt 0)
(throw 'exit (match-beginning 4))
(incf cnt))))))))
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When you have to put several entries into reftex-label-alist, just
put them after each other in a list, or create that many templates in
the customization buffer. Here is a lisp example which uses several of
the entries described above:
(setq reftex-label-alist
'(("axiom" ?a "ax:" "~\\ref{%s}" nil ("axiom" "ax.") -2)
("theorem" ?h "thr:" "~\\ref{%s}" t ("theorem" "theor." "th.") -3)
("\\quickeq{}" ?e nil nil 1 nil)
AMSTeX
("\\myfig[]{}{}{*}{}" ?f nil nil 3)
(detect-linguex ?x "ex:" "~\\ref{%s}" nil ("Example" "Ex."))))
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When point is idle for more than reftex-idle-time seconds on the
argument of a \ref macro, the echo area will display some
information about the label referenced there. Note that the information
is only displayed if the echo area is not occupied by a different
message.
RefTeX can also display the label definition corresponding to a
\ref macro, or all reference locations corresponding to a
\label macro. See section Viewing Cross–References, for more
information.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
xr: Cross-Document References The LaTeX package xr makes it possible to create references to
labels defined in external documents. The preamble of a document using
xr will contain something like this:
\usepackage{xr}
\externaldocument[V1-]{volume1}
\externaldocument[V3-]{volume3}
|
and we can make references to any labels defined in these external documents by using the prefixes ‘V1-’ and ‘V3-’, respectively.
RefTeX can be used to create such references as well. Start the referencing process normally, by pressing C-c ). Select a label type if necessary. When you see the label selection buffer, pressing x will switch to the label selection buffer of one of the external documents. You may then select a label as before and RefTeX will insert it along with the required prefix.
For this kind of inter-document cross-references, saving of parsing information and the use of multiple selection buffers can mean a large speed-up (see section Optimizations).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
varioref: Variable Page References varioref is a frequently used LaTeX package to create
cross–references with page information. When you want to make a
reference with the \vref macro, just press the v key in the
selection buffer to toggle between \ref and \vref
(see section Referencing Labels). The mode line of the selection buffer
shows the current status of this switch. If you find that you almost
always use \vref, you may want to make it the default by
customizing the variable reftex-vref-is-default. If this
toggling seems too inconvenient, you can also use the command
reftex-varioref-vref(2).
Or use AUCTeX to create your macros (see section AUCTeX).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
fancyref: Fancy Cross References fancyref is a LaTeX package where a macro call like
\fref{fig:map-of-germany} creates not only the number of
the referenced counter but also the complete text around it, like
‘Figure 3 on the preceding page’. In order to make it work you
need to use label prefixes like ‘fig:’ consistently - something
RefTeX does automatically. When you want to make a reference
with the \fref macro, just press the V key in the selection
buffer to cycle between \ref, \fref and \Fref
(see section Referencing Labels). The mode line of the selection buffer
shows the current status of this switch. If this cycling seems
inconvenient, you can also use the commands reftex-fancyref-fref
and reftex-fancyref-Fref(3). Or use AUCTeX to create your macros
(see section AUCTeX).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Citations in LaTeX are done with the \cite macro or variations of
it. The argument of the macro is a citation key which identifies an
article or book in either a BibTeX database file or in an explicit
thebibliography environment in the document. RefTeX's
support for citations helps to select the correct key quickly.
| 4.1 Creating Citations | How to create them. | |
| 4.2 Citation Styles | Natbib, Harvard, Chicago and Co. | |
| 4.3 Citation Info | View the corresponding database entry. | |
| 4.4 Chapterbib and Bibunits | Multiple bibliographies in a Document. | |
| 4.5 Citations outside LaTeX | How to make citations in Emails etc. | |
| 4.6 Database Subsets | Extract parts of a big database. |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In order to create a citation, press C-c [. RefTeX then prompts for a regular expression which will be used to search through the database and present the list of matches to choose from in a selection process similar to that for selecting labels (see section Referencing Labels).
The regular expression uses an extended syntax: ‘&&’ defines a
logic and for regular expressions. For example
‘Einstein&&Bose’ will match all articles which mention
Bose-Einstein condensation, or which are co-authored by Bose and
Einstein. When entering the regular expression, you can complete on
known citation keys. RefTeX also offers a default when prompting for a
regular expression. This default is the word before the cursor or the
word before the current ‘\cite’ command. Sometimes this may be a
good search key.
RefTeX prefers to use BibTeX database files specified with a
\bibliography macro to collect its information. Just like
BibTeX, it will search for the specified files in the current directory
and along the path given in the environment variable BIBINPUTS.
If you do not use BibTeX, but the document contains an explicit
thebibliography environment, RefTeX will collect its
information from there. Note that in this case the information
presented in the selection buffer will just be a copy of relevant
\bibitem entries, not the structured listing available with
BibTeX database files.
In the selection buffer, the following keys provide special commands. A summary of this information is always available from the selection process by pressing ?.
Show a summary of available commands.
Prefix argument.
Go to next article.
Go to previous article.
Show the database entry corresponding to the article at point, in another window. See also the f key.
Toggle follow mode. When follow mode is active, the other window will always display the full database entry of the current article. This is equivalent to pressing <SPC> after each cursor motion. With BibTeX entries, follow mode can be rather slow.
Insert a citation referencing the article at point into the buffer from which the selection process was started.
Clicking with mouse button 2 on a citation will accept it like <RET>
would. See also variable reftex-highlight-selection, Miscellaneous.
Mark the current entry. When one or several entries are marked, pressing a or A accepts all marked entries. Also, <RET> behaves like the a key.
Unmark a marked entry.
Accept all (marked) entries in the selection buffer and create a single
\cite macro referring to them.
Accept all (marked) entries in the selection buffer and create a
separate \cite macro for each of it.
Create a new BibTeX database file which contains all marked entries in the selection buffer. If no entries are marked, all entries are selected.
Create a new BibTeX database file which contains all unmarked entries in the selection buffer. If no entries are marked, all entries are selected.
Enter a citation key with completion. This may also be a key which does not yet exist.
Show insertion point in another window. This is the point from where you
called reftex-citation.
Exit the selection process without inserting a citation into the buffer.
Start over with a new regular expression. The full database will be rescanned with the new expression (see also r).
Refine the current selection with another regular expression. This will not rescan the entire database, but just the already selected entries.
In order to define additional commands for this selection process, the
keymap reftex-select-bib-map may be used.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The standard LaTeX macro \cite works well with numeric or simple
key citations. To deal with the more complex task of author-year
citations as used in many natural sciences, a variety of packages has
been developed which define derived forms of the \cite macro.
RefTeX can be configured to produce these citation macros as well
by setting the variable reftex-cite-format. For the most
commonly used packages (natbib, harvard, chicago,
jurabib) this may be done from the menu, under
Ref->Citation Styles. Since there are usually several macros to
create the citations, executing reftex-citation (C-c [)
starts by prompting for the correct macro. For the Natbib style, this
looks like this:
SELECT A CITATION FORMAT
[^M] \cite{%l}
[t] \citet{%l}
[T] \citet*{%l}
[p] \citep{%l}
[P] \citep*{%l}
[e] \citep[e.g.][]{%l}
[s] \citep[see][]{%l}
[a] \citeauthor{%l}
[A] \citeauthor*{%l}
[y] \citeyear{%l}
|
If cite formats contain empty paris of square brackets, RefTeX can
will prompt for values of these optional arguments if you call the
reftex-citation command with a C-u prefix.
Following the most generic of these packages, natbib, the builtin
citation packages always accept the t key for a textual
citation (like: Jones et al. (1997) have shown...) as well as
the p key for a parenthetical citation (like: As shown
earlier (Jones et al, 1997)).
To make one of these styles the default, customize the variable
reftex-cite-format or put into ‘.emacs’:
(setq reftex-cite-format 'natbib) |
You can also use AUCTeX style files to automatically set the
citation style based on the usepackage commands in a given
document. See section Style Files, for information on how to set up the style
files correctly.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When point is idle for more than reftex-idle-time seconds on the
argument of a \cite macro, the echo area will display some
information about the article cited there. Note that the information is
only displayed if the echo area is not occupied by a different message.
RefTeX can also display the \bibitem or BibTeX database
entry corresponding to a \cite macro, or all citation locations
corresponding to a \bibitem or BibTeX database entry.
See section Viewing Cross–References.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
chapterbib and bibunits are two LaTeX packages which
produce multiple bibliographies in a document. This is no problem for
RefTeX as long as all bibliographies use the same BibTeX database
files. If they do not, it is best to have each document part in a
separate file (as it is required for chapterbib anyway). Then
RefTeX will still scan the locally relevant databases correctly. If
you have multiple bibliographies within a single file, this may
or may not be the case.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The command reftex-citation can also be executed outside a LaTeX
buffer. This can be useful to reference articles in the mail buffer and
other documents. You should not enter reftex-mode for
this, just execute the command. The list of BibTeX files will in this
case be taken from the variable reftex-default-bibliography.
Setting the variable reftex-cite-format to the symbol
locally does a decent job of putting all relevant information
about a citation directly into the buffer. Here is the lisp code to add
the C-c [ binding to the mail buffer. It also provides a local
binding for reftex-cite-format.
(add-hook 'mail-setup-hook
(lambda () (define-key mail-mode-map "\C-c["
(lambda ()
(interactive)
(let ((reftex-cite-format 'locally))
(reftex-citation))))))
|
| [ < ] | [ > ] | [ << ] |