yatex

view yatexadd.el @ 247:3e3ccba06ca1

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