1 ;;; amsthm.el --- Style hook for the AMS-LaTeX amsthm package.
3 ;; Copyright (C) 1997, 2013--2015 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <dominik@strw.leidenuniv.nl>
6 ;; Maintainer: auctex-devel@gnu.org
8 ;; This file is part of AUCTeX.
10 ;; AUCTeX is free software; you can redistribute it and/or modify it
11 ;; under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; AUCTeX is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with AUCTeX; see the file COPYING. If not, write to the Free
22 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 ;; The style provides the function `LaTeX-amsthm-env-label' which
28 ;; enables new defined environments with "\newtheoreom" to interact
29 ;; with AUCTeX and RefTeX mechanisms for inserting labels. Check
30 ;; docstring of `LaTeX-amsthm-env-label' for instructions.
34 (defvar LaTeX-amsthm-package-options nil
35 "Package options for the amsthm package.")
37 (defvar LaTeX-amsthm-theoremstyle-list
38 '(("plain") ("definition") ("remark"))
39 "List of theorem styles provided by `amsthm.el' and new ones
40 defined with \"\\newtheoremstyle\".")
42 (defvar LaTeX-amsthm-fontdecl
44 "rmfamily" "sffamily" "ttfamily"
48 "upshape" "itshape" "slshape" "scshape"
50 "tiny" "scriptsize" "footnotesize"
51 "small" "normalsize" "large"
52 "Large" "LARGE" "huge" "Huge"
55 "List of font declaration commands for \"\\newtheoremstyle\".")
57 (defun LaTeX-arg-amsthm-fontdecl (optional &optional prompt)
58 "Prompt for font declaration commands in \"\\newtheoremstyle\".
59 If OPTIONAL is non-nil, insert the resulting value as an optional
60 argument. Use PROMPT as the prompt string."
61 ;; `INITIAL-INPUT' (5th argument to `TeX-completing-read-multiple')
62 ;; is hard-coded to `TeX-esc'.
63 (let* ((crm-separator (regexp-quote TeX-esc))
64 (fontdecl (mapconcat 'identity
65 (TeX-completing-read-multiple
66 (TeX-argument-prompt optional prompt "Font")
67 LaTeX-amsthm-fontdecl nil nil TeX-esc)
69 (TeX-argument-insert fontdecl optional)))
71 (defun LaTeX-amsthm-env-label (environment)
72 "Insert ENVIRONMENT, query for an optional argument and prompt
73 for label. AUCTeX users should add ENVIRONMENT to
74 `LaTeX-label-alist' via customize or in init-file with:
76 (add-to-list \\='LaTeX-label-alist \\='(\"lemma\" . \"lem:\"))
78 RefTeX users should customize or add ENVIRONMENT to
79 `LaTeX-label-alist' and `reftex-label-alist', e.g.
81 (add-to-list \\='LaTeX-label-alist \\='(\"lemma\" . \"lem:\"))
82 (add-to-list \\='reftex-label-alist
83 \\='(\"lemma\" ?m \"lem:\" \"~\\ref{%s}\"
84 nil (\"Lemma\" \"lemma\") nil))"
85 (let ((opthead (TeX-read-string
86 (TeX-argument-prompt t nil "Heading"))))
87 (LaTeX-insert-environment environment
89 (not (string= opthead "")))
90 (format "[%s]" opthead))))
91 (when (LaTeX-label environment 'environment)
93 (indent-according-to-mode)))
95 ;; Needed for auto-parsing
98 ;; Setup parsing for \newtheorem
99 (TeX-auto-add-type "amsthm-newtheorem" "LaTeX")
101 ;; Setup parsing for \newtheoremstyle
102 (TeX-auto-add-type "amsthm-newtheoremstyle" "LaTeX")
104 (defun LaTeX-amsthm-auto-prepare ()
105 "Clear `LaTeX-auto-amsthm-newtheorem' and
106 `LaTeX-auto-amsthm-newtheoremstyle' before parsing."
107 (setq LaTeX-auto-amsthm-newtheorem nil)
108 (setq LaTeX-auto-amsthm-newtheoremstyle nil))
110 (defun LaTeX-amsthm-auto-cleanup ()
111 "Move parsed results from `LaTeX-auto-amsthm-newtheorem' and
112 make them available as new environments. Update
113 `LaTeX-amsthm-theoremstyle-list' with styles defined with
114 \"\\newtheoremstyle\"."
115 (dolist (newthm (mapcar 'car (LaTeX-amsthm-newtheorem-list)))
116 (LaTeX-add-environments (list newthm 'LaTeX-amsthm-env-label)))
117 (dolist (newthmstyle (LaTeX-amsthm-newtheoremstyle-list))
118 (add-to-list (make-local-variable 'LaTeX-amsthm-theoremstyle-list)
121 (add-hook 'TeX-auto-prepare-hook #'LaTeX-amsthm-auto-prepare t)
122 (add-hook 'TeX-auto-cleanup-hook #'LaTeX-amsthm-auto-cleanup t)
123 (add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
128 (LaTeX-add-environments
129 '("proof" LaTeX-amsthm-env-label))
131 ;; Overrule the defintion in `latex.el':
135 (let ((nthm (TeX-read-string
136 (TeX-argument-prompt nil nil "Environment"))))
137 (LaTeX-add-amsthm-newtheorems nthm)
138 (LaTeX-add-environments (list nthm 'LaTeX-amsthm-env-label))
139 (format "%s" nthm))))
140 [ TeX-arg-environment "Numbered like" ]
141 t [ (TeX-arg-eval progn (if (eq (save-excursion
143 (preceding-char)) ?\])
145 (TeX-arg-counter t "Within counter"))
151 (let ((nthm (TeX-read-string
152 (TeX-argument-prompt nil nil "Environment")))
153 (heading (TeX-read-string
154 (TeX-argument-prompt nil nil "Heading"))))
155 (LaTeX-add-amsthm-newtheorems nthm)
156 (LaTeX-add-environments (list nthm 'LaTeX-amsthm-env-label))
157 (insert (concat TeX-grop nthm TeX-grcl))
158 (format "%s" heading)))))
161 (TeX-arg-eval completing-read "Style: "
162 LaTeX-amsthm-theoremstyle-list))
169 (let ((nthmstyle (TeX-read-string
170 (TeX-argument-prompt nil nil "Style name"))))
171 (LaTeX-add-amsthm-newtheoremstyles nthmstyle)
172 (add-to-list (make-local-variable 'LaTeX-amsthm-theoremstyle-list)
174 (format "%s" nthmstyle))))
175 (TeX-arg-length "Space above")
176 (TeX-arg-length "Space below")
177 (LaTeX-arg-amsthm-fontdecl "Body font")
179 (LaTeX-arg-amsthm-fontdecl "Theorem head font")
180 "Punctuation after head"
181 (TeX-arg-length "Space after head")
182 "Theorem head spec"))
185 `(,(concat "\\\\newtheorem\\*?{\\(" TeX-token-char "+\\)}")
186 1 LaTeX-auto-amsthm-newtheorem))
188 `(,(concat "\\\\newtheoremstyle{\\(" TeX-token-char "+\\)}")
189 1 LaTeX-auto-amsthm-newtheoremstyle))
192 (when (and (featurep 'font-latex)
193 (eq TeX-install-font-lock 'font-latex-setup))
194 (font-latex-add-keywords '(("newtheorem" "*{[{[")
196 ("newtheoremstyle" "{{{{{{{{{"))
200 ;;; amsthm.el ends here