[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[AUCTeX] Re: Referencing labels with refstyle.sty

From: Alan Ristow
Subject: [AUCTeX] Re: Referencing labels with refstyle.sty
Date: Wed, 11 Jul 2007 19:10:47 -0400
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070604 Thunderbird/ Mnenhy/

Ralf Angeli wrote:
* Alan Ristow (2007-07-11) writes:

This gets me halfway there, inserting \figref{fig:foo} rather than the \figref{foo} that I would like. Not being much of a Lisp programmer, after some struggle I came up with

(setq reftex-label-alist
       '(("figure"   ?f "fig:"  reftex-format-ref-function  caption nil)))

The fourth element in the list must be a string.  So you cannot use a
function there.  (Perhaps RefTeX should support that.)

Ah. Glad to see I least got the need for reftex-format-ref-function correct.... I figured that since it returns a string, I might be able to use it in place of one -- obviously not!

RefTeX allows specifying a function for formatting the reference by
setting `reftex-format-ref-function', see
(info "(reftex)Options (Referencing Labels)").  You could set this
function in a style file for refstyle.sty for example like this:

(defun my-reftex-format-ref-function (label format)
  (let* ((label-sep-pos (string-match ":" label))
         (prefix (substring label 0 label-sep-pos))
         (suffix (substring label (1+ label-sep-pos))))
    (format "\\%sref{%s}" prefix suffix)))

(set (make-local-variable 'reftex-format-ref-function)

I had to change that last line to:

(setq reftex-format-ref-function 'my-reftex-format-ref-function)))

but beyond that it works brilliantly (and I've learned a couple of important things about Elisp and AUCTeX in the process). I've put the code into my own refstyle.el and it loads and runs perfectly. Thanks for the help!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]