yuuji@11: ;;; -*- Emacs-Lisp -*- yuuji@23: ;;; YaTeX math-mode-specific functions. yuuji@53: ;;; yatexmth.el rev.4 yuuji@60: ;;; (c )1993-1997 by HIROSE Yuuji [yuuji@ae.keio.ac.jp] yuuji@60: ;;; Last modified Fri Jan 24 18:00:08 1997 on supra yuuji@11: ;;; $Id$ yuuji@11: yuuji@13: ;;; [Customization guide] yuuji@13: ;;; yuuji@13: ;;; By default, you can use two completion groups in YaTeX math yuuji@52: ;;; mode, `;' for mathematical signs and `:' for greek letters. But yuuji@13: ;;; you can add other completion groups by defining the alist of yuuji@13: ;;; `prefix key' vs `completion list' into the variable yuuji@13: ;;; YaTeX-math-key-list-private. If you wish to accomplish the yuuji@23: ;;; completion as follows(prefix key is `,'): yuuji@13: ;;; yuuji@13: ;;; KEY COMPLETION yuuji@13: ;;; s \sin yuuji@13: ;;; S \arcsin yuuji@13: ;;; c \cos yuuji@13: ;;; C \arccos yuuji@13: ;;; : yuuji@13: ;;; T \arctan yuuji@13: ;;; l \log yuuji@13: ;;; hs \sinh yuuji@13: ;;; yuuji@23: ;;; Typing `s' after `,' makes `\sin', `hs' after `,' makes `\sinh' yuuji@13: ;;; and so on. First, you have to define list of key-completion yuuji@13: ;;; pairs. Variable name(YaTeX-math-funcs-list) is arbitrary. yuuji@13: ;;; yuuji@13: ;;; (setq YaTeX-math-funcs-list yuuji@13: ;;; '(("s" "sin") yuuji@13: ;;; ("S" "arcsin") yuuji@13: ;;; : yuuji@13: ;;; ("hs" "sinh"))) yuuji@13: ;;; yuuji@13: ;;; Next, define the list of prefix-key vs completion list(defined yuuji@13: ;;; above) into the variable YaTeX-math-key-list-private. yuuji@13: ;;; yuuji@13: ;;; (setq YaTeX-math-key-list-private yuuji@23: ;;; '(("," . YaTeX-math-funcs-list) yuuji@13: ;;; ("'" . Other-List-if-any))) yuuji@13: ;;; yuuji@13: ;;; Put these expressions into your ~/.emacs, and you can use this yuuji@51: ;;; completion in the math-mode. yuuji@13: ;;; yuuji@13: ;;; And you can add your favorite completion sequences to the yuuji@23: ;;; default completion list invoked with `;', by defining those lists yuuji@13: ;;; into variable YaTeX-math-sign-alist-private. yuuji@13: yuuji@13: ;;; 【イメージ補完の追加方法】 yuuji@13: ;;; yuuji@52: ;;; 標準のイメージ補完では、「;」で始まる数式記号補完と、「:」で始 yuuji@13: ;;; まるギリシャ文字補完が使用可能ですが、これ以外の文字で始まる補完 yuuji@23: ;;; シリーズも定義することができます。例えば、「,」で始まる次のよう yuuji@13: ;;; な補完シリーズを定義する場合を考えてみます。 yuuji@13: ;;; yuuji@13: ;;; 補完キー 補完結果 yuuji@13: ;;; s \sin yuuji@13: ;;; S \arcsin yuuji@13: ;;; c \cos yuuji@13: ;;; C \arccos yuuji@13: ;;; : yuuji@13: ;;; T \arctan yuuji@13: ;;; l \log yuuji@13: ;;; hs \sinh yuuji@13: ;;; yuuji@23: ;;; 「,」のあとに s を押すと \sin が、hs を押すと \sinh が入力されま yuuji@13: ;;; す。このような補完リストの登録は以下のようにします(変数名は任意)。 yuuji@13: ;;; yuuji@13: ;;; (setq YaTeX-math-funcs-list yuuji@13: ;;; '(("s" "sin") yuuji@13: ;;; ("S" "arcsin") yuuji@13: ;;; : yuuji@13: ;;; ("hs" "sinh"))) yuuji@13: ;;; yuuji@23: ;;; さらに、「,」を押した時にイメージ補完が始まるよう次の変数に、起動キー yuuji@13: ;;; と上で定義した補完用変数の登録を行ないます。 yuuji@13: ;;; yuuji@13: ;;; (setq YaTeX-math-key-list-private yuuji@23: ;;; '(("," . YaTeX-math-funcs-list) yuuji@13: ;;; ("'" . ほかに定義したいシリーズがあれば…))) yuuji@13: ;;; yuuji@51: ;;; これらを ~/.emacs に書いておけば、math-mode で自分専用のイメージ yuuji@51: ;;; 補完が利用できます。 yuuji@13: yuuji@13: (defvar YaTeX-jisold yuuji@13: (and (boundp 'dos-machine-type) yuuji@13: (eq dos-machine-type 'pc98))) yuuji@13: yuuji@13: (defmacro YaTeX-setq-math-sym (sym old new) yuuji@13: (list 'setq sym (list 'if 'YaTeX-jisold old new))) yuuji@13: yuuji@13: (YaTeX-setq-math-sym YaTeX-image-in "E" "∈") yuuji@13: (YaTeX-setq-math-sym YaTeX-image-ni "ヨ" "∋") yuuji@13: (YaTeX-setq-math-sym YaTeX-image-subset " _\n(\n ~" "⊂") yuuji@13: (YaTeX-setq-math-sym YaTeX-image-subseteq " _\n(_\n ~" "⊆") yuuji@13: (YaTeX-setq-math-sym YaTeX-image-supset "_\n )\n~" "⊃") yuuji@13: (YaTeX-setq-math-sym YaTeX-image-supseteq "_\n_)\n~" "⊇") yuuji@13: (YaTeX-setq-math-sym YaTeX-image-nabla "___\n\\\\/" "∇") yuuji@13: (YaTeX-setq-math-sym YaTeX-image-partial " -+\n+-+\n+-+" "∂") yuuji@13: (YaTeX-setq-math-sym YaTeX-image-dagger "+\n|" "†") yuuji@13: (YaTeX-setq-math-sym YaTeX-image-ddagger "+\n+\n|" "‡") yuuji@13: (YaTeX-setq-math-sym YaTeX-image-equiv "=\n ̄" "≡") yuuji@13: (YaTeX-setq-math-sym YaTeX-image-int " /\\\n \\\n\\/" "∫") yuuji@13: (YaTeX-setq-math-sym YaTeX-image-bot "|\n ̄" "⊥") yuuji@13: (YaTeX-setq-math-sym YaTeX-image-neg "イ" "¬") yuuji@13: (YaTeX-setq-math-sym YaTeX-image-flat "b" "♭") yuuji@23: (YaTeX-setq-math-sym YaTeX-image-sqrt "" "√") yuuji@13: yuuji@52: (defvar yuuji@13: YaTeX-math-sign-alist-default yuuji@11: '( yuuji@11: ;frequently used yuuji@11: ("||" "|" ("||" "‖")) yuuji@11: ("sum" "sum" ("\\-+\n >\n/-+" "Σ")) yuuji@11: ("sigma" "sum" ("\\-+\n >\n/-+" "Σ")) yuuji@13: ("integral" "int" (" /\\\n \\\n\\/" YaTeX-image-int)) yuuji@11: ("ointegral" "oint" " /\\\n(\\)\n\\/") yuuji@23: ("sqrt" "sqrt" (" __\n,/" YaTeX-image-sqrt)) yuuji@23: ("root" "sqrt" (" __\n,/" YaTeX-image-sqrt)) yuuji@11: ("A" "forall" "|_|\nV") yuuji@11: ("E" "exists" "-+\n-+\n-+") yuuji@13: ("!" "neg" ("--+\n |" YaTeX-image-neg)) yuuji@11: ("oo" "infty" ("oo" "∞")) yuuji@11: ("\\" "backslash" ("\\" "\")) yuuji@11: yuuji@11: ;;binary operators yuuji@11: ("+-" "pm" ("+\n-" "±")) yuuji@11: ("-+" "mp" "-\n+") yuuji@11: ("x" "times" ("x" "×")) yuuji@11: ("/" "div" (",\n-\n'" "÷")) yuuji@23: ("f" "frac" "xxx\n---\nyyy" "÷") yuuji@11: ("*" "ast" "*") yuuji@11: ("#" "star" ("_/\\_\n\\ /\n//\\\\" "★")) yuuji@11: ("o" "circ" "o") yuuji@11: ("o*" "bullet" " _\n(*)\n ~") yuuji@11: ("." "cdot" ".") yuuji@11: ("cap" "cap" "/-\\\n| |") yuuji@11: ("cup" "cup" "| |\n\\-/") yuuji@11: ("u+" "uplus" "|+|\n\\-/") yuuji@11: ("|~|" "sqcap" "|~|") yuuji@11: ("|_|" "sqcup" "|_|") yuuji@11: ("v" "vee" "v") yuuji@11: ("^" "wedge" "^") yuuji@11: ("\\\\" "setminus" "\\") yuuji@11: (")(" "wr" " )\n(") yuuji@11: ("<>" "diamond" "<>") yuuji@11: ("/\-" "bigtriangleup" ("/\\\n~~" "△")) yuuji@11: ("-\\/" "bigtriangledown" ("__\n\\/" "▽")) yuuji@11: ("<|" "triangleleft" "<|") yuuji@11: ("|>" "triangleright" "|>") yuuji@11: ("<||" "lhd" "/|\n\\|") yuuji@11: ("||>" "rhd" "|\\\n|/") yuuji@11: ("<|-" "unlhd" "<|\n~~") yuuji@11: ("|>-" "unrhd" "|>\n~~") yuuji@11: ("o+" "oplus" " _\n(+)\n ~") yuuji@11: ("o-" "ominus" " _\n(-)\n ~") yuuji@11: ("ox" "otimes" " _\n(x)\n ~") yuuji@11: ("o/" "oslash" " _\n(/)\n ~") yuuji@11: ("o." "odot" "(.)") yuuji@11: ("O" "bigcirc" "O") yuuji@13: ("t" "dagger" ("+\n|" YaTeX-image-dagger)) yuuji@13: ("tt" "ddagger" ("+\n+\n|" YaTeX-image-ddagger)) yuuji@11: ("II" "amalg" "II") yuuji@11: ; : yuuji@11: ;;relational operators yuuji@11: ("<" "leq" ("<\n-" "≦")) yuuji@11: (">" "geq" (">\n-" "≧")) yuuji@13: ("-=" "equiv" ("=\n-" YaTeX-image-equiv)) yuuji@13: ("=-" "equiv" ("=\n-" YaTeX-image-equiv)) yuuji@13: ("---" "equiv" ("=\n-" YaTeX-image-equiv)) yuuji@13: ("(" "subset" (" _\n(\n ~" YaTeX-image-subset)) yuuji@13: ("(-" "subseteq" (" _\n(_\n ~" YaTeX-image-subseteq)) yuuji@13: (")" "supset" ("_\n )\n~" YaTeX-image-supset)) yuuji@13: (")-" "supseteq" ("_\n_)\n~" YaTeX-image-supseteq)) yuuji@11: ("[" "sqsubset" "[") yuuji@11: ("[-" "sqsubseteq" "[\n~") yuuji@11: ("]" "sqsupset" "]") yuuji@11: ("]-" "sqsupseteq" "]\n~") yuuji@13: ("{" "in" ("(-" YaTeX-image-in)) yuuji@13: ("}" "ni" ("-)" YaTeX-image-ni)) yuuji@11: ("|-" "vdash" "|-") yuuji@11: ("-|" "dashv" "-|") yuuji@11: ("~" "sim" "~(tild)") yuuji@11: ("~-" "simeq" "~\n-") yuuji@11: ("asymp" "asymp" "v\n^") yuuji@11: ("~~" "approx" "~\n~") yuuji@11: ("~=" "cong" "~\n=") yuuji@11: ("=/" "neq" ("=/=" "≠")) yuuji@11: (".=" "doteq" ".\n=") yuuji@11: ("o<" "propto" "o<") yuuji@11: ("|=" "models" "|=") yuuji@11: ("_|_" "perp" "_|_") yuuji@11: ("|" "mid" "|") yuuji@11: ("||" "parallel" "||") yuuji@11: ("bowtie" "bowtie" "|><|(wide)") yuuji@11: ("|><|" "join" "|><|") yuuji@11: ("\\_/" "smile" "\\_/") yuuji@11: ("/~\\" "frown" "/~~\\") yuuji@11: ("-<" "prec" ("-<" "く")) yuuji@11: ("-<=" "preceq" ("-<\n-" "く\n=")) yuuji@11: ("<<" "ll" ("<<" "《")) yuuji@11: ; : yuuji@11: ;;arrows yuuji@11: ("<-" "leftarrow" ("<-" "←")) yuuji@13: ("\C-b" "leftarrow" ("<-" "←")) yuuji@13: ("<--" "longleftarrow" ("<--" "←--")) yuuji@11: ("<=" "Leftarrow" "<=") yuuji@11: ("<==" "Longleftarrow" "<==") yuuji@11: ("->" "rightarrow" ("->" "→")) yuuji@13: ("\C-f" "rightarrow" ("->" "→")) yuuji@11: ("-->" "longrightarrow" ("-->" "--→")) yuuji@11: ("==>" "Longrightarrow" "==>") yuuji@11: ("<->" "leftrightarrow" ("<->" "←→")) yuuji@11: ("<-->" "longleftrightarrow" ("<---->" "←--→")) yuuji@47: ("<=>" "Leftrightarrow" "<=>") yuuji@11: ("<==>" "Longleftrightarrow" "<==>") yuuji@11: ("^|" "uparrow" ("^\n|" "↑")) yuuji@13: ("\C-p" "uparrow" ("^\n|" "↑")) yuuji@11: ("^||" "Uparrow" "/\\\n||") yuuji@11: ("\C-n" "downarrow" ("|\nv" "↓")) yuuji@13: ("v|" "downarrow" ("|\nv" "↓")) yuuji@13: ("v||" "Downarrow" "||\n\\/") yuuji@11: ("|->" "mapsto" ("|->" "|→")) yuuji@11: ("<-)" "hookleftarrow" (" ,\n<--+" " ヽ\n<--/")) yuuji@11: ("/-" "leftharpoonup" "/\n~~~") yuuji@11: ("\\-" "leftharpoondown" "__\n\\") yuuji@11: ("-/" "rightharpoondown" "__\n/") yuuji@11: ("-\\" "rightharpoonup" "~~\n\\") yuuji@53: ;;left and right yuuji@53: ("left" "left" "(leftmark)") yuuji@53: ("right" "right" "(rightmark)") yuuji@11: ;other marks yuuji@11: ("Z" "aleph" "|\\|") yuuji@11: ("|\\|" "aleph" "|\\|") yuuji@11: ("h-" "hbar" "_\nh") yuuji@11: ("i" "imath" "i") yuuji@11: ("j" "jmath" "j") yuuji@11: ("l" "ell" "l") yuuji@11: ("wp" "wp" "???") yuuji@11: ("R" "Re" ")R") yuuji@11: ("Im" "Im" "???") yuuji@11: ("mho" "mho" "~|_|~") yuuji@11: ("'" "prime" "'") yuuji@11: ("0" "emptyset" "0") yuuji@13: ("nabla" "nabla" ("___\n\\\\/" YaTeX-image-nabla)) yuuji@11: ("\\/" "surd" "-\\/") yuuji@11: ("surd" "surd" "-\\/") yuuji@11: ("top" "top" "T") yuuji@13: ("bot" "bot" ("_|_" YaTeX-image-bot)) yuuji@13: ("b" "flat" ("b" YaTeX-image-flat)) yuuji@11: ("LT" "natural" "|\nLT\n |") yuuji@13: ("6" "partial" (" -+\n+-+\n+-+" YaTeX-image-partial)) yuuji@13: ("partial" "partial" (" -+\n+-+\n+-+" YaTeX-image-partial)) yuuji@13: ("round" "partial" (" -+\n+-+\n+-+" YaTeX-image-partial)) yuuji@59: ("[]" "Box" "[]") yuuji@11: ("Diamond" "Diamond" "/\\\n\\/") yuuji@11: ("3" "triangle" "/\\\n~~") yuuji@11: ("C" "clubsuit" " o\no+o\n |") yuuji@11: ("D" "diamondsuit" "/\\\n\\/") yuuji@11: ("H" "heartsuit" "<^^>\n \\/") yuuji@11: ("S" "spadesuit" " /\\\n<++>\n /\\") yuuji@52: ) yuuji@52: "Default LaTeX-math-command alist.") yuuji@11: yuuji@13: (defvar YaTeX-math-sign-alist-private nil yuuji@11: "*User definable key vs LaTeX-math-command alist.") yuuji@11: yuuji@11: (defvar YaTeX-math-quit-with-strict-match nil yuuji@11: "*T for quitting completion as soon as strict-match is found.") yuuji@52: (defvar YaTeX-math-sign-alist yuuji@13: (append YaTeX-math-sign-alist-private YaTeX-math-sign-alist-default)) yuuji@11: yuuji@13: ;;(defun YaTeX-math-alist2array (alist array) yuuji@13: ;; (set array yuuji@13: ;; (let ((array (make-vector (length alist) "")) (list alist) (i 0)) yuuji@13: ;; (while list yuuji@13: ;; (aset array i (car (car list))) yuuji@13: ;; (setq i (1+ i) list (cdr list))) yuuji@13: ;; array)) yuuji@13: ;;) yuuji@11: yuuji@52: (defvar YaTeX-greek-key-alist-default yuuji@13: '( yuuji@13: ("a" "alpha" ("a" "α")) yuuji@13: ("b" "beta" ("|>\n|>\n|" "β")) yuuji@13: ("g" "gamma" ("~r" "γ")) yuuji@13: ("G" "Gamma" ("|~" "Γ")) yuuji@13: ("d" "delta" ("<~\n<>" "δ")) yuuji@13: ("D" "Delta" ("/\\\n~~" "Δ")) yuuji@13: ("e" "epsilon" "<\n<~") yuuji@13: ("e-" "varepsilon" ("(\n(~" "ε")) yuuji@13: ("z" "zeta" ("(~\n >" "ζ")) yuuji@13: ("et" "eta" ("n\n/" "η")) yuuji@13: ("th" "theta" ("8" "θ")) yuuji@13: ("Th" "Theta" ("(8)" "Θ")) yuuji@13: ("th-" "vartheta" ("-8" "-θ")) yuuji@13: ("i" "iota" ("i\n\\_/" "ι")) yuuji@13: ("k" "kappa" ("k" "κ")) yuuji@13: ("l" "lambda" ("\\n/\\" "λ")) yuuji@13: ("L" "Lambda" ("/\\" "Λ")) yuuji@13: ("m" "mu" (" u_\n/" "μ")) yuuji@13: ("n" "nu" ("|/" "ν")) yuuji@13: ("x" "xi" ("E\n >" "ξ")) yuuji@13: ("X" "Xi" ("---\n -\n---" "Ξ")) yuuji@13: ("p" "pi" ("__\n)(" "π")) yuuji@13: ("P" "Pi" ("__\n||" "Π")) yuuji@13: ("p-" "varpi" ("_\nw" "__\nω")) yuuji@13: ("r" "rho" ("/O" "ρ")) yuuji@13: ("r-" "varrho" ("/O\n~~" "ρ\n~~")) yuuji@13: ("s" "sigma" ("o~" "σ")) yuuji@13: ("S" "Sigma" ("\\-+\n >\n/-+" "Σ")) yuuji@13: ("s-" "varsigma" "(~~ \n>") yuuji@13: ("t" "tau" ("__\n(" "τ")) yuuji@13: ("u" "upsilon" ("~v" "υ")) yuuji@13: ("y" "upsilon" ("~v" "υ")) yuuji@13: ("U" "Upsilon" ("~Y~" "Υ")) yuuji@13: ("Y" "Upsilon" ("~Y~" "Υ")) yuuji@13: ("ph" "phi" (" /\n(/)\n/" "φ")) yuuji@13: ("Ph" "Phi" (" _\n(|)\n ~" "Φ")) yuuji@13: ("ph-" "varphi" "\\O\n|") yuuji@13: ("c" "chi" ("x" "χ")) yuuji@13: ("ps" "psi" ("\\|/\\n |" "ψ")) yuuji@13: ("Ps" "Psi" (" ~\n\\|/\\n |" "Ψ")) yuuji@13: ("o" "omega" ("w" "ω")) yuuji@13: ("w" "omega" ("w" "ω")) yuuji@13: ("O" "Omega" ("(~)\n~ ~" "Ω")) yuuji@13: ("W" "Omega" ("(~)\n~ ~" "Ω")) yuuji@13: ("f" "foo") yuuji@13: ) yuuji@52: "Default LaTeX-math-command alist.") yuuji@13: yuuji@13: (defvar YaTeX-greek-key-alist-private nil yuuji@13: "*User definable key vs LaTeX-math-command alist.") yuuji@13: yuuji@52: (defvar YaTeX-greek-key-alist yuuji@13: (append YaTeX-greek-key-alist-private YaTeX-greek-key-alist-default)) yuuji@13: yuuji@13: ;;(mapcar (function (lambda (x) (YaTeX-math-alist2array x))) yuuji@13: ;; YaTeX-math-key-list) yuuji@13: yuuji@52: (defvar YaTeX-math-indicator "KEY\tLaTeX sequence\t\tsign") yuuji@11: yuuji@11: (defvar YaTeX-math-need-image t yuuji@11: "*T for displaying pseudo image momentarily.") yuuji@11: (defvar YaTeX-math-max-key 8) yuuji@11: (defvar YaTeX-math-max-seq yuuji@11: (* 8 (1+ (/ (length "\\longleftrightarrow") 8)))) yuuji@11: (defvar YaTeX-math-max-sign 5) yuuji@11: (defvar YaTeX-math-sign-width yuuji@11: (+ YaTeX-math-max-key YaTeX-math-max-seq YaTeX-math-max-sign)) yuuji@11: (defvar YaTeX-math-display-width yuuji@11: (* 8 (1+ (/ YaTeX-math-sign-width 8)))) yuuji@11: (defvar YaTeX-math-menu-map nil yuuji@11: "Keymap used in YaTeX mathematical sign menu mode." yuuji@11: ) yuuji@11: (if YaTeX-math-menu-map nil yuuji@11: (setq YaTeX-math-menu-map (make-sparse-keymap)) yuuji@11: (define-key YaTeX-math-menu-map "n" 'next-line) yuuji@11: (define-key YaTeX-math-menu-map "p" 'previous-line) yuuji@11: (define-key YaTeX-math-menu-map "f" 'YaTeX-math-forward) yuuji@11: (define-key YaTeX-math-menu-map "b" 'YaTeX-math-backward) yuuji@11: (define-key YaTeX-math-menu-map "v" 'scroll-up) yuuji@11: (define-key YaTeX-math-menu-map " " 'scroll-up) yuuji@11: (define-key YaTeX-math-menu-map "c" 'scroll-up) yuuji@11: (define-key YaTeX-math-menu-map "V" 'scroll-down) yuuji@11: (define-key YaTeX-math-menu-map "r" 'scroll-down) yuuji@11: (define-key YaTeX-math-menu-map "\^h" 'scroll-down) yuuji@11: (define-key YaTeX-math-menu-map "<" 'beginning-of-buffer) yuuji@11: (define-key YaTeX-math-menu-map ">" 'end-of-buffer) yuuji@11: (define-key YaTeX-math-menu-map "\^m" 'exit-recursive-edit) yuuji@11: (define-key YaTeX-math-menu-map "q" 'abort-recursive-edit)) yuuji@11: yuuji@13: (defvar YaTeX-math-exit-key "\e" yuuji@13: "*Key sequence after prefix key of YaTeX-math-mode to exit from math-mode." yuuji@13: ) yuuji@13: yuuji@11: (defmacro YaTeX-math-japanese-sign (list) yuuji@11: (list 'nth 1 list)) yuuji@11: yuuji@11: (defvar YaTeX-math-cmd-regexp (concat (regexp-quote YaTeX-ec) "[A-z]")) yuuji@51: (defvar YaTeX-math-verbatim-environments yuuji@51: '("alltt") yuuji@51: "*List of environments in which LaTeX math mode is disabled. yuuji@51: This value is appended with YaTeX-verbatim-environments.") yuuji@11: yuuji@13: ;;; yuuji@13: ;;YaTeX math-mode functions yuuji@13: ;;; yuuji@23: ;;;###autoload from yatex.el yuuji@13: (defun YaTeX-toggle-math-mode (&optional arg) yuuji@13: (interactive "P") yuuji@13: (or (memq 'YaTeX-math-mode mode-line-format) nil yuuji@13: (setq mode-line-format yuuji@13: (append (list "" 'YaTeX-math-mode) mode-line-format))) yuuji@23: (if YaTeX-auto-math-mode nil ;Only effective on manual mode. yuuji@23: (if (or arg (null YaTeX-math-mode)) yuuji@23: (let (keys) yuuji@23: (setq YaTeX-math-mode "math:") yuuji@23: (message "Turn on math mode. Prefix keys are %s" yuuji@23: (mapconcat 'car YaTeX-math-key-list " ")) yuuji@23: (sit-for 3) yuuji@23: (message yuuji@23: (concat "To exit from math-mode, type `ESC' after prefix, " yuuji@23: "or type `" yuuji@23: (key-description yuuji@23: (car yuuji@23: (where-is-internal yuuji@23: 'YaTeX-switch-mode-menu YaTeX-mode-map))) yuuji@23: " $'"))) yuuji@23: (setq YaTeX-math-mode nil) yuuji@23: (message "Exit from math mode.")) yuuji@23: (set-buffer-modified-p (buffer-modified-p))) yuuji@13: ) yuuji@13: yuuji@11: (defun YaTeX-math-forward (arg) yuuji@11: (interactive "p") yuuji@11: (re-search-forward YaTeX-math-cmd-regexp nil t arg)) yuuji@11: yuuji@11: (defun YaTeX-math-backward (arg) yuuji@11: (interactive "p") yuuji@11: (re-search-backward YaTeX-math-cmd-regexp nil t arg)) yuuji@11: yuuji@13: (defun YaTeX-math-gets (sign) yuuji@13: (cond yuuji@13: ((null sign) nil) yuuji@13: ((listp sign) yuuji@13: (setq sign yuuji@13: (cond yuuji@13: (YaTeX-japan (YaTeX-math-japanese-sign sign)) yuuji@13: (t (car sign)))) yuuji@13: (YaTeX-math-gets sign)) yuuji@13: ((symbolp sign) yuuji@13: (YaTeX-math-gets (symbol-value sign))) yuuji@13: (t sign)) yuuji@13: ) yuuji@13: yuuji@11: (defun YaTeX-math-get-sign (list) yuuji@13: (YaTeX-math-gets (car (cdr-safe (cdr-safe list)))) yuuji@11: ) yuuji@23: (defun YaTeX-in-math-mode-p () yuuji@23: "If current position is supposed to be in LaTeX-math-mode, return t." yuuji@23: (or (YaTeX-quick-in-environment-p yuuji@58: (append yuuji@58: '("math" "eqnarray" "equation" "eqnarray*" "displaymath");LaTeX yuuji@58: (if YaTeX-use-AMS-LaTeX yuuji@58: ;; And math modes of AMS-LaTeX yuuji@58: '("align" "align*" "split" "multline" "multline*" "gather" yuuji@58: "gather*" "aligned*" "gathered" "gathered*" "alignat" yuuji@58: "alignat*" "xalignat" "xalignat*" "xxalignat" "xxalignat*")))) yuuji@51: (let*((p (point)) (nest 0) me0 yuuji@57: (delim (concat YaTeX-sectioning-regexp "\\|^$\\|^\C-l")) yuuji@23: (boundary yuuji@23: (save-excursion yuuji@51: (if (looking-at delim) yuuji@23: (goto-char (max (point-min) (1- (point))))) yuuji@51: (re-search-backward delim nil 1) yuuji@23: (point)))) yuuji@23: (save-excursion yuuji@23: (cond yuuji@23: ((catch 'open yuuji@23: (save-excursion yuuji@23: (while (and (>= nest 0) yuuji@23: (re-search-backward yuuji@23: (concat YaTeX-ec-regexp ;\ yuuji@23: "\\([()]\\|[][]\\)") boundary t)) yuuji@23: (setq me0 (match-end 0)) yuuji@23: (if (or (YaTeX-on-comment-p) yuuji@51: (YaTeX-literal-p)) nil yuuji@23: (if (or (= (char-after (1- me0)) ?\)) yuuji@23: (= (char-after (1- me0)) ?\])) yuuji@23: (setq nest (1+ nest)) yuuji@37: (if (= (preceding-char) ?\\ ) nil;;\\[5pt] yuuji@37: (setq nest (1- nest)))))) yuuji@23: (if (< nest 0) (throw 'open t)))) yuuji@23: t) yuuji@23: (t (catch 'dollar yuuji@51: (while ;(search-backward "$" boundary t);little bit fast. yuuji@51: (YaTeX-re-search-active-backward ;;;;;; Too slow??? yuuji@58: "\\$" (concat "[^\\\\]" YaTeX-comment-prefix) boundary t) yuuji@23: (cond yuuji@23: ((equal (char-after (1- (point))) ?$) ; $$ equation $$ yuuji@23: (backward-char 1) yuuji@23: (setq nest (1+ nest))) yuuji@51: ((let ((YaTeX-verbatim-environments yuuji@51: (append YaTeX-math-verbatim-environments yuuji@51: YaTeX-verbatim-environments))) yuuji@51: (YaTeX-literal-p)) yuuji@51: nil) yuuji@23: ((and (equal (char-after (1- (point))) ?\\ ) yuuji@23: (not (equal (char-after (- (point) 3)) ?\\ ))) yuuji@23: nil) ;\$ yuuji@23: (t (setq nest (1+ nest))))) yuuji@23: (if (= (% nest 2) 1) (throw 'dollar t)))))))) yuuji@23: ) yuuji@23: yuuji@11: (defun YaTeX-math-display-list (list cols) yuuji@11: (goto-char (point-max)) yuuji@11: (if (= cols 0) (if (not (eolp)) (newline 1)) yuuji@11: (forward-line -1) yuuji@11: (while (looking-at "[ \t\n]") (forward-line -1))) yuuji@11: (end-of-line) yuuji@11: (let ((indent (* YaTeX-math-display-width cols)) sign str to) yuuji@11: (indent-to indent) yuuji@11: (insert (car list)) yuuji@11: (indent-to (setq indent (+ indent YaTeX-math-max-key))) yuuji@11: (insert "\\" (car (cdr list))) yuuji@11: (setq indent (+ indent YaTeX-math-max-seq)) yuuji@11: (setq sign (YaTeX-math-get-sign list)) yuuji@13: (while (and sign (not (string= "" sign))) yuuji@11: (setq to (string-match "\n" sign) yuuji@11: str (if to (substring sign 0 to) sign)) yuuji@11: (end-of-line) yuuji@11: (indent-to indent) yuuji@11: (insert str) yuuji@11: (cond ((eobp) (newline 1)) yuuji@11: ((> cols 0) (forward-line 1))) yuuji@11: (setq sign (if to (substring sign (1+ to)) ""))))) yuuji@11: yuuji@11: (defvar YaTeX-math-menu-buffer "*math-mode-signs*") yuuji@11: yuuji@11: (defun YaTeX-math-show-menu (match-str) yuuji@11: (save-window-excursion yuuji@59: (YaTeX-showup-buffer YaTeX-math-menu-buffer nil t) yuuji@11: (let ((maxcols (max 1 (/ (screen-width) YaTeX-math-sign-width))) yuuji@11: (case-fold-search nil) yuuji@13: (cols 0) (list alist) command) yuuji@11: (erase-buffer) yuuji@13: (insert yuuji@13: "Candidates of sign. [n:next p:prev f:forw b:back q:quit RET:select]\n") yuuji@11: (insert YaTeX-math-indicator "\t") yuuji@11: (insert YaTeX-math-indicator) yuuji@11: (newline 1) yuuji@11: (insert-char ?- (1- (screen-width))) yuuji@11: (newline 1) yuuji@11: (while list yuuji@11: (if (string-match match-str (car (car list))) yuuji@11: (progn (YaTeX-math-display-list (car list) cols) yuuji@11: (setq cols (% (1+ cols) maxcols)))) yuuji@11: (setq list (cdr list))) yuuji@13: (goto-line 4) yuuji@11: (use-local-map YaTeX-math-menu-map) yuuji@60: (setq buffer-read-only t) yuuji@11: (unwind-protect yuuji@11: (recursive-edit) yuuji@11: (skip-chars-backward "^ \t\n") yuuji@11: (setq command yuuji@11: (if (re-search-forward YaTeX-math-cmd-regexp nil t) yuuji@11: (buffer-substring yuuji@11: (match-beginning 0) yuuji@11: (prog2 (skip-chars-forward "^ \t\n") (point))) yuuji@11: nil)) yuuji@11: (kill-buffer YaTeX-math-menu-buffer)) yuuji@11: command)) yuuji@11: ) yuuji@11: yuuji@11: ; yuuji@11: (defun YaTeX-math-show-image (image &optional exit-char) yuuji@11: "Momentarily display IMAGE at the beginning of the next line; yuuji@11: erase it on the next keystroke. The window is recentered if necessary yuuji@11: to make the whole string visible. If the window isn't large enough, yuuji@11: at least you get to read the beginning." yuuji@13: (if (and image (not (string= image ""))) yuuji@13: (let ((buffer-read-only nil) yuuji@13: (modified (buffer-modified-p)) yuuji@13: (name buffer-file-name) yuuji@13: insert-start yuuji@13: insert-end) yuuji@13: (unwind-protect yuuji@13: (progn yuuji@13: (save-excursion yuuji@13: ;; defeat file locking... don't try this at home, kids! yuuji@13: (setq buffer-file-name nil) yuuji@13: (forward-line 1) yuuji@13: (setq insert-start (point)) yuuji@13: (if (eobp) (newline)) yuuji@13: (insert image) yuuji@13: (setq insert-end (point))) yuuji@13: ; make sure the whole string is visible yuuji@13: (if (not (pos-visible-in-window-p insert-end)) yuuji@13: (recenter (max 0 yuuji@13: (- (window-height) yuuji@13: (count-lines insert-start insert-end) yuuji@13: 2)))) yuuji@13: (let ((char (read-char))) yuuji@13: (or (eq char exit-char) yuuji@13: (setq unread-command-char char)))) yuuji@13: (if insert-end yuuji@13: (save-excursion yuuji@13: (delete-region insert-start insert-end))) yuuji@13: (setq buffer-file-name name) yuuji@13: (set-buffer-modified-p modified))))) yuuji@11: yuuji@52: (defun YaTeX-math-insert-sequence (&optional force initial) yuuji@23: "Insert math-mode sequence with image completion." yuuji@23: (interactive "P") yuuji@52: (let*((key (or initial "")) regkey str last-char list i yuuji@13: (case-fold-search nil) match sign yuuji@13: (this-key (char-to-string last-command-char)) yuuji@60: (alistsym (cdr (assoc this-key YaTeX-math-key-list))) yuuji@60: (alistname (symbol-name alistsym)) yuuji@60: (alist (symbol-value alistsym)) yuuji@13: (n (length alist)) (beg (point)) result) yuuji@52: (if initial (insert YaTeX-ec (car (cdr (assoc initial alist))))) yuuji@60: (if (string-match "^YaTeX-" alistname) yuuji@60: (setq alistname (substring alistname (length "YaTeX-")))) yuuji@60: (setq alistname (substring alistname 0 (string-match "-" alistname))) yuuji@11: (setq result yuuji@11: (catch 'complete yuuji@23: (if (and (not force) yuuji@51: (if YaTeX-auto-math-mode yuuji@51: (not (YaTeX-in-math-mode-p)) yuuji@51: (not YaTeX-math-mode))) yuuji@23: (throw 'complete 'escape));this tag should be exit, but... yuuji@11: (while t yuuji@60: (message "%ssequence%s: %s" yuuji@60: (if YaTeX-simple-messages "" (concat alistname " ")) yuuji@56: (if YaTeX-simple-messages "" "(TAB for menu)") key) yuuji@11: (setq last-char (read-char) yuuji@11: key (concat key (char-to-string last-char)) yuuji@13: i 0) yuuji@11: (cond yuuji@13: ((string= key this-key) ;;invoke key itself yuuji@11: (throw 'complete 'escape)) yuuji@13: ((string= key YaTeX-math-exit-key) ;;exit from math-mode yuuji@13: (throw 'complete 'exit)) yuuji@23: ((string-match "\r" key) ;;RET = kakutei yuuji@23: (throw 'complete 'select)) yuuji@23: ((string-match "[\C-g\C-c]" key) ;;C-g = abort yuuji@23: (throw 'complete 'abort)) yuuji@23: ((string-match "[\t\n]" key) ;;TAB, LFD = menu yuuji@23: (throw 'complete 'menu)) yuuji@23: ((string-match "[\C-h\C-?]" key) ;;BS, DEL = BS yuuji@23: (if (< (length key) 2) (throw 'complete 'abort)) yuuji@13: (setq key (substring key 0 -2)))) yuuji@13: yuuji@13: (setq regkey (concat "^" (regexp-quote key))) yuuji@56: (message "Sequence%s: %s" yuuji@56: (if YaTeX-simple-messages "" "(TAB for menu)") key) yuuji@11: (if yuuji@11: (catch 'found yuuji@11: ;;(1)input string strictly matches with alist yuuji@23: (setq match (assoc key alist)) yuuji@23: ;;remember previous match yuuji@23: yuuji@11: ;;(2)search partial match into alist yuuji@13: (setq list alist) yuuji@11: (while (< i n) yuuji@11: (if (string-match yuuji@13: regkey yuuji@13: ;;(aref array i) yuuji@13: ;;(car (nth i alist)) yuuji@23: (car (car list))) yuuji@11: (progn yuuji@11: (or match yuuji@13: ;;(setq match (nth i alist)) yuuji@13: (setq match (car list))) yuuji@11: (throw 'found t))) yuuji@13: (setq i (1+ i) list (cdr list)))) ;catch 'found yuuji@11: nil ;;if any match, continue reading yuuji@11: ;;else reading of sequence has been done. yuuji@11: (message "complete.") yuuji@23: (throw 'complete t)) yuuji@23: yuuji@11: (if match yuuji@11: (progn (delete-region beg (point)) yuuji@23: (setq single-command (car (cdr match))) yuuji@23: (insert YaTeX-ec single-command) yuuji@13: (if (and YaTeX-math-need-image yuuji@13: (setq sign (YaTeX-math-get-sign match))) yuuji@13: (YaTeX-math-show-image (concat sign "\n"))) yuuji@11: ) yuuji@11: nil) yuuji@11: ))) yuuji@11: (cond yuuji@11: ((eq result t) yuuji@11: (setq YaTeX-current-completion-type 'maketitle) yuuji@23: yuuji@13: ;;;(sit-for 1) yuuji@11: (setq unread-command-char last-char) yuuji@11: (insert (YaTeX-addin single-command))) yuuji@11: ((eq result 'abort) yuuji@11: (delete-region beg (point)) yuuji@11: (message "Abort.")) yuuji@11: ((eq result 'escape) yuuji@11: (delete-region beg (point)) yuuji@52: (call-interactively (global-key-binding this-key))) yuuji@23: ((eq result 'select) yuuji@53: (message "Done.") yuuji@53: (setq YaTeX-current-completion-type 'maketitle) yuuji@53: (insert (YaTeX-addin single-command))) yuuji@13: ((eq result 'exit) yuuji@13: (delete-region beg (point)) yuuji@13: (YaTeX-toggle-math-mode)) yuuji@11: ((eq result 'menu) yuuji@11: (delete-region beg (point)) yuuji@11: (setq key (concat "^" (regexp-quote (substring key 0 -1)))) yuuji@11: (insert (YaTeX-math-show-menu key))))) yuuji@11: ) yuuji@52: yuuji@52: ;; ----- Change image completion types ----- yuuji@52: (defun YaTeX-math-member-p (item) yuuji@52: "Check if ITEM is a member of image completion. yuuji@52: If so return the cons of its invocation key and image-string." yuuji@52: (let ((lists YaTeX-math-key-list) list) yuuji@52: (catch 'found yuuji@52: (while lists yuuji@52: (setq list (symbol-value (cdr (car lists)))) yuuji@52: (while list yuuji@52: (if (string= item (nth 1 (car list))) yuuji@52: (throw 'found (cons (car (car lists)) (nth 0 (car list))))) yuuji@52: (setq list (cdr list))) yuuji@52: (setq lists (cdr lists)))))) yuuji@52: yuuji@11: ;; yuuji@11: (provide 'yatexmth) yuuji@13: yuuji@13: ; Local variables: yuuji@13: ; fill-prefix: ";;; " yuuji@13: ; paragraph-start: "^$\\| \\|;;;$" yuuji@13: ; paragraph-separate: "^$\\| \\|;;;$" yuuji@13: ; End: