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