0

Is there a way to add a reference / citation format which inserts the reference / citation label directly into the buffer without enclosing it into a macro?

To be clear: When I hit C-c ) AUCTeX prompts for a reference format, when I hit return it'll insert ~\ref{LABEL} into the buffer [after selecting the appropriate reference in the next buffer]. I would like to add a reference format which is bound to \?s (space) that inserts only the LABEL part.

That is to say: I hit C-c ), then <space>, then select the reference and... tadaa there's LABEL in the buffer.

[Edit:] I have tried

(eval-after-load "latex"
       '(progn
          (add-to-list
                'reftex-ref-style-alist
                '("Default" t
                  (("" ?\s))))))

however this encloses the label in curly braces and prepends ~ if there's a word before point.

elemakil
  • 3,681
  • 28
  • 53

1 Answers1

1

I have created a solution by adding an around-advice to reftex-reference, however, it's not a pretty solution. I'll put it up as an answer but I'm still hoping for a better solution.

(eval-after-load "latex"
  '(progn
     (add-to-list
      'reftex-ref-style-alist
      '("Default" t
    (("LABEL ONLY" ?\s))))

     (defadvice reftex-format-special (around reftex-format-special-labely-only activate)
       "Advice `reftex-format-special' such that if
REFSTYLE is \"LABEL ONLY\" it will insert
only the reference's label."
       (if (string= (ad-get-arg 2) "LABEL ONLY")
       (setq ad-return-value (format "%s" (ad-get-arg 0)))
     ad-do-it))))
elemakil
  • 3,681
  • 28
  • 53