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