rev |
line source |
yuuji@6
|
1 ;;; -*- Emacs-Lisp -*-
|
yuuji@8
|
2 ;;; YaTeX add-in functions.
|
yuuji@53
|
3 ;;; yatexadd.el rev.13
|
yuuji@52
|
4 ;;; (c )1991-1995 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
|
yuuji@53
|
5 ;;; Last modified Thu Jan 26 03:31:20 1995 on figaro
|
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@51
|
179 (defvar YaTeX-minibuffer-quick-map nil)
|
yuuji@51
|
180 (if YaTeX-minibuffer-quick-map nil
|
yuuji@51
|
181 (setq YaTeX-minibuffer-quick-map
|
yuuji@51
|
182 (copy-keymap minibuffer-local-completion-map))
|
yuuji@51
|
183 (let ((ch (1+ ? )))
|
yuuji@51
|
184 (while (< ch 127)
|
yuuji@51
|
185 (define-key YaTeX-minibuffer-quick-map (char-to-string ch)
|
yuuji@51
|
186 'YaTeX-minibuffer-quick-complete)
|
yuuji@51
|
187 (setq ch (1+ ch)))))
|
yuuji@51
|
188
|
yuuji@51
|
189 (defvar YaTeX:left-right-delimiters
|
yuuji@51
|
190 '(("(" . ")") (")" . "(") ("[" . "]") ("]" . "[")
|
yuuji@51
|
191 ("\\{" . "\\}") ("\\}" . "\\{") ("|") ("\\|")
|
yuuji@51
|
192 ("\\lfloor" . "\\rfloor") ("\\lceil" . "\\rceil")
|
yuuji@51
|
193 ("\\langle" . "\\rangle") ("/") (".")
|
yuuji@51
|
194 ("\\rfloor" . "\\rfloor") ("\\rceil" . "\\lceil")
|
yuuji@51
|
195 ("\\rangle" . "\\langle") ("\\backslash")
|
yuuji@51
|
196 ("\\uparrow") ("\\downarrow") ("\\updownarrow") ("\\Updownarrow"))
|
yuuji@51
|
197 "TeX math delimiter, which can be completed after \\right or \\left.")
|
yuuji@51
|
198
|
yuuji@51
|
199 (defvar YaTeX:left-right-default nil "Default string of YaTeX:right.")
|
yuuji@51
|
200
|
yuuji@23
|
201 (defun YaTeX:left ()
|
yuuji@51
|
202 (let ((minibuffer-completion-table YaTeX:left-right-delimiters)
|
yuuji@51
|
203 delimiter (leftp (string= single-command "left")))
|
yuuji@51
|
204 (setq delimiter
|
yuuji@51
|
205 (read-from-minibuffer
|
yuuji@51
|
206 (format "Delimiter%s: "
|
yuuji@51
|
207 (if YaTeX:left-right-default
|
yuuji@51
|
208 (format "(default=`%s')" YaTeX:left-right-default)
|
yuuji@51
|
209 "(SPC for menu)"))
|
yuuji@51
|
210 nil YaTeX-minibuffer-quick-map))
|
yuuji@51
|
211 (if (string= "" delimiter) (setq delimiter YaTeX:left-right-default))
|
yuuji@51
|
212 (setq single-command (if leftp "right" "left")
|
yuuji@51
|
213 YaTeX:left-right-default
|
yuuji@51
|
214 (or (cdr (assoc delimiter YaTeX:left-right-delimiters)) delimiter))
|
yuuji@51
|
215 delimiter))
|
yuuji@51
|
216
|
yuuji@23
|
217 (fset 'YaTeX:right 'YaTeX:left)
|
yuuji@23
|
218
|
yuuji@51
|
219
|
yuuji@8
|
220 (defun YaTeX:read-coordinates (&optional mes varX varY)
|
yuuji@8
|
221 (concat
|
yuuji@8
|
222 "("
|
yuuji@8
|
223 (read-string (format "%s %s: " (or mes "Dimension") (or varX "X")))
|
yuuji@8
|
224 ","
|
yuuji@8
|
225 (read-string (format "%s %s: " (or mes "Dimension") (or varY "Y")))
|
yuuji@8
|
226 ")")
|
yuuji@8
|
227 )
|
yuuji@8
|
228
|
yuuji@8
|
229 ;;;
|
yuuji@8
|
230 ;;Sample functions for maketitle-type command.
|
yuuji@8
|
231 ;;;
|
yuuji@8
|
232 (defun YaTeX:sum ()
|
yuuji@8
|
233 "Read range of summation."
|
yuuji@8
|
234 (YaTeX:check-completion-type 'maketitle)
|
yuuji@8
|
235 (concat (YaTeX:read-boundary "_") (YaTeX:read-boundary "^"))
|
yuuji@8
|
236 )
|
yuuji@8
|
237
|
yuuji@8
|
238 (fset 'YaTeX:int 'YaTeX:sum)
|
yuuji@8
|
239
|
yuuji@8
|
240 (defun YaTeX:lim ()
|
yuuji@8
|
241 "Insert limit notation of \\lim."
|
yuuji@8
|
242 (YaTeX:check-completion-type 'maketitle)
|
yuuji@8
|
243 (let ((var (read-string "Variable: ")) limit)
|
yuuji@8
|
244 (if (string= "" var) ""
|
yuuji@8
|
245 (setq limit (read-string "Limit ($ means infinity): "))
|
yuuji@8
|
246 (if (string= "$" limit) (setq limit "\\infty"))
|
yuuji@8
|
247 (concat "_{" var " \\rightarrow " limit "}")))
|
yuuji@8
|
248 )
|
yuuji@8
|
249
|
yuuji@8
|
250 (defun YaTeX:gcd ()
|
yuuji@8
|
251 "Add-in function for \\gcd(m,n)."
|
yuuji@8
|
252 (YaTeX:check-completion-type 'maketitle)
|
yuuji@8
|
253 (YaTeX:read-coordinates "\\gcd" "(?,)" "(,?)")
|
yuuji@8
|
254 )
|
yuuji@8
|
255
|
yuuji@8
|
256 (defun YaTeX:read-boundary (ULchar)
|
yuuji@8
|
257 "Read boundary usage by _ or ^. _ or ^ is indicated by argument ULchar."
|
yuuji@11
|
258 (let ((bndry (read-string (concat ULchar "{???} ($ for infinity): "))))
|
yuuji@8
|
259 (if (string= bndry "") ""
|
yuuji@11
|
260 (if (string= bndry "$") (setq bndry "\\infty"))
|
yuuji@8
|
261 (concat ULchar "{" bndry "}")))
|
yuuji@8
|
262 )
|
yuuji@8
|
263
|
yuuji@14
|
264 (defun YaTeX:verb ()
|
yuuji@14
|
265 "Enclose \\verb's contents with the same characters."
|
yuuji@14
|
266 (let ((quote-char (read-string "Quoting char: " "|"))
|
yuuji@14
|
267 (contents (read-string "Quoted contents: ")))
|
yuuji@14
|
268 (concat quote-char contents quote-char))
|
yuuji@14
|
269 )
|
yuuji@23
|
270 (fset 'YaTeX:verb* 'YaTeX:verb)
|
yuuji@14
|
271
|
yuuji@43
|
272 (defun YaTeX:footnotemark ()
|
yuuji@43
|
273 (setq section-name "footnotetext")
|
yuuji@43
|
274 nil
|
yuuji@43
|
275 )
|
yuuji@43
|
276
|
yuuji@48
|
277 (defun YaTeX:cite ()
|
yuuji@48
|
278 (let ((comment (read-string "Comment for citation: ")))
|
yuuji@48
|
279 (if (string= comment "") ""
|
yuuji@48
|
280 (concat "[" comment "]")))
|
yuuji@48
|
281 )
|
yuuji@48
|
282
|
yuuji@48
|
283 (defun YaTeX:bibitem ()
|
yuuji@48
|
284 (let ((label (read-string "Citation label: ")))
|
yuuji@48
|
285 (if (string= label "") ""
|
yuuji@48
|
286 (concat "[" label "]")))
|
yuuji@48
|
287 )
|
yuuji@48
|
288
|
yuuji@53
|
289 (defun YaTeX:item ()
|
yuuji@53
|
290 (YaTeX-indent-line)
|
yuuji@53
|
291 (setq section-name "label")
|
yuuji@53
|
292 " ")
|
yuuji@52
|
293 (fset 'YaTeX:item\[\] 'YaTeX:item)
|
yuuji@52
|
294 (fset 'YaTeX:subitem 'YaTeX:item)
|
yuuji@52
|
295 (fset 'YaTeX:subsubitem 'YaTeX:item)
|
yuuji@52
|
296
|
yuuji@14
|
297 ;;;
|
yuuji@14
|
298 ;;Subroutine
|
yuuji@14
|
299 ;;;
|
yuuji@14
|
300
|
yuuji@8
|
301 (defun YaTeX:check-completion-type (type)
|
yuuji@8
|
302 "Check valid completion type."
|
yuuji@8
|
303 (if (not (eq type YaTeX-current-completion-type))
|
yuuji@8
|
304 (error "This should be completed with %s-type completion." type))
|
yuuji@8
|
305 )
|
yuuji@11
|
306
|
yuuji@11
|
307
|
yuuji@11
|
308 ;;;
|
yuuji@11
|
309 ;;; [[Add-in functions for reading section arguments]]
|
yuuji@11
|
310 ;;;
|
yuuji@11
|
311 ;; All of add-in functions for reading sections arguments should
|
yuuji@11
|
312 ;; take an argument ARGP that specify the argument position.
|
yuuji@11
|
313 ;; If argument position is out of range, nil should be returned,
|
yuuji@11
|
314 ;; else nil should NOT be returned.
|
yuuji@13
|
315
|
yuuji@13
|
316 ;;
|
yuuji@13
|
317 ; Label selection
|
yuuji@13
|
318 ;;
|
yuuji@11
|
319 (defvar YaTeX-label-menu-other
|
yuuji@11
|
320 (if YaTeX-japan "':‘¼‚̃oƒbƒtƒ@‚̃‰ƒxƒ‹\n" "':LABEL IN OTHER BUFFER.\n"))
|
yuuji@23
|
321 (defvar YaTeX-label-menu-repeat
|
yuuji@23
|
322 (if YaTeX-japan ".:’¼‘O‚Ì\\ref‚Æ“¯‚¶\n" "/:REPEAT LAST \ref{}\n"))
|
yuuji@11
|
323 (defvar YaTeX-label-menu-any
|
yuuji@11
|
324 (if YaTeX-japan "*:”CˆÓ‚Ì•¶Žš—ñ\n" "*:ANY STRING.\n"))
|
yuuji@11
|
325 (defvar YaTeX-label-buffer "*Label completions*")
|
yuuji@11
|
326 (defvar YaTeX-label-guide-msg "Select label and hit RETURN.")
|
yuuji@11
|
327 (defvar YaTeX-label-select-map nil
|
yuuji@11
|
328 "Key map used in label selection buffer.")
|
yuuji@11
|
329 (defun YaTeX::label-setup-key-map ()
|
yuuji@11
|
330 (if YaTeX-label-select-map nil
|
yuuji@11
|
331 (message "Setting up label selection mode map...")
|
yuuji@11
|
332 (setq YaTeX-label-select-map (copy-keymap global-map))
|
yuuji@11
|
333 (suppress-keymap YaTeX-label-select-map)
|
yuuji@11
|
334 (substitute-all-key-definition
|
yuuji@11
|
335 'previous-line 'YaTeX::label-previous YaTeX-label-select-map)
|
yuuji@11
|
336 (substitute-all-key-definition
|
yuuji@11
|
337 'next-line 'YaTeX::label-next YaTeX-label-select-map)
|
yuuji@11
|
338 (define-key YaTeX-label-select-map "\C-n" 'YaTeX::label-next)
|
yuuji@11
|
339 (define-key YaTeX-label-select-map "\C-p" 'YaTeX::label-previous)
|
yuuji@11
|
340 (define-key YaTeX-label-select-map "<" 'beginning-of-buffer)
|
yuuji@11
|
341 (define-key YaTeX-label-select-map ">" 'end-of-buffer)
|
yuuji@11
|
342 (define-key YaTeX-label-select-map "\C-m" 'exit-recursive-edit)
|
yuuji@11
|
343 (define-key YaTeX-label-select-map "\C-j" 'exit-recursive-edit)
|
yuuji@11
|
344 (define-key YaTeX-label-select-map " " 'exit-recursive-edit)
|
yuuji@11
|
345 (define-key YaTeX-label-select-map "\C-g" 'abort-recursive-edit)
|
yuuji@11
|
346 (define-key YaTeX-label-select-map "/" 'isearch-forward)
|
yuuji@11
|
347 (define-key YaTeX-label-select-map "?" 'isearch-backward)
|
yuuji@11
|
348 (define-key YaTeX-label-select-map "'" 'YaTeX::label-search-tag)
|
yuuji@23
|
349 (define-key YaTeX-label-select-map "." 'YaTeX::label-search-tag)
|
yuuji@11
|
350 (define-key YaTeX-label-select-map "*" 'YaTeX::label-search-tag)
|
yuuji@11
|
351 (message "Setting up label selection mode map...Done")
|
yuuji@11
|
352 (let ((key ?A))
|
yuuji@11
|
353 (while (<= key ?Z)
|
yuuji@11
|
354 (define-key YaTeX-label-select-map (char-to-string key)
|
yuuji@11
|
355 'YaTeX::label-search-tag)
|
yuuji@11
|
356 (define-key YaTeX-label-select-map (char-to-string (+ key (- ?a ?A)))
|
yuuji@11
|
357 'YaTeX::label-search-tag)
|
yuuji@11
|
358 (setq key (1+ key)))))
|
yuuji@11
|
359 )
|
yuuji@11
|
360 (defun YaTeX::label-next ()
|
yuuji@11
|
361 (interactive) (forward-line 1) (message YaTeX-label-guide-msg))
|
yuuji@11
|
362 (defun YaTeX::label-previous ()
|
yuuji@11
|
363 (interactive) (forward-line -1) (message YaTeX-label-guide-msg))
|
yuuji@11
|
364 (defun YaTeX::label-search-tag ()
|
yuuji@11
|
365 (interactive)
|
yuuji@23
|
366 (let ((case-fold-search t) (tag (regexp-quote (this-command-keys))))
|
yuuji@11
|
367 (cond
|
yuuji@11
|
368 ((save-excursion
|
yuuji@11
|
369 (forward-char 1)
|
yuuji@23
|
370 (re-search-forward (concat "^" tag) nil t))
|
yuuji@11
|
371 (goto-char (match-beginning 0)))
|
yuuji@11
|
372 ((save-excursion
|
yuuji@11
|
373 (goto-char (point-min))
|
yuuji@23
|
374 (re-search-forward (concat "^" tag) nil t))
|
yuuji@11
|
375 (goto-char (match-beginning 0))))
|
yuuji@11
|
376 (message YaTeX-label-guide-msg))
|
yuuji@11
|
377 )
|
yuuji@48
|
378 (defun YaTeX::ref (argp &optional labelcmd refcmd)
|
yuuji@11
|
379 (cond
|
yuuji@11
|
380 ((= argp 1)
|
yuuji@11
|
381 (save-excursion
|
yuuji@48
|
382 (let ((lnum 0) e0 label label-list (buf (current-buffer))
|
yuuji@48
|
383 (labelcmd (or labelcmd "label")) (refcmd (or refcmd "ref"))
|
yuuji@11
|
384 (p (point)) initl line)
|
yuuji@11
|
385 (goto-char (point-min))
|
yuuji@11
|
386 (message "Collecting labels...")
|
yuuji@11
|
387 (save-window-excursion
|
yuuji@12
|
388 (YaTeX-showup-buffer
|
yuuji@12
|
389 YaTeX-label-buffer (function (lambda (x) (window-width x))))
|
yuuji@11
|
390 (with-output-to-temp-buffer YaTeX-label-buffer
|
yuuji@48
|
391 (while (YaTeX-re-search-active-forward
|
yuuji@48
|
392 (concat "\\\\" labelcmd)
|
yuuji@48
|
393 (regexp-quote YaTeX-comment-prefix) nil t)
|
yuuji@48
|
394 (goto-char (match-beginning 0))
|
yuuji@48
|
395 (skip-chars-forward "^{")
|
yuuji@48
|
396 (setq label
|
yuuji@48
|
397 (buffer-substring
|
yuuji@48
|
398 (1+ (point))
|
yuuji@48
|
399 (prog2 (forward-list 1) (setq e0 (1- (point)))))
|
yuuji@48
|
400 label-list (cons label label-list))
|
yuuji@48
|
401 (or initl
|
yuuji@48
|
402 (if (< p (point)) (setq initl lnum)))
|
yuuji@48
|
403 (beginning-of-line)
|
yuuji@48
|
404 (skip-chars-forward " \t\n" nil)
|
yuuji@48
|
405 (princ (format "%c:{%s}\t<<%s>>\n" (+ (% lnum 26) ?A) label
|
yuuji@48
|
406 (buffer-substring (point) (point-end-of-line))))
|
yuuji@48
|
407 (setq lnum (1+ lnum))
|
yuuji@48
|
408 (message "Collecting \\%s{}... %d" labelcmd lnum)
|
yuuji@11
|
409 (goto-char e0))
|
yuuji@11
|
410 (princ YaTeX-label-menu-other)
|
yuuji@23
|
411 (princ YaTeX-label-menu-repeat)
|
yuuji@11
|
412 (princ YaTeX-label-menu-any)
|
yuuji@11
|
413 );with
|
yuuji@11
|
414 (goto-char p)
|
yuuji@48
|
415 (message "Collecting %s...Done" labelcmd)
|
yuuji@11
|
416 (pop-to-buffer YaTeX-label-buffer)
|
yuuji@11
|
417 (YaTeX::label-setup-key-map)
|
yuuji@11
|
418 (setq truncate-lines t)
|
yuuji@11
|
419 (setq buffer-read-only t)
|
yuuji@11
|
420 (use-local-map YaTeX-label-select-map)
|
yuuji@11
|
421 (message YaTeX-label-guide-msg)
|
yuuji@11
|
422 (goto-line (or initl lnum)) ;goto recently defined label line
|
yuuji@11
|
423 (unwind-protect
|
yuuji@11
|
424 (progn
|
yuuji@11
|
425 (recursive-edit)
|
yuuji@11
|
426 (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
|
yuuji@11
|
427 (beginning-of-line)
|
yuuji@11
|
428 (setq line (count-lines (point-min)(point)))
|
yuuji@11
|
429 (cond
|
yuuji@11
|
430 ((= line lnum) (setq label (YaTeX-label-other)))
|
yuuji@23
|
431 ((= line (1+ lnum))
|
yuuji@23
|
432 (save-excursion
|
yuuji@23
|
433 (switch-to-buffer buf)
|
yuuji@23
|
434 (goto-char p)
|
yuuji@48
|
435 (if (re-search-backward
|
yuuji@48
|
436 (concat "\\\\" refcmd "{\\([^}]+\\)}") nil t)
|
yuuji@48
|
437 (setq label (YaTeX-match-string 1))
|
yuuji@23
|
438 (setq label ""))))
|
yuuji@23
|
439 ((>= line (+ lnum 2))
|
yuuji@48
|
440 (setq label (read-string (format "\\%s{???}: " refcmd))))
|
yuuji@11
|
441 (t (setq label (nth (- lnum line 1) label-list)))))
|
yuuji@11
|
442 (bury-buffer YaTeX-label-buffer)))
|
yuuji@11
|
443 label
|
yuuji@11
|
444 ))
|
yuuji@11
|
445 ))
|
yuuji@11
|
446 )
|
yuuji@16
|
447 (fset 'YaTeX::pageref 'YaTeX::ref)
|
yuuji@48
|
448 (defun YaTeX::cite (argp)
|
yuuji@48
|
449 (cond
|
yuuji@48
|
450 ((eq argp 1)
|
yuuji@48
|
451 (YaTeX::ref argp "bibitem\\(\\[.*\\]\\)?" "cite"))
|
yuuji@48
|
452 (t nil)))
|
yuuji@11
|
453
|
yuuji@48
|
454 (defun YaTeX-yatex-buffer-list ()
|
yuuji@48
|
455 (save-excursion
|
yuuji@48
|
456 (delq nil (mapcar (function (lambda (buf)
|
yuuji@48
|
457 (set-buffer buf)
|
yuuji@48
|
458 (if (eq major-mode 'yatex-mode) buf)))
|
yuuji@48
|
459 (buffer-list))))
|
yuuji@48
|
460 )
|
yuuji@48
|
461
|
yuuji@48
|
462 (defun YaTeX-select-other-yatex-buffer ()
|
yuuji@48
|
463 "Select buffer from all yatex-mode's buffers interactivelly."
|
yuuji@48
|
464 (interactive)
|
yuuji@48
|
465 (let ((lbuf "*YaTeX mode buffers*") (blist (YaTeX-yatex-buffer-list))
|
yuuji@48
|
466 (lnum -1) buf rv
|
yuuji@11
|
467 (ff "**find-file**"))
|
yuuji@12
|
468 (YaTeX-showup-buffer
|
yuuji@12
|
469 lbuf (function (lambda (x) 1))) ;;Select next window surely.
|
yuuji@11
|
470 (with-output-to-temp-buffer lbuf
|
yuuji@11
|
471 (while blist
|
yuuji@48
|
472 (princ
|
yuuji@48
|
473 (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A)
|
yuuji@48
|
474 (buffer-name (car blist))))
|
yuuji@11
|
475 (setq blist (cdr blist)))
|
yuuji@11
|
476 (princ (format "':{%s}" ff)))
|
yuuji@11
|
477 (pop-to-buffer lbuf)
|
yuuji@11
|
478 (YaTeX::label-setup-key-map)
|
yuuji@11
|
479 (setq buffer-read-only t)
|
yuuji@11
|
480 (use-local-map YaTeX-label-select-map)
|
yuuji@11
|
481 (message YaTeX-label-guide-msg)
|
yuuji@11
|
482 (unwind-protect
|
yuuji@11
|
483 (progn
|
yuuji@11
|
484 (recursive-edit)
|
yuuji@11
|
485 (set-buffer lbuf)
|
yuuji@11
|
486 (beginning-of-line)
|
yuuji@11
|
487 (setq rv
|
yuuji@11
|
488 (if (re-search-forward "{\\([^\\}]+\\)}" (point-end-of-line) t)
|
yuuji@11
|
489 (buffer-substring (match-beginning 1) (match-end 1)) nil)))
|
yuuji@11
|
490 (kill-buffer lbuf))
|
yuuji@48
|
491 (if (string= rv ff)
|
yuuji@48
|
492 (progn
|
yuuji@48
|
493 (call-interactively 'find-file)
|
yuuji@48
|
494 (current-buffer))
|
yuuji@48
|
495 rv))
|
yuuji@48
|
496 )
|
yuuji@48
|
497
|
yuuji@48
|
498 (defun YaTeX-label-other ()
|
yuuji@48
|
499 (let ((rv (YaTeX-select-other-yatex-buffer)))
|
yuuji@11
|
500 (cond
|
yuuji@11
|
501 ((null rv) "")
|
yuuji@11
|
502 (t
|
yuuji@11
|
503 (set-buffer rv)
|
yuuji@48
|
504 (YaTeX::ref argp labelcmd refcmd)))
|
yuuji@11
|
505 )
|
yuuji@11
|
506 )
|
yuuji@11
|
507
|
yuuji@13
|
508 ;;
|
yuuji@13
|
509 ; completion for the arguments of \newcommand
|
yuuji@13
|
510 ;;
|
yuuji@13
|
511 (defun YaTeX::newcommand (&optional argp)
|
yuuji@13
|
512 (cond
|
yuuji@13
|
513 ((= argp 1)
|
yuuji@13
|
514 (let ((command (read-string "Define newcommand: " "\\")))
|
yuuji@13
|
515 (put 'YaTeX::newcommand 'command (substring command 1))
|
yuuji@13
|
516 command))
|
yuuji@13
|
517 ((= argp 2)
|
yuuji@13
|
518 (let ((argc
|
yuuji@13
|
519 (string-to-int (read-string "Number of arguments(Default 0): ")))
|
yuuji@13
|
520 (def (read-string "Definition: "))
|
yuuji@13
|
521 (command (get 'YaTeX::newcommand 'command)))
|
yuuji@13
|
522 ;;!!! It's illegal to insert string in the add-in function !!!
|
yuuji@13
|
523 (if (> argc 0) (insert (format "[%d]" argc)))
|
yuuji@13
|
524 (if (and (stringp command)
|
yuuji@13
|
525 (string< "" command)
|
yuuji@51
|
526 (y-or-n-p "Update dictionary?"))
|
yuuji@18
|
527 (cond
|
yuuji@18
|
528 ((= argc 0)
|
yuuji@18
|
529 (YaTeX-update-table
|
yuuji@18
|
530 (list command)
|
yuuji@18
|
531 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table))
|
yuuji@18
|
532 ((= argc 1)
|
yuuji@18
|
533 (YaTeX-update-table
|
yuuji@18
|
534 (list command)
|
yuuji@18
|
535 'section-table 'user-section-table 'tmp-section-table))
|
yuuji@18
|
536 (t (YaTeX-update-table
|
yuuji@18
|
537 (list command argc)
|
yuuji@18
|
538 'section-table 'user-section-table 'tmp-section-table))))
|
yuuji@13
|
539 (message "")
|
yuuji@13
|
540 def ;return command name
|
yuuji@13
|
541 ))
|
yuuji@13
|
542 (t ""))
|
yuuji@13
|
543 )
|
yuuji@13
|
544
|
yuuji@16
|
545 ;;
|
yuuji@16
|
546 ; completion for the arguments of \pagestyle
|
yuuji@16
|
547 ;;
|
yuuji@16
|
548 (defun YaTeX::pagestyle (&optional argp)
|
yuuji@16
|
549 "Read the pagestyle with completion."
|
yuuji@16
|
550 (completing-read
|
yuuji@16
|
551 "Page style: "
|
yuuji@16
|
552 '(("plain") ("empty") ("headings") ("myheadings") ("normal") nil))
|
yuuji@16
|
553 )
|
yuuji@51
|
554 (fset 'YaTeX::thispagestyle 'YaTeX::pagestyle)
|
yuuji@51
|
555
|
yuuji@16
|
556 ;;
|
yuuji@16
|
557 ; completion for the arguments of \pagenumbering
|
yuuji@16
|
558 ;;
|
yuuji@16
|
559 (defun YaTeX::pagenumbering (&optional argp)
|
yuuji@16
|
560 "Read the numbering style."
|
yuuji@16
|
561 (completing-read
|
yuuji@16
|
562 "Page numbering style: "
|
yuuji@16
|
563 '(("arabic") ("Alpha") ("alpha") ("Roman") ("roman")))
|
yuuji@16
|
564 )
|
yuuji@13
|
565
|
yuuji@23
|
566 ;;
|
yuuji@23
|
567 ; Length
|
yuuji@23
|
568 ;;
|
yuuji@23
|
569 (defvar YaTeX:style-parameters-default
|
yuuji@23
|
570 '(("\\arraycolsep")
|
yuuji@23
|
571 ("\\arrayrulewidth")
|
yuuji@23
|
572 ("\\baselineskip")
|
yuuji@23
|
573 ("\\columnsep")
|
yuuji@23
|
574 ("\\columnseprule")
|
yuuji@23
|
575 ("\\doublerulesep")
|
yuuji@23
|
576 ("\\evensidemargin")
|
yuuji@23
|
577 ("\\footheight")
|
yuuji@23
|
578 ("\\footskip")
|
yuuji@23
|
579 ("\\headheight")
|
yuuji@23
|
580 ("\\headsep")
|
yuuji@23
|
581 ("\\itemindent")
|
yuuji@23
|
582 ("\\itemsep")
|
yuuji@23
|
583 ("\\labelsep")
|
yuuji@23
|
584 ("\\labelwidth")
|
yuuji@23
|
585 ("\\leftmargin")
|
yuuji@23
|
586 ("\\linewidth")
|
yuuji@23
|
587 ("\\listparindent")
|
yuuji@23
|
588 ("\\marginparsep")
|
yuuji@23
|
589 ("\\marginparwidth")
|
yuuji@23
|
590 ("\\mathindent")
|
yuuji@23
|
591 ("\\oddsidemargin")
|
yuuji@23
|
592 ("\\parindent")
|
yuuji@23
|
593 ("\\parsep")
|
yuuji@23
|
594 ("\\parskip")
|
yuuji@23
|
595 ("\\partopsep")
|
yuuji@23
|
596 ("\\rightmargin")
|
yuuji@23
|
597 ("\\tabcolsep")
|
yuuji@23
|
598 ("\\textheight")
|
yuuji@23
|
599 ("\\textwidth")
|
yuuji@23
|
600 ("\\topmargin")
|
yuuji@23
|
601 ("\\topsep")
|
yuuji@23
|
602 ("\\topskip")
|
yuuji@23
|
603 )
|
yuuji@23
|
604 "Alist of LaTeX style parameters.")
|
yuuji@23
|
605 (defvar YaTeX:style-parameters-private nil
|
yuuji@23
|
606 "*User definable alist of style parameters.")
|
yuuji@49
|
607 (defvar YaTeX:style-parameters-local nil
|
yuuji@49
|
608 "*User definable alist of local style parameters.")
|
yuuji@23
|
609
|
yuuji@23
|
610 (defvar YaTeX:length-history nil "Holds history of length.")
|
yuuji@51
|
611 (put 'YaTeX:length-history 'no-default t)
|
yuuji@23
|
612 (defun YaTeX::setlength (&optional argp)
|
yuuji@23
|
613 "YaTeX add-in function for arguments of \\setlength."
|
yuuji@23
|
614 (cond
|
yuuji@23
|
615 ((equal 1 argp)
|
yuuji@49
|
616 ;;(completing-read "Length variable: " YaTeX:style-parameters nil nil "\\")
|
yuuji@49
|
617 (YaTeX-cplread-with-learning
|
yuuji@49
|
618 "Length variable: "
|
yuuji@49
|
619 'YaTeX:style-parameters-default
|
yuuji@49
|
620 'YaTeX:style-parameters-private
|
yuuji@49
|
621 'YaTeX:style-parameters-local
|
yuuji@49
|
622 nil nil "\\")
|
yuuji@49
|
623 )
|
yuuji@23
|
624 ((equal 2 argp)
|
yuuji@51
|
625 (read-string-with-history "Length: " nil 'YaTeX:length-history)))
|
yuuji@23
|
626 )
|
yuuji@23
|
627 (fset 'YaTeX::addtolength 'YaTeX::setlength)
|
yuuji@23
|
628
|
yuuji@23
|
629 (defun YaTeX::settowidth (&optional argp)
|
yuuji@23
|
630 "YaTeX add-in function for arguments of \\settowidth."
|
yuuji@23
|
631 (cond
|
yuuji@23
|
632 ((equal 1 argp)
|
yuuji@49
|
633 (YaTeX-cplread-with-learning
|
yuuji@49
|
634 "Length variable: "
|
yuuji@49
|
635 'YaTeX:style-parameters-default
|
yuuji@49
|
636 'YaTeX:style-parameters-private
|
yuuji@49
|
637 'YaTeX:style-parameters-local
|
yuuji@49
|
638 nil nil "\\"))
|
yuuji@23
|
639 ((equal 2 argp)
|
yuuji@23
|
640 (read-string "Text: ")))
|
yuuji@23
|
641 )
|
yuuji@23
|
642 (defun YaTeX::newlength (&optional argp)
|
yuuji@23
|
643 "YaTeX add-in function for arguments of \\newlength"
|
yuuji@23
|
644 (cond
|
yuuji@23
|
645 ((equal argp 1)
|
yuuji@23
|
646 (let ((length (read-string "Length variable: " "\\")))
|
yuuji@49
|
647 (if (string< "" length)
|
yuuji@49
|
648 (YaTeX-update-table
|
yuuji@49
|
649 (list length)
|
yuuji@49
|
650 'YaTeX:style-parameters-default
|
yuuji@49
|
651 'YaTeX:style-parameters-private
|
yuuji@49
|
652 'YaTeX:style-parameters-local))
|
yuuji@49
|
653 length)
|
yuuji@49
|
654 ))
|
yuuji@23
|
655 )
|
yuuji@23
|
656
|
yuuji@23
|
657 ;; \multicolumn's arguments
|
yuuji@23
|
658 (defun YaTeX::multicolumn (&optional argp)
|
yuuji@23
|
659 "YaTeX add-in function for arguments of \\multicolumn."
|
yuuji@23
|
660 (cond
|
yuuji@23
|
661 ((equal 1 argp)
|
yuuji@23
|
662 (read-string "Number of columns: "))
|
yuuji@23
|
663 ((equal 2 argp)
|
yuuji@23
|
664 (let (c)
|
yuuji@23
|
665 (while (not (string-match
|
yuuji@23
|
666 (progn (message "Format(one of l,r,c): ")
|
yuuji@23
|
667 (setq c (char-to-string (read-char))))
|
yuuji@23
|
668 "lrc")))
|
yuuji@23
|
669 c))
|
yuuji@23
|
670 ((equal 3 argp)
|
yuuji@23
|
671 (read-string "Item: ")))
|
yuuji@23
|
672 )
|
yuuji@23
|
673
|
yuuji@49
|
674 (defvar YaTeX:documentstyles-default
|
yuuji@49
|
675 '(("article") ("jarticle") ("j-article")
|
yuuji@49
|
676 ("book") ("jbook") ("j-book")
|
yuuji@49
|
677 ("report") ("jreport") ("j-report")
|
yuuji@49
|
678 ("letter") ("ascjletter"))
|
yuuji@49
|
679 "List of LaTeX documentstyles.")
|
yuuji@49
|
680 (defvar YaTeX:documentstyles-private nil
|
yuuji@49
|
681 "*User defined list of LaTeX documentstyles.")
|
yuuji@49
|
682 (defvar YaTeX:documentstyles-local nil
|
yuuji@49
|
683 "*User defined list of local LaTeX documentstyles.")
|
yuuji@49
|
684 (defvar YaTeX:documentstyle-options-default
|
yuuji@49
|
685 '(("a4j") ("a5j") ("b4j") ("b5j")
|
yuuji@49
|
686 ("twocolumn") ("jtwocolumn") ("epsf") ("epsfig") ("epsbox") ("nfig"))
|
yuuji@49
|
687 "List of LaTeX documentstyle options.")
|
yuuji@49
|
688 (defvar YaTeX:documentstyle-options-private nil
|
yuuji@49
|
689 "*User defined list of LaTeX documentstyle options.")
|
yuuji@49
|
690 (defvar YaTeX:documentstyle-options-local nil
|
yuuji@49
|
691 "List of LaTeX local documentstyle options.")
|
yuuji@49
|
692
|
yuuji@49
|
693 (defvar YaTeX-minibuffer-completion-map nil
|
yuuji@49
|
694 "Minibuffer completion key map that allows comma completion.")
|
yuuji@49
|
695 (if YaTeX-minibuffer-completion-map nil
|
yuuji@49
|
696 (setq YaTeX-minibuffer-completion-map
|
yuuji@49
|
697 (copy-keymap minibuffer-local-completion-map))
|
yuuji@49
|
698 (define-key YaTeX-minibuffer-completion-map " "
|
yuuji@49
|
699 'YaTeX-minibuffer-complete)
|
yuuji@49
|
700 (define-key YaTeX-minibuffer-completion-map "\t"
|
yuuji@49
|
701 'YaTeX-minibuffer-complete))
|
yuuji@49
|
702
|
yuuji@49
|
703 (defun YaTeX:documentstyle ()
|
yuuji@49
|
704 (let*((delim ",")
|
yuuji@49
|
705 (dt (append YaTeX:documentstyle-options-local
|
yuuji@49
|
706 YaTeX:documentstyle-options-private
|
yuuji@49
|
707 YaTeX:documentstyle-options-default))
|
yuuji@49
|
708 (minibuffer-completion-table dt)
|
yuuji@49
|
709 (opt (read-from-minibuffer
|
yuuji@49
|
710 "Style options ([opt1,opt2,...]): "
|
yuuji@51
|
711 nil YaTeX-minibuffer-completion-map nil))
|
yuuji@49
|
712 (substr opt) o)
|
yuuji@49
|
713 (if (string< "" opt)
|
yuuji@49
|
714 (progn
|
yuuji@49
|
715 (while substr
|
yuuji@49
|
716 (setq o (substring substr 0 (string-match delim substr)))
|
yuuji@49
|
717 (or (assoc o dt)
|
yuuji@49
|
718 (YaTeX-update-table
|
yuuji@49
|
719 (list o)
|
yuuji@49
|
720 'YaTeX:documentstyle-options-default
|
yuuji@49
|
721 'YaTeX:documentstyle-options-private
|
yuuji@49
|
722 'YaTeX:documentstyle-options-local))
|
yuuji@49
|
723 (setq substr
|
yuuji@49
|
724 (if (string-match delim substr)
|
yuuji@49
|
725 (substring substr (1+ (string-match delim substr))))))
|
yuuji@49
|
726 (concat "[" opt "]"))
|
yuuji@49
|
727 "")))
|
yuuji@49
|
728
|
yuuji@49
|
729 (defun YaTeX::documentstyle (&optional argp)
|
yuuji@51
|
730 "YaTeX add-in function for arguments of \\documentstyle."
|
yuuji@49
|
731 (cond
|
yuuji@49
|
732 ((equal argp 1)
|
yuuji@51
|
733 (setq env-name "document")
|
yuuji@49
|
734 (let ((sname
|
yuuji@49
|
735 (YaTeX-cplread-with-learning
|
yuuji@49
|
736 (format "Documentstyle (default %s): "
|
yuuji@49
|
737 YaTeX-default-document-style)
|
yuuji@49
|
738 'YaTeX:documentstyles-default
|
yuuji@49
|
739 'YaTeX:documentstyles-private
|
yuuji@49
|
740 'YaTeX:documentstyles-local)))
|
yuuji@49
|
741 (if (string= "" sname) (setq sname YaTeX-default-document-style))
|
yuuji@49
|
742 (setq YaTeX-default-document-style sname))))
|
yuuji@49
|
743 )
|
yuuji@49
|
744
|
yuuji@23
|
745 ;;; -------------------- End of yatexadd --------------------
|
yuuji@23
|
746 (provide 'yatexadd)
|