yatex

view yatexadd.el @ 167:d891d7c6cd8e

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