yatex

annotate yatexmth.el @ 59:48ac97a6b6ce

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