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