annotate yatexenv.el @ 56:a9653fbd1c1c

Bug fix version
author yuuji
date Thu, 29 Jun 1995 13:46:57 +0000
parents 5f4b18da14b3
children 3a7c0c2bf16d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
1 ;;; -*- Emacs-Lisp -*-
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
2 ;;; YaTeX environment-specific functions.
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
3 ;;; yatexenv.el
56
a9653fbd1c1c Bug fix version
yuuji
parents: 53
diff changeset
4 ;;; (c ) 1994, 1995 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
a9653fbd1c1c Bug fix version
yuuji
parents: 53
diff changeset
5 ;;; Last modified Thu May 18 11:52:05 1995 on inspire
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
6 ;;; $Id$
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
7
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
8 ;;;
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
9 ;; Functions for tabular environment
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
10 ;;;
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
11
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
12 ;; Showing the matching column of tabular environment.
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
13 (defun YaTeX-array-what-column ()
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
14 "Show matching columne title of array environment.
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
15 When calling from a program, make sure to be in array/tabular environment."
49
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
16 (let ((p (point)) beg eot bor (nlptn "\\\\\\\\") (andptn "[^\\]&")
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
17 (n 0) j
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
18 (firsterr "This line might be the first row."))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
19 (save-excursion
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
20 (YaTeX-beginning-of-environment)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
21 (search-forward "{" p) (up-list 1)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
22 (search-forward "{" p) (up-list 1)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
23 ;;(re-search-forward andptn p)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
24 (while (progn (search-forward "&" p)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
25 (equal (char-after (1- (match-beginning 0))) ?\\ )))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
26 (setq beg (1- (point))) ;beg is the point of the first &
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
27 (or (re-search-forward nlptn p t)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
28 (error firsterr))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
29 (setq eot (point)) ;eot is the point of the first \\
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
30 (goto-char p)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
31 (or (re-search-backward nlptn beg t)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
32 (error firsterr))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
33 (setq bor (point)) ;bor is the beginning of this row.
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
34 (while (< (1- (point)) p)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
35 (if (equal (following-char) ?&)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
36 (forward-char 1)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
37 (re-search-forward andptn nil 1))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
38 (setq n (1+ n))) ;Check current column number
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
39 (goto-char p)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
40 (cond ;Start searching \multicolumn{N}
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
41 ((> n 1)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
42 (re-search-backward andptn) ;Sure to find!
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
43 (while (re-search-backward "\\\\multicolumn{\\([0-9]+\\)}" bor t)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
44 (setq n (+ n (string-to-int
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
45 (buffer-substring (match-beginning 1)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
46 (match-end 1)))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
47 -1)))))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
48 (message "%s" n)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
49 (goto-char (1- beg))
49
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
50 (setq j n)
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
51 (while (> j 1)
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
52 (or (re-search-forward andptn p nil)
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
53 (error "This column exceeds the limit."))
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
54 (setq j (1- j)))
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
55 (skip-chars-forward "\\s ")
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
56 (message
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
57 "This is the column(#%d) of: %s" n
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
58 (buffer-substring
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
59 (point)
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
60 (progn
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
61 (re-search-forward (concat andptn "\\|" nlptn) eot)
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
62 (goto-char (match-beginning 0))
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
63 (if (looking-at andptn)
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
64 (forward-char 1))
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
65 (skip-chars-backward "\\s ")
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
66 (point))))))
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
67 )
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
68
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
69 ;;;###autoload
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
70 (defun YaTeX-what-column ()
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
71 "Show which kind of column the current position is belonging to."
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
72 (interactive)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
73 (cond
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
74 ((YaTeX-quick-in-environment-p '("tabular" "tabular*" "array" "array*"))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
75 (YaTeX-array-what-column))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
76 (t (message "Not in array/tabuar environment.")))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
77 )
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
78
31
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
79 (defun YaTeX-tabular-parse-format (&optional tabular*)
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
80 "Parse `tabular' format.
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
81 Return the list of (No.ofCols PointEndofFormat)"
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
82 (let ((p (point)) elt boform eoform (cols 0))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
83 (save-excursion
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
84 (if (null (YaTeX-beginning-of-environment t))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
85 (error "Beginning of tabular not found."))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
86 (skip-chars-forward "^{")
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
87 (forward-list 1)
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
88 (if tabular*
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
89 (progn (skip-chars-forward "^{")
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
90 (forward-list 1)))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
91 (skip-chars-forward "^{" p)
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
92 (if (/= (following-char) ?\{) (error "Tabular format not found."))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
93 (setq boform (1+ (point))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
94 eoform (progn (forward-list 1) (1- (point))))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
95 (if (> eoform p) (error "Non-terminated tabular format."))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
96 (goto-char boform)
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
97 (while (< (point) eoform)
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
98 (setq elt (following-char))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
99 (cond
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
100 ((string-match (char-to-string elt) "clr") ;normal indicators.
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
101 (setq cols (1+ cols))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
102 (forward-char 1))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
103 ((equal elt ?|) ;vertical
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
104 (forward-char 1))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
105 ((string-match (char-to-string elt) "p@") ;p or @ expression
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
106 (setq cols (+ (if (eq elt ?p) 1 0) cols))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
107 (skip-chars-forward "^{" p)
56
a9653fbd1c1c Bug fix version
yuuji
parents: 53
diff changeset
108 (forward-list 1))
a9653fbd1c1c Bug fix version
yuuji
parents: 53
diff changeset
109 (t (forward-char 1)) ;unknown char
a9653fbd1c1c Bug fix version
yuuji
parents: 53
diff changeset
110 ))
31
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
111 (list cols (1+ eoform))))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
112 )
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
113 ;; Insert &
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
114 (defun YaTeX-intelligent-newline-tabular (&optional tabular*)
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
115 "Parse current tabular format and insert that many `&'s."
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
116 (let*((p (point)) (format (YaTeX-tabular-parse-format tabular*))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
117 (cols (car format)) (beg (car (cdr format)))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
118 space hline)
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
119 (setq hline (search-backward "\\hline" beg t))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
120 (goto-char p)
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
121 (setq space (if (search-backward "\t&" beg t) "\t" " "))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
122 (goto-char p)
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
123 (YaTeX-indent-line)
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
124 (setq p (point))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
125 (while (> (1- cols) 0)
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
126 (insert "&" space)
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
127 (setq cols (1- cols)))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
128 (insert "\\\\")
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
129 (if hline (insert " \\hline"))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
130 (goto-char p))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
131 )
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
132
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
133 (defun YaTeX-intelligent-newline-tabular* ()
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
134 "Parse current tabular* format and insert that many `&'s."
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
135 (YaTeX-intelligent-newline-tabular t)
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
136 )
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
137
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
138 (fset 'YaTeX-intelligent-newline-array 'YaTeX-intelligent-newline-tabular)
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
139
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
140 ;;;
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
141 ;; Functions for tabbing environment
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
142 ;;;
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
143 (defun YaTeX-intelligent-newline-tabbing ()
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
144 "Check the number of \\= in the first line and insert that many \\>."
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
145 (let ((p (point)) begenv tabcount)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
146 (save-excursion
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
147 (YaTeX-beginning-of-environment)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
148 (setq begenv (point-end-of-line))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
149 (if (YaTeX-search-active-forward "\\\\" YaTeX-comment-prefix p t)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
150 (progn
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
151 (setq tabcount 0)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
152 (while (> (point) begenv)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
153 (if (search-backward "\\=" begenv 1)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
154 (setq tabcount (1+ tabcount)))))))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
155 (YaTeX-indent-line)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
156 (if tabcount
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
157 (progn
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
158 (save-excursion
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
159 (while (> tabcount 0)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
160 (insert "\\>\t")
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
161 (setq tabcount (1- tabcount))))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
162 (forward-char 2))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
163 (insert "\\=")))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
164 )
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
165
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
166 ;;;
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
167 ;; Functions for itemize/enumerate/list environments
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
168 ;;;
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
169
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
170 (defvar YaTeX-item-for-insert "\\item ")
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
171 (defun YaTeX-intelligent-newline-itemize ()
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
172 "Insert '\\item '."
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
173 (insert YaTeX-item-for-insert)
53
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
174 (YaTeX-indent-line)
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
175 )
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
176 (fset 'YaTeX-intelligent-newline-enumerate 'YaTeX-intelligent-newline-itemize)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
177 (fset 'YaTeX-intelligent-newline-list 'YaTeX-intelligent-newline-itemize)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
178
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
179 (defun YaTeX-intelligent-newline-description ()
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
180 (insert "\\item[] ")
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
181 (forward-char -2)
53
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
182 (YaTeX-indent-line)
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
183 )
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
184
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
185
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
186 ;;;
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
187 ;; Intelligent newline
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
188 ;;;
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
189 ;;;###autoload
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
190 (defun YaTeX-intelligent-newline (arg)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
191 "Insert newline and environment-specific entry.
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
192 `\\item' for some itemizing environment,
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
193 `\\> \\> \\' for tabbing environemnt,
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
194 `& & \\ \hline' for tabular environment."
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
195 (interactive "P")
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
196 (let*((env (YaTeX-inner-environment))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
197 func)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
198 (if arg (setq env (YaTeX-read-environment "For what environment? ")))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
199 (setq func (intern-soft (concat "YaTeX-intelligent-newline-" env)))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
200 (end-of-line)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
201 (newline)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
202 (if (and env func (fboundp func))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
203 (funcall func)))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
204 )
53
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
205
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
206 ;;;
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
207 ;; Environment-specific line indenting functions
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
208 ;;;
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
209 ;;;###autoload
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
210 (defun YaTeX-indent-line-equation ()
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
211 "Indent a line in equation family."
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
212 (let ((p (point)) (l-r 0) right-p peol depth (mp YaTeX-environment-indent))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
213 (if (save-excursion
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
214 (beginning-of-line)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
215 (skip-chars-forward " \t")
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
216 (looking-at "\\\\right\\b"))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
217 (progn (YaTeX-reindent
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
218 (save-excursion (YaTeX-goto-corresponding-leftright)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
219 (current-column))))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
220 (save-excursion
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
221 (forward-line -1)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
222 (while (and (not (bobp)) (YaTeX-on-comment-p))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
223 (forward-line -1))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
224 ;;(beginning-of-line) ;must be unnecessary
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
225 (skip-chars-forward " \t")
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
226 (if (eolp) (error "Math-environment can't have a null line!!"))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
227 (setq depth (current-column)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
228 peol (point-end-of-line))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
229 (while (re-search-forward
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
230 "\\\\\\(\\(left\\)\\|\\(right\\)\\)\\b" peol t)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
231 (setq l-r (+ l-r (if (match-beginning 2) 1 -1))))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
232 (cond
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
233 ((progn (beginning-of-line)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
234 (re-search-forward "\\\\\\\\\\s *$" (point-end-of-line) t))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
235 ;;If previous line has `\\', this indentation is always normal.
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
236 (setq depth (+ (YaTeX-current-indentation) mp)))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
237 ((> l-r 0)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
238 (beginning-of-line)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
239 (search-forward "\\left" peol)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
240 (goto-char (1+ (match-beginning 0)))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
241 (setq depth (current-column)))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
242 ((< l-r 0)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
243 (goto-char (match-beginning 0)) ;should be \right
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
244 (YaTeX-goto-corresponding-leftright)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
245 (beginning-of-line)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
246 (skip-chars-forward " \t")
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
247 (setq depth (+ (current-column) mp))) ;+mp is good?
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
248 (t ;if \left - \right = 0
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
249 (cond
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
250 ((re-search-forward "\\\\\\\\\\s *$" peol t)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
251 (setq depth (+ (YaTeX-current-indentation) mp)))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
252 ((re-search-forward "\\\\end{" peol t)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
253 nil) ;same indentation as previous line's
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
254 ((re-search-forward "\\\\begin{" peol t)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
255 (setq depth (+ depth mp)))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
256 (t
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
257 (or (bobp) (forward-line -1))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
258 (cond
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
259 ((re-search-forward
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
260 "\\\\\\\\\\s *$\\|\\\\begin{" (point-end-of-line) t)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
261 (setq depth (+ depth mp)))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
262 )))))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
263 (goto-char p))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
264 (YaTeX-reindent depth))))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
265
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
266 ;;;###autoload
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
267 (defun YaTeX-goto-corresponding-leftright ()
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
268 "Go to corresponding \left or \right.
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
269 Note that this function assumes the corresponding \left\right
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
270 is on another line."
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
271 (let ((YaTeX-struct-begin "\\left%1")
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
272 (YaTeX-struct-end "\\right%1")
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
273 (YaTeX-struct-name-regexp "[][(){}.|]"))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
274 (YaTeX-goto-corresponding-environment t)))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
275
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
276 ;;;
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
277 ;; Functions for formatting region being enclosed with environment
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
278 ;;;
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
279 ; These functions must take two argument; region-beginning, region-end.
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
280
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
281 (defun YaTeX-enclose-equation (beg end)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
282 (goto-char beg)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
283 (save-restriction
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
284 (let (m0 bsl)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
285 (narrow-to-region beg end)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
286 (while (YaTeX-re-search-active-forward
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
287 "\\(\\$\\)" YaTeX-comment-prefix nil t)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
288 (goto-char (setq m0 (match-beginning 0)))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
289 (setq bsl 0)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
290 (if (and (not (bobp)) (= (char-after (1- (point))) ?\\ ))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
291 (while (progn (forward-char -1) (= (char-after (point)) ?\\ ))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
292 (setq bsl (1+ bsl))))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
293 (goto-char m0)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
294 (if (= 0 (% bsl 2))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
295 (delete-char 1)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
296 (forward-char 1))))))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
297
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
298 (fset 'YaTeX-enclose-eqnarray 'YaTeX-enclose-equation)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
299 (fset 'YaTeX-enclose-eqnarray* 'YaTeX-enclose-equation)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
300
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
301 (defun YaTeX-enclose-verbatim (beg end)) ;do nothing when enclose verbatim
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
302 (fset 'YaTeX-enclose-verbatim* 'YaTeX-enclose-verbatim)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
303
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
304 (provide 'yatexenv)

yatex.org