Commentary:
CDLaTeX is a minor mode supporting fast insertion of environment templates and math stuff in LaTeX.
To turn CDLaTeX Minor Mode on and off in a particular buffer, use `M-x cdlatex-mode'.
To turn on CDLaTeX Minor Mode for all LaTeX files, add one of the following lines to your .emacs file:
(add-hook 'LaTeX-mode-hook #'turn-on-cdlatex) ; with AUCTeX LaTeX mode (add-hook 'latex-mode-hook #'turn-on-cdlatex) ; with Emacs latex mode
For key bindings, see further down in this documentation.
CDLaTeX requires texmathp.el (which is distributed with AUCTeX) to auto-insert $...$ when needed, so we recommend you install AUCTeX to get this functionality.
CDLaTeX is a minor mode supporting mainly mathematical and scientific text development with LaTeX. CDLaTeX is really about speed. AUCTeX (the major mode I recommend for editing LaTeX files) does have a hook based system for inserting environments and macros - but while this is useful and general, it is sometimes slow to use. CDLaTeX tries to be quick, with very few and easy to remember keys, and intelligent on-the-fly help.
CDLaTeX has an abbrev-like mechanism to insert full LaTeX
environments and other templates into the buffer. Abbreviation
expansion is triggered with the TAB key only, not with SPC or RET.
For example, typing "iteC-c ?' (
cdlatex-command-help').
Typing C-c {' (
cdlatex-environment') uses the minibuffer to
complete the name of a LaTeX environment and inserts a template
for this environment into the buffer. These environment
templates also contain labels created with RefTeX. In a
template, text needs to be filled in at various places, which we
call "points of interest". You can use the TAB key to jump to
the next point of interest in the template. If there is an
active region, the region will be wrapped into the environment,
ignoring the template content.
For many frequently used LaTeX environments, abbreviations are
available. Most of the time, the abbreviation consists of the
first three letters of the environment name: `equ
\end{equation}
Similarly, ali<TAB>' inserts an AMS-LaTeX align environment template etc. For a full list of environment abbreviations, use
C-c ?'.
Use the command C-c -' (
cdlatex-item') to insert a generalized
new "item" in any "list"-like environment. For example, in an
itemize environment, this inserts "\item", in an enumerate
environment it inserts "\item\label{item:25}" and in an eqnarray
environment, it inserts "\label{eq:25} \n & &". When
appropriate, newlines are inserted, and the previous item is also
closed with "\". `cdlatex-item' can also be invoked with the
abbreviation "it
Abbreviations are also used to insert simple math templates
into the buffer. The cursor will be positioned properly. For
example, typing fr<TAB>' will insert "\frac{}{}" with the cursor in the first pair of parenthesis. Typing
lr(\frac{}{}' template, it will move you from the first argument to the second and then out of the second. For a list of available templates, type
C-c ?'.
As a special case, the left-right parenthesis combinations can
also be applied after writing the content by selecting the
content and typing '( or '[ or '{ or '< or '| .
This feature is similar to the functionality in the Math minor mode
of AUCTeX, and to the input methods of the X-Symbol package. It is
introduced by the backquote character. Backquote followed by any
character inserts a LaTeX math macro into the buffer. If
necessary, a pair of "$" is inserted to switch to math mode. For
example, typing "a" inserts "$\alpha$". Since LaTeX defines many more mathematical symbols than the alphabet has letters, different sets of math macros are provided. We call the different sets "levels". On each level, another LaTeX macro is assigned to a given letter. To select the different levels, simply press the backquote character several times before pressing the letter. For example, typing "
d" inserts "\delta" (level 1), and typing "d" inserts "\partial" (level 2). Similarly, "`e" inserts "\epsilon" and "
e" inserts "\vareppsilon".
On each level, on-thy-fly help will pop up automatically if you
hesitate to press the next key. The help screen is a window which
lists all math macros available on the current level. Initially,
when you type slowly, this window will pop up each time you press
backquote. However, after you have learned the different keys, you
will type more quickly and the help window is not shown. Try it
out: First press "" (backquote), wait for the help window and then press "a" to get "\alpha". Then press "
" and "b" as a quick
sequence to get "\beta", without the help window.
The LaTeX macros available through this mechanism are fully configurable - see the variable `cdlatex-math-symbol-alist'.
Putting accents on mathematical characters and/or changing the font of a character uses key combinations with the quote character "'" as a prefix. The accent or font change is applied to the character or LaTeX macro before point. For example
a'~ ERROR % in text mode $a'~ \tilde{a} % in math mode a': \ddot{a} ab'b \textbf{ab} % in text mode $ab'b a\mathbf{b} % in math mode \alpha'. \dot{\alpha} r{dust}'r r\mathrm{dust} % in math mode
Dollars and parens can be inserted as pairs. When you type the opening delimiter, the closing delimiter will be inserted as well, and the cursor positioned between them. You can configure which delimiter are inserted pairwise by configuring the variable `cdlatex-paired-parens'.
Also, the keys _' and
^' will insert "_{}" and "^{}",
respectively, and, if necessary, also a pair of dollar signs to
switch to math mode. You can use TAB to exit paired parenthesis.
As a special case, when you use TAB to exit a pair of braces that
belong to a subscript or superscript, CDLaTeX removes the braces if
the sub/superscript consists of a single character. For example
typing "$10^3
If you press _' or
^' twice, the template inserted will be
_{\mathrm{}}' or
^{\mathrm }', respectively, to insert a roman
sub/super-script. Style guides require that all sub- and
superscripts that are descriptive (so not a mathematical or
physical quantity themselves) need to be roman. So $xi$ is i
is an index, but $x{\rm max}$ to indicate the maximum value. You
can disable this behavior through the variable
`cdlatex-make-sub-superscript-roman-if-pressed-twice'.
You may have noticed that we use the TAB key for many different purposes in this package. While this may seem confusing, I have gotten used to this very much. Hopefully this will work for you as well: "when in doubt, press TAB". Here is a summary of what happens when you press the TAB key:
The function first tries to expand any abbreviation before point.
If there is none, it cleans up short subscripts and superscripts at point. I.e., is the cursor is just before the closing brace in "a^{2}", it changes it to "a^2", since this is more readable. If you want to keep the braces also for simple superscripts and subscripts, set the variable `cdlatex-simplify-sub-super-scripts' to nil.
After that, the TAB function jumps to the next point of interest in a LaTeX text where one would reasonably expect that more input can be put in. This does not use special markers in the template, but a heuristic method which works quite well. For the detailed rules which govern this feature, check the documentation of the function `cdlatex-tab'.
Check out the documentation of the variables in the configuration section. The variables must be set before cdlatex-mode is turned on, or, at the latext, in `cdlatex-mode-hook', in order to be effective. When changing the variables, toggle the mode off and on to make sure that everything is up to date.
Here is how you might configure CDLaTeX to provide environment templates (including automatic labels) for two theorem-like environments.
(setq cdlatex-env-alist '(("axiom" "\begin{axiom}\nAUTOLABEL\n?\n\end{axiom}\n" nil) ("theorem" "\begin{theorem}\nAUTOLABEL\n?\n\end{theorem}\n" nil)))
The "AUTOLABEL" indicates the place where an automatic label should be inserted, using RefTeX. The question mark defines the position of the cursor after the template has been inserted into the buffer.
You could also define your own keyword commands "axm" and "thr" to make
the template insertion quicker (e.g. axm<TAB>' and
thm
(setq cdlatex-command-alist '(("axm" "Insert axiom env" "" cdlatex-environment ("axiom") t nil) ("thr" "Insert theorem env" "" cdlatex-environment ("theorem") t nil)))
Here is how to add new math symbols to CDLaTeX's list: In order to put
all rightarrow commands onto `>, >, ```>, and ````> (i.e. several backquotes followed by >) and all leftarrow commands onto '<,
<, ```<,
and ````<, you could do this in .emacs:
(setq cdlatex-math-symbol-alist '((?< ("\leftarrow" "\Leftarrow" "\longleftarrow" "\Longleftarrow")) (?> ("\rightarrow" "\Rightarrow" "\longrightarrow" "\Longrightarrow")) ))
To change the prefix key for math accents and font switching, you could do something like
KEY BINDINGS
Here is the default set of keybindings from CDLaTeX. A menu is also installed.
$ cdlatex-dollar ( cdlatex-pbb { cdlatex-pbb [ cdlatex-pbb | cdlatex-pbb < cdlatex-pbb ^ cdlatex-sub-superscript _ cdlatex-sub-superscript
TAB cdlatex-tab C-c ? cdlatex-command-help C-c { cdlatex-environment C-c - cdlatex-item ` cdlatex-math-symbol ' cdlatex-math-modify
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;