[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: Uwe Brauer
Subject: Re: [AUCTeX-devel] amsmath, amsthm automatially insert thm, lemma etc
Date: Thu, 22 Oct 2015 12:03:11 +0300
User-agent: Gnus/5.13001 (Ma Gnus v0.10) Emacs/25.0.50 (gnu/linux)

>>> "Arash" == Arash Esbati <address@hidden> writes:
Date: Thu, 22 Oct 2015 11:52:48 +0300
Message-ID: <address@hidden>

   > 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?

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"
(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"
  (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!


reply via email to

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