11
|
1 ;;; -*- Emacs-Lisp -*-
|
|
2 ;;; YaTeX interface for math-mode.
|
|
3 ;;; yatexmth.el rev.0
|
|
4 ;;; (C)1993 by HIROSE Yuuji [yuuji@ae.keio.ac.jp]
|
|
5 ;;; Last modified Tue Aug 3 23:37:07 1993 on 98fa
|
|
6 ;;; $Id$
|
|
7
|
|
8 (setq
|
|
9 YaTeX-math-key-alist-default
|
|
10 '(
|
|
11 ;frequently used
|
|
12 ("||" "|" ("||" "a"))
|
|
13 ("sum" "sum" ("\\-+\n >\n/-+" ""))
|
|
14 ("sigma" "sum" ("\\-+\n >\n/-+" ""))
|
|
15 ("integral" "int" " /\\\n \\\n\\/")
|
|
16 ("ointegral" "oint" " /\\\n(\\)\n\\/")
|
|
17 ("A" "forall" "|_|\nV")
|
|
18 ("E" "exists" "-+\n-+\n-+")
|
|
19 ("!" "neg" "--+\n |")
|
|
20 ("oo" "infty" ("oo" ""))
|
|
21 ("\\" "backslash" ("\\" "_"))
|
|
22
|
|
23 ;;binary operators
|
|
24 ("+-" "pm" ("+\n-" "}"))
|
|
25 ("-+" "mp" "-\n+")
|
|
26 ("x" "times" ("x" "~"))
|
|
27 ("/" "div" (",\n-\n'" ""))
|
|
28 ("*" "ast" "*")
|
|
29 ("#" "star" ("_/\\_\n\\ /\n//\\\\" ""))
|
|
30 ("o" "circ" "o")
|
|
31 ("o*" "bullet" " _\n(*)\n ~")
|
|
32 ("." "cdot" ".")
|
|
33 ("cap" "cap" "/-\\\n| |")
|
|
34 ("cup" "cup" "| |\n\\-/")
|
|
35 ("u+" "uplus" "|+|\n\\-/")
|
|
36 ("|~|" "sqcap" "|~|")
|
|
37 ("|_|" "sqcup" "|_|")
|
|
38 ("v" "vee" "v")
|
|
39 ("^" "wedge" "^")
|
|
40 ("\\\\" "setminus" "\\")
|
|
41 (")(" "wr" " )\n(")
|
|
42 ("<>" "diamond" "<>")
|
|
43 ("/\-" "bigtriangleup" ("/\\\n~~" ""))
|
|
44 ("-\\/" "bigtriangledown" ("__\n\\/" ""))
|
|
45 ("<|" "triangleleft" "<|")
|
|
46 ("|>" "triangleright" "|>")
|
|
47 ("<||" "lhd" "/|\n\\|")
|
|
48 ("||>" "rhd" "|\\\n|/")
|
|
49 ("<|-" "unlhd" "<|\n~~")
|
|
50 ("|>-" "unrhd" "|>\n~~")
|
|
51 ("o+" "oplus" " _\n(+)\n ~")
|
|
52 ("o-" "ominus" " _\n(-)\n ~")
|
|
53 ("ox" "otimes" " _\n(x)\n ~")
|
|
54 ("o/" "oslash" " _\n(/)\n ~")
|
|
55 ("o." "odot" "(.)")
|
|
56 ("O" "bigcirc" "O")
|
|
57 ("t" "dagger" "+\n|")
|
|
58 ("tt" "ddagger" "+\n+\n|")
|
|
59 ("II" "amalg" "II")
|
|
60 ; :
|
|
61 ;;relational operators
|
|
62 ("<" "leq" ("<\n-" ""))
|
|
63 (">" "geq" (">\n-" ""))
|
|
64 ("-=" "equiv" "=\n-")
|
|
65 ("=-" "equiv" "=\n-")
|
|
66 ("---" "equiv" "=\n-")
|
|
67 ("(" "subset" " _\n(\n ~")
|
|
68 ("(-" "subseteq" " _\n(_\n~")
|
|
69 (")" "supset" "_\n )\n~")
|
|
70 (")-" "supseteq" "_\n_)\n~")
|
|
71 ("[" "sqsubset" "[")
|
|
72 ("[-" "sqsubseteq" "[\n~")
|
|
73 ("]" "sqsupset" "]")
|
|
74 ("]-" "sqsupseteq" "]\n~")
|
|
75 ("{" "in" "(-")
|
|
76 ("}" "ni" "-)")
|
|
77 ("|-" "vdash" "|-")
|
|
78 ("-|" "dashv" "-|")
|
|
79 ("~" "sim" "~(tild)")
|
|
80 ("~-" "simeq" "~\n-")
|
|
81 ("asymp" "asymp" "v\n^")
|
|
82 ("~~" "approx" "~\n~")
|
|
83 ("~=" "cong" "~\n=")
|
|
84 ("=/" "neq" ("=/=" ""))
|
|
85 (".=" "doteq" ".\n=")
|
|
86 ("o<" "propto" "o<")
|
|
87 ("|=" "models" "|=")
|
|
88 ("_|_" "perp" "_|_")
|
|
89 ("|" "mid" "|")
|
|
90 ("||" "parallel" "||")
|
|
91 ("bowtie" "bowtie" "|><|(wide)")
|
|
92 ("|><|" "join" "|><|")
|
|
93 ("\\_/" "smile" "\\_/")
|
|
94 ("/~\\" "frown" "/~~\\")
|
|
95 ("-<" "prec" ("-<" ""))
|
|
96 ("-<=" "preceq" ("-<\n-" "\n="))
|
|
97 ("<<" "ll" ("<<" "s"))
|
|
98 ; :
|
|
99 ;;arrows
|
|
100 ("<-" "leftarrow" ("<-" ""))
|
|
101 ("<--" "longleftarrow" ("<-" "--"))
|
|
102 ("<=" "Leftarrow" "<=")
|
|
103 ("<==" "Longleftarrow" "<==")
|
|
104 ("->" "rightarrow" ("->" ""))
|
|
105 ("-->" "longrightarrow" ("-->" "--"))
|
|
106 ("==>" "Longrightarrow" "==>")
|
|
107 ("<->" "leftrightarrow" ("<->" ""))
|
|
108 ("<-->" "longleftrightarrow" ("<---->" "--"))
|
|
109 ("<=>" "leftrightarrow" "<=>")
|
|
110 ("<==>" "Longleftrightarrow" "<==>")
|
|
111 ("^|" "uparrow" ("^\n|" ""))
|
|
112 ("^||" "Uparrow" "/\\\n||")
|
|
113 ("\C-n" "downarrow" ("|\nv" ""))
|
|
114 ("^|" "uparrow" ("^\n|" ""))
|
|
115 ("|->" "mapsto" ("|->" "|"))
|
|
116 ("<-)" "hookleftarrow" (" ,\n<--+" " R\n<--/"))
|
|
117 ("/-" "leftharpoonup" "/\n~~~")
|
|
118 ("\\-" "leftharpoondown" "__\n\\")
|
|
119 ("-/" "rightharpoondown" "__\n/")
|
|
120 ("-\\" "rightharpoonup" "~~\n\\")
|
|
121 ;other marks
|
|
122 ("Z" "aleph" "|\\|")
|
|
123 ("|\\|" "aleph" "|\\|")
|
|
124 ("h-" "hbar" "_\nh")
|
|
125 ("i" "imath" "i")
|
|
126 ("j" "jmath" "j")
|
|
127 ("l" "ell" "l")
|
|
128 ("wp" "wp" "???")
|
|
129 ("R" "Re" ")R")
|
|
130 ("Im" "Im" "???")
|
|
131 ("mho" "mho" "~|_|~")
|
|
132 ("'" "prime" "'")
|
|
133 ("0" "emptyset" "0")
|
|
134 ("nabla" "nabla" "___\n\\\\/")
|
|
135 ("\\/" "surd" "-\\/")
|
|
136 ("surd" "surd" "-\\/")
|
|
137 ("top" "top" "T")
|
|
138 ("bot" "bot" "_|_")
|
|
139 ("b" "flat" "b")
|
|
140 ("LT" "natural" "|\nLT\n |")
|
|
141 ("6" "partial" " -+\n+-+\n+-+")
|
|
142 ("partial" "partial" " -+\n+-+\n+-+")
|
|
143 ("round" "partial" " -+\n+-+\n+-+")
|
|
144 ("[]" "box" "[]")
|
|
145 ("Diamond" "Diamond" "/\\\n\\/")
|
|
146 ("3" "triangle" "/\\\n~~")
|
|
147 ("C" "clubsuit" " o\no+o\n |")
|
|
148 ("D" "diamondsuit" "/\\\n\\/")
|
|
149 ("H" "heartsuit" "<^^>\n \\/")
|
|
150 ("S" "spadesuit" " /\\\n<++>\n /\\")
|
|
151
|
|
152 ))
|
|
153
|
|
154 (defvar YaTeX-math-key-alist-private nil
|
|
155 "*User definable key vs LaTeX-math-command alist.")
|
|
156
|
|
157 (defvar YaTeX-math-quit-with-strict-match nil
|
|
158 "*T for quitting completion as soon as strict-match is found.")
|
|
159 (setq YaTeX-math-key-alist
|
|
160 (append YaTeX-math-key-alist-private YaTeX-math-key-alist-default))
|
|
161
|
|
162 (setq YaTeX-math-key-array
|
|
163 (let ((array (make-vector (length YaTeX-math-key-alist) ""))
|
|
164 (list YaTeX-math-key-alist) (i 0))
|
|
165 (while list
|
|
166 (aset array i (car (car list)))
|
|
167 (setq i (1+ i) list (cdr list)))
|
|
168 array))
|
|
169
|
|
170 (defvar YaTeX-ec "\\" "Escape character of mark-up language.")
|
|
171 (setq YaTeX-math-indicator
|
|
172 "KEY\tLaTeX sequence\t\tsign")
|
|
173
|
|
174 (defvar YaTeX-math-need-image t
|
|
175 "*T for displaying pseudo image momentarily.")
|
|
176 (defvar YaTeX-math-max-key 8)
|
|
177 (defvar YaTeX-math-max-seq
|
|
178 (* 8 (1+ (/ (length "\\longleftrightarrow") 8))))
|
|
179 (defvar YaTeX-math-max-sign 5)
|
|
180 (defvar YaTeX-math-sign-width
|
|
181 (+ YaTeX-math-max-key YaTeX-math-max-seq YaTeX-math-max-sign))
|
|
182 (defvar YaTeX-math-display-width
|
|
183 (* 8 (1+ (/ YaTeX-math-sign-width 8))))
|
|
184 (defvar YaTeX-math-menu-map nil
|
|
185 "Keymap used in YaTeX mathematical sign menu mode."
|
|
186 )
|
|
187 (if YaTeX-math-menu-map nil
|
|
188 (setq YaTeX-math-menu-map (make-sparse-keymap))
|
|
189 (define-key YaTeX-math-menu-map "n" 'next-line)
|
|
190 (define-key YaTeX-math-menu-map "p" 'previous-line)
|
|
191 (define-key YaTeX-math-menu-map "f" 'YaTeX-math-forward)
|
|
192 (define-key YaTeX-math-menu-map "b" 'YaTeX-math-backward)
|
|
193 (define-key YaTeX-math-menu-map "v" 'scroll-up)
|
|
194 (define-key YaTeX-math-menu-map " " 'scroll-up)
|
|
195 (define-key YaTeX-math-menu-map "c" 'scroll-up)
|
|
196 (define-key YaTeX-math-menu-map "V" 'scroll-down)
|
|
197 (define-key YaTeX-math-menu-map "r" 'scroll-down)
|
|
198 (define-key YaTeX-math-menu-map "\^h" 'scroll-down)
|
|
199 (define-key YaTeX-math-menu-map "<" 'beginning-of-buffer)
|
|
200 (define-key YaTeX-math-menu-map ">" 'end-of-buffer)
|
|
201 (define-key YaTeX-math-menu-map "\^m" 'exit-recursive-edit)
|
|
202 (define-key YaTeX-math-menu-map "q" 'abort-recursive-edit))
|
|
203
|
|
204 (defmacro YaTeX-math-japanese-sign (list)
|
|
205 (list 'nth 1 list))
|
|
206
|
|
207 (defvar YaTeX-math-cmd-regexp (concat (regexp-quote YaTeX-ec) "[A-z]"))
|
|
208
|
|
209 (defun YaTeX-math-forward (arg)
|
|
210 (interactive "p")
|
|
211 (re-search-forward YaTeX-math-cmd-regexp nil t arg))
|
|
212
|
|
213 (defun YaTeX-math-backward (arg)
|
|
214 (interactive "p")
|
|
215 (re-search-backward YaTeX-math-cmd-regexp nil t arg))
|
|
216
|
|
217 (defun YaTeX-math-get-sign (list)
|
|
218 (let ((sign (car (cdr (cdr list)))))
|
|
219 (if (listp sign)
|
|
220 (setq sign (cond
|
|
221 (YaTeX-japan (YaTeX-math-japanese-sign sign))
|
|
222 (t (car sign)))))
|
|
223 sign)
|
|
224 )
|
|
225
|
|
226 (defun YaTeX-math-display-list (list cols)
|
|
227 (goto-char (point-max))
|
|
228 (if (= cols 0) (if (not (eolp)) (newline 1))
|
|
229 (forward-line -1)
|
|
230 (while (looking-at "[ \t\n]") (forward-line -1)))
|
|
231 (end-of-line)
|
|
232 (let ((indent (* YaTeX-math-display-width cols)) sign str to)
|
|
233 (indent-to indent)
|
|
234 (insert (car list))
|
|
235 (indent-to (setq indent (+ indent YaTeX-math-max-key)))
|
|
236 (insert "\\" (car (cdr list)))
|
|
237 (setq indent (+ indent YaTeX-math-max-seq))
|
|
238 (setq sign (YaTeX-math-get-sign list))
|
|
239 (while (not (string= "" sign))
|
|
240 (setq to (string-match "\n" sign)
|
|
241 str (if to (substring sign 0 to) sign))
|
|
242 (end-of-line)
|
|
243 (indent-to indent)
|
|
244 (insert str)
|
|
245 (cond ((eobp) (newline 1))
|
|
246 ((> cols 0) (forward-line 1)))
|
|
247 (setq sign (if to (substring sign (1+ to)) "")))))
|
|
248
|
|
249 (defvar YaTeX-math-menu-buffer "*math-mode-signs*")
|
|
250
|
|
251 (defun YaTeX-math-show-menu (match-str)
|
|
252 (save-window-excursion
|
|
253 (pop-to-buffer YaTeX-math-menu-buffer)
|
|
254 (let ((maxcols (max 1 (/ (screen-width) YaTeX-math-sign-width)))
|
|
255 (case-fold-search nil)
|
|
256 (cols 0) (list YaTeX-math-key-alist) command)
|
|
257 (erase-buffer)
|
|
258 (insert YaTeX-math-indicator "\t")
|
|
259 (insert YaTeX-math-indicator)
|
|
260 (newline 1)
|
|
261 (insert-char ?- (1- (screen-width)))
|
|
262 (newline 1)
|
|
263 (while list
|
|
264 (if (string-match match-str (car (car list)))
|
|
265 (progn (YaTeX-math-display-list (car list) cols)
|
|
266 (setq cols (% (1+ cols) maxcols))))
|
|
267 (setq list (cdr list)))
|
|
268 (goto-char (point-min))
|
|
269 (use-local-map YaTeX-math-menu-map)
|
|
270 (unwind-protect
|
|
271 (recursive-edit)
|
|
272 (skip-chars-backward "^ \t\n")
|
|
273 (setq command
|
|
274 (if (re-search-forward YaTeX-math-cmd-regexp nil t)
|
|
275 (buffer-substring
|
|
276 (match-beginning 0)
|
|
277 (prog2 (skip-chars-forward "^ \t\n") (point)))
|
|
278 nil))
|
|
279 (kill-buffer YaTeX-math-menu-buffer))
|
|
280 command))
|
|
281 )
|
|
282
|
|
283 ;
|
|
284 (defun YaTeX-math-show-image (image &optional exit-char)
|
|
285 "Momentarily display IMAGE at the beginning of the next line;
|
|
286 erase it on the next keystroke. The window is recentered if necessary
|
|
287 to make the whole string visible. If the window isn't large enough,
|
|
288 at least you get to read the beginning."
|
|
289 (let ((buffer-read-only nil)
|
|
290 (modified (buffer-modified-p))
|
|
291 (name buffer-file-name)
|
|
292 insert-start
|
|
293 insert-end)
|
|
294 (unwind-protect
|
|
295 (progn
|
|
296 (save-excursion
|
|
297 ;; defeat file locking... don't try this at home, kids!
|
|
298 (setq buffer-file-name nil)
|
|
299 (forward-line 1)
|
|
300 (setq insert-start (point))
|
|
301 (if (eobp) (newline))
|
|
302 (insert image)
|
|
303 (setq insert-end (point)))
|
|
304 ; make sure the whole string is visible
|
|
305 (if (not (pos-visible-in-window-p insert-end))
|
|
306 (recenter (max 0
|
|
307 (- (window-height)
|
|
308 (count-lines insert-start insert-end)
|
|
309 2))))
|
|
310 (let ((char (read-char)))
|
|
311 (or (eq char exit-char)
|
|
312 (setq unread-command-char char))))
|
|
313 (if insert-end
|
|
314 (save-excursion
|
|
315 (delete-region insert-start insert-end)))
|
|
316 (setq buffer-file-name name)
|
|
317 (set-buffer-modified-p modified))))
|
|
318
|
|
319 (defun YaTeX-math-insert-sequence ()
|
|
320 (interactive)
|
|
321 (let ((key "") regkey str last-char list i
|
|
322 (case-fold-search nil) match
|
|
323 (n (length YaTeX-math-key-array)) (beg (point)) result)
|
|
324 (setq result
|
|
325 (catch 'complete
|
|
326 (while t
|
|
327 (setq last-char (read-char)
|
|
328 key (concat key (char-to-string last-char))
|
|
329 regkey (concat "^" (regexp-quote key)) i 0)
|
|
330 (cond
|
|
331 ((string= key YaTeX-math-invoke-key) ;;invoke key itself
|
|
332 (throw 'complete 'escape))
|
|
333 ((string-match "[\C-g\C-c]" key) (throw 'complete 'abort))
|
|
334 ((string-match "[\n\r]" key) (throw 'complete 'menu)))
|
|
335 (if
|
|
336 (catch 'found
|
|
337 ;;(1)input string strictly matches with alist
|
|
338 (setq single-command (car (cdr match))
|
|
339 ;;remember previous match
|
|
340 match (assoc key YaTeX-math-key-alist))
|
|
341 ;;(2)search partial match into alist
|
|
342 (while (< i n)
|
|
343 (if (string-match
|
|
344 regkey (aref YaTeX-math-key-array i))
|
|
345 (progn
|
|
346 (or match
|
|
347 (setq match (nth i YaTeX-math-key-alist)))
|
|
348 (throw 'found t)))
|
|
349 (setq i (1+ i)))) ;catch 'found
|
|
350 nil ;;if any match, continue reading
|
|
351 ;;else reading of sequence has been done.
|
|
352 (message "complete.")
|
|
353 (throw 'complete t)
|
|
354 )
|
|
355 (if match
|
|
356 (progn (delete-region beg (point))
|
|
357 (insert YaTeX-ec (car (cdr match)))
|
|
358 (if YaTeX-math-need-image
|
|
359 (YaTeX-math-show-image
|
|
360 (concat (YaTeX-math-get-sign match) "\n")))
|
|
361 )
|
|
362 nil)
|
|
363 )))
|
|
364 (cond
|
|
365 ((eq result t)
|
|
366 (setq YaTeX-current-completion-type 'maketitle)
|
|
367 (if t nil
|
|
368 (delete-region beg (point))
|
|
369 (setq single-command (car (cdr match)))
|
|
370 ;;(recursive-edit)
|
|
371 (insert YaTeX-ec single-command)
|
|
372 )
|
|
373 (sit-for 1)
|
|
374 (setq unread-command-char last-char)
|
|
375 (insert (YaTeX-addin single-command)))
|
|
376 ((eq result 'abort)
|
|
377 (delete-region beg (point))
|
|
378 (message "Abort."))
|
|
379 ((eq result 'escape)
|
|
380 (delete-region beg (point))
|
|
381 (insert YaTeX-math-invoke-key))
|
|
382 ((eq result 'menu)
|
|
383 (delete-region beg (point))
|
|
384 (setq key (concat "^" (regexp-quote (substring key 0 -1))))
|
|
385 (insert (YaTeX-math-show-menu key)))))
|
|
386 )
|
|
387 ;;
|
|
388 (provide 'yatexmth)
|