rev |
line source |
yuuji@6
|
1 ;;; -*- Emacs-Lisp -*-
|
yuuji@8
|
2 ;;; YaTeX add-in functions.
|
yuuji@80
|
3 ;;; yatexadd.el rev.18
|
yuuji@80
|
4 ;;; (c)1991-2006 by HIROSE Yuuji.[yuuji@yatex.org]
|
yuuji@105
|
5 ;;; Last modified Thu Oct 15 09:18:40 2009 on firestorm
|
yuuji@104
|
6 ;;; $Id: yatexadd.el,v f14ec50103d0 2009/09/27 22:55:44 yuuji $
|
yuuji@6
|
7
|
yuuji@6
|
8 ;;;
|
yuuji@6
|
9 ;;Sample functions for LaTeX environment.
|
yuuji@6
|
10 ;;;
|
yuuji@6
|
11 (defvar YaTeX:tabular-default-rule
|
yuuji@6
|
12 "@{\\vrule width 1pt\\ }c|c|c@{\\ \\vrule width 1pt}"
|
yuuji@69
|
13 "*Your favorite default rule format.")
|
yuuji@69
|
14
|
yuuji@23
|
15 (defvar YaTeX:tabular-thick-vrule "\\vrule width %s"
|
yuuji@69
|
16 "*Vertical thick line format (without @{}). %s'll be replaced by its width.")
|
yuuji@69
|
17
|
yuuji@23
|
18 (defvar YaTeX:tabular-thick-hrule "\\noalign{\\hrule height %s}"
|
yuuji@69
|
19 "*Horizontal thick line format. %s will be replaced by its width.")
|
yuuji@69
|
20
|
yuuji@6
|
21 (defun YaTeX:tabular ()
|
yuuji@18
|
22 "YaTeX add-in function for tabular environment.
|
yuuji@18
|
23 Notice that this function refers the let-variable `env' in
|
yuuji@18
|
24 YaTeX-make-begin-end."
|
yuuji@23
|
25 (let ((width "") bars (rule "") (and "") (j 1) loc ans (hline "\\hline"))
|
yuuji@72
|
26 (if (string= YaTeX-env-name "tabular*")
|
yuuji@18
|
27 (setq width (concat "{" (read-string "Width: ") "}")))
|
yuuji@18
|
28 (setq loc (YaTeX:read-position "tb")
|
yuuji@23
|
29 bars (string-to-int
|
yuuji@23
|
30 (read-string "Number of columns(0 for default format): " "3")))
|
yuuji@23
|
31 (if (<= bars 0)
|
yuuji@23
|
32 (setq ;if 0, simple format
|
yuuji@23
|
33 rule YaTeX:tabular-default-rule
|
yuuji@23
|
34 and "& &")
|
yuuji@23
|
35 (while (< j bars) ;repeat bars-1 times
|
yuuji@23
|
36 (setq rule (concat rule "c|")
|
yuuji@23
|
37 and (concat and "& ")
|
yuuji@23
|
38 j (1+ j)))
|
yuuji@23
|
39 (setq rule (concat rule "c"))
|
yuuji@23
|
40 (message "(N)ormal-frame or (T)hick frame? [nt]")
|
yuuji@23
|
41 (setq ans (read-char))
|
yuuji@23
|
42 (cond
|
yuuji@23
|
43 ((or (equal ans ?t) (equal ans ?T))
|
yuuji@23
|
44 (setq ans (read-string "Rule width: " "1pt")
|
yuuji@23
|
45 rule (concat
|
yuuji@23
|
46 "@{" (format YaTeX:tabular-thick-vrule ans) "}"
|
yuuji@23
|
47 rule
|
yuuji@23
|
48 "@{\\ " (format YaTeX:tabular-thick-vrule ans) "}")
|
yuuji@23
|
49 hline (format YaTeX:tabular-thick-hrule ans)))
|
yuuji@23
|
50 (t (setq rule (concat "|" rule "|")
|
yuuji@23
|
51 hline "\\hline"))))
|
yuuji@23
|
52
|
yuuji@6
|
53 (setq rule (read-string "rule format: " rule))
|
yuuji@72
|
54 (setq YaTeX-single-command "hline")
|
yuuji@6
|
55
|
yuuji@69
|
56 (format "%s%s{%s}" width loc rule)))
|
yuuji@69
|
57
|
yuuji@18
|
58 (fset 'YaTeX:tabular* 'YaTeX:tabular)
|
yuuji@80
|
59 (fset 'YaTeX:supertabular 'YaTeX:tabular)
|
yuuji@80
|
60 (defun YaTeX:alignat ()
|
yuuji@80
|
61 (concat "{" (read-string "Number of columns: ") "}"))
|
yuuji@18
|
62 (defun YaTeX:array ()
|
yuuji@18
|
63 (concat (YaTeX:read-position "tb")
|
yuuji@69
|
64 "{" (read-string "Column format: ") "}"))
|
yuuji@80
|
65 (defun YaTeX:subequations ()
|
yuuji@80
|
66 (message (if YaTeX-japan "分かりやすいコメントに変えるとref補完が楽よ"
|
yuuji@80
|
67 "Changing comment string reduces effort at `ref' completion"))
|
yuuji@80
|
68 (concat " " YaTeX-comment-prefix
|
yuuji@80
|
69 (YaTeX::ref-default-label "%H:%M")
|
yuuji@80
|
70 (if YaTeX-japan "の式群" "equations")))
|
yuuji@6
|
71
|
yuuji@79
|
72 (defun YaTeX:read-oneof (oneof &optional quick allow-dup)
|
yuuji@23
|
73 (let ((pos "") loc (guide ""))
|
yuuji@23
|
74 (and (boundp 'name) name (setq guide (format "%s " name)))
|
yuuji@79
|
75 (catch 'quick
|
yuuji@79
|
76 (while (not (string-match
|
yuuji@79
|
77 (setq loc (read-key-sequence
|
yuuji@79
|
78 (format "%s position (`%s') [%s]: "
|
yuuji@79
|
79 guide oneof pos));name is in YaTeX-addin
|
yuuji@79
|
80 loc (if (fboundp 'events-to-keys)
|
yuuji@79
|
81 (events-to-keys loc) loc))
|
yuuji@79
|
82 "\r\^g\n"))
|
yuuji@79
|
83 (cond
|
yuuji@79
|
84 ((string-match loc oneof)
|
yuuji@79
|
85 (if (or allow-dup (not (string-match loc pos)))
|
yuuji@79
|
86 (setq pos (concat pos loc)))
|
yuuji@79
|
87 (if quick (throw 'quick t)))
|
yuuji@79
|
88 ((and (string-match loc "\C-h\C-?") (> (length pos) 0))
|
yuuji@79
|
89 (setq pos (substring pos 0 (1- (length pos)))))
|
yuuji@79
|
90 (t
|
yuuji@79
|
91 (ding)
|
yuuji@79
|
92 (message "Please input one of `%s'." oneof)
|
yuuji@79
|
93 (sit-for 3)))))
|
yuuji@8
|
94 (message "")
|
yuuji@69
|
95 pos))
|
yuuji@23
|
96
|
yuuji@23
|
97 (defun YaTeX:read-position (oneof)
|
yuuji@23
|
98 "Read a LaTeX (optional) position format such as `[htbp]'."
|
yuuji@23
|
99 (let ((pos (YaTeX:read-oneof oneof)))
|
yuuji@69
|
100 (if (string= pos "") "" (concat "[" pos "]"))))
|
yuuji@8
|
101
|
yuuji@8
|
102 (defun YaTeX:table ()
|
yuuji@8
|
103 "YaTeX add-in function for table environment."
|
yuuji@73
|
104 (cond
|
yuuji@73
|
105 ((eq major-mode 'yatex-mode)
|
yuuji@73
|
106 (setq YaTeX-env-name "tabular"
|
yuuji@73
|
107 YaTeX-section-name "caption")
|
yuuji@73
|
108 (YaTeX:read-position "htbp"))
|
yuuji@73
|
109 ((eq major-mode 'texinfo-mode)
|
yuuji@73
|
110 (concat " "
|
yuuji@73
|
111 (completing-read
|
yuuji@73
|
112 "Highlights with: "
|
yuuji@73
|
113 '(("@samp")("@kbd")("@code")("@asis")("@file")("@var"))
|
yuuji@73
|
114 nil nil "@")))))
|
yuuji@6
|
115
|
yuuji@46
|
116 (fset 'YaTeX:figure 'YaTeX:table)
|
yuuji@46
|
117 (fset 'YaTeX:figure* 'YaTeX:table)
|
yuuji@46
|
118
|
yuuji@46
|
119
|
yuuji@6
|
120 (defun YaTeX:description ()
|
yuuji@6
|
121 "Truly poor service:-)"
|
yuuji@72
|
122 (setq YaTeX-single-command "item[]")
|
yuuji@69
|
123 "")
|
yuuji@6
|
124
|
yuuji@6
|
125 (defun YaTeX:itemize ()
|
yuuji@6
|
126 "It's also poor service."
|
yuuji@72
|
127 (setq YaTeX-single-command "item")
|
yuuji@69
|
128 "")
|
yuuji@6
|
129
|
yuuji@6
|
130 (fset 'YaTeX:enumerate 'YaTeX:itemize)
|
yuuji@8
|
131
|
yuuji@11
|
132 (defun YaTeX:picture ()
|
yuuji@11
|
133 "Ask the size of coordinates of picture environment."
|
yuuji@11
|
134 (concat (YaTeX:read-coordinates "Picture size")
|
yuuji@69
|
135 (YaTeX:read-coordinates "Initial position")))
|
yuuji@11
|
136
|
yuuji@12
|
137 (defun YaTeX:equation ()
|
yuuji@59
|
138 (YaTeX-jmode-off)
|
yuuji@12
|
139 (if (fboundp 'YaTeX-toggle-math-mode)
|
yuuji@69
|
140 (YaTeX-toggle-math-mode t))) ;force math-mode ON.
|
yuuji@69
|
141
|
yuuji@59
|
142 (mapcar '(lambda (f) (fset f 'YaTeX:equation))
|
yuuji@59
|
143 '(YaTeX:eqnarray YaTeX:eqnarray* YaTeX:align YaTeX:align*
|
yuuji@59
|
144 YaTeX:split YaTeX:multline YaTeX:multline* YaTeX:gather YaTeX:gather*
|
yuuji@59
|
145 YaTeX:aligned* YaTeX:gathered YaTeX:gathered*
|
yuuji@59
|
146 YaTeX:alignat YaTeX:alignat* YaTeX:xalignat YaTeX:xalignat*
|
yuuji@59
|
147 YaTeX:xxalignat YaTeX:xxalignat*))
|
yuuji@12
|
148
|
yuuji@80
|
149 (defun YaTeX:alignat ()
|
yuuji@80
|
150 (YaTeX:equation)
|
yuuji@80
|
151 (concat "{" (read-string "Number of cols: ") "}"))
|
yuuji@80
|
152
|
yuuji@80
|
153
|
yuuji@80
|
154
|
yuuji@16
|
155 (defun YaTeX:list ()
|
yuuji@69
|
156 "%\n{} %default label\n{} %formatting parameter")
|
yuuji@16
|
157
|
yuuji@18
|
158 (defun YaTeX:minipage ()
|
yuuji@18
|
159 (concat (YaTeX:read-position "cbt")
|
yuuji@69
|
160 "{" (read-string "Width: ") "}"))
|
yuuji@18
|
161
|
yuuji@64
|
162 (defun YaTeX:thebibliography ()
|
yuuji@72
|
163 (setq YaTeX-section-name "bibitem")
|
yuuji@77
|
164 (concat "{" (read-string "Longest label: ") "}"))
|
yuuji@64
|
165
|
yuuji@80
|
166 (defun YaTeX:multicols ()
|
yuuji@80
|
167 (concat "{" (read-string "Number of columns: ") "}"))
|
yuuji@80
|
168
|
yuuji@8
|
169 ;;;
|
yuuji@8
|
170 ;;Sample functions for section-type command.
|
yuuji@8
|
171 ;;;
|
yuuji@8
|
172 (defun YaTeX:multiput ()
|
yuuji@8
|
173 (concat (YaTeX:read-coordinates "Pos")
|
yuuji@8
|
174 (YaTeX:read-coordinates "Step")
|
yuuji@69
|
175 "{" (read-string "How many times: ") "}"))
|
yuuji@8
|
176
|
yuuji@8
|
177 (defun YaTeX:put ()
|
yuuji@69
|
178 (YaTeX:read-coordinates "Pos"))
|
yuuji@8
|
179
|
yuuji@8
|
180 (defun YaTeX:makebox ()
|
yuuji@23
|
181 (cond
|
yuuji@23
|
182 ((YaTeX-in-environment-p "picture")
|
yuuji@23
|
183 (concat (YaTeX:read-coordinates "Dimension")
|
yuuji@80
|
184 (YaTeX:read-position "lsrtb")))
|
yuuji@23
|
185 (t
|
yuuji@23
|
186 (let ((width (read-string "Width: ")))
|
yuuji@23
|
187 (if (string< "" width)
|
yuuji@23
|
188 (progn
|
yuuji@23
|
189 (or (equal (aref width 0) ?\[)
|
yuuji@23
|
190 (setq width (concat "[" width "]")))
|
yuuji@80
|
191 (concat width (YaTeX:read-position
|
yuuji@80
|
192 (if YaTeX-use-LaTeX2e "lrs" "lr")))))))))
|
yuuji@8
|
193
|
yuuji@80
|
194 ;; (defun YaTeX:framebox ()
|
yuuji@80
|
195 ;; (if (YaTeX-quick-in-environment-p "picture")
|
yuuji@80
|
196 ;; (YaTeX:makebox)))
|
yuuji@80
|
197 (fset 'YaTeX:framebox 'YaTeX:makebox)
|
yuuji@80
|
198
|
yuuji@80
|
199 (defun YaTeX:parbox ()
|
yuuji@80
|
200 (YaTeX:read-position "tbc"))
|
yuuji@104
|
201 (defun YaTeX::parbox (argp)
|
yuuji@104
|
202 (cond
|
yuuji@104
|
203 ((= argp 1) (read-string "Width: "))
|
yuuji@104
|
204 ((= argp 2) (read-string "Text: "))))
|
yuuji@8
|
205
|
yuuji@105
|
206 (defun YaTeX::dashbox ()
|
yuuji@8
|
207 (concat "{" (read-string "Dash dimension: ") "}"
|
yuuji@69
|
208 (YaTeX:read-coordinates "Dimension")))
|
yuuji@8
|
209
|
yuuji@105
|
210 (defun YaTeX::savebox (argp)
|
yuuji@80
|
211 (cond
|
yuuji@80
|
212 ((= argp 1) (read-string "Saved into name: " "\\"))
|
yuuji@80
|
213 ((= argp 2) (read-string "Text: "))))
|
yuuji@80
|
214
|
yuuji@51
|
215 (defvar YaTeX-minibuffer-quick-map nil)
|
yuuji@51
|
216 (if YaTeX-minibuffer-quick-map nil
|
yuuji@51
|
217 (setq YaTeX-minibuffer-quick-map
|
yuuji@51
|
218 (copy-keymap minibuffer-local-completion-map))
|
yuuji@51
|
219 (let ((ch (1+ ? )))
|
yuuji@51
|
220 (while (< ch 127)
|
yuuji@51
|
221 (define-key YaTeX-minibuffer-quick-map (char-to-string ch)
|
yuuji@51
|
222 'YaTeX-minibuffer-quick-complete)
|
yuuji@51
|
223 (setq ch (1+ ch)))))
|
yuuji@51
|
224
|
yuuji@51
|
225 (defvar YaTeX:left-right-delimiters
|
yuuji@51
|
226 '(("(" . ")") (")" . "(") ("[" . "]") ("]" . "[")
|
yuuji@51
|
227 ("\\{" . "\\}") ("\\}" . "\\{") ("|") ("\\|")
|
yuuji@51
|
228 ("\\lfloor" . "\\rfloor") ("\\lceil" . "\\rceil")
|
yuuji@51
|
229 ("\\langle" . "\\rangle") ("/") (".")
|
yuuji@51
|
230 ("\\rfloor" . "\\rfloor") ("\\rceil" . "\\lceil")
|
yuuji@51
|
231 ("\\rangle" . "\\langle") ("\\backslash")
|
yuuji@51
|
232 ("\\uparrow") ("\\downarrow") ("\\updownarrow") ("\\Updownarrow"))
|
yuuji@51
|
233 "TeX math delimiter, which can be completed after \\right or \\left.")
|
yuuji@51
|
234
|
yuuji@51
|
235 (defvar YaTeX:left-right-default nil "Default string of YaTeX:right.")
|
yuuji@51
|
236
|
yuuji@23
|
237 (defun YaTeX:left ()
|
yuuji@51
|
238 (let ((minibuffer-completion-table YaTeX:left-right-delimiters)
|
yuuji@72
|
239 delimiter (leftp (string= YaTeX-single-command "left")))
|
yuuji@51
|
240 (setq delimiter
|
yuuji@51
|
241 (read-from-minibuffer
|
yuuji@51
|
242 (format "Delimiter%s: "
|
yuuji@51
|
243 (if YaTeX:left-right-default
|
yuuji@51
|
244 (format "(default=`%s')" YaTeX:left-right-default)
|
yuuji@51
|
245 "(SPC for menu)"))
|
yuuji@51
|
246 nil YaTeX-minibuffer-quick-map))
|
yuuji@51
|
247 (if (string= "" delimiter) (setq delimiter YaTeX:left-right-default))
|
yuuji@72
|
248 (setq YaTeX-single-command (if leftp "right" "left")
|
yuuji@51
|
249 YaTeX:left-right-default
|
yuuji@51
|
250 (or (cdr (assoc delimiter YaTeX:left-right-delimiters)) delimiter))
|
yuuji@51
|
251 delimiter))
|
yuuji@51
|
252
|
yuuji@23
|
253 (fset 'YaTeX:right 'YaTeX:left)
|
yuuji@23
|
254
|
yuuji@80
|
255 (defun YaTeX:langle ()
|
yuuji@80
|
256 (setq YaTeX-single-command "rangle")
|
yuuji@80
|
257 nil)
|
yuuji@80
|
258
|
yuuji@8
|
259 (defun YaTeX:read-coordinates (&optional mes varX varY)
|
yuuji@8
|
260 (concat
|
yuuji@8
|
261 "("
|
yuuji@8
|
262 (read-string (format "%s %s: " (or mes "Dimension") (or varX "X")))
|
yuuji@8
|
263 ","
|
yuuji@8
|
264 (read-string (format "%s %s: " (or mes "Dimension") (or varY "Y")))
|
yuuji@69
|
265 ")"))
|
yuuji@8
|
266
|
yuuji@79
|
267 (defun YaTeX:itembox ()
|
yuuji@79
|
268 (concat "{" (read-string "Item heading string: ") "}"))
|
yuuji@79
|
269
|
yuuji@8
|
270 ;;;
|
yuuji@8
|
271 ;;Sample functions for maketitle-type command.
|
yuuji@8
|
272 ;;;
|
yuuji@8
|
273 (defun YaTeX:sum ()
|
yuuji@8
|
274 "Read range of summation."
|
yuuji@8
|
275 (YaTeX:check-completion-type 'maketitle)
|
yuuji@69
|
276 (concat (YaTeX:read-boundary "_") (YaTeX:read-boundary "^")))
|
yuuji@8
|
277
|
yuuji@8
|
278 (fset 'YaTeX:int 'YaTeX:sum)
|
yuuji@8
|
279
|
yuuji@8
|
280 (defun YaTeX:lim ()
|
yuuji@8
|
281 "Insert limit notation of \\lim."
|
yuuji@8
|
282 (YaTeX:check-completion-type 'maketitle)
|
yuuji@8
|
283 (let ((var (read-string "Variable: ")) limit)
|
yuuji@8
|
284 (if (string= "" var) ""
|
yuuji@8
|
285 (setq limit (read-string "Limit ($ means infinity): "))
|
yuuji@8
|
286 (if (string= "$" limit) (setq limit "\\infty"))
|
yuuji@69
|
287 (concat "_{" var " \\rightarrow " limit "}"))))
|
yuuji@8
|
288
|
yuuji@8
|
289 (defun YaTeX:gcd ()
|
yuuji@8
|
290 "Add-in function for \\gcd(m,n)."
|
yuuji@8
|
291 (YaTeX:check-completion-type 'maketitle)
|
yuuji@69
|
292 (YaTeX:read-coordinates "\\gcd" "(?,)" "(,?)"))
|
yuuji@8
|
293
|
yuuji@8
|
294 (defun YaTeX:read-boundary (ULchar)
|
yuuji@8
|
295 "Read boundary usage by _ or ^. _ or ^ is indicated by argument ULchar."
|
yuuji@11
|
296 (let ((bndry (read-string (concat ULchar "{???} ($ for infinity): "))))
|
yuuji@8
|
297 (if (string= bndry "") ""
|
yuuji@11
|
298 (if (string= bndry "$") (setq bndry "\\infty"))
|
yuuji@69
|
299 (concat ULchar "{" bndry "}"))))
|
yuuji@8
|
300
|
yuuji@14
|
301 (defun YaTeX:verb ()
|
yuuji@14
|
302 "Enclose \\verb's contents with the same characters."
|
yuuji@14
|
303 (let ((quote-char (read-string "Quoting char: " "|"))
|
yuuji@14
|
304 (contents (read-string "Quoted contents: ")))
|
yuuji@69
|
305 (concat quote-char contents quote-char)))
|
yuuji@69
|
306
|
yuuji@23
|
307 (fset 'YaTeX:verb* 'YaTeX:verb)
|
yuuji@14
|
308
|
yuuji@43
|
309 (defun YaTeX:footnotemark ()
|
yuuji@72
|
310 (setq YaTeX-section-name "footnotetext")
|
yuuji@69
|
311 nil)
|
yuuji@43
|
312
|
yuuji@48
|
313 (defun YaTeX:cite ()
|
yuuji@48
|
314 (let ((comment (read-string "Comment for citation: ")))
|
yuuji@48
|
315 (if (string= comment "") ""
|
yuuji@69
|
316 (concat "[" comment "]"))))
|
yuuji@48
|
317
|
yuuji@48
|
318 (defun YaTeX:bibitem ()
|
yuuji@64
|
319 (let ((label (read-string "Citation label for bibitem: ")))
|
yuuji@48
|
320 (if (string= label "") ""
|
yuuji@69
|
321 (concat "[" label "]"))))
|
yuuji@48
|
322
|
yuuji@53
|
323 (defun YaTeX:item ()
|
yuuji@73
|
324 (cond
|
yuuji@73
|
325 ((eq major-mode 'yatex-mode)
|
yuuji@73
|
326 (YaTeX-indent-line)
|
yuuji@73
|
327 (setq YaTeX-section-name "label"))
|
yuuji@73
|
328 ((eq major-mode 'texinfo-mode)
|
yuuji@73
|
329 (setq YaTeX-section-name "dots"))) ;??
|
yuuji@53
|
330 " ")
|
yuuji@52
|
331 (fset 'YaTeX:item\[\] 'YaTeX:item)
|
yuuji@52
|
332 (fset 'YaTeX:subitem 'YaTeX:item)
|
yuuji@52
|
333 (fset 'YaTeX:subsubitem 'YaTeX:item)
|
yuuji@52
|
334
|
yuuji@58
|
335 (defun YaTeX:linebreak ()
|
yuuji@58
|
336 (let (obl)
|
yuuji@58
|
337 (message "Break strength 0,1,2,3,4 (default: 4): ")
|
yuuji@58
|
338 (setq obl (char-to-string (read-char)))
|
yuuji@58
|
339 (if (string-match "[0-4]" obl)
|
yuuji@58
|
340 (concat "[" obl "]")
|
yuuji@69
|
341 "")))
|
yuuji@58
|
342 (fset 'YaTeX:pagebreak 'YaTeX:linebreak)
|
yuuji@58
|
343
|
yuuji@14
|
344 ;;;
|
yuuji@14
|
345 ;;Subroutine
|
yuuji@14
|
346 ;;;
|
yuuji@14
|
347
|
yuuji@8
|
348 (defun YaTeX:check-completion-type (type)
|
yuuji@8
|
349 "Check valid completion type."
|
yuuji@8
|
350 (if (not (eq type YaTeX-current-completion-type))
|
yuuji@69
|
351 (error "This should be completed with %s-type completion." type)))
|
yuuji@11
|
352
|
yuuji@11
|
353
|
yuuji@11
|
354 ;;;
|
yuuji@11
|
355 ;;; [[Add-in functions for reading section arguments]]
|
yuuji@11
|
356 ;;;
|
yuuji@11
|
357 ;; All of add-in functions for reading sections arguments should
|
yuuji@11
|
358 ;; take an argument ARGP that specify the argument position.
|
yuuji@11
|
359 ;; If argument position is out of range, nil should be returned,
|
yuuji@11
|
360 ;; else nil should NOT be returned.
|
yuuji@13
|
361
|
yuuji@13
|
362 ;;
|
yuuji@13
|
363 ; Label selection
|
yuuji@13
|
364 ;;
|
yuuji@11
|
365 (defvar YaTeX-label-menu-other
|
yuuji@11
|
366 (if YaTeX-japan "':他のバッファのラベル\n" "':LABEL IN OTHER BUFFER.\n"))
|
yuuji@23
|
367 (defvar YaTeX-label-menu-repeat
|
yuuji@23
|
368 (if YaTeX-japan ".:直前の\\refと同じ\n" "/:REPEAT LAST \ref{}\n"))
|
yuuji@11
|
369 (defvar YaTeX-label-menu-any
|
yuuji@11
|
370 (if YaTeX-japan "*:任意の文字列\n" "*:ANY STRING.\n"))
|
yuuji@11
|
371 (defvar YaTeX-label-buffer "*Label completions*")
|
yuuji@11
|
372 (defvar YaTeX-label-guide-msg "Select label and hit RETURN.")
|
yuuji@11
|
373 (defvar YaTeX-label-select-map nil
|
yuuji@11
|
374 "Key map used in label selection buffer.")
|
yuuji@11
|
375 (defun YaTeX::label-setup-key-map ()
|
yuuji@11
|
376 (if YaTeX-label-select-map nil
|
yuuji@11
|
377 (message "Setting up label selection mode map...")
|
yuuji@68
|
378 ;(setq YaTeX-label-select-map (copy-keymap global-map))
|
yuuji@68
|
379 (setq YaTeX-label-select-map (make-keymap))
|
yuuji@11
|
380 (suppress-keymap YaTeX-label-select-map)
|
yuuji@11
|
381 (substitute-all-key-definition
|
yuuji@11
|
382 'previous-line 'YaTeX::label-previous YaTeX-label-select-map)
|
yuuji@11
|
383 (substitute-all-key-definition
|
yuuji@11
|
384 'next-line 'YaTeX::label-next YaTeX-label-select-map)
|
yuuji@11
|
385 (define-key YaTeX-label-select-map "\C-n" 'YaTeX::label-next)
|
yuuji@11
|
386 (define-key YaTeX-label-select-map "\C-p" 'YaTeX::label-previous)
|
yuuji@11
|
387 (define-key YaTeX-label-select-map "<" 'beginning-of-buffer)
|
yuuji@11
|
388 (define-key YaTeX-label-select-map ">" 'end-of-buffer)
|
yuuji@11
|
389 (define-key YaTeX-label-select-map "\C-m" 'exit-recursive-edit)
|
yuuji@11
|
390 (define-key YaTeX-label-select-map "\C-j" 'exit-recursive-edit)
|
yuuji@11
|
391 (define-key YaTeX-label-select-map " " 'exit-recursive-edit)
|
yuuji@11
|
392 (define-key YaTeX-label-select-map "\C-g" 'abort-recursive-edit)
|
yuuji@11
|
393 (define-key YaTeX-label-select-map "/" 'isearch-forward)
|
yuuji@11
|
394 (define-key YaTeX-label-select-map "?" 'isearch-backward)
|
yuuji@11
|
395 (define-key YaTeX-label-select-map "'" 'YaTeX::label-search-tag)
|
yuuji@23
|
396 (define-key YaTeX-label-select-map "." 'YaTeX::label-search-tag)
|
yuuji@11
|
397 (define-key YaTeX-label-select-map "*" 'YaTeX::label-search-tag)
|
yuuji@11
|
398 (message "Setting up label selection mode map...Done")
|
yuuji@11
|
399 (let ((key ?A))
|
yuuji@11
|
400 (while (<= key ?Z)
|
yuuji@11
|
401 (define-key YaTeX-label-select-map (char-to-string key)
|
yuuji@11
|
402 'YaTeX::label-search-tag)
|
yuuji@11
|
403 (define-key YaTeX-label-select-map (char-to-string (+ key (- ?a ?A)))
|
yuuji@11
|
404 'YaTeX::label-search-tag)
|
yuuji@69
|
405 (setq key (1+ key))))))
|
yuuji@69
|
406
|
yuuji@11
|
407 (defun YaTeX::label-next ()
|
yuuji@11
|
408 (interactive) (forward-line 1) (message YaTeX-label-guide-msg))
|
yuuji@11
|
409 (defun YaTeX::label-previous ()
|
yuuji@11
|
410 (interactive) (forward-line -1) (message YaTeX-label-guide-msg))
|
yuuji@11
|
411 (defun YaTeX::label-search-tag ()
|
yuuji@11
|
412 (interactive)
|
yuuji@68
|
413 (let ((case-fold-search t)
|
yuuji@68
|
414 (tag (regexp-quote (char-to-string last-command-char))))
|
yuuji@11
|
415 (cond
|
yuuji@11
|
416 ((save-excursion
|
yuuji@11
|
417 (forward-char 1)
|
yuuji@23
|
418 (re-search-forward (concat "^" tag) nil t))
|
yuuji@11
|
419 (goto-char (match-beginning 0)))
|
yuuji@11
|
420 ((save-excursion
|
yuuji@11
|
421 (goto-char (point-min))
|
yuuji@23
|
422 (re-search-forward (concat "^" tag) nil t))
|
yuuji@11
|
423 (goto-char (match-beginning 0))))
|
yuuji@69
|
424 (message YaTeX-label-guide-msg)))
|
yuuji@69
|
425
|
yuuji@70
|
426 ; (defun YaTeX::ref (argp &optional labelcmd refcmd)
|
yuuji@70
|
427 ; (cond
|
yuuji@70
|
428 ; ((= argp 1)
|
yuuji@70
|
429 ; (let ((lnum 0) e0 label label-list (buf (current-buffer))
|
yuuji@70
|
430 ; (labelcmd (or labelcmd "label")) (refcmd (or refcmd "ref"))
|
yuuji@70
|
431 ; (p (point)) initl line cf)
|
yuuji@70
|
432 ; (message "Collecting labels...")
|
yuuji@70
|
433 ; (save-window-excursion
|
yuuji@70
|
434 ; (YaTeX-showup-buffer
|
yuuji@70
|
435 ; YaTeX-label-buffer (function (lambda (x) (window-width x))))
|
yuuji@70
|
436 ; (if (fboundp 'select-frame) (setq cf (selected-frame)))
|
yuuji@70
|
437 ; (if (eq (window-buffer (minibuffer-window)) buf)
|
yuuji@70
|
438 ; (progn
|
yuuji@70
|
439 ; (other-window 1)
|
yuuji@70
|
440 ; (setq buf (current-buffer))
|
yuuji@70
|
441 ; (set-buffer buf)
|
yuuji@70
|
442 ; ;(message "cb=%s" buf)(sit-for 3)
|
yuuji@70
|
443 ; ))
|
yuuji@70
|
444 ; (save-excursion
|
yuuji@70
|
445 ; (set-buffer (get-buffer-create YaTeX-label-buffer))
|
yuuji@70
|
446 ; (setq buffer-read-only nil)
|
yuuji@70
|
447 ; (erase-buffer))
|
yuuji@70
|
448 ; (save-excursion
|
yuuji@70
|
449 ; (goto-char (point-min))
|
yuuji@70
|
450 ; (let ((standard-output (get-buffer YaTeX-label-buffer)))
|
yuuji@70
|
451 ; (princ (format "=== LABELS in [%s] ===\n" (buffer-name buf)))
|
yuuji@70
|
452 ; (while (YaTeX-re-search-active-forward
|
yuuji@70
|
453 ; (concat "\\\\" labelcmd "\\b")
|
yuuji@70
|
454 ; (regexp-quote YaTeX-comment-prefix) nil t)
|
yuuji@70
|
455 ; (goto-char (match-beginning 0))
|
yuuji@70
|
456 ; (skip-chars-forward "^{")
|
yuuji@70
|
457 ; (setq label
|
yuuji@70
|
458 ; (buffer-substring
|
yuuji@70
|
459 ; (1+ (point))
|
yuuji@70
|
460 ; (prog2 (forward-list 1) (setq e0 (1- (point)))))
|
yuuji@70
|
461 ; label-list (cons label label-list))
|
yuuji@70
|
462 ; (or initl
|
yuuji@70
|
463 ; (if (< p (point)) (setq initl lnum)))
|
yuuji@70
|
464 ; (beginning-of-line)
|
yuuji@70
|
465 ; (skip-chars-forward " \t\n" nil)
|
yuuji@70
|
466 ; (princ (format "%c:{%s}\t<<%s>>\n" (+ (% lnum 26) ?A) label
|
yuuji@70
|
467 ; (buffer-substring (point) (point-end-of-line))))
|
yuuji@70
|
468 ; (setq lnum (1+ lnum))
|
yuuji@70
|
469 ; (message "Collecting \\%s{}... %d" labelcmd lnum)
|
yuuji@70
|
470 ; (goto-char e0))
|
yuuji@70
|
471 ; (princ YaTeX-label-menu-other)
|
yuuji@70
|
472 ; (princ YaTeX-label-menu-repeat)
|
yuuji@70
|
473 ; (princ YaTeX-label-menu-any)
|
yuuji@70
|
474 ; );standard-output
|
yuuji@70
|
475 ; (goto-char p)
|
yuuji@70
|
476 ; (or initl (setq initl lnum))
|
yuuji@70
|
477 ; (message "Collecting %s...Done" labelcmd)
|
yuuji@70
|
478 ; (if (fboundp 'select-frame) (select-frame cf))
|
yuuji@70
|
479 ; (YaTeX-showup-buffer YaTeX-label-buffer nil t)
|
yuuji@70
|
480 ; (YaTeX::label-setup-key-map)
|
yuuji@70
|
481 ; (setq truncate-lines t)
|
yuuji@70
|
482 ; (setq buffer-read-only t)
|
yuuji@70
|
483 ; (use-local-map YaTeX-label-select-map)
|
yuuji@70
|
484 ; (message YaTeX-label-guide-msg)
|
yuuji@70
|
485 ; (goto-line (1+ initl)) ;goto recently defined label line
|
yuuji@70
|
486 ; (switch-to-buffer (current-buffer))
|
yuuji@70
|
487 ; (unwind-protect
|
yuuji@70
|
488 ; (progn
|
yuuji@70
|
489 ; (recursive-edit)
|
yuuji@70
|
490 ; (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
|
yuuji@70
|
491 ; (beginning-of-line)
|
yuuji@70
|
492 ; (setq line (1- (count-lines (point-min)(point))))
|
yuuji@70
|
493 ; (cond
|
yuuji@70
|
494 ; ((= line -1) (setq label ""))
|
yuuji@70
|
495 ; ((= line lnum) (setq label (YaTeX-label-other)))
|
yuuji@70
|
496 ; ((= line (1+ lnum))
|
yuuji@70
|
497 ; (save-excursion
|
yuuji@70
|
498 ; (switch-to-buffer buf)
|
yuuji@70
|
499 ; (goto-char p)
|
yuuji@70
|
500 ; (if (re-search-backward
|
yuuji@70
|
501 ; (concat "\\\\" refcmd "{\\([^}]+\\)}") nil t)
|
yuuji@70
|
502 ; (setq label (YaTeX-match-string 1))
|
yuuji@70
|
503 ; (setq label ""))))
|
yuuji@70
|
504 ; ((>= line (+ lnum 2))
|
yuuji@70
|
505 ; (setq label (read-string (format "\\%s{???}: " refcmd))))
|
yuuji@70
|
506 ; (t (setq label (nth (- lnum line 1) label-list)))))
|
yuuji@70
|
507 ; (bury-buffer YaTeX-label-buffer)))
|
yuuji@70
|
508 ; label)))))
|
yuuji@70
|
509
|
yuuji@80
|
510 (defvar YaTeX-ref-default-label-string "%H%M%S_%d%b%y"
|
yuuji@80
|
511 "*Default \\ref time string format.
|
yuuji@80
|
512 This format is like strftime(3) but allowed conversion char are as follows;
|
yuuji@80
|
513 %y -> Last 2 digit of year, %b -> Month name, %m -> Monthe number(1-12),
|
yuuji@80
|
514 %d -> Day, %H -> Hour, %M -> Minute, %S -> Second,
|
yuuji@80
|
515 %qx -> alphabetical-decimal conversion of yymmdd.
|
yuuji@80
|
516 %qX -> alphabetical-decimal conversion of HHMMSS.
|
yuuji@80
|
517 Beware defualt label-string should be always unique. So this format string
|
yuuji@80
|
518 should have both time part (%H+%M+%S or %qX) and date
|
yuuji@80
|
519 part (%y+(%b|%m)+%d or %qx).")
|
yuuji@80
|
520
|
yuuji@80
|
521 (defun YaTeX::ref-alphabex (n)
|
yuuji@80
|
522 (let ((alphabex ""))
|
yuuji@80
|
523 (while (> n 0)
|
yuuji@80
|
524 (setq alphabex (concat (char-to-string (+ ?a (% n 26))) alphabex)
|
yuuji@80
|
525 n (/ n 26)))
|
yuuji@80
|
526 alphabex))
|
yuuji@80
|
527
|
yuuji@80
|
528 (defun YaTeX::ref-default-label (&optional format)
|
yuuji@80
|
529 "Default auto-genarated label string."
|
yuuji@80
|
530 ;; We do not use (format-time-string) for emacs-19
|
yuuji@80
|
531 (let*((ts (substring (current-time-string) 4))
|
yuuji@80
|
532 (y (substring ts -2))
|
yuuji@80
|
533 (b (substring ts 0 3))
|
yuuji@80
|
534 (d (format "%d" (string-to-int (substring ts 4 6))))
|
yuuji@80
|
535 (H (substring ts 7 9))
|
yuuji@80
|
536 (M (substring ts 10 12))
|
yuuji@80
|
537 (S (substring ts 13 15))
|
yuuji@80
|
538 (HMS (+ (* 10000 (string-to-int H))
|
yuuji@80
|
539 (* 100 (string-to-int M))
|
yuuji@80
|
540 (string-to-int S)))
|
yuuji@80
|
541 (talphabex (YaTeX::ref-alphabex HMS))
|
yuuji@80
|
542 (mnames "JanFebMarAprMayJunJulAugSepOctNovDec")
|
yuuji@80
|
543 (m (format "%02d" (/ (string-match b mnames) 3)))
|
yuuji@80
|
544 (ymd (+ (* 10000 (string-to-int y))
|
yuuji@80
|
545 (* 100 (string-to-int m))
|
yuuji@80
|
546 (string-to-int d)))
|
yuuji@80
|
547 (dalphabex (YaTeX::ref-alphabex ymd)))
|
yuuji@80
|
548 (YaTeX-replace-formats
|
yuuji@80
|
549 (or format YaTeX-ref-default-label-string)
|
yuuji@80
|
550 (list (cons "y" y)
|
yuuji@80
|
551 (cons "b" b)
|
yuuji@80
|
552 (cons "m" m)
|
yuuji@80
|
553 (cons "d" d)
|
yuuji@80
|
554 (cons "H" H)
|
yuuji@80
|
555 (cons "M" M)
|
yuuji@80
|
556 (cons "S" S)
|
yuuji@80
|
557 (cons "qX" talphabex)
|
yuuji@80
|
558 (cons "qx" dalphabex)))))
|
yuuji@80
|
559
|
yuuji@80
|
560 (defvar YaTeX-ref-generate-label-function 'YaTeX::ref-generate-label
|
yuuji@80
|
561 "*Function to generate default label for unnamed \\label{}s.
|
yuuji@80
|
562 The function pointed to this value should take two arguments.
|
yuuji@80
|
563 First argument is LaTeX macro's name, second is macro's argument.")
|
yuuji@80
|
564
|
yuuji@80
|
565 (defun YaTeX::ref-generate-label (command arg)
|
yuuji@70
|
566 "Generate a label string which is unique in current buffer."
|
yuuji@80
|
567 (let ((default (condition-case nil
|
yuuji@80
|
568 (YaTeX::ref-default-label)
|
yuuji@80
|
569 (error (substring (current-time-string) 4)))))
|
yuuji@70
|
570 (read-string "Give a label for this line: "
|
yuuji@70
|
571 (if YaTeX-emacs-19 (cons default 1) default))))
|
yuuji@70
|
572
|
yuuji@80
|
573 (defun YaTeX::ref-getset-label (buffer point &optional noset)
|
yuuji@70
|
574 "Get label string in the BUFFER near the POINT.
|
yuuji@80
|
575 Make \\label{xx} if no label.
|
yuuji@80
|
576 If optional third argument NOSET is non-nil, do not generate new label."
|
yuuji@73
|
577 ;;Here, we rewrite the LaTeX source. Therefore we should be careful
|
yuuji@73
|
578 ;;to decide the location suitable for \label. Do straightforward!
|
yuuji@80
|
579 (let (boundary inspoint cc newlabel (labelholder "label") mathp exp1 env
|
yuuji@80
|
580 (r-escape (regexp-quote YaTeX-comment-prefix))
|
yuuji@80
|
581 command arg alreadysought foundpoint)
|
yuuji@80
|
582 (set-buffer buffer)
|
yuuji@70
|
583 (save-excursion
|
yuuji@70
|
584 (goto-char point)
|
yuuji@70
|
585 (setq cc (current-column))
|
yuuji@70
|
586 (if (= (char-after (point)) ?\\) (forward-char 1))
|
yuuji@70
|
587 (cond
|
yuuji@70
|
588 ((looking-at YaTeX-sectioning-regexp)
|
yuuji@80
|
589 (setq command (YaTeX-match-string 0))
|
yuuji@70
|
590 (skip-chars-forward "^{")
|
yuuji@80
|
591 (setq arg (buffer-substring
|
yuuji@80
|
592 (1+ (point))
|
yuuji@80
|
593 (progn (forward-list 1) (1- (point)))))
|
yuuji@70
|
594 (skip-chars-forward " \t\n")
|
yuuji@73
|
595 ;(setq boundary "[^\\]")
|
yuuji@77
|
596 (setq inspoint (point))
|
yuuji@73
|
597 (setq boundary
|
yuuji@73
|
598 (save-excursion
|
yuuji@77
|
599 (if (YaTeX-re-search-active-forward
|
yuuji@77
|
600 (concat YaTeX-ec-regexp
|
yuuji@77
|
601 "\\(" YaTeX-sectioning-regexp "\\|"
|
yuuji@77
|
602 "begin\\|item\\)")
|
yuuji@77
|
603 r-escape nil 1)
|
yuuji@73
|
604 (match-beginning 0)
|
yuuji@73
|
605 (1- (point))))))
|
yuuji@70
|
606 ((looking-at "item\\s ")
|
yuuji@80
|
607 (setq command "item"
|
yuuji@80
|
608 cc (+ cc 6))
|
yuuji@73
|
609 ;(setq boundary (concat YaTeX-ec-regexp "\\(item\\|begin\\|end\\)\\b"))
|
yuuji@73
|
610 (setq boundary
|
yuuji@73
|
611 (save-excursion
|
yuuji@73
|
612 (if (YaTeX-re-search-active-forward
|
yuuji@73
|
613 (concat YaTeX-ec-regexp "\\(item\\|begin\\|end\\)\\b")
|
yuuji@73
|
614 r-escape nil 1)
|
yuuji@73
|
615 (match-beginning 0)
|
yuuji@77
|
616 (1- (point))))
|
yuuji@77
|
617 inspoint boundary))
|
yuuji@70
|
618 ((looking-at "bibitem")
|
yuuji@80
|
619 (setq labelholder "bibitem" ; label holder is bibitem itself
|
yuuji@80
|
620 command "bibitem")
|
yuuji@73
|
621 (setq boundary
|
yuuji@73
|
622 (save-excursion
|
yuuji@73
|
623 (if (YaTeX-re-search-active-forward
|
yuuji@73
|
624 (concat YaTeX-ec-regexp "\\(bibitem\\|end\\)\\b")
|
yuuji@73
|
625 r-escape nil 1)
|
yuuji@73
|
626 (match-beginning 0)
|
yuuji@77
|
627 (1- (point))))
|
yuuji@77
|
628 inspoint boundary))
|
yuuji@80
|
629 ((string-match YaTeX::ref-nestable-counter-regexp
|
yuuji@70
|
630 (setq env (or (YaTeX-inner-environment t) "document")))
|
yuuji@80
|
631 (let ((curtop (get 'YaTeX-inner-environment 'point))
|
yuuji@80
|
632 (end (point-max)) label)
|
yuuji@80
|
633 (skip-chars-forward " \t\n")
|
yuuji@80
|
634 (setq inspoint (point) ;initial candidate
|
yuuji@80
|
635 cc (current-column)
|
yuuji@80
|
636 command env
|
yuuji@80
|
637 alreadysought t)
|
yuuji@80
|
638 (if (condition-case nil
|
yuuji@80
|
639 (progn
|
yuuji@80
|
640 (goto-char curtop)
|
yuuji@80
|
641 (YaTeX-goto-corresponding-environment))
|
yuuji@80
|
642 (error nil))
|
yuuji@80
|
643 (setq end (point)))
|
yuuji@80
|
644 (goto-char inspoint)
|
yuuji@80
|
645 (while (YaTeX-re-search-active-forward
|
yuuji@80
|
646 (concat YaTeX-ec-regexp "label{\\([^}]+\\)}" )
|
yuuji@80
|
647 r-escape end t)
|
yuuji@80
|
648 (setq label (YaTeX-match-string 1))
|
yuuji@80
|
649 (if (and (equal env (YaTeX-inner-environment t))
|
yuuji@80
|
650 (= curtop (get 'YaTeX-inner-environment 'point)))
|
yuuji@80
|
651 ;;I found the label
|
yuuji@80
|
652 (setq alreadysought label
|
yuuji@80
|
653 foundpoint (match-end 0))))
|
yuuji@80
|
654 ))
|
yuuji@80
|
655 ((string-match YaTeX::ref-mathenv-regexp env) ;env is set in above case
|
yuuji@80
|
656 (setq command env
|
yuuji@80
|
657 mathp t
|
yuuji@80
|
658 exp1 (string-match YaTeX::ref-mathenv-exp1-regexp env))
|
yuuji@73
|
659 ;;(setq boundary (concat YaTeX-ec-regexp "\\(\\\\\\|end{" env "}\\)"))
|
yuuji@73
|
660 (setq boundary
|
yuuji@73
|
661 (save-excursion
|
yuuji@73
|
662 (if (YaTeX-re-search-active-forward
|
yuuji@80
|
663 (concat
|
yuuji@80
|
664 YaTeX-ec-regexp "\\("
|
yuuji@80
|
665 (if exp1 "" "\\\\\\|")
|
yuuji@80
|
666 "end{" env "}\\)")
|
yuuji@73
|
667 r-escape nil 1)
|
yuuji@73
|
668 (match-beginning 0)
|
yuuji@77
|
669 (1- (point))))
|
yuuji@77
|
670 inspoint boundary))
|
yuuji@73
|
671 ((looking-at "footnote\\s *{")
|
yuuji@80
|
672 (setq command "footnote")
|
yuuji@73
|
673 (skip-chars-forward "^{") ;move onto `{'
|
yuuji@73
|
674 (setq boundary
|
yuuji@73
|
675 (save-excursion
|
yuuji@73
|
676 (condition-case err
|
yuuji@73
|
677 (forward-list 1)
|
yuuji@73
|
678 (error (error "\\\\footnote at point %s's brace not closed"
|
yuuji@73
|
679 (point))))
|
yuuji@77
|
680 (1- (point)))
|
yuuji@77
|
681 inspoint boundary))
|
yuuji@70
|
682 ((looking-at "caption\\|\\(begin\\)")
|
yuuji@80
|
683 (setq command (YaTeX-match-string 0))
|
yuuji@70
|
684 (skip-chars-forward "^{")
|
yuuji@77
|
685 ;;;;;;(if (match-beginning 1) (forward-list 1))
|
yuuji@77
|
686 ;; caption can be treated as mathenv, is it right??
|
yuuji@80
|
687 (setq arg (buffer-substring
|
yuuji@80
|
688 (1+ (point))
|
yuuji@80
|
689 (progn (forward-list 1) (1- (point)))))
|
yuuji@73
|
690 ;;(setq boundary (concat YaTeX-ec-regexp "\\(begin\\|end\\)\\b"))
|
yuuji@77
|
691 (setq inspoint (point))
|
yuuji@73
|
692 (setq boundary
|
yuuji@73
|
693 (save-excursion
|
yuuji@73
|
694 (if (YaTeX-re-search-active-forward
|
yuuji@73
|
695 (concat YaTeX-ec-regexp "\\(begin\\|end\\)\\b")
|
yuuji@73
|
696 r-escape nil 1)
|
yuuji@73
|
697 (match-beginning 0)
|
yuuji@73
|
698 (1- (point))))))
|
yuuji@70
|
699 (t ))
|
yuuji@70
|
700 (if (save-excursion (skip-chars-forward " \t") (looking-at "%"))
|
yuuji@70
|
701 (forward-line 1))
|
yuuji@80
|
702 (cond
|
yuuji@80
|
703 ((stringp alreadysought)
|
yuuji@80
|
704 (put 'YaTeX::ref-getset-label 'foundpoint foundpoint) ;ugly...
|
yuuji@80
|
705 alreadysought)
|
yuuji@80
|
706 ((and (null alreadysought)
|
yuuji@80
|
707 (> boundary (point))
|
yuuji@80
|
708 (save-excursion
|
yuuji@80
|
709 (YaTeX-re-search-active-forward
|
yuuji@80
|
710 ;;(concat "\\(" labelholder "\\)\\|\\(" boundary "\\)")
|
yuuji@80
|
711 labelholder
|
yuuji@80
|
712 (regexp-quote YaTeX-comment-prefix)
|
yuuji@80
|
713 boundary 1))
|
yuuji@80
|
714 (match-beginning 0))
|
yuuji@70
|
715 ;; if \label{hoge} found, return it
|
yuuji@80
|
716 (put 'YaTeX::ref-getset-label 'foundpoint (1- (match-beginning 0)))
|
yuuji@80
|
717 (buffer-substring
|
yuuji@80
|
718 (progn
|
yuuji@80
|
719 (goto-char (match-end 0))
|
yuuji@80
|
720 (skip-chars-forward "^{") (1+ (point)))
|
yuuji@80
|
721 (progn
|
yuuji@80
|
722 (forward-sexp 1) (1- (point)))))
|
yuuji@70
|
723 ;;else make a label
|
yuuji@73
|
724 ;(goto-char (match-beginning 0))
|
yuuji@80
|
725 (noset nil) ;do not set label if noset
|
yuuji@80
|
726 (t
|
yuuji@77
|
727 (goto-char inspoint)
|
yuuji@70
|
728 (skip-chars-backward " \t\n")
|
yuuji@80
|
729 (save-excursion
|
yuuji@80
|
730 (setq newlabel
|
yuuji@80
|
731 (funcall YaTeX-ref-generate-label-function command arg)))
|
yuuji@70
|
732 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
|
yuuji@70
|
733 (if mathp nil
|
yuuji@70
|
734 (insert "\n")
|
yuuji@70
|
735 (YaTeX-reindent cc))
|
yuuji@70
|
736 (insert (format "\\label{%s}" newlabel))
|
yuuji@80
|
737 newlabel)))))
|
yuuji@70
|
738
|
yuuji@80
|
739 (defvar YaTeX::ref-labeling-regexp-alist-default
|
yuuji@80
|
740 '(("\\\\begin{\\(java\\|program\\)}{\\([^}]+\\)}" . 2)
|
yuuji@80
|
741 ("\\\\label{\\([^}]+\\)}" . 1))
|
yuuji@80
|
742 "Alist of labeling regexp vs. its group number points to label string.
|
yuuji@80
|
743 This alist is used in \\ref's argument's completion.")
|
yuuji@80
|
744 (defvar YaTeX::ref-labeling-regexp-alist-private nil
|
yuuji@80
|
745 "*Private extesion to YaTeX::ref-labeling-regexp-alist.
|
yuuji@80
|
746 See the documetation of YaTeX::ref-labeling-regexp-alist.")
|
yuuji@70
|
747 (defvar YaTeX::ref-labeling-regexp-alist
|
yuuji@80
|
748 (append YaTeX::ref-labeling-regexp-alist-default
|
yuuji@80
|
749 YaTeX::ref-labeling-regexp-alist-private))
|
yuuji@70
|
750 (defvar YaTeX::ref-labeling-regexp
|
yuuji@70
|
751 (mapconcat 'car YaTeX::ref-labeling-regexp-alist "\\|"))
|
yuuji@70
|
752 (defvar YaTeX::ref-mathenv-regexp
|
yuuji@80
|
753 ;; See also YaTeX-ams-math-begin-alist in yatex.el
|
yuuji@80
|
754 ;; Define only envs which has counter.(without *)
|
yuuji@80
|
755 "equation\\|eqnarray\\|align\\(at\\)?\\|flalign\\|gather\\|xx?alignat\\|multline")
|
yuuji@80
|
756 (defvar YaTeX::ref-mathenv-exp1-regexp
|
yuuji@80
|
757 "\\(equation\\|multline\\)\\b"
|
yuuji@80
|
758 "*Regexp of math-envname which has only one math-expression.")
|
yuuji@70
|
759 (defvar YaTeX::ref-enumerateenv-regexp
|
yuuji@70
|
760 "enumerate")
|
yuuji@80
|
761 (defvar YaTeX::ref-nestable-counter-regexp
|
yuuji@80
|
762 "subequations")
|
yuuji@70
|
763
|
yuuji@70
|
764 (defvar YaTeX::ref-labeling-section-level 2
|
yuuji@72
|
765 "*ref補完で収集するセクショニングコマンドの下限レベル
|
yuuji@70
|
766 YaTeX-sectioning-levelの数値で指定.")
|
yuuji@70
|
767
|
yuuji@80
|
768 (defun YaTeX::ref (argp &optional labelcmd refcmd predf)
|
yuuji@70
|
769 (setplist 'YaTeX::ref-labeling-regexp nil) ;erase memory cache
|
yuuji@70
|
770 (require 'yatexsec)
|
yuuji@11
|
771 (cond
|
yuuji@11
|
772 ((= argp 1)
|
yuuji@80
|
773 (let*((lnum 0) m0 e0 x cmd label match-point point-list boundary
|
yuuji@70
|
774 (buf (current-buffer))
|
yuuji@70
|
775 (llv YaTeX::ref-labeling-section-level)
|
yuuji@80
|
776 (mathenvs YaTeX::ref-mathenv-regexp) envname endrx
|
yuuji@70
|
777 (enums YaTeX::ref-enumerateenv-regexp)
|
yuuji@70
|
778 (counter
|
yuuji@70
|
779 (or labelcmd
|
yuuji@70
|
780 (concat
|
yuuji@70
|
781 YaTeX-ec-regexp "\\(\\("
|
yuuji@70
|
782 (mapconcat
|
yuuji@70
|
783 'concat
|
yuuji@70
|
784 (delq nil
|
yuuji@70
|
785 (mapcar
|
yuuji@72
|
786 (function
|
yuuji@72
|
787 (lambda (s)
|
yuuji@72
|
788 (if (>= llv (cdr s))
|
yuuji@72
|
789 (car s))))
|
yuuji@70
|
790 YaTeX-sectioning-level))
|
yuuji@70
|
791 "\\|")
|
yuuji@77
|
792 "\\|caption\\(\\[[^]]+\\]\\)?\\|footnote\\){"
|
yuuji@80
|
793 "\\|\\(begin{\\(" mathenvs "\\|" enums "\\)}\\)"
|
yuuji@80
|
794 (if YaTeX-use-AMS-LaTeX
|
yuuji@80
|
795 (concat
|
yuuji@80
|
796 "\\|\\(begin{"
|
yuuji@80
|
797 YaTeX::ref-nestable-counter-regexp "}\\)"))
|
yuuji@80
|
798 "\\)")))
|
yuuji@70
|
799 (regexp (concat "\\(" counter
|
yuuji@70
|
800 "\\)\\|\\(" YaTeX::ref-labeling-regexp "\\)"))
|
yuuji@70
|
801 (itemsep (concat YaTeX-ec-regexp
|
yuuji@70
|
802 "\\(\\(bib\\)?item\\|begin\\|end\\)"))
|
yuuji@86
|
803 (refcmd (or refcmd "\\(page\\)?ref"))
|
yuuji@70
|
804 (p (point)) initl line cf
|
yuuji@70
|
805 (percent (regexp-quote YaTeX-comment-prefix))
|
yuuji@70
|
806 (output
|
yuuji@70
|
807 (function
|
yuuji@70
|
808 (lambda (label p)
|
yuuji@80
|
809 (while (setq x (string-match "[\n\t]" label))
|
yuuji@70
|
810 (aset label x ? ))
|
yuuji@80
|
811 (while (setq x (string-match " +" label))
|
yuuji@70
|
812 (setq label (concat
|
yuuji@70
|
813 (substring label 0 (1+ (match-beginning 0)))
|
yuuji@70
|
814 (substring label (match-end 0)))))
|
yuuji@70
|
815 (princ (format "%c: <<%s>>\n" (+ (% lnum 26) ?A) label))
|
yuuji@70
|
816 (setq point-list (cons p point-list))
|
yuuji@70
|
817 (message "Collecting labels... %d" lnum)
|
yuuji@70
|
818 (setq lnum (1+ lnum)))))
|
yuuji@80
|
819 (me (if (boundp 'me) me 'YaTeX::ref))
|
yuuji@70
|
820 )
|
yuuji@60
|
821 (message "Collecting labels...")
|
yuuji@60
|
822 (save-window-excursion
|
yuuji@60
|
823 (YaTeX-showup-buffer
|
yuuji@60
|
824 YaTeX-label-buffer (function (lambda (x) (window-width x))))
|
yuuji@60
|
825 (if (fboundp 'select-frame) (setq cf (selected-frame)))
|
yuuji@60
|
826 (if (eq (window-buffer (minibuffer-window)) buf)
|
yuuji@60
|
827 (progn
|
yuuji@60
|
828 (other-window 1)
|
yuuji@60
|
829 (setq buf (current-buffer))
|
yuuji@70
|
830 (set-buffer buf)))
|
yuuji@60
|
831 (save-excursion
|
yuuji@69
|
832 (set-buffer (get-buffer-create YaTeX-label-buffer))
|
yuuji@80
|
833 (condition-case ()
|
yuuji@80
|
834 (if (and YaTeX-use-font-lock (fboundp 'font-lock-mode))
|
yuuji@80
|
835 (font-lock-mode 1))
|
yuuji@80
|
836 (error nil))
|
yuuji@69
|
837 (setq buffer-read-only nil)
|
yuuji@69
|
838 (erase-buffer))
|
yuuji@69
|
839 (save-excursion
|
yuuji@70
|
840 (set-buffer buf)
|
yuuji@60
|
841 (goto-char (point-min))
|
yuuji@80
|
842 (let ((standard-output (get-buffer YaTeX-label-buffer)) existlabel)
|
yuuji@60
|
843 (princ (format "=== LABELS in [%s] ===\n" (buffer-name buf)))
|
yuuji@48
|
844 (while (YaTeX-re-search-active-forward
|
yuuji@70
|
845 regexp ;;counter
|
yuuji@70
|
846 percent nil t)
|
yuuji@70
|
847 ;(goto-char (match-beginning 0))
|
yuuji@70
|
848 (setq e0 (match-end 0))
|
yuuji@70
|
849 (cond
|
yuuji@80
|
850 ;;
|
yuuji@80
|
851 ;;2005/10/21 Skip it if predicate function returns nil
|
yuuji@80
|
852 ((and predf
|
yuuji@80
|
853 (let ((md (match-data)))
|
yuuji@80
|
854 (prog1
|
yuuji@80
|
855 (condition-case nil
|
yuuji@80
|
856 (not (funcall predf))
|
yuuji@80
|
857 (error nil))
|
yuuji@80
|
858 (store-match-data md)))))
|
yuuji@73
|
859 ((YaTeX-literal-p) nil)
|
yuuji@72
|
860 ((YaTeX-match-string 1)
|
yuuji@70
|
861 ;;if standard counter commands found
|
yuuji@80
|
862 (setq cmd (YaTeX-match-string 2)
|
yuuji@80
|
863 m0 (match-beginning 0))
|
yuuji@70
|
864 (setq match-point (match-beginning 0))
|
yuuji@70
|
865 (or initl
|
yuuji@70
|
866 (if (< p (point)) (setq initl lnum)))
|
yuuji@70
|
867 (cond
|
yuuji@80
|
868 ;; In any case, variables e0 should be set
|
yuuji@80
|
869 ((and YaTeX-use-AMS-LaTeX
|
yuuji@80
|
870 (string-match YaTeX::ref-nestable-counter-regexp cmd))
|
yuuji@80
|
871 (let (label)
|
yuuji@80
|
872 (skip-chars-forward "}")
|
yuuji@80
|
873 (setq label (buffer-substring
|
yuuji@80
|
874 (point) (min (+ 80 (point)) (point-max))))
|
yuuji@80
|
875 ;; to skip (maybe)auto-generated comment
|
yuuji@80
|
876 (skip-chars-forward " \t")
|
yuuji@80
|
877 (if (looking-at YaTeX-comment-prefix)
|
yuuji@80
|
878 (forward-line 1))
|
yuuji@80
|
879 (setq e0 (point))
|
yuuji@80
|
880 (skip-chars-forward " \t\n")
|
yuuji@80
|
881 (if (looking-at "\\\\label{\\([^}]+\\)}")
|
yuuji@80
|
882 (setq label (format "(labe:%s)" (YaTeX-match-string 1))
|
yuuji@80
|
883 e0 (match-end 1)))
|
yuuji@80
|
884 (funcall output (format "--subequation--%s" label) e0)))
|
yuuji@70
|
885 ((string-match mathenvs cmd) ;;if matches mathematical env
|
yuuji@70
|
886 ;(skip-chars-forward "} \t\n")
|
yuuji@80
|
887 ;(forward-line 1) ;2004/1/25
|
yuuji@80
|
888 (skip-chars-forward "}")
|
yuuji@80
|
889 (setq x (point)
|
yuuji@80
|
890 envname (substring
|
yuuji@80
|
891 cmd (match-beginning 0) (match-end 0)))
|
yuuji@80
|
892 (save-restriction
|
yuuji@80
|
893 (narrow-to-region
|
yuuji@80
|
894 m0
|
yuuji@80
|
895 (save-excursion
|
yuuji@80
|
896 (YaTeX-re-search-active-forward
|
yuuji@80
|
897 (setq endrx (format "%send{%s}" YaTeX-ec-regexp
|
yuuji@80
|
898 (regexp-quote envname)))
|
yuuji@80
|
899 percent nil t)))
|
yuuji@80
|
900 (catch 'scan
|
yuuji@80
|
901 (while (YaTeX-re-search-active-forward
|
yuuji@80
|
902 (concat
|
yuuji@80
|
903 "\\\\end{\\(" (regexp-quote envname) "\\)";;(1)
|
yuuji@80
|
904 (if YaTeX-use-AMS-LaTeX
|
yuuji@80
|
905 "\\|\\\\\\(notag\\)") ;;2
|
yuuji@80
|
906 (if (string-match
|
yuuji@80
|
907 YaTeX::ref-mathenv-exp1-regexp cmd)
|
yuuji@80
|
908 "" "\\|\\\\\\\\$")
|
yuuji@80
|
909 )
|
yuuji@80
|
910 percent nil t)
|
yuuji@80
|
911 (let*((quit (match-beginning 1))
|
yuuji@80
|
912 (notag (match-beginning 2))
|
yuuji@80
|
913 (label ".......................") l2
|
yuuji@80
|
914 (e (point)) (m0 (match-beginning 0))
|
yuuji@80
|
915 (ln (YaTeX-string-width label)))
|
yuuji@80
|
916 (cond
|
yuuji@80
|
917 (notag
|
yuuji@80
|
918 (YaTeX-re-search-active-forward
|
yuuji@80
|
919 "\\\\\\\\" percent nil 1)
|
yuuji@80
|
920 (setq x (point)))
|
yuuji@80
|
921 (t
|
yuuji@80
|
922 (if (YaTeX-re-search-active-backward
|
yuuji@80
|
923 YaTeX::ref-labeling-regexp
|
yuuji@80
|
924 percent x t)
|
yuuji@80
|
925 ;; if \label{x} in math-expression, display it
|
yuuji@80
|
926 ;; because formula source is hard to recognize
|
yuuji@80
|
927 (progn
|
yuuji@80
|
928 (goto-char (match-end 0))
|
yuuji@80
|
929 (setq l2 (format "\"label:%s\""
|
yuuji@80
|
930 (buffer-substring
|
yuuji@80
|
931 (1- (point))
|
yuuji@80
|
932 (progn (forward-sexp -1)
|
yuuji@80
|
933 (1+ (point))))))
|
yuuji@80
|
934 (setq label
|
yuuji@80
|
935 (if (< (YaTeX-string-width l2) ln)
|
yuuji@80
|
936 (concat
|
yuuji@80
|
937 l2
|
yuuji@80
|
938 (substring
|
yuuji@80
|
939 label
|
yuuji@80
|
940 0 (- ln (YaTeX-string-width l2))))
|
yuuji@80
|
941 l2))
|
yuuji@80
|
942 (goto-char e)))
|
yuuji@80
|
943 (funcall output
|
yuuji@80
|
944 (concat
|
yuuji@80
|
945 label " "
|
yuuji@80
|
946 (buffer-substring x m0))
|
yuuji@80
|
947 x)
|
yuuji@80
|
948 (cond
|
yuuji@80
|
949 ((YaTeX-quick-in-environment-p
|
yuuji@80
|
950 YaTeX-math-gathering-list)
|
yuuji@80
|
951 ;; if here is inner split/cases/gathered env.,
|
yuuji@80
|
952 ;; counter for here is only one.
|
yuuji@80
|
953 ;; Go out this environment and,
|
yuuji@80
|
954 (YaTeX-end-of-environment)
|
yuuji@80
|
955 ;; search next expression unit boundary.
|
yuuji@80
|
956 (YaTeX-re-search-active-forward
|
yuuji@80
|
957 (concat endrx "\\|\\\\begin{")
|
yuuji@80
|
958 percent nil 1)
|
yuuji@80
|
959 (end-of-line)))
|
yuuji@80
|
960 (if quit (throw 'scan t)))))
|
yuuji@80
|
961 (setq x (point)))))
|
yuuji@70
|
962 (setq e0 (point)))
|
yuuji@70
|
963 ((string-match enums cmd)
|
yuuji@70
|
964 ;(skip-chars-forward "} \t\n")
|
yuuji@70
|
965 (save-restriction
|
yuuji@70
|
966 (narrow-to-region
|
yuuji@70
|
967 (point)
|
yuuji@70
|
968 (save-excursion
|
yuuji@70
|
969 (YaTeX-goto-corresponding-environment) (point)))
|
yuuji@70
|
970 (forward-line 1)
|
yuuji@70
|
971 (while (YaTeX-re-search-active-forward
|
yuuji@70
|
972 (concat YaTeX-ec-regexp "item\\s ")
|
yuuji@70
|
973 percent nil t)
|
yuuji@70
|
974 (setq x (match-beginning 0))
|
yuuji@70
|
975 (funcall
|
yuuji@70
|
976 output
|
yuuji@80
|
977 (concat
|
yuuji@80
|
978 existlabel
|
yuuji@80
|
979 (buffer-substring
|
yuuji@80
|
980 (match-beginning 0)
|
yuuji@80
|
981 (if (re-search-forward itemsep nil t)
|
yuuji@80
|
982 (progn (goto-char (match-beginning 0))
|
yuuji@80
|
983 (skip-chars-backward " \t")
|
yuuji@80
|
984 (1- (point)))
|
yuuji@80
|
985 (point-end-of-line))))
|
yuuji@77
|
986 x))
|
yuuji@77
|
987 (setq e0 (point-max))))
|
yuuji@80
|
988 ((string-match "bibitem" cmd) ;maybe generated by myself
|
yuuji@80
|
989 (setq label "")
|
yuuji@80
|
990 (skip-chars-forward " \t")
|
yuuji@80
|
991 (if (looking-at "{") ;sure to be true!!
|
yuuji@80
|
992 (forward-list 1))
|
yuuji@80
|
993 (let ((list '(30 10 65))
|
yuuji@80
|
994 (delim ";") q lim len l str)
|
yuuji@80
|
995 (save-excursion
|
yuuji@80
|
996 (setq lim (if (re-search-forward itemsep nil 1)
|
yuuji@80
|
997 (match-beginning 0) (point))))
|
yuuji@80
|
998 (while list
|
yuuji@80
|
999 (skip-chars-forward " \t\n\\")
|
yuuji@80
|
1000 (setq q (looking-at "[\"'{]")
|
yuuji@80
|
1001 len (car list)
|
yuuji@80
|
1002 str
|
yuuji@80
|
1003 (buffer-substring
|
yuuji@80
|
1004 (point)
|
yuuji@80
|
1005 (progn
|
yuuji@80
|
1006 (if q (forward-sexp 1)
|
yuuji@80
|
1007 (search-forward delim lim 1)
|
yuuji@80
|
1008 (forward-char -1))
|
yuuji@80
|
1009 (point))))
|
yuuji@80
|
1010 (if (> (setq l (YaTeX-string-width str)) len)
|
yuuji@80
|
1011 (setq str (concat
|
yuuji@80
|
1012 (YaTeX-truncate-string-width
|
yuuji@80
|
1013 str (- len (if q 5 4)))
|
yuuji@80
|
1014 "... "
|
yuuji@80
|
1015 (if q (substring str -1)))))
|
yuuji@80
|
1016 (if (< (setq l (YaTeX-string-width str)) len)
|
yuuji@80
|
1017 (setq str (concat str (make-string (- len l) ? ))))
|
yuuji@80
|
1018 (if (looking-at delim) (goto-char (match-end 0)))
|
yuuji@80
|
1019 (setq label (concat label " " str)
|
yuuji@80
|
1020 list (cdr list)))
|
yuuji@80
|
1021 (funcall output label match-point)))
|
yuuji@77
|
1022 ;;else, simple section-type counter
|
yuuji@70
|
1023 ((= (char-after (1- (point))) ?{)
|
yuuji@70
|
1024 (setq label (buffer-substring
|
yuuji@70
|
1025 (match-beginning 0)
|
yuuji@70
|
1026 (progn (forward-char -1)
|
yuuji@70
|
1027 (forward-list 1)
|
yuuji@70
|
1028 (point))))
|
yuuji@77
|
1029 (funcall output label match-point)
|
yuuji@77
|
1030 ;; Skip preceding label if exists
|
yuuji@80
|
1031 (if (YaTeX::ref-getset-label (current-buffer) match-point t)
|
yuuji@80
|
1032 (goto-char (get 'YaTeX::ref-getset-label 'foundpoint)))
|
yuuji@77
|
1033 (if (save-excursion
|
yuuji@77
|
1034 (skip-chars-forward "\t \n")
|
yuuji@77
|
1035 (looking-at YaTeX::ref-labeling-regexp))
|
yuuji@77
|
1036 (setq e0 (match-end 0))))
|
yuuji@70
|
1037 (t
|
yuuji@70
|
1038 (skip-chars-forward " \t")
|
yuuji@70
|
1039 (setq label (buffer-substring
|
yuuji@70
|
1040 (match-beginning 0)
|
yuuji@70
|
1041 (if (re-search-forward
|
yuuji@70
|
1042 itemsep
|
yuuji@70
|
1043 nil t)
|
yuuji@70
|
1044 (progn
|
yuuji@70
|
1045 (goto-char (match-beginning 0))
|
yuuji@70
|
1046 (skip-chars-backward " \t")
|
yuuji@70
|
1047 (1- (point)))
|
yuuji@70
|
1048 (point-end-of-line))))
|
yuuji@70
|
1049 (funcall output label match-point)
|
yuuji@77
|
1050 (if (save-excursion
|
yuuji@77
|
1051 (skip-chars-forward "\t \n")
|
yuuji@77
|
1052 (looking-at YaTeX::ref-labeling-regexp))
|
yuuji@77
|
1053 (setq e0 (match-end 0)))))
|
yuuji@70
|
1054 ) ;;put label buffer
|
yuuji@70
|
1055 ;;
|
yuuji@70
|
1056 ;; if user defined label found
|
yuuji@70
|
1057 (t
|
yuuji@70
|
1058 ;; memorize line number and label into property
|
yuuji@70
|
1059 (goto-char (match-beginning 0))
|
yuuji@70
|
1060 (let ((list YaTeX::ref-labeling-regexp-alist)
|
yuuji@70
|
1061 (cache (symbol-plist 'YaTeX::ref-labeling-regexp)))
|
yuuji@70
|
1062 (while list
|
yuuji@70
|
1063 (if (looking-at (car (car list)))
|
yuuji@70
|
1064 (progn
|
yuuji@70
|
1065 (setq label (YaTeX-match-string 0))
|
yuuji@70
|
1066 (put 'YaTeX::ref-labeling-regexp lnum
|
yuuji@70
|
1067 (YaTeX-match-string (cdr (car list))))
|
yuuji@70
|
1068 (funcall output label 0) ;;0 is dummy, never used
|
yuuji@70
|
1069 (setq list nil)))
|
yuuji@70
|
1070 (setq list (cdr list))))
|
yuuji@70
|
1071 ))
|
yuuji@11
|
1072 (goto-char e0))
|
yuuji@11
|
1073 (princ YaTeX-label-menu-other)
|
yuuji@23
|
1074 (princ YaTeX-label-menu-repeat)
|
yuuji@11
|
1075 (princ YaTeX-label-menu-any)
|
yuuji@69
|
1076 );standard-output
|
yuuji@11
|
1077 (goto-char p)
|
yuuji@60
|
1078 (or initl (setq initl lnum))
|
yuuji@70
|
1079 (message "Collecting labels...Done")
|
yuuji@60
|
1080 (if (fboundp 'select-frame) (select-frame cf))
|
yuuji@59
|
1081 (YaTeX-showup-buffer YaTeX-label-buffer nil t)
|
yuuji@11
|
1082 (YaTeX::label-setup-key-map)
|
yuuji@11
|
1083 (setq truncate-lines t)
|
yuuji@11
|
1084 (setq buffer-read-only t)
|
yuuji@11
|
1085 (use-local-map YaTeX-label-select-map)
|
yuuji@11
|
1086 (message YaTeX-label-guide-msg)
|
yuuji@60
|
1087 (goto-line (1+ initl)) ;goto recently defined label line
|
yuuji@68
|
1088 (switch-to-buffer (current-buffer))
|
yuuji@11
|
1089 (unwind-protect
|
yuuji@11
|
1090 (progn
|
yuuji@11
|
1091 (recursive-edit)
|
yuuji@70
|
1092
|
yuuji@11
|
1093 (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
|
yuuji@11
|
1094 (beginning-of-line)
|
yuuji@60
|
1095 (setq line (1- (count-lines (point-min)(point))))
|
yuuji@11
|
1096 (cond
|
yuuji@60
|
1097 ((= line -1) (setq label ""))
|
yuuji@11
|
1098 ((= line lnum) (setq label (YaTeX-label-other)))
|
yuuji@23
|
1099 ((= line (1+ lnum))
|
yuuji@23
|
1100 (save-excursion
|
yuuji@23
|
1101 (switch-to-buffer buf)
|
yuuji@23
|
1102 (goto-char p)
|
yuuji@48
|
1103 (if (re-search-backward
|
yuuji@86
|
1104 (concat "\\\\" refcmd "{") nil t)
|
yuuji@86
|
1105 (setq label (YaTeX-buffer-substring
|
yuuji@86
|
1106 (progn (goto-char (1- (match-end 0)))
|
yuuji@86
|
1107 (1+ (point)))
|
yuuji@86
|
1108 (progn (forward-list 1)
|
yuuji@86
|
1109 (1- (point)))))
|
yuuji@23
|
1110 (setq label ""))))
|
yuuji@23
|
1111 ((>= line (+ lnum 2))
|
yuuji@48
|
1112 (setq label (read-string (format "\\%s{???}: " refcmd))))
|
yuuji@70
|
1113 (t ;(setq label (nth (- lnum line 1) label-list))
|
yuuji@70
|
1114 (setq label
|
yuuji@70
|
1115 (or (get 'YaTeX::ref-labeling-regexp line)
|
yuuji@70
|
1116 (YaTeX::ref-getset-label
|
yuuji@70
|
1117 buf (nth (- lnum line 1) point-list))))
|
yuuji@70
|
1118 )))
|
yuuji@11
|
1119 (bury-buffer YaTeX-label-buffer)))
|
yuuji@69
|
1120 label)))))
|
yuuji@69
|
1121
|
yuuji@16
|
1122 (fset 'YaTeX::pageref 'YaTeX::ref)
|
yuuji@80
|
1123 (defun YaTeX::tabref (argp) ; For the style file of IPSJ journal
|
yuuji@80
|
1124 (YaTeX::ref
|
yuuji@80
|
1125 argp nil nil
|
yuuji@80
|
1126 (function
|
yuuji@80
|
1127 (lambda ()
|
yuuji@80
|
1128 (YaTeX-quick-in-environment-p "table")))))
|
yuuji@80
|
1129 (defun YaTeX::figref (argp) ; For the style file of IPSJ journal
|
yuuji@80
|
1130 (YaTeX::ref
|
yuuji@80
|
1131 argp nil nil
|
yuuji@80
|
1132 (function
|
yuuji@80
|
1133 (lambda ()
|
yuuji@80
|
1134 (YaTeX-quick-in-environment-p "figure")))))
|
yuuji@70
|
1135
|
yuuji@80
|
1136 (defun YaTeX::cite-collect-bibs-external (bibptn &rest files)
|
yuuji@80
|
1137 "Collect bibentry from FILES(variable length argument) ;
|
yuuji@70
|
1138 and print them to standard output."
|
yuuji@70
|
1139 ;;Thanks; http://icarus.ilcs.hokudai.ac.jp/comp/biblio.html
|
yuuji@80
|
1140 (let*((tb (get-buffer-create " *bibtmp*"))
|
yuuji@80
|
1141 (bibitemsep "^\\s *@[A-Za-z]")
|
yuuji@80
|
1142 (target (if (string< "" bibptn) bibptn bibitemsep))
|
yuuji@80
|
1143 (checkrx (concat "\\(" bibptn "\\)\\|" bibitemsep))
|
yuuji@80
|
1144 beg
|
yuuji@80
|
1145 (searchnext
|
yuuji@80
|
1146 (if (string< "" bibptn)
|
yuuji@80
|
1147 (function
|
yuuji@80
|
1148 (lambda()
|
yuuji@80
|
1149 (setq beg (point))
|
yuuji@80
|
1150 (and
|
yuuji@80
|
1151 (prog1
|
yuuji@80
|
1152 (re-search-forward target nil t)
|
yuuji@80
|
1153 (end-of-line))
|
yuuji@80
|
1154 (re-search-backward bibitemsep beg t))))
|
yuuji@80
|
1155 (function
|
yuuji@80
|
1156 (lambda()
|
yuuji@80
|
1157 (re-search-forward target nil t)))))
|
yuuji@80
|
1158 )
|
yuuji@70
|
1159 (save-excursion
|
yuuji@70
|
1160 (set-buffer tb)
|
yuuji@80
|
1161 (princ (format "%sbegin{thebibliography}\n" YaTeX-ec))
|
yuuji@70
|
1162 (while files
|
yuuji@70
|
1163 (erase-buffer)
|
yuuji@70
|
1164 (cond
|
yuuji@70
|
1165 ((file-exists-p (car files))
|
yuuji@70
|
1166 (insert-file-contents (car files)))
|
yuuji@70
|
1167 ((file-exists-p (concat (car files) ".bib"))
|
yuuji@70
|
1168 (insert-file-contents (concat (car files) ".bib"))))
|
yuuji@70
|
1169 (save-excursion
|
yuuji@70
|
1170 (goto-char (point-min))
|
yuuji@80
|
1171 (while (funcall searchnext)
|
yuuji@70
|
1172 (skip-chars-forward "^{,")
|
yuuji@80
|
1173 (setq beg (point))
|
yuuji@70
|
1174 (if (= (char-after (point)) ?{)
|
yuuji@70
|
1175 (princ (format "%sbibitem{%s}%s\n"
|
yuuji@70
|
1176 YaTeX-ec
|
yuuji@70
|
1177 (buffer-substring
|
yuuji@70
|
1178 (1+ (point))
|
yuuji@70
|
1179 (progn (skip-chars-forward "^,\n")
|
yuuji@70
|
1180 (point)))
|
yuuji@80
|
1181 (mapconcat
|
yuuji@80
|
1182 (function
|
yuuji@80
|
1183 (lambda (kwd)
|
yuuji@80
|
1184 (goto-char beg)
|
yuuji@80
|
1185 (if (re-search-forward
|
yuuji@80
|
1186 (concat kwd "\\s *=") nil t)
|
yuuji@80
|
1187 (buffer-substring
|
yuuji@80
|
1188 (progn
|
yuuji@80
|
1189 (goto-char (match-end 0))
|
yuuji@80
|
1190 (skip-chars-forward " \t\n")
|
yuuji@80
|
1191 (point))
|
yuuji@80
|
1192 (progn
|
yuuji@80
|
1193 (if (looking-at "[{\"]")
|
yuuji@80
|
1194 (forward-sexp 1)
|
yuuji@80
|
1195 (forward-char 1)
|
yuuji@80
|
1196 (skip-chars-forward "^,}"))
|
yuuji@80
|
1197 (point))))))
|
yuuji@80
|
1198 '("author" "year" "title" )
|
yuuji@80
|
1199 ";"))))
|
yuuji@80
|
1200 (and (re-search-forward bibitemsep nil t)
|
yuuji@80
|
1201 (forward-line -1))))
|
yuuji@80
|
1202 (setq files (cdr files)))
|
yuuji@80
|
1203 (princ (format "%sbegin{thebibliography}\n" YaTeX-ec)))))
|
yuuji@70
|
1204
|
yuuji@77
|
1205 (defvar YaTeX::cite-bibitem-macro-regexp "bibitem\\|harvarditem"
|
yuuji@77
|
1206 "*Regexp of macro name of bibitem definition")
|
yuuji@77
|
1207
|
yuuji@80
|
1208 (defun YaTeX::cite-collect-bibs-internal (bibptn)
|
yuuji@70
|
1209 "Collect bibentry in the current buffer and print them to standard output."
|
yuuji@77
|
1210 (let ((ptn (concat YaTeX-ec-regexp
|
yuuji@77
|
1211 "\\(" YaTeX::cite-bibitem-macro-regexp "\\)\\b"))
|
yuuji@80
|
1212 (lim (concat YaTeX-ec-regexp
|
yuuji@80
|
1213 "\\(" YaTeX::cite-bibitem-macro-regexp "\\b\\)"
|
yuuji@80
|
1214 "\\|\\(end{\\)"))
|
yuuji@70
|
1215 (pcnt (regexp-quote YaTeX-comment-prefix)))
|
yuuji@80
|
1216 ;; Using bibptn not yet implemented.
|
yuuji@80
|
1217 ;; Do you need it?? 2005/11/22
|
yuuji@70
|
1218 (save-excursion
|
yuuji@70
|
1219 (while (YaTeX-re-search-active-forward ptn pcnt nil t)
|
yuuji@70
|
1220 (skip-chars-forward "^{\n")
|
yuuji@70
|
1221 (or (eolp)
|
yuuji@80
|
1222 (princ (format "%sbibitem%s %s\n"
|
yuuji@70
|
1223 YaTeX-ec
|
yuuji@70
|
1224 (buffer-substring
|
yuuji@80
|
1225 (point)
|
yuuji@80
|
1226 (progn (forward-sexp 1) (point)))
|
yuuji@80
|
1227 (buffer-substring
|
yuuji@80
|
1228 (progn (skip-chars-forward "\n \t") (point))
|
yuuji@80
|
1229 (save-excursion
|
yuuji@80
|
1230 (if (YaTeX-re-search-active-forward
|
yuuji@80
|
1231 lim pcnt nil t)
|
yuuji@80
|
1232 (progn
|
yuuji@80
|
1233 (goto-char (match-beginning 0))
|
yuuji@80
|
1234 (skip-chars-backward "\n \t")
|
yuuji@80
|
1235 (point))
|
yuuji@80
|
1236 (point-end-of-line)))))))))))
|
yuuji@70
|
1237
|
yuuji@80
|
1238 (defun YaTeX::cite (argp &rest dummy)
|
yuuji@48
|
1239 (cond
|
yuuji@48
|
1240 ((eq argp 1)
|
yuuji@70
|
1241 (let* ((cb (current-buffer))
|
yuuji@70
|
1242 (f (file-name-nondirectory buffer-file-name))
|
yuuji@70
|
1243 (d default-directory)
|
yuuji@70
|
1244 (hilit-auto-highlight nil)
|
yuuji@70
|
1245 (pcnt (regexp-quote YaTeX-comment-prefix))
|
yuuji@70
|
1246 (bibrx (concat YaTeX-ec-regexp "bibliography{\\([^}]+\\)}"))
|
yuuji@80
|
1247 (bibptn (read-string "Pattern: "))
|
yuuji@70
|
1248 (bbuf (get-buffer-create " *bibitems*"))
|
yuuji@70
|
1249 (standard-output bbuf)
|
yuuji@80
|
1250 (me 'YaTeX::cite) ;shuld set this for using YaTeX::ref
|
yuuji@70
|
1251 bibs files)
|
yuuji@70
|
1252 (set-buffer bbuf)(erase-buffer)(set-buffer cb)
|
yuuji@70
|
1253 (save-excursion
|
yuuji@70
|
1254 (goto-char (point-min))
|
yuuji@70
|
1255 ;;(1)search external bibdata
|
yuuji@70
|
1256 (while (YaTeX-re-search-active-forward bibrx pcnt nil t)
|
yuuji@70
|
1257 (apply 'YaTeX::cite-collect-bibs-external
|
yuuji@80
|
1258 bibptn
|
yuuji@70
|
1259 (YaTeX-split-string
|
yuuji@70
|
1260 (YaTeX-match-string 1) ",")))
|
yuuji@70
|
1261 ;;(2)search direct \bibitem usage
|
yuuji@80
|
1262 (YaTeX::cite-collect-bibs-internal bibptn)
|
yuuji@70
|
1263 (if (progn
|
yuuji@70
|
1264 (YaTeX-visit-main t)
|
yuuji@70
|
1265 (not (eq (current-buffer) cb)))
|
yuuji@70
|
1266 (save-excursion
|
yuuji@70
|
1267 (goto-char (point-min))
|
yuuji@70
|
1268 ;;(1)search external bibdata
|
yuuji@70
|
1269 (while (YaTeX-re-search-active-forward bibrx pcnt nil t)
|
yuuji@70
|
1270 (apply 'YaTeX::cite-collect-bibs-external
|
yuuji@80
|
1271 bibptn
|
yuuji@70
|
1272 (YaTeX-split-string
|
yuuji@70
|
1273 (YaTeX-match-string 1) ",")))
|
yuuji@70
|
1274 ;;(2)search internal
|
yuuji@80
|
1275 (YaTeX::cite-collect-bibs-internal bibptn)))
|
yuuji@70
|
1276 ;;Now bbuf holds the list of bibitem
|
yuuji@70
|
1277 (set-buffer bbuf)
|
yuuji@80
|
1278 ;;;(switch-to-buffer bbuf)
|
yuuji@80
|
1279 (if (fboundp 'font-lock-fontify-buffer) (font-lock-fontify-buffer))
|
yuuji@77
|
1280 (YaTeX::ref
|
yuuji@77
|
1281 argp
|
yuuji@77
|
1282 (concat "\\\\\\("
|
yuuji@77
|
1283 YaTeX::cite-bibitem-macro-regexp
|
yuuji@77
|
1284 "\\)\\(\\[.*\\]\\)?")
|
yuuji@77
|
1285 "cite"))))
|
yuuji@77
|
1286
|
yuuji@48
|
1287 (t nil)))
|
yuuji@11
|
1288
|
yuuji@77
|
1289 ;;; for AMS-LaTeX
|
yuuji@70
|
1290 (and YaTeX-use-AMS-LaTeX (fset 'YaTeX::eqref 'YaTeX::ref))
|
yuuji@77
|
1291 ;;; for Harvard citation style
|
yuuji@77
|
1292 (fset 'YaTeX::citeasnoun 'YaTeX::cite)
|
yuuji@77
|
1293 (fset 'YaTeX::possessivecite 'YaTeX::cite)
|
yuuji@77
|
1294 (fset 'YaTeX::citeyear 'YaTeX::cite)
|
yuuji@77
|
1295 (fset 'YaTeX::citename 'YaTeX::cite)
|
yuuji@80
|
1296 (fset 'YaTeX::citep 'YaTeX::cite)
|
yuuji@80
|
1297 (fset 'YaTeX::citet 'YaTeX::cite)
|
yuuji@70
|
1298
|
yuuji@48
|
1299 (defun YaTeX-yatex-buffer-list ()
|
yuuji@48
|
1300 (save-excursion
|
yuuji@48
|
1301 (delq nil (mapcar (function (lambda (buf)
|
yuuji@48
|
1302 (set-buffer buf)
|
yuuji@48
|
1303 (if (eq major-mode 'yatex-mode) buf)))
|
yuuji@69
|
1304 (buffer-list)))))
|
yuuji@48
|
1305
|
yuuji@48
|
1306 (defun YaTeX-select-other-yatex-buffer ()
|
yuuji@48
|
1307 "Select buffer from all yatex-mode's buffers interactivelly."
|
yuuji@48
|
1308 (interactive)
|
yuuji@48
|
1309 (let ((lbuf "*YaTeX mode buffers*") (blist (YaTeX-yatex-buffer-list))
|
yuuji@48
|
1310 (lnum -1) buf rv
|
yuuji@11
|
1311 (ff "**find-file**"))
|
yuuji@12
|
1312 (YaTeX-showup-buffer
|
yuuji@12
|
1313 lbuf (function (lambda (x) 1))) ;;Select next window surely.
|
yuuji@69
|
1314 (save-excursion
|
yuuji@69
|
1315 (set-buffer (get-buffer lbuf))
|
yuuji@69
|
1316 (setq buffer-read-only nil)
|
yuuji@69
|
1317 (erase-buffer))
|
yuuji@69
|
1318 (let ((standard-output (get-buffer lbuf)))
|
yuuji@11
|
1319 (while blist
|
yuuji@48
|
1320 (princ
|
yuuji@48
|
1321 (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A)
|
yuuji@48
|
1322 (buffer-name (car blist))))
|
yuuji@11
|
1323 (setq blist (cdr blist)))
|
yuuji@11
|
1324 (princ (format "':{%s}" ff)))
|
yuuji@59
|
1325 (YaTeX-showup-buffer lbuf nil t)
|
yuuji@11
|
1326 (YaTeX::label-setup-key-map)
|
yuuji@11
|
1327 (setq buffer-read-only t)
|
yuuji@11
|
1328 (use-local-map YaTeX-label-select-map)
|
yuuji@11
|
1329 (message YaTeX-label-guide-msg)
|
yuuji@11
|
1330 (unwind-protect
|
yuuji@11
|
1331 (progn
|
yuuji@11
|
1332 (recursive-edit)
|
yuuji@11
|
1333 (set-buffer lbuf)
|
yuuji@11
|
1334 (beginning-of-line)
|
yuuji@11
|
1335 (setq rv
|
yuuji@11
|
1336 (if (re-search-forward "{\\([^\\}]+\\)}" (point-end-of-line) t)
|
yuuji@11
|
1337 (buffer-substring (match-beginning 1) (match-end 1)) nil)))
|
yuuji@11
|
1338 (kill-buffer lbuf))
|
yuuji@48
|
1339 (if (string= rv ff)
|
yuuji@48
|
1340 (progn
|
yuuji@48
|
1341 (call-interactively 'find-file)
|
yuuji@48
|
1342 (current-buffer))
|
yuuji@69
|
1343 rv)))
|
yuuji@48
|
1344
|
yuuji@48
|
1345 (defun YaTeX-label-other ()
|
yuuji@48
|
1346 (let ((rv (YaTeX-select-other-yatex-buffer)))
|
yuuji@11
|
1347 (cond
|
yuuji@11
|
1348 ((null rv) "")
|
yuuji@11
|
1349 (t
|
yuuji@11
|
1350 (set-buffer rv)
|
yuuji@80
|
1351 (funcall me argp labelcmd refcmd)))))
|
yuuji@11
|
1352
|
yuuji@13
|
1353 ;;
|
yuuji@13
|
1354 ; completion for the arguments of \newcommand
|
yuuji@13
|
1355 ;;
|
yuuji@13
|
1356 (defun YaTeX::newcommand (&optional argp)
|
yuuji@13
|
1357 (cond
|
yuuji@13
|
1358 ((= argp 1)
|
yuuji@13
|
1359 (let ((command (read-string "Define newcommand: " "\\")))
|
yuuji@13
|
1360 (put 'YaTeX::newcommand 'command (substring command 1))
|
yuuji@13
|
1361 command))
|
yuuji@13
|
1362 ((= argp 2)
|
yuuji@13
|
1363 (let ((argc
|
yuuji@13
|
1364 (string-to-int (read-string "Number of arguments(Default 0): ")))
|
yuuji@13
|
1365 (def (read-string "Definition: "))
|
yuuji@13
|
1366 (command (get 'YaTeX::newcommand 'command)))
|
yuuji@13
|
1367 ;;!!! It's illegal to insert string in the add-in function !!!
|
yuuji@13
|
1368 (if (> argc 0) (insert (format "[%d]" argc)))
|
yuuji@13
|
1369 (if (and (stringp command)
|
yuuji@13
|
1370 (string< "" command)
|
yuuji@51
|
1371 (y-or-n-p "Update dictionary?"))
|
yuuji@18
|
1372 (cond
|
yuuji@18
|
1373 ((= argc 0)
|
yuuji@18
|
1374 (YaTeX-update-table
|
yuuji@18
|
1375 (list command)
|
yuuji@18
|
1376 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table))
|
yuuji@18
|
1377 ((= argc 1)
|
yuuji@18
|
1378 (YaTeX-update-table
|
yuuji@18
|
1379 (list command)
|
yuuji@18
|
1380 'section-table 'user-section-table 'tmp-section-table))
|
yuuji@18
|
1381 (t (YaTeX-update-table
|
yuuji@18
|
1382 (list command argc)
|
yuuji@18
|
1383 'section-table 'user-section-table 'tmp-section-table))))
|
yuuji@13
|
1384 (message "")
|
yuuji@13
|
1385 def ;return command name
|
yuuji@13
|
1386 ))
|
yuuji@69
|
1387 (t "")))
|
yuuji@13
|
1388
|
yuuji@80
|
1389 (defun YaTeX::newcounter (&optional argp)
|
yuuji@80
|
1390 (cond
|
yuuji@80
|
1391 ((= argp 1)
|
yuuji@80
|
1392 (read-string "New counter name: "))
|
yuuji@80
|
1393 (t "")))
|
yuuji@80
|
1394
|
yuuji@16
|
1395 ;;
|
yuuji@16
|
1396 ; completion for the arguments of \pagestyle
|
yuuji@16
|
1397 ;;
|
yuuji@16
|
1398 (defun YaTeX::pagestyle (&optional argp)
|
yuuji@16
|
1399 "Read the pagestyle with completion."
|
yuuji@16
|
1400 (completing-read
|
yuuji@16
|
1401 "Page style: "
|
yuuji@69
|
1402 '(("plain") ("empty") ("headings") ("myheadings") ("normal") nil)))
|
yuuji@69
|
1403
|
yuuji@51
|
1404 (fset 'YaTeX::thispagestyle 'YaTeX::pagestyle)
|
yuuji@51
|
1405
|
yuuji@16
|
1406 ;;
|
yuuji@16
|
1407 ; completion for the arguments of \pagenumbering
|
yuuji@16
|
1408 ;;
|
yuuji@16
|
1409 (defun YaTeX::pagenumbering (&optional argp)
|
yuuji@16
|
1410 "Read the numbering style."
|
yuuji@16
|
1411 (completing-read
|
yuuji@16
|
1412 "Page numbering style: "
|
yuuji@69
|
1413 '(("arabic") ("Alpha") ("alpha") ("Roman") ("roman"))))
|
yuuji@13
|
1414
|
yuuji@23
|
1415 ;;
|
yuuji@23
|
1416 ; Length
|
yuuji@23
|
1417 ;;
|
yuuji@23
|
1418 (defvar YaTeX:style-parameters-default
|
yuuji@23
|
1419 '(("\\arraycolsep")
|
yuuji@23
|
1420 ("\\arrayrulewidth")
|
yuuji@23
|
1421 ("\\baselineskip")
|
yuuji@23
|
1422 ("\\columnsep")
|
yuuji@23
|
1423 ("\\columnseprule")
|
yuuji@23
|
1424 ("\\doublerulesep")
|
yuuji@23
|
1425 ("\\evensidemargin")
|
yuuji@23
|
1426 ("\\footheight")
|
yuuji@23
|
1427 ("\\footskip")
|
yuuji@23
|
1428 ("\\headheight")
|
yuuji@23
|
1429 ("\\headsep")
|
yuuji@23
|
1430 ("\\itemindent")
|
yuuji@23
|
1431 ("\\itemsep")
|
yuuji@23
|
1432 ("\\labelsep")
|
yuuji@23
|
1433 ("\\labelwidth")
|
yuuji@23
|
1434 ("\\leftmargin")
|
yuuji@23
|
1435 ("\\linewidth")
|
yuuji@23
|
1436 ("\\listparindent")
|
yuuji@23
|
1437 ("\\marginparsep")
|
yuuji@23
|
1438 ("\\marginparwidth")
|
yuuji@23
|
1439 ("\\mathindent")
|
yuuji@23
|
1440 ("\\oddsidemargin")
|
yuuji@23
|
1441 ("\\parindent")
|
yuuji@23
|
1442 ("\\parsep")
|
yuuji@23
|
1443 ("\\parskip")
|
yuuji@23
|
1444 ("\\partopsep")
|
yuuji@23
|
1445 ("\\rightmargin")
|
yuuji@23
|
1446 ("\\tabcolsep")
|
yuuji@23
|
1447 ("\\textheight")
|
yuuji@23
|
1448 ("\\textwidth")
|
yuuji@23
|
1449 ("\\topmargin")
|
yuuji@23
|
1450 ("\\topsep")
|
yuuji@23
|
1451 ("\\topskip")
|
yuuji@23
|
1452 )
|
yuuji@23
|
1453 "Alist of LaTeX style parameters.")
|
yuuji@23
|
1454 (defvar YaTeX:style-parameters-private nil
|
yuuji@23
|
1455 "*User definable alist of style parameters.")
|
yuuji@49
|
1456 (defvar YaTeX:style-parameters-local nil
|
yuuji@49
|
1457 "*User definable alist of local style parameters.")
|
yuuji@23
|
1458
|
yuuji@23
|
1459 (defvar YaTeX:length-history nil "Holds history of length.")
|
yuuji@51
|
1460 (put 'YaTeX:length-history 'no-default t)
|
yuuji@23
|
1461 (defun YaTeX::setlength (&optional argp)
|
yuuji@23
|
1462 "YaTeX add-in function for arguments of \\setlength."
|
yuuji@23
|
1463 (cond
|
yuuji@23
|
1464 ((equal 1 argp)
|
yuuji@49
|
1465 ;;(completing-read "Length variable: " YaTeX:style-parameters nil nil "\\")
|
yuuji@49
|
1466 (YaTeX-cplread-with-learning
|
yuuji@49
|
1467 "Length variable: "
|
yuuji@49
|
1468 'YaTeX:style-parameters-default
|
yuuji@49
|
1469 'YaTeX:style-parameters-private
|
yuuji@49
|
1470 'YaTeX:style-parameters-local
|
yuuji@49
|
1471 nil nil "\\")
|
yuuji@49
|
1472 )
|
yuuji@23
|
1473 ((equal 2 argp)
|
yuuji@69
|
1474 (read-string-with-history "Length: " nil 'YaTeX:length-history))))
|
yuuji@69
|
1475
|
yuuji@23
|
1476 (fset 'YaTeX::addtolength 'YaTeX::setlength)
|
yuuji@23
|
1477
|
yuuji@23
|
1478 (defun YaTeX::settowidth (&optional argp)
|
yuuji@23
|
1479 "YaTeX add-in function for arguments of \\settowidth."
|
yuuji@23
|
1480 (cond
|
yuuji@23
|
1481 ((equal 1 argp)
|
yuuji@49
|
1482 (YaTeX-cplread-with-learning
|
yuuji@49
|
1483 "Length variable: "
|
yuuji@49
|
1484 'YaTeX:style-parameters-default
|
yuuji@49
|
1485 'YaTeX:style-parameters-private
|
yuuji@49
|
1486 'YaTeX:style-parameters-local
|
yuuji@49
|
1487 nil nil "\\"))
|
yuuji@23
|
1488 ((equal 2 argp)
|
yuuji@69
|
1489 (read-string "Text: "))))
|
yuuji@69
|
1490
|
yuuji@23
|
1491 (defun YaTeX::newlength (&optional argp)
|
yuuji@23
|
1492 "YaTeX add-in function for arguments of \\newlength"
|
yuuji@23
|
1493 (cond
|
yuuji@23
|
1494 ((equal argp 1)
|
yuuji@23
|
1495 (let ((length (read-string "Length variable: " "\\")))
|
yuuji@49
|
1496 (if (string< "" length)
|
yuuji@49
|
1497 (YaTeX-update-table
|
yuuji@49
|
1498 (list length)
|
yuuji@49
|
1499 'YaTeX:style-parameters-default
|
yuuji@49
|
1500 'YaTeX:style-parameters-private
|
yuuji@49
|
1501 'YaTeX:style-parameters-local))
|
yuuji@69
|
1502 length))))
|
yuuji@23
|
1503
|
yuuji@23
|
1504 ;; \multicolumn's arguments
|
yuuji@23
|
1505 (defun YaTeX::multicolumn (&optional argp)
|
yuuji@23
|
1506 "YaTeX add-in function for arguments of \\multicolumn."
|
yuuji@23
|
1507 (cond
|
yuuji@23
|
1508 ((equal 1 argp)
|
yuuji@23
|
1509 (read-string "Number of columns: "))
|
yuuji@23
|
1510 ((equal 2 argp)
|
yuuji@79
|
1511 (YaTeX:read-oneof "|lrc" nil t))
|
yuuji@23
|
1512 ((equal 3 argp)
|
yuuji@69
|
1513 (read-string "Item: "))))
|
yuuji@23
|
1514
|
yuuji@49
|
1515 (defvar YaTeX:documentstyles-default
|
yuuji@49
|
1516 '(("article") ("jarticle") ("j-article")
|
yuuji@49
|
1517 ("book") ("jbook") ("j-book")
|
yuuji@49
|
1518 ("report") ("jreport") ("j-report")
|
yuuji@49
|
1519 ("letter") ("ascjletter"))
|
yuuji@49
|
1520 "List of LaTeX documentstyles.")
|
yuuji@49
|
1521 (defvar YaTeX:documentstyles-private nil
|
yuuji@49
|
1522 "*User defined list of LaTeX documentstyles.")
|
yuuji@49
|
1523 (defvar YaTeX:documentstyles-local nil
|
yuuji@49
|
1524 "*User defined list of local LaTeX documentstyles.")
|
yuuji@49
|
1525 (defvar YaTeX:documentstyle-options-default
|
yuuji@49
|
1526 '(("a4j") ("a5j") ("b4j") ("b5j")
|
yuuji@49
|
1527 ("twocolumn") ("jtwocolumn") ("epsf") ("epsfig") ("epsbox") ("nfig"))
|
yuuji@49
|
1528 "List of LaTeX documentstyle options.")
|
yuuji@49
|
1529 (defvar YaTeX:documentstyle-options-private nil
|
yuuji@49
|
1530 "*User defined list of LaTeX documentstyle options.")
|
yuuji@49
|
1531 (defvar YaTeX:documentstyle-options-local nil
|
yuuji@49
|
1532 "List of LaTeX local documentstyle options.")
|
yuuji@49
|
1533
|
yuuji@49
|
1534 (defun YaTeX:documentstyle ()
|
yuuji@49
|
1535 (let*((delim ",")
|
yuuji@49
|
1536 (dt (append YaTeX:documentstyle-options-local
|
yuuji@49
|
1537 YaTeX:documentstyle-options-private
|
yuuji@49
|
1538 YaTeX:documentstyle-options-default))
|
yuuji@49
|
1539 (minibuffer-completion-table dt)
|
yuuji@49
|
1540 (opt (read-from-minibuffer
|
yuuji@49
|
1541 "Style options ([opt1,opt2,...]): "
|
yuuji@51
|
1542 nil YaTeX-minibuffer-completion-map nil))
|
yuuji@49
|
1543 (substr opt) o)
|
yuuji@49
|
1544 (if (string< "" opt)
|
yuuji@49
|
1545 (progn
|
yuuji@49
|
1546 (while substr
|
yuuji@49
|
1547 (setq o (substring substr 0 (string-match delim substr)))
|
yuuji@49
|
1548 (or (assoc o dt)
|
yuuji@49
|
1549 (YaTeX-update-table
|
yuuji@49
|
1550 (list o)
|
yuuji@49
|
1551 'YaTeX:documentstyle-options-default
|
yuuji@49
|
1552 'YaTeX:documentstyle-options-private
|
yuuji@49
|
1553 'YaTeX:documentstyle-options-local))
|
yuuji@49
|
1554 (setq substr
|
yuuji@49
|
1555 (if (string-match delim substr)
|
yuuji@49
|
1556 (substring substr (1+ (string-match delim substr))))))
|
yuuji@49
|
1557 (concat "[" opt "]"))
|
yuuji@49
|
1558 "")))
|
yuuji@49
|
1559
|
yuuji@49
|
1560 (defun YaTeX::documentstyle (&optional argp)
|
yuuji@51
|
1561 "YaTeX add-in function for arguments of \\documentstyle."
|
yuuji@49
|
1562 (cond
|
yuuji@49
|
1563 ((equal argp 1)
|
yuuji@72
|
1564 (setq YaTeX-env-name "document")
|
yuuji@49
|
1565 (let ((sname
|
yuuji@49
|
1566 (YaTeX-cplread-with-learning
|
yuuji@49
|
1567 (format "Documentstyle (default %s): "
|
yuuji@49
|
1568 YaTeX-default-document-style)
|
yuuji@49
|
1569 'YaTeX:documentstyles-default
|
yuuji@49
|
1570 'YaTeX:documentstyles-private
|
yuuji@49
|
1571 'YaTeX:documentstyles-local)))
|
yuuji@49
|
1572 (if (string= "" sname) (setq sname YaTeX-default-document-style))
|
yuuji@69
|
1573 (setq YaTeX-default-document-style sname)))))
|
yuuji@49
|
1574
|
yuuji@80
|
1575 (defun YaTeX::include (argp &optional prompt)
|
yuuji@86
|
1576 "Read file name setting default directory to that of main file."
|
yuuji@80
|
1577 (cond
|
yuuji@80
|
1578 ((= argp 1)
|
yuuji@86
|
1579 (save-excursion
|
yuuji@86
|
1580 (YaTeX-visit-main t)
|
yuuji@86
|
1581 (let*((insert-default-directory)
|
yuuji@86
|
1582 (file (read-file-name (or prompt "Input file: ") "")))
|
yuuji@86
|
1583 (setq file (substring file 0 (string-match "\\.tex$" file))))))))
|
yuuji@80
|
1584
|
yuuji@80
|
1585 (fset 'YaTeX::input 'YaTeX::include)
|
yuuji@80
|
1586
|
yuuji@80
|
1587
|
yuuji@57
|
1588 ;;; -------------------- LaTeX2e stuff --------------------
|
yuuji@57
|
1589 (defvar YaTeX:documentclass-options-default
|
yuuji@70
|
1590 '(("a4paper") ("a5paper") ("b4paper") ("b5paper") ("10pt") ("11pt") ("12pt")
|
yuuji@57
|
1591 ("latterpaper") ("legalpaper") ("executivepaper") ("landscape")
|
yuuji@57
|
1592 ("oneside") ("twoside") ("draft") ("final") ("leqno") ("fleqn") ("openbib")
|
yuuji@70
|
1593 ("tombow") ("titlepage") ("notitlepage") ("dvips")
|
yuuji@57
|
1594 ("clock") ;for slides class only
|
yuuji@57
|
1595 )
|
yuuji@57
|
1596 "Default options list for documentclass")
|
yuuji@57
|
1597 (defvar YaTeX:documentclass-options-private nil
|
yuuji@57
|
1598 "*User defined options list for documentclass")
|
yuuji@57
|
1599 (defvar YaTeX:documentclass-options-local nil
|
yuuji@57
|
1600 "*User defined options list for local documentclass")
|
yuuji@57
|
1601
|
yuuji@57
|
1602 (defun YaTeX:documentclass ()
|
yuuji@57
|
1603 (let*((delim ",")
|
yuuji@57
|
1604 (dt (append YaTeX:documentclass-options-local
|
yuuji@57
|
1605 YaTeX:documentclass-options-private
|
yuuji@57
|
1606 YaTeX:documentclass-options-default))
|
yuuji@57
|
1607 (minibuffer-completion-table dt)
|
yuuji@57
|
1608 (opt (read-from-minibuffer
|
yuuji@57
|
1609 "Documentclass options ([opt1,opt2,...]): "
|
yuuji@57
|
1610 nil YaTeX-minibuffer-completion-map nil))
|
yuuji@57
|
1611 (substr opt) o)
|
yuuji@57
|
1612 (if (string< "" opt)
|
yuuji@57
|
1613 (progn
|
yuuji@57
|
1614 (while substr
|
yuuji@70
|
1615
|
yuuji@57
|
1616 (setq o (substring substr 0 (string-match delim substr)))
|
yuuji@57
|
1617 (or (assoc o dt)
|
yuuji@57
|
1618 (YaTeX-update-table
|
yuuji@57
|
1619 (list o)
|
yuuji@57
|
1620 'YaTeX:documentclass-options-default
|
yuuji@57
|
1621 'YaTeX:documentclass-options-private
|
yuuji@57
|
1622 'YaTeX:documentclass-options-local))
|
yuuji@57
|
1623 (setq substr
|
yuuji@57
|
1624 (if (string-match delim substr)
|
yuuji@57
|
1625 (substring substr (1+ (string-match delim substr))))))
|
yuuji@57
|
1626 (concat "[" opt "]"))
|
yuuji@57
|
1627 "")))
|
yuuji@57
|
1628
|
yuuji@57
|
1629 (defvar YaTeX:documentclasses-default
|
yuuji@57
|
1630 '(("article") ("jarticle") ("report") ("jreport") ("book") ("jbook")
|
yuuji@57
|
1631 ("j-article") ("j-report") ("j-book")
|
yuuji@57
|
1632 ("letter") ("slides") ("ltxdoc") ("ltxguide") ("ltnews") ("proc"))
|
yuuji@57
|
1633 "Default documentclass alist")
|
yuuji@57
|
1634 (defvar YaTeX:documentclasses-private nil
|
yuuji@57
|
1635 "*User defined documentclass alist")
|
yuuji@57
|
1636 (defvar YaTeX:documentclasses-local nil
|
yuuji@57
|
1637 "*User defined local documentclass alist")
|
yuuji@57
|
1638 (defvar YaTeX-default-documentclass (if YaTeX-japan "jarticle" "article")
|
yuuji@57
|
1639 "*Default documentclass")
|
yuuji@57
|
1640
|
yuuji@57
|
1641 (defun YaTeX::documentclass (&optional argp)
|
yuuji@57
|
1642 (cond
|
yuuji@57
|
1643 ((equal argp 1)
|
yuuji@72
|
1644 (setq YaTeX-env-name "document")
|
yuuji@57
|
1645 (let ((sname
|
yuuji@57
|
1646 (YaTeX-cplread-with-learning
|
yuuji@57
|
1647 (format "Documentclass (default %s): " YaTeX-default-documentclass)
|
yuuji@57
|
1648 'YaTeX:documentclasses-default
|
yuuji@57
|
1649 'YaTeX:documentclasses-private
|
yuuji@57
|
1650 'YaTeX:documentclasses-local)))
|
yuuji@57
|
1651 (if (string= "" sname) (setq sname YaTeX-default-documentclass))
|
yuuji@57
|
1652 (setq YaTeX-default-documentclass sname)))))
|
yuuji@57
|
1653
|
yuuji@70
|
1654 (defvar YaTeX:latex2e-named-color-alist
|
yuuji@70
|
1655 '(("GreenYellow") ("Yellow") ("Goldenrod") ("Dandelion") ("Apricot")
|
yuuji@70
|
1656 ("Peach") ("Melon") ("YellowOrange") ("Orange") ("BurntOrange")
|
yuuji@70
|
1657 ("Bittersweet") ("RedOrange") ("Mahogany") ("Maroon") ("BrickRed")
|
yuuji@70
|
1658 ("Red") ("OrangeRed") ("RubineRed") ("WildStrawberry") ("Salmon")
|
yuuji@70
|
1659 ("CarnationPink") ("Magenta") ("VioletRed") ("Rhodamine") ("Mulberry")
|
yuuji@70
|
1660 ("RedViolet") ("Fuchsia") ("Lavender") ("Thistle") ("Orchid")("DarkOrchid")
|
yuuji@70
|
1661 ("Purple") ("Plum") ("Violet") ("RoyalPurple") ("BlueViolet")
|
yuuji@70
|
1662 ("Periwinkle") ("CadetBlue") ("CornflowerBlue") ("MidnightBlue")
|
yuuji@70
|
1663 ("NavyBlue") ("RoyalBlue") ("Blue") ("Cerulean") ("Cyan") ("ProcessBlue")
|
yuuji@70
|
1664 ("SkyBlue") ("Turquoise") ("TealBlue") ("Aquamarine") ("BlueGreen")
|
yuuji@70
|
1665 ("Emerald") ("JungleGreen") ("SeaGreen") ("Green") ("ForestGreen")
|
yuuji@70
|
1666 ("PineGreen") ("LimeGreen") ("YellowGreen") ("SpringGreen") ("OliveGreen")
|
yuuji@70
|
1667 ("RawSienna") ("Sepia") ("Brown") ("Tan") ("Gray") ("Black") ("White"))
|
yuuji@70
|
1668 "Colors defined in $TEXMF/tex/plain/colordvi.tex")
|
yuuji@70
|
1669
|
yuuji@70
|
1670 (defvar YaTeX:latex2e-basic-color-alist
|
yuuji@70
|
1671 '(("black") ("white") ("red") ("blue") ("yellow") ("green") ("cyan")
|
yuuji@70
|
1672 ("magenta"))
|
yuuji@70
|
1673 "Basic colors")
|
yuuji@70
|
1674
|
yuuji@70
|
1675 (defun YaTeX:textcolor ()
|
yuuji@70
|
1676 "Add-in for \\color's option"
|
yuuji@70
|
1677 (if (y-or-n-p "Use `named' color? ")
|
yuuji@70
|
1678 "[named]"))
|
yuuji@70
|
1679
|
yuuji@70
|
1680 (defun YaTeX::color-completing-read (prompt)
|
yuuji@70
|
1681 (let ((completion-ignore-case t)
|
yuuji@70
|
1682 (namedp (save-excursion
|
yuuji@70
|
1683 (skip-chars-backward "^\n\\[\\\\")
|
yuuji@70
|
1684 (looking-at "named"))))
|
yuuji@70
|
1685 (completing-read
|
yuuji@70
|
1686 prompt
|
yuuji@70
|
1687 (if namedp
|
yuuji@70
|
1688 YaTeX:latex2e-named-color-alist
|
yuuji@70
|
1689 YaTeX:latex2e-basic-color-alist)
|
yuuji@70
|
1690 nil t)))
|
yuuji@70
|
1691
|
yuuji@70
|
1692 (defun YaTeX::textcolor (argp)
|
yuuji@70
|
1693 "Add-in for \\color's argument"
|
yuuji@70
|
1694 (cond
|
yuuji@70
|
1695 ((= argp 1) (YaTeX::color-completing-read "Color: "))
|
yuuji@70
|
1696 ((= argp 2) (read-string "Colored string: "))))
|
yuuji@70
|
1697
|
yuuji@70
|
1698 (fset 'YaTeX:color 'YaTeX:textcolor)
|
yuuji@70
|
1699 (fset 'YaTeX::color 'YaTeX::textcolor)
|
yuuji@70
|
1700 (fset 'YaTeX:colorbox 'YaTeX:textcolor)
|
yuuji@70
|
1701 (fset 'YaTeX::colorbox 'YaTeX::textcolor)
|
yuuji@70
|
1702 (fset 'YaTeX:fcolorbox 'YaTeX:textcolor)
|
yuuji@80
|
1703 (fset 'YaTeX:pagecolor 'YaTeX:textcolor)
|
yuuji@80
|
1704 (fset 'YaTeX::pagecolor 'YaTeX::textcolor)
|
yuuji@70
|
1705
|
yuuji@70
|
1706 (defun YaTeX::fcolorbox (argp)
|
yuuji@70
|
1707 (cond
|
yuuji@70
|
1708 ((= argp 1) (YaTeX::color-completing-read "Frame color: "))
|
yuuji@70
|
1709 ((= argp 2) (YaTeX::color-completing-read "Inner color: "))
|
yuuji@70
|
1710 ((= argp 3) (read-string "Colored string: "))))
|
yuuji@70
|
1711
|
yuuji@70
|
1712 (defun YaTeX:scalebox ()
|
yuuji@80
|
1713 "Add-in for \\scalebox"
|
yuuji@80
|
1714 (let ((vmag (read-string
|
yuuji@80
|
1715 (if YaTeX-japan "倍率(負で反転): "
|
yuuji@80
|
1716 "Magnification(Negative for flipped): ")))
|
yuuji@80
|
1717 (hmag (read-string (if YaTeX-japan "縦倍率(省略可): "
|
yuuji@80
|
1718 "Vertical magnification(Optional): "))))
|
yuuji@70
|
1719 (if (and hmag (string< "" hmag))
|
yuuji@70
|
1720 (format "{%s}[%s]" vmag hmag)
|
yuuji@70
|
1721 (format "{%s}" vmag))))
|
yuuji@70
|
1722
|
yuuji@80
|
1723 (defun YaTeX:rotatebox ()
|
yuuji@80
|
1724 "Optional argument add-in for \\rotatebox"
|
yuuji@80
|
1725 (message "Rotate origin? (N)one (O)rigin (X)-Y: ")
|
yuuji@80
|
1726 (let ((c (read-char)) r (defx "x=mm") x (defy "y=mm") y something)
|
yuuji@80
|
1727 (cond
|
yuuji@80
|
1728 ((memq c '(?O ?o))
|
yuuji@80
|
1729 (if (string< "" (setq r (YaTeX:read-oneof "htbpB")))
|
yuuji@80
|
1730 (concat "[origin=" r "]")))
|
yuuji@80
|
1731 ((memq c '(?X ?x ?Y ?y))
|
yuuji@80
|
1732 (setq r (read-string "" (if YaTeX-emacs-19 (cons defx 3) defx))
|
yuuji@80
|
1733 x (if (string< "x=" r) r)
|
yuuji@80
|
1734 r (read-string "" (if YaTeX-emacs-19 (cons defy 3) defy))
|
yuuji@80
|
1735 y (if (string< "y=" r) r)
|
yuuji@80
|
1736 something (or x y))
|
yuuji@80
|
1737 (format "%s%s%s%s%s"
|
yuuji@80
|
1738 (if something "[" "")
|
yuuji@80
|
1739 (if x x "")
|
yuuji@80
|
1740 (if (and x y) "," "")
|
yuuji@80
|
1741 (if y y "")
|
yuuji@80
|
1742 (if something "]" ""))))))
|
yuuji@80
|
1743
|
yuuji@80
|
1744 (defun YaTeX::rotatebox (argp)
|
yuuji@80
|
1745 "Argument add-in for \\rotatebox"
|
yuuji@80
|
1746 (cond
|
yuuji@80
|
1747 ((= argp 1)
|
yuuji@80
|
1748 (read-string (if YaTeX-japan "回転角(度; 左回り): "
|
yuuji@80
|
1749 "Angle in degree(unclockwise): ")))
|
yuuji@80
|
1750 ((= argp 2)
|
yuuji@80
|
1751 (read-string (if YaTeX-japan "テキスト: " "Text: ")))))
|
yuuji@80
|
1752
|
yuuji@73
|
1753 (defun YaTeX:includegraphics ()
|
yuuji@73
|
1754 "Add-in for \\includegraphics's option"
|
yuuji@73
|
1755 (let (width height (scale "") angle str)
|
yuuji@73
|
1756 (setq width (read-string "Width: ")
|
yuuji@73
|
1757 height (read-string "Height: "))
|
yuuji@73
|
1758 (or (string< width "") (string< "" height)
|
yuuji@73
|
1759 (setq scale (read-string "Scale: ")))
|
yuuji@73
|
1760 (setq angle (read-string "Angle(0-359): "))
|
yuuji@73
|
1761 (setq str
|
yuuji@73
|
1762 (mapconcat
|
yuuji@73
|
1763 'concat
|
yuuji@73
|
1764 (delq nil
|
yuuji@73
|
1765 (mapcar '(lambda (s)
|
yuuji@73
|
1766 (and (stringp (symbol-value s))
|
yuuji@73
|
1767 (string< "" (symbol-value s))
|
yuuji@73
|
1768 (format "%s=%s" s (symbol-value s))))
|
yuuji@73
|
1769 '(width height scale angle)))
|
yuuji@73
|
1770 ","))
|
yuuji@73
|
1771 (if (string= "" str) ""
|
yuuji@73
|
1772 (concat "[" str "]"))))
|
yuuji@73
|
1773
|
yuuji@70
|
1774 (defun YaTeX::includegraphics (argp)
|
yuuji@70
|
1775 "Add-in for \\includegraphics"
|
yuuji@80
|
1776 (YaTeX::include argp "Image File: "))
|
yuuji@70
|
1777
|
yuuji@86
|
1778 (defun YaTeX::verbfile (argp)
|
yuuji@86
|
1779 "Add-in for \\verbfile"
|
yuuji@86
|
1780 (YaTeX::include argp "Virbatim File: "))
|
yuuji@86
|
1781
|
yuuji@68
|
1782 (defun YaTeX:caption ()
|
yuuji@72
|
1783 (setq YaTeX-section-name "label")
|
yuuji@68
|
1784 nil)
|
yuuji@68
|
1785
|
yuuji@80
|
1786
|
yuuji@79
|
1787 (defvar YaTeX::usepackage-alist-default
|
yuuji@79
|
1788 '(("version") ("plext") ("url") ("fancybox") ("pifont") ("longtable")
|
yuuji@79
|
1789 ("ascmac") ("bm") ("graphics") ("graphicx") ("alltt") ("misc") ("eclbkbox")
|
yuuji@79
|
1790 ("amsmath") ("amssymb") ("xymtex") ("chemist")
|
yuuji@79
|
1791 ("a4j") ("array") ("epsf") ("color") ("epsfig") ("floatfig")
|
yuuji@80
|
1792 ("landscape") ("path") ("supertabular") ("twocolumn")
|
yuuji@80
|
1793 ("latexsym") ("times") ("makeidx"))
|
yuuji@80
|
1794 "Default completion table for arguments of \\usepackage")
|
yuuji@79
|
1795
|
yuuji@79
|
1796 (defvar YaTeX::usepackage-alist-private nil
|
yuuji@79
|
1797 "*Private completion list of the argument for usepackage")
|
yuuji@79
|
1798
|
yuuji@79
|
1799 (defvar YaTeX::usepackage-alist-local nil
|
yuuji@79
|
1800 "Directory local completion list of the argument for usepackage")
|
yuuji@79
|
1801
|
yuuji@79
|
1802 (defun YaTeX::usepackage (&optional argp)
|
yuuji@79
|
1803 (cond
|
yuuji@79
|
1804 ((equal argp 1)
|
yuuji@79
|
1805 (setq YaTeX-env-name "document")
|
yuuji@80
|
1806 (let ((minibuffer-local-completion-map YaTeX-minibuffer-completion-map)
|
yuuji@80
|
1807 (delim ","))
|
yuuji@80
|
1808 (YaTeX-cplread-with-learning
|
yuuji@80
|
1809 (if YaTeX-japan "Use package(カンマで区切ってOK): "
|
yuuji@80
|
1810 "Use package(delimitable by comma): ")
|
yuuji@80
|
1811 'YaTeX::usepackage-alist-default
|
yuuji@80
|
1812 'YaTeX::usepackage-alist-private
|
yuuji@80
|
1813 'YaTeX::usepackage-alist-local)))))
|
yuuji@79
|
1814
|
yuuji@79
|
1815 (defun YaTeX::mask (argp)
|
yuuji@79
|
1816 (cond
|
yuuji@79
|
1817 ((equal argp 1)
|
yuuji@79
|
1818 (read-string "String: "))
|
yuuji@79
|
1819 ((equal argp 2)
|
yuuji@79
|
1820 (let (c)
|
yuuji@79
|
1821 (while (not (memq c '(?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K)))
|
yuuji@79
|
1822 (message "Mask type(A..K): ")
|
yuuji@79
|
1823 (setq c (upcase (read-char))))
|
yuuji@79
|
1824 (format "%c" c)))))
|
yuuji@79
|
1825
|
yuuji@79
|
1826 (defun YaTeX::maskbox (argp)
|
yuuji@79
|
1827 (cond
|
yuuji@79
|
1828 ((equal argp 1)
|
yuuji@79
|
1829 (read-string "Width: "))
|
yuuji@79
|
1830 ((equal argp 2)
|
yuuji@79
|
1831 (read-string "Height: "))
|
yuuji@79
|
1832 ((equal argp 3)
|
yuuji@79
|
1833 (let (c)
|
yuuji@79
|
1834 (while (not (memq c '(?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K)))
|
yuuji@79
|
1835 (message "Mask type(A..K): ")
|
yuuji@79
|
1836 (setq c (upcase (read-char))))
|
yuuji@79
|
1837 (format "%c" c)))
|
yuuji@79
|
1838 ((equal argp 4)
|
yuuji@79
|
1839 (YaTeX:read-oneof "lcr" 'quick))
|
yuuji@79
|
1840 ((equal argp 5)
|
yuuji@80
|
1841 (read-string "String: "))))
|
yuuji@80
|
1842
|
yuuji@80
|
1843 (defun YaTeX::textcircled (argp)
|
yuuji@80
|
1844 (cond
|
yuuji@80
|
1845 ((equal argp 1)
|
yuuji@80
|
1846 (let ((char (read-string "Circled char: "))
|
yuuji@80
|
1847 (left "") (right "") c)
|
yuuji@80
|
1848 (setq c (read-char
|
yuuji@80
|
1849 "Enclose also with (s)mall (t)iny s(C)riptsize (N)one:"))
|
yuuji@80
|
1850 (cond
|
yuuji@80
|
1851 ((memq c '(?s ?S)) (setq left "{\\small " right "}"))
|
yuuji@80
|
1852 ((memq c '(?t ?T)) (setq left "{\\tiny " right "}"))
|
yuuji@80
|
1853 ((memq c '(?c ?C)) (setq left "{\\scriptsize " right "}")))
|
yuuji@80
|
1854 (format "%s%s%s" left char right)))))
|
yuuji@79
|
1855
|
yuuji@68
|
1856 ;;; -------------------- math-mode stuff --------------------
|
yuuji@68
|
1857 (defun YaTeX::tilde (&optional pos)
|
yuuji@68
|
1858 "For accent macros in mathmode"
|
yuuji@68
|
1859 (cond
|
yuuji@68
|
1860 ((equal pos 1)
|
yuuji@68
|
1861 (message "Put accent on variable: ")
|
yuuji@68
|
1862 (let ((v (char-to-string (read-char))) (case-fold-search nil))
|
yuuji@68
|
1863 (message "")
|
yuuji@68
|
1864 (cond
|
yuuji@68
|
1865 ((string-match "i\\|j" v)
|
yuuji@68
|
1866 (concat "\\" v "math"))
|
yuuji@68
|
1867 ((string-match "[\r\n\t ]" v)
|
yuuji@68
|
1868 "")
|
yuuji@68
|
1869 (t v))))
|
yuuji@68
|
1870 (nil "")))
|
yuuji@68
|
1871
|
yuuji@68
|
1872 (fset 'YaTeX::hat 'YaTeX::tilde)
|
yuuji@68
|
1873 (fset 'YaTeX::check 'YaTeX::tilde)
|
yuuji@68
|
1874 (fset 'YaTeX::bar 'YaTeX::tilde)
|
yuuji@68
|
1875 (fset 'YaTeX::dot 'YaTeX::tilde)
|
yuuji@68
|
1876 (fset 'YaTeX::ddot 'YaTeX::tilde)
|
yuuji@68
|
1877 (fset 'YaTeX::vec 'YaTeX::tilde)
|
yuuji@68
|
1878
|
yuuji@68
|
1879 (defun YaTeX::widetilde (&optional pos)
|
yuuji@68
|
1880 "For multichar accent macros in mathmode"
|
yuuji@68
|
1881 (cond
|
yuuji@68
|
1882 ((equal pos 1)
|
yuuji@68
|
1883 (let ((m "Put over chars[%s ]: ") v v2)
|
yuuji@68
|
1884 (message m " ")
|
yuuji@68
|
1885 (setq v (char-to-string (read-char)))
|
yuuji@68
|
1886 (message "")
|
yuuji@68
|
1887 (if (string-match "[\r\n\t ]" v)
|
yuuji@68
|
1888 ""
|
yuuji@68
|
1889 (message m v)
|
yuuji@68
|
1890 (setq v2 (char-to-string (read-char)))
|
yuuji@68
|
1891 (message "")
|
yuuji@68
|
1892 (if (string-match "[\r\n\t ]" v2)
|
yuuji@68
|
1893 v
|
yuuji@68
|
1894 (concat v v2)))))
|
yuuji@68
|
1895 (nil "")))
|
yuuji@68
|
1896
|
yuuji@68
|
1897 (fset 'YaTeX::widehat 'YaTeX::widetilde)
|
yuuji@68
|
1898 (fset 'YaTeX::overline 'YaTeX::widetilde)
|
yuuji@68
|
1899 (fset 'YaTeX::overrightarrow 'YaTeX::widetilde)
|
yuuji@68
|
1900
|
yuuji@79
|
1901 ;
|
yuuji@79
|
1902 ; for \frac{}{} region
|
yuuji@79
|
1903 (defun YaTeX::frac-region (beg end)
|
yuuji@79
|
1904 (if (catch 'done
|
yuuji@79
|
1905 (while (re-search-forward "\\s *\\(\\\\over\\|/\\)\\s *" end t)
|
yuuji@79
|
1906 (goto-char (match-beginning 0))
|
yuuji@79
|
1907 (if (y-or-n-p
|
yuuji@79
|
1908 (format "Replace this `%s' with `}{'" (YaTeX-match-string 0)))
|
yuuji@79
|
1909 (throw 'done t))
|
yuuji@79
|
1910 (goto-char (match-end 0))))
|
yuuji@79
|
1911 (let (p (b0 (match-beginning 0)) e0)
|
yuuji@79
|
1912 (replace-match "}{")
|
yuuji@79
|
1913 (setq e0 (point))
|
yuuji@79
|
1914 (save-restriction
|
yuuji@79
|
1915 (narrow-to-region beg end)
|
yuuji@79
|
1916 (goto-char e0)
|
yuuji@79
|
1917 (skip-chars-forward " \t")
|
yuuji@79
|
1918 (setq p (point))
|
yuuji@79
|
1919 (YaTeX-goto-corresponding-paren)
|
yuuji@79
|
1920 (forward-char 1)
|
yuuji@79
|
1921 (skip-chars-forward " \t\r\n")
|
yuuji@79
|
1922 (if (= end (1+ (point)))
|
yuuji@79
|
1923 (progn
|
yuuji@79
|
1924 (goto-char p)
|
yuuji@79
|
1925 (if (looking-at "\\\\") (forward-char 1))
|
yuuji@79
|
1926 (YaTeX-kill-paren nil)))
|
yuuji@79
|
1927 (goto-char beg)
|
yuuji@79
|
1928 (skip-chars-forward " \t")
|
yuuji@79
|
1929 (setq p (point))
|
yuuji@79
|
1930 (YaTeX-goto-corresponding-paren)
|
yuuji@79
|
1931 (forward-char 1)
|
yuuji@79
|
1932 (skip-chars-forward " \t\r\n")
|
yuuji@79
|
1933 (if (>= (point) b0)
|
yuuji@79
|
1934 (progn
|
yuuji@79
|
1935 (goto-char p)
|
yuuji@79
|
1936 (if (looking-at "\\\\") (forward-char 1))
|
yuuji@79
|
1937 (YaTeX-kill-paren nil))))))
|
yuuji@79
|
1938 (message ""))
|
yuuji@68
|
1939
|
yuuji@80
|
1940 (defun YaTeX::DeclareMathOperator (argp)
|
yuuji@80
|
1941 (cond
|
yuuji@80
|
1942 ((equal argp 1)
|
yuuji@80
|
1943 (read-string "Operator: " "\\"))))
|
yuuji@80
|
1944
|
yuuji@68
|
1945 ;;;
|
yuuji@68
|
1946 ;; Add-in functions for large-type command.
|
yuuji@68
|
1947 ;;;
|
yuuji@68
|
1948 (defun YaTeX:em ()
|
yuuji@68
|
1949 (cond
|
yuuji@68
|
1950 ((eq YaTeX-current-completion-type 'large) "\\/")
|
yuuji@68
|
1951 (t nil)))
|
yuuji@68
|
1952 (fset 'YaTeX:it 'YaTeX:em)
|
yuuji@68
|
1953
|
yuuji@23
|
1954 ;;; -------------------- End of yatexadd --------------------
|
yuuji@23
|
1955 (provide 'yatexadd)
|
yuuji@72
|
1956 ; Local variables:
|
yuuji@72
|
1957 ; fill-prefix: ";;; "
|
yuuji@72
|
1958 ; paragraph-start: "^$\\|\\|;;;$"
|
yuuji@72
|
1959 ; paragraph-separate: "^$\\|\\|;;;$"
|
yuuji@80
|
1960 ; coding: sjis
|
yuuji@72
|
1961 ; End:
|