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