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