blob: 4c5211d52737cbe50d9cd1b81c5b1d46bb929b1d (
plain)
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
|
;;; tex-conf.el --- My configurations of TeX -*- lexical-binding: t; -*-
;; Copyright (C) 2021 李俊緯
;; Author: 李俊緯 <mmemmew@gmail.com>
;; Keywords: tex
;; This program 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 of the License, or
;; (at your option) any later version.
;; This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This is my configuration file for (La)TeX. In particular I use and
;; configure the package AUCTeX here.
;;; Code:
(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq TeX-view-program-selection
'((output-dvi "open")
(output-pdf "PDF Tools")
(output-html "open")))
;; I don't want to split the screen.
;;;###autoload
(defun durand-TeX-pdf-tools-sync-view-a ()
"Advice to `TeX-pdf-tools-sync-view', which won't pop buffers."
(unless (fboundp 'pdf-tools-install)
(error "PDF Tools are not available"))
(unless TeX-PDF-mode
(error "PDF Tools only work with PDF output"))
(add-hook 'pdf-sync-backward-redirect-functions
#'TeX-source-correlate-handle-TeX-region)
(if (and TeX-source-correlate-mode
(fboundp 'pdf-sync-forward-search))
(with-current-buffer (or (when TeX-current-process-region-p
(get-file-buffer (TeX-region-file t)))
(current-buffer))
(pdf-sync-forward-search))
(let ((pdf (TeX-active-master (TeX-output-extension))))
(switch-to-buffer (or (find-buffer-visiting pdf)
(find-file-noselect pdf))))))
(advice-add #'TeX-pdf-tools-sync-view :override
#'durand-TeX-pdf-tools-sync-view-a)
;;; Dollars
(setq TeX-electric-math (cons "\\(" "\\)"))
(define-key LaTeX-mode-map (vector ?\§) #'durand-insert-escape)
;;;###autoload
(defun durand-insert-escape ()
"Insert an escape character."
(interactive)
(insert "\\"))
;;; Expansions
(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
(define-key LaTeX-math-mode-map (LaTeX-math-abbrev-prefix) t)
(set-default 'LaTeX-math-abbrev-prefix "ù")
(define-key LaTeX-math-mode-map
(LaTeX-math-abbrev-prefix) LaTeX-math-keymap)
(cond ((boundp 'LaTeX-math-keymap))
((defvar LaTeX-math-keymap)))
(define-key LaTeX-math-keymap [?$] 'durand-insert-display-equation)
(define-key LaTeX-math-keymap [?o] 'durand-insert-o-things)
(setq LaTeX-math-list '((?$ durand-insert-display-equation)
(?o durand-insert-o-things)))
;;;###autoload
(defun durand-insert-display-equation ()
"Insert display equation symbols."
(interactive)
(insert "\\[\\]")
(goto-char (- (point) 2)))
;;;###autoload
(defvar durand-o-things-list nil
"A list of things associated with the \"o\" key.
Each entry should have the form (key . macro),
where the macro part is without the backslash.")
(setq durand-o-things-list
(list
(cons "x" "otimes")
(cons "s" "sum")
(cons "p" "prod")
(cons "+" "oplus")
(cons "o" "circ")
(list "{" "{" "}")))
;;;###autoload
(defun durand-insert-o-things ()
"Insert a symbol associated with \"o\" key.
The list is in the variable `durand-o-things-list'"
(interactive)
(let ((thing (minibuffer-with-setup-hook 'durand-headlong-minibuffer-setup-hook
(completing-read
"Chois une chose associée à \"o\":" (mapcar 'car durand-o-things-list)
nil t "^"))))
(let ((associated (alist-get thing durand-o-things-list nil nil #'string=)))
(cond
((not (consp associated))
;; length = 1
(insert (format "\\%s" (assoc-default thing durand-o-things-list #'string=))))
((null (cddr associated))
;; length = 2
(insert (format "\\left\\%s" (car associated)))
(save-excursion
(insert
(format "\\right\\%s" (cadr associated)))))
(t
(user-error "Weird associated: %S" associated))))))
;; Automatic braces
(setq TeX-electric-sub-and-superscript t)
;;; If I need to type nested documents frequently, the following will
;;; come in handy.
;; (setq-default TeX-master nil)
(provide 'tex-conf)
;;; tex-conf.el ends here
|