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