When invoking RefTeX to generate LaTeX code for a reference (to an equation, figure) I need a short unbreakable space (LaTeX: \,) when the abbreviation is used (Eq.\,\ref{}, Fig.\,\ref{}) and a long space (~) when the full word is used (Equation~\ref{}, Figure~\ref{}). I thought I understood the reftex-label-alist and added to my init.el:

(add-to-list 'reftex-label-alist '("equation" ?e "eq:" "~\\ref{%s}"   t (regexp "equations?")))

(add-to-list 'reftex-label-alist '("eq"       ?e "eq:" "\\,\\ref{%s}" t (regexp "eqs?\\." "eqn\\.")))

i.e. the first line matching "equation(s)" and the second matching "eq(s)", but this always results in a short space. Is there a way to do this, or am I asking for something impossible?

1 Answer 1


The relevant piece when you make a reference (\ref) to a label is the type-indicator, in this case ?e. You can't have multiple setups around a single type-indicator.

In your case, you want to set the value of reftex-format-ref-function. The docstring says:

Function which produces the string to insert as a reference. Normally should be nil, because the format to insert a reference can already be specified in reftex-label-alist.

This hook also is used by the special commands to insert e.g. \vref and \fref references, so even if you set this, your setting will be ignored by the special commands.

The function will be called with three arguments, the LABEL, the DEFAULT FORMAT, which normally is ~\ref{%s} and the REFERENCE STYLE. The function should return the string to insert into the buffer.

Something like this in your init file should do the job:

(setq reftex-format-ref-function
      (lambda (label fmt ref-style)
        (let ((fmt (if (= (char-before) ?.)
                       (replace-regexp-in-string "~" "\\," fmt nil t)
          (format fmt label ref-style))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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