Mercurial > hgrepos > hgweb.cgi > yatex
annotate yatexmth.el @ 294:8d3156073892 dev
for 1.77
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Mon, 01 Apr 2013 22:47:31 +0900 |
parents | e1c1616c4f07 |
children | 53709ee88448 |
rev | line source |
---|---|
287 | 1 ;;; yatexmth.el --- YaTeX math-mode-specific functions |
2 ;;; | |
294 | 3 ;;; (c)1993-2013 by HIROSE Yuuji [yuuji@yatex.org] |
4 ;;; Last modified Mon Apr 1 22:44:22 2013 on firestorm | |
11 | 5 ;;; $Id$ |
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" ":") | |
11 | 313 ("Diamond" "Diamond" "/\\\n\\/") |
314 ("3" "triangle" "/\\\n~~") | |
315 ("C" "clubsuit" " o\no+o\n |") | |
316 ("D" "diamondsuit" "/\\\n\\/") | |
317 ("H" "heartsuit" "<^^>\n \\/") | |
318 ("S" "spadesuit" " /\\\n<++>\n /\\") | |
229 | 319 ("mi" "mathit" "\\mathit{}") |
320 ("mr" "mathrm" "\\mathrm{}") | |
321 ("mb" "mathbf" "\\mathbf{}") | |
322 ("mt" "mathtt" "\\mathtt{}") | |
323 ("ms" "mathsf" "\\mathsf{}") | |
324 ("mc" "mathcal" "\\mathcal{}") | |
325 ("mn" "mathnormal" "\\mathnormal{}") | |
52 | 326 ) |
327 "Default LaTeX-math-command alist.") | |
11 | 328 |
13 | 329 (defvar YaTeX-math-sign-alist-private nil |
11 | 330 "*User definable key vs LaTeX-math-command alist.") |
331 | |
332 (defvar YaTeX-math-quit-with-strict-match nil | |
333 "*T for quitting completion as soon as strict-match is found.") | |
52 | 334 (defvar YaTeX-math-sign-alist |
13 | 335 (append YaTeX-math-sign-alist-private YaTeX-math-sign-alist-default)) |
336 | |
337 ;;(defun YaTeX-math-alist2array (alist array) | |
338 ;; (set array | |
339 ;; (let ((array (make-vector (length alist) "")) (list alist) (i 0)) | |
340 ;; (while list | |
341 ;; (aset array i (car (car list))) | |
342 ;; (setq i (1+ i) list (cdr list))) | |
343 ;; array)) | |
344 ;;) | |
11 | 345 |
52 | 346 (defvar YaTeX-greek-key-alist-default |
13 | 347 '( |
348 ("a" "alpha" ("a" "α")) | |
349 ("b" "beta" ("|>\n|>\n|" "β")) | |
350 ("g" "gamma" ("~r" "γ")) | |
351 ("G" "Gamma" ("|~" "Γ")) | |
352 ("d" "delta" ("<~\n<>" "δ")) | |
353 ("D" "Delta" ("/\\\n~~" "Δ")) | |
354 ("e" "epsilon" "<\n<~") | |
355 ("e-" "varepsilon" ("(\n(~" "ε")) | |
356 ("z" "zeta" ("(~\n >" "ζ")) | |
357 ("et" "eta" ("n\n/" "η")) | |
358 ("th" "theta" ("8" "θ")) | |
359 ("Th" "Theta" ("(8)" "Θ")) | |
360 ("th-" "vartheta" ("-8" "-θ")) | |
361 ("i" "iota" ("i\n\\_/" "ι")) | |
362 ("k" "kappa" ("k" "κ")) | |
363 ("l" "lambda" ("\\n/\\" "λ")) | |
364 ("L" "Lambda" ("/\\" "Λ")) | |
365 ("m" "mu" (" u_\n/" "μ")) | |
366 ("n" "nu" ("|/" "ν")) | |
367 ("x" "xi" ("E\n >" "ξ")) | |
368 ("X" "Xi" ("---\n -\n---" "Ξ")) | |
369 ("p" "pi" ("__\n)(" "π")) | |
370 ("P" "Pi" ("__\n||" "Π")) | |
371 ("p-" "varpi" ("_\nw" "__\nω")) | |
372 ("r" "rho" ("/O" "ρ")) | |
373 ("r-" "varrho" ("/O\n~~" "ρ\n~~")) | |
374 ("s" "sigma" ("o~" "σ")) | |
375 ("S" "Sigma" ("\\-+\n >\n/-+" "Σ")) | |
376 ("s-" "varsigma" "(~~ \n>") | |
377 ("t" "tau" ("__\n(" "τ")) | |
378 ("u" "upsilon" ("~v" "υ")) | |
379 ("y" "upsilon" ("~v" "υ")) | |
380 ("U" "Upsilon" ("~Y~" "Υ")) | |
381 ("Y" "Upsilon" ("~Y~" "Υ")) | |
382 ("ph" "phi" (" /\n(/)\n/" "φ")) | |
383 ("Ph" "Phi" (" _\n(|)\n ~" "Φ")) | |
384 ("ph-" "varphi" "\\O\n|") | |
385 ("c" "chi" ("x" "χ")) | |
386 ("ps" "psi" ("\\|/\\n |" "ψ")) | |
387 ("Ps" "Psi" (" ~\n\\|/\\n |" "Ψ")) | |
388 ("o" "omega" ("w" "ω")) | |
389 ("w" "omega" ("w" "ω")) | |
390 ("O" "Omega" ("(~)\n~ ~" "Ω")) | |
391 ("W" "Omega" ("(~)\n~ ~" "Ω")) | |
392 ("f" "foo") | |
393 ) | |
52 | 394 "Default LaTeX-math-command alist.") |
11 | 395 |
13 | 396 (defvar YaTeX-greek-key-alist-private nil |
397 "*User definable key vs LaTeX-math-command alist.") | |
398 | |
52 | 399 (defvar YaTeX-greek-key-alist |
13 | 400 (append YaTeX-greek-key-alist-private YaTeX-greek-key-alist-default)) |
401 | |
402 ;;(mapcar (function (lambda (x) (YaTeX-math-alist2array x))) | |
403 ;; YaTeX-math-key-list) | |
404 | |
52 | 405 (defvar YaTeX-math-indicator "KEY\tLaTeX sequence\t\tsign") |
11 | 406 |
407 (defvar YaTeX-math-need-image t | |
408 "*T for displaying pseudo image momentarily.") | |
409 (defvar YaTeX-math-max-key 8) | |
410 (defvar YaTeX-math-max-seq | |
411 (* 8 (1+ (/ (length "\\longleftrightarrow") 8)))) | |
412 (defvar YaTeX-math-max-sign 5) | |
413 (defvar YaTeX-math-sign-width | |
414 (+ YaTeX-math-max-key YaTeX-math-max-seq YaTeX-math-max-sign)) | |
415 (defvar YaTeX-math-display-width | |
416 (* 8 (1+ (/ YaTeX-math-sign-width 8)))) | |
417 (defvar YaTeX-math-menu-map nil | |
80 | 418 "Keymap used in YaTeX mathematical sign menu mode.") |
419 | |
11 | 420 (if YaTeX-math-menu-map nil |
421 (setq YaTeX-math-menu-map (make-sparse-keymap)) | |
422 (define-key YaTeX-math-menu-map "n" 'next-line) | |
423 (define-key YaTeX-math-menu-map "p" 'previous-line) | |
424 (define-key YaTeX-math-menu-map "f" 'YaTeX-math-forward) | |
425 (define-key YaTeX-math-menu-map "b" 'YaTeX-math-backward) | |
426 (define-key YaTeX-math-menu-map "v" 'scroll-up) | |
427 (define-key YaTeX-math-menu-map " " 'scroll-up) | |
428 (define-key YaTeX-math-menu-map "c" 'scroll-up) | |
429 (define-key YaTeX-math-menu-map "V" 'scroll-down) | |
430 (define-key YaTeX-math-menu-map "r" 'scroll-down) | |
431 (define-key YaTeX-math-menu-map "\^h" 'scroll-down) | |
432 (define-key YaTeX-math-menu-map "<" 'beginning-of-buffer) | |
433 (define-key YaTeX-math-menu-map ">" 'end-of-buffer) | |
434 (define-key YaTeX-math-menu-map "\^m" 'exit-recursive-edit) | |
435 (define-key YaTeX-math-menu-map "q" 'abort-recursive-edit)) | |
436 | |
13 | 437 (defvar YaTeX-math-exit-key "\e" |
80 | 438 "*Key sequence after prefix key of YaTeX-math-mode to exit from math-mode.") |
13 | 439 |
11 | 440 (defmacro YaTeX-math-japanese-sign (list) |
441 (list 'nth 1 list)) | |
442 | |
72 | 443 (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
|
444 |
9c5a764a871f
Treat `alltt' in YaTeX-verbatim-environments.
yuuji@gentei.org
parents:
143
diff
changeset
|
445 ;;; alltt goes into YaTeX-verbatim-environments 2011/3/16 |
9c5a764a871f
Treat `alltt' in YaTeX-verbatim-environments.
yuuji@gentei.org
parents:
143
diff
changeset
|
446 ;;(defvar YaTeX-math-verbatim-environments |
9c5a764a871f
Treat `alltt' in YaTeX-verbatim-environments.
yuuji@gentei.org
parents:
143
diff
changeset
|
447 ;; '("alltt") |
9c5a764a871f
Treat `alltt' in YaTeX-verbatim-environments.
yuuji@gentei.org
parents:
143
diff
changeset
|
448 ;; "*List of environments in which LaTeX math mode is disabled. |
9c5a764a871f
Treat `alltt' in YaTeX-verbatim-environments.
yuuji@gentei.org
parents:
143
diff
changeset
|
449 ;;This value is appended with YaTeX-verbatim-environments.") |
11 | 450 |
13 | 451 ;;; |
452 ;;YaTeX math-mode functions | |
453 ;;; | |
23 | 454 ;;;###autoload from yatex.el |
13 | 455 (defun YaTeX-toggle-math-mode (&optional arg) |
456 (interactive "P") | |
457 (or (memq 'YaTeX-math-mode mode-line-format) nil | |
458 (setq mode-line-format | |
459 (append (list "" 'YaTeX-math-mode) mode-line-format))) | |
23 | 460 (if YaTeX-auto-math-mode nil ;Only effective on manual mode. |
461 (if (or arg (null YaTeX-math-mode)) | |
462 (let (keys) | |
463 (setq YaTeX-math-mode "math:") | |
464 (message "Turn on math mode. Prefix keys are %s" | |
465 (mapconcat 'car YaTeX-math-key-list " ")) | |
466 (sit-for 3) | |
467 (message | |
468 (concat "To exit from math-mode, type `ESC' after prefix, " | |
469 "or type `" | |
470 (key-description | |
471 (car | |
472 (where-is-internal | |
473 'YaTeX-switch-mode-menu YaTeX-mode-map))) | |
474 " $'"))) | |
475 (setq YaTeX-math-mode nil) | |
476 (message "Exit from math mode.")) | |
80 | 477 (set-buffer-modified-p (buffer-modified-p)))) |
13 | 478 |
11 | 479 (defun YaTeX-math-forward (arg) |
480 (interactive "p") | |
481 (re-search-forward YaTeX-math-cmd-regexp nil t arg)) | |
482 | |
483 (defun YaTeX-math-backward (arg) | |
484 (interactive "p") | |
485 (re-search-backward YaTeX-math-cmd-regexp nil t arg)) | |
486 | |
13 | 487 (defun YaTeX-math-gets (sign) |
488 (cond | |
489 ((null sign) nil) | |
490 ((listp sign) | |
491 (setq sign | |
492 (cond | |
493 (YaTeX-japan (YaTeX-math-japanese-sign sign)) | |
494 (t (car sign)))) | |
495 (YaTeX-math-gets sign)) | |
496 ((symbolp sign) | |
497 (YaTeX-math-gets (symbol-value sign))) | |
80 | 498 (t sign))) |
13 | 499 |
11 | 500 (defun YaTeX-math-get-sign (list) |
80 | 501 (YaTeX-math-gets (car (cdr-safe (cdr-safe list))))) |
502 | |
77 | 503 (defvar YaTeX-math-section-type-regexp |
504 "eqn\\\\\\sw+\\b" | |
505 "*Regexp of section-type math-mode macro") | |
506 | |
23 | 507 (defun YaTeX-in-math-mode-p () |
80 | 508 "If current position is supposed to be in LaTeX-math-mode, return t. |
509 This function refers a local variable `source-window' in YaTeX-make-section." | |
510 (save-excursion | |
511 (and (boundp 'source-window) source-window | |
512 (set-buffer (window-buffer source-window))) | |
513 (or (YaTeX-quick-in-environment-p | |
514 (append | |
515 '("math" "eqnarray" "equation" "eqnarray*" "displaymath") ;LaTeX | |
516 (if YaTeX-use-AMS-LaTeX | |
517 ;; And math modes of AMS-LaTeX | |
518 ;;'("align" "align*" "split" "multline" "multline*" "gather" | |
519 ;; "gather*" "aligned*" "gathered" "gathered*" "alignat" | |
520 ;; "equation*" "cases" "flalign" "flalign*" | |
521 ;; "alignat*" "xalignat" "xalignat*" "xxalignat" "xxalignat*" | |
522 YaTeX-math-begin-list | |
523 ))) | |
130
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
524 (let*((p (point)) (nest 0) me0 r firstp dollar |
80 | 525 (delim (concat YaTeX-sectioning-regexp "\\|^$\\|^\C-l")) |
526 (boundary | |
527 (save-excursion | |
528 (if (looking-at delim) | |
529 (goto-char (max (point-min) (1- (point))))) | |
530 (re-search-backward delim nil 1) | |
531 (point)))) | |
532 (save-excursion | |
533 (cond | |
534 ((catch 'open | |
535 (save-excursion | |
536 (while (and (>= nest 0) | |
537 (re-search-backward | |
538 (concat YaTeX-ec-regexp ;\ | |
539 "\\([()]\\|[][]\\)") boundary t)) | |
540 (setq me0 (match-end 0)) | |
541 (if (or (YaTeX-on-comment-p) | |
542 (YaTeX-literal-p)) nil | |
543 (if (or (= (char-after (1- me0)) ?\)) | |
544 (= (char-after (1- me0)) ?\])) | |
545 (setq nest (1+ nest)) | |
546 (if (= (preceding-char) ?\\ ) nil ;;\\[5pt] | |
547 (setq nest (1- nest)))))) | |
130
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
548 (if (< nest 0) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
549 (throw 'open (cons (YaTeX-match-string 0) (point))))))) |
80 | 550 ((and (setq r (YaTeX-on-section-command-p |
551 YaTeX-math-section-type-regexp)) | |
552 (numberp r) | |
553 (> r 0)) | |
554 t) | |
555 (t (catch 'dollar | |
556 (while ;(search-backward "$" boundary t);little bit fast. | |
557 (YaTeX-re-search-active-backward ;;;;;; Too slow??? | |
558 "\\$" (concat "[^\\\\]" YaTeX-comment-prefix) boundary t) | |
130
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
559 (setq dollar "$") |
80 | 560 (cond |
561 ((equal (char-after (1- (point))) ?$) ; $$ equation $$ | |
130
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
562 (setq dollar "$$") |
80 | 563 (backward-char 1) |
564 (setq nest (1+ nest))) | |
177
9c5a764a871f
Treat `alltt' in YaTeX-verbatim-environments.
yuuji@gentei.org
parents:
143
diff
changeset
|
565 ((YaTeX-literal-p) |
80 | 566 nil) |
567 ((and (equal (char-after (1- (point))) ?\\ ) | |
568 (not (equal (char-after (- (point) 3)) ?\\ ))) | |
569 nil) ;\$ | |
130
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
570 (t (setq nest (1+ nest)))) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
571 (if (and (= nest 1) (null firstp)) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
572 (setq firstp (cons dollar (point))))) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
573 (if (= (% nest 2) 1) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
574 (throw 'dollar firstp)))))))))) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
575 |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
576 (defun YaTeX-mark-mathenv () |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
577 "Mark current mathematic environment." |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
578 (interactive) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
579 (let ((mmp (YaTeX-in-math-mode-p)) type bpt) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
580 (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
|
581 nil ;if nil or not string, do nothing |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
582 (setq bpt (cdr mmp)) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
583 (goto-char bpt) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
584 (cond |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
585 ((string-match "\\$" type) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
586 (set-mark-command nil) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
587 (skip-chars-forward "$") |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
588 (YaTeX-search-active-forward |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
589 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
|
590 (goto-char (match-end 0))) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
591 ;; |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
592 ((string-match "^\\\\[\\[(]" type) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
593 (set-mark-command nil) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
594 (YaTeX-goto-corresponding-leftright) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
595 (skip-chars-forward "])\\\\")) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
596 ;; |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
597 ((string-match "^[a-z]" type) ; \begin\end type math |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
598 (set-mark-command nil) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
599 (YaTeX-goto-corresponding-environment) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
128
diff
changeset
|
600 (goto-char (match-end 0))))))) |
23 | 601 |
11 | 602 (defun YaTeX-math-display-list (list cols) |
603 (goto-char (point-max)) | |
604 (if (= cols 0) (if (not (eolp)) (newline 1)) | |
605 (forward-line -1) | |
606 (while (looking-at "[ \t\n]") (forward-line -1))) | |
607 (end-of-line) | |
608 (let ((indent (* YaTeX-math-display-width cols)) sign str to) | |
609 (indent-to indent) | |
610 (insert (car list)) | |
611 (indent-to (setq indent (+ indent YaTeX-math-max-key))) | |
612 (insert "\\" (car (cdr list))) | |
613 (setq indent (+ indent YaTeX-math-max-seq)) | |
614 (setq sign (YaTeX-math-get-sign list)) | |
13 | 615 (while (and sign (not (string= "" sign))) |
11 | 616 (setq to (string-match "\n" sign) |
617 str (if to (substring sign 0 to) sign)) | |
618 (end-of-line) | |
619 (indent-to indent) | |
620 (insert str) | |
621 (cond ((eobp) (newline 1)) | |
622 ((> cols 0) (forward-line 1))) | |
623 (setq sign (if to (substring sign (1+ to)) ""))))) | |
624 | |
625 (defvar YaTeX-math-menu-buffer "*math-mode-signs*") | |
626 | |
627 (defun YaTeX-math-show-menu (match-str) | |
628 (save-window-excursion | |
59 | 629 (YaTeX-showup-buffer YaTeX-math-menu-buffer nil t) |
70 | 630 (let ((maxcols (max 1 (/ (YaTeX-screen-width) YaTeX-math-sign-width))) |
11 | 631 (case-fold-search nil) |
13 | 632 (cols 0) (list alist) command) |
11 | 633 (erase-buffer) |
13 | 634 (insert |
635 "Candidates of sign. [n:next p:prev f:forw b:back q:quit RET:select]\n") | |
11 | 636 (insert YaTeX-math-indicator "\t") |
637 (insert YaTeX-math-indicator) | |
638 (newline 1) | |
70 | 639 (insert-char ?- (1- (YaTeX-screen-width))) |
11 | 640 (newline 1) |
641 (while list | |
642 (if (string-match match-str (car (car list))) | |
643 (progn (YaTeX-math-display-list (car list) cols) | |
644 (setq cols (% (1+ cols) maxcols)))) | |
645 (setq list (cdr list))) | |
178 | 646 (goto-char (point-min)) (forward-line 3) |
11 | 647 (use-local-map YaTeX-math-menu-map) |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
648 (setq buffer-read-only t) |
11 | 649 (unwind-protect |
650 (recursive-edit) | |
651 (skip-chars-backward "^ \t\n") | |
652 (setq command | |
653 (if (re-search-forward YaTeX-math-cmd-regexp nil t) | |
654 (buffer-substring | |
655 (match-beginning 0) | |
656 (prog2 (skip-chars-forward "^ \t\n") (point))) | |
657 nil)) | |
658 (kill-buffer YaTeX-math-menu-buffer)) | |
80 | 659 command))) |
11 | 660 |
661 ; | |
662 (defun YaTeX-math-show-image (image &optional exit-char) | |
663 "Momentarily display IMAGE at the beginning of the next line; | |
664 erase it on the next keystroke. The window is recentered if necessary | |
665 to make the whole string visible. If the window isn't large enough, | |
666 at least you get to read the beginning." | |
13 | 667 (if (and image (not (string= image ""))) |
668 (let ((buffer-read-only nil) | |
669 (modified (buffer-modified-p)) | |
670 (name buffer-file-name) | |
671 insert-start | |
672 insert-end) | |
673 (unwind-protect | |
674 (progn | |
675 (save-excursion | |
676 ;; defeat file locking... don't try this at home, kids! | |
677 (setq buffer-file-name nil) | |
678 (forward-line 1) | |
679 (setq insert-start (point)) | |
680 (if (eobp) (newline)) | |
681 (insert image) | |
682 (setq insert-end (point))) | |
683 ; make sure the whole string is visible | |
684 (if (not (pos-visible-in-window-p insert-end)) | |
685 (recenter (max 0 | |
686 (- (window-height) | |
687 (count-lines insert-start insert-end) | |
688 2)))) | |
689 (let ((char (read-char))) | |
690 (or (eq char exit-char) | |
292
e1c1616c4f07
Use unread-command-events when bound.
HIROSE Yuuji <yuuji@gentei.org>
parents:
290
diff
changeset
|
691 (if (boundp 'unread-command-events) |
e1c1616c4f07
Use unread-command-events when bound.
HIROSE Yuuji <yuuji@gentei.org>
parents:
290
diff
changeset
|
692 (setq unread-command-events (list char)) |
e1c1616c4f07
Use unread-command-events when bound.
HIROSE Yuuji <yuuji@gentei.org>
parents:
290
diff
changeset
|
693 (setq unread-command-char char))))) |
13 | 694 (if insert-end |
695 (save-excursion | |
696 (delete-region insert-start insert-end))) | |
697 (setq buffer-file-name name) | |
698 (set-buffer-modified-p modified))))) | |
11 | 699 |
52 | 700 (defun YaTeX-math-insert-sequence (&optional force initial) |
23 | 701 "Insert math-mode sequence with image completion." |
702 (interactive "P") | |
52 | 703 (let*((key (or initial "")) regkey str last-char list i |
13 | 704 (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
|
705 (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
|
706 (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
|
707 (alistname (symbol-name alistsym)) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
708 (alist (symbol-value alistsym)) |
13 | 709 (n (length alist)) (beg (point)) result) |
52 | 710 (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
|
711 (if (string-match "^YaTeX-" alistname) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
712 (setq alistname (substring alistname (length "YaTeX-")))) |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
713 (setq alistname (substring alistname 0 (string-match "-" alistname))) |
11 | 714 (setq result |
715 (catch 'complete | |
23 | 716 (if (and (not force) |
51 | 717 (if YaTeX-auto-math-mode |
718 (not (YaTeX-in-math-mode-p)) | |
719 (not YaTeX-math-mode))) | |
23 | 720 (throw 'complete 'escape));this tag should be exit, but... |
11 | 721 (while t |
60
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
722 (message "%ssequence%s: %s" |
9e08ed569d80
yahtml: change keystroke of calling browser to [prefix] t p
yuuji
parents:
59
diff
changeset
|
723 (if YaTeX-simple-messages "" (concat alistname " ")) |
56 | 724 (if YaTeX-simple-messages "" "(TAB for menu)") key) |
11 | 725 (setq last-char (read-char) |
726 key (concat key (char-to-string last-char)) | |
13 | 727 i 0) |
11 | 728 (cond |
13 | 729 ((string= key this-key) ;;invoke key itself |
11 | 730 (throw 'complete 'escape)) |
13 | 731 ((string= key YaTeX-math-exit-key) ;;exit from math-mode |
732 (throw 'complete 'exit)) | |
23 | 733 ((string-match "\r" key) ;;RET = kakutei |
734 (throw 'complete 'select)) | |
735 ((string-match "[\C-g\C-c]" key) ;;C-g = abort | |
736 (throw 'complete 'abort)) | |
737 ((string-match "[\t\n]" key) ;;TAB, LFD = menu | |
738 (throw 'complete 'menu)) | |
739 ((string-match "[\C-h\C-?]" key) ;;BS, DEL = BS | |
740 (if (< (length key) 2) (throw 'complete 'abort)) | |
13 | 741 (setq key (substring key 0 -2)))) |
742 | |
743 (setq regkey (concat "^" (regexp-quote key))) | |
56 | 744 (message "Sequence%s: %s" |
745 (if YaTeX-simple-messages "" "(TAB for menu)") key) | |
11 | 746 (if |
747 (catch 'found | |
748 ;;(1)input string strictly matches with alist | |
23 | 749 (setq match (assoc key alist)) |
750 ;;remember previous match | |
751 | |
11 | 752 ;;(2)search partial match into alist |
13 | 753 (setq list alist) |
11 | 754 (while (< i n) |
755 (if (string-match | |
13 | 756 regkey |
757 ;;(aref array i) | |
758 ;;(car (nth i alist)) | |
23 | 759 (car (car list))) |
11 | 760 (progn |
761 (or match | |
13 | 762 ;;(setq match (nth i alist)) |
763 (setq match (car list))) | |
11 | 764 (throw 'found t))) |
13 | 765 (setq i (1+ i) list (cdr list)))) ;catch 'found |
11 | 766 nil ;;if any match, continue reading |
767 ;;else reading of sequence has been done. | |
768 (message "complete.") | |
23 | 769 (throw 'complete t)) |
770 | |
11 | 771 (if match |
772 (progn (delete-region beg (point)) | |
80 | 773 (setq YaTeX-single-command (car (cdr match))) |
774 (insert YaTeX-ec YaTeX-single-command) | |
13 | 775 (if (and YaTeX-math-need-image |
776 (setq sign (YaTeX-math-get-sign match))) | |
777 (YaTeX-math-show-image (concat sign "\n"))) | |
11 | 778 ) |
779 nil) | |
780 ))) | |
68 | 781 (delete-region beg (point)) |
11 | 782 (cond |
68 | 783 ((memq result '(t select)) |
784 (if (eq result t) | |
292
e1c1616c4f07
Use unread-command-events when bound.
HIROSE Yuuji <yuuji@gentei.org>
parents:
290
diff
changeset
|
785 (if (boundp 'unread-command-events) |
e1c1616c4f07
Use unread-command-events when bound.
HIROSE Yuuji <yuuji@gentei.org>
parents:
290
diff
changeset
|
786 (setq unread-command-events (list last-char)) |
e1c1616c4f07
Use unread-command-events when bound.
HIROSE Yuuji <yuuji@gentei.org>
parents:
290
diff
changeset
|
787 (setq unread-command-char last-char)) |
68 | 788 (message "Done.")) |
80 | 789 (if (assoc YaTeX-single-command section-table) |
790 (YaTeX-make-section nil nil nil YaTeX-single-command) | |
68 | 791 (setq YaTeX-current-completion-type 'maketitle) |
80 | 792 (YaTeX-make-singlecmd YaTeX-single-command))) |
11 | 793 ((eq result 'abort) |
794 (message "Abort.")) | |
795 ((eq result 'escape) | |
80 | 796 (call-interactively (lookup-key global-map this-key))) |
13 | 797 ((eq result 'exit) |
798 (YaTeX-toggle-math-mode)) | |
11 | 799 ((eq result 'menu) |
800 (setq key (concat "^" (regexp-quote (substring key 0 -1)))) | |
68 | 801 (insert (YaTeX-math-show-menu key)))))) |
52 | 802 |
803 ;; ----- Change image completion types ----- | |
804 (defun YaTeX-math-member-p (item) | |
805 "Check if ITEM is a member of image completion. | |
806 If so return the cons of its invocation key and image-string." | |
807 (let ((lists YaTeX-math-key-list) list) | |
808 (catch 'found | |
809 (while lists | |
810 (setq list (symbol-value (cdr (car lists)))) | |
811 (while list | |
812 (if (string= item (nth 1 (car list))) | |
813 (throw 'found (cons (car (car lists)) (nth 0 (car list))))) | |
814 (setq list (cdr list))) | |
815 (setq lists (cdr lists)))))) | |
816 | |
193 | 817 ;;; ----- for AMS LaTeX (by matsu<at>math.s.chiba-u.ac.jp) ----- |
69 | 818 (defvar YaTeX-ams-paren-modifier |
819 '(("Biggl" . "Biggr") ("biggl" . "biggr") | |
820 ("Bigl" . "Bigr") ("bigl" . "bigr") | |
821 ("left" . "right") ("" . "")) | |
822 "Alist of modifier of parentheses.") | |
823 | |
824 (defvar YaTeX-left-paren "(\\|\\[\\|\\\\{") | |
825 (defvar YaTeX-right-paren ")\\|\\]\\|\\\\}") | |
826 (defvar YaTeX-paren | |
827 (concat YaTeX-left-paren "\\|" YaTeX-right-paren)) | |
828 | |
829 (defun YaTeX-on-parenthesis-p () | |
830 "If cursor is on an (AMS-LaTeX) parenthesis, return the parenthesis." | |
831 (interactive) | |
832 (let* ((list YaTeX-ams-paren-modifier) | |
833 (longest 0) ;; the longest length of parenthesis command strings | |
834 (flag t) ;; flag for whether on braces not following \ | |
835 (point (point)) | |
836 (move 0) | |
837 (paren)) | |
838 (while list | |
839 (setq longest | |
840 (max longest (length (car (car list))) (length (cdr (car list))))) | |
841 (setq list (cdr list))) | |
842 (save-excursion | |
843 ;; search {} and, if it does not follow `\', set flag nil. | |
844 ;; if it is right after `\', set flag t and move to the position of \. | |
845 ;; mmmmm. | |
846 (if (looking-at "{\\|}") | |
847 (if (not (equal (char-after (1- (point))) 92)) | |
848 (setq flag nil) | |
849 (forward-char -1))) | |
850 ;; if flag is nil, do nothing. | |
851 (if (and flag (re-search-forward YaTeX-paren | |
852 (+ (point) 3 longest) t)) | |
853 (progn | |
854 (setq move (- (point) point)) | |
80 | 855 (setq paren (YaTeX-match-string 0)) |
69 | 856 (setq list YaTeX-ams-paren-modifier) |
857 ;; criterion for whether on [] () \{\} or not. | |
858 (if (string-match YaTeX-left-paren paren) | |
859 (while (and list flag) | |
860 (let* ((mod (car (car list))) | |
861 (mod-length 0) ;; length of modifier | |
862 paren-regexp ;; regexp of paren. | |
863 mod-regexp) ;; regexp of modifier. | |
864 (if (> (length mod) 0) | |
865 (setq mod-regexp (concat "\\\\" mod) | |
866 mod-length (1+ (length mod)))) | |
867 (cond ((string= paren "\\{") | |
868 (setq paren-regexp (concat "\\" paren))) | |
869 ((string= paren "[") | |
870 (setq paren-regexp "\\[")) | |
871 (t (setq paren-regexp paren))) | |
872 (save-excursion | |
873 (if (and (>= (- (point) (point-min)) | |
874 (+ mod-length (length paren))) | |
875 (not (forward-char | |
876 (- 0 mod-length (length paren)))) | |
877 (looking-at (concat "\\(" mod-regexp "\\)\\(" | |
878 paren-regexp "\\)"))) | |
879 (setq flag nil))) | |
880 (setq list (cdr list)))) | |
881 (while (and list flag) | |
882 (let* ((mod (cdr (car list))) | |
883 (mod-length 0) | |
884 paren-regexp | |
885 mod-regexp) | |
886 (if (> (length mod) 0) | |
887 (setq mod-regexp (concat "\\\\" mod) | |
888 mod-length (1+ (length mod)))) | |
889 (cond ((string= paren "\\}") | |
890 (setq paren-regexp (concat "\\" paren))) | |
891 ((string= paren "]") | |
892 (setq paren-regexp "\\]")) | |
893 (t (setq paren-regexp paren))) | |
894 (save-excursion | |
895 (if (and (>= (- (point) (point-min)) | |
896 (+ mod-length (length paren))) | |
897 (not (forward-char | |
898 (- 0 mod-length (length paren)))) | |
899 (looking-at (concat "\\(" mod-regexp "\\)\\(" | |
900 paren-regexp "\\)"))) | |
901 (setq flag nil))) | |
902 (setq list (cdr list))))) | |
80 | 903 (if (<= move (length (YaTeX-match-string 0))) |
904 (YaTeX-match-string 0))))))) | |
69 | 905 |
77 | 906 (defun YaTeX-goto-open-paren (&optional jumpto-co) |
907 "Jump to the exact position of open parenthesis. | |
908 If optional argument JUMPTO-CO is non-nil, goto corresponding parentheses." | |
69 | 909 (interactive) |
910 (let ((paren) | |
911 (backslash-syntax (char-to-string (char-syntax ?\\)))) | |
912 (if (setq paren (YaTeX-on-parenthesis-p)) | |
913 (if (string-match "(\\|{\\|\\[" paren (1- (length paren))) | |
914 (progn | |
915 (re-search-forward "(\\|{\\|\\[" (+ (point) (length paren)) t) | |
77 | 916 (backward-char) |
917 (if jumpto-co | |
918 (unwind-protect | |
919 (progn | |
920 (modify-syntax-entry ?\\ " ") | |
921 (forward-list) | |
922 (backward-char)) | |
923 (modify-syntax-entry ?\\ backslash-syntax))) | |
924 (point)) | |
69 | 925 (re-search-forward ")\\|}\\|\\]" (+ (point) (length paren)) t) |
926 (unwind-protect | |
927 (progn | |
928 (modify-syntax-entry ?\\ " ") | |
77 | 929 (backward-list) |
930 (point)) | |
69 | 931 (modify-syntax-entry ?\\ backslash-syntax)))))) |
932 | |
77 | 933 ;;;###autoload |
934 (defun YaTeX-goto-corresponding-paren () | |
935 "Go to corresponding mathematical parentheses." | |
936 (if (YaTeX-on-parenthesis-p) | |
937 (YaTeX-goto-open-paren t) | |
938 nil)) | |
939 | |
69 | 940 (defun YaTeX-change-parentheses () |
941 "Change the size of parentheses, braces, and brackets of AMS-LaTeX." | |
942 (interactive) | |
943 (if (not (and YaTeX-use-AMS-LaTeX (YaTeX-on-parenthesis-p))) | |
944 nil | |
80 | 945 (let* ((mod (YaTeX-match-string 1)) ;; modifier |
946 (paren (if mod (YaTeX-match-string 2) (YaTeX-match-string 0))) ;; paren | |
69 | 947 (mod-length (if (or (string= mod "\\left") (string= mod "\\right")) |
948 5 ;; 5 in case left or right | |
949 (length mod))) ;; length of modifier | |
950 (paren-length (length paren)) ;; length of paren | |
951 (length (+ mod-length paren-length)) ;; length of whole string | |
952 (big-p t) ;; flag whether new modifier is "[Bb]ig+" or not. | |
953 size ;; left, big, Big etc. | |
77 | 954 type ;; parentheses type |
69 | 955 lr ;; "l" or "r". |
956 char newsize newsize-length | |
957 (backslash-syntax (char-to-string (char-syntax ?\\))) | |
958 (case-fold-search)) | |
959 ;; decide lr and size from mod and paren. | |
960 (cond ((string-match "\\(\\\\[Bb]ig+\\)[lr]" mod) | |
961 (setq size (substring mod 1 (match-end 1)) | |
962 lr (substring mod (match-end 1) (match-end 0)))) | |
963 ((string-match "\\\\left" mod) | |
964 (setq size "left-right" lr "l")) | |
965 ((string-match "\\\\right" mod) | |
966 (setq size "left-right" lr "r")) | |
967 ((string-match "(\\|\\[\\|\\\\{" paren) | |
968 (setq size "null" lr "l")) | |
969 ((string-match ")\\|\\]\\|\\\\}" paren) | |
970 (setq size "null" lr "r")) | |
971 (t | |
972 (setq size nil lr nil))) | |
973 (while (not newsize) | |
974 (message (format (concat "Change from %s: " | |
975 "l(big) L(Big) h(bigg) H(Bigg) " | |
77 | 976 "r(left-right) n(NONE) ( { [") size)) |
69 | 977 (setq char (read-char) |
978 newsize (cond ((char-equal char ?l) "\\big") | |
979 ((char-equal char ?L) "\\Big") | |
980 ((char-equal char ?h) "\\bigg") | |
981 ((char-equal char ?H) "\\Bigg") | |
982 ((char-equal char ?r) | |
983 (setq big-p nil) "\\left") | |
77 | 984 ((memq char '(?\( ?\))) |
985 (setq big-p nil type '("(" . ")")) "") | |
986 ((memq char '(?\{ ?\})) | |
987 (setq big-p nil type '("\\{" . "\\}")) "") | |
988 ((memq char '(?\[ ?\])) | |
989 (setq big-p nil type '("[" . "]")) "") | |
69 | 990 ((char-equal char ?n) |
991 (setq big-p nil) "") | |
992 (t nil)) | |
993 newsize-length (length newsize))) | |
994 (YaTeX-goto-open-paren) | |
995 (forward-char) | |
77 | 996 (cond |
997 (type | |
998 (delete-region (point) (- (point) paren-length)) | |
999 (save-excursion (insert (car type)))) | |
1000 (t | |
1001 (delete-region (- (point) length) (- (point) paren-length)) | |
1002 (backward-char paren-length))) | |
69 | 1003 (insert-string newsize) |
1004 (if big-p (insert ?l)) | |
1005 (unwind-protect | |
1006 (progn | |
1007 (modify-syntax-entry ?\\ " ") | |
1008 (forward-list) | |
1009 (if (string= size "left-right") (setq length (1+ length))) | |
1010 (if (eq char ?r) (setq newsize "\\right")) | |
77 | 1011 (cond |
1012 (type | |
1013 (delete-region (point) (- (point) paren-length)) | |
1014 (insert (cdr type))) | |
1015 (t | |
1016 (delete-region (- (point) length) (- (point) paren-length)) | |
1017 (backward-char paren-length) | |
1018 (insert-string newsize) | |
1019 (if big-p (insert ?r)) | |
1020 (forward-char paren-length))) | |
69 | 1021 (if (string= lr "l") (backward-list))) |
1022 (modify-syntax-entry ?\\ backslash-syntax)) | |
1023 t))) | |
1024 | |
1025 (defun YaTeX-insert-amsparens-region (beg end char) | |
1026 (interactive "r\ncWhich one ? l(big) L(Big) h(bigg) H(Bigg): ") | |
1027 (let* ((case-fold-search) | |
1028 (st (cond ((char-equal char ?l) "big") | |
1029 ((char-equal char ?L) "Big") | |
1030 ((char-equal char ?h) "bigg") | |
1031 ((char-equal char ?H) "Bigg")))) | |
1032 (if st | |
1033 (YaTeX-insert-braces-region | |
1034 beg end (concat "\\" st "l(") (concat "\\" st "r)")) | |
1035 (YaTeX-insert-braces-region beg end "(" ")")))) | |
1036 | |
1037 (defun YaTeX-insert-amsbraces-region (beg end char) | |
1038 (interactive "r\ncWhich one ? l(big) L(Big) h(bigg) H(Bigg): ") | |
1039 (let* ((case-fold-search) | |
1040 (st (cond ((char-equal char ?l) "big") | |
1041 ((char-equal char ?L) "Big") | |
1042 ((char-equal char ?h) "bigg") | |
1043 ((char-equal char ?H) "Bigg")))) | |
1044 (if st | |
1045 (YaTeX-insert-braces-region | |
1046 beg end (concat "\\" st "l\\{") (concat "\\" st "r\\}")) | |
1047 (YaTeX-insert-braces-region beg end "\\{" "\\}")))) | |
1048 | |
1049 (defun YaTeX-insert-amsbrackets-region (beg end char) | |
1050 (interactive "r\ncWhich one ? l(big) L(Big) h(bigg) H(Bigg): ") | |
1051 (let* ((case-fold-search) | |
1052 (st (cond ((char-equal char ?l) "big") | |
1053 ((char-equal char ?L) "Big") | |
1054 ((char-equal char ?h) "bigg") | |
1055 ((char-equal char ?H) "Bigg")))) | |
1056 (if st | |
1057 (YaTeX-insert-braces-region | |
1058 beg end (concat "\\" st "l[") (concat "\\" st "r]")) | |
1059 (YaTeX-insert-braces-region beg end "[" "]")))) | |
1060 | |
1061 | |
11 | 1062 ;; |
1063 (provide 'yatexmth) | |
13 | 1064 |
1065 ; Local variables: | |
1066 ; fill-prefix: ";;; " | |
1067 ; paragraph-start: "^$\\|\\|;;;$" | |
1068 ; paragraph-separate: "^$\\|\\|;;;$" | |
1069 ; End: |