auctex
[Top][All Lists]
Advanced

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

Re: [AUCTeX] Customizing equation/figure label strings per document (Sol


From: Ritesh Sood
Subject: Re: [AUCTeX] Customizing equation/figure label strings per document (Solved)
Date: Sat, 4 Oct 2008 16:39:07 -0700

On Mon, Sep 8, 2008 at 12:52 PM, Ralf Angeli <address@hidden> wrote:
> * Ritesh Sood (2008-09-08) writes:
>
>> I want to change the equation/figure label strings in the following manner:
>>
>> Environment                   Current (default)   Desired
>> equation                          eq:1                         eq:P1-1
>> figure                                fig:1                          fig:P1-1
>>
>>  P1- stands for Part1-, and I'd like to have P2-, P3-, etc for different
>> documents.  So the thing to do would be to write an AUCTeX style file and
>> drop it in style/ subdir of the document directory. Only, I don't know
>> elisp, and  couldn't make out what to do even after reading the AUCTeX and
>> RefTeX documentation.
>
> AFAICS this is not so easy since the label prefixes are usually defined
> per label in `reftex-label-alist{-builtin}'.  Perhaps you could define
> your own function for `reftex-format-label-function' which inserts a
> string of your liking into the already computed label.  If you want to
> stick that into the local variables stanza you could e.g. use this:
>
> %%% reftex-format-label-function: (lambda (label format) (let* ((parts 
> (split-string label ":")) (label (concat (car parts) ":P1-" (cadr parts)))) 
> (format format label)))
>
> The function makes the assumption that each label contains a single
> colon, so I am quite sure that it will eventually fail.  One would have
> to add precautions for dealing with labels not following this
> assumption.
>
>> Can someone please give me an elisp code snippet that i can drop in style/ ?
>
> I don't think a style file would be the right place because styles
> depend on properties of the document, like LaTeX classes or packages.
>
> Perhaps it would be better to define the format function in your init
> file as a named function and set it in the local variables stanza.  You
> could also set a variable which defines the string to be inserted by the
> function.
>
> By the way, please don't send HTML mails to this mailing list.
>
> --
> Ralf
>

Thanks Ralf, for the elisp code above. I built on it to accomplish
what I really wanted to: have the code in style/main.el so that AucTeX
loads it automatically through the multifile parsing mechanism. This
way i don't have to meddle with the file variables. Here's what i have
in  style/main.el:

(TeX-add-style-hook "main"
 (lambda ()
    (TeX-run-style-hooks
     "preamble")
    (setq reftex-format-label-function
        (lambda  (label format)
      "Return labels in the form eq:P1-<eq_num>, etc."
      (let* ((parts (split-string label ":"))
             (label (concat (car parts) ":P1-" (cadr parts))))
        (format format label))))))

It might not seem much to a seasoned elisp programmer, but this is my
first experience with lisp (elisp), and I'm elated :) But those
parentheses!!
How do you guys keep track of where a list is ending? I had to keep
going to the end time and again and rely on vim highlighting the
matching pair to figure out what list is what, and that gets very
tedious :(

Thanks again, and can you also please look another request that i made
earlier today?
Ritesh.




reply via email to

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