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