RefTeX stores regexps matching \label
definitions in reftex-label-regexps
; you have to customize it in order to match label
without a \
. You can make the \
optional by putting it inside a shy group.
Then you have to write some code to run the functions reftex-reference
and reftex-label
with the second optional NO-INSERT
argument and bind the functions to some key strokes. Putting something like this in your .emacs
should do the trick:
(add-hook 'reftex-mode-hook
(lambda ()
;; do this all only once
(unless (member
"\\(?:\\\\\\)?label{\\(?1:[^}]*\\)}"
reftex-label-regexps)
;; label stuff
(setq reftex-label-regexps
'("\\(?:\\\\\\)?label{\\(?1:[^}]*\\)}"
"\\[[^][]\\{0,2000\\}\\<label[[:space:]]*=\[[:space:]]*\
{?\\(?1:[^],}]+\\)}?"))
(reftex-compile-variables)
(defun doconce-label ()
(interactive)
(insert "label{" (reftex-label nil t) "}"))
(local-set-key (kbd "C-c l") #'doconce-label)
;; ref stuff
(defun doconce-ref ()
(interactive)
(insert "ref{" (reftex-reference nil t) "}"))
(local-set-key (kbd "C-c r") #'doconce-ref))))
\label{thisisaverynicelabel}
or\label{einstein was right}
would work too ;-) In fact,\label{eq:1}
with numbers is not the preferred style to do so, as soon as the order of equations changes, the 1st equation might become the 3rd one, for example, but it is still labeled aseq:1
label{eq:1}
instead of\label{eq:1}
in LaTEX. But I could use RefTeX for Doconce but RefTeX doesn't recognizelabel{eq:1}
. RefTeX wants backslash in front oflabel
.