yatex

view yatexmth.el @ 68:0eb6997bee16

More adjustment for Emacs20 and XEmacs [prefix] g for <applet> <!--#include> <!--#exec>
author yuuji
date Mon, 26 Oct 1998 12:05:32 +0000
parents 36a48185b95a
children 807c1e7e68b7
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX math-mode-specific functions.
3 ;;; yatexmth.el
4 ;;; (c )1993-1998 by HIROSE Yuuji [yuuji@ae.keio.ac.jp]
5 ;;; Last modified Wed Sep 30 21:26:29 1998 on firestorm
6 ;;; $Id$
8 ;;; [Customization guide]
9 ;;;
10 ;;; By default, you can use two completion groups in YaTeX math
11 ;;; mode, `;' for mathematical signs and `:' for greek letters. But
12 ;;; you can add other completion groups by defining the alist of
13 ;;; `prefix key' vs `completion list' into the variable
14 ;;; YaTeX-math-key-list-private. If you wish to accomplish the
15 ;;; completion as follows(prefix key is `,'):
16 ;;;
17 ;;; KEY COMPLETION
18 ;;; s \sin
19 ;;; S \arcsin
20 ;;; c \cos
21 ;;; C \arccos
22 ;;; :
23 ;;; T \arctan
24 ;;; l \log
25 ;;; hs \sinh
26 ;;;
27 ;;; Typing `s' after `,' makes `\sin', `hs' after `,' makes `\sinh'
28 ;;; and so on. First, you have to define list of key-completion
29 ;;; pairs. Variable name(YaTeX-math-funcs-list) is arbitrary.
30 ;;;
31 ;;; (setq YaTeX-math-funcs-list
32 ;;; '(("s" "sin")
33 ;;; ("S" "arcsin")
34 ;;; :
35 ;;; ("hs" "sinh")))
36 ;;;
37 ;;; Next, define the list of prefix-key vs completion list(defined
38 ;;; above) into the variable YaTeX-math-key-list-private.
39 ;;;
40 ;;; (setq YaTeX-math-key-list-private
41 ;;; '(("," . YaTeX-math-funcs-list)
42 ;;; ("'" . Other-List-if-any)))
43 ;;;
44 ;;; Put these expressions into your ~/.emacs, and you can use this
45 ;;; completion in the math-mode.
46 ;;;
47 ;;; And you can add your favorite completion sequences to the
48 ;;; default completion list invoked with `;', by defining those lists
49 ;;; into variable YaTeX-math-sign-alist-private.
51 ;;; 【イメージ補完の追加方法】
52 ;;;
53 ;;; 標準のイメージ補完では、「;」で始まる数式記号補完と、「:」で始
54 ;;; まるギリシャ文字補完が使用可能ですが、これ以外の文字で始まる補完
55 ;;; シリーズも定義することができます。例えば、「,」で始まる次のよう
56 ;;; な補完シリーズを定義する場合を考えてみます。
57 ;;;
58 ;;; 補完キー 補完結果
59 ;;; s \sin
60 ;;; S \arcsin
61 ;;; c \cos
62 ;;; C \arccos
63 ;;; :
64 ;;; T \arctan
65 ;;; l \log
66 ;;; hs \sinh
67 ;;;
68 ;;; 「,」のあとに s を押すと \sin が、hs を押すと \sinh が入力されま
69 ;;; す。このような補完リストの登録は以下のようにします(変数名は任意)。
70 ;;;
71 ;;; (setq YaTeX-math-funcs-list
72 ;;; '(("s" "sin")
73 ;;; ("S" "arcsin")
74 ;;; :
75 ;;; ("hs" "sinh")))
76 ;;;
77 ;;; さらに、「,」を押した時にイメージ補完が始まるよう次の変数に、起動キー
78 ;;; と上で定義した補完用変数の登録を行ないます。
79 ;;;
80 ;;; (setq YaTeX-math-key-list-private
81 ;;; '(("," . YaTeX-math-funcs-list)
82 ;;; ("'" . ほかに定義したいシリーズがあれば…)))
83 ;;;
84 ;;; これらを ~/.emacs に書いておけば、math-mode で自分専用のイメージ
85 ;;; 補完が利用できます。
87 (defvar YaTeX-jisold
88 (and (boundp 'dos-machine-type)
89 (eq dos-machine-type 'pc98)))
91 (defmacro YaTeX-setq-math-sym (sym old new)
92 (list 'setq sym (list 'if 'YaTeX-jisold old new)))
94 (YaTeX-setq-math-sym YaTeX-image-in "E" "∈")
95 (YaTeX-setq-math-sym YaTeX-image-ni "ヨ" "∋")
96 (YaTeX-setq-math-sym YaTeX-image-subset " _\n(\n ~" "⊂")
97 (YaTeX-setq-math-sym YaTeX-image-subseteq " _\n(_\n ~" "⊆")
98 (YaTeX-setq-math-sym YaTeX-image-supset "_\n )\n~" "⊃")
99 (YaTeX-setq-math-sym YaTeX-image-supseteq "_\n_)\n~" "⊇")
100 (YaTeX-setq-math-sym YaTeX-image-nabla "___\n\\\\/" "∇")
101 (YaTeX-setq-math-sym YaTeX-image-partial " -+\n+-+\n+-+" "∂")
102 (YaTeX-setq-math-sym YaTeX-image-dagger "+\n|" "†")
103 (YaTeX-setq-math-sym YaTeX-image-ddagger "+\n+\n|" "‡")
104 (YaTeX-setq-math-sym YaTeX-image-equiv "=\n ̄" "≡")
105 (YaTeX-setq-math-sym YaTeX-image-int " /\\\n \\\n\\/" "∫")
106 (YaTeX-setq-math-sym YaTeX-image-bot "|\n ̄" "⊥")
107 (YaTeX-setq-math-sym YaTeX-image-neg "イ" "¬")
108 (YaTeX-setq-math-sym YaTeX-image-flat "b" "♭")
109 (YaTeX-setq-math-sym YaTeX-image-sqrt "" "√")
111 (defvar
112 YaTeX-math-sign-alist-default
113 '(
114 ;frequently used
115 ("||" "|" ("||" "‖"))
116 ("sum" "sum" ("\\-+\n >\n/-+" "Σ"))
117 ("sigma" "sum" ("\\-+\n >\n/-+" "Σ"))
118 ("integral" "int" (" /\\\n \\\n\\/" YaTeX-image-int))
119 ("ointegral" "oint" " /\\\n(\\)\n\\/")
120 ("sqrt" "sqrt" (" __\n,/" YaTeX-image-sqrt))
121 ("root" "sqrt" (" __\n,/" YaTeX-image-sqrt))
122 ("A" "forall" "|_|\nV")
123 ("E" "exists" "-+\n-+\n-+")
124 ("!" "neg" ("--+\n |" YaTeX-image-neg))
125 ("oo" "infty" ("oo" "∞"))
126 ("\\" "backslash" ("\\" "\"))
127 ("..." "cdots" ("..." "…"))
129 ;;binary operators
130 ("+-" "pm" ("+\n-" "±"))
131 ("-+" "mp" "-\n+")
132 ("x" "times" ("x" "×"))
133 ("/" "div" (",\n-\n'" "÷"))
134 ("f" "frac" "xxx\n---\nyyy" "÷")
135 ("*" "ast" "*")
136 ("#" "star" ("_/\\_\n\\ /\n//\\\\" "★"))
137 ("o" "circ" "o")
138 ("o*" "bullet" " _\n(*)\n ~")
139 ("." "cdot" ".")
140 ("cap" "cap" "/-\\\n| |")
141 ("cup" "cup" "| |\n\\-/")
142 ("u+" "uplus" "|+|\n\\-/")
143 ("|~|" "sqcap" "|~|")
144 ("|_|" "sqcup" "|_|")
145 ("v" "vee" "v")
146 ("^" "wedge" "^")
147 ("\\\\" "setminus" "\\")
148 (")(" "wr" " )\n(")
149 ("<>" "diamond" "<>")
150 ("/\-" "bigtriangleup" ("/\\\n~~" "△"))
151 ("-\\/" "bigtriangledown" ("__\n\\/" "▽"))
152 ("<|" "triangleleft" "<|")
153 ("|>" "triangleright" "|>")
154 ("<||" "lhd" "/|\n\\|")
155 ("||>" "rhd" "|\\\n|/")
156 ("<|-" "unlhd" "<|\n~~")
157 ("|>-" "unrhd" "|>\n~~")
158 ("o+" "oplus" " _\n(+)\n ~")
159 ("o-" "ominus" " _\n(-)\n ~")
160 ("ox" "otimes" " _\n(x)\n ~")
161 ("o/" "oslash" " _\n(/)\n ~")
162 ("o." "odot" "(.)")
163 ("O" "bigcirc" "O")
164 ("t" "dagger" ("+\n|" YaTeX-image-dagger))
165 ("tt" "ddagger" ("+\n+\n|" YaTeX-image-ddagger))
166 ("II" "amalg" "II")
167 ; :
168 ;;relational operators
169 ("<" "leq" ("<\n-" "≦"))
170 (">" "geq" (">\n-" "≧"))
171 ("-=" "equiv" ("=\n-" YaTeX-image-equiv))
172 ("=-" "equiv" ("=\n-" YaTeX-image-equiv))
173 ("---" "equiv" ("=\n-" YaTeX-image-equiv))
174 ("(" "subset" (" _\n(\n ~" YaTeX-image-subset))
175 ("(-" "subseteq" (" _\n(_\n ~" YaTeX-image-subseteq))
176 (")" "supset" ("_\n )\n~" YaTeX-image-supset))
177 (")-" "supseteq" ("_\n_)\n~" YaTeX-image-supseteq))
178 ("[" "sqsubset" "[")
179 ("[-" "sqsubseteq" "[\n~")
180 ("]" "sqsupset" "]")
181 ("]-" "sqsupseteq" "]\n~")
182 ("{" "in" ("(-" YaTeX-image-in))
183 ("}" "ni" ("-)" YaTeX-image-ni))
184 ("|-" "vdash" "|-")
185 ("-|" "dashv" "-|")
186 ("~" "sim" "~(tild)")
187 ("~-" "simeq" "~\n-")
188 ("asymp" "asymp" "v\n^")
189 ("~~" "approx" "~\n~")
190 ("~=" "cong" "~\n=")
191 ("=/" "neq" ("=/=" "≠"))
192 (".=" "doteq" ".\n=")
193 ("o<" "propto" "o<")
194 ("|=" "models" "|=")
195 ("_|_" "perp" "_|_")
196 ("|" "mid" "|")
197 ("||" "parallel" "||")
198 ("bowtie" "bowtie" "|><|(wide)")
199 ("|><|" "join" "|><|")
200 ("\\_/" "smile" "\\_/")
201 ("/~\\" "frown" "/~~\\")
202 ("-<" "prec" ("-<" "く"))
203 ("-<=" "preceq" ("-<\n-" "く\n="))
204 ("<<" "ll" ("<<" "《"))
205 ; :
206 ;;arrows
207 ("<-" "leftarrow" ("<-" "←"))
208 ("\C-b" "leftarrow" ("<-" "←"))
209 ("<--" "longleftarrow" ("<--" "←--"))
210 ("<=" "Leftarrow" "<=")
211 ("<==" "Longleftarrow" "<==")
212 ("->" "rightarrow" ("->" "→"))
213 ("\C-f" "rightarrow" ("->" "→"))
214 ("-->" "longrightarrow" ("-->" "--→"))
215 ("=>" "Rightarrow" "=>")
216 ("==>" "Longrightarrow" "==>")
217 ("<->" "leftrightarrow" ("<->" "←→"))
218 ("<-->" "longleftrightarrow" ("<---->" "←--→"))
219 ("<=>" "Leftrightarrow" "<=>")
220 ("<==>" "Longleftrightarrow" "<==>")
221 ("^|" "uparrow" ("^\n|" "↑"))
222 ("\C-p" "uparrow" ("^\n|" "↑"))
223 ("^||" "Uparrow" "/\\\n||")
224 ("\C-n" "downarrow" ("|\nv" "↓"))
225 ("v|" "downarrow" ("|\nv" "↓"))
226 ("v||" "Downarrow" "||\n\\/")
227 ("|->" "mapsto" ("|->" "|→"))
228 ("<-)" "hookleftarrow" (" ,\n<--+" " ヽ\n<--/"))
229 ("/-" "leftharpoonup" "/\n~~~")
230 ("\\-" "leftharpoondown" "__\n\\")
231 ("-/" "rightharpoondown" "__\n/")
232 ("-\\" "rightharpoonup" "~~\n\\")
233 ;;left and right
234 ("left" "left" "(leftmark)")
235 ("right" "right" "(rightmark)")
236 ;;accent marks
237 ("tilde" "tilde" "~\n?")
238 ("T" "tilde" "~\n?")
239 ("wtilde" "widetilde" "~\n?")
240 ("hat" "hat" "^\n?")
241 ("what" "widehat" "/\\\n??")
242 ("w^" "widehat" "/\\\n?")
243 ("check" "check" "v\n?")
244 ("bar" "bar" "_\n?")
245 ("overline" "overline" "_\n?")
246 ("wbar" "overline" "--\n??")
247 ("dot" "dot" ".\n?")
248 ("ddot" "ddot" "..\n??")
249 ("vec" "vec" ("->\n??" "→\n??"))
250 ("~>" "overrightarrow" ("-->\nAB" "→\nAB"))
251 ("VEC" "overrightarrow" ("-->\nAB" "→\nAB"))
252 ;;rage-aware stuffs
253 ("prod" "prod" ("-+--+-\n | |" "Π"))
254 ("CUP" "bigcup" "|~~|\n| |\n| |")
255 ("union" "bigcup" "|~~|\n| |\n| |")
256 ("CAP" "bigcap" "| |\n| |\n|__|")
257 ("isc" "bigcap" "| |\n| |\n|__|")
258 ("O+" "bigoplus" "/~~~\\\n| + |\n\\___/")
259 ("Ox" "bigotimes" "/~~~\\\n| X |\n\\___/")
260 ;;other marks
261 ("Z" "aleph" "|\\|")
262 ("|\\|" "aleph" "|\\|")
263 ("h-" "hbar" "_\nh")
264 ; ("i" "imath" "i") ;These chars are appeared only
265 ; ("j" "jmath" "j") ;as section-type arguments
266 ("l" "ell" "l")
267 ("wp" "wp" "???")
268 ("R" "Re" ")R")
269 ("Im" "Im" "???")
270 ("mho" "mho" "~|_|~")
271 ("'" "prime" "'")
272 ("0" "emptyset" "0")
273 ("nabla" "nabla" ("___\n\\\\/" YaTeX-image-nabla))
274 ("\\/" "surd" "-\\/")
275 ("surd" "surd" "-\\/")
276 ("top" "top" "T")
277 ("bot" "bot" ("_|_" YaTeX-image-bot))
278 ("b" "flat" ("b" YaTeX-image-flat))
279 ("LT" "natural" "|\nLT\n |")
280 ("6" "partial" (" -+\n+-+\n+-+" YaTeX-image-partial))
281 ("partial" "partial" (" -+\n+-+\n+-+" YaTeX-image-partial))
282 ("round" "partial" (" -+\n+-+\n+-+" YaTeX-image-partial))
283 ("[]" "Box" "[]")
284 ("Diamond" "Diamond" "/\\\n\\/")
285 ("3" "triangle" "/\\\n~~")
286 ("C" "clubsuit" " o\no+o\n |")
287 ("D" "diamondsuit" "/\\\n\\/")
288 ("H" "heartsuit" "<^^>\n \\/")
289 ("S" "spadesuit" " /\\\n<++>\n /\\")
290 )
291 "Default LaTeX-math-command alist.")
293 (defvar YaTeX-math-sign-alist-private nil
294 "*User definable key vs LaTeX-math-command alist.")
296 (defvar YaTeX-math-quit-with-strict-match nil
297 "*T for quitting completion as soon as strict-match is found.")
298 (defvar YaTeX-math-sign-alist
299 (append YaTeX-math-sign-alist-private YaTeX-math-sign-alist-default))
301 ;;(defun YaTeX-math-alist2array (alist array)
302 ;; (set array
303 ;; (let ((array (make-vector (length alist) "")) (list alist) (i 0))
304 ;; (while list
305 ;; (aset array i (car (car list)))
306 ;; (setq i (1+ i) list (cdr list)))
307 ;; array))
308 ;;)
310 (defvar YaTeX-greek-key-alist-default
311 '(
312 ("a" "alpha" ("a" "α"))
313 ("b" "beta" ("|>\n|>\n|" "β"))
314 ("g" "gamma" ("~r" "γ"))
315 ("G" "Gamma" ("|~" "Γ"))
316 ("d" "delta" ("<~\n<>" "δ"))
317 ("D" "Delta" ("/\\\n~~" "Δ"))
318 ("e" "epsilon" "<\n<~")
319 ("e-" "varepsilon" ("(\n(~" "ε"))
320 ("z" "zeta" ("(~\n >" "ζ"))
321 ("et" "eta" ("n\n/" "η"))
322 ("th" "theta" ("8" "θ"))
323 ("Th" "Theta" ("(8)" "Θ"))
324 ("th-" "vartheta" ("-8" "-θ"))
325 ("i" "iota" ("i\n\\_/" "ι"))
326 ("k" "kappa" ("k" "κ"))
327 ("l" "lambda" ("\\n/\\" "λ"))
328 ("L" "Lambda" ("/\\" "Λ"))
329 ("m" "mu" (" u_\n/" "μ"))
330 ("n" "nu" ("|/" "ν"))
331 ("x" "xi" ("E\n >" "ξ"))
332 ("X" "Xi" ("---\n -\n---" "Ξ"))
333 ("p" "pi" ("__\n)(" "π"))
334 ("P" "Pi" ("__\n||" "Π"))
335 ("p-" "varpi" ("_\nw" "__\nω"))
336 ("r" "rho" ("/O" "ρ"))
337 ("r-" "varrho" ("/O\n~~" "ρ\n~~"))
338 ("s" "sigma" ("o~" "σ"))
339 ("S" "Sigma" ("\\-+\n >\n/-+" "Σ"))
340 ("s-" "varsigma" "(~~ \n>")
341 ("t" "tau" ("__\n(" "τ"))
342 ("u" "upsilon" ("~v" "υ"))
343 ("y" "upsilon" ("~v" "υ"))
344 ("U" "Upsilon" ("~Y~" "Υ"))
345 ("Y" "Upsilon" ("~Y~" "Υ"))
346 ("ph" "phi" (" /\n(/)\n/" "φ"))
347 ("Ph" "Phi" (" _\n(|)\n ~" "Φ"))
348 ("ph-" "varphi" "\\O\n|")
349 ("c" "chi" ("x" "χ"))
350 ("ps" "psi" ("\\|/\\n |" "ψ"))
351 ("Ps" "Psi" (" ~\n\\|/\\n |" "Ψ"))
352 ("o" "omega" ("w" "ω"))
353 ("w" "omega" ("w" "ω"))
354 ("O" "Omega" ("(~)\n~ ~" "Ω"))
355 ("W" "Omega" ("(~)\n~ ~" "Ω"))
356 ("f" "foo")
357 )
358 "Default LaTeX-math-command alist.")
360 (defvar YaTeX-greek-key-alist-private nil
361 "*User definable key vs LaTeX-math-command alist.")
363 (defvar YaTeX-greek-key-alist
364 (append YaTeX-greek-key-alist-private YaTeX-greek-key-alist-default))
366 ;;(mapcar (function (lambda (x) (YaTeX-math-alist2array x)))
367 ;; YaTeX-math-key-list)
369 (defvar YaTeX-math-indicator "KEY\tLaTeX sequence\t\tsign")
371 (defvar YaTeX-math-need-image t
372 "*T for displaying pseudo image momentarily.")
373 (defvar YaTeX-math-max-key 8)
374 (defvar YaTeX-math-max-seq
375 (* 8 (1+ (/ (length "\\longleftrightarrow") 8))))
376 (defvar YaTeX-math-max-sign 5)
377 (defvar YaTeX-math-sign-width
378 (+ YaTeX-math-max-key YaTeX-math-max-seq YaTeX-math-max-sign))
379 (defvar YaTeX-math-display-width
380 (* 8 (1+ (/ YaTeX-math-sign-width 8))))
381 (defvar YaTeX-math-menu-map nil
382 "Keymap used in YaTeX mathematical sign menu mode."
383 )
384 (if YaTeX-math-menu-map nil
385 (setq YaTeX-math-menu-map (make-sparse-keymap))
386 (define-key YaTeX-math-menu-map "n" 'next-line)
387 (define-key YaTeX-math-menu-map "p" 'previous-line)
388 (define-key YaTeX-math-menu-map "f" 'YaTeX-math-forward)
389 (define-key YaTeX-math-menu-map "b" 'YaTeX-math-backward)
390 (define-key YaTeX-math-menu-map "v" 'scroll-up)
391 (define-key YaTeX-math-menu-map " " 'scroll-up)
392 (define-key YaTeX-math-menu-map "c" 'scroll-up)
393 (define-key YaTeX-math-menu-map "V" 'scroll-down)
394 (define-key YaTeX-math-menu-map "r" 'scroll-down)
395 (define-key YaTeX-math-menu-map "\^h" 'scroll-down)
396 (define-key YaTeX-math-menu-map "<" 'beginning-of-buffer)
397 (define-key YaTeX-math-menu-map ">" 'end-of-buffer)
398 (define-key YaTeX-math-menu-map "\^m" 'exit-recursive-edit)
399 (define-key YaTeX-math-menu-map "q" 'abort-recursive-edit))
401 (defvar YaTeX-math-exit-key "\e"
402 "*Key sequence after prefix key of YaTeX-math-mode to exit from math-mode."
403 )
405 (defmacro YaTeX-math-japanese-sign (list)
406 (list 'nth 1 list))
408 (defvar YaTeX-math-cmd-regexp (concat (regexp-quote YaTeX-ec) "[A-z]"))
409 (defvar YaTeX-math-verbatim-environments
410 '("alltt")
411 "*List of environments in which LaTeX math mode is disabled.
412 This value is appended with YaTeX-verbatim-environments.")
414 ;;;
415 ;;YaTeX math-mode functions
416 ;;;
417 ;;;###autoload from yatex.el
418 (defun YaTeX-toggle-math-mode (&optional arg)
419 (interactive "P")
420 (or (memq 'YaTeX-math-mode mode-line-format) nil
421 (setq mode-line-format
422 (append (list "" 'YaTeX-math-mode) mode-line-format)))
423 (if YaTeX-auto-math-mode nil ;Only effective on manual mode.
424 (if (or arg (null YaTeX-math-mode))
425 (let (keys)
426 (setq YaTeX-math-mode "math:")
427 (message "Turn on math mode. Prefix keys are %s"
428 (mapconcat 'car YaTeX-math-key-list " "))
429 (sit-for 3)
430 (message
431 (concat "To exit from math-mode, type `ESC' after prefix, "
432 "or type `"
433 (key-description
434 (car
435 (where-is-internal
436 'YaTeX-switch-mode-menu YaTeX-mode-map)))
437 " $'")))
438 (setq YaTeX-math-mode nil)
439 (message "Exit from math mode."))
440 (set-buffer-modified-p (buffer-modified-p)))
441 )
443 (defun YaTeX-math-forward (arg)
444 (interactive "p")
445 (re-search-forward YaTeX-math-cmd-regexp nil t arg))
447 (defun YaTeX-math-backward (arg)
448 (interactive "p")
449 (re-search-backward YaTeX-math-cmd-regexp nil t arg))
451 (defun YaTeX-math-gets (sign)
452 (cond
453 ((null sign) nil)
454 ((listp sign)
455 (setq sign
456 (cond
457 (YaTeX-japan (YaTeX-math-japanese-sign sign))
458 (t (car sign))))
459 (YaTeX-math-gets sign))
460 ((symbolp sign)
461 (YaTeX-math-gets (symbol-value sign)))
462 (t sign))
463 )
465 (defun YaTeX-math-get-sign (list)
466 (YaTeX-math-gets (car (cdr-safe (cdr-safe list))))
467 )
468 (defun YaTeX-in-math-mode-p ()
469 "If current position is supposed to be in LaTeX-math-mode, return t."
470 (or (YaTeX-quick-in-environment-p
471 (append
472 '("math" "eqnarray" "equation" "eqnarray*" "displaymath");LaTeX
473 (if YaTeX-use-AMS-LaTeX
474 ;; And math modes of AMS-LaTeX
475 '("align" "align*" "split" "multline" "multline*" "gather"
476 "gather*" "aligned*" "gathered" "gathered*" "alignat"
477 "alignat*" "xalignat" "xalignat*" "xxalignat" "xxalignat*"))))
478 (let*((p (point)) (nest 0) me0
479 (delim (concat YaTeX-sectioning-regexp "\\|^$\\|^\C-l"))
480 (boundary
481 (save-excursion
482 (if (looking-at delim)
483 (goto-char (max (point-min) (1- (point)))))
484 (re-search-backward delim nil 1)
485 (point))))
486 (save-excursion
487 (cond
488 ((catch 'open
489 (save-excursion
490 (while (and (>= nest 0)
491 (re-search-backward
492 (concat YaTeX-ec-regexp ;\
493 "\\([()]\\|[][]\\)") boundary t))
494 (setq me0 (match-end 0))
495 (if (or (YaTeX-on-comment-p)
496 (YaTeX-literal-p)) nil
497 (if (or (= (char-after (1- me0)) ?\))
498 (= (char-after (1- me0)) ?\]))
499 (setq nest (1+ nest))
500 (if (= (preceding-char) ?\\ ) nil;;\\[5pt]
501 (setq nest (1- nest))))))
502 (if (< nest 0) (throw 'open t))))
503 t)
504 (t (catch 'dollar
505 (while ;(search-backward "$" boundary t);little bit fast.
506 (YaTeX-re-search-active-backward ;;;;;; Too slow???
507 "\\$" (concat "[^\\\\]" YaTeX-comment-prefix) boundary t)
508 (cond
509 ((equal (char-after (1- (point))) ?$) ; $$ equation $$
510 (backward-char 1)
511 (setq nest (1+ nest)))
512 ((let ((YaTeX-verbatim-environments
513 (append YaTeX-math-verbatim-environments
514 YaTeX-verbatim-environments)))
515 (YaTeX-literal-p))
516 nil)
517 ((and (equal (char-after (1- (point))) ?\\ )
518 (not (equal (char-after (- (point) 3)) ?\\ )))
519 nil) ;\$
520 (t (setq nest (1+ nest)))))
521 (if (= (% nest 2) 1) (throw 'dollar t))))))))
522 )
524 (defun YaTeX-math-display-list (list cols)
525 (goto-char (point-max))
526 (if (= cols 0) (if (not (eolp)) (newline 1))
527 (forward-line -1)
528 (while (looking-at "[ \t\n]") (forward-line -1)))
529 (end-of-line)
530 (let ((indent (* YaTeX-math-display-width cols)) sign str to)
531 (indent-to indent)
532 (insert (car list))
533 (indent-to (setq indent (+ indent YaTeX-math-max-key)))
534 (insert "\\" (car (cdr list)))
535 (setq indent (+ indent YaTeX-math-max-seq))
536 (setq sign (YaTeX-math-get-sign list))
537 (while (and sign (not (string= "" sign)))
538 (setq to (string-match "\n" sign)
539 str (if to (substring sign 0 to) sign))
540 (end-of-line)
541 (indent-to indent)
542 (insert str)
543 (cond ((eobp) (newline 1))
544 ((> cols 0) (forward-line 1)))
545 (setq sign (if to (substring sign (1+ to)) "")))))
547 (defvar YaTeX-math-menu-buffer "*math-mode-signs*")
549 (defun YaTeX-math-show-menu (match-str)
550 (save-window-excursion
551 (YaTeX-showup-buffer YaTeX-math-menu-buffer nil t)
552 (let ((maxcols (max 1 (/ (screen-width) YaTeX-math-sign-width)))
553 (case-fold-search nil)
554 (cols 0) (list alist) command)
555 (erase-buffer)
556 (insert
557 "Candidates of sign. [n:next p:prev f:forw b:back q:quit RET:select]\n")
558 (insert YaTeX-math-indicator "\t")
559 (insert YaTeX-math-indicator)
560 (newline 1)
561 (insert-char ?- (1- (screen-width)))
562 (newline 1)
563 (while list
564 (if (string-match match-str (car (car list)))
565 (progn (YaTeX-math-display-list (car list) cols)
566 (setq cols (% (1+ cols) maxcols))))
567 (setq list (cdr list)))
568 (goto-line 4)
569 (use-local-map YaTeX-math-menu-map)
570 (setq buffer-read-only t)
571 (unwind-protect
572 (recursive-edit)
573 (skip-chars-backward "^ \t\n")
574 (setq command
575 (if (re-search-forward YaTeX-math-cmd-regexp nil t)
576 (buffer-substring
577 (match-beginning 0)
578 (prog2 (skip-chars-forward "^ \t\n") (point)))
579 nil))
580 (kill-buffer YaTeX-math-menu-buffer))
581 command))
582 )
584 ;
585 (defun YaTeX-math-show-image (image &optional exit-char)
586 "Momentarily display IMAGE at the beginning of the next line;
587 erase it on the next keystroke. The window is recentered if necessary
588 to make the whole string visible. If the window isn't large enough,
589 at least you get to read the beginning."
590 (if (and image (not (string= image "")))
591 (let ((buffer-read-only nil)
592 (modified (buffer-modified-p))
593 (name buffer-file-name)
594 insert-start
595 insert-end)
596 (unwind-protect
597 (progn
598 (save-excursion
599 ;; defeat file locking... don't try this at home, kids!
600 (setq buffer-file-name nil)
601 (forward-line 1)
602 (setq insert-start (point))
603 (if (eobp) (newline))
604 (insert image)
605 (setq insert-end (point)))
606 ; make sure the whole string is visible
607 (if (not (pos-visible-in-window-p insert-end))
608 (recenter (max 0
609 (- (window-height)
610 (count-lines insert-start insert-end)
611 2))))
612 (let ((char (read-char)))
613 (or (eq char exit-char)
614 (setq unread-command-char char))))
615 (if insert-end
616 (save-excursion
617 (delete-region insert-start insert-end)))
618 (setq buffer-file-name name)
619 (set-buffer-modified-p modified)))))
621 (defun YaTeX-math-insert-sequence (&optional force initial)
622 "Insert math-mode sequence with image completion."
623 (interactive "P")
624 (let*((key (or initial "")) regkey str last-char list i
625 (case-fold-search nil) match sign
626 (this-key (char-to-string last-command-char))
627 (alistsym (cdr (assoc this-key YaTeX-math-key-list)))
628 (alistname (symbol-name alistsym))
629 (alist (symbol-value alistsym))
630 (n (length alist)) (beg (point)) result)
631 (if initial (insert YaTeX-ec (car (cdr (assoc initial alist)))))
632 (if (string-match "^YaTeX-" alistname)
633 (setq alistname (substring alistname (length "YaTeX-"))))
634 (setq alistname (substring alistname 0 (string-match "-" alistname)))
635 (setq result
636 (catch 'complete
637 (if (and (not force)
638 (if YaTeX-auto-math-mode
639 (not (YaTeX-in-math-mode-p))
640 (not YaTeX-math-mode)))
641 (throw 'complete 'escape));this tag should be exit, but...
642 (while t
643 (message "%ssequence%s: %s"
644 (if YaTeX-simple-messages "" (concat alistname " "))
645 (if YaTeX-simple-messages "" "(TAB for menu)") key)
646 (setq last-char (read-char)
647 key (concat key (char-to-string last-char))
648 i 0)
649 (cond
650 ((string= key this-key) ;;invoke key itself
651 (throw 'complete 'escape))
652 ((string= key YaTeX-math-exit-key) ;;exit from math-mode
653 (throw 'complete 'exit))
654 ((string-match "\r" key) ;;RET = kakutei
655 (throw 'complete 'select))
656 ((string-match "[\C-g\C-c]" key) ;;C-g = abort
657 (throw 'complete 'abort))
658 ((string-match "[\t\n]" key) ;;TAB, LFD = menu
659 (throw 'complete 'menu))
660 ((string-match "[\C-h\C-?]" key) ;;BS, DEL = BS
661 (if (< (length key) 2) (throw 'complete 'abort))
662 (setq key (substring key 0 -2))))
664 (setq regkey (concat "^" (regexp-quote key)))
665 (message "Sequence%s: %s"
666 (if YaTeX-simple-messages "" "(TAB for menu)") key)
667 (if
668 (catch 'found
669 ;;(1)input string strictly matches with alist
670 (setq match (assoc key alist))
671 ;;remember previous match
673 ;;(2)search partial match into alist
674 (setq list alist)
675 (while (< i n)
676 (if (string-match
677 regkey
678 ;;(aref array i)
679 ;;(car (nth i alist))
680 (car (car list)))
681 (progn
682 (or match
683 ;;(setq match (nth i alist))
684 (setq match (car list)))
685 (throw 'found t)))
686 (setq i (1+ i) list (cdr list)))) ;catch 'found
687 nil ;;if any match, continue reading
688 ;;else reading of sequence has been done.
689 (message "complete.")
690 (throw 'complete t))
692 (if match
693 (progn (delete-region beg (point))
694 (setq single-command (car (cdr match)))
695 (insert YaTeX-ec single-command)
696 (if (and YaTeX-math-need-image
697 (setq sign (YaTeX-math-get-sign match)))
698 (YaTeX-math-show-image (concat sign "\n")))
699 )
700 nil)
701 )))
702 (delete-region beg (point))
703 (cond
704 ((memq result '(t select))
705 (if (eq result t)
706 (setq unread-command-char last-char)
707 (message "Done."))
708 (if (assoc single-command section-table)
709 (YaTeX-make-section nil nil nil single-command)
710 (setq YaTeX-current-completion-type 'maketitle)
711 (YaTeX-make-singlecmd single-command)))
712 ((eq result 'abort)
713 (message "Abort."))
714 ((eq result 'escape)
715 (call-interactively (global-key-binding this-key)))
716 ((eq result 'exit)
717 (YaTeX-toggle-math-mode))
718 ((eq result 'menu)
719 (setq key (concat "^" (regexp-quote (substring key 0 -1))))
720 (insert (YaTeX-math-show-menu key))))))
722 ;; ----- Change image completion types -----
723 (defun YaTeX-math-member-p (item)
724 "Check if ITEM is a member of image completion.
725 If so return the cons of its invocation key and image-string."
726 (let ((lists YaTeX-math-key-list) list)
727 (catch 'found
728 (while lists
729 (setq list (symbol-value (cdr (car lists))))
730 (while list
731 (if (string= item (nth 1 (car list)))
732 (throw 'found (cons (car (car lists)) (nth 0 (car list)))))
733 (setq list (cdr list)))
734 (setq lists (cdr lists))))))
736 ;;
737 (provide 'yatexmth)
739 ; Local variables:
740 ; fill-prefix: ";;; "
741 ; paragraph-start: "^$\\| \\|;;;$"
742 ; paragraph-separate: "^$\\| \\|;;;$"
743 ; End: