auctex-devel
[Top][All Lists]
Advanced

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

Re: [AUCTeX-devel] Any equivalent to `reftex-label' in AUCTeX


From: Arash Esbati
Subject: Re: [AUCTeX-devel] Any equivalent to `reftex-label' in AUCTeX
Date: Wed, 19 Aug 2015 00:27:49 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5

Mosè Giordano <address@hidden> writes:

Hi Mosè,

> 2015-08-18 22:19 GMT+02:00 Arash Esbati <address@hidden>:

[...]

>> My question is, does AUCTeX has something equivalent to `reftex-label'
>> or should I just read the label as a string?
>
> To insert a new label there is `TeX-arg-define-label', instead to read
> a label we have `TeX-arg-label'.  There is also `LaTeX-label' to
> insert the whole "\label{}" macro (which is probably what you're
> looking for, right?).

thanks for your response.  Indeed, I want to read-in the label and then
insert it at once with the caption text.  The issue with the other
functions you mentioned is that they insert text at point upon
execution, i.e.:

--8<---------------cut here---------------start------------->8---
\begin{figure}
  % with (reftex-label nil t): Works
  \captionbox{foobar\label{fig:foo}}{}
  % with (TeX-arg-define-label)
  \captionbox{fig:foo}{foobar\label{nil}}{}
  % with (LaTeX-label 'environment)
  \captionbox\label{fig:foo}{foobar\label{fig:foo}}{}
\end{figure}
--8<---------------cut here---------------end--------------->8---

The function was modified like this:
--8<---------------cut here---------------start------------->8---

(defun LaTeX-arg-caption-captionbox (optional &optional prompt)
  "Query for the arguments of `\\captionbox' incl. a label and
insert them."
  (let* ((caption (TeX-read-string (TeX-argument-prompt optional prompt 
"Caption")))
         (label   ; (if (fboundp 'reftex-label)  Version 1
                  ;     (reftex-label nil t)     Version 1
                  ;  (TeX-read-string (TeX-argument-prompt optional prompt 
"Label"))) Version 1
                  ;    (TeX-arg-define-label optional prompt) ; Version 2
          (LaTeX-label 'environment) ;; Version 3
          )
         (width   (completing-read (TeX-argument-prompt t prompt "Width")
                                   (mapcar (lambda(elt) (concat TeX-esc (car 
elt)))
                                           (LaTeX-length-list))))
         (inpos   (completing-read (TeX-argument-prompt t prompt "Inner 
position")
                                   '("c" "l" "r" "s")))
         (heading (format "%s\\label{%s}" caption label)))
    (LaTeX-indent-line)
    (TeX-argument-insert heading optional)
    (cond (;; 2 optional args
           (and width (not (string-equal width ""))
                inpos (not (string-equal inpos "")))
           (insert (format "[%s][%s]" width inpos)))
          (;; 1st empty opt. arg, 2nd opt. arg
           (and (string-equal width "")
                inpos (not (string-equal inpos "")))
           (insert (format "[][%s]" inpos)))
          (;; 1st opt. arg, 2nd empty opt. arg
           (and width (not (string-equal width ""))
                (string-equal inpos ""))
           (insert (format "[%s]" width)))
          (t ; Do nothing if both empty
           (ignore)))
    (LaTeX-fill-paragraph)))
--8<---------------cut here---------------end--------------->8---

> As a rule of thumb, in AUCTeX you should always use these functions
> and avoid using reftex' ones, since the jobs are seamlessly
> transferred to the reftex equivalents if `reftex-plug-into-AUCTeX' has
> been called.

Of course, you're right.  But do you a hint how I can achieve the
desired result with AUCTeX functions?  Or am I missing something?

Best, Arash




reply via email to

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