yatex

view yatexadd.el @ 84:73cba5ddd111

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