yatex

view yatexadd.el @ 70:44e3a5e1e883

Fix makefile for Windows Brush up label completion \cite completion Support much more about LaTeX2e --- [yahtml] English Info (By Jun Ohya) Automatic pixel size detection for <img src="..."> Aware global-class of css definition & for char-entity reference
author yuuji
date Sun, 09 Apr 2000 03:37:47 +0000
parents 807c1e7e68b7
children 0aaebd07dad0
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX add-in functions.
3 ;;; yatexadd.el rev.14
4 ;;; (c )1991-1999 by HIROSE Yuuji.[yuuji@yatex.org]
5 ;;; Last modified Fri Mar 17 20:21:45 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= env "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 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 env-name "tabular"
94 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 single-command "item[]")
104 "")
106 (defun YaTeX:itemize ()
107 "It's also poor service."
108 (setq 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 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= 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 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 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 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 "\\S "))
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 (lambda (s)
553 (if (>= llv (cdr s))
554 (car s)))
555 YaTeX-sectioning-level))
556 "\\|")
557 "\\|caption\\){"
558 "\\|\\(begin{\\(" mathenvs "\\|" enums "\\)\\)\\)")))
559 (regexp (concat "\\(" counter
560 "\\)\\|\\(" YaTeX::ref-labeling-regexp "\\)"))
561 (itemsep (concat YaTeX-ec-regexp
562 "\\(\\(bib\\)?item\\|begin\\|end\\)"))
563 (refcmd (or refcmd "ref"))
564 (p (point)) initl line cf
565 (percent (regexp-quote YaTeX-comment-prefix))
566 (output
567 (function
568 (lambda (label p)
569 (while (setq x (string-match "\n" label))
570 (aset label x ? ))
571 (while (setq x (string-match "[ \t\n][ \t\n]+" label))
572 (setq label (concat
573 (substring label 0 (1+ (match-beginning 0)))
574 (substring label (match-end 0)))))
575 (princ (format "%c: <<%s>>\n" (+ (% lnum 26) ?A) label))
576 (setq point-list (cons p point-list))
577 (message "Collecting labels... %d" lnum)
578 (setq lnum (1+ lnum)))))
579 )
580 (message "Collecting labels...")
581 (save-window-excursion
582 (YaTeX-showup-buffer
583 YaTeX-label-buffer (function (lambda (x) (window-width x))))
584 (if (fboundp 'select-frame) (setq cf (selected-frame)))
585 (if (eq (window-buffer (minibuffer-window)) buf)
586 (progn
587 (other-window 1)
588 (setq buf (current-buffer))
589 (set-buffer buf)))
590 (save-excursion
591 (set-buffer (get-buffer-create YaTeX-label-buffer))
592 (setq buffer-read-only nil)
593 (erase-buffer))
594 (save-excursion
595 (set-buffer buf)
596 (goto-char (point-min))
597 (let ((standard-output (get-buffer YaTeX-label-buffer)))
598 (princ (format "=== LABELS in [%s] ===\n" (buffer-name buf)))
599 (while (YaTeX-re-search-active-forward
600 regexp ;;counter
601 percent nil t)
602 ;(goto-char (match-beginning 0))
603 (setq e0 (match-end 0))
604 (cond
605 ((match-string 1)
606 ;;if standard counter commands found
607 (setq cmd (YaTeX-match-string 2))
608 (setq match-point (match-beginning 0))
609 (or initl
610 (if (< p (point)) (setq initl lnum)))
611 (cond
612 ((string-match mathenvs cmd) ;;if matches mathematical env
613 ;(skip-chars-forward "} \t\n")
614 (forward-line 1)
615 (setq x (point))
616 (catch 'scan
617 (while (YaTeX-re-search-active-forward
618 (concat "\\\\\\\\$\\|\\\\end{\\(" mathenvs "\\)")
619 percent nil t)
620 (let ((quit (match-beginning 1)))
621 (funcall output
622 (buffer-substring x (match-beginning 0))
623 x)
624 (if quit (throw 'scan t)))
625 (setq x (point))))
626 (setq e0 (point)))
627 ((string-match enums cmd)
628 ;(skip-chars-forward "} \t\n")
629 (save-restriction
630 (narrow-to-region
631 (point)
632 (save-excursion
633 (YaTeX-goto-corresponding-environment) (point)))
634 (forward-line 1)
635 (while (YaTeX-re-search-active-forward
636 (concat YaTeX-ec-regexp "item\\s ")
637 percent nil t)
638 (setq x (match-beginning 0))
639 (funcall
640 output
641 (buffer-substring
642 (match-beginning 0)
643 (if (re-search-forward itemsep nil t)
644 (progn (goto-char (match-beginning 0))
645 (skip-chars-backward " \t")
646 (1- (point)))
647 (point-end-of-line)))
648 x))))
650 ((= (char-after (1- (point))) ?{)
651 (setq label (buffer-substring
652 (match-beginning 0)
653 (progn (forward-char -1)
654 (forward-list 1)
655 (point))))
656 (funcall output label match-point))
657 (t
658 (skip-chars-forward " \t")
659 (setq label (buffer-substring
660 (match-beginning 0)
661 (if (re-search-forward
662 itemsep
663 nil t)
664 (progn
665 (goto-char (match-beginning 0))
666 (skip-chars-backward " \t")
667 (1- (point)))
668 (point-end-of-line))))
669 (funcall output label match-point)
670 ))
671 ) ;;put label buffer
672 ;;
673 ;; if user defined label found
674 (t
675 ;; memorize line number and label into property
676 (goto-char (match-beginning 0))
677 (let ((list YaTeX::ref-labeling-regexp-alist)
678 (cache (symbol-plist 'YaTeX::ref-labeling-regexp)))
679 (while list
680 (if (looking-at (car (car list)))
681 (progn
682 (setq label (YaTeX-match-string 0))
683 (put 'YaTeX::ref-labeling-regexp lnum
684 (YaTeX-match-string (cdr (car list))))
685 (funcall output label 0) ;;0 is dummy, never used
686 (setq list nil)))
687 (setq list (cdr list))))
688 ))
689 (goto-char e0))
690 (princ YaTeX-label-menu-other)
691 (princ YaTeX-label-menu-repeat)
692 (princ YaTeX-label-menu-any)
693 );standard-output
694 (goto-char p)
695 (or initl (setq initl lnum))
696 (message "Collecting labels...Done")
697 (if (fboundp 'select-frame) (select-frame cf))
698 (YaTeX-showup-buffer YaTeX-label-buffer nil t)
699 (YaTeX::label-setup-key-map)
700 (setq truncate-lines t)
701 (setq buffer-read-only t)
702 (use-local-map YaTeX-label-select-map)
703 (message YaTeX-label-guide-msg)
704 (goto-line (1+ initl)) ;goto recently defined label line
705 (switch-to-buffer (current-buffer))
706 (unwind-protect
707 (progn
708 (recursive-edit)
710 (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
711 (beginning-of-line)
712 (setq line (1- (count-lines (point-min)(point))))
713 (cond
714 ((= line -1) (setq label ""))
715 ((= line lnum) (setq label (YaTeX-label-other)))
716 ((= line (1+ lnum))
717 (save-excursion
718 (switch-to-buffer buf)
719 (goto-char p)
720 (if (re-search-backward
721 (concat "\\\\" refcmd "{\\([^}]+\\)}") nil t)
722 (setq label (YaTeX-match-string 1))
723 (setq label ""))))
724 ((>= line (+ lnum 2))
725 (setq label (read-string (format "\\%s{???}: " refcmd))))
726 (t ;(setq label (nth (- lnum line 1) label-list))
727 (setq label
728 (or (get 'YaTeX::ref-labeling-regexp line)
729 (YaTeX::ref-getset-label
730 buf (nth (- lnum line 1) point-list))))
731 )))
732 (bury-buffer YaTeX-label-buffer)))
733 label)))))
735 (fset 'YaTeX::pageref 'YaTeX::ref)
737 (defun YaTeX::cite-collect-bibs-external (&rest files)
738 "Collect bibentry from FILES(variable length argument);
739 and print them to standard output."
740 ;;Thanks; http://icarus.ilcs.hokudai.ac.jp/comp/biblio.html
741 (let ((tb (get-buffer-create " *bibtmp*")))
742 (save-excursion
743 (set-buffer tb)
744 (while files
745 (erase-buffer)
746 (cond
747 ((file-exists-p (car files))
748 (insert-file-contents (car files)))
749 ((file-exists-p (concat (car files) ".bib"))
750 (insert-file-contents (concat (car files) ".bib"))))
751 (save-excursion
752 (goto-char (point-min))
753 (while (re-search-forward "^\\s *@[A-Za-z]" nil t)
754 (skip-chars-forward "^{,")
755 (if (= (char-after (point)) ?{)
756 (princ (format "%sbibitem{%s}%s\n"
757 YaTeX-ec
758 (buffer-substring
759 (1+ (point))
760 (progn (skip-chars-forward "^,\n")
761 (point)))
762 (if (re-search-forward "title\\s *=" nil t)
763 (buffer-substring
764 (progn
765 (goto-char (match-end 0))
766 (skip-chars-forward " \t\n")
767 (point))
768 (progn
769 (if (looking-at "[{\"]")
770 (forward-sexp 1)
771 (forward-char 1)
772 (skip-chars-forward "^,"))
773 (point)))))))))
774 (setq files (cdr files))))))
776 (defun YaTeX::cite-collect-bibs-internal ()
777 "Collect bibentry in the current buffer and print them to standard output."
778 (let ((ptn (concat YaTeX-ec-regexp "bibitem\\b"))
779 (pcnt (regexp-quote YaTeX-comment-prefix)))
780 (save-excursion
781 (while (YaTeX-re-search-active-forward ptn pcnt nil t)
782 (skip-chars-forward "^{\n")
783 (or (eolp)
784 (princ (format "%sbibitem{%s}\n"
785 YaTeX-ec
786 (buffer-substring
787 (1+ (point))
788 (progn (forward-sexp 1) (point))))))))))
790 (defun YaTeX::cite (argp)
791 (cond
792 ((eq argp 1)
793 (let* ((cb (current-buffer))
794 (f (file-name-nondirectory buffer-file-name))
795 (d default-directory)
796 (hilit-auto-highlight nil)
797 (pcnt (regexp-quote YaTeX-comment-prefix))
798 (bibrx (concat YaTeX-ec-regexp "bibliography{\\([^}]+\\)}"))
799 (bbuf (get-buffer-create " *bibitems*"))
800 (standard-output bbuf)
801 bibs files)
802 (set-buffer bbuf)(erase-buffer)(set-buffer cb)
803 (save-excursion
804 (goto-char (point-min))
805 ;;(1)search external bibdata
806 (while (YaTeX-re-search-active-forward bibrx pcnt nil t)
807 (apply 'YaTeX::cite-collect-bibs-external
808 (YaTeX-split-string
809 (YaTeX-match-string 1) ",")))
810 ;;(2)search direct \bibitem usage
811 (YaTeX::cite-collect-bibs-internal)
812 (if (progn
813 (YaTeX-visit-main t)
814 (not (eq (current-buffer) cb)))
815 (save-excursion
816 (goto-char (point-min))
817 ;;(1)search external bibdata
818 (while (YaTeX-re-search-active-forward bibrx pcnt nil t)
819 (apply 'YaTeX::cite-collect-bibs-external
820 (YaTeX-split-string
821 (YaTeX-match-string 1) ",")))
822 ;;(2)search internal
823 (YaTeX::cite-collect-bibs-internal)))
824 ;;Now bbuf holds the list of bibitem
825 (set-buffer bbuf)
826 (YaTeX::ref argp "\\\\\\(bibitem\\)\\(\\[.*\\]\\)?" "cite"))))
828 (t nil)))
830 (and YaTeX-use-AMS-LaTeX (fset 'YaTeX::eqref 'YaTeX::ref))
832 (defun YaTeX-yatex-buffer-list ()
833 (save-excursion
834 (delq nil (mapcar (function (lambda (buf)
835 (set-buffer buf)
836 (if (eq major-mode 'yatex-mode) buf)))
837 (buffer-list)))))
839 (defun YaTeX-select-other-yatex-buffer ()
840 "Select buffer from all yatex-mode's buffers interactivelly."
841 (interactive)
842 (let ((lbuf "*YaTeX mode buffers*") (blist (YaTeX-yatex-buffer-list))
843 (lnum -1) buf rv
844 (ff "**find-file**"))
845 (YaTeX-showup-buffer
846 lbuf (function (lambda (x) 1))) ;;Select next window surely.
847 (save-excursion
848 (set-buffer (get-buffer lbuf))
849 (setq buffer-read-only nil)
850 (erase-buffer))
851 (let ((standard-output (get-buffer lbuf)))
852 (while blist
853 (princ
854 (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A)
855 (buffer-name (car blist))))
856 (setq blist (cdr blist)))
857 (princ (format "':{%s}" ff)))
858 (YaTeX-showup-buffer lbuf nil t)
859 (YaTeX::label-setup-key-map)
860 (setq buffer-read-only t)
861 (use-local-map YaTeX-label-select-map)
862 (message YaTeX-label-guide-msg)
863 (unwind-protect
864 (progn
865 (recursive-edit)
866 (set-buffer lbuf)
867 (beginning-of-line)
868 (setq rv
869 (if (re-search-forward "{\\([^\\}]+\\)}" (point-end-of-line) t)
870 (buffer-substring (match-beginning 1) (match-end 1)) nil)))
871 (kill-buffer lbuf))
872 (if (string= rv ff)
873 (progn
874 (call-interactively 'find-file)
875 (current-buffer))
876 rv)))
878 (defun YaTeX-label-other ()
879 (let ((rv (YaTeX-select-other-yatex-buffer)))
880 (cond
881 ((null rv) "")
882 (t
883 (set-buffer rv)
884 (YaTeX::ref argp labelcmd refcmd)))))
886 ;;
887 ; completion for the arguments of \newcommand
888 ;;
889 (defun YaTeX::newcommand (&optional argp)
890 (cond
891 ((= argp 1)
892 (let ((command (read-string "Define newcommand: " "\\")))
893 (put 'YaTeX::newcommand 'command (substring command 1))
894 command))
895 ((= argp 2)
896 (let ((argc
897 (string-to-int (read-string "Number of arguments(Default 0): ")))
898 (def (read-string "Definition: "))
899 (command (get 'YaTeX::newcommand 'command)))
900 ;;!!! It's illegal to insert string in the add-in function !!!
901 (if (> argc 0) (insert (format "[%d]" argc)))
902 (if (and (stringp command)
903 (string< "" command)
904 (y-or-n-p "Update dictionary?"))
905 (cond
906 ((= argc 0)
907 (YaTeX-update-table
908 (list command)
909 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table))
910 ((= argc 1)
911 (YaTeX-update-table
912 (list command)
913 'section-table 'user-section-table 'tmp-section-table))
914 (t (YaTeX-update-table
915 (list command argc)
916 'section-table 'user-section-table 'tmp-section-table))))
917 (message "")
918 def ;return command name
919 ))
920 (t "")))
922 ;;
923 ; completion for the arguments of \pagestyle
924 ;;
925 (defun YaTeX::pagestyle (&optional argp)
926 "Read the pagestyle with completion."
927 (completing-read
928 "Page style: "
929 '(("plain") ("empty") ("headings") ("myheadings") ("normal") nil)))
931 (fset 'YaTeX::thispagestyle 'YaTeX::pagestyle)
933 ;;
934 ; completion for the arguments of \pagenumbering
935 ;;
936 (defun YaTeX::pagenumbering (&optional argp)
937 "Read the numbering style."
938 (completing-read
939 "Page numbering style: "
940 '(("arabic") ("Alpha") ("alpha") ("Roman") ("roman"))))
942 ;;
943 ; Length
944 ;;
945 (defvar YaTeX:style-parameters-default
946 '(("\\arraycolsep")
947 ("\\arrayrulewidth")
948 ("\\baselineskip")
949 ("\\columnsep")
950 ("\\columnseprule")
951 ("\\doublerulesep")
952 ("\\evensidemargin")
953 ("\\footheight")
954 ("\\footskip")
955 ("\\headheight")
956 ("\\headsep")
957 ("\\itemindent")
958 ("\\itemsep")
959 ("\\labelsep")
960 ("\\labelwidth")
961 ("\\leftmargin")
962 ("\\linewidth")
963 ("\\listparindent")
964 ("\\marginparsep")
965 ("\\marginparwidth")
966 ("\\mathindent")
967 ("\\oddsidemargin")
968 ("\\parindent")
969 ("\\parsep")
970 ("\\parskip")
971 ("\\partopsep")
972 ("\\rightmargin")
973 ("\\tabcolsep")
974 ("\\textheight")
975 ("\\textwidth")
976 ("\\topmargin")
977 ("\\topsep")
978 ("\\topskip")
979 )
980 "Alist of LaTeX style parameters.")
981 (defvar YaTeX:style-parameters-private nil
982 "*User definable alist of style parameters.")
983 (defvar YaTeX:style-parameters-local nil
984 "*User definable alist of local style parameters.")
986 (defvar YaTeX:length-history nil "Holds history of length.")
987 (put 'YaTeX:length-history 'no-default t)
988 (defun YaTeX::setlength (&optional argp)
989 "YaTeX add-in function for arguments of \\setlength."
990 (cond
991 ((equal 1 argp)
992 ;;(completing-read "Length variable: " YaTeX:style-parameters nil nil "\\")
993 (YaTeX-cplread-with-learning
994 "Length variable: "
995 'YaTeX:style-parameters-default
996 'YaTeX:style-parameters-private
997 'YaTeX:style-parameters-local
998 nil nil "\\")
999 )
1000 ((equal 2 argp)
1001 (read-string-with-history "Length: " nil 'YaTeX:length-history))))
1003 (fset 'YaTeX::addtolength 'YaTeX::setlength)
1005 (defun YaTeX::settowidth (&optional argp)
1006 "YaTeX add-in function for arguments of \\settowidth."
1007 (cond
1008 ((equal 1 argp)
1009 (YaTeX-cplread-with-learning
1010 "Length variable: "
1011 'YaTeX:style-parameters-default
1012 'YaTeX:style-parameters-private
1013 'YaTeX:style-parameters-local
1014 nil nil "\\"))
1015 ((equal 2 argp)
1016 (read-string "Text: "))))
1018 (defun YaTeX::newlength (&optional argp)
1019 "YaTeX add-in function for arguments of \\newlength"
1020 (cond
1021 ((equal argp 1)
1022 (let ((length (read-string "Length variable: " "\\")))
1023 (if (string< "" length)
1024 (YaTeX-update-table
1025 (list length)
1026 'YaTeX:style-parameters-default
1027 'YaTeX:style-parameters-private
1028 'YaTeX:style-parameters-local))
1029 length))))
1031 ;; \multicolumn's arguments
1032 (defun YaTeX::multicolumn (&optional argp)
1033 "YaTeX add-in function for arguments of \\multicolumn."
1034 (cond
1035 ((equal 1 argp)
1036 (read-string "Number of columns: "))
1037 ((equal 2 argp)
1038 (let (c)
1039 (while (not (string-match
1040 (progn (message "Format(one of l,r,c): ")
1041 (setq c (char-to-string (read-char))))
1042 "lrc")))
1043 c))
1044 ((equal 3 argp)
1045 (read-string "Item: "))))
1047 (defvar YaTeX:documentstyles-default
1048 '(("article") ("jarticle") ("j-article")
1049 ("book") ("jbook") ("j-book")
1050 ("report") ("jreport") ("j-report")
1051 ("letter") ("ascjletter"))
1052 "List of LaTeX documentstyles.")
1053 (defvar YaTeX:documentstyles-private nil
1054 "*User defined list of LaTeX documentstyles.")
1055 (defvar YaTeX:documentstyles-local nil
1056 "*User defined list of local LaTeX documentstyles.")
1057 (defvar YaTeX:documentstyle-options-default
1058 '(("a4j") ("a5j") ("b4j") ("b5j")
1059 ("twocolumn") ("jtwocolumn") ("epsf") ("epsfig") ("epsbox") ("nfig"))
1060 "List of LaTeX documentstyle options.")
1061 (defvar YaTeX:documentstyle-options-private nil
1062 "*User defined list of LaTeX documentstyle options.")
1063 (defvar YaTeX:documentstyle-options-local nil
1064 "List of LaTeX local documentstyle options.")
1066 (defvar YaTeX-minibuffer-completion-map nil
1067 "Minibuffer completion key map that allows comma completion.")
1068 (if YaTeX-minibuffer-completion-map nil
1069 (setq YaTeX-minibuffer-completion-map
1070 (copy-keymap minibuffer-local-completion-map))
1071 (define-key YaTeX-minibuffer-completion-map " "
1072 'YaTeX-minibuffer-complete)
1073 (define-key YaTeX-minibuffer-completion-map "\t"
1074 'YaTeX-minibuffer-complete))
1076 (defun YaTeX:documentstyle ()
1077 (let*((delim ",")
1078 (dt (append YaTeX:documentstyle-options-local
1079 YaTeX:documentstyle-options-private
1080 YaTeX:documentstyle-options-default))
1081 (minibuffer-completion-table dt)
1082 (opt (read-from-minibuffer
1083 "Style options ([opt1,opt2,...]): "
1084 nil YaTeX-minibuffer-completion-map nil))
1085 (substr opt) o)
1086 (if (string< "" opt)
1087 (progn
1088 (while substr
1089 (setq o (substring substr 0 (string-match delim substr)))
1090 (or (assoc o dt)
1091 (YaTeX-update-table
1092 (list o)
1093 'YaTeX:documentstyle-options-default
1094 'YaTeX:documentstyle-options-private
1095 'YaTeX:documentstyle-options-local))
1096 (setq substr
1097 (if (string-match delim substr)
1098 (substring substr (1+ (string-match delim substr))))))
1099 (concat "[" opt "]"))
1100 "")))
1102 (defun YaTeX::documentstyle (&optional argp)
1103 "YaTeX add-in function for arguments of \\documentstyle."
1104 (cond
1105 ((equal argp 1)
1106 (setq env-name "document")
1107 (let ((sname
1108 (YaTeX-cplread-with-learning
1109 (format "Documentstyle (default %s): "
1110 YaTeX-default-document-style)
1111 'YaTeX:documentstyles-default
1112 'YaTeX:documentstyles-private
1113 'YaTeX:documentstyles-local)))
1114 (if (string= "" sname) (setq sname YaTeX-default-document-style))
1115 (setq YaTeX-default-document-style sname)))))
1117 ;;; -------------------- LaTeX2e stuff --------------------
1118 (defvar YaTeX:documentclass-options-default
1119 '(("a4paper") ("a5paper") ("b4paper") ("b5paper") ("10pt") ("11pt") ("12pt")
1120 ("latterpaper") ("legalpaper") ("executivepaper") ("landscape")
1121 ("oneside") ("twoside") ("draft") ("final") ("leqno") ("fleqn") ("openbib")
1122 ("tombow") ("titlepage") ("notitlepage") ("dvips")
1123 ("clock") ;for slides class only
1125 "Default options list for documentclass")
1126 (defvar YaTeX:documentclass-options-private nil
1127 "*User defined options list for documentclass")
1128 (defvar YaTeX:documentclass-options-local nil
1129 "*User defined options list for local documentclass")
1131 (defun YaTeX:documentclass ()
1132 (let*((delim ",")
1133 (dt (append YaTeX:documentclass-options-local
1134 YaTeX:documentclass-options-private
1135 YaTeX:documentclass-options-default))
1136 (minibuffer-completion-table dt)
1137 (opt (read-from-minibuffer
1138 "Documentclass options ([opt1,opt2,...]): "
1139 nil YaTeX-minibuffer-completion-map nil))
1140 (substr opt) o)
1141 (if (string< "" opt)
1142 (progn
1143 (while substr
1145 (setq o (substring substr 0 (string-match delim substr)))
1146 (or (assoc o dt)
1147 (YaTeX-update-table
1148 (list o)
1149 'YaTeX:documentclass-options-default
1150 'YaTeX:documentclass-options-private
1151 'YaTeX:documentclass-options-local))
1152 (setq substr
1153 (if (string-match delim substr)
1154 (substring substr (1+ (string-match delim substr))))))
1155 (concat "[" opt "]"))
1156 "")))
1158 (defvar YaTeX:documentclasses-default
1159 '(("article") ("jarticle") ("report") ("jreport") ("book") ("jbook")
1160 ("j-article") ("j-report") ("j-book")
1161 ("letter") ("slides") ("ltxdoc") ("ltxguide") ("ltnews") ("proc"))
1162 "Default documentclass alist")
1163 (defvar YaTeX:documentclasses-private nil
1164 "*User defined documentclass alist")
1165 (defvar YaTeX:documentclasses-local nil
1166 "*User defined local documentclass alist")
1167 (defvar YaTeX-default-documentclass (if YaTeX-japan "jarticle" "article")
1168 "*Default documentclass")
1170 (defun YaTeX::documentclass (&optional argp)
1171 (cond
1172 ((equal argp 1)
1173 (setq env-name "document")
1174 (let ((sname
1175 (YaTeX-cplread-with-learning
1176 (format "Documentclass (default %s): " YaTeX-default-documentclass)
1177 'YaTeX:documentclasses-default
1178 'YaTeX:documentclasses-private
1179 'YaTeX:documentclasses-local)))
1180 (if (string= "" sname) (setq sname YaTeX-default-documentclass))
1181 (setq YaTeX-default-documentclass sname)))))
1183 (defvar YaTeX:latex2e-named-color-alist
1184 '(("GreenYellow") ("Yellow") ("Goldenrod") ("Dandelion") ("Apricot")
1185 ("Peach") ("Melon") ("YellowOrange") ("Orange") ("BurntOrange")
1186 ("Bittersweet") ("RedOrange") ("Mahogany") ("Maroon") ("BrickRed")
1187 ("Red") ("OrangeRed") ("RubineRed") ("WildStrawberry") ("Salmon")
1188 ("CarnationPink") ("Magenta") ("VioletRed") ("Rhodamine") ("Mulberry")
1189 ("RedViolet") ("Fuchsia") ("Lavender") ("Thistle") ("Orchid")("DarkOrchid")
1190 ("Purple") ("Plum") ("Violet") ("RoyalPurple") ("BlueViolet")
1191 ("Periwinkle") ("CadetBlue") ("CornflowerBlue") ("MidnightBlue")
1192 ("NavyBlue") ("RoyalBlue") ("Blue") ("Cerulean") ("Cyan") ("ProcessBlue")
1193 ("SkyBlue") ("Turquoise") ("TealBlue") ("Aquamarine") ("BlueGreen")
1194 ("Emerald") ("JungleGreen") ("SeaGreen") ("Green") ("ForestGreen")
1195 ("PineGreen") ("LimeGreen") ("YellowGreen") ("SpringGreen") ("OliveGreen")
1196 ("RawSienna") ("Sepia") ("Brown") ("Tan") ("Gray") ("Black") ("White"))
1197 "Colors defined in $TEXMF/tex/plain/colordvi.tex")
1199 (defvar YaTeX:latex2e-basic-color-alist
1200 '(("black") ("white") ("red") ("blue") ("yellow") ("green") ("cyan")
1201 ("magenta"))
1202 "Basic colors")
1204 (defun YaTeX:textcolor ()
1205 "Add-in for \\color's option"
1206 (if (y-or-n-p "Use `named' color? ")
1207 "[named]"))
1209 (defun YaTeX::color-completing-read (prompt)
1210 (let ((completion-ignore-case t)
1211 (namedp (save-excursion
1212 (skip-chars-backward "^\n\\[\\\\")
1213 (looking-at "named"))))
1214 (completing-read
1215 prompt
1216 (if namedp
1217 YaTeX:latex2e-named-color-alist
1218 YaTeX:latex2e-basic-color-alist)
1219 nil t)))
1221 (defun YaTeX::textcolor (argp)
1222 "Add-in for \\color's argument"
1223 (cond
1224 ((= argp 1) (YaTeX::color-completing-read "Color: "))
1225 ((= argp 2) (read-string "Colored string: "))))
1227 (fset 'YaTeX:color 'YaTeX:textcolor)
1228 (fset 'YaTeX::color 'YaTeX::textcolor)
1229 (fset 'YaTeX:colorbox 'YaTeX:textcolor)
1230 (fset 'YaTeX::colorbox 'YaTeX::textcolor)
1231 (fset 'YaTeX:fcolorbox 'YaTeX:textcolor)
1233 (defun YaTeX::fcolorbox (argp)
1234 (cond
1235 ((= argp 1) (YaTeX::color-completing-read "Frame color: "))
1236 ((= argp 2) (YaTeX::color-completing-read "Inner color: "))
1237 ((= argp 3) (read-string "Colored string: "))))
1239 (defun YaTeX:scalebox ()
1240 "Add-in for \\rotatebox"
1241 (let ((vmag (read-string (if YaTeX-japan "倍率: " "Magnification: ")))
1242 (hmag (read-string (if YaTeX-japan "横倍率(省略可): "
1243 "Horizontal magnification(Optional): "))))
1244 (if (and hmag (string< "" hmag))
1245 (format "{%s}[%s]" vmag hmag)
1246 (format "{%s}" vmag))))
1248 (defun YaTeX::includegraphics (argp)
1249 "Add-in for \\includegraphics"
1250 (cond
1251 ((= argp 1)
1252 (read-file-name "EPS File: " ""))))
1254 (defun YaTeX:caption ()
1255 (setq section-name "label")
1256 nil)
1258 ;;; -------------------- math-mode stuff --------------------
1259 (defun YaTeX::tilde (&optional pos)
1260 "For accent macros in mathmode"
1261 (cond
1262 ((equal pos 1)
1263 (message "Put accent on variable: ")
1264 (let ((v (char-to-string (read-char))) (case-fold-search nil))
1265 (message "")
1266 (cond
1267 ((string-match "i\\|j" v)
1268 (concat "\\" v "math"))
1269 ((string-match "[\r\n\t ]" v)
1270 "")
1271 (t v))))
1272 (nil "")))
1274 (fset 'YaTeX::hat 'YaTeX::tilde)
1275 (fset 'YaTeX::check 'YaTeX::tilde)
1276 (fset 'YaTeX::bar 'YaTeX::tilde)
1277 (fset 'YaTeX::dot 'YaTeX::tilde)
1278 (fset 'YaTeX::ddot 'YaTeX::tilde)
1279 (fset 'YaTeX::vec 'YaTeX::tilde)
1281 (defun YaTeX::widetilde (&optional pos)
1282 "For multichar accent macros in mathmode"
1283 (cond
1284 ((equal pos 1)
1285 (let ((m "Put over chars[%s ]: ") v v2)
1286 (message m " ")
1287 (setq v (char-to-string (read-char)))
1288 (message "")
1289 (if (string-match "[\r\n\t ]" v)
1290 ""
1291 (message m v)
1292 (setq v2 (char-to-string (read-char)))
1293 (message "")
1294 (if (string-match "[\r\n\t ]" v2)
1296 (concat v v2)))))
1297 (nil "")))
1299 (fset 'YaTeX::widehat 'YaTeX::widetilde)
1300 (fset 'YaTeX::overline 'YaTeX::widetilde)
1301 (fset 'YaTeX::overrightarrow 'YaTeX::widetilde)
1304 ;;;
1305 ;; Add-in functions for large-type command.
1306 ;;;
1307 (defun YaTeX:em ()
1308 (cond
1309 ((eq YaTeX-current-completion-type 'large) "\\/")
1310 (t nil)))
1311 (fset 'YaTeX:it 'YaTeX:em)
1313 ;;; -------------------- End of yatexadd --------------------
1314 (provide 'yatexadd)