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