1 ;;; theorem.el --- AUCTeX style for `theorem.sty' (v2.2c)
3 ;; Copyright (C) 2015 Free Software Foundation, Inc.
5 ;; Author: Arash Esbati <arash@gnu.org>
6 ;; Maintainer: auctex-devel@gnu.org
10 ;; This file is part of AUCTeX.
12 ;; AUCTeX is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; AUCTeX is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with AUCTeX; see the file COPYING. If not, write to the Free
24 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
29 ;; This file adds support for `theorem.sty' (v2.2c) from 2014/10/28.
30 ;; `theorem.sty' is a standard LaTeX package and part of TeXLive.
32 ;; The style provides the function `LaTeX-theorem-env-label' which
33 ;; enables new defined environments with "\newtheoreom" to interact
34 ;; with AUCTeX and RefTeX mechanisms for inserting labels. Check
35 ;; docstring of `LaTeX-theorem-env-label' for instructions.
39 (defvar LaTeX-theorem-theoremstyle-list
40 '(("plain") ("break") ("margin") ("change")
41 ("marginbreak") ("changebreak"))
42 "List of theorem styles provided by `theorem.sty'.")
44 (defvar LaTeX-theorem-fontdecl
46 "rmfamily" "sffamily" "ttfamily"
50 "upshape" "itshape" "slshape" "scshape"
52 "tiny" "scriptsize" "footnotesize"
53 "small" "normalsize" "large"
54 "Large" "LARGE" "huge" "Huge"
57 "List of font declaration commands for \"\\theorem(body\|header)font\".")
59 (defun LaTeX-arg-theorem-fontdecl (optional &optional prompt)
60 "Prompt for font declaration commands in \"\\theorem(body\|header)font\".
61 If OPTIONAL is non-nil, insert the resulting value as an optional
62 argument. Use PROMPT as the prompt string."
63 ;; `INITIAL-INPUT' (5th argument to `TeX-completing-read-multiple')
64 ;; is hard-coded to `TeX-esc'.
65 (let* ((crm-separator (regexp-quote TeX-esc))
66 (fontdecl (mapconcat 'identity
67 (TeX-completing-read-multiple
68 (TeX-argument-prompt optional prompt "Font")
69 LaTeX-theorem-fontdecl nil nil TeX-esc)
71 (TeX-argument-insert fontdecl optional)))
73 (defun LaTeX-theorem-env-label (environment)
74 "Insert ENVIRONMENT, query for an optional argument and prompt
75 for label. AUCTeX users should add ENVIRONMENT to
76 `LaTeX-label-alist' via customize or in init-file with:
78 (add-to-list \\='LaTeX-label-alist \\='(\"lemma\" . \"lem:\"))
80 RefTeX users should customize or add ENVIRONMENT to
81 `LaTeX-label-alist' and `reftex-label-alist', e.g.
83 (add-to-list \\='LaTeX-label-alist \\='(\"lemma\" . \"lem:\"))
84 (add-to-list \\='reftex-label-alist
85 \\='(\"lemma\" ?m \"lem:\" \"~\\ref{%s}\"
86 nil (\"Lemma\" \"lemma\") nil))"
87 (let ((opthead (TeX-read-string
88 (TeX-argument-prompt t nil "Heading"))))
89 (LaTeX-insert-environment environment
91 (not (string= opthead "")))
92 (format "[%s]" opthead))))
93 (when (LaTeX-label environment 'environment)
95 (indent-according-to-mode)))
97 ;; Needed for auto-parsing
100 ;; Setup parsing for \newtheorem
101 (TeX-auto-add-type "theorem-newtheorem" "LaTeX")
103 (defun LaTeX-theorem-auto-prepare ()
104 "Clear `LaTeX-auto-theorem-newtheorem' before parsing."
105 (setq LaTeX-auto-theorem-newtheorem nil))
107 (defun LaTeX-theorem-auto-cleanup ()
108 "Move parsed results from `LaTeX-auto-theorem-newtheorem' and
109 make them available as new environments."
110 (dolist (newthm (mapcar 'car (LaTeX-theorem-newtheorem-list)))
111 (LaTeX-add-environments (list newthm 'LaTeX-theorem-env-label))))
113 (add-hook 'TeX-auto-prepare-hook #'LaTeX-theorem-auto-prepare t)
114 (add-hook 'TeX-auto-cleanup-hook #'LaTeX-theorem-auto-cleanup t)
115 (add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
122 `(,(concat "\\\\newtheorem{\\(" TeX-token-char "+\\)}")
123 1 LaTeX-auto-theorem-newtheorem))
126 ;; Overrule the defintion in `latex.el':
130 (let ((nthm (TeX-read-string
131 (TeX-argument-prompt nil nil "Environment"))))
132 (LaTeX-add-theorem-newtheorems nthm)
133 (LaTeX-add-environments (list nthm 'LaTeX-theorem-env-label))
134 (format "%s" nthm))))
135 [ TeX-arg-environment "Numbered like" ]
136 t [ (TeX-arg-eval progn (if (eq (save-excursion
138 (preceding-char)) ?\])
140 (TeX-arg-counter t "Within counter"))
144 (TeX-arg-eval completing-read
146 LaTeX-theorem-theoremstyle-list))
149 (LaTeX-arg-theorem-fontdecl "Body font"))
151 '("theoremheaderfont"
152 (LaTeX-arg-theorem-fontdecl "Header font"))
154 '("theorempreskipamount"
155 (TeX-arg-length "Skip before theorem"))
157 '("theorempostskipamount"
158 (TeX-arg-length "Skip after theorem")))
161 (when (and (featurep 'font-latex)
162 (eq TeX-install-font-lock 'font-latex-setup))
163 (font-latex-add-keywords '(("theoremstyle" "{")
164 ("theorembodyfont" "{")
165 ("theoremheaderfont" "{")
166 ("theorempreskipamount" "{")
167 ("theorempostskipamount" "{"))
171 (defvar LaTeX-theorem-package-options nil
172 "Package options for the theorem package.")
174 ;;; theorem.el ends here