1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
|
;;; ntheorem.el --- AUCTeX style for `ntheorem.sty' (v1.33) -*- lexical-binding: t; -*-
;; Copyright (C) 2015-2021 Free Software Foundation, Inc.
;; Author: Arash Esbati <arash@gnu.org>
;; Maintainer: auctex-devel@gnu.org
;; Created: 2015-10-31
;; Keywords: tex
;; This file is part of AUCTeX.
;; AUCTeX is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; AUCTeX is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with AUCTeX; see the file COPYING. If not, write to the Free
;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
;; 02110-1301, USA.
;;; Commentary:
;; This file adds support for `ntheorem.sty' (v1.33) from 2011/08/15.
;; `ntheorem.sty' is and part of TeXLive.
;; The style provides the function `LaTeX-ntheorem-env-label' which
;; enables new defined environments with "\newtheoreom" to interact
;; with AUCTeX and RefTeX mechanisms for inserting labels. Check
;; docstring of `LaTeX-ntheorem-env-label' for instructions.
;;; Code
(require 'crm)
(require 'tex)
(require 'latex)
;; Silence the compiler:
(declare-function font-latex-add-keywords
"font-latex"
(keywords class))
(declare-function LaTeX-color-definecolor-list
"color"
())
(declare-function LaTeX-xcolor-definecolor-list
"xcolor"
())
(defvar LaTeX-ntheorem-theoremstyle-list
'(("plain") ("break") ("change") ("changebreak") ("margin")
("marginbreak") ("nonumberplain") ("nonumberbreak") ("empty"))
"List of theorem styles provided by `ntheorem.el' and new ones
defined with \"\\newtheoremstyle\".")
(defvar LaTeX-ntheorem-listtype-list
'(("all") ("allname") ("opt") ("optname"))
"List of predefined formatting options available for
\"\\theoremlisttype\" provided by `ntheorem.el' and new ones
defined with \"\\newtheoremlisttype\".")
(defvar LaTeX-ntheorem-fontdecl
'(;; family
"rmfamily" "sffamily" "ttfamily"
;; series
"mdseries" "bfseries"
;; shape
"upshape" "itshape" "slshape" "scshape"
;; size
"tiny" "scriptsize" "footnotesize"
"small" "normalsize" "large"
"Large" "LARGE" "huge" "Huge"
;; reset macro
"normalfont")
"List of font declaration commands for \"\\newtheoremstyle\".")
(defun LaTeX-arg-ntheorem-fontdecl (optional &optional prompt)
"Prompt for font declaration commands in \"\\theorem(body|header)font\".
If OPTIONAL is non-nil, insert the resulting value as an optional
argument. Use PROMPT as the prompt string."
(let* ((crm-separator (regexp-quote TeX-esc))
(fontdecl (mapconcat #'identity
(TeX-completing-read-multiple
(TeX-argument-prompt optional prompt "Font declaration: \\" t)
LaTeX-ntheorem-fontdecl)
TeX-esc)))
(TeX-argument-insert fontdecl
optional
(when (and fontdecl (not (string= fontdecl "")))
TeX-esc))))
(defun LaTeX-ntheorem-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', for example
(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)))
;; Setup parsing for \newtheorem
(TeX-auto-add-type "ntheorem-newtheorem" "LaTeX")
;; Setup parsing for \newtheoremstyle
(TeX-auto-add-type "ntheorem-newtheoremstyle" "LaTeX")
;; Setup parsing for \newtheoremlisttype
(TeX-auto-add-type "ntheorem-newtheoremlisttype" "LaTeX")
(defun LaTeX-ntheorem-auto-prepare ()
"Clear `LaTeX-auto-ntheorem-newtheorem' and
`LaTeX-auto-ntheorem-newtheoremstyle' before parsing."
(setq LaTeX-auto-ntheorem-newtheorem nil)
(setq LaTeX-auto-ntheorem-newtheoremstyle nil)
(setq LaTeX-auto-ntheorem-newtheoremlisttype nil))
(defun LaTeX-ntheorem-auto-cleanup ()
"Move parsed results from `LaTeX-auto-ntheorem-newtheorem' and
make them available as new environments. Update
`LaTeX-ntheorem-theoremstyle-list' with styles defined with
\"\\newtheoremstyle\"."
(dolist (newthm (mapcar #'car (LaTeX-ntheorem-newtheorem-list)))
(LaTeX-add-environments (list newthm #'LaTeX-ntheorem-env-label))
(LaTeX-add-environments (list (concat newthm "*")
#'LaTeX-ntheorem-env-label)))
(dolist (newthmstyle (LaTeX-ntheorem-newtheoremstyle-list))
(add-to-list (make-local-variable 'LaTeX-ntheorem-theoremstyle-list)
newthmstyle))
(dolist (newthmlist (LaTeX-ntheorem-newtheoremlisttype-list))
(add-to-list (make-local-variable 'LaTeX-ntheorem-listtype-list)
newthmlist))
(when (LaTeX-provided-package-options-member "ntheorem" "thmmarks")
(dolist (nthm (mapcar #'car (LaTeX-ntheorem-newtheorem-list)))
(TeX-add-symbols (concat nthm "Symbol"))))
(dolist (nthm (mapcar #'car (LaTeX-ntheorem-newtheorem-list)))
(TeX-add-symbols (concat nthm "name"))))
(add-hook 'TeX-auto-prepare-hook #'LaTeX-ntheorem-auto-prepare t)
(add-hook 'TeX-auto-cleanup-hook #'LaTeX-ntheorem-auto-cleanup t)
(add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
(TeX-add-style-hook
"ntheorem"
(lambda ()
(TeX-auto-add-regexp
`(,(concat "\\\\newtheorem{\\(" TeX-token-char "+\\)}")
1 LaTeX-auto-ntheorem-newtheorem))
(TeX-auto-add-regexp
`(,(concat "\\\\newframedtheorem{\\(" TeX-token-char "+\\)}")
1 LaTeX-auto-ntheorem-newtheorem))
(TeX-auto-add-regexp
`(,(concat "\\\\newshadedtheorem{\\(" TeX-token-char "+\\)}")
1 LaTeX-auto-ntheorem-newtheorem))
(TeX-auto-add-regexp
`(,(concat "\\\\newtheoremstyle{\\(" TeX-token-char "+\\)}")
1 LaTeX-auto-ntheorem-newtheoremstyle))
(TeX-auto-add-regexp
`(,(concat "\\\\newtheoremlisttype{\\(" TeX-token-char "+\\)}")
1 LaTeX-auto-ntheorem-newtheoremlisttype))
(TeX-add-symbols
;; 2.2 Defining New Theorem Sets
;; Overrule the defintion in `latex.el':
'("newtheorem"
(TeX-arg-eval
(lambda ()
(let ((nthm (TeX-read-string
(TeX-argument-prompt nil nil "Environment"))))
(LaTeX-add-ntheorem-newtheorems nthm)
(LaTeX-add-environments (list nthm #'LaTeX-ntheorem-env-label))
(LaTeX-add-environments (list (concat nthm "*")
#'LaTeX-ntheorem-env-label))
(format "%s" nthm))))
[ TeX-arg-environment "Numbered like" ]
t [ (TeX-arg-eval progn (if (eq (save-excursion
(backward-char 2)
(preceding-char)) ?\])
()
(TeX-arg-counter t "Within counter"))
"") ])
'("renewtheorem"
(TeX-arg-eval completing-read "Environment: "
(LaTeX-ntheorem-newtheorem-list))
[ TeX-arg-environment "Numbered like" ]
t [ (TeX-arg-eval progn (if (eq (save-excursion
(backward-char 2)
(preceding-char)) ?\])
()
(TeX-arg-counter t "Within counter"))
"") ])
;; 2.3 Defining the Layout of Theorem Sets
'("theoremstyle"
(TeX-arg-eval completing-read "Style: "
LaTeX-ntheorem-theoremstyle-list))
'("theorembodyfont"
(LaTeX-arg-ntheorem-fontdecl "Body font"))
'("theoremheaderfont"
(LaTeX-arg-ntheorem-fontdecl "Header font"))
'("theoremnumbering"
(TeX-arg-eval completing-read
(TeX-argument-prompt nil nil "Numbering scheme")
'("arabic" "roman" "Roman" "alph" "Alph"
"greek" "Greek" "fnsymbol")))
'("theoremseparator" "Separator")
'("theorempreskip"
(TeX-arg-length "Skip before theorem"))
'("theorempostskip"
(TeX-arg-length "Skip after theorem"))
'("theoremindent"
(TeX-arg-free "Theorem indent"))
(when (LaTeX-provided-package-options-member "ntheorem" "thmmarks")
'("theoremsymbol" t))
'("theoremprework" t)
'("theorempostwork" t)
'("theoremclass"
(TeX-arg-eval completing-read "Theorem type: "
(append '(("LaTeX"))
(LaTeX-ntheorem-newtheorem-list))))
;; 2.3.6 A Standard Set of Theorems
(when (LaTeX-provided-package-options-member "ntheorem" "standard")
(let ((env '("Theorem" "Lemma" "Proposition"
"Corollary" "Satz" "Korollar"
"Definition" "Example" "Beispiel"
"Anmerkung" "Bemerkung" "Remark"
"Proof" "Beweis")))
(dolist (elt env)
(LaTeX-add-ntheorem-newtheorems elt)
(LaTeX-add-environments (list elt #'LaTeX-ntheorem-env-label))
(LaTeX-add-environments (list (concat elt "*")
#'LaTeX-ntheorem-env-label)))))
;; 2.3.7 Framed and Boxed Theorems
'("newframedtheorem"
(TeX-arg-eval
(lambda ()
(let ((nthm (TeX-read-string
(TeX-argument-prompt nil nil "Environment"))))
(LaTeX-add-ntheorem-newtheorems nthm)
(LaTeX-add-environments (list nthm #'LaTeX-ntheorem-env-label))
(LaTeX-add-environments (list (concat nthm "*")
#'LaTeX-ntheorem-env-label))
(format "%s" nthm))))
[ TeX-arg-environment "Numbered like" ]
t [ (TeX-arg-eval progn (if (eq (save-excursion
(backward-char 2)
(preceding-char)) ?\])
()
(TeX-arg-counter t "Within counter"))
"") ])
'("newshadedtheorem"
(TeX-arg-eval
(lambda ()
(let ((nthm (TeX-read-string
(TeX-argument-prompt nil nil "Environment"))))
(LaTeX-add-ntheorem-newtheorems nthm)
(LaTeX-add-environments (list nthm #'LaTeX-ntheorem-env-label))
(LaTeX-add-environments (list (concat nthm "*")
#'LaTeX-ntheorem-env-label))
(format "%s" nthm))))
[ TeX-arg-environment "Numbered like" ]
t [ (TeX-arg-eval progn (if (eq (save-excursion
(backward-char 2)
(preceding-char)) ?\])
()
(TeX-arg-counter t "Within counter"))
"") ])
'("shadecolor"
(TeX-arg-eval
(lambda ()
(let ((color (cond ((member "xcolor" (TeX-style-list))
(completing-read "Color name: " (LaTeX-xcolor-definecolor-list)))
((member "color" (TeX-style-list))
(completing-read "Color name: " (LaTeX-color-definecolor-list)))
(t
(TeX-read-string "Color name: ")))))
(format "%s" color)))))
'("theoremframepreskip"
(TeX-arg-length "Skip before framed theorem"))
'("theoremframepostskip"
(TeX-arg-length "Skip after framed theorem"))
'("theoreminframepreskip"
(TeX-arg-length "Skip inside framed theorem"))
'("theoreminframepostskip"
(TeX-arg-length "Skip inside framed theorem"))
;; 2.4 Generating Theoremlists
'("listtheorems"
(TeX-arg-eval mapconcat #'identity
(TeX-completing-read-multiple
"Lists: "
(LaTeX-ntheorem-newtheorem-list)) ","))
;; 2.4.2 Writing Extra Stuff to the Theorem File
'("addtheoremline"
(TeX-arg-eval completing-read "Environment: "
(LaTeX-ntheorem-newtheorem-list))
t)
'("addtheoremline*"
(TeX-arg-eval completing-read "Environment: "
(LaTeX-ntheorem-newtheorem-list))
t)
'("addtotheoremfile"
[ TeX-arg-eval completing-read "Environment: "
(LaTeX-ntheorem-newtheorem-list) ]
t)
;; 2.5.1 Defining New Theorem Layouts
'("newtheoremstyle"
(TeX-arg-eval
(lambda ()
(let ((style (TeX-read-string
(TeX-argument-prompt nil nil "Style name"))))
(LaTeX-add-ntheorem-newtheoremstyles style)
(add-to-list (make-local-variable 'LaTeX-ntheorem-theoremstyle-list)
(list style))
(format "%s" style))))
2)
'("renewtheoremstyle"
(TeX-arg-eval completing-read "Style name: "
LaTeX-ntheorem-theoremstyle-list)
2)
;; 2.5.2 Defining New Theorem List Layouts
'("newtheoremlisttype"
(TeX-arg-eval
(lambda ()
(let ((layout (TeX-read-string
(TeX-argument-prompt nil nil "List layout name"))))
(LaTeX-add-ntheorem-newtheoremlisttypes layout)
(add-to-list (make-local-variable 'LaTeX-ntheorem-listtype-list)
(list layout))
(format "%s" layout))))
3)
'("renewtheoremlisttype"
(TeX-arg-eval completing-read "Style name: "
LaTeX-ntheorem-listtype-list)
3)
;; 2.6 Setting End Marks
'("qedsymbol" t)
'("NoEndMark" 0)
;; 2.7 Extended Referencing Features
(when (LaTeX-provided-package-options-member "ntheorem" "thref")
'("thref" TeX-arg-ref)) )
;; 2.6 Setting End Marks
;; ... the endmark can manually be set by just saying \<name>Symbol.
(when (LaTeX-provided-package-options-member "ntheorem" "thmmarks")
(dolist (nthm (mapcar #'car (LaTeX-ntheorem-newtheorem-list)))
(TeX-add-symbols (concat nthm "Symbol"))))
;; 2.8 Miscellaneous
;; Inside a theorem-like environment <env>, the name given as
;; optional argument is accessible by \<env>name
(dolist (nthm (mapcar #'car (LaTeX-ntheorem-newtheorem-list)))
(TeX-add-symbols (concat nthm "name")))
;; Fontification
(when (and (featurep 'font-latex)
(eq TeX-install-font-lock 'font-latex-setup))
(font-latex-add-keywords '(("newtheorem" "{[{[")
("renewtheorem" "{[{[")
("theoremstyle" "{")
("theorembodyfont" "{")
("theoremheaderfont" "{")
("theoremnumbering" "{")
("theoremseparator" "{")
("theorempreskip" "{")
("theorempostskip" "{")
("theoremsymbol" "{")
("theoremindent" "")
("theoremprework" "{")
("theorempostwork" "{")
("theoremclass" "{")
("newframedtheorem" "{[{[")
("newshadedtheorem" "*{[{[")
("shadecolor" "{")
("theoremframepreskip" "{")
("theoremframepostskip" "{")
("theoreminframepreskip" "{")
("theoreminframepostskip" "{")
("listtheorems" "{")
("addtheoremline" "*{{")
("addtotheoremfile" "[{")
("newtheoremstyle" "{{{")
("renewtheoremstyle" "{{{")
("newtheoremlisttype" "{{{{")
("renewtheoremlisttype" "{{{{"))
'function)
(font-latex-add-keywords '(("thref" "{"))
'reference)))
TeX-dialect)
(defvar LaTeX-ntheorem-package-options
'("standard" "noconfig" "framed" "thmmarks" "thref" "amsmath" "hyperref")
"Package options for the ntheorem package.")
;;; ntheorem.el ends here
|