Debian Codegraph @

RichterHilbertAxiomGeometry/miz3/hol-light-fonts.el

raw
1 ;; The function Math-fonts-for-HOL-Light replace the expressions
2 ;; ==>, <=>, ~, \/, /\, !, ?, SUBSET, IN, UNION, INTER and {}
3 ;; in a file with the mathematical characters (used by Isabelle)
4 ;; ⇒, ⇔, ¬, ∨, ∧, ∀, ∃, ⊂, ∈, ∪, ∩ and ∅.
5 ;; The function Remove-math-fonts-for-HOL-Light turns the mathematical characters
6 ;; ⇒, ⇔, ¬ etc back to HOL Light expressions ==>, <=>, ~ etc.
7
8 ;; Given a file with mathematical characters, the function
9 ;; File-remove-math-fonts-for-HOL-Light makes the X-selection a
10 ;; version of the file with ∀, ∃, ∩,... replaced by !, ?, INTER,... so
11 ;; it can be pasted into a ocaml/HOL-Light process.
12
13 ;; the function Region-math-fonts-removed-for-HOL-Light similarly
14 ;; processes the region.
15
16 (defun Math-fonts-for-HOL-Light ()
17 "replace HOL Light expressions (!, ?, INTER,...) with mathematical characters (∀, ∃, ∩,...) in the entire buffer."
18 (interactive)
19 (let ((start (point)))
20 (setq case-fold-search nil)
21 (goto-char (point-min))
22 (while (search-forward "\\/" nil t)
23 (replace-match "∨" nil t))
24 (goto-char (point-min))
25 (while (search-forward "/\\" nil t)
26 (replace-match "∧" nil t))
27 (goto-char (point-min))
28 (while (search-forward "===" nil t)
29 (replace-match "≡" nil t))
30 (goto-char (point-min))
31 (while (search-forward "==>" nil t)
32 (replace-match "⇒" nil t))
33 (goto-char (point-min))
34 (while (search-forward "~" nil t)
35 (replace-match "¬" nil t))
36 (goto-char (point-min))
37 (while (search-forward "<=>" nil t)
38 (replace-match "⇔" nil t))
39 (goto-char (point-min))
40 (while (search-forward "!" nil t)
41 (replace-match "∀" nil t))
42 (goto-char (point-min))
43 (while (search-forward "?" nil t)
44 (replace-match "∃" nil t))
45 (goto-char (point-min))
46 (while (search-forward "∃∀" nil t)
47 (replace-match "∃!" nil t))
48 (goto-char (point-min))
49 (while (search-forward " SUBSET " nil t)
50 (replace-match " ⊂ " nil t))
51 (goto-char (point-min))
52 (while (search-forward " SUBSET
53 " nil t)
54 (replace-match " ⊂
55 " nil t))
56 (goto-char (point-min))
57 (while (search-forward " INTER " nil t)
58 (replace-match " ∩ " nil t))
59 (goto-char (point-min))
60 (while (search-forward " INTER
61 " nil t)
62 (replace-match " ∩
63 " nil t))
64 (goto-char (point-min))
65 (while (search-forward " UNION " nil t)
66 (replace-match " ∪ " nil t))
67 (goto-char (point-min))
68 (while (search-forward " UNION
69 " nil t)
70 (replace-match " ∪
71 " nil t))
72 (goto-char (point-min))
73 (while (search-forward "{}" nil t)
74 (replace-match "∅" nil t))
75 (goto-char (point-min))
76 (while (search-forward "cong" nil t)
77 (replace-match "≅" nil t))
78 (goto-char (point-min))
79 (while (search-forward " IN " nil t)
80 (replace-match " ∈ " nil t))
81 (goto-char (point-min))
82 (while (search-forward " DIFF " nil t)
83 (replace-match " ━ " nil t))
84 (goto-char (point-min))
85 (while (search-forward " DIFF
86 " nil t)
87 (replace-match " ━
88 " nil t))
89 (goto-char (point-min))
90 (while (search-forward " INSERT " nil t)
91 (replace-match " ╪ " nil t))
92 (goto-char (point-min))
93 (while (search-forward "alpha" nil t)
94 (replace-match "α" nil t))
95 (goto-char (point-min))
96 (while (search-forward "beta" nil t)
97 (replace-match "β" nil t))
98 (goto-char (point-min))
99 (while (search-forward "gamma" nil t)
100 (replace-match "γ" nil t))
101 (goto-char (point-min))
102 (while (search-forward " angle " nil t)
103 (replace-match " ∡ " nil t))
104 (goto-char (point-min))
105 (while (search-forward "(angle " nil t)
106 (replace-match "(∡ " nil t))
107 (goto-char (point-min))
108 (while (search-forward "not===" nil t)
109 (replace-match " ≢ " nil t))
110 (goto-char (point-min))
111 (while (search-forward "NOTIN" nil t)
112 (replace-match "∉" nil t))
113 (goto-char (point-min))
114 (while (search-forward "neq" nil t)
115 (replace-match " ≠ " nil t))
116 (goto-char (point-min))
117 (while (search-forward "\\" nil t)
118 (replace-match "λ" nil t))
119 (goto-char (point-min))
120 (while (search-forward "parallel" nil t)
121 (replace-match "∥" nil t))
122 (goto-char (point-min))
123 (while (search-forward "theta" nil t)
124 (replace-match "θ" nil t))
125 (goto-char (point-min))
126 (while (search-forward "mu" nil t)
127 (replace-match "μ" nil t))
128 (goto-char (point-min))
129 (while (search-forward "--->" nil t)
130 (replace-match "→" nil t))
131 (goto-char (point-min))
132 (while (search-forward " prod " nil t)
133 (replace-match " ∏ " nil t))
134 (goto-char (point-min))
135 (while (search-forward " _o_ " nil t)
136 (replace-match " ∘ " nil t))
137 (goto-char start)))
138
139 (defun Remove-math-fonts-for-HOL-Light ()
140 "replace mathematical characters (∀, ∃, ∩,...) with HOL Light expressions (!, ?, INTER,...)."
141 (interactive)
142 (setq case-fold-search nil)
143 (untabify (point-min) (point-max))
144 (goto-char (point-min))
145 (while (search-forward "∨" nil t)
146 (replace-match "\\/" nil t))
147 (goto-char (point-min))
148 (while (search-forward "∧" nil t)
149 (replace-match "/\\" nil t))
150 (goto-char (point-min))
151 (while (search-forward "≡" nil t)
152 (replace-match "===" nil t))
153 (goto-char (point-min))
154 (while (search-forward "⇒" nil t)
155 (replace-match "==>" nil t))
156 (goto-char (point-min))
157 (while (search-forward "¬" nil t)
158 (replace-match "~" nil t))
159 (goto-char (point-min))
160 (while (search-forward "⇔" nil t)
161 (replace-match "<=>" nil t))
162 (goto-char (point-min))
163 (while (search-forward "∀" nil t)
164 (replace-match "!" nil t))
165 (goto-char (point-min))
166 (while (search-forward "∃" nil t)
167 (replace-match "?" nil t))
168 (goto-char (point-min))
169 (while (search-forward " ⊂ " nil t)
170 (replace-match " SUBSET " nil t))
171 (goto-char (point-min))
172 (while (search-forward " ∩ " nil t)
173 (replace-match " INTER " nil t))
174 (goto-char (point-min))
175 (while (search-forward " ∪ " nil t)
176 (replace-match " UNION " nil t))
177 (goto-char (point-min))
178 (while (search-forward "∅" nil t)
179 (replace-match "{}" nil t))
180 (goto-char (point-min))
181 (while (search-forward "≅" nil t)
182 (replace-match "cong" nil t))
183 (goto-char (point-min))
184 (while (search-forward " ∈ " nil t)
185 (replace-match " IN " nil t))
186 (goto-char (point-min))
187 (while (search-forward " ━ " nil t)
188 (replace-match " DIFF " nil t))
189 (goto-char (point-min))
190 (while (search-forward " ╪ " nil t)
191 (replace-match " INSERT " nil t))
192 (goto-char (point-min))
193 (while (search-forward "α" nil t)
194 (replace-match "alpha" nil t))
195 (goto-char (point-min))
196 (while (search-forward "β" nil t)
197 (replace-match "beta" nil t))
198 (goto-char (point-min))
199 (while (search-forward "γ" nil t)
200 (replace-match "gamma" nil t))
201 (goto-char (point-min))
202 (while (search-forward " ∡ " nil t)
203 (replace-match " angle " nil t))
204 (goto-char (point-min))
205 (while (search-forward "(∡ " nil t)
206 (replace-match "(angle " nil t))
207 (goto-char (point-min))
208 (while (search-forward " ≢ " nil t)
209 (replace-match " not=== " nil t))
210 (goto-char (point-min))
211 (while (search-forward "∉" nil t)
212 (replace-match "NOTIN" nil t))
213 (goto-char (point-min))
214 (while (search-forward " ≠ " nil t)
215 (replace-match " neq " nil t))
216 (goto-char (point-min))
217 (while (search-forward "λ" nil t)
218 (replace-match "\\" nil t))
219 (goto-char (point-min))
220 (while (search-forward "∥" nil t)
221 (replace-match "parallel" nil t))
222 (goto-char (point-min))
223 (while (search-forward "θ" nil t)
224 (replace-match "theta" nil t))
225 (goto-char (point-min))
226 (while (search-forward "μ" nil t)
227 (replace-match "mu" nil t))
228 (goto-char (point-min))
229 (while (search-forward "→" nil t)
230 (replace-match "--->" nil t))
231 (goto-char (point-min))
232 (while (search-forward " ∏ " nil t)
233 (replace-match " prod " nil t))
234 (goto-char (point-min))
235 (while (search-forward " ∘ " nil t)
236 (replace-match " _o_ " nil t))
237 (goto-char (point-min)))
238
239 (defun Region-math-fonts-removed-for-HOL-Light (bottom top)
240 "writes the file joe.ml in which the mathematical characters (∀, ∃, ∩,...) of the region of this file are replaced by HOL Light expressions (!, ?, INTER,...), and makes joe.ml the X-selection."
241 (interactive "r")
242 (let ((rebuff (current-buffer)))
243 ;; (save-current-buffer
244 (save-window-excursion
245 (find-file "joe.ml")
246 (goto-char (point-min))
247 (delete-region (point-min) (point-max))
248 (insert-buffer-substring rebuff bottom top)
249 (Remove-math-fonts-for-HOL-Light)
250 (goto-char (point-max))
251 (untabify (point-min) (point-max))
252 (copy-region-as-kill (point-min) (point-max))
253 (save-buffer)
254 (kill-buffer "joe.ml"))))
255
256 (defun File-math-fonts-removed-for-HOL-Light ()
257 "writes the file joe.ml in which the mathematical characters (∀, ∃, ∩,...) of this file are replaced by HOL Light expressions (!, ?, INTER,...), and makes joe.ml the X-selection."
258 (interactive)
259 (Region-math-fonts-removed-for-HOL-Light (point-min) (point-max)))
260
261 ;; Assuming the function key F2 is an unbound prefix key in Emacs, and
262 ;; this code binds the keys
263 ;; F2 i, F2 b (for biconditional) etc
264 ;; to inserting the symbols (sometimes padded with spaces), as indicated:
265
266 (global-set-key '[f2 73] '(lambda () (interactive) (insert " ⇒ "))) ;; F2 I
267 (global-set-key '[f2 98] '(lambda () (interactive) (insert " ⇔ "))) ;; F2 b
268 (global-set-key '[f2 110] '(lambda () (interactive) (insert "¬"))) ;; F2 n
269 (global-set-key '[f2 111] '(lambda () (interactive) (insert " ∨ "))) ;; F2 o
270 (global-set-key '[f2 97] '(lambda () (interactive) (insert " ∧ "))) ;; F2 a
271 (global-set-key '[f2 102] '(lambda () (interactive) (insert "∀"))) ;; F2 f
272 (global-set-key '[f2 69] '(lambda () (interactive) (insert "∃"))) ;; F2 E
273 (global-set-key '[f2 115] '(lambda () (interactive) (insert " ⊂ "))) ;; F2 s
274 (global-set-key '[f2 105] '(lambda () (interactive) (insert " ∈ "))) ;; F2 i
275 (global-set-key '[f2 86] '(lambda () (interactive) (insert " ∪ "))) ;; F2 V
276 (global-set-key '[f2 65] '(lambda () (interactive) (insert " ∩ "))) ;; F2 A
277 (global-set-key '[f2 99] '(lambda () (interactive) (insert " ≅ "))) ;; F2 c
278 (global-set-key '[f2 101] '(lambda () (interactive) (insert " ≡ "))) ;; F2 e
279 (global-set-key '[f2 78] '(lambda () (interactive) (insert "∅"))) ;; F2 N
280 (global-set-key '[f2 100] '(lambda () (interactive) (insert " ━ "))) ;; F2 d
281 (global-set-key '[f2 112] '(lambda () (interactive) (insert " ╪ "))) ;; F2 p
282 (global-set-key '[f2 108] '(lambda () (interactive) (insert "λ"))) ;; F2 l
283 (global-set-key '[f2 109] '(lambda () (interactive) (insert "μ"))) ;; F2 m
284 (global-set-key '[f2 49] '(lambda () (interactive) (insert "α"))) ;; F2 1
285 (global-set-key '[f2 50] '(lambda () (interactive) (insert "β"))) ;; F2 2
286 (global-set-key '[f2 51] '(lambda () (interactive) (insert "γ"))) ;; F2 3
287 (global-set-key '[f2 52] '(lambda () (interactive) (insert "θ"))) ;; F2 4
288 (global-set-key '[f2 53] '(lambda () (interactive) (insert "φ"))) ;; F2 5
289 (global-set-key '[f2 125] '(lambda () (interactive) (insert " ≠ " ))) ;; F2 }
290 (global-set-key '[f2 123] '(lambda () (interactive) (insert " ∉ "))) ;; F2 {
291 (global-set-key '[f2 48] '(lambda () (interactive) (insert " ≢ "))) ;; F2 0
292 (global-set-key '[f2 57] '(lambda () (interactive) (insert "∡ "))) ;; F2 9
293 (global-set-key '[f2 56] '(lambda () (interactive) (insert " ≇ "))) ;; F2 8
294 (global-set-key '[f2 55] '(lambda () (interactive) (insert " ∥ "))) ;; F2 7
295 (global-set-key '[f2 54] '(lambda () (interactive) (insert " ∦ "))) ;; F2 6
296 (global-set-key '[f2 70] '(lambda () (interactive) (insert " → "))) ;; F2 F
297 (global-set-key '[f2 80] '(lambda () (interactive) (insert " ∏ "))) ;; F2 P
298 (global-set-key '[f2 79] '(lambda () (interactive) (insert " ∘ "))) ;; F2 O
299 (global-set-key '[f2 79] '(lambda () (interactive) (insert " ∘ "))) ;; F2 O
300 (global-set-key '[f2 68] '(lambda () (interactive) (insert " ◼ "))) ;; F2 D
301
302 ;; Two Emacs functions are useful in this context:
303 ;; (string-to-char "⇒") => 8658
304 ;; (char-to-string 8660) => "⇔"
305
306 ;; Here's my low-level system using math symbols in HOL-Light/Miz3 .
307 ;; In the Emacs buffer containing math symbols, type
308 ;; M-x remove-math-fonts-for-HOL-Light
309 ;; and then mouse-paste into a terminal window (or Emacs shell)
310 ;; running ocaml/HOL Light/miz3. The X selection pasted by the mouse
311 ;; is copied to a file joe.ml, which is the original file with the math symbols
312 ;; ∅ etc replaced by into their HOL Light versions {} etc.
313
314 ;; The command M-x remove-math-fonts-for-HOL-Light will be in the
315 ;; command history, and you can recall it with repeat-complex-command,
316 ;; which I bind to the function key F8 by
317 ;; (global-set-key [f8] 'repeat-complex-command)
318
319 (setq auto-mode-alist (append `(("ml\\'" . text-mode))
320 auto-mode-alist))
321 (add-hook 'text-mode-hook 'turn-off-auto-fill)
322 (add-hook 'text-mode-hook 'turn-on-visual-line-mode)
323 (add-hook 'text-mode-hook
324 (lambda ()
325 (setq comment-start "::")))
326
327 (setq select-active-regions nil)
328 (setq mouse-drag-copy-region t)
329 (setq x-select-enable-primary t)
330 (setq x-select-enable-clipboard nil)