yatex
diff yatexmth.el @ 11:390df0e505da
Label completion works.
author | yuuji |
---|---|
date | Mon, 20 Sep 1993 08:56:09 +0000 |
parents | |
children | eafae54794a0 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/yatexmth.el Mon Sep 20 08:56:09 1993 +0000 1.3 @@ -0,0 +1,388 @@ 1.4 +;;; -*- Emacs-Lisp -*- 1.5 +;;; YaTeX interface for math-mode. 1.6 +;;; yatexmth.el rev.0 1.7 +;;; (C)1993 by HIROSE Yuuji [yuuji@ae.keio.ac.jp] 1.8 +;;; Last modified Tue Aug 3 23:37:07 1993 on 98fa 1.9 +;;; $Id$ 1.10 + 1.11 +(setq 1.12 + YaTeX-math-key-alist-default 1.13 + '( 1.14 + ;frequently used 1.15 + ("||" "|" ("||" "a")) 1.16 + ("sum" "sum" ("\\-+\n >\n/-+" "")) 1.17 + ("sigma" "sum" ("\\-+\n >\n/-+" "")) 1.18 + ("integral" "int" " /\\\n \\\n\\/") 1.19 + ("ointegral" "oint" " /\\\n(\\)\n\\/") 1.20 + ("A" "forall" "|_|\nV") 1.21 + ("E" "exists" "-+\n-+\n-+") 1.22 + ("!" "neg" "--+\n |") 1.23 + ("oo" "infty" ("oo" "")) 1.24 + ("\\" "backslash" ("\\" "_")) 1.25 + 1.26 + ;;binary operators 1.27 + ("+-" "pm" ("+\n-" "}")) 1.28 + ("-+" "mp" "-\n+") 1.29 + ("x" "times" ("x" "~")) 1.30 + ("/" "div" (",\n-\n'" "")) 1.31 + ("*" "ast" "*") 1.32 + ("#" "star" ("_/\\_\n\\ /\n//\\\\" "")) 1.33 + ("o" "circ" "o") 1.34 + ("o*" "bullet" " _\n(*)\n ~") 1.35 + ("." "cdot" ".") 1.36 + ("cap" "cap" "/-\\\n| |") 1.37 + ("cup" "cup" "| |\n\\-/") 1.38 + ("u+" "uplus" "|+|\n\\-/") 1.39 + ("|~|" "sqcap" "|~|") 1.40 + ("|_|" "sqcup" "|_|") 1.41 + ("v" "vee" "v") 1.42 + ("^" "wedge" "^") 1.43 + ("\\\\" "setminus" "\\") 1.44 + (")(" "wr" " )\n(") 1.45 + ("<>" "diamond" "<>") 1.46 + ("/\-" "bigtriangleup" ("/\\\n~~" "")) 1.47 + ("-\\/" "bigtriangledown" ("__\n\\/" "")) 1.48 + ("<|" "triangleleft" "<|") 1.49 + ("|>" "triangleright" "|>") 1.50 + ("<||" "lhd" "/|\n\\|") 1.51 + ("||>" "rhd" "|\\\n|/") 1.52 + ("<|-" "unlhd" "<|\n~~") 1.53 + ("|>-" "unrhd" "|>\n~~") 1.54 + ("o+" "oplus" " _\n(+)\n ~") 1.55 + ("o-" "ominus" " _\n(-)\n ~") 1.56 + ("ox" "otimes" " _\n(x)\n ~") 1.57 + ("o/" "oslash" " _\n(/)\n ~") 1.58 + ("o." "odot" "(.)") 1.59 + ("O" "bigcirc" "O") 1.60 + ("t" "dagger" "+\n|") 1.61 + ("tt" "ddagger" "+\n+\n|") 1.62 + ("II" "amalg" "II") 1.63 + ; : 1.64 + ;;relational operators 1.65 + ("<" "leq" ("<\n-" "")) 1.66 + (">" "geq" (">\n-" "")) 1.67 + ("-=" "equiv" "=\n-") 1.68 + ("=-" "equiv" "=\n-") 1.69 + ("---" "equiv" "=\n-") 1.70 + ("(" "subset" " _\n(\n ~") 1.71 + ("(-" "subseteq" " _\n(_\n~") 1.72 + (")" "supset" "_\n )\n~") 1.73 + (")-" "supseteq" "_\n_)\n~") 1.74 + ("[" "sqsubset" "[") 1.75 + ("[-" "sqsubseteq" "[\n~") 1.76 + ("]" "sqsupset" "]") 1.77 + ("]-" "sqsupseteq" "]\n~") 1.78 + ("{" "in" "(-") 1.79 + ("}" "ni" "-)") 1.80 + ("|-" "vdash" "|-") 1.81 + ("-|" "dashv" "-|") 1.82 + ("~" "sim" "~(tild)") 1.83 + ("~-" "simeq" "~\n-") 1.84 + ("asymp" "asymp" "v\n^") 1.85 + ("~~" "approx" "~\n~") 1.86 + ("~=" "cong" "~\n=") 1.87 + ("=/" "neq" ("=/=" "")) 1.88 + (".=" "doteq" ".\n=") 1.89 + ("o<" "propto" "o<") 1.90 + ("|=" "models" "|=") 1.91 + ("_|_" "perp" "_|_") 1.92 + ("|" "mid" "|") 1.93 + ("||" "parallel" "||") 1.94 + ("bowtie" "bowtie" "|><|(wide)") 1.95 + ("|><|" "join" "|><|") 1.96 + ("\\_/" "smile" "\\_/") 1.97 + ("/~\\" "frown" "/~~\\") 1.98 + ("-<" "prec" ("-<" "")) 1.99 + ("-<=" "preceq" ("-<\n-" "\n=")) 1.100 + ("<<" "ll" ("<<" "s")) 1.101 + ; : 1.102 + ;;arrows 1.103 + ("<-" "leftarrow" ("<-" "")) 1.104 + ("<--" "longleftarrow" ("<-" "--")) 1.105 + ("<=" "Leftarrow" "<=") 1.106 + ("<==" "Longleftarrow" "<==") 1.107 + ("->" "rightarrow" ("->" "")) 1.108 + ("-->" "longrightarrow" ("-->" "--")) 1.109 + ("==>" "Longrightarrow" "==>") 1.110 + ("<->" "leftrightarrow" ("<->" "")) 1.111 + ("<-->" "longleftrightarrow" ("<---->" "--")) 1.112 + ("<=>" "leftrightarrow" "<=>") 1.113 + ("<==>" "Longleftrightarrow" "<==>") 1.114 + ("^|" "uparrow" ("^\n|" "")) 1.115 + ("^||" "Uparrow" "/\\\n||") 1.116 + ("\C-n" "downarrow" ("|\nv" "")) 1.117 + ("^|" "uparrow" ("^\n|" "")) 1.118 + ("|->" "mapsto" ("|->" "|")) 1.119 + ("<-)" "hookleftarrow" (" ,\n<--+" " R\n<--/")) 1.120 + ("/-" "leftharpoonup" "/\n~~~") 1.121 + ("\\-" "leftharpoondown" "__\n\\") 1.122 + ("-/" "rightharpoondown" "__\n/") 1.123 + ("-\\" "rightharpoonup" "~~\n\\") 1.124 + ;other marks 1.125 + ("Z" "aleph" "|\\|") 1.126 + ("|\\|" "aleph" "|\\|") 1.127 + ("h-" "hbar" "_\nh") 1.128 + ("i" "imath" "i") 1.129 + ("j" "jmath" "j") 1.130 + ("l" "ell" "l") 1.131 + ("wp" "wp" "???") 1.132 + ("R" "Re" ")R") 1.133 + ("Im" "Im" "???") 1.134 + ("mho" "mho" "~|_|~") 1.135 + ("'" "prime" "'") 1.136 + ("0" "emptyset" "0") 1.137 + ("nabla" "nabla" "___\n\\\\/") 1.138 + ("\\/" "surd" "-\\/") 1.139 + ("surd" "surd" "-\\/") 1.140 + ("top" "top" "T") 1.141 + ("bot" "bot" "_|_") 1.142 + ("b" "flat" "b") 1.143 + ("LT" "natural" "|\nLT\n |") 1.144 + ("6" "partial" " -+\n+-+\n+-+") 1.145 + ("partial" "partial" " -+\n+-+\n+-+") 1.146 + ("round" "partial" " -+\n+-+\n+-+") 1.147 + ("[]" "box" "[]") 1.148 + ("Diamond" "Diamond" "/\\\n\\/") 1.149 + ("3" "triangle" "/\\\n~~") 1.150 + ("C" "clubsuit" " o\no+o\n |") 1.151 + ("D" "diamondsuit" "/\\\n\\/") 1.152 + ("H" "heartsuit" "<^^>\n \\/") 1.153 + ("S" "spadesuit" " /\\\n<++>\n /\\") 1.154 + 1.155 + )) 1.156 + 1.157 +(defvar YaTeX-math-key-alist-private nil 1.158 + "*User definable key vs LaTeX-math-command alist.") 1.159 + 1.160 +(defvar YaTeX-math-quit-with-strict-match nil 1.161 + "*T for quitting completion as soon as strict-match is found.") 1.162 +(setq YaTeX-math-key-alist 1.163 + (append YaTeX-math-key-alist-private YaTeX-math-key-alist-default)) 1.164 + 1.165 +(setq YaTeX-math-key-array 1.166 + (let ((array (make-vector (length YaTeX-math-key-alist) "")) 1.167 + (list YaTeX-math-key-alist) (i 0)) 1.168 + (while list 1.169 + (aset array i (car (car list))) 1.170 + (setq i (1+ i) list (cdr list))) 1.171 + array)) 1.172 + 1.173 +(defvar YaTeX-ec "\\" "Escape character of mark-up language.") 1.174 +(setq YaTeX-math-indicator 1.175 + "KEY\tLaTeX sequence\t\tsign") 1.176 + 1.177 +(defvar YaTeX-math-need-image t 1.178 + "*T for displaying pseudo image momentarily.") 1.179 +(defvar YaTeX-math-max-key 8) 1.180 +(defvar YaTeX-math-max-seq 1.181 + (* 8 (1+ (/ (length "\\longleftrightarrow") 8)))) 1.182 +(defvar YaTeX-math-max-sign 5) 1.183 +(defvar YaTeX-math-sign-width 1.184 + (+ YaTeX-math-max-key YaTeX-math-max-seq YaTeX-math-max-sign)) 1.185 +(defvar YaTeX-math-display-width 1.186 + (* 8 (1+ (/ YaTeX-math-sign-width 8)))) 1.187 +(defvar YaTeX-math-menu-map nil 1.188 + "Keymap used in YaTeX mathematical sign menu mode." 1.189 +) 1.190 +(if YaTeX-math-menu-map nil 1.191 + (setq YaTeX-math-menu-map (make-sparse-keymap)) 1.192 + (define-key YaTeX-math-menu-map "n" 'next-line) 1.193 + (define-key YaTeX-math-menu-map "p" 'previous-line) 1.194 + (define-key YaTeX-math-menu-map "f" 'YaTeX-math-forward) 1.195 + (define-key YaTeX-math-menu-map "b" 'YaTeX-math-backward) 1.196 + (define-key YaTeX-math-menu-map "v" 'scroll-up) 1.197 + (define-key YaTeX-math-menu-map " " 'scroll-up) 1.198 + (define-key YaTeX-math-menu-map "c" 'scroll-up) 1.199 + (define-key YaTeX-math-menu-map "V" 'scroll-down) 1.200 + (define-key YaTeX-math-menu-map "r" 'scroll-down) 1.201 + (define-key YaTeX-math-menu-map "\^h" 'scroll-down) 1.202 + (define-key YaTeX-math-menu-map "<" 'beginning-of-buffer) 1.203 + (define-key YaTeX-math-menu-map ">" 'end-of-buffer) 1.204 + (define-key YaTeX-math-menu-map "\^m" 'exit-recursive-edit) 1.205 + (define-key YaTeX-math-menu-map "q" 'abort-recursive-edit)) 1.206 + 1.207 +(defmacro YaTeX-math-japanese-sign (list) 1.208 + (list 'nth 1 list)) 1.209 + 1.210 +(defvar YaTeX-math-cmd-regexp (concat (regexp-quote YaTeX-ec) "[A-z]")) 1.211 + 1.212 +(defun YaTeX-math-forward (arg) 1.213 + (interactive "p") 1.214 + (re-search-forward YaTeX-math-cmd-regexp nil t arg)) 1.215 + 1.216 +(defun YaTeX-math-backward (arg) 1.217 + (interactive "p") 1.218 + (re-search-backward YaTeX-math-cmd-regexp nil t arg)) 1.219 + 1.220 +(defun YaTeX-math-get-sign (list) 1.221 + (let ((sign (car (cdr (cdr list))))) 1.222 + (if (listp sign) 1.223 + (setq sign (cond 1.224 + (YaTeX-japan (YaTeX-math-japanese-sign sign)) 1.225 + (t (car sign))))) 1.226 + sign) 1.227 +) 1.228 + 1.229 +(defun YaTeX-math-display-list (list cols) 1.230 + (goto-char (point-max)) 1.231 + (if (= cols 0) (if (not (eolp)) (newline 1)) 1.232 + (forward-line -1) 1.233 + (while (looking-at "[ \t\n]") (forward-line -1))) 1.234 + (end-of-line) 1.235 + (let ((indent (* YaTeX-math-display-width cols)) sign str to) 1.236 + (indent-to indent) 1.237 + (insert (car list)) 1.238 + (indent-to (setq indent (+ indent YaTeX-math-max-key))) 1.239 + (insert "\\" (car (cdr list))) 1.240 + (setq indent (+ indent YaTeX-math-max-seq)) 1.241 + (setq sign (YaTeX-math-get-sign list)) 1.242 + (while (not (string= "" sign)) 1.243 + (setq to (string-match "\n" sign) 1.244 + str (if to (substring sign 0 to) sign)) 1.245 + (end-of-line) 1.246 + (indent-to indent) 1.247 + (insert str) 1.248 + (cond ((eobp) (newline 1)) 1.249 + ((> cols 0) (forward-line 1))) 1.250 + (setq sign (if to (substring sign (1+ to)) ""))))) 1.251 + 1.252 +(defvar YaTeX-math-menu-buffer "*math-mode-signs*") 1.253 + 1.254 +(defun YaTeX-math-show-menu (match-str) 1.255 + (save-window-excursion 1.256 + (pop-to-buffer YaTeX-math-menu-buffer) 1.257 + (let ((maxcols (max 1 (/ (screen-width) YaTeX-math-sign-width))) 1.258 + (case-fold-search nil) 1.259 + (cols 0) (list YaTeX-math-key-alist) command) 1.260 + (erase-buffer) 1.261 + (insert YaTeX-math-indicator "\t") 1.262 + (insert YaTeX-math-indicator) 1.263 + (newline 1) 1.264 + (insert-char ?- (1- (screen-width))) 1.265 + (newline 1) 1.266 + (while list 1.267 + (if (string-match match-str (car (car list))) 1.268 + (progn (YaTeX-math-display-list (car list) cols) 1.269 + (setq cols (% (1+ cols) maxcols)))) 1.270 + (setq list (cdr list))) 1.271 + (goto-char (point-min)) 1.272 + (use-local-map YaTeX-math-menu-map) 1.273 + (unwind-protect 1.274 + (recursive-edit) 1.275 + (skip-chars-backward "^ \t\n") 1.276 + (setq command 1.277 + (if (re-search-forward YaTeX-math-cmd-regexp nil t) 1.278 + (buffer-substring 1.279 + (match-beginning 0) 1.280 + (prog2 (skip-chars-forward "^ \t\n") (point))) 1.281 + nil)) 1.282 + (kill-buffer YaTeX-math-menu-buffer)) 1.283 + command)) 1.284 +) 1.285 + 1.286 +; 1.287 +(defun YaTeX-math-show-image (image &optional exit-char) 1.288 + "Momentarily display IMAGE at the beginning of the next line; 1.289 +erase it on the next keystroke. The window is recentered if necessary 1.290 +to make the whole string visible. If the window isn't large enough, 1.291 +at least you get to read the beginning." 1.292 + (let ((buffer-read-only nil) 1.293 + (modified (buffer-modified-p)) 1.294 + (name buffer-file-name) 1.295 + insert-start 1.296 + insert-end) 1.297 + (unwind-protect 1.298 + (progn 1.299 + (save-excursion 1.300 + ;; defeat file locking... don't try this at home, kids! 1.301 + (setq buffer-file-name nil) 1.302 + (forward-line 1) 1.303 + (setq insert-start (point)) 1.304 + (if (eobp) (newline)) 1.305 + (insert image) 1.306 + (setq insert-end (point))) 1.307 + ; make sure the whole string is visible 1.308 + (if (not (pos-visible-in-window-p insert-end)) 1.309 + (recenter (max 0 1.310 + (- (window-height) 1.311 + (count-lines insert-start insert-end) 1.312 + 2)))) 1.313 + (let ((char (read-char))) 1.314 + (or (eq char exit-char) 1.315 + (setq unread-command-char char)))) 1.316 + (if insert-end 1.317 + (save-excursion 1.318 + (delete-region insert-start insert-end))) 1.319 + (setq buffer-file-name name) 1.320 + (set-buffer-modified-p modified)))) 1.321 + 1.322 +(defun YaTeX-math-insert-sequence () 1.323 + (interactive) 1.324 + (let ((key "") regkey str last-char list i 1.325 + (case-fold-search nil) match 1.326 + (n (length YaTeX-math-key-array)) (beg (point)) result) 1.327 + (setq result 1.328 + (catch 'complete 1.329 + (while t 1.330 + (setq last-char (read-char) 1.331 + key (concat key (char-to-string last-char)) 1.332 + regkey (concat "^" (regexp-quote key)) i 0) 1.333 + (cond 1.334 + ((string= key YaTeX-math-invoke-key) ;;invoke key itself 1.335 + (throw 'complete 'escape)) 1.336 + ((string-match "[\C-g\C-c]" key) (throw 'complete 'abort)) 1.337 + ((string-match "[\n\r]" key) (throw 'complete 'menu))) 1.338 + (if 1.339 + (catch 'found 1.340 + ;;(1)input string strictly matches with alist 1.341 + (setq single-command (car (cdr match)) 1.342 + ;;remember previous match 1.343 + match (assoc key YaTeX-math-key-alist)) 1.344 + ;;(2)search partial match into alist 1.345 + (while (< i n) 1.346 + (if (string-match 1.347 + regkey (aref YaTeX-math-key-array i)) 1.348 + (progn 1.349 + (or match 1.350 + (setq match (nth i YaTeX-math-key-alist))) 1.351 + (throw 'found t))) 1.352 + (setq i (1+ i)))) ;catch 'found 1.353 + nil ;;if any match, continue reading 1.354 + ;;else reading of sequence has been done. 1.355 + (message "complete.") 1.356 + (throw 'complete t) 1.357 + ) 1.358 + (if match 1.359 + (progn (delete-region beg (point)) 1.360 + (insert YaTeX-ec (car (cdr match))) 1.361 + (if YaTeX-math-need-image 1.362 + (YaTeX-math-show-image 1.363 + (concat (YaTeX-math-get-sign match) "\n"))) 1.364 + ) 1.365 + nil) 1.366 + ))) 1.367 + (cond 1.368 + ((eq result t) 1.369 + (setq YaTeX-current-completion-type 'maketitle) 1.370 + (if t nil 1.371 + (delete-region beg (point)) 1.372 + (setq single-command (car (cdr match))) 1.373 + ;;(recursive-edit) 1.374 + (insert YaTeX-ec single-command) 1.375 + ) 1.376 + (sit-for 1) 1.377 + (setq unread-command-char last-char) 1.378 + (insert (YaTeX-addin single-command))) 1.379 + ((eq result 'abort) 1.380 + (delete-region beg (point)) 1.381 + (message "Abort.")) 1.382 + ((eq result 'escape) 1.383 + (delete-region beg (point)) 1.384 + (insert YaTeX-math-invoke-key)) 1.385 + ((eq result 'menu) 1.386 + (delete-region beg (point)) 1.387 + (setq key (concat "^" (regexp-quote (substring key 0 -1)))) 1.388 + (insert (YaTeX-math-show-menu key))))) 1.389 +) 1.390 +;; 1.391 +(provide 'yatexmth)