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