yatex

view yatexadd.el @ 72:0aaebd07dad0

Support font-lock on XEmacs-21, Emacs-20, Emacs-21. Support Emacs-21.
author yuuji
date Mon, 25 Dec 2000 10:19:28 +0000
parents 44e3a5e1e883
children f41b01fef5d6
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX add-in functions.
3 ;;; yatexadd.el rev.14
4 ;;; (c )1991-2000 by HIROSE Yuuji.[yuuji@yatex.org]
5 ;;; Last modified Mon Dec 25 19:17:09 2000 on firestorm
6 ;;; $Id$
8 ;;;
9 ;;Sample functions for LaTeX environment.
10 ;;;
11 (defvar YaTeX:tabular-default-rule
12 "@{\\vrule width 1pt\\ }c|c|c@{\\ \\vrule width 1pt}"
13 "*Your favorite default rule format.")
15 (defvar YaTeX:tabular-thick-vrule "\\vrule width %s"
16 "*Vertical thick line format (without @{}). %s'll be replaced by its width.")
18 (defvar YaTeX:tabular-thick-hrule "\\noalign{\\hrule height %s}"
19 "*Horizontal thick line format. %s will be replaced by its width.")
21 (defun YaTeX:tabular ()
22 "YaTeX add-in function for tabular environment.
23 Notice that this function refers the let-variable `env' in
24 YaTeX-make-begin-end."
25 (let ((width "") bars (rule "") (and "") (j 1) loc ans (hline "\\hline"))
26 (if (string= YaTeX-env-name "tabular*")
27 (setq width (concat "{" (read-string "Width: ") "}")))
28 (setq loc (YaTeX:read-position "tb")
29 bars (string-to-int
30 (read-string "Number of columns(0 for default format): " "3")))
31 (if (<= bars 0)
32 (setq ;if 0, simple format
33 rule YaTeX:tabular-default-rule
34 and "& &")
35 (while (< j bars) ;repeat bars-1 times
36 (setq rule (concat rule "c|")
37 and (concat and "& ")
38 j (1+ j)))
39 (setq rule (concat rule "c"))
40 (message "(N)ormal-frame or (T)hick frame? [nt]")
41 (setq ans (read-char))
42 (cond
43 ((or (equal ans ?t) (equal ans ?T))
44 (setq ans (read-string "Rule width: " "1pt")
45 rule (concat
46 "@{" (format YaTeX:tabular-thick-vrule ans) "}"
47 rule
48 "@{\\ " (format YaTeX:tabular-thick-vrule ans) "}")
49 hline (format YaTeX:tabular-thick-hrule ans)))
50 (t (setq rule (concat "|" rule "|")
51 hline "\\hline"))))
53 (setq rule (read-string "rule format: " rule))
54 (setq YaTeX-single-command "hline")
56 (format "%s%s{%s}" width loc rule)))
58 (fset 'YaTeX:tabular* 'YaTeX:tabular)
59 (defun YaTeX:array ()
60 (concat (YaTeX:read-position "tb")
61 "{" (read-string "Column format: ") "}"))
63 (defun YaTeX:read-oneof (oneof)
64 (let ((pos "") loc (guide ""))
65 (and (boundp 'name) name (setq guide (format "%s " name)))
66 (while (not (string-match
67 (setq loc (read-key-sequence
68 (format "%s position (`%s') [%s]: "
69 guide oneof pos));name is in YaTeX-addin
70 loc (if (fboundp 'events-to-keys)
71 (events-to-keys loc) loc))
72 "\r\^g\n"))
73 (cond
74 ((string-match loc oneof)
75 (if (not (string-match loc pos))
76 (setq pos (concat pos loc))))
77 ((and (string-match loc "\C-h\C-?") (> (length pos) 0))
78 (setq pos (substring pos 0 (1- (length pos)))))
79 (t
80 (ding)
81 (message "Please input one of `%s'." oneof)
82 (sit-for 3))))
83 (message "")
84 pos))
86 (defun YaTeX:read-position (oneof)
87 "Read a LaTeX (optional) position format such as `[htbp]'."
88 (let ((pos (YaTeX:read-oneof oneof)))
89 (if (string= pos "") "" (concat "[" pos "]"))))
91 (defun YaTeX:table ()
92 "YaTeX add-in function for table environment."
93 (setq YaTeX-env-name "tabular"
94 YaTeX-section-name "caption")
95 (YaTeX:read-position "htbp"))
97 (fset 'YaTeX:figure 'YaTeX:table)
98 (fset 'YaTeX:figure* 'YaTeX:table)
101 (defun YaTeX:description ()
102 "Truly poor service:-)"
103 (setq YaTeX-single-command "item[]")
104 "")
106 (defun YaTeX:itemize ()
107 "It's also poor service."
108 (setq YaTeX-single-command "item")
109 "")
111 (fset 'YaTeX:enumerate 'YaTeX:itemize)
113 (defun YaTeX:picture ()
114 "Ask the size of coordinates of picture environment."
115 (concat (YaTeX:read-coordinates "Picture size")
116 (YaTeX:read-coordinates "Initial position")))
118 (defun YaTeX:equation ()
119 (YaTeX-jmode-off)
120 (if (fboundp 'YaTeX-toggle-math-mode)
121 (YaTeX-toggle-math-mode t))) ;force math-mode ON.
123 (mapcar '(lambda (f) (fset f 'YaTeX:equation))
124 '(YaTeX:eqnarray YaTeX:eqnarray* YaTeX:align YaTeX:align*
125 YaTeX:split YaTeX:multline YaTeX:multline* YaTeX:gather YaTeX:gather*
126 YaTeX:aligned* YaTeX:gathered YaTeX:gathered*
127 YaTeX:alignat YaTeX:alignat* YaTeX:xalignat YaTeX:xalignat*
128 YaTeX:xxalignat YaTeX:xxalignat*))
130 (defun YaTeX:list ()
131 "%\n{} %default label\n{} %formatting parameter")
133 (defun YaTeX:minipage ()
134 (concat (YaTeX:read-position "cbt")
135 "{" (read-string "Width: ") "}"))
137 (defun YaTeX:thebibliography ()
138 (setq YaTeX-section-name "bibitem")
139 "")
141 ;;;
142 ;;Sample functions for section-type command.
143 ;;;
144 (defun YaTeX:multiput ()
145 (concat (YaTeX:read-coordinates "Pos")
146 (YaTeX:read-coordinates "Step")
147 "{" (read-string "How many times: ") "}"))
149 (defun YaTeX:put ()
150 (YaTeX:read-coordinates "Pos"))
152 (defun YaTeX:makebox ()
153 (cond
154 ((YaTeX-in-environment-p "picture")
155 (concat (YaTeX:read-coordinates "Dimension")
156 (YaTeX:read-position "lrtb")))
157 (t
158 (let ((width (read-string "Width: ")))
159 (if (string< "" width)
160 (progn
161 (or (equal (aref width 0) ?\[)
162 (setq width (concat "[" width "]")))
163 (concat width (YaTeX:read-position "lr"))))))))
165 (defun YaTeX:framebox ()
166 (if (YaTeX-quick-in-environment-p "picture")
167 (YaTeX:makebox)))
169 (defun YaTeX:dashbox ()
170 (concat "{" (read-string "Dash dimension: ") "}"
171 (YaTeX:read-coordinates "Dimension")))
173 (defvar YaTeX-minibuffer-quick-map nil)
174 (if YaTeX-minibuffer-quick-map nil
175 (setq YaTeX-minibuffer-quick-map
176 (copy-keymap minibuffer-local-completion-map))
177 (let ((ch (1+ ? )))
178 (while (< ch 127)
179 (define-key YaTeX-minibuffer-quick-map (char-to-string ch)
180 'YaTeX-minibuffer-quick-complete)
181 (setq ch (1+ ch)))))
183 (defvar YaTeX:left-right-delimiters
184 '(("(" . ")") (")" . "(") ("[" . "]") ("]" . "[")
185 ("\\{" . "\\}") ("\\}" . "\\{") ("|") ("\\|")
186 ("\\lfloor" . "\\rfloor") ("\\lceil" . "\\rceil")
187 ("\\langle" . "\\rangle") ("/") (".")
188 ("\\rfloor" . "\\rfloor") ("\\rceil" . "\\lceil")
189 ("\\rangle" . "\\langle") ("\\backslash")
190 ("\\uparrow") ("\\downarrow") ("\\updownarrow") ("\\Updownarrow"))
191 "TeX math delimiter, which can be completed after \\right or \\left.")
193 (defvar YaTeX:left-right-default nil "Default string of YaTeX:right.")
195 (defun YaTeX:left ()
196 (let ((minibuffer-completion-table YaTeX:left-right-delimiters)
197 delimiter (leftp (string= YaTeX-single-command "left")))
198 (setq delimiter
199 (read-from-minibuffer
200 (format "Delimiter%s: "
201 (if YaTeX:left-right-default
202 (format "(default=`%s')" YaTeX:left-right-default)
203 "(SPC for menu)"))
204 nil YaTeX-minibuffer-quick-map))
205 (if (string= "" delimiter) (setq delimiter YaTeX:left-right-default))
206 (setq YaTeX-single-command (if leftp "right" "left")
207 YaTeX:left-right-default
208 (or (cdr (assoc delimiter YaTeX:left-right-delimiters)) delimiter))
209 delimiter))
211 (fset 'YaTeX:right 'YaTeX:left)
214 (defun YaTeX:read-coordinates (&optional mes varX varY)
215 (concat
216 "("
217 (read-string (format "%s %s: " (or mes "Dimension") (or varX "X")))
218 ","
219 (read-string (format "%s %s: " (or mes "Dimension") (or varY "Y")))
220 ")"))
222 ;;;
223 ;;Sample functions for maketitle-type command.
224 ;;;
225 (defun YaTeX:sum ()
226 "Read range of summation."
227 (YaTeX:check-completion-type 'maketitle)
228 (concat (YaTeX:read-boundary "_") (YaTeX:read-boundary "^")))
230 (fset 'YaTeX:int 'YaTeX:sum)
232 (defun YaTeX:lim ()
233 "Insert limit notation of \\lim."
234 (YaTeX:check-completion-type 'maketitle)
235 (let ((var (read-string "Variable: ")) limit)
236 (if (string= "" var) ""
237 (setq limit (read-string "Limit ($ means infinity): "))
238 (if (string= "$" limit) (setq limit "\\infty"))
239 (concat "_{" var " \\rightarrow " limit "}"))))
241 (defun YaTeX:gcd ()
242 "Add-in function for \\gcd(m,n)."
243 (YaTeX:check-completion-type 'maketitle)
244 (YaTeX:read-coordinates "\\gcd" "(?,)" "(,?)"))
246 (defun YaTeX:read-boundary (ULchar)
247 "Read boundary usage by _ or ^. _ or ^ is indicated by argument ULchar."
248 (let ((bndry (read-string (concat ULchar "{???} ($ for infinity): "))))
249 (if (string= bndry "") ""
250 (if (string= bndry "$") (setq bndry "\\infty"))
251 (concat ULchar "{" bndry "}"))))
253 (defun YaTeX:verb ()
254 "Enclose \\verb's contents with the same characters."
255 (let ((quote-char (read-string "Quoting char: " "|"))
256 (contents (read-string "Quoted contents: ")))
257 (concat quote-char contents quote-char)))
259 (fset 'YaTeX:verb* 'YaTeX:verb)
261 (defun YaTeX:footnotemark ()
262 (setq YaTeX-section-name "footnotetext")
263 nil)
265 (defun YaTeX:cite ()
266 (let ((comment (read-string "Comment for citation: ")))
267 (if (string= comment "") ""
268 (concat "[" comment "]"))))
270 (defun YaTeX:bibitem ()
271 (let ((label (read-string "Citation label for bibitem: ")))
272 (if (string= label "") ""
273 (concat "[" label "]"))))
275 (defun YaTeX:item ()
276 (YaTeX-indent-line)
277 (setq YaTeX-section-name "label")
278 " ")
279 (fset 'YaTeX:item\[\] 'YaTeX:item)
280 (fset 'YaTeX:subitem 'YaTeX:item)
281 (fset 'YaTeX:subsubitem 'YaTeX:item)
283 (defun YaTeX:linebreak ()
284 (let (obl)
285 (message "Break strength 0,1,2,3,4 (default: 4): ")
286 (setq obl (char-to-string (read-char)))
287 (if (string-match "[0-4]" obl)
288 (concat "[" obl "]")
289 "")))
290 (fset 'YaTeX:pagebreak 'YaTeX:linebreak)
292 ;;;
293 ;;Subroutine
294 ;;;
296 (defun YaTeX:check-completion-type (type)
297 "Check valid completion type."
298 (if (not (eq type YaTeX-current-completion-type))
299 (error "This should be completed with %s-type completion." type)))
302 ;;;
303 ;;; [[Add-in functions for reading section arguments]]
304 ;;;
305 ;; All of add-in functions for reading sections arguments should
306 ;; take an argument ARGP that specify the argument position.
307 ;; If argument position is out of range, nil should be returned,
308 ;; else nil should NOT be returned.
310 ;;
311 ; Label selection
312 ;;
313 (defvar YaTeX-label-menu-other
314 (if YaTeX-japan "':他のバッファのラベル\n" "':LABEL IN OTHER BUFFER.\n"))
315 (defvar YaTeX-label-menu-repeat
316 (if YaTeX-japan ".:直前の\\refと同じ\n" "/:REPEAT LAST \ref{}\n"))
317 (defvar YaTeX-label-menu-any
318 (if YaTeX-japan "*:任意の文字列\n" "*:ANY STRING.\n"))
319 (defvar YaTeX-label-buffer "*Label completions*")
320 (defvar YaTeX-label-guide-msg "Select label and hit RETURN.")
321 (defvar YaTeX-label-select-map nil
322 "Key map used in label selection buffer.")
323 (defun YaTeX::label-setup-key-map ()
324 (if YaTeX-label-select-map nil
325 (message "Setting up label selection mode map...")
326 ;(setq YaTeX-label-select-map (copy-keymap global-map))
327 (setq YaTeX-label-select-map (make-keymap))
328 (suppress-keymap YaTeX-label-select-map)
329 (substitute-all-key-definition
330 'previous-line 'YaTeX::label-previous YaTeX-label-select-map)
331 (substitute-all-key-definition
332 'next-line 'YaTeX::label-next YaTeX-label-select-map)
333 (define-key YaTeX-label-select-map "\C-n" 'YaTeX::label-next)
334 (define-key YaTeX-label-select-map "\C-p" 'YaTeX::label-previous)
335 (define-key YaTeX-label-select-map "<" 'beginning-of-buffer)
336 (define-key YaTeX-label-select-map ">" 'end-of-buffer)
337 (define-key YaTeX-label-select-map "\C-m" 'exit-recursive-edit)
338 (define-key YaTeX-label-select-map "\C-j" 'exit-recursive-edit)
339 (define-key YaTeX-label-select-map " " 'exit-recursive-edit)
340 (define-key YaTeX-label-select-map "\C-g" 'abort-recursive-edit)
341 (define-key YaTeX-label-select-map "/" 'isearch-forward)
342 (define-key YaTeX-label-select-map "?" 'isearch-backward)
343 (define-key YaTeX-label-select-map "'" 'YaTeX::label-search-tag)
344 (define-key YaTeX-label-select-map "." 'YaTeX::label-search-tag)
345 (define-key YaTeX-label-select-map "*" 'YaTeX::label-search-tag)
346 (message "Setting up label selection mode map...Done")
347 (let ((key ?A))
348 (while (<= key ?Z)
349 (define-key YaTeX-label-select-map (char-to-string key)
350 'YaTeX::label-search-tag)
351 (define-key YaTeX-label-select-map (char-to-string (+ key (- ?a ?A)))
352 'YaTeX::label-search-tag)
353 (setq key (1+ key))))))
355 (defun YaTeX::label-next ()
356 (interactive) (forward-line 1) (message YaTeX-label-guide-msg))
357 (defun YaTeX::label-previous ()
358 (interactive) (forward-line -1) (message YaTeX-label-guide-msg))
359 (defun YaTeX::label-search-tag ()
360 (interactive)
361 (let ((case-fold-search t)
362 (tag (regexp-quote (char-to-string last-command-char))))
363 (cond
364 ((save-excursion
365 (forward-char 1)
366 (re-search-forward (concat "^" tag) nil t))
367 (goto-char (match-beginning 0)))
368 ((save-excursion
369 (goto-char (point-min))
370 (re-search-forward (concat "^" tag) nil t))
371 (goto-char (match-beginning 0))))
372 (message YaTeX-label-guide-msg)))
374 ; (defun YaTeX::ref (argp &optional labelcmd refcmd)
375 ; (cond
376 ; ((= argp 1)
377 ; (let ((lnum 0) e0 label label-list (buf (current-buffer))
378 ; (labelcmd (or labelcmd "label")) (refcmd (or refcmd "ref"))
379 ; (p (point)) initl line cf)
380 ; (message "Collecting labels...")
381 ; (save-window-excursion
382 ; (YaTeX-showup-buffer
383 ; YaTeX-label-buffer (function (lambda (x) (window-width x))))
384 ; (if (fboundp 'select-frame) (setq cf (selected-frame)))
385 ; (if (eq (window-buffer (minibuffer-window)) buf)
386 ; (progn
387 ; (other-window 1)
388 ; (setq buf (current-buffer))
389 ; (set-buffer buf)
390 ; ;(message "cb=%s" buf)(sit-for 3)
391 ; ))
392 ; (save-excursion
393 ; (set-buffer (get-buffer-create YaTeX-label-buffer))
394 ; (setq buffer-read-only nil)
395 ; (erase-buffer))
396 ; (save-excursion
397 ; (goto-char (point-min))
398 ; (let ((standard-output (get-buffer YaTeX-label-buffer)))
399 ; (princ (format "=== LABELS in [%s] ===\n" (buffer-name buf)))
400 ; (while (YaTeX-re-search-active-forward
401 ; (concat "\\\\" labelcmd "\\b")
402 ; (regexp-quote YaTeX-comment-prefix) nil t)
403 ; (goto-char (match-beginning 0))
404 ; (skip-chars-forward "^{")
405 ; (setq label
406 ; (buffer-substring
407 ; (1+ (point))
408 ; (prog2 (forward-list 1) (setq e0 (1- (point)))))
409 ; label-list (cons label label-list))
410 ; (or initl
411 ; (if (< p (point)) (setq initl lnum)))
412 ; (beginning-of-line)
413 ; (skip-chars-forward " \t\n" nil)
414 ; (princ (format "%c:{%s}\t<<%s>>\n" (+ (% lnum 26) ?A) label
415 ; (buffer-substring (point) (point-end-of-line))))
416 ; (setq lnum (1+ lnum))
417 ; (message "Collecting \\%s{}... %d" labelcmd lnum)
418 ; (goto-char e0))
419 ; (princ YaTeX-label-menu-other)
420 ; (princ YaTeX-label-menu-repeat)
421 ; (princ YaTeX-label-menu-any)
422 ; );standard-output
423 ; (goto-char p)
424 ; (or initl (setq initl lnum))
425 ; (message "Collecting %s...Done" labelcmd)
426 ; (if (fboundp 'select-frame) (select-frame cf))
427 ; (YaTeX-showup-buffer YaTeX-label-buffer nil t)
428 ; (YaTeX::label-setup-key-map)
429 ; (setq truncate-lines t)
430 ; (setq buffer-read-only t)
431 ; (use-local-map YaTeX-label-select-map)
432 ; (message YaTeX-label-guide-msg)
433 ; (goto-line (1+ initl)) ;goto recently defined label line
434 ; (switch-to-buffer (current-buffer))
435 ; (unwind-protect
436 ; (progn
437 ; (recursive-edit)
438 ; (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
439 ; (beginning-of-line)
440 ; (setq line (1- (count-lines (point-min)(point))))
441 ; (cond
442 ; ((= line -1) (setq label ""))
443 ; ((= line lnum) (setq label (YaTeX-label-other)))
444 ; ((= line (1+ lnum))
445 ; (save-excursion
446 ; (switch-to-buffer buf)
447 ; (goto-char p)
448 ; (if (re-search-backward
449 ; (concat "\\\\" refcmd "{\\([^}]+\\)}") nil t)
450 ; (setq label (YaTeX-match-string 1))
451 ; (setq label ""))))
452 ; ((>= line (+ lnum 2))
453 ; (setq label (read-string (format "\\%s{???}: " refcmd))))
454 ; (t (setq label (nth (- lnum line 1) label-list)))))
455 ; (bury-buffer YaTeX-label-buffer)))
456 ; label)))))
458 (defun YaTeX::ref-generate-label ()
459 "Generate a label string which is unique in current buffer."
460 (let ((default (substring (current-time-string) 4)))
461 (read-string "Give a label for this line: "
462 (if YaTeX-emacs-19 (cons default 1) default))))
464 (defun YaTeX::ref-getset-label (buffer point)
465 "Get label string in the BUFFER near the POINT.
466 Make \\label{xx} if no label."
467 (let (boundary inspoint cc newlabel (labelholder "label") mathp env)
468 ;(set-buffer buffer)
469 (switch-to-buffer buffer)
470 (save-excursion
471 (goto-char point)
472 (setq cc (current-column))
473 (if (= (char-after (point)) ?\\) (forward-char 1))
474 (cond
475 ((looking-at YaTeX-sectioning-regexp)
476 (skip-chars-forward "^{")
477 (forward-list 1)
478 (skip-chars-forward " \t\n")
479 (setq boundary "[^\\]"))
480 ((looking-at "item\\s ")
481 (setq cc (+ cc 6))
482 (setq boundary (concat YaTeX-ec-regexp "\\(item\\|begin\\|end\\)\\b")))
483 ((looking-at "bibitem")
484 (setq labelholder "bibitem")) ; label holder is bibitem itself
485 ((string-match YaTeX::ref-mathenv-regexp
486 (setq env (or (YaTeX-inner-environment t) "document")))
487 (setq mathp t)
488 (setq boundary (concat YaTeX-ec-regexp "\\(\\\\\\|end{" env "}\\)")))
489 ((looking-at "caption\\|\\(begin\\)")
490 (skip-chars-forward "^{")
491 (if (match-beginning 1) (forward-list 1))
492 (setq boundary (concat YaTeX-ec-regexp "\\(begin\\|end\\)\\b")))
493 (t ))
494 (if (save-excursion (skip-chars-forward " \t") (looking-at "%"))
495 (forward-line 1))
496 (if (and (save-excursion
497 (YaTeX-re-search-active-forward
498 (concat "\\(" labelholder "\\)\\|\\(" boundary "\\)")
499 (regexp-quote YaTeX-comment-prefix)
500 nil 1))
501 (match-beginning 1))
502 ;; if \label{hoge} found, return it
503 (buffer-substring
504 (progn
505 (goto-char (match-end 0))
506 (skip-chars-forward "^{") (1+ (point)))
507 (progn
508 (forward-sexp 1) (1- (point))))
509 ;;else make a label
510 (goto-char (match-beginning 0))
511 (skip-chars-backward " \t\n")
512 (save-excursion (setq newlabel (YaTeX::ref-generate-label)))
513 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
514 (if mathp nil
515 (insert "\n")
516 (YaTeX-reindent cc))
517 (insert (format "\\label{%s}" newlabel))
518 newlabel))))
520 (defvar YaTeX::ref-labeling-regexp-alist
521 '(("\\\\begin{java}{\\([^}]+\\)}" . 1)
522 ("\\\\elabel{\\([^}]+\\)}" . 1)))
523 (defvar YaTeX::ref-labeling-regexp
524 (mapconcat 'car YaTeX::ref-labeling-regexp-alist "\\|"))
525 (defvar YaTeX::ref-mathenv-regexp
526 "equation\\|eqnarray\\|align\\|gather\\|alignat\\|xalignat")
527 (defvar YaTeX::ref-enumerateenv-regexp
528 "enumerate")
530 (defvar YaTeX::ref-labeling-section-level 2
531 "*ref補完で収集するセクショニングコマンドの下限レベル
532 YaTeX-sectioning-levelの数値で指定.")
534 (defun YaTeX::ref (argp &optional labelcmd refcmd)
535 (setplist 'YaTeX::ref-labeling-regexp nil) ;erase memory cache
536 (require 'yatexsec)
537 (cond
538 ((= argp 1)
539 (let*((lnum 0) e0 x cmd label match-point point-list boundary
540 (buf (current-buffer))
541 (llv YaTeX::ref-labeling-section-level)
542 (mathenvs YaTeX::ref-mathenv-regexp)
543 (enums YaTeX::ref-enumerateenv-regexp)
544 (counter
545 (or labelcmd
546 (concat
547 YaTeX-ec-regexp "\\(\\("
548 (mapconcat
549 'concat
550 (delq nil
551 (mapcar
552 (function
553 (lambda (s)
554 (if (>= llv (cdr s))
555 (car s))))
556 YaTeX-sectioning-level))
557 "\\|")
558 "\\|caption\\){"
559 "\\|\\(begin{\\(" mathenvs "\\|" enums "\\)\\)\\)")))
560 (regexp (concat "\\(" counter
561 "\\)\\|\\(" YaTeX::ref-labeling-regexp "\\)"))
562 (itemsep (concat YaTeX-ec-regexp
563 "\\(\\(bib\\)?item\\|begin\\|end\\)"))
564 (refcmd (or refcmd "ref"))
565 (p (point)) initl line cf
566 (percent (regexp-quote YaTeX-comment-prefix))
567 (output
568 (function
569 (lambda (label p)
570 (while (setq x (string-match "\n" label))
571 (aset label x ? ))
572 (while (setq x (string-match "[ \t\n][ \t\n]+" label))
573 (setq label (concat
574 (substring label 0 (1+ (match-beginning 0)))
575 (substring label (match-end 0)))))
576 (princ (format "%c: <<%s>>\n" (+ (% lnum 26) ?A) label))
577 (setq point-list (cons p point-list))
578 (message "Collecting labels... %d" lnum)
579 (setq lnum (1+ lnum)))))
580 )
581 (message "Collecting labels...")
582 (save-window-excursion
583 (YaTeX-showup-buffer
584 YaTeX-label-buffer (function (lambda (x) (window-width x))))
585 (if (fboundp 'select-frame) (setq cf (selected-frame)))
586 (if (eq (window-buffer (minibuffer-window)) buf)
587 (progn
588 (other-window 1)
589 (setq buf (current-buffer))
590 (set-buffer buf)))
591 (save-excursion
592 (set-buffer (get-buffer-create YaTeX-label-buffer))
593 (setq buffer-read-only nil)
594 (erase-buffer))
595 (save-excursion
596 (set-buffer buf)
597 (goto-char (point-min))
598 (let ((standard-output (get-buffer YaTeX-label-buffer)))
599 (princ (format "=== LABELS in [%s] ===\n" (buffer-name buf)))
600 (while (YaTeX-re-search-active-forward
601 regexp ;;counter
602 percent nil t)
603 ;(goto-char (match-beginning 0))
604 (setq e0 (match-end 0))
605 (cond
606 ((YaTeX-match-string 1)
607 ;;if standard counter commands found
608 (setq cmd (YaTeX-match-string 2))
609 (setq match-point (match-beginning 0))
610 (or initl
611 (if (< p (point)) (setq initl lnum)))
612 (cond
613 ((string-match mathenvs cmd) ;;if matches mathematical env
614 ;(skip-chars-forward "} \t\n")
615 (forward-line 1)
616 (setq x (point))
617 (catch 'scan
618 (while (YaTeX-re-search-active-forward
619 (concat "\\\\\\\\$\\|\\\\end{\\(" mathenvs "\\)")
620 percent nil t)
621 (let ((quit (match-beginning 1)))
622 (funcall output
623 (buffer-substring x (match-beginning 0))
624 x)
625 (if quit (throw 'scan t)))
626 (setq x (point))))
627 (setq e0 (point)))
628 ((string-match enums cmd)
629 ;(skip-chars-forward "} \t\n")
630 (save-restriction
631 (narrow-to-region
632 (point)
633 (save-excursion
634 (YaTeX-goto-corresponding-environment) (point)))
635 (forward-line 1)
636 (while (YaTeX-re-search-active-forward
637 (concat YaTeX-ec-regexp "item\\s ")
638 percent nil t)
639 (setq x (match-beginning 0))
640 (funcall
641 output
642 (buffer-substring
643 (match-beginning 0)
644 (if (re-search-forward itemsep nil t)
645 (progn (goto-char (match-beginning 0))
646 (skip-chars-backward " \t")
647 (1- (point)))
648 (point-end-of-line)))
649 x))))
651 ((= (char-after (1- (point))) ?{)
652 (setq label (buffer-substring
653 (match-beginning 0)
654 (progn (forward-char -1)
655 (forward-list 1)
656 (point))))
657 (funcall output label match-point))
658 (t
659 (skip-chars-forward " \t")
660 (setq label (buffer-substring
661 (match-beginning 0)
662 (if (re-search-forward
663 itemsep
664 nil t)
665 (progn
666 (goto-char (match-beginning 0))
667 (skip-chars-backward " \t")
668 (1- (point)))
669 (point-end-of-line))))
670 (funcall output label match-point)
671 ))
672 ) ;;put label buffer
673 ;;
674 ;; if user defined label found
675 (t
676 ;; memorize line number and label into property
677 (goto-char (match-beginning 0))
678 (let ((list YaTeX::ref-labeling-regexp-alist)
679 (cache (symbol-plist 'YaTeX::ref-labeling-regexp)))
680 (while list
681 (if (looking-at (car (car list)))
682 (progn
683 (setq label (YaTeX-match-string 0))
684 (put 'YaTeX::ref-labeling-regexp lnum
685 (YaTeX-match-string (cdr (car list))))
686 (funcall output label 0) ;;0 is dummy, never used
687 (setq list nil)))
688 (setq list (cdr list))))
689 ))
690 (goto-char e0))
691 (princ YaTeX-label-menu-other)
692 (princ YaTeX-label-menu-repeat)
693 (princ YaTeX-label-menu-any)
694 );standard-output
695 (goto-char p)
696 (or initl (setq initl lnum))
697 (message "Collecting labels...Done")
698 (if (fboundp 'select-frame) (select-frame cf))
699 (YaTeX-showup-buffer YaTeX-label-buffer nil t)
700 (YaTeX::label-setup-key-map)
701 (setq truncate-lines t)
702 (setq buffer-read-only t)
703 (use-local-map YaTeX-label-select-map)
704 (message YaTeX-label-guide-msg)
705 (goto-line (1+ initl)) ;goto recently defined label line
706 (switch-to-buffer (current-buffer))
707 (unwind-protect
708 (progn
709 (recursive-edit)
711 (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
712 (beginning-of-line)
713 (setq line (1- (count-lines (point-min)(point))))
714 (cond
715 ((= line -1) (setq label ""))
716 ((= line lnum) (setq label (YaTeX-label-other)))
717 ((= line (1+ lnum))
718 (save-excursion
719 (switch-to-buffer buf)
720 (goto-char p)
721 (if (re-search-backward
722 (concat "\\\\" refcmd "{\\([^}]+\\)}") nil t)
723 (setq label (YaTeX-match-string 1))
724 (setq label ""))))
725 ((>= line (+ lnum 2))
726 (setq label (read-string (format "\\%s{???}: " refcmd))))
727 (t ;(setq label (nth (- lnum line 1) label-list))
728 (setq label
729 (or (get 'YaTeX::ref-labeling-regexp line)
730 (YaTeX::ref-getset-label
731 buf (nth (- lnum line 1) point-list))))
732 )))
733 (bury-buffer YaTeX-label-buffer)))
734 label)))))
736 (fset 'YaTeX::pageref 'YaTeX::ref)
738 (defun YaTeX::cite-collect-bibs-external (&rest files)
739 "Collect bibentry from FILES(variable length argument);
740 and print them to standard output."
741 ;;Thanks; http://icarus.ilcs.hokudai.ac.jp/comp/biblio.html
742 (let ((tb (get-buffer-create " *bibtmp*")))
743 (save-excursion
744 (set-buffer tb)
745 (while files
746 (erase-buffer)
747 (cond
748 ((file-exists-p (car files))
749 (insert-file-contents (car files)))
750 ((file-exists-p (concat (car files) ".bib"))
751 (insert-file-contents (concat (car files) ".bib"))))
752 (save-excursion
753 (goto-char (point-min))
754 (while (re-search-forward "^\\s *@[A-Za-z]" nil t)
755 (skip-chars-forward "^{,")
756 (if (= (char-after (point)) ?{)
757 (princ (format "%sbibitem{%s}%s\n"
758 YaTeX-ec
759 (buffer-substring
760 (1+ (point))
761 (progn (skip-chars-forward "^,\n")
762 (point)))
763 (if (re-search-forward "title\\s *=" nil t)
764 (buffer-substring
765 (progn
766 (goto-char (match-end 0))
767 (skip-chars-forward " \t\n")
768 (point))
769 (progn
770 (if (looking-at "[{\"]")
771 (forward-sexp 1)
772 (forward-char 1)
773 (skip-chars-forward "^,"))
774 (point)))))))))
775 (setq files (cdr files))))))
777 (defun YaTeX::cite-collect-bibs-internal ()
778 "Collect bibentry in the current buffer and print them to standard output."
779 (let ((ptn (concat YaTeX-ec-regexp "bibitem\\b"))
780 (pcnt (regexp-quote YaTeX-comment-prefix)))
781 (save-excursion
782 (while (YaTeX-re-search-active-forward ptn pcnt nil t)
783 (skip-chars-forward "^{\n")
784 (or (eolp)
785 (princ (format "%sbibitem{%s}\n"
786 YaTeX-ec
787 (buffer-substring
788 (1+ (point))
789 (progn (forward-sexp 1) (point))))))))))
791 (defun YaTeX::cite (argp)
792 (cond
793 ((eq argp 1)
794 (let* ((cb (current-buffer))
795 (f (file-name-nondirectory buffer-file-name))
796 (d default-directory)
797 (hilit-auto-highlight nil)
798 (pcnt (regexp-quote YaTeX-comment-prefix))
799 (bibrx (concat YaTeX-ec-regexp "bibliography{\\([^}]+\\)}"))
800 (bbuf (get-buffer-create " *bibitems*"))
801 (standard-output bbuf)
802 bibs files)
803 (set-buffer bbuf)(erase-buffer)(set-buffer cb)
804 (save-excursion
805 (goto-char (point-min))
806 ;;(1)search external bibdata
807 (while (YaTeX-re-search-active-forward bibrx pcnt nil t)
808 (apply 'YaTeX::cite-collect-bibs-external
809 (YaTeX-split-string
810 (YaTeX-match-string 1) ",")))
811 ;;(2)search direct \bibitem usage
812 (YaTeX::cite-collect-bibs-internal)
813 (if (progn
814 (YaTeX-visit-main t)
815 (not (eq (current-buffer) cb)))
816 (save-excursion
817 (goto-char (point-min))
818 ;;(1)search external bibdata
819 (while (YaTeX-re-search-active-forward bibrx pcnt nil t)
820 (apply 'YaTeX::cite-collect-bibs-external
821 (YaTeX-split-string
822 (YaTeX-match-string 1) ",")))
823 ;;(2)search internal
824 (YaTeX::cite-collect-bibs-internal)))
825 ;;Now bbuf holds the list of bibitem
826 (set-buffer bbuf)
827 (YaTeX::ref argp "\\\\\\(bibitem\\)\\(\\[.*\\]\\)?" "cite"))))
829 (t nil)))
831 (and YaTeX-use-AMS-LaTeX (fset 'YaTeX::eqref 'YaTeX::ref))
833 (defun YaTeX-yatex-buffer-list ()
834 (save-excursion
835 (delq nil (mapcar (function (lambda (buf)
836 (set-buffer buf)
837 (if (eq major-mode 'yatex-mode) buf)))
838 (buffer-list)))))
840 (defun YaTeX-select-other-yatex-buffer ()
841 "Select buffer from all yatex-mode's buffers interactivelly."
842 (interactive)
843 (let ((lbuf "*YaTeX mode buffers*") (blist (YaTeX-yatex-buffer-list))
844 (lnum -1) buf rv
845 (ff "**find-file**"))
846 (YaTeX-showup-buffer
847 lbuf (function (lambda (x) 1))) ;;Select next window surely.
848 (save-excursion
849 (set-buffer (get-buffer lbuf))
850 (setq buffer-read-only nil)
851 (erase-buffer))
852 (let ((standard-output (get-buffer lbuf)))
853 (while blist
854 (princ
855 (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A)
856 (buffer-name (car blist))))
857 (setq blist (cdr blist)))
858 (princ (format "':{%s}" ff)))
859 (YaTeX-showup-buffer lbuf nil t)
860 (YaTeX::label-setup-key-map)
861 (setq buffer-read-only t)
862 (use-local-map YaTeX-label-select-map)
863 (message YaTeX-label-guide-msg)
864 (unwind-protect
865 (progn
866 (recursive-edit)
867 (set-buffer lbuf)
868 (beginning-of-line)
869 (setq rv
870 (if (re-search-forward "{\\([^\\}]+\\)}" (point-end-of-line) t)
871 (buffer-substring (match-beginning 1) (match-end 1)) nil)))
872 (kill-buffer lbuf))
873 (if (string= rv ff)
874 (progn
875 (call-interactively 'find-file)
876 (current-buffer))
877 rv)))
879 (defun YaTeX-label-other ()
880 (let ((rv (YaTeX-select-other-yatex-buffer)))
881 (cond
882 ((null rv) "")
883 (t
884 (set-buffer rv)
885 (YaTeX::ref argp labelcmd refcmd)))))
887 ;;
888 ; completion for the arguments of \newcommand
889 ;;
890 (defun YaTeX::newcommand (&optional argp)
891 (cond
892 ((= argp 1)
893 (let ((command (read-string "Define newcommand: " "\\")))
894 (put 'YaTeX::newcommand 'command (substring command 1))
895 command))
896 ((= argp 2)
897 (let ((argc
898 (string-to-int (read-string "Number of arguments(Default 0): ")))
899 (def (read-string "Definition: "))
900 (command (get 'YaTeX::newcommand 'command)))
901 ;;!!! It's illegal to insert string in the add-in function !!!
902 (if (> argc 0) (insert (format "[%d]" argc)))
903 (if (and (stringp command)
904 (string< "" command)
905 (y-or-n-p "Update dictionary?"))
906 (cond
907 ((= argc 0)
908 (YaTeX-update-table
909 (list command)
910 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table))
911 ((= argc 1)
912 (YaTeX-update-table
913 (list command)
914 'section-table 'user-section-table 'tmp-section-table))
915 (t (YaTeX-update-table
916 (list command argc)
917 'section-table 'user-section-table 'tmp-section-table))))
918 (message "")
919 def ;return command name
920 ))
921 (t "")))
923 ;;
924 ; completion for the arguments of \pagestyle
925 ;;
926 (defun YaTeX::pagestyle (&optional argp)
927 "Read the pagestyle with completion."
928 (completing-read
929 "Page style: "
930 '(("plain") ("empty") ("headings") ("myheadings") ("normal") nil)))
932 (fset 'YaTeX::thispagestyle 'YaTeX::pagestyle)
934 ;;
935 ; completion for the arguments of \pagenumbering
936 ;;
937 (defun YaTeX::pagenumbering (&optional argp)
938 "Read the numbering style."
939 (completing-read
940 "Page numbering style: "
941 '(("arabic") ("Alpha") ("alpha") ("Roman") ("roman"))))
943 ;;
944 ; Length
945 ;;
946 (defvar YaTeX:style-parameters-default
947 '(("\\arraycolsep")
948 ("\\arrayrulewidth")
949 ("\\baselineskip")
950 ("\\columnsep")
951 ("\\columnseprule")
952 ("\\doublerulesep")
953 ("\\evensidemargin")
954 ("\\footheight")
955 ("\\footskip")
956 ("\\headheight")
957 ("\\headsep")
958 ("\\itemindent")
959 ("\\itemsep")
960 ("\\labelsep")
961 ("\\labelwidth")
962 ("\\leftmargin")
963 ("\\linewidth")
964 ("\\listparindent")
965 ("\\marginparsep")
966 ("\\marginparwidth")
967 ("\\mathindent")
968 ("\\oddsidemargin")
969 ("\\parindent")
970 ("\\parsep")
971 ("\\parskip")
972 ("\\partopsep")
973 ("\\rightmargin")
974 ("\\tabcolsep")
975 ("\\textheight")
976 ("\\textwidth")
977 ("\\topmargin")
978 ("\\topsep")
979 ("\\topskip")
980 )
981 "Alist of LaTeX style parameters.")
982 (defvar YaTeX:style-parameters-private nil
983 "*User definable alist of style parameters.")
984 (defvar YaTeX:style-parameters-local nil
985 "*User definable alist of local style parameters.")
987 (defvar YaTeX:length-history nil "Holds history of length.")
988 (put 'YaTeX:length-history 'no-default t)
989 (defun YaTeX::setlength (&optional argp)
990 "YaTeX add-in function for arguments of \\setlength."
991 (cond
992 ((equal 1 argp)
993 ;;(completing-read "Length variable: " YaTeX:style-parameters nil nil "\\")
994 (YaTeX-cplread-with-learning
995 "Length variable: "
996 'YaTeX:style-parameters-default
997 'YaTeX:style-parameters-private
998 'YaTeX:style-parameters-local
999 nil nil "\\")
1001 ((equal 2 argp)
1002 (read-string-with-history "Length: " nil 'YaTeX:length-history))))
1004 (fset 'YaTeX::addtolength 'YaTeX::setlength)
1006 (defun YaTeX::settowidth (&optional argp)
1007 "YaTeX add-in function for arguments of \\settowidth."
1008 (cond
1009 ((equal 1 argp)
1010 (YaTeX-cplread-with-learning
1011 "Length variable: "
1012 'YaTeX:style-parameters-default
1013 'YaTeX:style-parameters-private
1014 'YaTeX:style-parameters-local
1015 nil nil "\\"))
1016 ((equal 2 argp)
1017 (read-string "Text: "))))
1019 (defun YaTeX::newlength (&optional argp)
1020 "YaTeX add-in function for arguments of \\newlength"
1021 (cond
1022 ((equal argp 1)
1023 (let ((length (read-string "Length variable: " "\\")))
1024 (if (string< "" length)
1025 (YaTeX-update-table
1026 (list length)
1027 'YaTeX:style-parameters-default
1028 'YaTeX:style-parameters-private
1029 'YaTeX:style-parameters-local))
1030 length))))
1032 ;; \multicolumn's arguments
1033 (defun YaTeX::multicolumn (&optional argp)
1034 "YaTeX add-in function for arguments of \\multicolumn."
1035 (cond
1036 ((equal 1 argp)
1037 (read-string "Number of columns: "))
1038 ((equal 2 argp)
1039 (let (c)
1040 (while (not (string-match
1041 (progn (message "Format(one of l,r,c): ")
1042 (setq c (char-to-string (read-char))))
1043 "lrc")))
1044 c))
1045 ((equal 3 argp)
1046 (read-string "Item: "))))
1048 (defvar YaTeX:documentstyles-default
1049 '(("article") ("jarticle") ("j-article")
1050 ("book") ("jbook") ("j-book")
1051 ("report") ("jreport") ("j-report")
1052 ("letter") ("ascjletter"))
1053 "List of LaTeX documentstyles.")
1054 (defvar YaTeX:documentstyles-private nil
1055 "*User defined list of LaTeX documentstyles.")
1056 (defvar YaTeX:documentstyles-local nil
1057 "*User defined list of local LaTeX documentstyles.")
1058 (defvar YaTeX:documentstyle-options-default
1059 '(("a4j") ("a5j") ("b4j") ("b5j")
1060 ("twocolumn") ("jtwocolumn") ("epsf") ("epsfig") ("epsbox") ("nfig"))
1061 "List of LaTeX documentstyle options.")
1062 (defvar YaTeX:documentstyle-options-private nil
1063 "*User defined list of LaTeX documentstyle options.")
1064 (defvar YaTeX:documentstyle-options-local nil
1065 "List of LaTeX local documentstyle options.")
1067 (defvar YaTeX-minibuffer-completion-map nil
1068 "Minibuffer completion key map that allows comma completion.")
1069 (if YaTeX-minibuffer-completion-map nil
1070 (setq YaTeX-minibuffer-completion-map
1071 (copy-keymap minibuffer-local-completion-map))
1072 (define-key YaTeX-minibuffer-completion-map " "
1073 'YaTeX-minibuffer-complete)
1074 (define-key YaTeX-minibuffer-completion-map "\t"
1075 'YaTeX-minibuffer-complete))
1077 (defun YaTeX:documentstyle ()
1078 (let*((delim ",")
1079 (dt (append YaTeX:documentstyle-options-local
1080 YaTeX:documentstyle-options-private
1081 YaTeX:documentstyle-options-default))
1082 (minibuffer-completion-table dt)
1083 (opt (read-from-minibuffer
1084 "Style options ([opt1,opt2,...]): "
1085 nil YaTeX-minibuffer-completion-map nil))
1086 (substr opt) o)
1087 (if (string< "" opt)
1088 (progn
1089 (while substr
1090 (setq o (substring substr 0 (string-match delim substr)))
1091 (or (assoc o dt)
1092 (YaTeX-update-table
1093 (list o)
1094 'YaTeX:documentstyle-options-default
1095 'YaTeX:documentstyle-options-private
1096 'YaTeX:documentstyle-options-local))
1097 (setq substr
1098 (if (string-match delim substr)
1099 (substring substr (1+ (string-match delim substr))))))
1100 (concat "[" opt "]"))
1101 "")))
1103 (defun YaTeX::documentstyle (&optional argp)
1104 "YaTeX add-in function for arguments of \\documentstyle."
1105 (cond
1106 ((equal argp 1)
1107 (setq YaTeX-env-name "document")
1108 (let ((sname
1109 (YaTeX-cplread-with-learning
1110 (format "Documentstyle (default %s): "
1111 YaTeX-default-document-style)
1112 'YaTeX:documentstyles-default
1113 'YaTeX:documentstyles-private
1114 'YaTeX:documentstyles-local)))
1115 (if (string= "" sname) (setq sname YaTeX-default-document-style))
1116 (setq YaTeX-default-document-style sname)))))
1118 ;;; -------------------- LaTeX2e stuff --------------------
1119 (defvar YaTeX:documentclass-options-default
1120 '(("a4paper") ("a5paper") ("b4paper") ("b5paper") ("10pt") ("11pt") ("12pt")
1121 ("latterpaper") ("legalpaper") ("executivepaper") ("landscape")
1122 ("oneside") ("twoside") ("draft") ("final") ("leqno") ("fleqn") ("openbib")
1123 ("tombow") ("titlepage") ("notitlepage") ("dvips")
1124 ("clock") ;for slides class only
1126 "Default options list for documentclass")
1127 (defvar YaTeX:documentclass-options-private nil
1128 "*User defined options list for documentclass")
1129 (defvar YaTeX:documentclass-options-local nil
1130 "*User defined options list for local documentclass")
1132 (defun YaTeX:documentclass ()
1133 (let*((delim ",")
1134 (dt (append YaTeX:documentclass-options-local
1135 YaTeX:documentclass-options-private
1136 YaTeX:documentclass-options-default))
1137 (minibuffer-completion-table dt)
1138 (opt (read-from-minibuffer
1139 "Documentclass options ([opt1,opt2,...]): "
1140 nil YaTeX-minibuffer-completion-map nil))
1141 (substr opt) o)
1142 (if (string< "" opt)
1143 (progn
1144 (while substr
1146 (setq o (substring substr 0 (string-match delim substr)))
1147 (or (assoc o dt)
1148 (YaTeX-update-table
1149 (list o)
1150 'YaTeX:documentclass-options-default
1151 'YaTeX:documentclass-options-private
1152 'YaTeX:documentclass-options-local))
1153 (setq substr
1154 (if (string-match delim substr)
1155 (substring substr (1+ (string-match delim substr))))))
1156 (concat "[" opt "]"))
1157 "")))
1159 (defvar YaTeX:documentclasses-default
1160 '(("article") ("jarticle") ("report") ("jreport") ("book") ("jbook")
1161 ("j-article") ("j-report") ("j-book")
1162 ("letter") ("slides") ("ltxdoc") ("ltxguide") ("ltnews") ("proc"))
1163 "Default documentclass alist")
1164 (defvar YaTeX:documentclasses-private nil
1165 "*User defined documentclass alist")
1166 (defvar YaTeX:documentclasses-local nil
1167 "*User defined local documentclass alist")
1168 (defvar YaTeX-default-documentclass (if YaTeX-japan "jarticle" "article")
1169 "*Default documentclass")
1171 (defun YaTeX::documentclass (&optional argp)
1172 (cond
1173 ((equal argp 1)
1174 (setq YaTeX-env-name "document")
1175 (let ((sname
1176 (YaTeX-cplread-with-learning
1177 (format "Documentclass (default %s): " YaTeX-default-documentclass)
1178 'YaTeX:documentclasses-default
1179 'YaTeX:documentclasses-private
1180 'YaTeX:documentclasses-local)))
1181 (if (string= "" sname) (setq sname YaTeX-default-documentclass))
1182 (setq YaTeX-default-documentclass sname)))))
1184 (defvar YaTeX:latex2e-named-color-alist
1185 '(("GreenYellow") ("Yellow") ("Goldenrod") ("Dandelion") ("Apricot")
1186 ("Peach") ("Melon") ("YellowOrange") ("Orange") ("BurntOrange")
1187 ("Bittersweet") ("RedOrange") ("Mahogany") ("Maroon") ("BrickRed")
1188 ("Red") ("OrangeRed") ("RubineRed") ("WildStrawberry") ("Salmon")
1189 ("CarnationPink") ("Magenta") ("VioletRed") ("Rhodamine") ("Mulberry")
1190 ("RedViolet") ("Fuchsia") ("Lavender") ("Thistle") ("Orchid")("DarkOrchid")
1191 ("Purple") ("Plum") ("Violet") ("RoyalPurple") ("BlueViolet")
1192 ("Periwinkle") ("CadetBlue") ("CornflowerBlue") ("MidnightBlue")
1193 ("NavyBlue") ("RoyalBlue") ("Blue") ("Cerulean") ("Cyan") ("ProcessBlue")
1194 ("SkyBlue") ("Turquoise") ("TealBlue") ("Aquamarine") ("BlueGreen")
1195 ("Emerald") ("JungleGreen") ("SeaGreen") ("Green") ("ForestGreen")
1196 ("PineGreen") ("LimeGreen") ("YellowGreen") ("SpringGreen") ("OliveGreen")
1197 ("RawSienna") ("Sepia") ("Brown") ("Tan") ("Gray") ("Black") ("White"))
1198 "Colors defined in $TEXMF/tex/plain/colordvi.tex")
1200 (defvar YaTeX:latex2e-basic-color-alist
1201 '(("black") ("white") ("red") ("blue") ("yellow") ("green") ("cyan")
1202 ("magenta"))
1203 "Basic colors")
1205 (defun YaTeX:textcolor ()
1206 "Add-in for \\color's option"
1207 (if (y-or-n-p "Use `named' color? ")
1208 "[named]"))
1210 (defun YaTeX::color-completing-read (prompt)
1211 (let ((completion-ignore-case t)
1212 (namedp (save-excursion
1213 (skip-chars-backward "^\n\\[\\\\")
1214 (looking-at "named"))))
1215 (completing-read
1216 prompt
1217 (if namedp
1218 YaTeX:latex2e-named-color-alist
1219 YaTeX:latex2e-basic-color-alist)
1220 nil t)))
1222 (defun YaTeX::textcolor (argp)
1223 "Add-in for \\color's argument"
1224 (cond
1225 ((= argp 1) (YaTeX::color-completing-read "Color: "))
1226 ((= argp 2) (read-string "Colored string: "))))
1228 (fset 'YaTeX:color 'YaTeX:textcolor)
1229 (fset 'YaTeX::color 'YaTeX::textcolor)
1230 (fset 'YaTeX:colorbox 'YaTeX:textcolor)
1231 (fset 'YaTeX::colorbox 'YaTeX::textcolor)
1232 (fset 'YaTeX:fcolorbox 'YaTeX:textcolor)
1234 (defun YaTeX::fcolorbox (argp)
1235 (cond
1236 ((= argp 1) (YaTeX::color-completing-read "Frame color: "))
1237 ((= argp 2) (YaTeX::color-completing-read "Inner color: "))
1238 ((= argp 3) (read-string "Colored string: "))))
1240 (defun YaTeX:scalebox ()
1241 "Add-in for \\rotatebox"
1242 (let ((vmag (read-string (if YaTeX-japan "倍率: " "Magnification: ")))
1243 (hmag (read-string (if YaTeX-japan "横倍率(省略可): "
1244 "Horizontal magnification(Optional): "))))
1245 (if (and hmag (string< "" hmag))
1246 (format "{%s}[%s]" vmag hmag)
1247 (format "{%s}" vmag))))
1249 (defun YaTeX::includegraphics (argp)
1250 "Add-in for \\includegraphics"
1251 (cond
1252 ((= argp 1)
1253 (read-file-name "EPS File: " ""))))
1255 (defun YaTeX:caption ()
1256 (setq YaTeX-section-name "label")
1257 nil)
1259 ;;; -------------------- math-mode stuff --------------------
1260 (defun YaTeX::tilde (&optional pos)
1261 "For accent macros in mathmode"
1262 (cond
1263 ((equal pos 1)
1264 (message "Put accent on variable: ")
1265 (let ((v (char-to-string (read-char))) (case-fold-search nil))
1266 (message "")
1267 (cond
1268 ((string-match "i\\|j" v)
1269 (concat "\\" v "math"))
1270 ((string-match "[\r\n\t ]" v)
1271 "")
1272 (t v))))
1273 (nil "")))
1275 (fset 'YaTeX::hat 'YaTeX::tilde)
1276 (fset 'YaTeX::check 'YaTeX::tilde)
1277 (fset 'YaTeX::bar 'YaTeX::tilde)
1278 (fset 'YaTeX::dot 'YaTeX::tilde)
1279 (fset 'YaTeX::ddot 'YaTeX::tilde)
1280 (fset 'YaTeX::vec 'YaTeX::tilde)
1282 (defun YaTeX::widetilde (&optional pos)
1283 "For multichar accent macros in mathmode"
1284 (cond
1285 ((equal pos 1)
1286 (let ((m "Put over chars[%s ]: ") v v2)
1287 (message m " ")
1288 (setq v (char-to-string (read-char)))
1289 (message "")
1290 (if (string-match "[\r\n\t ]" v)
1291 ""
1292 (message m v)
1293 (setq v2 (char-to-string (read-char)))
1294 (message "")
1295 (if (string-match "[\r\n\t ]" v2)
1297 (concat v v2)))))
1298 (nil "")))
1300 (fset 'YaTeX::widehat 'YaTeX::widetilde)
1301 (fset 'YaTeX::overline 'YaTeX::widetilde)
1302 (fset 'YaTeX::overrightarrow 'YaTeX::widetilde)
1305 ;;;
1306 ;; Add-in functions for large-type command.
1307 ;;;
1308 (defun YaTeX:em ()
1309 (cond
1310 ((eq YaTeX-current-completion-type 'large) "\\/")
1311 (t nil)))
1312 (fset 'YaTeX:it 'YaTeX:em)
1314 ;;; -------------------- End of yatexadd --------------------
1315 (provide 'yatexadd)
1316 ; Local variables:
1317 ; fill-prefix: ";;; "
1318 ; paragraph-start: "^$\\| \\|;;;$"
1319 ; paragraph-separate: "^$\\| \\|;;;$"
1320 ; buffer-file-coding-system: sjis
1321 ; End: