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