rev |
line source |
yuuji@6
|
1 ;;; -*- Emacs-Lisp -*-
|
yuuji@8
|
2 ;;; YaTeX add-in functions.
|
yuuji@23
|
3 ;;; yatexadd.el rev.9
|
yuuji@14
|
4 ;;; (c )1991-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
|
yuuji@49
|
5 ;;; Last modified Sat Nov 12 07:03:15 1994 on VFR
|
yuuji@8
|
6 ;;; $Id$
|
yuuji@6
|
7
|
yuuji@6
|
8 ;;;
|
yuuji@6
|
9 ;;Sample functions for LaTeX environment.
|
yuuji@6
|
10 ;;;
|
yuuji@6
|
11 (defvar YaTeX:tabular-default-rule
|
yuuji@6
|
12 "@{\\vrule width 1pt\\ }c|c|c@{\\ \\vrule width 1pt}"
|
yuuji@6
|
13 "*Your favorite default rule format."
|
yuuji@6
|
14 )
|
yuuji@23
|
15 (defvar YaTeX:tabular-thick-vrule "\\vrule width %s"
|
yuuji@23
|
16 "*Vertical thick line format (without @{}). %s'll be replaced by its width."
|
yuuji@23
|
17 )
|
yuuji@23
|
18 (defvar YaTeX:tabular-thick-hrule "\\noalign{\\hrule height %s}"
|
yuuji@23
|
19 "*Horizontal thick line format. %s will be replaced by its width."
|
yuuji@23
|
20 )
|
yuuji@6
|
21 (defun YaTeX:tabular ()
|
yuuji@18
|
22 "YaTeX add-in function for tabular environment.
|
yuuji@18
|
23 Notice that this function refers the let-variable `env' in
|
yuuji@18
|
24 YaTeX-make-begin-end."
|
yuuji@23
|
25 (let ((width "") bars (rule "") (and "") (j 1) loc ans (hline "\\hline"))
|
yuuji@18
|
26 (if (string= env "tabular*")
|
yuuji@18
|
27 (setq width (concat "{" (read-string "Width: ") "}")))
|
yuuji@18
|
28 (setq loc (YaTeX:read-position "tb")
|
yuuji@23
|
29 bars (string-to-int
|
yuuji@23
|
30 (read-string "Number of columns(0 for default format): " "3")))
|
yuuji@23
|
31 (if (<= bars 0)
|
yuuji@23
|
32 (setq ;if 0, simple format
|
yuuji@23
|
33 rule YaTeX:tabular-default-rule
|
yuuji@23
|
34 and "& &")
|
yuuji@23
|
35 (while (< j bars) ;repeat bars-1 times
|
yuuji@23
|
36 (setq rule (concat rule "c|")
|
yuuji@23
|
37 and (concat and "& ")
|
yuuji@23
|
38 j (1+ j)))
|
yuuji@23
|
39 (setq rule (concat rule "c"))
|
yuuji@23
|
40 (message "(N)ormal-frame or (T)hick frame? [nt]")
|
yuuji@23
|
41 (setq ans (read-char))
|
yuuji@23
|
42 (cond
|
yuuji@23
|
43 ((or (equal ans ?t) (equal ans ?T))
|
yuuji@23
|
44 (setq ans (read-string "Rule width: " "1pt")
|
yuuji@23
|
45 rule (concat
|
yuuji@23
|
46 "@{" (format YaTeX:tabular-thick-vrule ans) "}"
|
yuuji@23
|
47 rule
|
yuuji@23
|
48 "@{\\ " (format YaTeX:tabular-thick-vrule ans) "}")
|
yuuji@23
|
49 hline (format YaTeX:tabular-thick-hrule ans)))
|
yuuji@23
|
50 (t (setq rule (concat "|" rule "|")
|
yuuji@23
|
51 hline "\\hline"))))
|
yuuji@23
|
52
|
yuuji@6
|
53 (setq rule (read-string "rule format: " rule))
|
yuuji@6
|
54
|
yuuji@23
|
55 (message "Dont forget to remove null line at the end of tabular.")
|
yuuji@23
|
56 (format "%s%s{%s}%s"
|
yuuji@23
|
57 width loc rule
|
yuuji@23
|
58 (if (and (boundp 'region-mode) region-mode)
|
yuuji@23
|
59 "" ;do nothing in region-mode
|
yuuji@23
|
60 (format "\n%s\n%s \\\\ \\hline\n%s\n\\\\ %s"
|
yuuji@23
|
61 hline and and hline))))
|
yuuji@18
|
62 )
|
yuuji@18
|
63 (fset 'YaTeX:tabular* 'YaTeX:tabular)
|
yuuji@18
|
64 (defun YaTeX:array ()
|
yuuji@18
|
65 (concat (YaTeX:read-position "tb")
|
yuuji@18
|
66 "{" (read-string "Column format: ") "}")
|
yuuji@6
|
67 )
|
yuuji@6
|
68
|
yuuji@23
|
69 (defun YaTeX:read-oneof (oneof)
|
yuuji@23
|
70 (let ((pos "") loc (guide ""))
|
yuuji@23
|
71 (and (boundp 'name) name (setq guide (format "%s " name)))
|
yuuji@6
|
72 (while (not (string-match
|
yuuji@8
|
73 (setq loc (read-key-sequence
|
yuuji@23
|
74 (format "%s position (`%s') [%s]: "
|
yuuji@23
|
75 guide oneof pos)));name is in YaTeX-addin
|
yuuji@6
|
76 "\r\^g\n"))
|
yuuji@6
|
77 (cond
|
yuuji@8
|
78 ((string-match loc oneof)
|
yuuji@6
|
79 (if (not (string-match loc pos))
|
yuuji@6
|
80 (setq pos (concat pos loc))))
|
yuuji@6
|
81 ((and (string-match loc "\C-h\C-?") (> (length pos) 0))
|
yuuji@6
|
82 (setq pos (substring pos 0 (1- (length pos)))))
|
yuuji@6
|
83 (t
|
yuuji@6
|
84 (ding)
|
yuuji@8
|
85 (message "Please input one of `%s'." oneof)
|
yuuji@6
|
86 (sit-for 3))))
|
yuuji@8
|
87 (message "")
|
yuuji@23
|
88 pos)
|
yuuji@23
|
89 )
|
yuuji@23
|
90
|
yuuji@23
|
91 (defun YaTeX:read-position (oneof)
|
yuuji@23
|
92 "Read a LaTeX (optional) position format such as `[htbp]'."
|
yuuji@23
|
93 (let ((pos (YaTeX:read-oneof oneof)))
|
yuuji@23
|
94 (if (string= pos "") "" (concat "[" pos "]")))
|
yuuji@8
|
95 )
|
yuuji@8
|
96
|
yuuji@8
|
97 (defun YaTeX:table ()
|
yuuji@8
|
98 "YaTeX add-in function for table environment."
|
yuuji@8
|
99 (YaTeX:read-position "htbp")
|
yuuji@6
|
100 )
|
yuuji@6
|
101
|
yuuji@46
|
102 (fset 'YaTeX:figure 'YaTeX:table)
|
yuuji@46
|
103 (fset 'YaTeX:figure* 'YaTeX:table)
|
yuuji@46
|
104
|
yuuji@46
|
105
|
yuuji@6
|
106 (defun YaTeX:description ()
|
yuuji@6
|
107 "Truly poor service:-)"
|
yuuji@6
|
108 (setq single-command "item[]")
|
yuuji@8
|
109 ""
|
yuuji@6
|
110 )
|
yuuji@6
|
111
|
yuuji@6
|
112 (defun YaTeX:itemize ()
|
yuuji@6
|
113 "It's also poor service."
|
yuuji@6
|
114 (setq single-command "item")
|
yuuji@8
|
115 ""
|
yuuji@6
|
116 )
|
yuuji@6
|
117
|
yuuji@6
|
118 (fset 'YaTeX:enumerate 'YaTeX:itemize)
|
yuuji@8
|
119
|
yuuji@11
|
120 (defun YaTeX:picture ()
|
yuuji@11
|
121 "Ask the size of coordinates of picture environment."
|
yuuji@11
|
122 (concat (YaTeX:read-coordinates "Picture size")
|
yuuji@11
|
123 (YaTeX:read-coordinates "Initial position"))
|
yuuji@11
|
124 )
|
yuuji@11
|
125
|
yuuji@12
|
126 (defun YaTeX:equation ()
|
yuuji@12
|
127 (if (fboundp 'YaTeX-toggle-math-mode)
|
yuuji@12
|
128 (YaTeX-toggle-math-mode t)) ;force math-mode ON.
|
yuuji@12
|
129 )
|
yuuji@12
|
130 (fset 'YaTeX:eqnarray 'YaTeX:equation)
|
yuuji@12
|
131 (fset 'YaTeX:displaymath 'YaTeX:equation)
|
yuuji@12
|
132
|
yuuji@16
|
133 (defun YaTeX:list ()
|
yuuji@16
|
134 "%\n{} %default label\n{} %formatting parameter"
|
yuuji@16
|
135 )
|
yuuji@16
|
136
|
yuuji@18
|
137 (defun YaTeX:minipage ()
|
yuuji@18
|
138 (concat (YaTeX:read-position "cbt")
|
yuuji@18
|
139 "{" (read-string "Width: ") "}")
|
yuuji@18
|
140 )
|
yuuji@18
|
141
|
yuuji@8
|
142 ;;;
|
yuuji@8
|
143 ;;Sample functions for section-type command.
|
yuuji@8
|
144 ;;;
|
yuuji@8
|
145 (defun YaTeX:multiput ()
|
yuuji@8
|
146 (concat (YaTeX:read-coordinates "Pos")
|
yuuji@8
|
147 (YaTeX:read-coordinates "Step")
|
yuuji@8
|
148 "{" (read-string "How many times: ") "}")
|
yuuji@8
|
149 )
|
yuuji@8
|
150
|
yuuji@8
|
151 (defun YaTeX:put ()
|
yuuji@8
|
152 (YaTeX:read-coordinates "Pos")
|
yuuji@8
|
153 )
|
yuuji@8
|
154
|
yuuji@8
|
155 (defun YaTeX:makebox ()
|
yuuji@23
|
156 (cond
|
yuuji@23
|
157 ((YaTeX-in-environment-p "picture")
|
yuuji@23
|
158 (concat (YaTeX:read-coordinates "Dimension")
|
yuuji@23
|
159 (YaTeX:read-position "lrtb")))
|
yuuji@23
|
160 (t
|
yuuji@23
|
161 (let ((width (read-string "Width: ")))
|
yuuji@23
|
162 (if (string< "" width)
|
yuuji@23
|
163 (progn
|
yuuji@23
|
164 (or (equal (aref width 0) ?\[)
|
yuuji@23
|
165 (setq width (concat "[" width "]")))
|
yuuji@23
|
166 (concat width (YaTeX:read-position "lr")))))))
|
yuuji@8
|
167 )
|
yuuji@8
|
168
|
yuuji@8
|
169 (defun YaTeX:framebox ()
|
yuuji@8
|
170 (if (YaTeX-quick-in-environment-p "picture")
|
yuuji@8
|
171 (YaTeX:makebox))
|
yuuji@8
|
172 )
|
yuuji@8
|
173
|
yuuji@8
|
174 (defun YaTeX:dashbox ()
|
yuuji@8
|
175 (concat "{" (read-string "Dash dimension: ") "}"
|
yuuji@8
|
176 (YaTeX:read-coordinates "Dimension"))
|
yuuji@8
|
177 )
|
yuuji@8
|
178
|
yuuji@23
|
179 (defun YaTeX:left ()
|
yuuji@23
|
180 (let (c)
|
yuuji@23
|
181 (while (not (string-match
|
yuuji@23
|
182 (progn (message "Which parenthesis? One of [{(|)}]: ")
|
yuuji@23
|
183 (setq c (regexp-quote (char-to-string (read-char)))))
|
yuuji@23
|
184 "[{(|)}]")))
|
yuuji@23
|
185 (setq single-command "right")
|
yuuji@23
|
186 (cond
|
yuuji@23
|
187 ((string-match c "[(|)]") c)
|
yuuji@23
|
188 (t (concat "\\" c))))
|
yuuji@23
|
189 )
|
yuuji@23
|
190 (fset 'YaTeX:right 'YaTeX:left)
|
yuuji@23
|
191
|
yuuji@8
|
192 (defun YaTeX:read-coordinates (&optional mes varX varY)
|
yuuji@8
|
193 (concat
|
yuuji@8
|
194 "("
|
yuuji@8
|
195 (read-string (format "%s %s: " (or mes "Dimension") (or varX "X")))
|
yuuji@8
|
196 ","
|
yuuji@8
|
197 (read-string (format "%s %s: " (or mes "Dimension") (or varY "Y")))
|
yuuji@8
|
198 ")")
|
yuuji@8
|
199 )
|
yuuji@8
|
200
|
yuuji@8
|
201 ;;;
|
yuuji@8
|
202 ;;Sample functions for maketitle-type command.
|
yuuji@8
|
203 ;;;
|
yuuji@8
|
204 (defun YaTeX:sum ()
|
yuuji@8
|
205 "Read range of summation."
|
yuuji@8
|
206 (YaTeX:check-completion-type 'maketitle)
|
yuuji@8
|
207 (concat (YaTeX:read-boundary "_") (YaTeX:read-boundary "^"))
|
yuuji@8
|
208 )
|
yuuji@8
|
209
|
yuuji@8
|
210 (fset 'YaTeX:int 'YaTeX:sum)
|
yuuji@8
|
211
|
yuuji@8
|
212 (defun YaTeX:lim ()
|
yuuji@8
|
213 "Insert limit notation of \\lim."
|
yuuji@8
|
214 (YaTeX:check-completion-type 'maketitle)
|
yuuji@8
|
215 (let ((var (read-string "Variable: ")) limit)
|
yuuji@8
|
216 (if (string= "" var) ""
|
yuuji@8
|
217 (setq limit (read-string "Limit ($ means infinity): "))
|
yuuji@8
|
218 (if (string= "$" limit) (setq limit "\\infty"))
|
yuuji@8
|
219 (concat "_{" var " \\rightarrow " limit "}")))
|
yuuji@8
|
220 )
|
yuuji@8
|
221
|
yuuji@8
|
222 (defun YaTeX:gcd ()
|
yuuji@8
|
223 "Add-in function for \\gcd(m,n)."
|
yuuji@8
|
224 (YaTeX:check-completion-type 'maketitle)
|
yuuji@8
|
225 (YaTeX:read-coordinates "\\gcd" "(?,)" "(,?)")
|
yuuji@8
|
226 )
|
yuuji@8
|
227
|
yuuji@8
|
228 (defun YaTeX:read-boundary (ULchar)
|
yuuji@8
|
229 "Read boundary usage by _ or ^. _ or ^ is indicated by argument ULchar."
|
yuuji@11
|
230 (let ((bndry (read-string (concat ULchar "{???} ($ for infinity): "))))
|
yuuji@8
|
231 (if (string= bndry "") ""
|
yuuji@11
|
232 (if (string= bndry "$") (setq bndry "\\infty"))
|
yuuji@8
|
233 (concat ULchar "{" bndry "}")))
|
yuuji@8
|
234 )
|
yuuji@8
|
235
|
yuuji@14
|
236 (defun YaTeX:verb ()
|
yuuji@14
|
237 "Enclose \\verb's contents with the same characters."
|
yuuji@14
|
238 (let ((quote-char (read-string "Quoting char: " "|"))
|
yuuji@14
|
239 (contents (read-string "Quoted contents: ")))
|
yuuji@14
|
240 (concat quote-char contents quote-char))
|
yuuji@14
|
241 )
|
yuuji@23
|
242 (fset 'YaTeX:verb* 'YaTeX:verb)
|
yuuji@14
|
243
|
yuuji@43
|
244 (defun YaTeX:footnotemark ()
|
yuuji@43
|
245 (setq section-name "footnotetext")
|
yuuji@43
|
246 nil
|
yuuji@43
|
247 )
|
yuuji@43
|
248
|
yuuji@48
|
249 (defun YaTeX:cite ()
|
yuuji@48
|
250 (let ((comment (read-string "Comment for citation: ")))
|
yuuji@48
|
251 (if (string= comment "") ""
|
yuuji@48
|
252 (concat "[" comment "]")))
|
yuuji@48
|
253 )
|
yuuji@48
|
254
|
yuuji@48
|
255 (defun YaTeX:bibitem ()
|
yuuji@48
|
256 (let ((label (read-string "Citation label: ")))
|
yuuji@48
|
257 (if (string= label "") ""
|
yuuji@48
|
258 (concat "[" label "]")))
|
yuuji@48
|
259 )
|
yuuji@48
|
260
|
yuuji@14
|
261 ;;;
|
yuuji@14
|
262 ;;Subroutine
|
yuuji@14
|
263 ;;;
|
yuuji@14
|
264
|
yuuji@8
|
265 (defun YaTeX:check-completion-type (type)
|
yuuji@8
|
266 "Check valid completion type."
|
yuuji@8
|
267 (if (not (eq type YaTeX-current-completion-type))
|
yuuji@8
|
268 (error "This should be completed with %s-type completion." type))
|
yuuji@8
|
269 )
|
yuuji@11
|
270
|
yuuji@11
|
271
|
yuuji@11
|
272 ;;;
|
yuuji@11
|
273 ;;; [[Add-in functions for reading section arguments]]
|
yuuji@11
|
274 ;;;
|
yuuji@11
|
275 ;; All of add-in functions for reading sections arguments should
|
yuuji@11
|
276 ;; take an argument ARGP that specify the argument position.
|
yuuji@11
|
277 ;; If argument position is out of range, nil should be returned,
|
yuuji@11
|
278 ;; else nil should NOT be returned.
|
yuuji@13
|
279
|
yuuji@13
|
280 ;;
|
yuuji@13
|
281 ; Label selection
|
yuuji@13
|
282 ;;
|
yuuji@11
|
283 (defvar YaTeX-label-menu-other
|
yuuji@11
|
284 (if YaTeX-japan "':‘¼‚̃oƒbƒtƒ@‚̃‰ƒxƒ‹\n" "':LABEL IN OTHER BUFFER.\n"))
|
yuuji@23
|
285 (defvar YaTeX-label-menu-repeat
|
yuuji@23
|
286 (if YaTeX-japan ".:’¼‘O‚Ì\\ref‚Æ“¯‚¶\n" "/:REPEAT LAST \ref{}\n"))
|
yuuji@11
|
287 (defvar YaTeX-label-menu-any
|
yuuji@11
|
288 (if YaTeX-japan "*:”CˆÓ‚Ì•¶Žš—ñ\n" "*:ANY STRING.\n"))
|
yuuji@11
|
289 (defvar YaTeX-label-buffer "*Label completions*")
|
yuuji@11
|
290 (defvar YaTeX-label-guide-msg "Select label and hit RETURN.")
|
yuuji@11
|
291 (defvar YaTeX-label-select-map nil
|
yuuji@11
|
292 "Key map used in label selection buffer.")
|
yuuji@11
|
293 (defun YaTeX::label-setup-key-map ()
|
yuuji@11
|
294 (if YaTeX-label-select-map nil
|
yuuji@11
|
295 (message "Setting up label selection mode map...")
|
yuuji@11
|
296 (setq YaTeX-label-select-map (copy-keymap global-map))
|
yuuji@11
|
297 (suppress-keymap YaTeX-label-select-map)
|
yuuji@11
|
298 (substitute-all-key-definition
|
yuuji@11
|
299 'previous-line 'YaTeX::label-previous YaTeX-label-select-map)
|
yuuji@11
|
300 (substitute-all-key-definition
|
yuuji@11
|
301 'next-line 'YaTeX::label-next YaTeX-label-select-map)
|
yuuji@11
|
302 (define-key YaTeX-label-select-map "\C-n" 'YaTeX::label-next)
|
yuuji@11
|
303 (define-key YaTeX-label-select-map "\C-p" 'YaTeX::label-previous)
|
yuuji@11
|
304 (define-key YaTeX-label-select-map "<" 'beginning-of-buffer)
|
yuuji@11
|
305 (define-key YaTeX-label-select-map ">" 'end-of-buffer)
|
yuuji@11
|
306 (define-key YaTeX-label-select-map "\C-m" 'exit-recursive-edit)
|
yuuji@11
|
307 (define-key YaTeX-label-select-map "\C-j" 'exit-recursive-edit)
|
yuuji@11
|
308 (define-key YaTeX-label-select-map " " 'exit-recursive-edit)
|
yuuji@11
|
309 (define-key YaTeX-label-select-map "\C-g" 'abort-recursive-edit)
|
yuuji@11
|
310 (define-key YaTeX-label-select-map "/" 'isearch-forward)
|
yuuji@11
|
311 (define-key YaTeX-label-select-map "?" 'isearch-backward)
|
yuuji@11
|
312 (define-key YaTeX-label-select-map "'" 'YaTeX::label-search-tag)
|
yuuji@23
|
313 (define-key YaTeX-label-select-map "." 'YaTeX::label-search-tag)
|
yuuji@11
|
314 (define-key YaTeX-label-select-map "*" 'YaTeX::label-search-tag)
|
yuuji@11
|
315 (message "Setting up label selection mode map...Done")
|
yuuji@11
|
316 (let ((key ?A))
|
yuuji@11
|
317 (while (<= key ?Z)
|
yuuji@11
|
318 (define-key YaTeX-label-select-map (char-to-string key)
|
yuuji@11
|
319 'YaTeX::label-search-tag)
|
yuuji@11
|
320 (define-key YaTeX-label-select-map (char-to-string (+ key (- ?a ?A)))
|
yuuji@11
|
321 'YaTeX::label-search-tag)
|
yuuji@11
|
322 (setq key (1+ key)))))
|
yuuji@11
|
323 )
|
yuuji@11
|
324 (defun YaTeX::label-next ()
|
yuuji@11
|
325 (interactive) (forward-line 1) (message YaTeX-label-guide-msg))
|
yuuji@11
|
326 (defun YaTeX::label-previous ()
|
yuuji@11
|
327 (interactive) (forward-line -1) (message YaTeX-label-guide-msg))
|
yuuji@11
|
328 (defun YaTeX::label-search-tag ()
|
yuuji@11
|
329 (interactive)
|
yuuji@23
|
330 (let ((case-fold-search t) (tag (regexp-quote (this-command-keys))))
|
yuuji@11
|
331 (cond
|
yuuji@11
|
332 ((save-excursion
|
yuuji@11
|
333 (forward-char 1)
|
yuuji@23
|
334 (re-search-forward (concat "^" tag) nil t))
|
yuuji@11
|
335 (goto-char (match-beginning 0)))
|
yuuji@11
|
336 ((save-excursion
|
yuuji@11
|
337 (goto-char (point-min))
|
yuuji@23
|
338 (re-search-forward (concat "^" tag) nil t))
|
yuuji@11
|
339 (goto-char (match-beginning 0))))
|
yuuji@11
|
340 (message YaTeX-label-guide-msg))
|
yuuji@11
|
341 )
|
yuuji@48
|
342 (defun YaTeX::ref (argp &optional labelcmd refcmd)
|
yuuji@11
|
343 (cond
|
yuuji@11
|
344 ((= argp 1)
|
yuuji@11
|
345 (save-excursion
|
yuuji@48
|
346 (let ((lnum 0) e0 label label-list (buf (current-buffer))
|
yuuji@48
|
347 (labelcmd (or labelcmd "label")) (refcmd (or refcmd "ref"))
|
yuuji@11
|
348 (p (point)) initl line)
|
yuuji@11
|
349 (goto-char (point-min))
|
yuuji@11
|
350 (message "Collecting labels...")
|
yuuji@11
|
351 (save-window-excursion
|
yuuji@12
|
352 (YaTeX-showup-buffer
|
yuuji@12
|
353 YaTeX-label-buffer (function (lambda (x) (window-width x))))
|
yuuji@11
|
354 (with-output-to-temp-buffer YaTeX-label-buffer
|
yuuji@48
|
355 (while (YaTeX-re-search-active-forward
|
yuuji@48
|
356 (concat "\\\\" labelcmd)
|
yuuji@48
|
357 (regexp-quote YaTeX-comment-prefix) nil t)
|
yuuji@48
|
358 (goto-char (match-beginning 0))
|
yuuji@48
|
359 (skip-chars-forward "^{")
|
yuuji@48
|
360 (setq label
|
yuuji@48
|
361 (buffer-substring
|
yuuji@48
|
362 (1+ (point))
|
yuuji@48
|
363 (prog2 (forward-list 1) (setq e0 (1- (point)))))
|
yuuji@48
|
364 label-list (cons label label-list))
|
yuuji@48
|
365 (or initl
|
yuuji@48
|
366 (if (< p (point)) (setq initl lnum)))
|
yuuji@48
|
367 (beginning-of-line)
|
yuuji@48
|
368 (skip-chars-forward " \t\n" nil)
|
yuuji@48
|
369 (princ (format "%c:{%s}\t<<%s>>\n" (+ (% lnum 26) ?A) label
|
yuuji@48
|
370 (buffer-substring (point) (point-end-of-line))))
|
yuuji@48
|
371 (setq lnum (1+ lnum))
|
yuuji@48
|
372 (message "Collecting \\%s{}... %d" labelcmd lnum)
|
yuuji@11
|
373 (goto-char e0))
|
yuuji@11
|
374 (princ YaTeX-label-menu-other)
|
yuuji@23
|
375 (princ YaTeX-label-menu-repeat)
|
yuuji@11
|
376 (princ YaTeX-label-menu-any)
|
yuuji@11
|
377 );with
|
yuuji@11
|
378 (goto-char p)
|
yuuji@48
|
379 (message "Collecting %s...Done" labelcmd)
|
yuuji@11
|
380 (pop-to-buffer YaTeX-label-buffer)
|
yuuji@11
|
381 (YaTeX::label-setup-key-map)
|
yuuji@11
|
382 (setq truncate-lines t)
|
yuuji@11
|
383 (setq buffer-read-only t)
|
yuuji@11
|
384 (use-local-map YaTeX-label-select-map)
|
yuuji@11
|
385 (message YaTeX-label-guide-msg)
|
yuuji@11
|
386 (goto-line (or initl lnum)) ;goto recently defined label line
|
yuuji@11
|
387 (unwind-protect
|
yuuji@11
|
388 (progn
|
yuuji@11
|
389 (recursive-edit)
|
yuuji@11
|
390 (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
|
yuuji@11
|
391 (beginning-of-line)
|
yuuji@11
|
392 (setq line (count-lines (point-min)(point)))
|
yuuji@11
|
393 (cond
|
yuuji@11
|
394 ((= line lnum) (setq label (YaTeX-label-other)))
|
yuuji@23
|
395 ((= line (1+ lnum))
|
yuuji@23
|
396 (save-excursion
|
yuuji@23
|
397 (switch-to-buffer buf)
|
yuuji@23
|
398 (goto-char p)
|
yuuji@48
|
399 (if (re-search-backward
|
yuuji@48
|
400 (concat "\\\\" refcmd "{\\([^}]+\\)}") nil t)
|
yuuji@48
|
401 (setq label (YaTeX-match-string 1))
|
yuuji@23
|
402 (setq label ""))))
|
yuuji@23
|
403 ((>= line (+ lnum 2))
|
yuuji@48
|
404 (setq label (read-string (format "\\%s{???}: " refcmd))))
|
yuuji@11
|
405 (t (setq label (nth (- lnum line 1) label-list)))))
|
yuuji@11
|
406 (bury-buffer YaTeX-label-buffer)))
|
yuuji@11
|
407 label
|
yuuji@11
|
408 ))
|
yuuji@11
|
409 ))
|
yuuji@11
|
410 )
|
yuuji@16
|
411 (fset 'YaTeX::pageref 'YaTeX::ref)
|
yuuji@48
|
412 (defun YaTeX::cite (argp)
|
yuuji@48
|
413 (cond
|
yuuji@48
|
414 ((eq argp 1)
|
yuuji@48
|
415 (YaTeX::ref argp "bibitem\\(\\[.*\\]\\)?" "cite"))
|
yuuji@48
|
416 (t nil)))
|
yuuji@11
|
417
|
yuuji@48
|
418 (defun YaTeX-yatex-buffer-list ()
|
yuuji@48
|
419 (save-excursion
|
yuuji@48
|
420 (delq nil (mapcar (function (lambda (buf)
|
yuuji@48
|
421 (set-buffer buf)
|
yuuji@48
|
422 (if (eq major-mode 'yatex-mode) buf)))
|
yuuji@48
|
423 (buffer-list))))
|
yuuji@48
|
424 )
|
yuuji@48
|
425
|
yuuji@48
|
426 (defun YaTeX-select-other-yatex-buffer ()
|
yuuji@48
|
427 "Select buffer from all yatex-mode's buffers interactivelly."
|
yuuji@48
|
428 (interactive)
|
yuuji@48
|
429 (let ((lbuf "*YaTeX mode buffers*") (blist (YaTeX-yatex-buffer-list))
|
yuuji@48
|
430 (lnum -1) buf rv
|
yuuji@11
|
431 (ff "**find-file**"))
|
yuuji@12
|
432 (YaTeX-showup-buffer
|
yuuji@12
|
433 lbuf (function (lambda (x) 1))) ;;Select next window surely.
|
yuuji@11
|
434 (with-output-to-temp-buffer lbuf
|
yuuji@11
|
435 (while blist
|
yuuji@48
|
436 (princ
|
yuuji@48
|
437 (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A)
|
yuuji@48
|
438 (buffer-name (car blist))))
|
yuuji@11
|
439 (setq blist (cdr blist)))
|
yuuji@11
|
440 (princ (format "':{%s}" ff)))
|
yuuji@11
|
441 (pop-to-buffer lbuf)
|
yuuji@11
|
442 (YaTeX::label-setup-key-map)
|
yuuji@11
|
443 (setq buffer-read-only t)
|
yuuji@11
|
444 (use-local-map YaTeX-label-select-map)
|
yuuji@11
|
445 (message YaTeX-label-guide-msg)
|
yuuji@11
|
446 (unwind-protect
|
yuuji@11
|
447 (progn
|
yuuji@11
|
448 (recursive-edit)
|
yuuji@11
|
449 (set-buffer lbuf)
|
yuuji@11
|
450 (beginning-of-line)
|
yuuji@11
|
451 (setq rv
|
yuuji@11
|
452 (if (re-search-forward "{\\([^\\}]+\\)}" (point-end-of-line) t)
|
yuuji@11
|
453 (buffer-substring (match-beginning 1) (match-end 1)) nil)))
|
yuuji@11
|
454 (kill-buffer lbuf))
|
yuuji@48
|
455 (if (string= rv ff)
|
yuuji@48
|
456 (progn
|
yuuji@48
|
457 (call-interactively 'find-file)
|
yuuji@48
|
458 (current-buffer))
|
yuuji@48
|
459 rv))
|
yuuji@48
|
460 )
|
yuuji@48
|
461
|
yuuji@48
|
462 (defun YaTeX-label-other ()
|
yuuji@48
|
463 (let ((rv (YaTeX-select-other-yatex-buffer)))
|
yuuji@11
|
464 (cond
|
yuuji@11
|
465 ((null rv) "")
|
yuuji@11
|
466 (t
|
yuuji@11
|
467 (set-buffer rv)
|
yuuji@48
|
468 (YaTeX::ref argp labelcmd refcmd)))
|
yuuji@11
|
469 )
|
yuuji@11
|
470 )
|
yuuji@11
|
471
|
yuuji@13
|
472 ;;
|
yuuji@13
|
473 ; completion for the arguments of \newcommand
|
yuuji@13
|
474 ;;
|
yuuji@13
|
475 (defun YaTeX::newcommand (&optional argp)
|
yuuji@13
|
476 (cond
|
yuuji@13
|
477 ((= argp 1)
|
yuuji@13
|
478 (let ((command (read-string "Define newcommand: " "\\")))
|
yuuji@13
|
479 (put 'YaTeX::newcommand 'command (substring command 1))
|
yuuji@13
|
480 command))
|
yuuji@13
|
481 ((= argp 2)
|
yuuji@13
|
482 (let ((argc
|
yuuji@13
|
483 (string-to-int (read-string "Number of arguments(Default 0): ")))
|
yuuji@13
|
484 (def (read-string "Definition: "))
|
yuuji@13
|
485 (command (get 'YaTeX::newcommand 'command)))
|
yuuji@13
|
486 ;;!!! It's illegal to insert string in the add-in function !!!
|
yuuji@13
|
487 (if (> argc 0) (insert (format "[%d]" argc)))
|
yuuji@13
|
488 (if (and (stringp command)
|
yuuji@13
|
489 (string< "" command)
|
yuuji@13
|
490 (y-or-n-p "Update user completion table?"))
|
yuuji@18
|
491 (cond
|
yuuji@18
|
492 ((= argc 0)
|
yuuji@18
|
493 (YaTeX-update-table
|
yuuji@18
|
494 (list command)
|
yuuji@18
|
495 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table))
|
yuuji@18
|
496 ((= argc 1)
|
yuuji@18
|
497 (YaTeX-update-table
|
yuuji@18
|
498 (list command)
|
yuuji@18
|
499 'section-table 'user-section-table 'tmp-section-table))
|
yuuji@18
|
500 (t (YaTeX-update-table
|
yuuji@18
|
501 (list command argc)
|
yuuji@18
|
502 'section-table 'user-section-table 'tmp-section-table))))
|
yuuji@13
|
503 (message "")
|
yuuji@13
|
504 def ;return command name
|
yuuji@13
|
505 ))
|
yuuji@13
|
506 (t ""))
|
yuuji@13
|
507 )
|
yuuji@13
|
508
|
yuuji@16
|
509 ;;
|
yuuji@16
|
510 ; completion for the arguments of \pagestyle
|
yuuji@16
|
511 ;;
|
yuuji@16
|
512 (defun YaTeX::pagestyle (&optional argp)
|
yuuji@16
|
513 "Read the pagestyle with completion."
|
yuuji@16
|
514 (completing-read
|
yuuji@16
|
515 "Page style: "
|
yuuji@16
|
516 '(("plain") ("empty") ("headings") ("myheadings") ("normal") nil))
|
yuuji@16
|
517 )
|
yuuji@16
|
518 ;;
|
yuuji@16
|
519 ; completion for the arguments of \pagenumbering
|
yuuji@16
|
520 ;;
|
yuuji@16
|
521 (defun YaTeX::pagenumbering (&optional argp)
|
yuuji@16
|
522 "Read the numbering style."
|
yuuji@16
|
523 (completing-read
|
yuuji@16
|
524 "Page numbering style: "
|
yuuji@16
|
525 '(("arabic") ("Alpha") ("alpha") ("Roman") ("roman")))
|
yuuji@16
|
526 )
|
yuuji@13
|
527
|
yuuji@23
|
528 ;;
|
yuuji@23
|
529 ; Length
|
yuuji@23
|
530 ;;
|
yuuji@23
|
531 (defvar YaTeX:style-parameters-default
|
yuuji@23
|
532 '(("\\arraycolsep")
|
yuuji@23
|
533 ("\\arrayrulewidth")
|
yuuji@23
|
534 ("\\baselineskip")
|
yuuji@23
|
535 ("\\columnsep")
|
yuuji@23
|
536 ("\\columnseprule")
|
yuuji@23
|
537 ("\\doublerulesep")
|
yuuji@23
|
538 ("\\evensidemargin")
|
yuuji@23
|
539 ("\\footheight")
|
yuuji@23
|
540 ("\\footskip")
|
yuuji@23
|
541 ("\\headheight")
|
yuuji@23
|
542 ("\\headsep")
|
yuuji@23
|
543 ("\\itemindent")
|
yuuji@23
|
544 ("\\itemsep")
|
yuuji@23
|
545 ("\\labelsep")
|
yuuji@23
|
546 ("\\labelwidth")
|
yuuji@23
|
547 ("\\leftmargin")
|
yuuji@23
|
548 ("\\linewidth")
|
yuuji@23
|
549 ("\\listparindent")
|
yuuji@23
|
550 ("\\marginparsep")
|
yuuji@23
|
551 ("\\marginparwidth")
|
yuuji@23
|
552 ("\\mathindent")
|
yuuji@23
|
553 ("\\oddsidemargin")
|
yuuji@23
|
554 ("\\parindent")
|
yuuji@23
|
555 ("\\parsep")
|
yuuji@23
|
556 ("\\parskip")
|
yuuji@23
|
557 ("\\partopsep")
|
yuuji@23
|
558 ("\\rightmargin")
|
yuuji@23
|
559 ("\\tabcolsep")
|
yuuji@23
|
560 ("\\textheight")
|
yuuji@23
|
561 ("\\textwidth")
|
yuuji@23
|
562 ("\\topmargin")
|
yuuji@23
|
563 ("\\topsep")
|
yuuji@23
|
564 ("\\topskip")
|
yuuji@23
|
565 )
|
yuuji@23
|
566 "Alist of LaTeX style parameters.")
|
yuuji@23
|
567 (defvar YaTeX:style-parameters-private nil
|
yuuji@23
|
568 "*User definable alist of style parameters.")
|
yuuji@49
|
569 (defvar YaTeX:style-parameters-local nil
|
yuuji@49
|
570 "*User definable alist of local style parameters.")
|
yuuji@23
|
571
|
yuuji@23
|
572 (defvar YaTeX:length-history nil "Holds history of length.")
|
yuuji@23
|
573 (defun YaTeX::setlength (&optional argp)
|
yuuji@23
|
574 "YaTeX add-in function for arguments of \\setlength."
|
yuuji@23
|
575 (cond
|
yuuji@23
|
576 ((equal 1 argp)
|
yuuji@49
|
577 ;;(completing-read "Length variable: " YaTeX:style-parameters nil nil "\\")
|
yuuji@49
|
578 (YaTeX-cplread-with-learning
|
yuuji@49
|
579 "Length variable: "
|
yuuji@49
|
580 'YaTeX:style-parameters-default
|
yuuji@49
|
581 'YaTeX:style-parameters-private
|
yuuji@49
|
582 'YaTeX:style-parameters-local
|
yuuji@49
|
583 nil nil "\\")
|
yuuji@49
|
584 )
|
yuuji@23
|
585 ((equal 2 argp)
|
yuuji@23
|
586 (let ((minibuffer-history-symbol 'YaTeX:length-history))
|
yuuji@23
|
587 (read-string "Length: "))))
|
yuuji@23
|
588 )
|
yuuji@23
|
589 (fset 'YaTeX::addtolength 'YaTeX::setlength)
|
yuuji@23
|
590
|
yuuji@23
|
591 (defun YaTeX::settowidth (&optional argp)
|
yuuji@23
|
592 "YaTeX add-in function for arguments of \\settowidth."
|
yuuji@23
|
593 (cond
|
yuuji@23
|
594 ((equal 1 argp)
|
yuuji@49
|
595 (YaTeX-cplread-with-learning
|
yuuji@49
|
596 "Length variable: "
|
yuuji@49
|
597 'YaTeX:style-parameters-default
|
yuuji@49
|
598 'YaTeX:style-parameters-private
|
yuuji@49
|
599 'YaTeX:style-parameters-local
|
yuuji@49
|
600 nil nil "\\"))
|
yuuji@23
|
601 ((equal 2 argp)
|
yuuji@23
|
602 (read-string "Text: ")))
|
yuuji@23
|
603 )
|
yuuji@23
|
604 (defun YaTeX::newlength (&optional argp)
|
yuuji@23
|
605 "YaTeX add-in function for arguments of \\newlength"
|
yuuji@23
|
606 (cond
|
yuuji@23
|
607 ((equal argp 1)
|
yuuji@23
|
608 (let ((length (read-string "Length variable: " "\\")))
|
yuuji@49
|
609 (if (string< "" length)
|
yuuji@49
|
610 (YaTeX-update-table
|
yuuji@49
|
611 (list length)
|
yuuji@49
|
612 'YaTeX:style-parameters-default
|
yuuji@49
|
613 'YaTeX:style-parameters-private
|
yuuji@49
|
614 'YaTeX:style-parameters-local))
|
yuuji@49
|
615 length)
|
yuuji@49
|
616 ))
|
yuuji@23
|
617 )
|
yuuji@23
|
618
|
yuuji@23
|
619 ;; \multicolumn's arguments
|
yuuji@23
|
620 (defun YaTeX::multicolumn (&optional argp)
|
yuuji@23
|
621 "YaTeX add-in function for arguments of \\multicolumn."
|
yuuji@23
|
622 (cond
|
yuuji@23
|
623 ((equal 1 argp)
|
yuuji@23
|
624 (read-string "Number of columns: "))
|
yuuji@23
|
625 ((equal 2 argp)
|
yuuji@23
|
626 (let (c)
|
yuuji@23
|
627 (while (not (string-match
|
yuuji@23
|
628 (progn (message "Format(one of l,r,c): ")
|
yuuji@23
|
629 (setq c (char-to-string (read-char))))
|
yuuji@23
|
630 "lrc")))
|
yuuji@23
|
631 c))
|
yuuji@23
|
632 ((equal 3 argp)
|
yuuji@23
|
633 (read-string "Item: ")))
|
yuuji@23
|
634 )
|
yuuji@23
|
635
|
yuuji@49
|
636 (defvar YaTeX:documentstyles-default
|
yuuji@49
|
637 '(("article") ("jarticle") ("j-article")
|
yuuji@49
|
638 ("book") ("jbook") ("j-book")
|
yuuji@49
|
639 ("report") ("jreport") ("j-report")
|
yuuji@49
|
640 ("letter") ("ascjletter"))
|
yuuji@49
|
641 "List of LaTeX documentstyles.")
|
yuuji@49
|
642 (defvar YaTeX:documentstyles-private nil
|
yuuji@49
|
643 "*User defined list of LaTeX documentstyles.")
|
yuuji@49
|
644 (defvar YaTeX:documentstyles-local nil
|
yuuji@49
|
645 "*User defined list of local LaTeX documentstyles.")
|
yuuji@49
|
646 (defvar YaTeX:documentstyle-options-default
|
yuuji@49
|
647 '(("a4j") ("a5j") ("b4j") ("b5j")
|
yuuji@49
|
648 ("twocolumn") ("jtwocolumn") ("epsf") ("epsfig") ("epsbox") ("nfig"))
|
yuuji@49
|
649 "List of LaTeX documentstyle options.")
|
yuuji@49
|
650 (defvar YaTeX:documentstyle-options-private nil
|
yuuji@49
|
651 "*User defined list of LaTeX documentstyle options.")
|
yuuji@49
|
652 (defvar YaTeX:documentstyle-options-local nil
|
yuuji@49
|
653 "List of LaTeX local documentstyle options.")
|
yuuji@49
|
654
|
yuuji@49
|
655 (defvar YaTeX-minibuffer-completion-map nil
|
yuuji@49
|
656 "Minibuffer completion key map that allows comma completion.")
|
yuuji@49
|
657 (if YaTeX-minibuffer-completion-map nil
|
yuuji@49
|
658 (setq YaTeX-minibuffer-completion-map
|
yuuji@49
|
659 (copy-keymap minibuffer-local-completion-map))
|
yuuji@49
|
660 (define-key YaTeX-minibuffer-completion-map " "
|
yuuji@49
|
661 'YaTeX-minibuffer-complete)
|
yuuji@49
|
662 (define-key YaTeX-minibuffer-completion-map "\t"
|
yuuji@49
|
663 'YaTeX-minibuffer-complete))
|
yuuji@49
|
664
|
yuuji@49
|
665 (defun YaTeX:documentstyle ()
|
yuuji@49
|
666 (let*((delim ",")
|
yuuji@49
|
667 (dt (append YaTeX:documentstyle-options-local
|
yuuji@49
|
668 YaTeX:documentstyle-options-private
|
yuuji@49
|
669 YaTeX:documentstyle-options-default))
|
yuuji@49
|
670 (minibuffer-completion-table dt)
|
yuuji@49
|
671 (opt (read-from-minibuffer
|
yuuji@49
|
672 "Style options ([opt1,opt2,...]): "
|
yuuji@49
|
673 nil YaTeX-minibuffer-completion-map))
|
yuuji@49
|
674 (substr opt) o)
|
yuuji@49
|
675 (if (string< "" opt)
|
yuuji@49
|
676 (progn
|
yuuji@49
|
677 (while substr
|
yuuji@49
|
678 (setq o (substring substr 0 (string-match delim substr)))
|
yuuji@49
|
679 (or (assoc o dt)
|
yuuji@49
|
680 (YaTeX-update-table
|
yuuji@49
|
681 (list o)
|
yuuji@49
|
682 'YaTeX:documentstyle-options-default
|
yuuji@49
|
683 'YaTeX:documentstyle-options-private
|
yuuji@49
|
684 'YaTeX:documentstyle-options-local))
|
yuuji@49
|
685 (setq substr
|
yuuji@49
|
686 (if (string-match delim substr)
|
yuuji@49
|
687 (substring substr (1+ (string-match delim substr))))))
|
yuuji@49
|
688 (concat "[" opt "]"))
|
yuuji@49
|
689 "")))
|
yuuji@49
|
690
|
yuuji@49
|
691 (defun YaTeX::documentstyle (&optional argp)
|
yuuji@49
|
692 "YaTeX add-in function for arguments of \\socumentstyle."
|
yuuji@49
|
693 (cond
|
yuuji@49
|
694 ((equal argp 1)
|
yuuji@49
|
695 (let ((sname
|
yuuji@49
|
696 (YaTeX-cplread-with-learning
|
yuuji@49
|
697 (format "Documentstyle (default %s): "
|
yuuji@49
|
698 YaTeX-default-document-style)
|
yuuji@49
|
699 'YaTeX:documentstyles-default
|
yuuji@49
|
700 'YaTeX:documentstyles-private
|
yuuji@49
|
701 'YaTeX:documentstyles-local)))
|
yuuji@49
|
702 (if (string= "" sname) (setq sname YaTeX-default-document-style))
|
yuuji@49
|
703 (setq YaTeX-default-document-style sname))))
|
yuuji@49
|
704 )
|
yuuji@49
|
705
|
yuuji@23
|
706 ;;; -------------------- End of yatexadd --------------------
|
yuuji@23
|
707 (provide 'yatexadd)
|