[Top][All Lists]

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

Re: [AUCTeX-devel] amsmath, amsthm automatially insert thm, lemma etc

From: Arash Esbati
Subject: Re: [AUCTeX-devel] amsmath, amsthm automatially insert thm, lemma etc
Date: Wed, 21 Oct 2015 22:04:53 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5

Uwe Brauer <address@hidden> writes:

> Now wait, all what you said below is true and I am aware of it. But
> this is not automatically insertion of labels.
> Take my solution:
> ,----
> | (defun LaTeX-thm-insert (environment)       ;Version:1.20
> |   (if (y-or-n-p
> |        (format "Do you want a title "))
> |     (let ((title (read-input "(optional) Title: ")))
> |     (LaTeX-insert-environment "thm" (concat "[" title "]"))
> |     (and (LaTeX-label environment)
> |        (newline-and-indent)))
> |     (LaTeX-insert-environment "thm")
> |     (and (LaTeX-label environment)
> |        (newline-and-indent))))
> `----

I don't understand why you need those `and's.  Wouldn't it be easier to
do something like this?

--8<---------------cut here---------------start------------->8---
(defun LaTeX-thm-insert (environment)
  (if (y-or-n-p "Do you want a title?")
      (let ((title (read-input "(optional) Title: ")))
        (LaTeX-insert-environment "thm" (concat "[" title "]")))
    (LaTeX-insert-environment "thm"))
  (LaTeX-label environment)
--8<---------------cut here---------------end--------------->8---

> This function of course is in
> ,----
> | (defun my-LaTeX-TeX-add-symbols ()
> |      (LaTeX-add-environments
> |        '("thm" LaTeX-thm-insert)))
> | (add-hook 'LaTeX-mode-hook 'my-LaTeX-TeX-add-symbols)
> `----
> So as you can see a label is added automatically. Couldn't you provide
> that functionality?

I see that your function add this into a document

--8<---------------cut here---------------start------------->8---
--8<---------------cut here---------------end--------------->8---

where it asks me to complete the label, I entered `foo'.

I can provide a version where RefTeX inserts the complete, unique label

--8<---------------cut here---------------start------------->8---

Eval with C-x C-e

(defun LaTeX-amsthm-env-label (environment)
  "Insert ENVIRONMENT, query for an optional argument and prompt for
label. AUCTeX users should add ENVIRONMENT to `LaTeX-label-alist'
via customize or in init-file with:

(add-to-list 'LaTeX-label-alist '(\"lemma\" . \"lem:\"))

RefTeX users should customize or add ENVIRONMENT to
`LaTeX-label-alist' and `reftex-label-alist', e.g.

(add-to-list 'LaTeX-label-alist '(\"lemma\" . \"lem:\"))
(add-to-list 'reftex-label-alist
             '(\"lemma\" ?m \"lem:\" \"~\\ref{%s}\" nil (\"Lemma\" \"lemma\") 
  (let ((opthead (TeX-read-string
                   (TeX-argument-prompt t nil "Heading"))))
    (LaTeX-insert-environment environment
                              (when (and opthead (not (string= opthead "")))
                                (format "[%s]" opthead))))
  (when (LaTeX-label environment 'environment)

(LaTeX-add-environments (list "lemma" 'LaTeX-amsthm-env-label))

Should be set by user:

(add-to-list 'LaTeX-label-alist '("lemma" . "lem:"))

(add-to-list 'LaTeX-label-alist '("lemma" . ""))
(add-to-list 'reftex-label-alist
             '("lemma" ?e "lem:" "~\\ref{%s}" nil ("Lemma" "lemma") nil))


`C-c C-e lemma RET Optional RET' inserts:
--8<---------------cut here---------------end--------------->8---

Best, Arash

reply via email to

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