-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlatex-stuff.el
45 lines (41 loc) · 1.51 KB
/
latex-stuff.el
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
; LaTeX stuff
(load "auctex.el" nil t t) ; auctex
(load "preview-latex.el" nil t t) ; preview-latex
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(add-hook 'LaTeX-mode-hook 'TeX-PDF-mode)
(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
(defun insert-latex-brackets (opening closing) ; prototype function for all enclosing things
(interactive)
(insert opening)
(insert " ")
(insert closing)
(backward-char (+ 1 (length closing )))
)
(defun check-char-and-insert (char opening closing)
(interactive)
(if (equal char (char-to-string (char-before (point))))
(progn (delete-backward-char 1)
(insert-latex-brackets opening closing))
(insert char)
)
)
(add-hook 'reftex-mode-hook ; balanced math parentheses in LaTeX
(lambda ()
(define-key reftex-mode-map (kbd "(")
(lambda ()(interactive) (check-char-and-insert "(" "\\left(" "\\right)")))
(define-key reftex-mode-map (kbd "[")
(lambda ()
(interactive) (check-char-and-insert "[" "\\left[" "\\right]")))
(define-key reftex-mode-map (kbd "{")
(lambda ()
(interactive) (check-char-and-insert "{" "\\left\\{" "\\right\\}")))
(define-key reftex-mode-map (kbd "C-( (")
(lambda ()
(interactive) (insert-latex-brackets "\\left(" "\\right)")))
(define-key reftex-mode-map (kbd "C-( [")
(lambda ()
(interactive) (insert-latex-brackets "\\left[" "\\right]")))
(define-key reftex-mode-map (kbd "C-( {")
(lambda ()
(interactive) (insert-latex-brackets "\\left\\{" "\\right\\}"))))
)