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