yatex

annotate yatexmth.el @ 11:390df0e505da

Label completion works.
author yuuji
date Mon, 20 Sep 1993 08:56:09 +0000
parents
children eafae54794a0
rev   line source
yuuji@11 1 ;;; -*- Emacs-Lisp -*-
yuuji@11 2 ;;; YaTeX interface for math-mode.
yuuji@11 3 ;;; yatexmth.el rev.0
yuuji@11 4 ;;; (C)1993 by HIROSE Yuuji [yuuji@ae.keio.ac.jp]
yuuji@11 5 ;;; Last modified Tue Aug 3 23:37:07 1993 on 98fa
yuuji@11 6 ;;; $Id$
yuuji@11 7
yuuji@11 8 (setq
yuuji@11 9 YaTeX-math-key-alist-default
yuuji@11 10 '(
yuuji@11 11 ;frequently used
yuuji@11 12 ("||" "|" ("||" "a"))
yuuji@11 13 ("sum" "sum" ("\\-+\n >\n/-+" ""))
yuuji@11 14 ("sigma" "sum" ("\\-+\n >\n/-+" ""))
yuuji@11 15 ("integral" "int" " /\\\n \\\n\\/")
yuuji@11 16 ("ointegral" "oint" " /\\\n(\\)\n\\/")
yuuji@11 17 ("A" "forall" "|_|\nV")
yuuji@11 18 ("E" "exists" "-+\n-+\n-+")
yuuji@11 19 ("!" "neg" "--+\n |")
yuuji@11 20 ("oo" "infty" ("oo" ""))
yuuji@11 21 ("\\" "backslash" ("\\" "_"))
yuuji@11 22
yuuji@11 23 ;;binary operators
yuuji@11 24 ("+-" "pm" ("+\n-" "}"))
yuuji@11 25 ("-+" "mp" "-\n+")
yuuji@11 26 ("x" "times" ("x" "~"))
yuuji@11 27 ("/" "div" (",\n-\n'" ""))
yuuji@11 28 ("*" "ast" "*")
yuuji@11 29 ("#" "star" ("_/\\_\n\\ /\n//\\\\" ""))
yuuji@11 30 ("o" "circ" "o")
yuuji@11 31 ("o*" "bullet" " _\n(*)\n ~")
yuuji@11 32 ("." "cdot" ".")
yuuji@11 33 ("cap" "cap" "/-\\\n| |")
yuuji@11 34 ("cup" "cup" "| |\n\\-/")
yuuji@11 35 ("u+" "uplus" "|+|\n\\-/")
yuuji@11 36 ("|~|" "sqcap" "|~|")
yuuji@11 37 ("|_|" "sqcup" "|_|")
yuuji@11 38 ("v" "vee" "v")
yuuji@11 39 ("^" "wedge" "^")
yuuji@11 40 ("\\\\" "setminus" "\\")
yuuji@11 41 (")(" "wr" " )\n(")
yuuji@11 42 ("<>" "diamond" "<>")
yuuji@11 43 ("/\-" "bigtriangleup" ("/\\\n~~" ""))
yuuji@11 44 ("-\\/" "bigtriangledown" ("__\n\\/" ""))
yuuji@11 45 ("<|" "triangleleft" "<|")
yuuji@11 46 ("|>" "triangleright" "|>")
yuuji@11 47 ("<||" "lhd" "/|\n\\|")
yuuji@11 48 ("||>" "rhd" "|\\\n|/")
yuuji@11 49 ("<|-" "unlhd" "<|\n~~")
yuuji@11 50 ("|>-" "unrhd" "|>\n~~")
yuuji@11 51 ("o+" "oplus" " _\n(+)\n ~")
yuuji@11 52 ("o-" "ominus" " _\n(-)\n ~")
yuuji@11 53 ("ox" "otimes" " _\n(x)\n ~")
yuuji@11 54 ("o/" "oslash" " _\n(/)\n ~")
yuuji@11 55 ("o." "odot" "(.)")
yuuji@11 56 ("O" "bigcirc" "O")
yuuji@11 57 ("t" "dagger" "+\n|")
yuuji@11 58 ("tt" "ddagger" "+\n+\n|")
yuuji@11 59 ("II" "amalg" "II")
yuuji@11 60 ; :
yuuji@11 61 ;;relational operators
yuuji@11 62 ("<" "leq" ("<\n-" ""))
yuuji@11 63 (">" "geq" (">\n-" ""))
yuuji@11 64 ("-=" "equiv" "=\n-")
yuuji@11 65 ("=-" "equiv" "=\n-")
yuuji@11 66 ("---" "equiv" "=\n-")
yuuji@11 67 ("(" "subset" " _\n(\n ~")
yuuji@11 68 ("(-" "subseteq" " _\n(_\n~")
yuuji@11 69 (")" "supset" "_\n )\n~")
yuuji@11 70 (")-" "supseteq" "_\n_)\n~")
yuuji@11 71 ("[" "sqsubset" "[")
yuuji@11 72 ("[-" "sqsubseteq" "[\n~")
yuuji@11 73 ("]" "sqsupset" "]")
yuuji@11 74 ("]-" "sqsupseteq" "]\n~")
yuuji@11 75 ("{" "in" "(-")
yuuji@11 76 ("}" "ni" "-)")
yuuji@11 77 ("|-" "vdash" "|-")
yuuji@11 78 ("-|" "dashv" "-|")
yuuji@11 79 ("~" "sim" "~(tild)")
yuuji@11 80 ("~-" "simeq" "~\n-")
yuuji@11 81 ("asymp" "asymp" "v\n^")
yuuji@11 82 ("~~" "approx" "~\n~")
yuuji@11 83 ("~=" "cong" "~\n=")
yuuji@11 84 ("=/" "neq" ("=/=" ""))
yuuji@11 85 (".=" "doteq" ".\n=")
yuuji@11 86 ("o<" "propto" "o<")
yuuji@11 87 ("|=" "models" "|=")
yuuji@11 88 ("_|_" "perp" "_|_")
yuuji@11 89 ("|" "mid" "|")
yuuji@11 90 ("||" "parallel" "||")
yuuji@11 91 ("bowtie" "bowtie" "|><|(wide)")
yuuji@11 92 ("|><|" "join" "|><|")
yuuji@11 93 ("\\_/" "smile" "\\_/")
yuuji@11 94 ("/~\\" "frown" "/~~\\")
yuuji@11 95 ("-<" "prec" ("-<" ""))
yuuji@11 96 ("-<=" "preceq" ("-<\n-" "\n="))
yuuji@11 97 ("<<" "ll" ("<<" "s"))
yuuji@11 98 ; :
yuuji@11 99 ;;arrows
yuuji@11 100 ("<-" "leftarrow" ("<-" ""))
yuuji@11 101 ("<--" "longleftarrow" ("<-" "--"))
yuuji@11 102 ("<=" "Leftarrow" "<=")
yuuji@11 103 ("<==" "Longleftarrow" "<==")
yuuji@11 104 ("->" "rightarrow" ("->" ""))
yuuji@11 105 ("-->" "longrightarrow" ("-->" "--"))
yuuji@11 106 ("==>" "Longrightarrow" "==>")
yuuji@11 107 ("<->" "leftrightarrow" ("<->" ""))
yuuji@11 108 ("<-->" "longleftrightarrow" ("<---->" "--"))
yuuji@11 109 ("<=>" "leftrightarrow" "<=>")
yuuji@11 110 ("<==>" "Longleftrightarrow" "<==>")
yuuji@11 111 ("^|" "uparrow" ("^\n|" ""))
yuuji@11 112 ("^||" "Uparrow" "/\\\n||")
yuuji@11 113 ("\C-n" "downarrow" ("|\nv" ""))
yuuji@11 114 ("^|" "uparrow" ("^\n|" ""))
yuuji@11 115 ("|->" "mapsto" ("|->" "|"))
yuuji@11 116 ("<-)" "hookleftarrow" (" ,\n<--+" " R\n<--/"))
yuuji@11 117 ("/-" "leftharpoonup" "/\n~~~")
yuuji@11 118 ("\\-" "leftharpoondown" "__\n\\")
yuuji@11 119 ("-/" "rightharpoondown" "__\n/")
yuuji@11 120 ("-\\" "rightharpoonup" "~~\n\\")
yuuji@11 121 ;other marks
yuuji@11 122 ("Z" "aleph" "|\\|")
yuuji@11 123 ("|\\|" "aleph" "|\\|")
yuuji@11 124 ("h-" "hbar" "_\nh")
yuuji@11 125 ("i" "imath" "i")
yuuji@11 126 ("j" "jmath" "j")
yuuji@11 127 ("l" "ell" "l")
yuuji@11 128 ("wp" "wp" "???")
yuuji@11 129 ("R" "Re" ")R")
yuuji@11 130 ("Im" "Im" "???")
yuuji@11 131 ("mho" "mho" "~|_|~")
yuuji@11 132 ("'" "prime" "'")
yuuji@11 133 ("0" "emptyset" "0")
yuuji@11 134 ("nabla" "nabla" "___\n\\\\/")
yuuji@11 135 ("\\/" "surd" "-\\/")
yuuji@11 136 ("surd" "surd" "-\\/")
yuuji@11 137 ("top" "top" "T")
yuuji@11 138 ("bot" "bot" "_|_")
yuuji@11 139 ("b" "flat" "b")
yuuji@11 140 ("LT" "natural" "|\nLT\n |")
yuuji@11 141 ("6" "partial" " -+\n+-+\n+-+")
yuuji@11 142 ("partial" "partial" " -+\n+-+\n+-+")
yuuji@11 143 ("round" "partial" " -+\n+-+\n+-+")
yuuji@11 144 ("[]" "box" "[]")
yuuji@11 145 ("Diamond" "Diamond" "/\\\n\\/")
yuuji@11 146 ("3" "triangle" "/\\\n~~")
yuuji@11 147 ("C" "clubsuit" " o\no+o\n |")
yuuji@11 148 ("D" "diamondsuit" "/\\\n\\/")
yuuji@11 149 ("H" "heartsuit" "<^^>\n \\/")
yuuji@11 150 ("S" "spadesuit" " /\\\n<++>\n /\\")
yuuji@11 151
yuuji@11 152 ))
yuuji@11 153
yuuji@11 154 (defvar YaTeX-math-key-alist-private nil
yuuji@11 155 "*User definable key vs LaTeX-math-command alist.")
yuuji@11 156
yuuji@11 157 (defvar YaTeX-math-quit-with-strict-match nil
yuuji@11 158 "*T for quitting completion as soon as strict-match is found.")
yuuji@11 159 (setq YaTeX-math-key-alist
yuuji@11 160 (append YaTeX-math-key-alist-private YaTeX-math-key-alist-default))
yuuji@11 161
yuuji@11 162 (setq YaTeX-math-key-array
yuuji@11 163 (let ((array (make-vector (length YaTeX-math-key-alist) ""))
yuuji@11 164 (list YaTeX-math-key-alist) (i 0))
yuuji@11 165 (while list
yuuji@11 166 (aset array i (car (car list)))
yuuji@11 167 (setq i (1+ i) list (cdr list)))
yuuji@11 168 array))
yuuji@11 169
yuuji@11 170 (defvar YaTeX-ec "\\" "Escape character of mark-up language.")
yuuji@11 171 (setq YaTeX-math-indicator
yuuji@11 172 "KEY\tLaTeX sequence\t\tsign")
yuuji@11 173
yuuji@11 174 (defvar YaTeX-math-need-image t
yuuji@11 175 "*T for displaying pseudo image momentarily.")
yuuji@11 176 (defvar YaTeX-math-max-key 8)
yuuji@11 177 (defvar YaTeX-math-max-seq
yuuji@11 178 (* 8 (1+ (/ (length "\\longleftrightarrow") 8))))
yuuji@11 179 (defvar YaTeX-math-max-sign 5)
yuuji@11 180 (defvar YaTeX-math-sign-width
yuuji@11 181 (+ YaTeX-math-max-key YaTeX-math-max-seq YaTeX-math-max-sign))
yuuji@11 182 (defvar YaTeX-math-display-width
yuuji@11 183 (* 8 (1+ (/ YaTeX-math-sign-width 8))))
yuuji@11 184 (defvar YaTeX-math-menu-map nil
yuuji@11 185 "Keymap used in YaTeX mathematical sign menu mode."
yuuji@11 186 )
yuuji@11 187 (if YaTeX-math-menu-map nil
yuuji@11 188 (setq YaTeX-math-menu-map (make-sparse-keymap))
yuuji@11 189 (define-key YaTeX-math-menu-map "n" 'next-line)
yuuji@11 190 (define-key YaTeX-math-menu-map "p" 'previous-line)
yuuji@11 191 (define-key YaTeX-math-menu-map "f" 'YaTeX-math-forward)
yuuji@11 192 (define-key YaTeX-math-menu-map "b" 'YaTeX-math-backward)
yuuji@11 193 (define-key YaTeX-math-menu-map "v" 'scroll-up)
yuuji@11 194 (define-key YaTeX-math-menu-map " " 'scroll-up)
yuuji@11 195 (define-key YaTeX-math-menu-map "c" 'scroll-up)
yuuji@11 196 (define-key YaTeX-math-menu-map "V" 'scroll-down)
yuuji@11 197 (define-key YaTeX-math-menu-map "r" 'scroll-down)
yuuji@11 198 (define-key YaTeX-math-menu-map "\^h" 'scroll-down)
yuuji@11 199 (define-key YaTeX-math-menu-map "<" 'beginning-of-buffer)
yuuji@11 200 (define-key YaTeX-math-menu-map ">" 'end-of-buffer)
yuuji@11 201 (define-key YaTeX-math-menu-map "\^m" 'exit-recursive-edit)
yuuji@11 202 (define-key YaTeX-math-menu-map "q" 'abort-recursive-edit))
yuuji@11 203
yuuji@11 204 (defmacro YaTeX-math-japanese-sign (list)
yuuji@11 205 (list 'nth 1 list))
yuuji@11 206
yuuji@11 207 (defvar YaTeX-math-cmd-regexp (concat (regexp-quote YaTeX-ec) "[A-z]"))
yuuji@11 208
yuuji@11 209 (defun YaTeX-math-forward (arg)
yuuji@11 210 (interactive "p")
yuuji@11 211 (re-search-forward YaTeX-math-cmd-regexp nil t arg))
yuuji@11 212
yuuji@11 213 (defun YaTeX-math-backward (arg)
yuuji@11 214 (interactive "p")
yuuji@11 215 (re-search-backward YaTeX-math-cmd-regexp nil t arg))
yuuji@11 216
yuuji@11 217 (defun YaTeX-math-get-sign (list)
yuuji@11 218 (let ((sign (car (cdr (cdr list)))))
yuuji@11 219 (if (listp sign)
yuuji@11 220 (setq sign (cond
yuuji@11 221 (YaTeX-japan (YaTeX-math-japanese-sign sign))
yuuji@11 222 (t (car sign)))))
yuuji@11 223 sign)
yuuji@11 224 )
yuuji@11 225
yuuji@11 226 (defun YaTeX-math-display-list (list cols)
yuuji@11 227 (goto-char (point-max))
yuuji@11 228 (if (= cols 0) (if (not (eolp)) (newline 1))
yuuji@11 229 (forward-line -1)
yuuji@11 230 (while (looking-at "[ \t\n]") (forward-line -1)))
yuuji@11 231 (end-of-line)
yuuji@11 232 (let ((indent (* YaTeX-math-display-width cols)) sign str to)
yuuji@11 233 (indent-to indent)
yuuji@11 234 (insert (car list))
yuuji@11 235 (indent-to (setq indent (+ indent YaTeX-math-max-key)))
yuuji@11 236 (insert "\\" (car (cdr list)))
yuuji@11 237 (setq indent (+ indent YaTeX-math-max-seq))
yuuji@11 238 (setq sign (YaTeX-math-get-sign list))
yuuji@11 239 (while (not (string= "" sign))
yuuji@11 240 (setq to (string-match "\n" sign)
yuuji@11 241 str (if to (substring sign 0 to) sign))
yuuji@11 242 (end-of-line)
yuuji@11 243 (indent-to indent)
yuuji@11 244 (insert str)
yuuji@11 245 (cond ((eobp) (newline 1))
yuuji@11 246 ((> cols 0) (forward-line 1)))
yuuji@11 247 (setq sign (if to (substring sign (1+ to)) "")))))
yuuji@11 248
yuuji@11 249 (defvar YaTeX-math-menu-buffer "*math-mode-signs*")
yuuji@11 250
yuuji@11 251 (defun YaTeX-math-show-menu (match-str)
yuuji@11 252 (save-window-excursion
yuuji@11 253 (pop-to-buffer YaTeX-math-menu-buffer)
yuuji@11 254 (let ((maxcols (max 1 (/ (screen-width) YaTeX-math-sign-width)))
yuuji@11 255 (case-fold-search nil)
yuuji@11 256 (cols 0) (list YaTeX-math-key-alist) command)
yuuji@11 257 (erase-buffer)
yuuji@11 258 (insert YaTeX-math-indicator "\t")
yuuji@11 259 (insert YaTeX-math-indicator)
yuuji@11 260 (newline 1)
yuuji@11 261 (insert-char ?- (1- (screen-width)))
yuuji@11 262 (newline 1)
yuuji@11 263 (while list
yuuji@11 264 (if (string-match match-str (car (car list)))
yuuji@11 265 (progn (YaTeX-math-display-list (car list) cols)
yuuji@11 266 (setq cols (% (1+ cols) maxcols))))
yuuji@11 267 (setq list (cdr list)))
yuuji@11 268 (goto-char (point-min))
yuuji@11 269 (use-local-map YaTeX-math-menu-map)
yuuji@11 270 (unwind-protect
yuuji@11 271 (recursive-edit)
yuuji@11 272 (skip-chars-backward "^ \t\n")
yuuji@11 273 (setq command
yuuji@11 274 (if (re-search-forward YaTeX-math-cmd-regexp nil t)
yuuji@11 275 (buffer-substring
yuuji@11 276 (match-beginning 0)
yuuji@11 277 (prog2 (skip-chars-forward "^ \t\n") (point)))
yuuji@11 278 nil))
yuuji@11 279 (kill-buffer YaTeX-math-menu-buffer))
yuuji@11 280 command))
yuuji@11 281 )
yuuji@11 282
yuuji@11 283 ;
yuuji@11 284 (defun YaTeX-math-show-image (image &optional exit-char)
yuuji@11 285 "Momentarily display IMAGE at the beginning of the next line;
yuuji@11 286 erase it on the next keystroke. The window is recentered if necessary
yuuji@11 287 to make the whole string visible. If the window isn't large enough,
yuuji@11 288 at least you get to read the beginning."
yuuji@11 289 (let ((buffer-read-only nil)
yuuji@11 290 (modified (buffer-modified-p))
yuuji@11 291 (name buffer-file-name)
yuuji@11 292 insert-start
yuuji@11 293 insert-end)
yuuji@11 294 (unwind-protect
yuuji@11 295 (progn
yuuji@11 296 (save-excursion
yuuji@11 297 ;; defeat file locking... don't try this at home, kids!
yuuji@11 298 (setq buffer-file-name nil)
yuuji@11 299 (forward-line 1)
yuuji@11 300 (setq insert-start (point))
yuuji@11 301 (if (eobp) (newline))
yuuji@11 302 (insert image)
yuuji@11 303 (setq insert-end (point)))
yuuji@11 304 ; make sure the whole string is visible
yuuji@11 305 (if (not (pos-visible-in-window-p insert-end))
yuuji@11 306 (recenter (max 0
yuuji@11 307 (- (window-height)
yuuji@11 308 (count-lines insert-start insert-end)
yuuji@11 309 2))))
yuuji@11 310 (let ((char (read-char)))
yuuji@11 311 (or (eq char exit-char)
yuuji@11 312 (setq unread-command-char char))))
yuuji@11 313 (if insert-end
yuuji@11 314 (save-excursion
yuuji@11 315 (delete-region insert-start insert-end)))
yuuji@11 316 (setq buffer-file-name name)
yuuji@11 317 (set-buffer-modified-p modified))))
yuuji@11 318
yuuji@11 319 (defun YaTeX-math-insert-sequence ()
yuuji@11 320 (interactive)
yuuji@11 321 (let ((key "") regkey str last-char list i
yuuji@11 322 (case-fold-search nil) match
yuuji@11 323 (n (length YaTeX-math-key-array)) (beg (point)) result)
yuuji@11 324 (setq result
yuuji@11 325 (catch 'complete
yuuji@11 326 (while t
yuuji@11 327 (setq last-char (read-char)
yuuji@11 328 key (concat key (char-to-string last-char))
yuuji@11 329 regkey (concat "^" (regexp-quote key)) i 0)
yuuji@11 330 (cond
yuuji@11 331 ((string= key YaTeX-math-invoke-key) ;;invoke key itself
yuuji@11 332 (throw 'complete 'escape))
yuuji@11 333 ((string-match "[\C-g\C-c]" key) (throw 'complete 'abort))
yuuji@11 334 ((string-match "[\n\r]" key) (throw 'complete 'menu)))
yuuji@11 335 (if
yuuji@11 336 (catch 'found
yuuji@11 337 ;;(1)input string strictly matches with alist
yuuji@11 338 (setq single-command (car (cdr match))
yuuji@11 339 ;;remember previous match
yuuji@11 340 match (assoc key YaTeX-math-key-alist))
yuuji@11 341 ;;(2)search partial match into alist
yuuji@11 342 (while (< i n)
yuuji@11 343 (if (string-match
yuuji@11 344 regkey (aref YaTeX-math-key-array i))
yuuji@11 345 (progn
yuuji@11 346 (or match
yuuji@11 347 (setq match (nth i YaTeX-math-key-alist)))
yuuji@11 348 (throw 'found t)))
yuuji@11 349 (setq i (1+ i)))) ;catch 'found
yuuji@11 350 nil ;;if any match, continue reading
yuuji@11 351 ;;else reading of sequence has been done.
yuuji@11 352 (message "complete.")
yuuji@11 353 (throw 'complete t)
yuuji@11 354 )
yuuji@11 355 (if match
yuuji@11 356 (progn (delete-region beg (point))
yuuji@11 357 (insert YaTeX-ec (car (cdr match)))
yuuji@11 358 (if YaTeX-math-need-image
yuuji@11 359 (YaTeX-math-show-image
yuuji@11 360 (concat (YaTeX-math-get-sign match) "\n")))
yuuji@11 361 )
yuuji@11 362 nil)
yuuji@11 363 )))
yuuji@11 364 (cond
yuuji@11 365 ((eq result t)
yuuji@11 366 (setq YaTeX-current-completion-type 'maketitle)
yuuji@11 367 (if t nil
yuuji@11 368 (delete-region beg (point))
yuuji@11 369 (setq single-command (car (cdr match)))
yuuji@11 370 ;;(recursive-edit)
yuuji@11 371 (insert YaTeX-ec single-command)
yuuji@11 372 )
yuuji@11 373 (sit-for 1)
yuuji@11 374 (setq unread-command-char last-char)
yuuji@11 375 (insert (YaTeX-addin single-command)))
yuuji@11 376 ((eq result 'abort)
yuuji@11 377 (delete-region beg (point))
yuuji@11 378 (message "Abort."))
yuuji@11 379 ((eq result 'escape)
yuuji@11 380 (delete-region beg (point))
yuuji@11 381 (insert YaTeX-math-invoke-key))
yuuji@11 382 ((eq result 'menu)
yuuji@11 383 (delete-region beg (point))
yuuji@11 384 (setq key (concat "^" (regexp-quote (substring key 0 -1))))
yuuji@11 385 (insert (YaTeX-math-show-menu key)))))
yuuji@11 386 )
yuuji@11 387 ;;
yuuji@11 388 (provide 'yatexmth)