changeset 23:b00c74813e56

Change the YaTeX-math-mode's prefix from `,' to `;'. Add YaTeX-apropos, YaTeX-what-column, YaTeX-beginning-of-environment, YaTeX-end-of-environment. Add variables YaTeX-default-pop-window-height, YaTeX-close-paren-always, YaTeX-no-begend-shortcut, YaTeX-auto-math-mode. Remove Greek letters from maketitle-type. Make YaTeX-inner-environment two times faster and more reliable. C-u for [prefix] k kills contents too. Fix the detection of the range of section-type commands when nested. Add \end{ completion. Add YaTeX-generate-simple. Refine documents(using Texinfo). %#REQUIRE for sub-preambles.
author yuuji
date Thu, 07 Jul 1994 16:37:05 +0000
parents 9d2387100375
children 21a751ddf614
files yatex.new yatexadd.el yatexenv.el yatexgen.el yatexhks.el yatexhlp.el yatexlib.el yatexmth.el yatexprc.el yatexsec.el
diffstat 10 files changed, 1382 insertions(+), 218 deletions(-) [+]
line wrap: on
line diff
--- a/yatex.new	Thu Jul 07 16:37:05 1994 +0000
+++ b/yatex.new	Thu Jul 07 16:37:05 1994 +0000
@@ -1,6 +1,36 @@
 	Yet Another tex-mode for Emacs
 	yatex.el 各バージョンの変更点について。
 
+1.50	YaTeX-math モードの記号用 prefix を , から ; に変えた(注意!)。
+	イメージ補完の一覧表示キーを RET から TAB に変えた(注意!)。
+	[prefix] / の YaTeX-apropos の追加。
+	[prefix] & の YaTeX-what-column の追加。
+	YaTeX-math モードは自動判定するようにした。YaTeX-math モード用の
+	prefix を強制的に活かす時は C-u ; などとする。
+	YaTeX-beginning-of-environment(ESC C-a)
+	YaTeX-end-of-environment(ESC C-e)
+	YaTeX-mark-environment(ESC C-@) をそれぞれ追加。
+	YaTeX-default-pop-window-height でデフォルトのタイプセットバッ
+	ファの高さを指定できるようにした。数値を指定するとタイプセットバッ
+	ファの行数、数字文字列でEmacsウィンドウの高さに対する百分率。
+	YaTeX-close-paren-always がt、かつ新規入力モードなら常に開き括弧
+	の入力で閉じ括弧も入力する(デフォルトはt)。
+	ギリシャ文字補完候補を maketitle 型補完から除去。
+	YaTeX-end-environment で呼んでいる YaTeX-inner-environment の高速化。
+	YaTeX-end-environment で次の\end検索がうまく行かないバグを直した。
+	C-u [prefix] k でLaTeXコマンドとその中身を同時削除するようにし、
+	子ファイルでpreview用コマンドを変えても反映されないバグを直した。
+	\endの次で{を押した時には自動的に閉じるべき環境名を入れる(^^;)。
+	引数型アドイン関数も作れる M-x YaTeX-generate-simple を用意した。
+	%#REQUIRE の行は必ず typeset-region の時にコピーする。
+	ドキュメントの Texinfo 化。
+    <Fixes>
+	ネストしたsection型コマンドの削除範囲判定のバグを直した。
+	\begin と \end の uncomment が verbatim 環境でうまく行かないバグ
+	を直した。
+	typeset-regionでend-of-bufferまでか%#ENDまでかの表示が逆だったの
+	を直した。
+
 1.49	YaTeX::newcommand において \newcommand の引数0個の時は maketitle 
 	型用の辞書を更新するようにした。
 	テンポラリ辞書を格納する変数を buffer-local に。
--- a/yatexadd.el	Thu Jul 07 16:37:05 1994 +0000
+++ b/yatexadd.el	Thu Jul 07 16:37:05 1994 +0000
@@ -1,12 +1,10 @@
 ;;; -*- Emacs-Lisp -*-
 ;;; YaTeX add-in functions.
-;;; yatexadd.el rev.8
+;;; yatexadd.el rev.9
 ;;; (c )1991-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
-;;; Last modified Sun May 15 18:00:12 1994 on 98fa
+;;; Last modified Mon Jun 27 17:00:19 1994 on figaro
 ;;; $Id$
 
-(provide 'yatexadd)
-
 ;;;
 ;;Sample functions for LaTeX environment.
 ;;;
@@ -14,22 +12,53 @@
   "@{\\vrule width 1pt\\ }c|c|c@{\\ \\vrule width 1pt}"
   "*Your favorite default rule format."
 )
+(defvar YaTeX:tabular-thick-vrule "\\vrule width %s"
+  "*Vertical thick line format (without @{}).  %s'll be replaced by its width."
+)
+(defvar YaTeX:tabular-thick-hrule "\\noalign{\\hrule height %s}"
+  "*Horizontal thick line format.  %s will be replaced by its width."
+)
 (defun YaTeX:tabular ()
   "YaTeX add-in function for tabular environment.
 Notice that this function refers the let-variable `env' in
 YaTeX-make-begin-end."
-  (let ((width "") bars (rule "") (j 0) loc)
+  (let ((width "") bars (rule "") (and "") (j 1) loc ans (hline "\\hline"))
     (if (string= env "tabular*")
 	(setq width (concat "{" (read-string "Width: ") "}")))
     (setq loc (YaTeX:read-position "tb")
-	  bars (string-to-int (read-string "Number of `|': ")))
-    (if (> bars 0)
-	(while (< j bars) (setq rule (concat rule "|")) (setq j (1+ j)))
-      (setq rule YaTeX:tabular-default-rule))
+	  bars (string-to-int
+		(read-string "Number of columns(0 for default format): " "3")))
+    (if (<= bars 0)
+	(setq				;if 0, simple format
+	 rule YaTeX:tabular-default-rule
+	 and "& &")
+      (while (< j bars)			;repeat bars-1 times
+	(setq rule (concat rule "c|")
+	      and (concat and "& ")
+	      j (1+ j)))
+      (setq rule (concat rule "c"))
+      (message "(N)ormal-frame or (T)hick frame? [nt]")
+      (setq ans (read-char))
+      (cond
+       ((or (equal ans ?t) (equal ans ?T))
+	(setq ans (read-string "Rule width: " "1pt")
+	      rule (concat
+		    "@{" (format YaTeX:tabular-thick-vrule ans) "}"
+		    rule
+		    "@{\\ " (format YaTeX:tabular-thick-vrule ans) "}")
+	      hline (format YaTeX:tabular-thick-hrule ans)))
+       (t (setq rule (concat "|" rule "|")
+		hline "\\hline"))))
+
     (setq rule (read-string "rule format: " rule))
 
-    (message "")
-    (format "%s%s{%s}" width loc rule))
+    (message "Dont forget to remove null line at the end of tabular.")
+    (format "%s%s{%s}%s"
+	    width loc rule
+	    (if (and (boundp 'region-mode) region-mode)
+		""		;do nothing in region-mode
+	      (format "\n%s\n%s \\\\ \\hline\n%s\n\\\\ %s"
+		      hline and and hline))))
 )
 (fset 'YaTeX:tabular* 'YaTeX:tabular)
 (defun YaTeX:array ()
@@ -37,11 +66,13 @@
 	  "{" (read-string "Column format: ") "}")
 )
 
-(defun YaTeX:read-position (oneof)
-  (let ((pos "") loc)
+(defun YaTeX:read-oneof (oneof)
+  (let ((pos "") loc (guide ""))
+    (and (boundp 'name) name (setq guide (format "%s " name)))
     (while (not (string-match
 		 (setq loc (read-key-sequence
-			    (format "Position (`%s') [%s]: " oneof pos)))
+			    (format "%s position (`%s') [%s]: "
+				    guide oneof pos)));name is in YaTeX-addin
 		 "\r\^g\n"))
       (cond
        ((string-match loc oneof)
@@ -54,8 +85,13 @@
 	(message "Please input one of `%s'." oneof)
 	(sit-for 3))))
     (message "")
-    (if (string= pos "") ""
-      (concat "[" pos "]")))
+    pos)
+)
+
+(defun YaTeX:read-position (oneof)
+  "Read a LaTeX (optional) position format such as `[htbp]'."
+  (let ((pos (YaTeX:read-oneof oneof)))
+    (if (string= pos "")  "" (concat "[" pos "]")))
 )
 
 (defun YaTeX:table ()
@@ -113,8 +149,17 @@
 )
 
 (defun YaTeX:makebox ()
-  (concat (YaTeX:read-coordinates "Dimension")
-	  (YaTeX:read-position "lrtb"))
+  (cond
+   ((YaTeX-in-environment-p "picture")
+    (concat (YaTeX:read-coordinates "Dimension")
+	    (YaTeX:read-position "lrtb")))
+   (t
+    (let ((width (read-string "Width: ")))
+      (if (string< "" width)
+	  (progn
+	    (or (equal (aref width 0) ?\[)
+		(setq width (concat "[" width "]")))
+	    (concat width (YaTeX:read-position "lr")))))))
 )
 
 (defun YaTeX:framebox ()
@@ -127,6 +172,19 @@
 	  (YaTeX:read-coordinates "Dimension"))
 )
 
+(defun YaTeX:left ()
+  (let (c)
+    (while (not (string-match
+		 (progn (message "Which parenthesis? One of [{(|)}]: ")
+			(setq c (regexp-quote (char-to-string (read-char)))))
+		 "[{(|)}]")))
+    (setq single-command "right")
+    (cond
+     ((string-match c "[(|)]") c)
+     (t (concat "\\" c))))
+)
+(fset 'YaTeX:right 'YaTeX:left)
+
 (defun YaTeX:read-coordinates (&optional mes varX varY)
   (concat
    "("
@@ -177,6 +235,7 @@
 	(contents (read-string "Quoted contents: ")))
     (concat quote-char contents quote-char))
 )
+(fset 'YaTeX:verb* 'YaTeX:verb)
 
 ;;;
 ;;Subroutine
@@ -202,6 +261,8 @@
 ;;
 (defvar YaTeX-label-menu-other
   (if YaTeX-japan "':他のバッファのラベル\n" "':LABEL IN OTHER BUFFER.\n"))
+(defvar YaTeX-label-menu-repeat
+  (if YaTeX-japan ".:直前の\\refと同じ\n" "/:REPEAT LAST \ref{}\n"))
 (defvar YaTeX-label-menu-any
   (if YaTeX-japan "*:任意の文字列\n" "*:ANY STRING.\n"))
 (defvar YaTeX-label-buffer "*Label completions*")
@@ -228,6 +289,7 @@
     (define-key YaTeX-label-select-map "/"	'isearch-forward)
     (define-key YaTeX-label-select-map "?"	'isearch-backward)
     (define-key YaTeX-label-select-map "'"	'YaTeX::label-search-tag)
+    (define-key YaTeX-label-select-map "."	'YaTeX::label-search-tag)
     (define-key YaTeX-label-select-map "*"	'YaTeX::label-search-tag)
     (message "Setting up label selection mode map...Done")
     (let ((key ?A))
@@ -244,15 +306,15 @@
   (interactive) (forward-line -1) (message YaTeX-label-guide-msg))
 (defun YaTeX::label-search-tag ()
   (interactive)
-  (let ((case-fold-search t))
+  (let ((case-fold-search t) (tag (regexp-quote (this-command-keys))))
     (cond
      ((save-excursion
 	(forward-char 1)
-	(re-search-forward (concat "^" (this-command-keys)) nil t))
+	(re-search-forward (concat "^" tag) nil t))
       (goto-char (match-beginning 0)))
      ((save-excursion
 	(goto-char (point-min))
-	(re-search-forward (concat "^" (this-command-keys)) nil t))
+	(re-search-forward (concat "^" tag) nil t))
       (goto-char (match-beginning 0))))
     (message YaTeX-label-guide-msg))
 )
@@ -284,6 +346,7 @@
 		(message "Collecting \\label{}... %d" lnum))
 	      (goto-char e0))
 	    (princ YaTeX-label-menu-other)
+	    (princ YaTeX-label-menu-repeat)
 	    (princ YaTeX-label-menu-any)
 	    );with
 	  (goto-char p)
@@ -303,7 +366,15 @@
 		(setq line (count-lines (point-min)(point)))
 		(cond
 		 ((= line lnum) (setq label (YaTeX-label-other)))
-		 ((>= line (1+ lnum ))
+		 ((= line (1+ lnum))
+		  (save-excursion
+		    (switch-to-buffer buf)
+		    (goto-char p)
+		    (if (re-search-backward "\\\\ref{\\([^}]+\\)}" nil t)
+			(setq label (buffer-substring
+				     (match-beginning 1) (match-end 1)))
+		      (setq label ""))))
+		 ((>= line (+ lnum 2))
 		  (setq label (read-string "\\ref{???}: ")))
 		 (t (setq label (nth (- lnum line 1) label-list)))))
 	    (bury-buffer YaTeX-label-buffer)))
@@ -408,24 +479,101 @@
    '(("arabic") ("Alpha") ("alpha") ("Roman") ("roman")))
 )
 
-;;;
-;; global subroutines
-;;;
-(defun substitute-all-key-definition (olddef newdef keymap)
-  "Replace recursively OLDDEF with NEWDEF for any keys in KEYMAP now
-defined as OLDDEF. In other words, OLDDEF is replaced with NEWDEF
-where ever it appears."
-  (if (arrayp keymap)
-      (let ((len (length keymap))
-	    (i 0))
-	(while (< i len)
-	  (let ((map (aref keymap i)))
-	    (cond
-	     ((arrayp map) (substitute-key-definition olddef newdef map))
-	     ((equal map olddef)
-	      (aset keymap i newdef)))
-	    (setq i (1+ i)))))
-    (while keymap
-      (if (equal (cdr-safe (car-safe keymap)) olddef)
-	  (setcdr (car keymap) newdef))
-      (setq keymap (cdr keymap)))))
+;;
+; Length
+;;
+(defvar YaTeX:style-parameters-default
+  '(("\\arraycolsep")
+    ("\\arrayrulewidth")
+    ("\\baselineskip")
+    ("\\columnsep")
+    ("\\columnseprule")
+    ("\\doublerulesep")
+    ("\\evensidemargin")
+    ("\\footheight")
+    ("\\footskip")
+    ("\\headheight")
+    ("\\headsep")
+    ("\\itemindent")
+    ("\\itemsep")
+    ("\\labelsep")
+    ("\\labelwidth")
+    ("\\leftmargin")
+    ("\\linewidth")
+    ("\\listparindent")
+    ("\\marginparsep")
+    ("\\marginparwidth")
+    ("\\mathindent")
+    ("\\oddsidemargin")
+    ("\\parindent")
+    ("\\parsep")
+    ("\\parskip")
+    ("\\partopsep")
+    ("\\rightmargin")
+    ("\\tabcolsep")
+    ("\\textheight")
+    ("\\textwidth")
+    ("\\topmargin")
+    ("\\topsep")
+    ("\\topskip")
+    )
+  "Alist of LaTeX style parameters.")
+(defvar YaTeX:style-parameters-private nil
+  "*User definable alist of style parameters.")
+(defvar YaTeX:style-parameters-private nil
+  "Holds the union of LaTeX style parameters.")
+(setq YaTeX:style-parameters
+      (append YaTeX:style-parameters-private YaTeX:style-parameters-default))
+
+(defvar YaTeX:length-history nil "Holds history of length.")
+(defun YaTeX::setlength (&optional argp)
+  "YaTeX add-in function for arguments of \\setlength."
+  (cond
+   ((equal 1 argp)
+    (completing-read "Length variable: " YaTeX:style-parameters nil nil "\\"))
+   ((equal 2 argp)
+    (let ((minibuffer-history-symbol 'YaTeX:length-history))
+      (read-string "Length: "))))
+)
+(fset 'YaTeX::addtolength 'YaTeX::setlength)
+
+(defun YaTeX::settowidth (&optional argp)
+  "YaTeX add-in function for arguments of \\settowidth."
+  (cond
+   ((equal 1 argp)
+    (completing-read "Length variable: " YaTeX:style-parameters nil nil "\\"))
+   ((equal 2 argp)
+    (read-string "Text: ")))
+)
+(defun YaTeX::newlength (&optional argp)
+  "YaTeX add-in function for arguments of \\newlength"
+  (cond
+   ((equal argp 1)
+    (let ((length (read-string "Length variable: " "\\")))
+      (or (assoc length YaTeX:style-parameters-private)
+	  (setq YaTeX:style-parameters-private
+		(cons (list length) YaTeX:style-parameters-private)
+		YaTeX:style-parameters
+		(cons (list length) YaTeX:style-parameters)))
+      length)))
+)
+
+;; \multicolumn's arguments
+(defun YaTeX::multicolumn (&optional argp)
+  "YaTeX add-in function for arguments of \\multicolumn."
+  (cond
+   ((equal 1 argp)
+    (read-string "Number of columns: "))
+   ((equal 2 argp)
+    (let (c)
+      (while (not (string-match
+		   (progn (message "Format(one of l,r,c): ")
+			  (setq c (char-to-string (read-char))))
+		   "lrc")))
+      c))
+   ((equal 3 argp)
+    (read-string "Item: ")))
+)
+
+;;; -------------------- End of yatexadd --------------------
+(provide 'yatexadd)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yatexenv.el	Thu Jul 07 16:37:05 1994 +0000
@@ -0,0 +1,154 @@
+;;; -*- Emacs-Lisp -*-
+;;; YaTeX environment-specific functions.
+;;; yatexenv.el
+;;; (c ) 1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
+;;; Last modified Fri Jul  8 00:48:40 1994 on figaro
+;;; $Id$
+
+;;;
+;; Functions for tabular environment
+;;;
+
+;; Showing the matching column of tabular environment.
+(defun YaTeX-array-what-column ()
+  "Show matching columne title of array environment.
+When calling from a program, make sure to be in array/tabular environment."
+  (let ((p (point)) beg eot bor (nlptn "\\\\\\\\") (andptn "[^\\]&") (n 0)
+	(firsterr "This line might be the first row."))
+    (save-excursion
+      (YaTeX-beginning-of-environment)
+      (search-forward "{" p) (up-list 1)
+      (search-forward "{" p) (up-list 1)
+      ;;(re-search-forward andptn p)
+      (while (progn (search-forward "&" p)
+		    (equal (char-after (1- (match-beginning 0))) ?\\ )))
+      (setq beg (1- (point)))		;beg is the point of the first &
+      (or (re-search-forward nlptn p t)
+	  (error firsterr))
+      (setq eot (point))		;eot is the point of the first \\
+      (goto-char p)
+      (or (re-search-backward nlptn beg t)
+	  (error firsterr))
+      (setq bor (point))		;bor is the beginning of this row.
+      (while (< (1- (point)) p)
+	(if (equal (following-char) ?&)
+	    (forward-char 1)
+	  (re-search-forward andptn nil 1))
+	(setq n (1+ n)))		;Check current column number
+      (goto-char p)
+      (cond				;Start searching \multicolumn{N}
+       ((> n 1)
+	(re-search-backward andptn)	;Sure to find!
+	(while (re-search-backward "\\\\multicolumn{\\([0-9]+\\)}" bor t)
+	  (setq n (+ n (string-to-int
+			(buffer-substring (match-beginning 1)
+					  (match-end 1)))
+		     -1)))))
+      (message "%s" n)
+      (goto-char (1- beg))
+      (cond
+       ((= n 1) (message "Here is the FIRST column!"))
+       (t (while (> n 1)
+	    (or (re-search-forward andptn p nil)
+		(error "This column exceeds the limit."))
+	    (setq n (1- n)))
+	  (skip-chars-forward "\\s ")
+	  (message
+	   "Here is the column of: %s"
+	   (buffer-substring
+	    (point)
+	    (progn
+	      (re-search-forward (concat andptn "\\|" nlptn) eot)
+	      (goto-char (match-beginning 0))
+	      (if (looking-at andptn)
+		  (forward-char 1))
+	      (skip-chars-backward "\\s ")
+	      (point))))))))
+)
+
+;;;###autoload
+(defun YaTeX-what-column ()
+  "Show which kind of column the current position is belonging to."
+  (interactive)
+  (cond
+   ((YaTeX-quick-in-environment-p '("tabular" "tabular*" "array" "array*"))
+    (YaTeX-array-what-column))
+   (t (message "Not in array/tabuar environment.")))
+)
+
+;;;
+;; Functions for tabbing environment
+;;;
+(defun YaTeX-intelligent-newline-tabbing ()
+  "Check the number of \\= in the first line and insert that many \\>."
+  (let ((p (point)) begenv tabcount)
+    (save-excursion
+      (YaTeX-beginning-of-environment)
+      (setq begenv (point-end-of-line))
+      (if (YaTeX-search-active-forward "\\\\" YaTeX-comment-prefix p t)
+	  (progn
+	    (setq tabcount 0)
+	    (while (> (point) begenv)
+	      (if (search-backward "\\=" begenv 1)
+		  (setq tabcount (1+ tabcount)))))))
+    (YaTeX-indent-line)
+    (if tabcount
+	(progn
+	  (save-excursion
+	    (while (> tabcount 0)
+	      (insert "\\>\t")
+	      (setq tabcount (1- tabcount))))
+	  (forward-char 2))
+      (insert "\\=")))
+)
+
+;;;
+;; Functions for itemize/enumerate/list environments
+;;;
+
+(defun YaTeX-indent-for-item ()
+  (let (col (p (point)) begenv)
+    (save-excursion
+      (YaTeX-beginning-of-environment t)
+      (setq begenv (point-end-of-line))
+      (goto-char p)
+      (if (YaTeX-search-active-backward "\\item" YaTeX-comment-prefix begenv t)
+	  (setq col (current-column))))
+    (if col (indent-to col) (YaTeX-indent-line)))
+)
+
+(defvar YaTeX-item-for-insert "\\item ")
+(defun YaTeX-intelligent-newline-itemize ()
+  "Insert '\\item '."
+  (YaTeX-indent-for-item)
+  (insert YaTeX-item-for-insert)
+)
+(fset 'YaTeX-intelligent-newline-enumerate 'YaTeX-intelligent-newline-itemize)
+(fset 'YaTeX-intelligent-newline-list 'YaTeX-intelligent-newline-itemize)
+
+(defun YaTeX-intelligent-newline-description ()
+  (YaTeX-indent-for-item)
+  (insert "\\item[] ")
+  (forward-char -2)
+)
+
+
+;;;
+;; Intelligent newline
+;;;
+;;;###autoload
+(defun YaTeX-intelligent-newline (arg)
+  "Insert newline and environment-specific entry.
+`\\item'	for some itemizing environment,
+`\\> \\> \\'	for tabbing environemnt,
+`& & \\ \hline'	for tabular environment."
+  (interactive "P")
+  (let*((env (YaTeX-inner-environment))
+	func)
+    (if arg (setq env (YaTeX-read-environment "For what environment? ")))
+    (setq func (intern-soft (concat "YaTeX-intelligent-newline-" env)))
+    (end-of-line)
+    (newline)
+    (if (and env func (fboundp func))
+	(funcall func)))
+)
--- a/yatexgen.el	Thu Jul 07 16:37:05 1994 +0000
+++ b/yatexgen.el	Thu Jul 07 16:37:05 1994 +0000
@@ -1,8 +1,8 @@
 ;;; -*- Emacs-Lisp -*-
-;;; Generate add-in functions for YaTeX.
-;;; yatexgen.el rev.1(beta2)
+;;; YaTeX add-in function generator.
+;;; yatexgen.el rev.2
 ;;; (c )1991-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
-;;; Last modified Sat Apr 23 02:26:34 1994 on pajero
+;;; Last modified Fri Jul  8 00:46:09 1994 on figaro
 ;;; $Id$
 
 (require 'yatex)
@@ -403,3 +403,195 @@
       (define-key map (char-to-string i) 'undefined)
       (setq i (1+ i))))
 )
+
+;;;
+;; Auto-generate Function for Lispers.
+;;;
+(defun YaTeX-generate-read-completion-type (nth)
+  (message
+"Read type(%d): (S)tring (C)omplete (F)ile ([)option (P)osition co(O)rd. (q)uit" nth)
+  (let ((c (read-char)))
+    (cond
+     ((= c ?s) 'string)
+     ((= c ?c) 'completion)
+     ((= c ?f) 'file)
+     ((= c ?\[) 'option)
+     ((= c ?p) 'oneof)
+     ((= c ?o) 'coord)
+     ;;((= c ?m) 'macro)
+     (t        'quit)))
+ )
+(defun YaTeX-generate-read-completion-table ()
+  (let ((i 1) cand (cands "(") (cb (current-buffer))
+	(buf (get-buffer-create " *Candidates*")))
+    (save-window-excursion
+      (save-excursion
+      (YaTeX-showup-buffer buf nil)
+      (set-buffer buf)
+      (erase-buffer)
+      (while (string<
+	      ""
+	      (setq cand (read-string (format "Item[%d](RET to exit): " i))))
+	(setq cands (concat cands (format "(""%s"")\n" cand))
+	      i (1+ i))
+	(insert cand "\n"))
+      (kill-buffer buf)))
+    ;;(set-buffer cb)
+    (concat cands ")"))
+)
+(defun YaTeX-generate-corresponding-paren (left)
+  (cond
+   ((equal left "{") "}")
+   ((equal left "[") "]")
+   ((equal left "(") ")")
+   ((equal left "<") ">")
+   ((equal left "\\begin{" "}"))
+   (t left))
+)
+(defun YaTeX-generate-create-read-string (&optional nth)
+  (concat
+   "(read-string """
+   (read-string (if nth (format "Prompt for argument#%d: " nth) "Prompt: "))
+   ": ""\n"
+   """" (read-string "Default: ") """"
+   ")\n")
+)
+(defun YaTeX-generate-create-completing-read (&optional nth)
+  (concat
+   "(completing-read """
+   (read-string (if nth (format "Prompt for argument#%d: " nth) "Prompt: "))
+   ": ""\n"
+   (format "'%s\n" (YaTeX-generate-read-completion-table))
+   "nil "
+   (format "%s)" (y-or-n-p "Require match? ")))
+)
+(defun YaTeX-generate-create-read-file-name (&optional nth)
+  (concat
+   "(read-file-name """
+   (read-string (if nth (format "Prompt for argument#%d: " nth) "Prompt: "))
+   ": "" nil nil t """")\n")
+)
+(defun YaTeX-generate-create-read-oneof (&optional nth readpos)
+  (concat
+   (if readpos
+       "(YaTeX:read-position """
+     "(YaTeX:read-oneof """)
+   (read-string "Acceptable characters: " "lcr") """)\n")
+)
+(defun YaTeX-generate-option-type (command)
+  (let ((func (format "YaTeX:%s" command)) leftp
+	(buf (get-buffer-create YaTeX-generate-buffer)) type (n 1))
+    (set-buffer buf)
+    (erase-buffer)
+    (insert "(defun " func " ()\n  (concat\n")
+    (catch 'done
+      (while t
+	(setq type (YaTeX-generate-read-completion-type n))
+	(insert 
+	 (cond
+	  ;;Read string
+	  ((eq type 'string)
+	   (concat """" (setq leftp (read-string "Left parenthesis: " "{"))
+		   """\n"
+		   (YaTeX-generate-create-read-string)
+		   """" (YaTeX-generate-corresponding-paren leftp) """"
+		   ))
+	  
+	  ;;Completing-read
+	  ((eq type 'completion)
+	   (concat """" (setq leftp (read-string "Left parenthesis: " "{"))
+		   """\n"
+		   (YaTeX-generate-create-completing-read)
+		   """" (YaTeX-generate-corresponding-paren leftp) """")
+	   )
+	  ((eq type 'file)
+	   (concat """" (setq leftp (read-string "Left parenthesis: " "{"))
+		   """\n"
+		   (YaTeX-generate-create-read-file-name)
+		   """" (YaTeX-generate-corresponding-paren leftp) """")
+	   )
+	  ((eq type 'oneof)
+	   (YaTeX-generate-create-read-oneof nil t)
+	   )
+	  ((eq type 'option)
+	   (concat "(let ((op (read-string """
+		   (read-string "Prompt: ")
+		   ": "")))\n"
+		   "(if (string< """" op)\n"
+		   "    (concat ""["" op ""]"")\n"
+		   "  """"))\n")
+	   )
+	  
+	  ((eq type 'coord)
+	   (concat "(YaTeX:read-coordinates """
+		   (read-string "Prompt for coordinates: ")
+		   ": """)
+	   )
+	  ((eq type 'macro)
+	   (error "not yet supported")
+	   )
+	  (t (throw 'done t))))
+	(setq n (1+ n))))
+    (insert "))\n")			;close defun
+    (goto-char (point-min))
+    (while (not (eobp)) (lisp-indent-line) (forward-line 1))
+    (eval-current-buffer)
+    buf)
+)
+(defun YaTeX-generate-argument-type (command argc)
+  "Create an argument-type add-in function."
+  (interactive)
+  (let ((func (format "YaTeX::%s" command)) (argp 1)
+	(cb (current-buffer))
+	(buf (get-buffer-create YaTeX-generate-buffer)))
+    (set-buffer buf)
+    (erase-buffer)
+    (insert "(defun " func " (&optional argp)\n(cond\n")
+    (while (<= argp argc)
+      (insert (format "((equal argp %d)\n" argp))
+      (setq type (YaTeX-generate-read-completion-type argp))
+      (insert
+       (cond
+	((eq type 'string)
+	 (concat (YaTeX-generate-create-read-string argp)))
+	((eq type 'completion)
+	 (concat (YaTeX-generate-create-completing-read argp)))
+	((eq type 'oneof)
+	 (YaTeX-generate-create-read-oneof))
+	((eq type 'file)
+	 (concat (YaTeX-generate-create-read-file-name argp)))
+	(t ""))
+       ")\n")
+      (setq argp (1+ argp)))
+    (insert "))\n")
+    (goto-char (point-min))
+    (while (not (eobp)) (lisp-indent-line) (forward-line 1))
+    (eval-current-buffer)
+    (set-buffer cb)
+    (YaTeX-update-table
+     (if (> argc 1) (list command argc) (list command))
+     'section-table 'user-section-table 'tmp-section-table)
+    buf)
+)
+(defun YaTeX-generate-simple (&optional command)
+  "Simple but requiring some elisp knowledge add-in generator."
+  (interactive)
+  (or command
+      (setq command
+	    (completing-read
+	     (format "Making add-in function for (default %s): " section-name)
+	     (append
+	      section-table user-section-table tmp-section-table
+	      article-table user-article-table
+	      env-table     user-env-table     tmp-env-table
+	      singlecmd-table user-singlecmd-table tmp-singlecmd-table)
+	     nil nil)
+	    command (if (string= "" command) section-name command)))
+  (message "(o)追加型? (a)引数型? (yatexadd.docを参照のこと) :")
+  (YaTeX-showup-buffer
+   (if (= (read-char) ?o)
+       (YaTeX-generate-option-type command)
+     (YaTeX-generate-argument-type
+      command
+      (string-to-int (read-string "How many arguments?: ")))) nil)
+)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yatexhks.el	Thu Jul 07 16:37:05 1994 +0000
@@ -0,0 +1,16 @@
+;;; -*- Emacs-Lisp -*-
+;;; Hooks for YaTeX
+
+;;; $BLnD;$K4XO"$9$k5-=R(B($B$?$H$($P%"%I%$%s4X?t(B)$B$O(B yatexhks.el $B$H$$$&L>A0$N(B
+;;; $B%U%!%$%k$KF~$l$F$/$@$5$$!#5/F0;~$K<+F0E*$K%m!<%I$7$^$9!#(B
+
+;;; All the private definitions for YaTeX can be stuffed into the file
+;;; named `yatexhks.el'.  The file `yatexhks.el' will be automatically
+;;; loaded at the end of loading `yatex.el'.
+
+;Private definitions begins from here.
+
+
+;
+;;; End of yatexhks.el
+(provide 'yatexhks)
--- a/yatexhlp.el	Thu Jul 07 16:37:05 1994 +0000
+++ b/yatexhlp.el	Thu Jul 07 16:37:05 1994 +0000
@@ -2,7 +2,7 @@
 ;;; YaTeX helper with LaTeX commands and macros.
 ;;; yatexhlp.el
 ;;; (c )1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
-;;; Last modified Thu May  5 16:09:42 1994 on 98fa
+;;; Last modified Fri Jul  1 17:03:23 1994 on VFR
 ;;; $Id$
 
 (let ((help-file
@@ -34,7 +34,73 @@
 	(t "[[ Description ]]"))
   "Section header of description.")
 
-(defun YaTeX-refer-help (command help-file)
+(defvar YaTeX-help-reference-regexp "<refer\\s +\\([^>]+\\)>"
+  "Regexp of reference format of YaTeX-help file.")
+(defvar YaTeX-help-buffer "** YaTeX HELP **" "Help buffer name for yatexhlp")
+
+(defun YaTeX-help-entries ()
+  "Return the alist which contains all the entries in YaTeX-help file."
+  (let (entries entry)
+    (save-excursion
+      (mapcar
+       (function
+	(lambda (help)
+	  (if (file-exists-p help)
+	      (progn
+		(set-buffer (find-file-noselect help))
+		(save-excursion
+		  (goto-char (point-min))
+		  (while (re-search-forward
+			  (concat "^" (regexp-quote YaTeX-help-delimiter)
+				  "\\(.+\\)$") nil t)
+		    (setq entry (buffer-substring
+				 (match-beginning 1) (match-end 1)))
+		    (or (assoc entry entries)
+			(setq entries (cons (list entry) entries)))))))))
+       (list YaTeX-help-file YaTeX-help-file-private)))
+    entries)
+)
+
+(defvar YaTeX-help-entries (YaTeX-help-entries))
+
+(defun YaTeX-help-resolve-reference (buffer1 buffer2 &optional done-list)
+  "Replace reference format in buffer1 with refered contents in buffer2."
+  (let (ref ref-list beg end)
+    (save-excursion
+      (switch-to-buffer buffer1)
+      (goto-char (point-min))
+      (while (re-search-forward YaTeX-help-reference-regexp nil t)
+	(setq ref (buffer-substring (match-beginning 1) (match-end 1))
+	      ref-list (cons (list ref) ref-list))
+	(replace-match "")
+	(if (assoc ref done-list) nil	;already documented.
+	  (switch-to-buffer buffer2)
+	  (save-excursion
+	    (goto-char (point-min))
+	    (if (re-search-forward
+		 (concat (regexp-quote YaTeX-help-delimiter)
+			 (regexp-quote ref)
+			 "$") nil t)
+		(progn
+		  (setq beg (progn (forward-line 2) (point))
+			end (progn
+			      (re-search-forward
+			       (concat "^" (regexp-quote YaTeX-help-delimiter))
+			       nil 1)
+			      (goto-char (match-beginning 0))
+			      (forward-line -1)
+			      (while (and (bolp) (eolp) (not (bobp)))
+				(forward-char -1))
+			      (point)))
+		  (switch-to-buffer buffer1)
+		  (insert-buffer-substring buffer2 beg end))))
+	  (switch-to-buffer buffer1)))
+      (if beg (YaTeX-help-resolve-reference
+	       buffer1 buffer2 (append done-list ref-list))))
+    )
+)
+
+(defun YaTeX-refer-help (command help-file &optional append)
   "Refer the COMMAND's help into HELP-FILE.
 \[Help-file format\]
 <DELIM><LaTeX/TeX command without escape character(\\)><NL>
@@ -44,31 +110,35 @@
 	<NL> is newline.
 	<TERM> is newline or end of buffer."
   (let ((hfbuf (find-file-noselect help-file))
-	(hbuf (get-buffer-create "** YaTeX HELP **"))
+	(hbuf (get-buffer-create YaTeX-help-buffer))
 	(curwin (selected-window))
 	sb se db de)
     (set-buffer hfbuf)
     (goto-char (point-min))
     (if (null
-	 (re-search-forward
-	  (concat (regexp-quote YaTeX-help-delimiter)
-		  (regexp-quote command)
-		  "$") nil t))
+	 (let ((case-fold-search nil))
+	   (re-search-forward
+	    (concat (regexp-quote YaTeX-help-delimiter)
+		    (regexp-quote command)
+		    "$") nil t)))
 	nil				;if not found, return nil
       (forward-line 1)
       (setq sb (point)
 	    se (progn (forward-line 1) (point))
 	    db (point)
 	    de (progn
-		 (re-search-forward (regexp-quote YaTeX-help-delimiter) nil 1)
-		 (1- (match-beginning 0))))
-      (YaTeX-showup-buffer hbuf)
+		 (re-search-forward
+		  (concat "^" (regexp-quote YaTeX-help-delimiter)) nil 1)
+		 (- (point) (length YaTeX-help-delimiter))))
+      (YaTeX-showup-buffer
+       hbuf (function (lambda (x) (nth 3 (window-edges x)))))
       (pop-to-buffer hbuf)
-      (erase-buffer)
+      (if append (goto-char (point-max)) (erase-buffer))
       (insert YaTeX-help-synopsis "\n")
       (insert-buffer-substring hfbuf sb se)
       (insert "\n" YaTeX-help-description "\n")
       (insert-buffer-substring hfbuf db de)
+      (YaTeX-help-resolve-reference hbuf hfbuf (list (list command)))
       (goto-char (point-min))
       (select-window curwin)
       t))
@@ -110,13 +180,15 @@
     (delete-blank-lines)
     (let ((make-backup-files t))
       (basic-save-buffer))
-    (bury-buffer hfbuf))
+    (bury-buffer hfbuf)
+    (setq YaTeX-help-entries (cons (list command) YaTeX-help-entries)))
 )
 (defun YaTeX-help-prepare-entry (command help-file)
   "Read help description on COMMAND and add it to HELP-FILE."
   (let ((buf (get-buffer-create "**Description**"))
 	(conf (current-window-configuration)))
-    (YaTeX-showup-buffer buf)
+    (YaTeX-showup-buffer
+     buf (function (lambda (x) (nth 3 (window-edges x)))))
     (pop-to-buffer buf)
     (make-local-variable 'YaTeX-help-file-current)
     (make-local-variable 'YaTeX-help-command-current)
@@ -153,6 +225,44 @@
    nil "\\(\\sw+\\)\\([^]+\\|\\s'\\)" "\\1" (point-min) (point-max))
 )
 
+(defun YaTeX-apropos-file (keyword help-file &optional append)
+  (let ((hb (find-file-noselect help-file))
+	(ab (get-buffer-create YaTeX-help-buffer))
+	(sw (selected-window))
+	(head (concat "^" (regexp-quote YaTeX-help-delimiter)))
+	pt command)
+    (YaTeX-showup-buffer
+     ab (function (lambda (x) (nth 3 (window-edges x)))))
+    (select-window (get-buffer-window ab))
+    (set-buffer ab)			;assertion
+    (or append (erase-buffer))
+    (set-buffer hb)
+    (goto-char (point-min))
+    (while (re-search-forward keyword nil t)
+      (setq pt (point))
+      (re-search-backward head nil t)
+      (setq command (buffer-substring (match-end 0) (point-end-of-line)))
+      (switch-to-buffer ab)
+      (goto-char (point-max))
+      (insert-char ?- (1- (window-width)))
+      (insert (format "\n<<%s>>\n" command))
+      (YaTeX-refer-help command help-file t) ;append mode
+      (set-buffer hb)
+      (goto-char pt)
+      (if (re-search-forward head nil 1)
+	  (goto-char (1- (match-beginning 0)))))
+    (select-window sw)
+    pt)
+)
+
+;;;###autoload
+(defun YaTeX-apropos (key)
+  (interactive "sLaTeX apropos (regexp): ")
+  (or (YaTeX-apropos-file key YaTeX-help-file)
+      (YaTeX-apropos-file key YaTeX-help-file-private t)
+      (message "No matches found."))
+)
+
 ;;;###autoload
 (defun YaTeX-help ()
   "Show help buffer of LaTeX/TeX commands or macros."
@@ -172,7 +282,7 @@
 		     (buffer-substring (match-beginning 2) (match-end 2))))))
        ((search-backward YaTeX-ec (point-beginning-of-line) t)
 	(goto-char (setq beg (match-end 0)))
-	(re-search-forward "\\sw+")
+	(re-search-forward YaTeX-TeX-token-regexp (point-end-of-line) t)
 	(setq end (point))
 	(if (and (<= beg p) (<= p end))
 	    (setq command (buffer-substring beg end)))))
@@ -185,12 +295,7 @@
       (setq command
 	    (completing-read
 	     "Describe (La)TeX command: "
-	     (append
-	      section-table user-section-table tmp-section-table
-	      article-table user-article-table
-	      env-table     user-env-table     tmp-env-table
-	      singlecmd-table user-singlecmd-table tmp-singlecmd-table)
-	     nil nil command))	;no-predicate, not require match
+	     YaTeX-help-entries nil nil command))
       );end excursion
     (or (YaTeX-refer-help command YaTeX-help-file)
 	(YaTeX-refer-help command YaTeX-help-file-private)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yatexlib.el	Thu Jul 07 16:37:05 1994 +0000
@@ -0,0 +1,227 @@
+;;; -*- Emacs-Lisp -*-
+;;; YaTeX library of general functions.
+;;; yatexlib.el
+;;; (c )1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
+;;; Last modified Fri Jul  8 00:44:41 1994 on figaro
+;;; $Id$
+
+;;;###autoload
+(defun YaTeX-search-active-forward (string cmntrx &optional bound err cnt func)
+  "Search STRING which is not commented out by CMNTRX.
+Optional arguments after BOUND, ERR, CNT are passed literally to search-forward
+or search-backward.
+Optional sixth argument FUNC changes search-function."
+  (let ((sfunc (if func func 'search-forward)) found md)
+    (while (and (prog1
+		    (setq found (funcall sfunc string bound err cnt))
+		  (setq md (match-data)))
+		(or
+		 (YaTeX-in-verb-p (match-beginning 0))
+		 (save-excursion
+		   (beginning-of-line)
+		   (re-search-forward cmntrx (match-beginning 0) t)))))
+    (store-match-data md)
+    found)
+)
+
+(defun YaTeX-re-search-active-forward (regexp cmntrx &optional bound err cnt)
+  "Search REGEXP backward which is not commented out by regexp CMNTRX.
+See also YaTeX-search-active-forward."
+  (YaTeX-search-active-forward regexp cmntrx bound err cnt 're-search-forward)
+)
+(defun YaTeX-search-active-backward (string cmntrx &optional bound err cnt)
+  "Search STRING backward which is not commented out by regexp CMNTRX.
+See also YaTeX-search-active-forward."
+  (YaTeX-search-active-forward string cmntrx bound err cnt 'search-backward)
+)
+(defun YaTeX-re-search-active-backward (regexp cmntrx &optional bound err cnt)
+  "Search REGEXP backward which is not commented out by regexp CMNTRX.
+See also YaTeX-search-active-forward."
+  (YaTeX-search-active-forward regexp cmntrx bound err cnt 're-search-backward)
+)
+
+
+;;;###autoload
+(defun YaTeX-switch-to-buffer (file &optional setbuf)
+  "Switch to buffer if buffer exists, find file if not.
+Optional second arg SETBUF t make use set-buffer instead of switch-to-buffer."
+  (interactive "Fswitch to file: ")
+  (let (buf)
+    (if (setq buf (get-buffer (file-name-nondirectory file)))
+	(progn
+	  (funcall (if setbuf 'set-buffer 'switch-to-buffer)
+		   (file-name-nondirectory file))
+	  buf)
+      (if (file-exists-p file)
+	  (progn (find-file file) (current-buffer))
+	(message "%s was not found in this directory." file)
+	nil)))
+)
+
+;;;###autoload
+(defun YaTeX-switch-to-buffer-other-window (file)
+  "Switch to buffer if buffer exists, find file if not."
+  (interactive "Fswitch to file: ")
+  (if (get-buffer (file-name-nondirectory file))
+      (progn (switch-to-buffer-other-window file) t)
+    (if (file-exists-p file)
+	(progn (find-file-other-window file) t)
+      (message "%s was not found in this directory." file)
+      nil))
+)
+
+(defun YaTeX-replace-format-sub (string format repl)
+  (let ((beg (or (string-match (concat "^\\(%" format "\\)") string)
+		 (string-match (concat "[^%]\\(%" format "\\)") string)))
+	(len (length format)))
+    (if (null beg) string ;no conversion
+      (concat
+       (substring string 0 (match-beginning 1)) repl
+       (substring string (match-end 1)))))
+)
+
+;;;###autoload
+(defun YaTeX-replace-format (string format repl)
+  "In STRING, replace first appearance of FORMAT to REPL as if
+function `format' does.  FORMAT does not contain `%'"
+  (let ((ans string))
+    (while (not (string=
+		 ans (setq string (YaTeX-replace-format-sub ans format repl))))
+      (setq ans string))
+    string)
+)
+
+;;;###autoload
+(defun YaTeX-replace-format-args (string &rest args)
+  "Translate the argument mark #1, #2, ... #n in the STRING into the
+corresponding real arguments ARGS."
+  (let ((argp 1))
+    (while args
+      (setq string
+	    (YaTeX-replace-format string (int-to-string argp) (car args)))
+      (setq args (cdr args) argp (1+ argp))))
+  string
+)
+
+;;;###autoload
+(defun rindex (string char)
+  (let ((pos (1- (length string)))(index -1))
+    (while (>= pos 0)
+      (cond
+       ((= (aref string pos) char)
+	(setq index pos) (setq pos -1))
+       (t (setq pos (1- pos))))
+      )
+    index)
+)
+
+;;;###autoload
+(defun YaTeX-showup-buffer (buffer &optional func select)
+  "Make BUFFER show up in certain window (but current window)
+that gives the maximum value by the FUNC.  FUNC should take an argument
+of its window object.  Non-nil for optional third argument SELECT selects
+that window."
+  (or (and (get-buffer-window buffer)
+	   (progn (if select (select-window (get-buffer-window buffer)))
+		  t))
+      (let ((window (selected-window))
+	    (wlist (YaTeX-window-list)) win w (x 0))
+	(cond
+	 ((> (length wlist) 2)
+	  (if func
+	      (while wlist
+		(setq w (car wlist))
+		(if (and (not (eq window w))
+			 (> (funcall func w) x))
+		    (setq win w x (funcall func w)))
+		(setq wlist (cdr wlist)))
+	    (setq win (get-lru-window)))
+	  (select-window win)
+	  (switch-to-buffer buffer)
+	  (or select (select-window window)))
+	 ((= (length wlist) 2)
+	  (other-window 1)
+	  (switch-to-buffer buffer)
+	  (or select (select-window window)))
+	 (t				;if one-window
+	  (cond
+	   (YaTeX-default-pop-window-height
+	    (split-window
+	     (selected-window)
+	     (max
+	      (min
+	       (- (screen-height)
+		  (if (numberp YaTeX-default-pop-window-height)
+		      (+ YaTeX-default-pop-window-height 2)
+		    (/ (* (screen-height)
+			  (string-to-int YaTeX-default-pop-window-height))
+		       100)))
+	       (- (screen-height) window-min-height 1))
+	      window-min-height))
+	    (pop-to-buffer buffer)
+	    (or select (select-window window)))
+	   (t nil)))
+	 )))
+)
+
+;;;###autoload
+(defun YaTeX-window-list ()
+  (let*((curw (selected-window)) (win curw) (wlist (list curw)))
+    (while (not (eq curw (setq win (next-window win))))
+      (or (eq win (minibuffer-window))
+	  (setq wlist (cons win wlist))))
+    wlist)
+)
+
+;;;###autoload
+(defun substitute-all-key-definition (olddef newdef keymap)
+  "Replace recursively OLDDEF with NEWDEF for any keys in KEYMAP now
+defined as OLDDEF. In other words, OLDDEF is replaced with NEWDEF
+where ever it appears."
+  (mapcar
+   (function (lambda (key) (define-key keymap key newdef)))
+   (where-is-internal olddef))
+)
+
+;;;###autoload
+(defun YaTeX-match-string (n &optional m)
+  "Return (buffer-substring (match-beginning n) (match-beginning m))."
+  (if (match-beginning n)
+      (buffer-substring (match-beginning n)
+			(match-end (if m m n))))
+)
+
+;;;###autoload
+(defun YaTeX-minibuffer-complete ()
+  "Complete in minibuffer"
+  (interactive)
+  (let (beg word compl)
+    (setq beg (if (and (boundp 'delim) delim)
+		  (save-excursion
+		    (skip-chars-backward (concat "^" delim))
+		    (1- (point)))
+		(point-min))
+	  word (buffer-substring beg (point-max))
+	  compl (try-completion word minibuffer-completion-table))
+    (cond
+     ((eq compl t) nil)
+     ((eq compl nil)
+      (ding)
+      (save-excursion
+	(let (p)
+	  (goto-char (setq p (point-max)))
+	  (insert " [No match]")
+	  (goto-char p)
+	  (sit-for 2)
+	  (delete-region p (point-max)))))
+     ((string= compl word)
+      (with-output-to-temp-buffer "*Completions*"
+	(display-completion-list
+	 (all-completions word minibuffer-completion-table))))
+     (t (delete-region beg (point-max))
+	(insert compl))
+     ))
+)
+
+
+(provide 'yatexlib)
--- a/yatexmth.el	Thu Jul 07 16:37:05 1994 +0000
+++ b/yatexmth.el	Thu Jul 07 16:37:05 1994 +0000
@@ -1,18 +1,18 @@
 ;;; -*- Emacs-Lisp -*-
-;;; YaTeX interface for math-mode.
+;;; YaTeX math-mode-specific functions.
 ;;; yatexmth.el rev.2
 ;;; (c )1993-1994 by HIROSE Yuuji [yuuji@ae.keio.ac.jp]
-;;; Last modified Sat Apr 23 02:26:57 1994 on pajero
+;;; Last modified Fri Jul  8 00:48:24 1994 on figaro
 ;;; $Id$
 
 ;;; [Customization guide]
 ;;;
 ;;;	  By default,  you can use two  completion  groups in YaTeX math
-;;;	mode, `,' for mathematical signs and `/' for greek letters.  But
+;;;	mode, `;' for mathematical signs and `/' for greek letters.  But
 ;;;	you  can add other completion groups   by defining the  alist of
 ;;;	`prefix  key'    vs   `completion   list'    into  the  variable
 ;;;	YaTeX-math-key-list-private.  If  you wish  to    accomplish the
-;;;	completion as follows(prefix key is `;'):
+;;;	completion as follows(prefix key is `,'):
 ;;;
 ;;;		KEY		COMPLETION
 ;;;		s		\sin
@@ -24,7 +24,7 @@
 ;;;		l		\log
 ;;;		hs		\sinh
 ;;;
-;;;	Typing `s' after `;' makes `\sin', `hs' after `;' makes `\sinh'
+;;;	Typing `s' after `,' makes `\sin', `hs' after `,' makes `\sinh'
 ;;;	and so on.  First, you have to define list of key-completion
 ;;;	pairs.  Variable name(YaTeX-math-funcs-list) is arbitrary.
 ;;;
@@ -38,21 +38,21 @@
 ;;;	above) into the variable YaTeX-math-key-list-private.
 ;;;
 ;;;		(setq YaTeX-math-key-list-private
-;;;		      '((";" . YaTeX-math-funcs-list)
+;;;		      '(("," . YaTeX-math-funcs-list)
 ;;;			("'" . Other-List-if-any)))
 ;;;
 ;;;	  Put these expressions into your ~/.emacs, and you can use this
 ;;;	completion in the YaTeX-math-mode.
 ;;;
 ;;;	  And you can add your favorite completion sequences to the
-;;;	default completion list invoked with `,', by defining those lists
+;;;	default completion list invoked with `;', by defining those lists
 ;;;	into variable YaTeX-math-sign-alist-private.
 
 ;;; 【イメージ補完の追加方法】
 ;;;
-;;;	  標準のイメージ補完では、「,」で始まる数式記号補完と、「/」で始
+;;;	  標準のイメージ補完では、「;」で始まる数式記号補完と、「/」で始
 ;;;	まるギリシャ文字補完が使用可能ですが、これ以外の文字で始まる補完
-;;;	シリーズも定義することができます。例えば、「;」で始まる次のよう
+;;;	シリーズも定義することができます。例えば、「,」で始まる次のよう
 ;;;	な補完シリーズを定義する場合を考えてみます。
 ;;;
 ;;;		補完キー	補完結果
@@ -65,7 +65,7 @@
 ;;;		l		\log
 ;;;		hs		\sinh
 ;;;
-;;;	「;」のあとに s を押すと \sin が、hs を押すと \sinh が入力されま
+;;;	「,」のあとに s を押すと \sin が、hs を押すと \sinh が入力されま
 ;;;	す。このような補完リストの登録は以下のようにします(変数名は任意)。
 ;;;
 ;;;		(setq YaTeX-math-funcs-list
@@ -74,11 +74,11 @@
 ;;;				:
 ;;;			("hs"	"sinh")))
 ;;;
-;;;	さらに、「;」を押した時にイメージ補完が始まるよう次の変数に、起動キー
+;;;	さらに、「,」を押した時にイメージ補完が始まるよう次の変数に、起動キー
 ;;;	と上で定義した補完用変数の登録を行ないます。
 ;;;
 ;;;		(setq YaTeX-math-key-list-private
-;;;		      '((";" . YaTeX-math-funcs-list)
+;;;		      '(("," . YaTeX-math-funcs-list)
 ;;;			("'" . ほかに定義したいシリーズがあれば…)))
 ;;;
 ;;;	これらを ~/.emacs に書いておけば、野鳥の math-mode で自分専用の
@@ -106,6 +106,7 @@
 (YaTeX-setq-math-sym YaTeX-image-bot		"|\n ̄"	"⊥")
 (YaTeX-setq-math-sym YaTeX-image-neg		"イ"		"¬")
 (YaTeX-setq-math-sym YaTeX-image-flat		"b"		"♭")
+(YaTeX-setq-math-sym YaTeX-image-sqrt		""		"√")
 
 (setq
  YaTeX-math-sign-alist-default
@@ -116,6 +117,8 @@
    ("sigma"	"sum"		("\\-+\n >\n/-+" "Σ"))
    ("integral"	"int"		(" /\\\n \\\n\\/" YaTeX-image-int))
    ("ointegral"	"oint"		" /\\\n(\\)\n\\/")
+   ("sqrt"	"sqrt"		("  __\n,/" YaTeX-image-sqrt))
+   ("root"	"sqrt"		("  __\n,/" YaTeX-image-sqrt))
    ("A"		"forall"	"|_|\nV")
    ("E"		"exists"	"-+\n-+\n-+")
    ("!"		"neg"		("--+\n  |" YaTeX-image-neg))
@@ -127,6 +130,7 @@
    ("-+"	"mp"		"-\n+")
    ("x"		"times"		("x" "×"))
    ("/"		"div"		(",\n-\n'" "÷"))
+   ("f"		"frac"		"xxx\n---\nyyy" "÷")
    ("*"		"ast"		"*")
    ("#"		"star"		("_/\\_\n\\  /\n//\\\\" "★"))
    ("o"		"circ"		"o")
@@ -366,18 +370,6 @@
   (define-key YaTeX-math-menu-map "\^m"	'exit-recursive-edit)
   (define-key YaTeX-math-menu-map "q"	'abort-recursive-edit))
 
-(defvar YaTeX-math-key-list-default
-  '(("," . YaTeX-math-sign-alist)
-    ("/" . YaTeX-greek-key-alist))
-  "Default key sequence to invoke math-mode's image completion."
-)
-(defvar YaTeX-math-key-list-private nil
-  "*User defined alist, math-mode-prefix vs completion alist"
-)
-(defvar YaTeX-math-key-list
-  (append YaTeX-math-key-list-private YaTeX-math-key-list-default)
-  "Key sequence to invoke math-mode's image completion."
-)
 (defvar YaTeX-math-exit-key "\e"
   "*Key sequence after prefix key of YaTeX-math-mode to exit from math-mode."
 )
@@ -390,43 +382,30 @@
 ;;;
 ;;YaTeX math-mode functions
 ;;;
-;##autoload from yatex.el
+;;;###autoload from yatex.el
 (defun YaTeX-toggle-math-mode (&optional arg)
   (interactive "P")
-  (require 'yatexmth)
   (or (memq 'YaTeX-math-mode mode-line-format) nil
       (setq mode-line-format
 	    (append (list "" 'YaTeX-math-mode) mode-line-format)))
-  (if (or arg (null YaTeX-math-mode))
-      (let ((keys ""))
-	(setq YaTeX-math-mode "math:")
-	(mapcar
-	 (function (lambda (x)
-		     (let ((key (car x)) (list (cdr x)))
-		       (setq keys (concat keys " " key))
-		       (put 'YaTeX-math-key-list list (key-binding key))
-		       (define-key YaTeX-mode-map key
-			 'YaTeX-math-insert-sequence))))
-	 YaTeX-math-key-list)
-	(message "Turn on math mode. Prefix keys are %s" keys)
-	(sit-for 3)
-	(message
-	 (concat "To exit from math-mode, type `ESC' after prefix, "
-		 "or type `"
-		 (key-description
-		  (car
-		   (where-is-internal 'YaTeX-switch-mode-menu YaTeX-mode-map)))
-		 " $'")))
-    (setq YaTeX-math-mode nil)
-    (mapcar
-     (function (lambda (x)
-		 (let ((key (car x)) (list (cdr x)))
-		   (define-key YaTeX-mode-map key
-		     (get 'YaTeX-math-key-list list)))))
-     YaTeX-math-key-list)
-    (setq YaTeX-math-mode nil)
-    (message "Exit from math mode."))
-  (set-buffer-modified-p (buffer-modified-p))
+  (if YaTeX-auto-math-mode nil		;Only effective on manual mode.
+    (if (or arg (null YaTeX-math-mode))
+	(let (keys)
+	  (setq YaTeX-math-mode "math:")
+	  (message "Turn on math mode. Prefix keys are %s"
+		   (mapconcat 'car YaTeX-math-key-list " "))
+	  (sit-for 3)
+	  (message
+	   (concat "To exit from math-mode, type `ESC' after prefix, "
+		   "or type `"
+		   (key-description
+		    (car
+		     (where-is-internal
+		      'YaTeX-switch-mode-menu YaTeX-mode-map)))
+		   " $'")))
+      (setq YaTeX-math-mode nil)
+      (message "Exit from math mode."))
+    (set-buffer-modified-p (buffer-modified-p)))
 )
 
 (defun YaTeX-math-forward (arg)
@@ -455,6 +434,47 @@
   (YaTeX-math-gets (car (cdr-safe (cdr-safe list))))
 )
 
+(defun YaTeX-in-math-mode-p ()
+  "If current position is supposed to be in LaTeX-math-mode, return t."
+  (or (YaTeX-quick-in-environment-p
+       '("math" "eqnarray" "equation" "eqnarray*" "displaymath"))
+      (let ((p (point)) (nest 0) me0
+	    (boundary
+	     (save-excursion
+	       (if (looking-at YaTeX-paragraph-delimiter)
+		   (goto-char (max (point-min) (1- (point)))))
+	       (re-search-backward YaTeX-paragraph-delimiter nil 1)
+	       (point))))
+	(save-excursion
+	  (cond
+	   ((catch 'open
+	      (save-excursion
+		(while (and (>= nest 0)
+			    (re-search-backward
+			     (concat YaTeX-ec-regexp	;\
+				     "\\([()]\\|[][]\\)") boundary t))
+		  (setq me0 (match-end 0))
+		  (if (or (YaTeX-on-comment-p)
+			  (YaTeX-quick-in-environment-p "verbatim")) nil
+		    (if (or (= (char-after (1- me0)) ?\))
+			    (= (char-after (1- me0)) ?\]))
+			(setq nest (1+ nest))
+		      (setq nest (1- nest)))))
+		(if (< nest 0) (throw 'open t))))
+	    t)
+	   (t (catch 'dollar
+		(while (search-backward "$" boundary t)
+		  (cond
+		   ((equal (char-after (1- (point))) ?$) ; $$ equation $$
+		    (backward-char 1)
+		    (setq nest (1+ nest)))
+		   ((and (equal (char-after (1- (point))) ?\\ )
+			 (not (equal (char-after (- (point) 3)) ?\\ )))
+		    nil)		;\$
+		   (t (setq nest (1+ nest)))))
+		(if (= (% nest 2) 1) (throw 'dollar t))))))))
+)
+
 (defun YaTeX-math-display-list (list cols)
   (goto-char (point-max))
   (if (= cols 0) (if (not (eolp)) (newline 1))
@@ -551,8 +571,9 @@
 	  (setq buffer-file-name name)
 	  (set-buffer-modified-p modified)))))
 
-(defun YaTeX-math-insert-sequence ()
-  (interactive)
+(defun YaTeX-math-insert-sequence (&optional force)
+  "Insert math-mode sequence with image completion."
+  (interactive "P")
   (let*((key "") regkey str  last-char list i
 	(case-fold-search nil) match sign
 	(this-key (char-to-string last-command-char))
@@ -560,8 +581,12 @@
 	(n (length alist)) (beg (point)) result)
     (setq result
 	  (catch 'complete
+	    (if (and (not force)
+		     (or (and (not YaTeX-auto-math-mode) (not YaTeX-math-mode))
+			 (not (YaTeX-in-math-mode-p))))
+		(throw 'complete 'escape));this tag should be exit, but...
 	    (while t
-	      (message "Sequence: %s" key)
+	      (message "Sequence(TAB for menu): %s" key)
 	      (setq last-char (read-char)
 		    key (concat key (char-to-string last-char))
 		    i 0)
@@ -570,20 +595,24 @@
 		(throw 'complete 'escape))
 	       ((string= key YaTeX-math-exit-key)	;;exit from math-mode
 		(throw 'complete 'exit))
-	       ((string-match "[\C-g\C-c]" key) (throw 'complete 'abort))
-	       ((string-match "[\n\r]" key) (throw 'complete 'menu))
-	       ((string-match "[\C-h\C-?]" key)
-		(if (string= key "") (throw 'complete 'abort))
+	       ((string-match "\r" key)			;;RET = kakutei
+		(throw 'complete 'select))
+	       ((string-match "[\C-g\C-c]" key)		;;C-g = abort
+		(throw 'complete 'abort))
+	       ((string-match "[\t\n]" key)		;;TAB, LFD = menu
+		(throw 'complete 'menu))
+	       ((string-match "[\C-h\C-?]" key)		;;BS, DEL = BS
+		(if (< (length key) 2) (throw 'complete 'abort))
 		(setq key (substring key 0 -2))))
 	      
 	      (setq regkey (concat "^" (regexp-quote key)))
-	      (message "Sequence: %s" key)
+	      (message "Sequence(TAB for menu): %s" key)
 	      (if
 		  (catch 'found
 		    ;;(1)input string strictly matches with alist
-		    (setq single-command (car (cdr match))
-			  ;;remember previous match
-			  match (assoc key alist))
+		    (setq match (assoc key alist))
+		    ;;remember previous match
+
 		    ;;(2)search partial match into alist
 		    (setq list alist)
 		    (while (< i n)
@@ -591,8 +620,7 @@
 			   regkey
 			   ;;(aref array i)
 			   ;;(car (nth i alist))
-			   (car (car list))
-			   )
+			   (car (car list)))
 			  (progn
 			    (or match
 				;;(setq match (nth i alist))
@@ -602,11 +630,12 @@
 		  nil ;;if any match, continue reading
 		;;else reading of sequence has been done.
 		(message "complete.")
-		(throw 'complete t)
-		)
+		(throw 'complete t))
+
 	      (if match
 		  (progn (delete-region beg (point))
-			 (insert YaTeX-ec (car (cdr match)))
+			 (setq single-command (car (cdr match)))
+			 (insert YaTeX-ec single-command)
 			 (if (and YaTeX-math-need-image
 				  (setq sign (YaTeX-math-get-sign match)))
 			     (YaTeX-math-show-image (concat sign "\n")))
@@ -616,12 +645,7 @@
     (cond
      ((eq result t)
       (setq YaTeX-current-completion-type 'maketitle)
-      (if t nil
-	(delete-region beg (point))
-	(setq single-command (car (cdr match)))
-	;;(recursive-edit)
-	(insert YaTeX-ec single-command)
-	)
+
       ;;;(sit-for 1)
       (setq unread-command-char last-char)
       (insert (YaTeX-addin single-command)))
@@ -631,6 +655,8 @@
      ((eq result 'escape)
       (delete-region beg (point))
       (insert this-key))
+     ((eq result 'select)
+      (message "Done."))
      ((eq result 'exit)
       (delete-region beg (point))
       (YaTeX-toggle-math-mode))
--- a/yatexprc.el	Thu Jul 07 16:37:05 1994 +0000
+++ b/yatexprc.el	Thu Jul 07 16:37:05 1994 +0000
@@ -2,7 +2,7 @@
 ;;; YaTeX process handler.
 ;;; yatexprc.el
 ;;; (c )1993-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
-;;; Last modified Fri May 13 01:22:54 1994 on 98fa
+;;; Last modified Fri Jul  1 02:44:32 1994 on figaro
 ;;; $Id$
 
 (require 'yatex)
@@ -44,7 +44,7 @@
     (with-output-to-temp-buffer buffer
       (if YaTeX-dos			;if MS-DOS
 	  (progn
-	    (message (concat "Typesetting " (buffer-name) "..."))
+	    (message (format "Calling `%s'..." command))
 	    (YaTeX-put-nonstopmode)
 	    (call-process shell-file-name
 			  nil buffer nil "/c" command)
@@ -64,10 +64,9 @@
 		YaTeX-latex-message-code YaTeX-coding-system))
 	      ((boundp 'NEMACS)
 	       (set-kanji-process-code YaTeX-latex-message-code))))
-    (message "Type SPC to continue.")
     (goto-char (point-max))
     (if YaTeX-dos (message "Done.")
-      (insert (message " "))
+      (insert " ")
       (set-marker (process-mark YaTeX-typeset-process) (1- (point))))
     (if (bolp) (forward-line -1))
     (recenter -1)
@@ -80,16 +79,19 @@
          (set-process-buffer proc nil))
         ((memq (process-status proc) '(signal exit))
          (let* ((obuf (current-buffer)) (pbuf (process-buffer proc))
+		(pwin (get-buffer-window pbuf))
 		(owin (selected-window)) win)
            ;; save-excursion isn't the right thing if
            ;;  process-buffer is current-buffer
            (unwind-protect
                (progn
                  ;; Write something in *typesetting* and hack its mode line
-		 (YaTeX-pop-to-buffer pbuf)
-		 (set-buffer (process-buffer proc))
+		 (if pwin
+		     (select-window pwin)
+		   (set-buffer pbuf))
+		 ;;(YaTeX-showup-buffer pbuf nil t)
                  (goto-char (point-max))
-		 (recenter -3)
+		 (if pwin (recenter -3))
                  (insert ?\n "latex typesetting " mes)
                  (forward-char -1)
                  (insert " at " (substring (current-time-string) 0 -5) "\n")
@@ -132,19 +134,34 @@
     (let*
 	((end "") typeout ;Type out message that tells the method of cutting.
 	 (cmd (concat (YaTeX-get-latex-command nil) " " YaTeX-texput-file))
-	 (buffer (current-buffer)) opoint preamble main
+	 (buffer (current-buffer)) opoint preamble (subpreamble "") main
 	 reg-begin reg-end)
-      
-      (if (re-search-backward "%#BEGIN" nil t)
+
+      (if (search-backward "%#BEGIN" nil t)
 	  (progn
-	    (setq typeout "--- Region from BEGIN to " end "END ---"
+	    (setq typeout "--- Region from BEGIN to "
+		  end "the end of the buffer ---"
 		  reg-begin (match-end 0))
-	    (if (re-search-forward "%#END" nil t)
+	    (if (search-forward "%#END" nil t)
 		(setq reg-end (match-beginning 0)
-		      end "end of buffer ---")
+		      end "END ---")
 	      (setq reg-end (point-max))))
 	(setq typeout "=== Region from (point) to (mark) ===")
 	(setq reg-begin (point) reg-end (mark)))
+      (goto-char (point-min))
+      (while (search-forward "%#REQUIRE" nil t)
+	(setq subpreamble
+	      (concat subpreamble
+		      (cond
+		       ((eolp)
+			(buffer-substring
+			 (match-beginning 0)
+			 (point-beginning-of-line)))
+		       (t (buffer-substring
+			   (match-end 0)
+			   (point-end-of-line))))
+		      "\n"))
+	(goto-char (match-end 0)))
       (YaTeX-visit-main t)
       (setq main (current-buffer))
       (setq opoint (point))
@@ -162,7 +179,7 @@
       (erase-buffer)
       (if YaTeX-need-nonstop
 	  (insert "\\nonstopmode{}\n"))
-      (insert preamble "\n")
+      (insert preamble "\n" subpreamble "\n")
       (insert-buffer-substring buffer reg-begin reg-end)
       (insert "\\typeout{" typeout end "}\n") ;Notice the selected method.
       (insert "\n\\end{document}\n")
@@ -261,6 +278,8 @@
 (defun YaTeX-system (command buffer)
   "Execute some command on buffer.  Not a official function."
   (save-excursion
+    (YaTeX-showup-buffer
+     buffer (function (lambda (x) (nth 3 (window-edges x)))))
     (with-output-to-temp-buffer buffer
       (if YaTeX-dos
 	  (call-process shell-file-name nil buffer nil "/c " command)
@@ -286,20 +305,24 @@
 				  0 (rindex YaTeX-texput-file ?.))
 		     (YaTeX-get-preview-file-name))
 		   ))))
-  (setq dvi2-command preview-command)
+  (setq dvi2-command preview-command)	;`dvi2command' is buffer local
   (save-excursion
     (YaTeX-visit-main t)
-    (with-output-to-temp-buffer "*dvi-preview*"
-      (if YaTeX-dos			;if MS-DOS
-	  (progn (send-string-to-terminal "\e[2J\e[>5h") ;CLS & hide cursor
-		 (call-process shell-file-name "con" "*dvi-preview*" nil
-			       "/c " dvi2-command preview-file)
-		 (send-string-to-terminal "\e[>5l") ;show cursor
-		 (redraw-display))
-	(start-process "preview" "*dvi-preview*" shell-file-name "-c"
-		       (concat dvi2-command " " preview-file)) ;if UNIX
-	(message
-	 (concat "Starting " dvi2-command " to preview " preview-file)))))
+    (let ((pbuffer "*dvi-preview*"))
+      (YaTeX-showup-buffer
+       pbuffer (function (x) (nth 3 (window-edges x))))
+      (with-output-to-temp-buffer pbuffer
+	(if YaTeX-dos			;if MS-DOS
+	    (progn (send-string-to-terminal "\e[2J\e[>5h") ;CLS & hide cursor
+		   (call-process shell-file-name "con" "*dvi-preview*" nil
+				 "/c " preview-command preview-file)
+		   (send-string-to-terminal "\e[>5l") ;show cursor
+		   (redraw-display))
+	  (start-process "preview" "*dvi-preview*" shell-file-name "-c"
+			 (concat preview-command " " preview-file)) ;if UNIX
+	  (message
+	   (concat "Starting " preview-command
+		   " to preview " preview-file))))))
 )
 
 (defun YaTeX-prev-error ()
@@ -311,7 +334,7 @@
 	error-line typeset-win error-buffer error-win)
     (if (null (get-buffer YaTeX-typeset-buffer))
 	(error "There is no typesetting buffer."))
-    (YaTeX-pop-to-buffer YaTeX-typeset-buffer)
+    (YaTeX-showup-buffer YaTeX-typeset-buffer nil t)
     (setq typeset-win (selected-window))
     (if (re-search-backward
 	 (concat "\\(" latex-error-regexp "\\)\\|\\("
@@ -397,8 +420,9 @@
   (if (null (get-buffer YaTeX-typeset-buffer))
       (message "No typeset buffer found.")
     (let ((win (selected-window)))
-      (YaTeX-pop-to-buffer YaTeX-typeset-buffer)
+      (YaTeX-showup-buffer YaTeX-typeset-buffer nil t)
       (goto-char (point-max))
+      (forward-line -1)
       (recenter -1)
       (select-window win)))
 )
@@ -504,7 +528,8 @@
   "Print out.  If prefix arg ARG is non nil, call print driver without
 page range description."
   (interactive "P")
-  (let*(from to (cmd (or (YaTeX-get-builtin "LPR") dviprint-command-format)))
+  (let*((cmd (or (YaTeX-get-builtin "LPR") dviprint-command-format))
+	from to (lbuffer "*dvi-printing*"))
     (setq
      cmd 
      (YaTeX-replace-format
@@ -534,7 +559,9 @@
 			 (format cmd (YaTeX-get-preview-file-name)))))
     (save-excursion
       (YaTeX-visit-main t) ;;change execution directory
-      (with-output-to-temp-buffer "*dvi-printing*"
+      (YaTeX-showup-buffer
+       lbuffer (function (lambda (x) (nth 3 (window-edges x)))))
+      (with-output-to-temp-buffer lbuffer
 	(if YaTeX-dos
 	    (call-process shell-file-name "con" "*dvi-printing*" nil
 			  "/c " cmd)
@@ -565,7 +592,8 @@
     (if (setq b-in (YaTeX-get-builtin "!"))
 	(setq main-file (YaTeX-guess-parent b-in)))
     (if YaTeX-parent-file
-	(setq main-file (get-file-buffer YaTeX-parent-file)))
+	(setq main-file ;;(get-file-buffer YaTeX-parent-file)
+	      YaTeX-parent-file))
     (if (YaTeX-main-file-p)
 	(if (interactive-p) (message "I think this is main LaTeX source.") nil)
       (cond
@@ -632,47 +660,4 @@
 	    (buffer-list)))
 )
 
-(defun YaTeX-pop-to-buffer (buffer &optional win)
-  (if (setq win (get-buffer-window buffer))
-      (select-window win)
-    (pop-to-buffer buffer))
-)
-
-(defun YaTeX-showup-buffer (buffer &optional func select)
-  "Make BUFFER show up in certain window (but current window)
-that gives the maximum value by the FUNC.  FUNC should take an argument
-of its window object.  Non-nil for optional third argument SELECT selects
-that window."
-  (or (and (get-buffer-window buffer)
-	   (progn (if select (select-window (get-buffer-window buffer)))
-		  t))
-      (cond
-       ((> (length (YaTeX-window-list)) 2)
-	(let ((window (selected-window))
-	      (list (YaTeX-window-list)) win w (x 0))
-	  (if func
-	      (while list
-		(setq w (car list))
-		(if (and (not (eq window w))
-			 (> (funcall func w) x))
-		    (setq win w x (funcall func w)))
-		(setq list (cdr list)))
-	    (setq win (get-lru-window)))
-	  (select-window win)
-	  (switch-to-buffer buffer)
-	  (or select (select-window window))))
-       ((= (length (YaTeX-window-list)) 2)
-	(let ((window (selected-window)))
-	  (other-window 1)
-	  (switch-to-buffer buffer)
-	  (or select (select-window window))))
-       (t nil)))
-)
-
-(defun YaTeX-window-list ()
-  (let*((curw (selected-window)) (win curw) (wlist (list curw)))
-    (while (not (eq curw (setq win (next-window win))))
-      (setq wlist (cons win wlist)))
-    wlist)
-)
 (provide 'yatexprc)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yatexsec.el	Thu Jul 07 16:37:05 1994 +0000
@@ -0,0 +1,281 @@
+;;; -*- Emacs-Lisp -*-
+;;; YaTeX sectioning browser.
+;;; yatexsec.el
+;;; (c ) 1994 by HIROSE Yuuji [yuuji@ae.keio.ac.jp]
+;;; Last modified Thu Jul  7 01:26:26 1994 on 98fa
+;;; $Id$
+
+(defvar YaTeX-sectioning-level
+  '(("part" . 0) ("chapter" . 1) ("section" . 2) ("subsection" . 3)
+    ("subsubsection" . 4) ("paragraph" . 5) ("subparagraph" . 6))
+  "Sectioning level.")
+
+(defun YaTeX-sectioning-map-hide (map)
+  (let ((ch ?0))
+    (while (<= ch ?9)
+      (define-key map (char-to-string ch) 'YaTeX-sectioning-hide)
+      (setq ch (1+ ch))))
+)
+
+(defvar YaTeX-minibuffer-sectioning-map nil
+  "Key map used in minibuffer for sectioning.")
+(if YaTeX-minibuffer-sectioning-map nil
+  (setq YaTeX-minibuffer-sectioning-map
+	(copy-keymap minibuffer-local-completion-map))
+  (define-key YaTeX-minibuffer-sectioning-map "\C-p"
+    'YaTeX-sectioning-up)
+  (define-key YaTeX-minibuffer-sectioning-map "\C-e"
+    'YaTeX-sectioning-up)
+  (define-key YaTeX-minibuffer-sectioning-map "\C-i"
+    'YaTeX-minibuffer-complete)
+  (define-key YaTeX-minibuffer-sectioning-map " "
+    'YaTeX-minibuffer-complete)
+  (define-key YaTeX-minibuffer-sectioning-map "\C-n"
+    'YaTeX-sectioning-down)
+  (define-key YaTeX-minibuffer-sectioning-map "\C-x"
+    'YaTeX-sectioning-down)
+  (define-key YaTeX-minibuffer-sectioning-map "\C-v"
+    'YaTeX-sectioning-scroll-up)
+  (define-key YaTeX-minibuffer-sectioning-map "\C-c"
+    'YaTeX-sectioning-scroll-up)
+  (define-key YaTeX-minibuffer-sectioning-map "\M-v"
+    'YaTeX-sectioning-scroll-down)
+  (define-key YaTeX-minibuffer-sectioning-map "\C-r"
+    'YaTeX-sectioning-scroll-down)
+  (define-key YaTeX-minibuffer-sectioning-map "\C-w"
+    '(lambda () (interactive) (YaTeX-sectioning-scroll-down 1)))
+  (define-key YaTeX-minibuffer-sectioning-map "\C-z"
+    '(lambda () (interactive) (YaTeX-sectioning-scroll-up 1)))
+  (define-key YaTeX-minibuffer-sectioning-map "\C-l"
+    'YaTeX-sectioning-recenter)
+  (define-key YaTeX-minibuffer-sectioning-map "?"
+    'YaTeX-sectioning-help)
+  (YaTeX-sectioning-map-hide YaTeX-minibuffer-sectioning-map)
+)
+
+(defvar YaTeX-sectioning-buffer-map nil
+  "Key map used in YaTeX-sectioning-buffer.")
+(if YaTeX-sectioning-buffer-map nil
+  (setq YaTeX-sectioning-buffer-map (make-sparse-keymap))
+  (define-key YaTeX-sectioning-buffer-map " "
+    'YaTeX-sectioning-buffer-jump)
+  (define-key YaTeX-sectioning-buffer-map (concat YaTeX-prefix "\C-c")
+    'YaTeX-sectioning-buffer-jump)
+  (YaTeX-sectioning-map-hide YaTeX-sectioning-buffer-map)
+)
+
+(defvar YaTeX-sectioning-buffer-parent nil)
+(defun YaTeX-sectioning-buffer-jump ()
+  (interactive)
+  (if (and YaTeX-sectioning-buffer-parent
+	   (get-buffer YaTeX-sectioning-buffer-parent))
+      (let (ptn)
+	(beginning-of-line)
+	(if (re-search-forward YaTeX-sectioning-regexp)
+	    (progn (setq ptn (buffer-substring
+			      (1- (match-beginning 0))
+			      (progn (skip-chars-forward "^}") (1+ (point)))))
+		   (YaTeX-showup-buffer YaTeX-sectioning-buffer-parent nil t)
+		   (goto-char (point-max))
+		   (search-backward ptn))
+	  (message "No line number expression."))))
+)
+
+(defun YaTeX-sectioning-hide-under (n)
+  "Hide sectioning commands under level N."
+  (let ((cw (selected-window)))
+    (YaTeX-showup-buffer YaTeX-sectioning-buffer nil t)
+    (if (>= n (1- (length YaTeX-sectioning-level)))
+	(progn
+	  (set-selective-display nil)
+	  (message "Show all."))
+      (set-selective-display (1+ n))
+      (if (nth n YaTeX-sectioning-level)
+	  (message "Hide lower than %s" (car (nth n YaTeX-sectioning-level)))
+	(message "")))
+    (if (numberp selective-display)
+	(setq mode-name (format "level %d" (1- selective-display)))
+      (setq mode-name (format "all")))
+    (select-window cw))
+)
+(defun YaTeX-sectioning-hide ()
+  "Call YaTeX-sectioning-hide-under with argument according to pressed key."
+  (interactive)
+  (YaTeX-sectioning-hide-under (- last-command-char ?0)))
+
+(defun YaTeX-sectioning-help ()
+  "Show help of sectioning."
+  (interactive)
+  (let ((cw (selected-window)) sb (hb (get-buffer-create "*Help*")))
+    (unwind-protect
+	(progn
+	  (other-window 1)
+	  (setq sb (current-buffer))
+	  (switch-to-buffer hb)
+	  (erase-buffer)
+	  (insert "===== View sectioning =====
+C-p	Up sectioning level.			0	Show only \\part, 
+C-n	Down sectioning level.			1	 and \\chapter,
+C-v	Scroll up *Sectioning line* buffer.	2	 and \\section,
+M-v	Scroll down *Sectioning line* buffer.	3	 and \\subsection,
+SPC	Complete word.				4	 and \\subsubsection,
+TAB	Complete word.				5	 and \\paragraph.
+C-l	Recenter recent line.			6	Show all.
+RET	Select.
+==== End of HELP =====
+")
+	  (set-buffer-modified-p nil)
+	  (goto-char (point-min))
+	  (momentary-string-display "" (point-min)))
+      (bury-buffer hb)
+      (switch-to-buffer sb)
+      (select-window cw)))
+)
+
+(defun YaTeX-sectioning-up (n)
+  "Up section level.
+Refers the YaTeX-read-section-in-minibuffer's local variable minibuffer-start."
+  (interactive "p")
+  (if (eq (selected-window) (minibuffer-window))
+      (let*((command (buffer-string))
+	    (alist YaTeX-sectioning-level)
+	    (level (cdr-safe (assoc command alist))))
+	(or level (error "No such sectioning command."))
+	(setq level (- level n))
+	(if (or (< level 0) (>= level (length alist)))
+	    (ding)
+	  (erase-buffer)
+	  (insert (car (nth level alist))))
+    ))
+)
+
+(defun YaTeX-sectioning-down (n)
+  "Down section level."
+  (interactive "p")
+  (YaTeX-sectioning-up (- n))
+)
+
+(defun YaTeX-sectioning-scroll-up (n)
+  (interactive "P")
+  (let ((section-buffer YaTeX-sectioning-buffer)
+	(cw (selected-window)))
+    (YaTeX-showup-buffer section-buffer nil t)
+    (unwind-protect
+	(scroll-up (or n (- (window-height) 2)))
+      (select-window cw)))
+)
+
+(defun YaTeX-sectioning-scroll-down (n)
+  (interactive "P")
+  (let ((section-buffer YaTeX-sectioning-buffer)
+	(cw (selected-window)))
+    (YaTeX-showup-buffer section-buffer nil t)
+    (unwind-protect
+	(scroll-down (or n (- (window-height) 2)))
+      (select-window cw)))
+)
+
+(defun YaTeX-sectioning-recenter (arg)
+  "Recenter `<<--' line"
+  (interactive "P")
+  (let ((cw (selected-window)))
+    (unwind-protect
+	(progn
+	  (YaTeX-showup-buffer YaTeX-sectioning-buffer nil t)
+	  (or (search-forward "<<--" nil t)
+	      (search-backward "<<--" nil t))
+	  (recenter (or arg (/ (window-height) 2))))
+      (select-window cw)))
+)
+
+(defvar YaTeX-sectioning-minibuffer " *sectioning*"
+  "Miniuffer used for sectioning")
+(defun YaTeX-read-section-in-minibuffer (prompt table &optional default delim)
+  (interactive)
+  (let ((minibuffer-completion-table table))
+    (read-from-minibuffer
+     prompt default YaTeX-minibuffer-sectioning-map))
+)
+
+(defun YaTeX-get-sectioning-level ()
+  "Get section-level on the cursor."
+   (cdr-safe (assoc (buffer-substring
+		     (point)
+		     (progn (skip-chars-forward "a-z") (point)))
+		     YaTeX-sectioning-level))
+)
+
+(defvar YaTeX-sectioning-buffer "*Sectioning lines*")
+(defun YaTeX-colloect-sections ()
+  "Collect all the lines which contains sectioning command."
+  (let ((cw (selected-window)) level indent begp (prevp 1) (prevl 1)
+	(pattern (concat YaTeX-ec-regexp
+			 "\\(" YaTeX-sectioning-regexp "\\)\\*?{"))
+	(cb (current-buffer)))
+    (save-excursion
+      (YaTeX-showup-buffer YaTeX-sectioning-buffer) ;show buffer
+      (goto-char (point-min))
+      (with-output-to-temp-buffer YaTeX-sectioning-buffer
+	(while (re-search-forward pattern nil t)
+	  (goto-char (1+ (match-beginning 0)))
+	  (setq level (YaTeX-get-sectioning-level)
+		begp (match-beginning 0))
+	  ;;(beginning-of-line)
+	  ;;(skip-chars-forward " \t")
+	  (setq indent (format "%%%ds" level))
+	  (princ (format indent ""))
+	  (if (YaTeX-on-comment-p) (princ "%"))
+	  (princ (buffer-substring begp (progn (forward-list 1) (point))))
+	  (setq prevl (+ prevl (count-lines prevp (point)) -1)
+		prevp (point))
+	  (princ (format " (line:%d)" prevl))
+	  (princ "\n")))
+      (set-buffer YaTeX-sectioning-buffer)
+      (make-local-variable 'YaTeX-sectioning-buffer-parent)
+      (use-local-map YaTeX-sectioning-buffer-map)
+      (setq YaTeX-sectioning-buffer-parent cb)
+      (if (numberp selective-display)
+	  (setq mode-name (format "level %d" (1- selective-display))))
+      YaTeX-sectioning-buffer))
+)
+
+(defun YaTeX-section-overview ()
+  "Show section overview.  Return the nearest sectioning command."
+  (interactive)
+  (let ((cw (selected-window)) (ln (count-lines (point-min) (point)))
+	(pattern "(line:\\([0-9]+\\))")
+	(secbuf YaTeX-sectioning-buffer) (command ""))
+    (save-excursion
+      (setq secbuf (YaTeX-colloect-sections))
+      (YaTeX-showup-buffer secbuf nil t)
+      (goto-char (point-max))
+      (while (re-search-backward pattern nil t)
+	(if (< ln (string-to-int (YaTeX-match-string 1))) nil
+	  (beginning-of-line)
+	  (search-forward YaTeX-ec)
+	  (looking-at YaTeX-TeX-token-regexp)
+	  (setq command (YaTeX-match-string 0))
+	  (end-of-line)
+	  (insert "  <<--")
+	  (setq pattern (concat "HackyRegexp" "ForFailure"))))
+      (set-buffer-modified-p nil)
+      (forward-line 1)
+      (if (eobp) (recenter -1) (recenter -3))
+      (select-window cw)
+      command))
+)
+
+(defun YaTeX-make-section-with-overview ()
+  "Input sectining command with previous overview."
+  (interactive)
+  (insert
+   YaTeX-ec
+   (YaTeX-read-section-in-minibuffer
+    "Sectioning(Up=C-p, Down=C-n, Help=?): "
+    YaTeX-sectioning-level (YaTeX-section-overview))
+   "{}")
+  (forward-char -1)
+)
+
+(provide 'yatexsec)
+;;(YaTeX-define-key "o" 'YaTeX-make-section-with-overview)

yatex.org