[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)
(newline-and-indent))
--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---
\begin{thm}
\label{sec:foo}
\end{thm}
--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
automatically.
--8<---------------cut here---------------start------------->8---
\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}
--8<---------------cut here---------------end--------------->8---
Best, Arash
- Re: [AUCTeX-devel] amsmath, amsthm automatially insert thm, lemma etc, (continued)
- Re: [AUCTeX-devel] amsmath, amsthm automatially insert thm, lemma etc, Arash Esbati, 2015/10/18
- Re: [AUCTeX-devel] amsmath, amsthm automatially insert thm, lemma etc, Uwe Brauer, 2015/10/18
- Re: [AUCTeX-devel] amsmath, amsthm automatially insert thm, lemma etc, Mosè Giordano, 2015/10/18
- Re: [AUCTeX-devel] amsmath, amsthm automatially insert thm, lemma etc, Arash Esbati, 2015/10/20
- Re: [AUCTeX-devel] amsmath, amsthm automatially insert thm, lemma etc, David Kastrup, 2015/10/20
- Re: [AUCTeX-devel] amsmath, amsthm automatially insert thm, lemma etc, Mosè Giordano, 2015/10/20
- Re: [AUCTeX-devel] amsmath, amsthm automatially insert thm, lemma etc, Uwe Brauer, 2015/10/20
- Re: [AUCTeX-devel] amsmath, amsthm automatially insert thm, lemma etc, Arash Esbati, 2015/10/20
- Re: [AUCTeX-devel] amsmath, amsthm automatially insert thm, lemma etc, Uwe Brauer, 2015/10/21
- Re: [AUCTeX-devel] amsmath, amsthm automatially insert thm, lemma etc,
Arash Esbati <=
- Re: [AUCTeX-devel] amsmath, amsthm automatially insert thm, lemma etc, Uwe Brauer, 2015/10/22