In LaTeX, the labels are defined as \label{eq:1}. When you want to reference to that equation, you could easily search all \label in the document by C-c ) and that command insert reference to that label \ref{eq:1}

Currently I am using a special language in which every labels are in the form label{eq:1} and the references ref{eq:1}(no backslash). So I wonder how I could customize RefTeX to search label and insert ref for a chosen label.

  • Off-topic: You can use basically use anything in a label name, so \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 as eq:1 – user31729 Sep 7 '17 at 16:08
  • I am not using LaTeX but a special markup language (Doconce) requires label{eq:1} instead of \label{eq:1} in LaTEX. But I could use RefTeX for Doconce but RefTeX doesn't recognize label{eq:1}. RefTeX wants backslash in front of label. – ofenerci Sep 7 '17 at 16:12

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 stuff
              (setq reftex-label-regexps
              (defun doconce-label ()
                (insert "label{" (reftex-label nil t) "}"))
              (local-set-key (kbd "C-c l") #'doconce-label)
              ;; ref stuff
              (defun doconce-ref ()
                (insert "ref{" (reftex-reference nil t) "}"))
              (local-set-key (kbd "C-c r") #'doconce-ref))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.