yatex

view yatexadd.el @ 79:0734be649cb8

Do not care file-coding-system when YaTeX-kanji-code is nil. New completion yatexpkg.el is introduced.
author yuuji
date Thu, 25 Dec 2003 04:10:32 +0000
parents 1b172d26b55e
children 9b4354af748c
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX add-in functions.
3 ;;; yatexadd.el rev.17
4 ;;; (c)1991-2003 by HIROSE Yuuji.[yuuji@yatex.org]
5 ;;; Last modified Thu Nov 27 11:11:30 2003 on firestorm
6 ;;; $Id$
8 ;;;
9 ;;Sample functions for LaTeX environment.
10 ;;;
11 (defvar YaTeX:tabular-default-rule
12 "@{\\vrule width 1pt\\ }c|c|c@{\\ \\vrule width 1pt}"
13 "*Your favorite default rule format.")
15 (defvar YaTeX:tabular-thick-vrule "\\vrule width %s"
16 "*Vertical thick line format (without @{}). %s'll be replaced by its width.")
18 (defvar YaTeX:tabular-thick-hrule "\\noalign{\\hrule height %s}"
19 "*Horizontal thick line format. %s will be replaced by its width.")
21 (defun YaTeX:tabular ()
22 "YaTeX add-in function for tabular environment.
23 Notice that this function refers the let-variable `env' in
24 YaTeX-make-begin-end."
25 (let ((width "") bars (rule "") (and "") (j 1) loc ans (hline "\\hline"))
26 (if (string= YaTeX-env-name "tabular*")
27 (setq width (concat "{" (read-string "Width: ") "}")))
28 (setq loc (YaTeX:read-position "tb")
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"))))
53 (setq rule (read-string "rule format: " rule))
54 (setq YaTeX-single-command "hline")
56 (format "%s%s{%s}" width loc rule)))
58 (fset 'YaTeX:tabular* 'YaTeX:tabular)
59 (defun YaTeX:array ()
60 (concat (YaTeX:read-position "tb")
61 "{" (read-string "Column format: ") "}"))
63 (defun YaTeX:read-oneof (oneof &optional quick allow-dup)
64 (let ((pos "") loc (guide ""))
65 (and (boundp 'name) name (setq guide (format "%s " name)))
66 (catch 'quick
67 (while (not (string-match
68 (setq loc (read-key-sequence
69 (format "%s position (`%s') [%s]: "
70 guide oneof pos));name is in YaTeX-addin
71 loc (if (fboundp 'events-to-keys)
72 (events-to-keys loc) loc))
73 "\r\^g\n"))
74 (cond
75 ((string-match loc oneof)
76 (if (or allow-dup (not (string-match loc pos)))
77 (setq pos (concat pos loc)))
78 (if quick (throw 'quick t)))
79 ((and (string-match loc "\C-h\C-?") (> (length pos) 0))
80 (setq pos (substring pos 0 (1- (length pos)))))
81 (t
82 (ding)
83 (message "Please input one of `%s'." oneof)
84 (sit-for 3)))))
85 (message "")
86 pos))
88 (defun YaTeX:read-position (oneof)
89 "Read a LaTeX (optional) position format such as `[htbp]'."
90 (let ((pos (YaTeX:read-oneof oneof)))
91 (if (string= pos "") "" (concat "[" pos "]"))))
93 (defun YaTeX:table ()
94 "YaTeX add-in function for table environment."
95 (cond
96 ((eq major-mode 'yatex-mode)
97 (setq YaTeX-env-name "tabular"
98 YaTeX-section-name "caption")
99 (YaTeX:read-position "htbp"))
100 ((eq major-mode 'texinfo-mode)
101 (concat " "
102 (completing-read
103 "Highlights with: "
104 '(("@samp")("@kbd")("@code")("@asis")("@file")("@var"))
105 nil nil "@")))))
107 (fset 'YaTeX:figure 'YaTeX:table)
108 (fset 'YaTeX:figure* 'YaTeX:table)
111 (defun YaTeX:description ()
112 "Truly poor service:-)"
113 (setq YaTeX-single-command "item[]")
114 "")
116 (defun YaTeX:itemize ()
117 "It's also poor service."
118 (setq YaTeX-single-command "item")
119 "")
121 (fset 'YaTeX:enumerate 'YaTeX:itemize)
123 (defun YaTeX:picture ()
124 "Ask the size of coordinates of picture environment."
125 (concat (YaTeX:read-coordinates "Picture size")
126 (YaTeX:read-coordinates "Initial position")))
128 (defun YaTeX:equation ()
129 (YaTeX-jmode-off)
130 (if (fboundp 'YaTeX-toggle-math-mode)
131 (YaTeX-toggle-math-mode t))) ;force math-mode ON.
133 (mapcar '(lambda (f) (fset f 'YaTeX:equation))
134 '(YaTeX:eqnarray YaTeX:eqnarray* YaTeX:align YaTeX:align*
135 YaTeX:split YaTeX:multline YaTeX:multline* YaTeX:gather YaTeX:gather*
136 YaTeX:aligned* YaTeX:gathered YaTeX:gathered*
137 YaTeX:alignat YaTeX:alignat* YaTeX:xalignat YaTeX:xalignat*
138 YaTeX:xxalignat YaTeX:xxalignat*))
140 (defun YaTeX:list ()
141 "%\n{} %default label\n{} %formatting parameter")
143 (defun YaTeX:minipage ()
144 (concat (YaTeX:read-position "cbt")
145 "{" (read-string "Width: ") "}"))
147 (defun YaTeX:thebibliography ()
148 (setq YaTeX-section-name "bibitem")
149 (concat "{" (read-string "Longest label: ") "}"))
151 ;;;
152 ;;Sample functions for section-type command.
153 ;;;
154 (defun YaTeX:multiput ()
155 (concat (YaTeX:read-coordinates "Pos")
156 (YaTeX:read-coordinates "Step")
157 "{" (read-string "How many times: ") "}"))
159 (defun YaTeX:put ()
160 (YaTeX:read-coordinates "Pos"))
162 (defun YaTeX:makebox ()
163 (cond
164 ((YaTeX-in-environment-p "picture")
165 (concat (YaTeX:read-coordinates "Dimension")
166 (YaTeX:read-position "lrtb")))
167 (t
168 (let ((width (read-string "Width: ")))
169 (if (string< "" width)
170 (progn
171 (or (equal (aref width 0) ?\[)
172 (setq width (concat "[" width "]")))
173 (concat width (YaTeX:read-position "lr"))))))))
175 (defun YaTeX:framebox ()
176 (if (YaTeX-quick-in-environment-p "picture")
177 (YaTeX:makebox)))
179 (defun YaTeX:dashbox ()
180 (concat "{" (read-string "Dash dimension: ") "}"
181 (YaTeX:read-coordinates "Dimension")))
183 (defvar YaTeX-minibuffer-quick-map nil)
184 (if YaTeX-minibuffer-quick-map nil
185 (setq YaTeX-minibuffer-quick-map
186 (copy-keymap minibuffer-local-completion-map))
187 (let ((ch (1+ ? )))
188 (while (< ch 127)
189 (define-key YaTeX-minibuffer-quick-map (char-to-string ch)
190 'YaTeX-minibuffer-quick-complete)
191 (setq ch (1+ ch)))))
193 (defvar YaTeX:left-right-delimiters
194 '(("(" . ")") (")" . "(") ("[" . "]") ("]" . "[")
195 ("\\{" . "\\}") ("\\}" . "\\{") ("|") ("\\|")
196 ("\\lfloor" . "\\rfloor") ("\\lceil" . "\\rceil")
197 ("\\langle" . "\\rangle") ("/") (".")
198 ("\\rfloor" . "\\rfloor") ("\\rceil" . "\\lceil")
199 ("\\rangle" . "\\langle") ("\\backslash")
200 ("\\uparrow") ("\\downarrow") ("\\updownarrow") ("\\Updownarrow"))
201 "TeX math delimiter, which can be completed after \\right or \\left.")
203 (defvar YaTeX:left-right-default nil "Default string of YaTeX:right.")
205 (defun YaTeX:left ()
206 (let ((minibuffer-completion-table YaTeX:left-right-delimiters)
207 delimiter (leftp (string= YaTeX-single-command "left")))
208 (setq delimiter
209 (read-from-minibuffer
210 (format "Delimiter%s: "
211 (if YaTeX:left-right-default
212 (format "(default=`%s')" YaTeX:left-right-default)
213 "(SPC for menu)"))
214 nil YaTeX-minibuffer-quick-map))
215 (if (string= "" delimiter) (setq delimiter YaTeX:left-right-default))
216 (setq YaTeX-single-command (if leftp "right" "left")
217 YaTeX:left-right-default
218 (or (cdr (assoc delimiter YaTeX:left-right-delimiters)) delimiter))
219 delimiter))
221 (fset 'YaTeX:right 'YaTeX:left)
223 (defun YaTeX:read-coordinates (&optional mes varX varY)
224 (concat
225 "("
226 (read-string (format "%s %s: " (or mes "Dimension") (or varX "X")))
227 ","
228 (read-string (format "%s %s: " (or mes "Dimension") (or varY "Y")))
229 ")"))
231 (defun YaTeX:itembox ()
232 (concat "{" (read-string "Item heading string: ") "}"))
234 ;;;
235 ;;Sample functions for maketitle-type command.
236 ;;;
237 (defun YaTeX:sum ()
238 "Read range of summation."
239 (YaTeX:check-completion-type 'maketitle)
240 (concat (YaTeX:read-boundary "_") (YaTeX:read-boundary "^")))
242 (fset 'YaTeX:int 'YaTeX:sum)
244 (defun YaTeX:lim ()
245 "Insert limit notation of \\lim."
246 (YaTeX:check-completion-type 'maketitle)
247 (let ((var (read-string "Variable: ")) limit)
248 (if (string= "" var) ""
249 (setq limit (read-string "Limit ($ means infinity): "))
250 (if (string= "$" limit) (setq limit "\\infty"))
251 (concat "_{" var " \\rightarrow " limit "}"))))
253 (defun YaTeX:gcd ()
254 "Add-in function for \\gcd(m,n)."
255 (YaTeX:check-completion-type 'maketitle)
256 (YaTeX:read-coordinates "\\gcd" "(?,)" "(,?)"))
258 (defun YaTeX:read-boundary (ULchar)
259 "Read boundary usage by _ or ^. _ or ^ is indicated by argument ULchar."
260 (let ((bndry (read-string (concat ULchar "{???} ($ for infinity): "))))
261 (if (string= bndry "") ""
262 (if (string= bndry "$") (setq bndry "\\infty"))
263 (concat ULchar "{" bndry "}"))))
265 (defun YaTeX:verb ()
266 "Enclose \\verb's contents with the same characters."
267 (let ((quote-char (read-string "Quoting char: " "|"))
268 (contents (read-string "Quoted contents: ")))
269 (concat quote-char contents quote-char)))
271 (fset 'YaTeX:verb* 'YaTeX:verb)
273 (defun YaTeX:footnotemark ()
274 (setq YaTeX-section-name "footnotetext")
275 nil)
277 (defun YaTeX:cite ()
278 (let ((comment (read-string "Comment for citation: ")))
279 (if (string= comment "") ""
280 (concat "[" comment "]"))))
282 (defun YaTeX:bibitem ()
283 (let ((label (read-string "Citation label for bibitem: ")))
284 (if (string= label "") ""
285 (concat "[" label "]"))))
287 (defun YaTeX:item ()
288 (cond
289 ((eq major-mode 'yatex-mode)
290 (YaTeX-indent-line)
291 (setq YaTeX-section-name "label"))
292 ((eq major-mode 'texinfo-mode)
293 (setq YaTeX-section-name "dots"))) ;??
294 " ")
295 (fset 'YaTeX:item\[\] 'YaTeX:item)
296 (fset 'YaTeX:subitem 'YaTeX:item)
297 (fset 'YaTeX:subsubitem 'YaTeX:item)
299 (defun YaTeX:linebreak ()
300 (let (obl)
301 (message "Break strength 0,1,2,3,4 (default: 4): ")
302 (setq obl (char-to-string (read-char)))
303 (if (string-match "[0-4]" obl)
304 (concat "[" obl "]")
305 "")))
306 (fset 'YaTeX:pagebreak 'YaTeX:linebreak)
308 ;;;
309 ;;Subroutine
310 ;;;
312 (defun YaTeX:check-completion-type (type)
313 "Check valid completion type."
314 (if (not (eq type YaTeX-current-completion-type))
315 (error "This should be completed with %s-type completion." type)))
318 ;;;
319 ;;; [[Add-in functions for reading section arguments]]
320 ;;;
321 ;; All of add-in functions for reading sections arguments should
322 ;; take an argument ARGP that specify the argument position.
323 ;; If argument position is out of range, nil should be returned,
324 ;; else nil should NOT be returned.
326 ;;
327 ; Label selection
328 ;;
329 (defvar YaTeX-label-menu-other
330 (if YaTeX-japan "':‘Ό‚Μƒoƒbƒtƒ@‚Μƒ‰ƒxƒ‹\n" "':LABEL IN OTHER BUFFER.\n"))
331 (defvar YaTeX-label-menu-repeat
332 (if YaTeX-japan ".:’Ό‘O‚Μ\\ref‚Ζ“―‚Ά\n" "/:REPEAT LAST \ref{}\n"))
333 (defvar YaTeX-label-menu-any
334 (if YaTeX-japan "*:”CˆΣ‚Μ•ΆŽš—ρ\n" "*:ANY STRING.\n"))
335 (defvar YaTeX-label-buffer "*Label completions*")
336 (defvar YaTeX-label-guide-msg "Select label and hit RETURN.")
337 (defvar YaTeX-label-select-map nil
338 "Key map used in label selection buffer.")
339 (defun YaTeX::label-setup-key-map ()
340 (if YaTeX-label-select-map nil
341 (message "Setting up label selection mode map...")
342 ;(setq YaTeX-label-select-map (copy-keymap global-map))
343 (setq YaTeX-label-select-map (make-keymap))
344 (suppress-keymap YaTeX-label-select-map)
345 (substitute-all-key-definition
346 'previous-line 'YaTeX::label-previous YaTeX-label-select-map)
347 (substitute-all-key-definition
348 'next-line 'YaTeX::label-next YaTeX-label-select-map)
349 (define-key YaTeX-label-select-map "\C-n" 'YaTeX::label-next)
350 (define-key YaTeX-label-select-map "\C-p" 'YaTeX::label-previous)
351 (define-key YaTeX-label-select-map "<" 'beginning-of-buffer)
352 (define-key YaTeX-label-select-map ">" 'end-of-buffer)
353 (define-key YaTeX-label-select-map "\C-m" 'exit-recursive-edit)
354 (define-key YaTeX-label-select-map "\C-j" 'exit-recursive-edit)
355 (define-key YaTeX-label-select-map " " 'exit-recursive-edit)
356 (define-key YaTeX-label-select-map "\C-g" 'abort-recursive-edit)
357 (define-key YaTeX-label-select-map "/" 'isearch-forward)
358 (define-key YaTeX-label-select-map "?" 'isearch-backward)
359 (define-key YaTeX-label-select-map "'" 'YaTeX::label-search-tag)
360 (define-key YaTeX-label-select-map "." 'YaTeX::label-search-tag)
361 (define-key YaTeX-label-select-map "*" 'YaTeX::label-search-tag)
362 (message "Setting up label selection mode map...Done")
363 (let ((key ?A))
364 (while (<= key ?Z)
365 (define-key YaTeX-label-select-map (char-to-string key)
366 'YaTeX::label-search-tag)
367 (define-key YaTeX-label-select-map (char-to-string (+ key (- ?a ?A)))
368 'YaTeX::label-search-tag)
369 (setq key (1+ key))))))
371 (defun YaTeX::label-next ()
372 (interactive) (forward-line 1) (message YaTeX-label-guide-msg))
373 (defun YaTeX::label-previous ()
374 (interactive) (forward-line -1) (message YaTeX-label-guide-msg))
375 (defun YaTeX::label-search-tag ()
376 (interactive)
377 (let ((case-fold-search t)
378 (tag (regexp-quote (char-to-string last-command-char))))
379 (cond
380 ((save-excursion
381 (forward-char 1)
382 (re-search-forward (concat "^" tag) nil t))
383 (goto-char (match-beginning 0)))
384 ((save-excursion
385 (goto-char (point-min))
386 (re-search-forward (concat "^" tag) nil t))
387 (goto-char (match-beginning 0))))
388 (message YaTeX-label-guide-msg)))
390 ; (defun YaTeX::ref (argp &optional labelcmd refcmd)
391 ; (cond
392 ; ((= argp 1)
393 ; (let ((lnum 0) e0 label label-list (buf (current-buffer))
394 ; (labelcmd (or labelcmd "label")) (refcmd (or refcmd "ref"))
395 ; (p (point)) initl line cf)
396 ; (message "Collecting labels...")
397 ; (save-window-excursion
398 ; (YaTeX-showup-buffer
399 ; YaTeX-label-buffer (function (lambda (x) (window-width x))))
400 ; (if (fboundp 'select-frame) (setq cf (selected-frame)))
401 ; (if (eq (window-buffer (minibuffer-window)) buf)
402 ; (progn
403 ; (other-window 1)
404 ; (setq buf (current-buffer))
405 ; (set-buffer buf)
406 ; ;(message "cb=%s" buf)(sit-for 3)
407 ; ))
408 ; (save-excursion
409 ; (set-buffer (get-buffer-create YaTeX-label-buffer))
410 ; (setq buffer-read-only nil)
411 ; (erase-buffer))
412 ; (save-excursion
413 ; (goto-char (point-min))
414 ; (let ((standard-output (get-buffer YaTeX-label-buffer)))
415 ; (princ (format "=== LABELS in [%s] ===\n" (buffer-name buf)))
416 ; (while (YaTeX-re-search-active-forward
417 ; (concat "\\\\" labelcmd "\\b")
418 ; (regexp-quote YaTeX-comment-prefix) nil t)
419 ; (goto-char (match-beginning 0))
420 ; (skip-chars-forward "^{")
421 ; (setq label
422 ; (buffer-substring
423 ; (1+ (point))
424 ; (prog2 (forward-list 1) (setq e0 (1- (point)))))
425 ; label-list (cons label label-list))
426 ; (or initl
427 ; (if (< p (point)) (setq initl lnum)))
428 ; (beginning-of-line)
429 ; (skip-chars-forward " \t\n" nil)
430 ; (princ (format "%c:{%s}\t<<%s>>\n" (+ (% lnum 26) ?A) label
431 ; (buffer-substring (point) (point-end-of-line))))
432 ; (setq lnum (1+ lnum))
433 ; (message "Collecting \\%s{}... %d" labelcmd lnum)
434 ; (goto-char e0))
435 ; (princ YaTeX-label-menu-other)
436 ; (princ YaTeX-label-menu-repeat)
437 ; (princ YaTeX-label-menu-any)
438 ; );standard-output
439 ; (goto-char p)
440 ; (or initl (setq initl lnum))
441 ; (message "Collecting %s...Done" labelcmd)
442 ; (if (fboundp 'select-frame) (select-frame cf))
443 ; (YaTeX-showup-buffer YaTeX-label-buffer nil t)
444 ; (YaTeX::label-setup-key-map)
445 ; (setq truncate-lines t)
446 ; (setq buffer-read-only t)
447 ; (use-local-map YaTeX-label-select-map)
448 ; (message YaTeX-label-guide-msg)
449 ; (goto-line (1+ initl)) ;goto recently defined label line
450 ; (switch-to-buffer (current-buffer))
451 ; (unwind-protect
452 ; (progn
453 ; (recursive-edit)
454 ; (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
455 ; (beginning-of-line)
456 ; (setq line (1- (count-lines (point-min)(point))))
457 ; (cond
458 ; ((= line -1) (setq label ""))
459 ; ((= line lnum) (setq label (YaTeX-label-other)))
460 ; ((= line (1+ lnum))
461 ; (save-excursion
462 ; (switch-to-buffer buf)
463 ; (goto-char p)
464 ; (if (re-search-backward
465 ; (concat "\\\\" refcmd "{\\([^}]+\\)}") nil t)
466 ; (setq label (YaTeX-match-string 1))
467 ; (setq label ""))))
468 ; ((>= line (+ lnum 2))
469 ; (setq label (read-string (format "\\%s{???}: " refcmd))))
470 ; (t (setq label (nth (- lnum line 1) label-list)))))
471 ; (bury-buffer YaTeX-label-buffer)))
472 ; label)))))
474 (defun YaTeX::ref-generate-label ()
475 "Generate a label string which is unique in current buffer."
476 (let ((default (substring (current-time-string) 4)))
477 (read-string "Give a label for this line: "
478 (if YaTeX-emacs-19 (cons default 1) default))))
480 (defun YaTeX::ref-getset-label (buffer point)
481 "Get label string in the BUFFER near the POINT.
482 Make \\label{xx} if no label."
483 ;;Here, we rewrite the LaTeX source. Therefore we should be careful
484 ;;to decide the location suitable for \label. Do straightforward!
485 (let (boundary inspoint cc newlabel (labelholder "label") mathp env
486 (r-escape (regexp-quote YaTeX-comment-prefix)))
487 ;;(set-buffer buffer)
488 (switch-to-buffer buffer)
489 (save-excursion
490 (goto-char point)
491 (setq cc (current-column))
492 (if (= (char-after (point)) ?\\) (forward-char 1))
493 (cond
494 ((looking-at YaTeX-sectioning-regexp)
495 (skip-chars-forward "^{")
496 (forward-list 1)
497 (skip-chars-forward " \t\n")
498 ;(setq boundary "[^\\]")
499 (setq inspoint (point))
500 (setq boundary
501 (save-excursion
502 (if (YaTeX-re-search-active-forward
503 (concat YaTeX-ec-regexp
504 "\\(" YaTeX-sectioning-regexp "\\|"
505 "begin\\|item\\)")
506 r-escape nil 1)
507 (match-beginning 0)
508 (1- (point))))))
509 ((looking-at "item\\s ")
510 (setq cc (+ cc 6))
511 ;(setq boundary (concat YaTeX-ec-regexp "\\(item\\|begin\\|end\\)\\b"))
512 (setq boundary
513 (save-excursion
514 (if (YaTeX-re-search-active-forward
515 (concat YaTeX-ec-regexp "\\(item\\|begin\\|end\\)\\b")
516 r-escape nil 1)
517 (match-beginning 0)
518 (1- (point))))
519 inspoint boundary))
520 ((looking-at "bibitem")
521 (setq labelholder "bibitem") ; label holder is bibitem itself
522 (setq boundary
523 (save-excursion
524 (if (YaTeX-re-search-active-forward
525 (concat YaTeX-ec-regexp "\\(bibitem\\|end\\)\\b")
526 r-escape nil 1)
527 (match-beginning 0)
528 (1- (point))))
529 inspoint boundary))
530 ((string-match YaTeX::ref-mathenv-regexp
531 (setq env (or (YaTeX-inner-environment t) "document")))
532 (setq mathp t)
533 ;;(setq boundary (concat YaTeX-ec-regexp "\\(\\\\\\|end{" env "}\\)"))
534 (setq boundary
535 (save-excursion
536 (if (YaTeX-re-search-active-forward
537 (concat YaTeX-ec-regexp "\\(\\\\\\|end{" env "}\\)")
538 r-escape nil 1)
539 (match-beginning 0)
540 (1- (point))))
541 inspoint boundary))
542 ((looking-at "footnote\\s *{")
543 (skip-chars-forward "^{") ;move onto `{'
544 (setq boundary
545 (save-excursion
546 (condition-case err
547 (forward-list 1)
548 (error (error "\\\\footnote at point %s's brace not closed"
549 (point))))
550 (1- (point)))
551 inspoint boundary))
552 ((looking-at "caption\\|\\(begin\\)")
553 (skip-chars-forward "^{")
554 ;;;;;;(if (match-beginning 1) (forward-list 1))
555 ;; caption can be treated as mathenv, is it right??
556 (forward-list 1)
557 ;;(setq boundary (concat YaTeX-ec-regexp "\\(begin\\|end\\)\\b"))
558 (setq inspoint (point))
559 (setq boundary
560 (save-excursion
561 (if (YaTeX-re-search-active-forward
562 (concat YaTeX-ec-regexp "\\(begin\\|end\\)\\b")
563 r-escape nil 1)
564 (match-beginning 0)
565 (1- (point))))))
566 (t ))
567 (if (save-excursion (skip-chars-forward " \t") (looking-at "%"))
568 (forward-line 1))
569 (if (and (save-excursion
570 (YaTeX-re-search-active-forward
571 ;;(concat "\\(" labelholder "\\)\\|\\(" boundary "\\)")
572 labelholder
573 (regexp-quote YaTeX-comment-prefix)
574 boundary 1))
575 (match-beginning 0))
576 ;; if \label{hoge} found, return it
577 (buffer-substring
578 (progn
579 (goto-char (match-end 0))
580 (skip-chars-forward "^{") (1+ (point)))
581 (progn
582 (forward-sexp 1) (1- (point))))
583 ;;else make a label
584 ;(goto-char (match-beginning 0))
585 (goto-char inspoint)
586 (skip-chars-backward " \t\n")
587 (save-excursion (setq newlabel (YaTeX::ref-generate-label)))
588 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
589 (if mathp nil
590 (insert "\n")
591 (YaTeX-reindent cc))
592 (insert (format "\\label{%s}" newlabel))
593 newlabel))))
595 (defvar YaTeX::ref-labeling-regexp-alist
596 '(("\\\\begin{java}{\\([^}]+\\)}" . 1)
597 ("\\\\label{\\([^}]+\\)}" . 1)))
598 (defvar YaTeX::ref-labeling-regexp
599 (mapconcat 'car YaTeX::ref-labeling-regexp-alist "\\|"))
600 (defvar YaTeX::ref-mathenv-regexp
601 "equation\\|eqnarray\\|align\\|gather\\|alignat\\|xalignat")
602 (defvar YaTeX::ref-enumerateenv-regexp
603 "enumerate")
605 (defvar YaTeX::ref-labeling-section-level 2
606 "*ref•βŠ‚ΕŽϋW‚·‚ιƒZƒNƒVƒ‡ƒjƒ“ƒOƒRƒ}ƒ“ƒh‚Μ‰ΊŒΐƒŒƒxƒ‹
607 YaTeX-sectioning-level‚̐”’l‚ΕŽw’θ.")
609 (defun YaTeX::ref (argp &optional labelcmd refcmd)
610 (setplist 'YaTeX::ref-labeling-regexp nil) ;erase memory cache
611 (require 'yatexsec)
612 (cond
613 ((= argp 1)
614 (let*((lnum 0) e0 x cmd label match-point point-list boundary
615 (buf (current-buffer))
616 (llv YaTeX::ref-labeling-section-level)
617 (mathenvs YaTeX::ref-mathenv-regexp)
618 (enums YaTeX::ref-enumerateenv-regexp)
619 (counter
620 (or labelcmd
621 (concat
622 YaTeX-ec-regexp "\\(\\("
623 (mapconcat
624 'concat
625 (delq nil
626 (mapcar
627 (function
628 (lambda (s)
629 (if (>= llv (cdr s))
630 (car s))))
631 YaTeX-sectioning-level))
632 "\\|")
633 "\\|caption\\(\\[[^]]+\\]\\)?\\|footnote\\){"
634 "\\|\\(begin{\\(" mathenvs "\\|" enums "\\)\\)\\)")))
635 (regexp (concat "\\(" counter
636 "\\)\\|\\(" YaTeX::ref-labeling-regexp "\\)"))
637 (itemsep (concat YaTeX-ec-regexp
638 "\\(\\(bib\\)?item\\|begin\\|end\\)"))
639 (refcmd (or refcmd "ref"))
640 (p (point)) initl line cf
641 (percent (regexp-quote YaTeX-comment-prefix))
642 (output
643 (function
644 (lambda (label p)
645 (while (setq x (string-match "\n" label))
646 (aset label x ? ))
647 (while (setq x (string-match "[ \t\n][ \t\n]+" label))
648 (setq label (concat
649 (substring label 0 (1+ (match-beginning 0)))
650 (substring label (match-end 0)))))
651 (princ (format "%c: <<%s>>\n" (+ (% lnum 26) ?A) label))
652 (setq point-list (cons p point-list))
653 (message "Collecting labels... %d" lnum)
654 (setq lnum (1+ lnum)))))
655 )
656 (message "Collecting labels...")
657 (save-window-excursion
658 (YaTeX-showup-buffer
659 YaTeX-label-buffer (function (lambda (x) (window-width x))))
660 (if (fboundp 'select-frame) (setq cf (selected-frame)))
661 (if (eq (window-buffer (minibuffer-window)) buf)
662 (progn
663 (other-window 1)
664 (setq buf (current-buffer))
665 (set-buffer buf)))
666 (save-excursion
667 (set-buffer (get-buffer-create YaTeX-label-buffer))
668 (setq buffer-read-only nil)
669 (erase-buffer))
670 (save-excursion
671 (set-buffer buf)
672 (goto-char (point-min))
673 (let ((standard-output (get-buffer YaTeX-label-buffer)))
674 (princ (format "=== LABELS in [%s] ===\n" (buffer-name buf)))
675 (while (YaTeX-re-search-active-forward
676 regexp ;;counter
677 percent nil t)
678 ;(goto-char (match-beginning 0))
679 (setq e0 (match-end 0))
680 (cond
681 ((YaTeX-literal-p) nil)
682 ((YaTeX-match-string 1)
683 ;;if standard counter commands found
684 (setq cmd (YaTeX-match-string 2))
685 (setq match-point (match-beginning 0))
686 (or initl
687 (if (< p (point)) (setq initl lnum)))
688 (cond
689 ((string-match mathenvs cmd) ;;if matches mathematical env
690 ;(skip-chars-forward "} \t\n")
691 (forward-line 1)
692 (setq x (point))
693 (catch 'scan
694 (while (YaTeX-re-search-active-forward
695 (concat "\\\\\\\\$\\|\\\\end{\\(" mathenvs "\\)")
696 percent nil t)
697 (let ((quit (match-beginning 1)))
698 (funcall output
699 (buffer-substring x (match-beginning 0))
700 x)
701 (if quit (throw 'scan t)))
702 (setq x (point))))
703 (setq e0 (point)))
704 ((string-match enums cmd)
705 ;(skip-chars-forward "} \t\n")
706 (save-restriction
707 (narrow-to-region
708 (point)
709 (save-excursion
710 (YaTeX-goto-corresponding-environment) (point)))
711 (forward-line 1)
712 (while (YaTeX-re-search-active-forward
713 (concat YaTeX-ec-regexp "item\\s ")
714 percent nil t)
715 (setq x (match-beginning 0))
716 (funcall
717 output
718 (buffer-substring
719 (match-beginning 0)
720 (if (re-search-forward itemsep nil t)
721 (progn (goto-char (match-beginning 0))
722 (skip-chars-backward " \t")
723 (1- (point)))
724 (point-end-of-line)))
725 x))
726 (setq e0 (point-max))))
727 ;;else, simple section-type counter
728 ((= (char-after (1- (point))) ?{)
729 (setq label (buffer-substring
730 (match-beginning 0)
731 (progn (forward-char -1)
732 (forward-list 1)
733 (point))))
734 (funcall output label match-point)
735 ;; Skip preceding label if exists
736 (if (save-excursion
737 (skip-chars-forward "\t \n")
738 (looking-at YaTeX::ref-labeling-regexp))
739 (setq e0 (match-end 0))))
740 (t
741 (skip-chars-forward " \t")
742 (setq label (buffer-substring
743 (match-beginning 0)
744 (if (re-search-forward
745 itemsep
746 nil t)
747 (progn
748 (goto-char (match-beginning 0))
749 (skip-chars-backward " \t")
750 (1- (point)))
751 (point-end-of-line))))
752 (funcall output label match-point)
753 (if (save-excursion
754 (skip-chars-forward "\t \n")
755 (looking-at YaTeX::ref-labeling-regexp))
756 (setq e0 (match-end 0)))))
757 ) ;;put label buffer
758 ;;
759 ;; if user defined label found
760 (t
761 ;; memorize line number and label into property
762 (goto-char (match-beginning 0))
763 (let ((list YaTeX::ref-labeling-regexp-alist)
764 (cache (symbol-plist 'YaTeX::ref-labeling-regexp)))
765 (while list
766 (if (looking-at (car (car list)))
767 (progn
768 (setq label (YaTeX-match-string 0))
769 (put 'YaTeX::ref-labeling-regexp lnum
770 (YaTeX-match-string (cdr (car list))))
771 (funcall output label 0) ;;0 is dummy, never used
772 (setq list nil)))
773 (setq list (cdr list))))
774 ))
775 (goto-char e0))
776 (princ YaTeX-label-menu-other)
777 (princ YaTeX-label-menu-repeat)
778 (princ YaTeX-label-menu-any)
779 );standard-output
780 (goto-char p)
781 (or initl (setq initl lnum))
782 (message "Collecting labels...Done")
783 (if (fboundp 'select-frame) (select-frame cf))
784 (YaTeX-showup-buffer YaTeX-label-buffer nil t)
785 (YaTeX::label-setup-key-map)
786 (setq truncate-lines t)
787 (setq buffer-read-only t)
788 (use-local-map YaTeX-label-select-map)
789 (message YaTeX-label-guide-msg)
790 (goto-line (1+ initl)) ;goto recently defined label line
791 (switch-to-buffer (current-buffer))
792 (unwind-protect
793 (progn
794 (recursive-edit)
796 (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
797 (beginning-of-line)
798 (setq line (1- (count-lines (point-min)(point))))
799 (cond
800 ((= line -1) (setq label ""))
801 ((= line lnum) (setq label (YaTeX-label-other)))
802 ((= line (1+ lnum))
803 (save-excursion
804 (switch-to-buffer buf)
805 (goto-char p)
806 (if (re-search-backward
807 (concat "\\\\" refcmd "{\\([^}]+\\)}") nil t)
808 (setq label (YaTeX-match-string 1))
809 (setq label ""))))
810 ((>= line (+ lnum 2))
811 (setq label (read-string (format "\\%s{???}: " refcmd))))
812 (t ;(setq label (nth (- lnum line 1) label-list))
813 (setq label
814 (or (get 'YaTeX::ref-labeling-regexp line)
815 (YaTeX::ref-getset-label
816 buf (nth (- lnum line 1) point-list))))
817 )))
818 (bury-buffer YaTeX-label-buffer)))
819 label)))))
821 (fset 'YaTeX::pageref 'YaTeX::ref)
823 (defun YaTeX::cite-collect-bibs-external (&rest files)
824 "Collect bibentry from FILES(variable length argument);
825 and print them to standard output."
826 ;;Thanks; http://icarus.ilcs.hokudai.ac.jp/comp/biblio.html
827 (let ((tb (get-buffer-create " *bibtmp*")))
828 (save-excursion
829 (set-buffer tb)
830 (while files
831 (erase-buffer)
832 (cond
833 ((file-exists-p (car files))
834 (insert-file-contents (car files)))
835 ((file-exists-p (concat (car files) ".bib"))
836 (insert-file-contents (concat (car files) ".bib"))))
837 (save-excursion
838 (goto-char (point-min))
839 (while (re-search-forward "^\\s *@[A-Za-z]" nil t)
840 (skip-chars-forward "^{,")
841 (if (= (char-after (point)) ?{)
842 (princ (format "%sbibitem{%s}%s\n"
843 YaTeX-ec
844 (buffer-substring
845 (1+ (point))
846 (progn (skip-chars-forward "^,\n")
847 (point)))
848 (if (re-search-forward "title\\s *=" nil t)
849 (buffer-substring
850 (progn
851 (goto-char (match-end 0))
852 (skip-chars-forward " \t\n")
853 (point))
854 (progn
855 (if (looking-at "[{\"]")
856 (forward-sexp 1)
857 (forward-char 1)
858 (skip-chars-forward "^,"))
859 (point)))))))))
860 (setq files (cdr files))))))
862 (defvar YaTeX::cite-bibitem-macro-regexp "bibitem\\|harvarditem"
863 "*Regexp of macro name of bibitem definition")
865 (defun YaTeX::cite-collect-bibs-internal ()
866 "Collect bibentry in the current buffer and print them to standard output."
867 (let ((ptn (concat YaTeX-ec-regexp
868 "\\(" YaTeX::cite-bibitem-macro-regexp "\\)\\b"))
869 (pcnt (regexp-quote YaTeX-comment-prefix)))
870 (save-excursion
871 (while (YaTeX-re-search-active-forward ptn pcnt nil t)
872 (skip-chars-forward "^{\n")
873 (or (eolp)
874 (princ (format "%sbibitem{%s}\n"
875 YaTeX-ec
876 (buffer-substring
877 (1+ (point))
878 (progn (forward-sexp 1) (point))))))))))
880 (defun YaTeX::cite (argp)
881 (cond
882 ((eq argp 1)
883 (let* ((cb (current-buffer))
884 (f (file-name-nondirectory buffer-file-name))
885 (d default-directory)
886 (hilit-auto-highlight nil)
887 (pcnt (regexp-quote YaTeX-comment-prefix))
888 (bibrx (concat YaTeX-ec-regexp "bibliography{\\([^}]+\\)}"))
889 (bbuf (get-buffer-create " *bibitems*"))
890 (standard-output bbuf)
891 bibs files)
892 (set-buffer bbuf)(erase-buffer)(set-buffer cb)
893 (save-excursion
894 (goto-char (point-min))
895 ;;(1)search external bibdata
896 (while (YaTeX-re-search-active-forward bibrx pcnt nil t)
897 (apply 'YaTeX::cite-collect-bibs-external
898 (YaTeX-split-string
899 (YaTeX-match-string 1) ",")))
900 ;;(2)search direct \bibitem usage
901 (YaTeX::cite-collect-bibs-internal)
902 (if (progn
903 (YaTeX-visit-main t)
904 (not (eq (current-buffer) cb)))
905 (save-excursion
906 (goto-char (point-min))
907 ;;(1)search external bibdata
908 (while (YaTeX-re-search-active-forward bibrx pcnt nil t)
909 (apply 'YaTeX::cite-collect-bibs-external
910 (YaTeX-split-string
911 (YaTeX-match-string 1) ",")))
912 ;;(2)search internal
913 (YaTeX::cite-collect-bibs-internal)))
914 ;;Now bbuf holds the list of bibitem
915 (set-buffer bbuf)
916 (YaTeX::ref
917 argp
918 (concat "\\\\\\("
919 YaTeX::cite-bibitem-macro-regexp
920 "\\)\\(\\[.*\\]\\)?")
921 "cite"))))
923 (t nil)))
925 ;;; for AMS-LaTeX
926 (and YaTeX-use-AMS-LaTeX (fset 'YaTeX::eqref 'YaTeX::ref))
927 ;;; for Harvard citation style
928 (fset 'YaTeX::citeasnoun 'YaTeX::cite)
929 (fset 'YaTeX::possessivecite 'YaTeX::cite)
930 (fset 'YaTeX::citeyear 'YaTeX::cite)
931 (fset 'YaTeX::citename 'YaTeX::cite)
933 (defun YaTeX-yatex-buffer-list ()
934 (save-excursion
935 (delq nil (mapcar (function (lambda (buf)
936 (set-buffer buf)
937 (if (eq major-mode 'yatex-mode) buf)))
938 (buffer-list)))))
940 (defun YaTeX-select-other-yatex-buffer ()
941 "Select buffer from all yatex-mode's buffers interactivelly."
942 (interactive)
943 (let ((lbuf "*YaTeX mode buffers*") (blist (YaTeX-yatex-buffer-list))
944 (lnum -1) buf rv
945 (ff "**find-file**"))
946 (YaTeX-showup-buffer
947 lbuf (function (lambda (x) 1))) ;;Select next window surely.
948 (save-excursion
949 (set-buffer (get-buffer lbuf))
950 (setq buffer-read-only nil)
951 (erase-buffer))
952 (let ((standard-output (get-buffer lbuf)))
953 (while blist
954 (princ
955 (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A)
956 (buffer-name (car blist))))
957 (setq blist (cdr blist)))
958 (princ (format "':{%s}" ff)))
959 (YaTeX-showup-buffer lbuf nil t)
960 (YaTeX::label-setup-key-map)
961 (setq buffer-read-only t)
962 (use-local-map YaTeX-label-select-map)
963 (message YaTeX-label-guide-msg)
964 (unwind-protect
965 (progn
966 (recursive-edit)
967 (set-buffer lbuf)
968 (beginning-of-line)
969 (setq rv
970 (if (re-search-forward "{\\([^\\}]+\\)}" (point-end-of-line) t)
971 (buffer-substring (match-beginning 1) (match-end 1)) nil)))
972 (kill-buffer lbuf))
973 (if (string= rv ff)
974 (progn
975 (call-interactively 'find-file)
976 (current-buffer))
977 rv)))
979 (defun YaTeX-label-other ()
980 (let ((rv (YaTeX-select-other-yatex-buffer)))
981 (cond
982 ((null rv) "")
983 (t
984 (set-buffer rv)
985 (YaTeX::ref argp labelcmd refcmd)))))
987 ;;
988 ; completion for the arguments of \newcommand
989 ;;
990 (defun YaTeX::newcommand (&optional argp)
991 (cond
992 ((= argp 1)
993 (let ((command (read-string "Define newcommand: " "\\")))
994 (put 'YaTeX::newcommand 'command (substring command 1))
995 command))
996 ((= argp 2)
997 (let ((argc
998 (string-to-int (read-string "Number of arguments(Default 0): ")))
999 (def (read-string "Definition: "))
1000 (command (get 'YaTeX::newcommand 'command)))
1001 ;;!!! It's illegal to insert string in the add-in function !!!
1002 (if (> argc 0) (insert (format "[%d]" argc)))
1003 (if (and (stringp command)
1004 (string< "" command)
1005 (y-or-n-p "Update dictionary?"))
1006 (cond
1007 ((= argc 0)
1008 (YaTeX-update-table
1009 (list command)
1010 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table))
1011 ((= argc 1)
1012 (YaTeX-update-table
1013 (list command)
1014 'section-table 'user-section-table 'tmp-section-table))
1015 (t (YaTeX-update-table
1016 (list command argc)
1017 'section-table 'user-section-table 'tmp-section-table))))
1018 (message "")
1019 def ;return command name
1020 ))
1021 (t "")))
1023 ;;
1024 ; completion for the arguments of \pagestyle
1025 ;;
1026 (defun YaTeX::pagestyle (&optional argp)
1027 "Read the pagestyle with completion."
1028 (completing-read
1029 "Page style: "
1030 '(("plain") ("empty") ("headings") ("myheadings") ("normal") nil)))
1032 (fset 'YaTeX::thispagestyle 'YaTeX::pagestyle)
1034 ;;
1035 ; completion for the arguments of \pagenumbering
1036 ;;
1037 (defun YaTeX::pagenumbering (&optional argp)
1038 "Read the numbering style."
1039 (completing-read
1040 "Page numbering style: "
1041 '(("arabic") ("Alpha") ("alpha") ("Roman") ("roman"))))
1043 ;;
1044 ; Length
1045 ;;
1046 (defvar YaTeX:style-parameters-default
1047 '(("\\arraycolsep")
1048 ("\\arrayrulewidth")
1049 ("\\baselineskip")
1050 ("\\columnsep")
1051 ("\\columnseprule")
1052 ("\\doublerulesep")
1053 ("\\evensidemargin")
1054 ("\\footheight")
1055 ("\\footskip")
1056 ("\\headheight")
1057 ("\\headsep")
1058 ("\\itemindent")
1059 ("\\itemsep")
1060 ("\\labelsep")
1061 ("\\labelwidth")
1062 ("\\leftmargin")
1063 ("\\linewidth")
1064 ("\\listparindent")
1065 ("\\marginparsep")
1066 ("\\marginparwidth")
1067 ("\\mathindent")
1068 ("\\oddsidemargin")
1069 ("\\parindent")
1070 ("\\parsep")
1071 ("\\parskip")
1072 ("\\partopsep")
1073 ("\\rightmargin")
1074 ("\\tabcolsep")
1075 ("\\textheight")
1076 ("\\textwidth")
1077 ("\\topmargin")
1078 ("\\topsep")
1079 ("\\topskip")
1081 "Alist of LaTeX style parameters.")
1082 (defvar YaTeX:style-parameters-private nil
1083 "*User definable alist of style parameters.")
1084 (defvar YaTeX:style-parameters-local nil
1085 "*User definable alist of local style parameters.")
1087 (defvar YaTeX:length-history nil "Holds history of length.")
1088 (put 'YaTeX:length-history 'no-default t)
1089 (defun YaTeX::setlength (&optional argp)
1090 "YaTeX add-in function for arguments of \\setlength."
1091 (cond
1092 ((equal 1 argp)
1093 ;;(completing-read "Length variable: " YaTeX:style-parameters nil nil "\\")
1094 (YaTeX-cplread-with-learning
1095 "Length variable: "
1096 'YaTeX:style-parameters-default
1097 'YaTeX:style-parameters-private
1098 'YaTeX:style-parameters-local
1099 nil nil "\\")
1101 ((equal 2 argp)
1102 (read-string-with-history "Length: " nil 'YaTeX:length-history))))
1104 (fset 'YaTeX::addtolength 'YaTeX::setlength)
1106 (defun YaTeX::settowidth (&optional argp)
1107 "YaTeX add-in function for arguments of \\settowidth."
1108 (cond
1109 ((equal 1 argp)
1110 (YaTeX-cplread-with-learning
1111 "Length variable: "
1112 'YaTeX:style-parameters-default
1113 'YaTeX:style-parameters-private
1114 'YaTeX:style-parameters-local
1115 nil nil "\\"))
1116 ((equal 2 argp)
1117 (read-string "Text: "))))
1119 (defun YaTeX::newlength (&optional argp)
1120 "YaTeX add-in function for arguments of \\newlength"
1121 (cond
1122 ((equal argp 1)
1123 (let ((length (read-string "Length variable: " "\\")))
1124 (if (string< "" length)
1125 (YaTeX-update-table
1126 (list length)
1127 'YaTeX:style-parameters-default
1128 'YaTeX:style-parameters-private
1129 'YaTeX:style-parameters-local))
1130 length))))
1132 ;; \multicolumn's arguments
1133 (defun YaTeX::multicolumn (&optional argp)
1134 "YaTeX add-in function for arguments of \\multicolumn."
1135 (cond
1136 ((equal 1 argp)
1137 (read-string "Number of columns: "))
1138 ((equal 2 argp)
1139 (YaTeX:read-oneof "|lrc" nil t))
1140 ((equal 3 argp)
1141 (read-string "Item: "))))
1143 (defvar YaTeX:documentstyles-default
1144 '(("article") ("jarticle") ("j-article")
1145 ("book") ("jbook") ("j-book")
1146 ("report") ("jreport") ("j-report")
1147 ("letter") ("ascjletter"))
1148 "List of LaTeX documentstyles.")
1149 (defvar YaTeX:documentstyles-private nil
1150 "*User defined list of LaTeX documentstyles.")
1151 (defvar YaTeX:documentstyles-local nil
1152 "*User defined list of local LaTeX documentstyles.")
1153 (defvar YaTeX:documentstyle-options-default
1154 '(("a4j") ("a5j") ("b4j") ("b5j")
1155 ("twocolumn") ("jtwocolumn") ("epsf") ("epsfig") ("epsbox") ("nfig"))
1156 "List of LaTeX documentstyle options.")
1157 (defvar YaTeX:documentstyle-options-private nil
1158 "*User defined list of LaTeX documentstyle options.")
1159 (defvar YaTeX:documentstyle-options-local nil
1160 "List of LaTeX local documentstyle options.")
1162 (defvar YaTeX-minibuffer-completion-map nil
1163 "Minibuffer completion key map that allows comma completion.")
1164 (if YaTeX-minibuffer-completion-map nil
1165 (setq YaTeX-minibuffer-completion-map
1166 (copy-keymap minibuffer-local-completion-map))
1167 (define-key YaTeX-minibuffer-completion-map " "
1168 'YaTeX-minibuffer-complete)
1169 (define-key YaTeX-minibuffer-completion-map "\t"
1170 'YaTeX-minibuffer-complete))
1172 (defun YaTeX:documentstyle ()
1173 (let*((delim ",")
1174 (dt (append YaTeX:documentstyle-options-local
1175 YaTeX:documentstyle-options-private
1176 YaTeX:documentstyle-options-default))
1177 (minibuffer-completion-table dt)
1178 (opt (read-from-minibuffer
1179 "Style options ([opt1,opt2,...]): "
1180 nil YaTeX-minibuffer-completion-map nil))
1181 (substr opt) o)
1182 (if (string< "" opt)
1183 (progn
1184 (while substr
1185 (setq o (substring substr 0 (string-match delim substr)))
1186 (or (assoc o dt)
1187 (YaTeX-update-table
1188 (list o)
1189 'YaTeX:documentstyle-options-default
1190 'YaTeX:documentstyle-options-private
1191 'YaTeX:documentstyle-options-local))
1192 (setq substr
1193 (if (string-match delim substr)
1194 (substring substr (1+ (string-match delim substr))))))
1195 (concat "[" opt "]"))
1196 "")))
1198 (defun YaTeX::documentstyle (&optional argp)
1199 "YaTeX add-in function for arguments of \\documentstyle."
1200 (cond
1201 ((equal argp 1)
1202 (setq YaTeX-env-name "document")
1203 (let ((sname
1204 (YaTeX-cplread-with-learning
1205 (format "Documentstyle (default %s): "
1206 YaTeX-default-document-style)
1207 'YaTeX:documentstyles-default
1208 'YaTeX:documentstyles-private
1209 'YaTeX:documentstyles-local)))
1210 (if (string= "" sname) (setq sname YaTeX-default-document-style))
1211 (setq YaTeX-default-document-style sname)))))
1213 ;;; -------------------- LaTeX2e stuff --------------------
1214 (defvar YaTeX:documentclass-options-default
1215 '(("a4paper") ("a5paper") ("b4paper") ("b5paper") ("10pt") ("11pt") ("12pt")
1216 ("latterpaper") ("legalpaper") ("executivepaper") ("landscape")
1217 ("oneside") ("twoside") ("draft") ("final") ("leqno") ("fleqn") ("openbib")
1218 ("tombow") ("titlepage") ("notitlepage") ("dvips")
1219 ("clock") ;for slides class only
1221 "Default options list for documentclass")
1222 (defvar YaTeX:documentclass-options-private nil
1223 "*User defined options list for documentclass")
1224 (defvar YaTeX:documentclass-options-local nil
1225 "*User defined options list for local documentclass")
1227 (defun YaTeX:documentclass ()
1228 (let*((delim ",")
1229 (dt (append YaTeX:documentclass-options-local
1230 YaTeX:documentclass-options-private
1231 YaTeX:documentclass-options-default))
1232 (minibuffer-completion-table dt)
1233 (opt (read-from-minibuffer
1234 "Documentclass options ([opt1,opt2,...]): "
1235 nil YaTeX-minibuffer-completion-map nil))
1236 (substr opt) o)
1237 (if (string< "" opt)
1238 (progn
1239 (while substr
1241 (setq o (substring substr 0 (string-match delim substr)))
1242 (or (assoc o dt)
1243 (YaTeX-update-table
1244 (list o)
1245 'YaTeX:documentclass-options-default
1246 'YaTeX:documentclass-options-private
1247 'YaTeX:documentclass-options-local))
1248 (setq substr
1249 (if (string-match delim substr)
1250 (substring substr (1+ (string-match delim substr))))))
1251 (concat "[" opt "]"))
1252 "")))
1254 (defvar YaTeX:documentclasses-default
1255 '(("article") ("jarticle") ("report") ("jreport") ("book") ("jbook")
1256 ("j-article") ("j-report") ("j-book")
1257 ("letter") ("slides") ("ltxdoc") ("ltxguide") ("ltnews") ("proc"))
1258 "Default documentclass alist")
1259 (defvar YaTeX:documentclasses-private nil
1260 "*User defined documentclass alist")
1261 (defvar YaTeX:documentclasses-local nil
1262 "*User defined local documentclass alist")
1263 (defvar YaTeX-default-documentclass (if YaTeX-japan "jarticle" "article")
1264 "*Default documentclass")
1266 (defun YaTeX::documentclass (&optional argp)
1267 (cond
1268 ((equal argp 1)
1269 (setq YaTeX-env-name "document")
1270 (let ((sname
1271 (YaTeX-cplread-with-learning
1272 (format "Documentclass (default %s): " YaTeX-default-documentclass)
1273 'YaTeX:documentclasses-default
1274 'YaTeX:documentclasses-private
1275 'YaTeX:documentclasses-local)))
1276 (if (string= "" sname) (setq sname YaTeX-default-documentclass))
1277 (setq YaTeX-default-documentclass sname)))))
1279 (defvar YaTeX:latex2e-named-color-alist
1280 '(("GreenYellow") ("Yellow") ("Goldenrod") ("Dandelion") ("Apricot")
1281 ("Peach") ("Melon") ("YellowOrange") ("Orange") ("BurntOrange")
1282 ("Bittersweet") ("RedOrange") ("Mahogany") ("Maroon") ("BrickRed")
1283 ("Red") ("OrangeRed") ("RubineRed") ("WildStrawberry") ("Salmon")
1284 ("CarnationPink") ("Magenta") ("VioletRed") ("Rhodamine") ("Mulberry")
1285 ("RedViolet") ("Fuchsia") ("Lavender") ("Thistle") ("Orchid")("DarkOrchid")
1286 ("Purple") ("Plum") ("Violet") ("RoyalPurple") ("BlueViolet")
1287 ("Periwinkle") ("CadetBlue") ("CornflowerBlue") ("MidnightBlue")
1288 ("NavyBlue") ("RoyalBlue") ("Blue") ("Cerulean") ("Cyan") ("ProcessBlue")
1289 ("SkyBlue") ("Turquoise") ("TealBlue") ("Aquamarine") ("BlueGreen")
1290 ("Emerald") ("JungleGreen") ("SeaGreen") ("Green") ("ForestGreen")
1291 ("PineGreen") ("LimeGreen") ("YellowGreen") ("SpringGreen") ("OliveGreen")
1292 ("RawSienna") ("Sepia") ("Brown") ("Tan") ("Gray") ("Black") ("White"))
1293 "Colors defined in $TEXMF/tex/plain/colordvi.tex")
1295 (defvar YaTeX:latex2e-basic-color-alist
1296 '(("black") ("white") ("red") ("blue") ("yellow") ("green") ("cyan")
1297 ("magenta"))
1298 "Basic colors")
1300 (defun YaTeX:textcolor ()
1301 "Add-in for \\color's option"
1302 (if (y-or-n-p "Use `named' color? ")
1303 "[named]"))
1305 (defun YaTeX::color-completing-read (prompt)
1306 (let ((completion-ignore-case t)
1307 (namedp (save-excursion
1308 (skip-chars-backward "^\n\\[\\\\")
1309 (looking-at "named"))))
1310 (completing-read
1311 prompt
1312 (if namedp
1313 YaTeX:latex2e-named-color-alist
1314 YaTeX:latex2e-basic-color-alist)
1315 nil t)))
1317 (defun YaTeX::textcolor (argp)
1318 "Add-in for \\color's argument"
1319 (cond
1320 ((= argp 1) (YaTeX::color-completing-read "Color: "))
1321 ((= argp 2) (read-string "Colored string: "))))
1323 (fset 'YaTeX:color 'YaTeX:textcolor)
1324 (fset 'YaTeX::color 'YaTeX::textcolor)
1325 (fset 'YaTeX:colorbox 'YaTeX:textcolor)
1326 (fset 'YaTeX::colorbox 'YaTeX::textcolor)
1327 (fset 'YaTeX:fcolorbox 'YaTeX:textcolor)
1329 (defun YaTeX::fcolorbox (argp)
1330 (cond
1331 ((= argp 1) (YaTeX::color-completing-read "Frame color: "))
1332 ((= argp 2) (YaTeX::color-completing-read "Inner color: "))
1333 ((= argp 3) (read-string "Colored string: "))))
1335 (defun YaTeX:scalebox ()
1336 "Add-in for \\rotatebox"
1337 (let ((vmag (read-string (if YaTeX-japan "”{—¦: " "Magnification: ")))
1338 (hmag (read-string (if YaTeX-japan "‰‘”{—¦(Θ—ͺ‰Β): "
1339 "Horizontal magnification(Optional): "))))
1340 (if (and hmag (string< "" hmag))
1341 (format "{%s}[%s]" vmag hmag)
1342 (format "{%s}" vmag))))
1344 (defun YaTeX:includegraphics ()
1345 "Add-in for \\includegraphics's option"
1346 (let (width height (scale "") angle str)
1347 (setq width (read-string "Width: ")
1348 height (read-string "Height: "))
1349 (or (string< width "") (string< "" height)
1350 (setq scale (read-string "Scale: ")))
1351 (setq angle (read-string "Angle(0-359): "))
1352 (setq str
1353 (mapconcat
1354 'concat
1355 (delq nil
1356 (mapcar '(lambda (s)
1357 (and (stringp (symbol-value s))
1358 (string< "" (symbol-value s))
1359 (format "%s=%s" s (symbol-value s))))
1360 '(width height scale angle)))
1361 ","))
1362 (if (string= "" str) ""
1363 (concat "[" str "]"))))
1365 (defun YaTeX::includegraphics (argp)
1366 "Add-in for \\includegraphics"
1367 (cond
1368 ((= argp 1)
1369 (read-file-name "EPS File: " ""))))
1371 (defun YaTeX:caption ()
1372 (setq YaTeX-section-name "label")
1373 nil)
1375 (defvar YaTeX::usepackage-alist-default
1376 '(("version") ("plext") ("url") ("fancybox") ("pifont") ("longtable")
1377 ("ascmac") ("bm") ("graphics") ("graphicx") ("alltt") ("misc") ("eclbkbox")
1378 ("amsmath") ("amssymb") ("xymtex") ("chemist")
1379 ("a4j") ("array") ("epsf") ("color") ("epsfig") ("floatfig")
1380 ("landscape") ("path") ("supertabular") ("twocolumn"))
1381 "Default completion table for arguments of \usepackage")
1383 (defvar YaTeX::usepackage-alist-private nil
1384 "*Private completion list of the argument for usepackage")
1386 (defvar YaTeX::usepackage-alist-local nil
1387 "Directory local completion list of the argument for usepackage")
1389 (defun YaTeX::usepackage (&optional argp)
1390 (cond
1391 ((equal argp 1)
1392 (setq YaTeX-env-name "document")
1393 (YaTeX-cplread-with-learning
1394 "Use package: "
1395 'YaTeX::usepackage-alist-default
1396 'YaTeX::usepackage-alist-private
1397 'YaTeX::usepackage-alist-local))))
1399 (defun YaTeX::mask (argp)
1400 (cond
1401 ((equal argp 1)
1402 (read-string "String: "))
1403 ((equal argp 2)
1404 (let (c)
1405 (while (not (memq c '(?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K)))
1406 (message "Mask type(A..K): ")
1407 (setq c (upcase (read-char))))
1408 (format "%c" c)))))
1410 (defun YaTeX::maskbox (argp)
1411 (cond
1412 ((equal argp 1)
1413 (read-string "Width: "))
1414 ((equal argp 2)
1415 (read-string "Height: "))
1416 ((equal argp 3)
1417 (let (c)
1418 (while (not (memq c '(?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K)))
1419 (message "Mask type(A..K): ")
1420 (setq c (upcase (read-char))))
1421 (format "%c" c)))
1422 ((equal argp 4)
1423 (YaTeX:read-oneof "lcr" 'quick))
1424 ((equal argp 5)
1425 (read-string "String: "))
1426 ))
1428 ;;; -------------------- math-mode stuff --------------------
1429 (defun YaTeX::tilde (&optional pos)
1430 "For accent macros in mathmode"
1431 (cond
1432 ((equal pos 1)
1433 (message "Put accent on variable: ")
1434 (let ((v (char-to-string (read-char))) (case-fold-search nil))
1435 (message "")
1436 (cond
1437 ((string-match "i\\|j" v)
1438 (concat "\\" v "math"))
1439 ((string-match "[\r\n\t ]" v)
1440 "")
1441 (t v))))
1442 (nil "")))
1444 (fset 'YaTeX::hat 'YaTeX::tilde)
1445 (fset 'YaTeX::check 'YaTeX::tilde)
1446 (fset 'YaTeX::bar 'YaTeX::tilde)
1447 (fset 'YaTeX::dot 'YaTeX::tilde)
1448 (fset 'YaTeX::ddot 'YaTeX::tilde)
1449 (fset 'YaTeX::vec 'YaTeX::tilde)
1451 (defun YaTeX::widetilde (&optional pos)
1452 "For multichar accent macros in mathmode"
1453 (cond
1454 ((equal pos 1)
1455 (let ((m "Put over chars[%s ]: ") v v2)
1456 (message m " ")
1457 (setq v (char-to-string (read-char)))
1458 (message "")
1459 (if (string-match "[\r\n\t ]" v)
1460 ""
1461 (message m v)
1462 (setq v2 (char-to-string (read-char)))
1463 (message "")
1464 (if (string-match "[\r\n\t ]" v2)
1466 (concat v v2)))))
1467 (nil "")))
1469 (fset 'YaTeX::widehat 'YaTeX::widetilde)
1470 (fset 'YaTeX::overline 'YaTeX::widetilde)
1471 (fset 'YaTeX::overrightarrow 'YaTeX::widetilde)
1474 ; for \frac{}{} region
1475 (defun YaTeX::frac-region (beg end)
1476 (if (catch 'done
1477 (while (re-search-forward "\\s *\\(\\\\over\\|/\\)\\s *" end t)
1478 (goto-char (match-beginning 0))
1479 (if (y-or-n-p
1480 (format "Replace this `%s' with `}{'" (YaTeX-match-string 0)))
1481 (throw 'done t))
1482 (goto-char (match-end 0))))
1483 (let (p (b0 (match-beginning 0)) e0)
1484 (replace-match "}{")
1485 (setq e0 (point))
1486 (save-restriction
1487 (narrow-to-region beg end)
1488 (goto-char e0)
1489 (skip-chars-forward " \t")
1490 (setq p (point))
1491 (YaTeX-goto-corresponding-paren)
1492 (forward-char 1)
1493 (skip-chars-forward " \t\r\n")
1494 (if (= end (1+ (point)))
1495 (progn
1496 (goto-char p)
1497 (if (looking-at "\\\\") (forward-char 1))
1498 (YaTeX-kill-paren nil)))
1499 (goto-char beg)
1500 (skip-chars-forward " \t")
1501 (setq p (point))
1502 (YaTeX-goto-corresponding-paren)
1503 (forward-char 1)
1504 (skip-chars-forward " \t\r\n")
1505 (if (>= (point) b0)
1506 (progn
1507 (goto-char p)
1508 (if (looking-at "\\\\") (forward-char 1))
1509 (YaTeX-kill-paren nil))))))
1510 (message ""))
1512 ;;;
1513 ;; Add-in functions for large-type command.
1514 ;;;
1515 (defun YaTeX:em ()
1516 (cond
1517 ((eq YaTeX-current-completion-type 'large) "\\/")
1518 (t nil)))
1519 (fset 'YaTeX:it 'YaTeX:em)
1521 ;;; -------------------- End of yatexadd --------------------
1522 (provide 'yatexadd)
1523 ; Local variables:
1524 ; fill-prefix: ";;; "
1525 ; paragraph-start: "^$\\| \\|;;;$"
1526 ; paragraph-separate: "^$\\| \\|;;;$"
1527 ; buffer-file-coding-system: sjis
1528 ; End: