简体   繁体   中英

AUCTeX: insert reference / citation without macro

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 Cc ) 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 Cc ) , 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.

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))))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM