In AUCTeX’s LaTeX mode, C-c C-j
is by default bound to LaTeX-insert-item
. By default, it just inserts an \item
on a new line.
I thought that it would be cool to make it insert something else in non-itemize environments. It turns out that I was late, though – the functionality is already there! It is not widely known, however; in particular, it’s not mentioned in the manual. That does not mean, however, that you can’t discover it; the option is called LaTeX-item-list
, and it can be found using M-x apropos
or its more modern cousins, like Icicles or Ivy. Really, you should make a resolution to fire your favourite way of searching through commands and/or options once a day, with some meaningful regex, only to be surprised by some hidden cool functionality you never suspected to exist!
Basically, LaTeX-item-list
is an alist whose keys are environment names and values are functions inserting that environment’s “variant” of \item
. Unfortunately, just setting it accoridingly in init.el
is not enough; the variable gets rebuilt in every new document. Actually, LaTeX mode initializaton is a complicated business. I know, because I grepped the source for LaTeX-item-list
and found the LaTeX-common-initialization
function. I could grep for that, too, or I could use debug-on-entry
to look at the backtrace and see where it is called. Either way, it turns out that it is called by the TeX-latex-mode
function, which starts the LaTeX mode. (For some strange reason, it is defined with an ordinary defun
instead of define-derived-mode
.) From that it is more or less clear that one good place to modify LaTeX-item-list
is LaTeX-mode-hook
.
As an example, consider this piece of code, which you can put in your init.el
:
(add-hook 'LaTeX-mode-hook (lambda () (add-to-list 'LaTeX-item-list '("frame" . (lambda () (TeX-insert-macro "pause"))))))
This has an unwanted side effect of putting braces after \pause
. This can also be helped, but that will be the topic of another post.