>>> "Arash" == Arash Esbati <esb...@gmx.de> writes:
Date: Thu, 22 Oct 2015 11:52:48 +0300
Message-ID: <87si53b7z3....@mat.ucm.es>

   > Uwe Brauer <o...@mat.ucm.es> 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?

Hm I don't remember, why I did this, but what you say makes sense.

> (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)
   >   (newline-and-indent))

   > I see that your function add this into a document

   > \begin{thm}
   >   \label{sec:foo}
  
   > \end{thm}

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

Ok my bad. I forgot to mention my reftex setting :'(

(defun my-reftex-label-alist-6 ()
"Sets reftex-label to have a 6th entry"
(interactive)
(setq reftex-label-alist
("thm" ?h "thr:%f:" "~\\ref{%s}" t   ("Theorem" "Theor." "Th."))))

Or even

(defun my-reftex-label-alist-7 () 
  "Sets reftex-label to have a 7th entry"
  (interactive)
  (setq reftex-label-alist
                  ("thm" ?h "thr:%f:" "~\\ref{%s}" t   ("Theorem"
  "Theor." "Th.")-1)))

And I put them into the corresponding hook.


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

That is better than my solution.
   > \documentclass{article}

   > 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\") nil))"
   >   (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-newline)
   >     (indent-according-to-mode)))

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

   > Should be set by user:

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

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

   > \begin{document}

   > `C-c C-e lemma RET Optional RET' inserts:
   > \begin{lemma}[Optional]
   >   \label{lem:1}
  
   > \end{lemma}
   > \end{document}


That sounds cool and would be appreciate by the users, I think!
Thanks


Uwe 

_______________________________________________
auctex-devel mailing list
auctex-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/auctex-devel

Reply via email to