yatex

view yatexadd.el @ 454:aaa655456752

Label completion filter by M-c, M-e, M-i, M-s, M-m
author HIROSE Yuuji <yuuji@gentei.org>
date Wed, 22 Feb 2017 08:47:39 +0859
parents 2d9589a786d1
children 7bf780961390
line source
1 ;;; yatexadd.el --- YaTeX add-in functions -*- coding: sjis -*-
2 ;;; (c)1991-2017 by HIROSE Yuuji.[yuuji@yatex.org]
3 ;;; Last modified Wed Feb 22 08:17:25 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 ()
857 ;; Sub-function of YaTeX::ref() for recursive call
858 ;; DO NOT CALL FROM OTHER FUNCTIONS but YaTeX:ref()
859 (while (YaTeX-re-search-active-forward
860 regexp ;;counter
861 percent nil t)
862 ;(goto-char (match-beginning 0))
863 (setq e0 (match-end 0))
864 (cond
865 ;;
866 ;;2005/10/21 Skip it if predicate function returns nil
867 ((and predf
868 (let ((md (match-data)))
869 (prog1
870 (condition-case nil
871 (not (funcall predf))
872 (error nil))
873 (store-match-data md)))))
874 ((YaTeX-literal-p) nil)
875 ((YaTeX-match-string 1)
876 ;;if standard counter commands found
877 (setq cmd (YaTeX-match-string 2)
878 m0 (match-beginning 0))
879 (setq match-point (match-beginning 0))
880 (or initl
881 (if (< p (point)) (setq initl lnum)))
882 (cond
883 ;; In any case, variables e0 should be set
884 ((and YaTeX-use-AMS-LaTeX
885 (string-match YaTeX::ref-nestable-counter-regexp cmd))
886 (let (label)
887 (skip-chars-forward "}")
888 (setq label (buffer-substring
889 (point) (min (+ 80 (point)) (point-max))))
890 ;; to skip (maybe)auto-generated comment
891 (skip-chars-forward " \t")
892 (if (looking-at YaTeX-comment-prefix)
893 (forward-line 1))
894 (setq e0 (point))
895 (skip-chars-forward " \t\n")
896 (if (looking-at "\\\\label{\\([^}]+\\)}")
897 (setq label (format "(labe:%s)" (YaTeX-match-string 1))
898 e0 (match-end 1)))
899 (funcall output (format "--subequation--%s" label) e0 'eqn)))
900 ((string-match mathenvs cmd) ;;if matches mathematical env
901 (skip-chars-forward "}")
902 (setq x (point)
903 envname (substring
904 cmd (match-beginning 0) (match-end 0)))
905 (save-restriction
906 (narrow-to-region
907 m0
908 (save-excursion
909 (YaTeX-re-search-active-forward
910 (setq endrx (format "%send{%s}" YaTeX-ec-regexp
911 (regexp-quote envname)))
912 percent nil t)))
913 (catch 'scan
914 (while (YaTeX-re-search-active-forward
915 (concat
916 "\\\\end{\\(" (regexp-quote envname) "\\)" ;;(1)
917 "\\|\\\\\\(notag\\)" ;;2
918 (if (string-match
919 YaTeX::ref-mathenv-exp1-regexp cmd)
920 "" "\\|\\(\\\\\\\\\\)$") ;;3
921 )
922 percent nil t)
923 (let*((quit (match-beginning 1))
924 (notag (match-beginning 2))
925 (newln (match-beginning 3))
926 (label ".......................") l2
927 (e (point)) (m0 (match-beginning 0))
928 (ln (YaTeX-string-width label)))
929 (cond
930 (notag
931 (YaTeX-re-search-active-forward
932 "\\\\\\\\" percent nil 1)
933 (setq x (point))) ;use x as \label search bound
934 ((and newln ; `\\' found
935 (not (equal (YaTeX-inner-environment)
936 envname)))
937 (YaTeX-end-of-environment)
938 (goto-char (match-end 0)))
939 (t
940 (if (YaTeX-re-search-active-backward
941 YaTeX::ref-labeling-regexp
942 percent x t)
943 ;; if \label{x} in math-expression, display it
944 ;; because formula source is hard to recognize
945 (progn
946 (goto-char (match-end 0))
947 (setq l2 (format "\"label:%s\""
948 (buffer-substring
949 (1- (point))
950 (progn (forward-sexp -1)
951 (1+ (point))))))
952 (setq label
953 (if (< (YaTeX-string-width l2) ln)
954 (concat
955 l2
956 (substring
957 label
958 0 (- ln (YaTeX-string-width l2))))
959 l2))
960 (goto-char e)))
961 (funcall output
962 (concat
963 label " "
964 (buffer-substring x m0))
965 x 'eqn)
966 (cond
967 ((YaTeX-quick-in-environment-p
968 YaTeX-math-gathering-list)
969 ;; if here is inner split/cases/gathered env.,
970 ;; counter for here is only one.
971 ;; Go out this environment and,
972 (YaTeX-end-of-environment)
973 ;; search next expression unit boundary.
974 (YaTeX-re-search-active-forward
975 (concat endrx "\\|\\\\begin{")
976 percent nil 1)
977 (end-of-line)))
978 (if quit (throw 'scan t)))))
979 (setq x (point)))))
980 (setq e0 (point)))
981 ((string-match enums cmd)
982 ;(skip-chars-forward "} \t\n")
983 (save-restriction
984 (narrow-to-region
985 (point)
986 (save-excursion
987 (YaTeX-goto-corresponding-environment nil t 'nonstop) (point)))
988 (forward-line 1)
989 (let ((b0 nil) mb0)
990 (while (not (eobp))
991 (setq x (and
992 (YaTeX-re-search-active-forward
993 (concat YaTeX-ec-regexp "item\\s ")
994 percent nil 1)
995 (match-beginning 0)))
997 (if b0 ;Inspect sentence after previous \item
998 (save-excursion
999 (save-restriction
1000 (let ((md (match-data))) ;save-match-data
1001 (unwind-protect
1002 (progn
1003 (narrow-to-region b0 (or x (point)))
1004 (goto-char (point-min))
1005 (let ((x x)) (YaTeX::ref-1))
1006 (goto-char (point-max)))
1007 (store-match-data md))))))
1008 (if x ;Output THIS \item line
1009 (funcall
1010 output
1011 (concat
1012 existlabel
1013 (buffer-substring
1014 (match-beginning 0)
1015 (if (re-search-forward itemsep nil t)
1016 (progn (goto-char (match-beginning 0))
1017 (skip-chars-backward " \t")
1018 (1- (point)))
1019 (point-end-of-line))))
1020 x 'item))
1021 (setq b0 (point))
1022 ))
1023 (setq e0 (point-max))))
1024 ((string-match "bibitem" cmd) ;maybe generated by myself
1025 (setq label "")
1026 (skip-chars-forward " \t")
1027 (if (looking-at "{") ;sure to be true!!
1028 (forward-list 1))
1029 (let ((list '(30 10 65))
1030 (delim ";") q lim len l str)
1031 (save-excursion
1032 (setq lim (if (re-search-forward itemsep nil 1)
1033 (match-beginning 0) (point))))
1034 (while list
1035 (skip-chars-forward " \t\n\\")
1036 (setq q (looking-at "[\"'{]")
1037 len (car list)
1038 str
1039 (buffer-substring
1040 (point)
1041 (progn
1042 (if q (forward-sexp 1)
1043 (search-forward delim lim 1)
1044 (forward-char -1))
1045 (point))))
1046 (if (> (setq l (YaTeX-string-width str)) len)
1047 (setq str (concat
1048 (YaTeX-truncate-string-width
1049 str (- len (if q 5 4)))
1050 "... "
1051 (if q (substring str -1)))))
1052 (if (< (setq l (YaTeX-string-width str)) len)
1053 (setq str (concat str (make-string (- len l) ? ))))
1054 (if (looking-at delim) (goto-char (match-end 0)))
1055 (setq label (concat label " " str)
1056 list (cdr list)))
1057 (funcall output label match-point 'bib)))
1058 ;;else, simple section-type counter
1059 ((= (char-after (1- (point))) ?{)
1060 (setq label (buffer-substring
1061 (match-beginning 0)
1062 (progn (forward-char -1)
1063 (forward-list 1)
1064 (point))))
1065 (funcall output label match-point
1066 (if (string-match "caption" cmd) 'cap 'sec))
1067 ;; Skip preceding label if exists
1068 (if (YaTeX::ref-getset-label (current-buffer) match-point t)
1069 (goto-char (get 'YaTeX::ref-getset-label 'foundpoint)))
1070 (if (save-excursion
1071 (skip-chars-forward "\t \n")
1072 (looking-at YaTeX::ref-labeling-regexp))
1073 (setq e0 (match-end 0))))
1074 (t
1075 (skip-chars-forward " \t")
1076 (setq label (buffer-substring
1077 (match-beginning 0)
1078 (if (re-search-forward
1079 itemsep
1080 nil t)
1081 (progn
1082 (goto-char (match-beginning 0))
1083 (skip-chars-backward " \t")
1084 (1- (point)))
1085 (point-end-of-line))))
1086 (funcall output label match-point 'misc)
1087 (if (save-excursion
1088 (skip-chars-forward "\t \n")
1089 (looking-at YaTeX::ref-labeling-regexp))
1090 (setq e0 (match-end 0)))))
1091 ) ;;put label buffer
1092 ;;
1093 ;; if user defined label found
1094 (t
1095 ;; memorize line number and label into property
1096 (goto-char (match-beginning 0))
1097 (let ((list YaTeX::ref-labeling-regexp-alist)
1098 (cache (symbol-plist 'YaTeX::ref-labeling-regexp)))
1099 (while list
1100 (if (looking-at (car (car list)))
1101 (progn
1102 (setq label (YaTeX-match-string 0))
1103 (put 'YaTeX::ref-labeling-regexp lnum
1104 (YaTeX-match-string (cdr (car list))))
1105 (funcall output label 0) ;;0 is dummy, never used
1106 (setq list nil)))
1107 (setq list (cdr list))))
1108 ))
1109 (goto-char e0)))
1111 (defun YaTeX::ref (argp &optional labelcmd refcmd predf)
1112 (setplist 'YaTeX::ref-labeling-regexp nil) ;erase memory cache
1113 (require 'yatexsec)
1114 (cond
1115 ((= argp 1)
1116 (let*((lnum 0) m0 e0 x cmd label match-point point-list boundary
1117 (buf (current-buffer))
1118 (llv YaTeX::ref-labeling-section-level)
1119 (mathenvs YaTeX::ref-mathenv-regexp) envname endrx
1120 (enums YaTeX::ref-enumerateenv-regexp)
1121 (counter
1122 (or labelcmd
1123 (concat
1124 YaTeX-ec-regexp "\\(\\("
1125 (mapconcat
1126 'concat
1127 (delq nil
1128 (mapcar
1129 (function
1130 (lambda (s)
1131 (if (>= llv (cdr s))
1132 (car s))))
1133 YaTeX-sectioning-level))
1134 "\\|")
1135 "\\|caption\\(\\[[^]]+\\]\\)?\\|footnote\\){"
1136 "\\|\\(begin{\\(" mathenvs "\\|" enums "\\)}\\)"
1137 (if YaTeX-use-AMS-LaTeX
1138 (concat
1139 "\\|\\(begin{"
1140 YaTeX::ref-nestable-counter-regexp "}\\)"))
1141 "\\)")))
1142 (regexp (concat "\\(" counter
1143 "\\)\\|\\(" YaTeX::ref-labeling-regexp "\\)"))
1144 (itemsep (concat YaTeX-ec-regexp
1145 "\\(\\(bib\\)?item\\|begin\\|end\\)"))
1146 (refcmd (or refcmd "\\(page\\)?ref"))
1147 (p (point)) initl line cf
1148 (percent (regexp-quote YaTeX-comment-prefix))
1149 (output
1150 (function
1151 (lambda (label p &optional type) ;type: 'eqn 'item 'cap 'sec 'misc
1152 (while (setq x (string-match "[\n\t]" label))
1153 (aset label x ? ))
1154 (while (setq x (string-match " +" label))
1155 (setq label (concat
1156 (substring label 0 (1+ (match-beginning 0)))
1157 (substring label (match-end 0)))))
1158 (save-excursion
1159 (set-buffer standard-output)
1160 (overlay-put
1161 (make-overlay
1162 (point)
1163 (progn
1164 (insert (format "%c: <<%s>>\n" (+ (% lnum 26) ?A) label))
1165 (point)))
1166 'type type))
1167 (setq point-list (cons p point-list))
1168 (message "Collecting labels... %d" lnum)
1169 (setq lnum (1+ lnum)))))
1170 (me (if (boundp 'me) me 'YaTeX::ref))
1172 (message "Collecting labels...")
1173 (save-window-excursion
1174 (YaTeX-showup-buffer
1175 YaTeX-label-buffer (function (lambda (x) (window-width x))))
1176 (if (fboundp 'select-frame) (setq cf (selected-frame)))
1177 (if (eq (window-buffer (minibuffer-window)) buf)
1178 (progn
1179 (other-window 1)
1180 (setq buf (current-buffer))
1181 (set-buffer buf)))
1182 (save-excursion
1183 (set-buffer (get-buffer-create YaTeX-label-buffer))
1184 (condition-case ()
1185 (if (and YaTeX-use-font-lock (fboundp 'font-lock-mode))
1186 (font-lock-mode 1))
1187 (error nil))
1188 (setq buffer-read-only nil)
1189 (erase-buffer))
1190 (save-excursion
1191 (set-buffer buf)
1192 (goto-char (point-min))
1193 (let ((standard-output (get-buffer YaTeX-label-buffer)) existlabel)
1194 (princ (format "=== LABELS in [%s] ===\n" (buffer-name buf)))
1196 (YaTeX::ref-1)
1199 (princ YaTeX-label-menu-other)
1200 (princ YaTeX-label-menu-repeat)
1201 (princ YaTeX-label-menu-any)
1202 );standard-output
1203 (goto-char p)
1204 (or initl (setq initl lnum))
1205 (message "Collecting labels...Done")
1206 (if (fboundp 'select-frame) (select-frame cf))
1207 (YaTeX-showup-buffer YaTeX-label-buffer nil t)
1208 (YaTeX::label-setup-key-map)
1209 (setq truncate-lines t)
1210 (setq buffer-read-only t)
1211 (use-local-map YaTeX-label-select-map)
1212 (message YaTeX-label-guide-msg)
1213 (goto-line (1+ initl)) ;goto recently defined label line
1214 (switch-to-buffer (current-buffer))
1215 (unwind-protect
1216 (progn
1217 (recursive-edit)
1219 (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
1220 (beginning-of-line)
1221 (setq line (1- (count-lines (point-min)(point))))
1222 (cond
1223 ((= line -1) (setq label ""))
1224 ((= line lnum) (setq label (YaTeX-label-other)))
1225 ((= line (1+ lnum))
1226 (save-excursion
1227 (switch-to-buffer buf)
1228 (goto-char p)
1229 (if (re-search-backward
1230 (concat "\\\\" refcmd "{") nil t)
1231 (setq label (YaTeX-buffer-substring
1232 (progn (goto-char (1- (match-end 0)))
1233 (1+ (point)))
1234 (progn (forward-list 1)
1235 (1- (point)))))
1236 (setq label ""))))
1237 ((>= line (+ lnum 2))
1238 (setq label (read-string (format "\\%s{???}: " refcmd))))
1239 (t ;(setq label (nth (- lnum line 1) label-list))
1240 (setq label
1241 (or (get 'YaTeX::ref-labeling-regexp line)
1242 (YaTeX::ref-getset-label
1243 buf (nth (- lnum line 1) point-list))))
1244 )))
1245 (bury-buffer YaTeX-label-buffer)))
1246 label)))))
1248 (defun YaTeX::label-rename-refs (old new &optional def ref)
1249 "Rename reference tag from OLD to NEW.
1250 Optional arguments DEF and REF specify defining command and
1251 referring command respectively.
1252 ---------------------------------------------------------
1253 CONTROL KEYS - キーの説明
1254 y Replace 置換する
1255 n Do not replace 置換しない
1256 ! Replace All w/o query 残る全部を確認なしで置換
1257 r Enter Recursive-edit 再帰編集モードへ
1258 q Quit from replacing ここまでで置換をやめる
1260 Don't forget to exit from recursive edit by typing \\[exit-recursive-edit]
1261 再帰編集に入ったら \\[exit-recursive-edit] で抜け忘れなきよう。"
1262 (save-window-excursion
1263 (catch 'exit
1264 (let*((bufs (YaTeX-yatex-buffer-list)) buf b e
1265 (oldptn (regexp-quote old))
1266 (sw (selected-window))
1267 (ptn (concat
1268 "\\(" YaTeX-refcommand-ref-regexp "\\)"
1269 "\\s *{" oldptn "}"))
1270 (repface (and (fboundp 'make-overlay)
1271 (fboundp 'internal-find-face)
1272 (if (internal-find-face 'isearch) 'isearch 'region)))
1273 ov
1274 (qmsg "Replace to `%s'? [yn!rq?]")
1275 continue ch)
1276 (while bufs
1277 (set-buffer (setq buf (car bufs)))
1278 (save-excursion
1279 (goto-char (point-min))
1280 (while (re-search-forward ptn nil t)
1281 (goto-char (match-end 1))
1282 (skip-chars-forward " \t\n{")
1283 (unwind-protect
1284 (if (and
1285 (looking-at oldptn)
1286 (setq b (match-beginning 0)
1287 e (match-end 0))
1288 (or continue
1289 (catch 'query
1290 (if repface
1291 (if ov (move-overlay ov b e)
1292 (overlay-put
1293 (setq ov (make-overlay b e))
1294 'face repface)))
1295 (switch-to-buffer buf)
1296 (while t
1297 (message qmsg new)
1298 (setq ch (read-char))
1299 (cond
1300 ((= ch ?q) (throw 'exit t))
1301 ((= ch ?r)
1302 (message
1303 "Don't forget to exit recursive-edit by `%s'"
1304 (key-description
1305 (where-is-internal
1306 'exit-recursive-edit '(keymap) t)))
1307 (sleep-for 2)
1308 (recursive-edit))
1309 ((memq ch '(?y ?\ )) (throw 'query t))
1310 ((= ch ?!) (throw 'query (setq continue t)))
1311 ((= ch ??)
1312 (describe-function
1313 'YaTeX::label-rename-refs)
1314 (select-window (get-buffer-window "*Help*"))
1315 (search-forward "----")
1316 (forward-line 1)
1317 (set-window-start (selected-window) (point))
1318 (sit-for 0)
1319 (select-window sw))
1320 ((= ch ?n) (throw 'query nil)))))))
1321 (replace-match new t))
1322 (and ov (delete-overlay ov)))))
1323 (setq bufs (cdr bufs)))))))
1325 (defun YaTeX::label (argp &optional labname refname)
1326 "Read label name and return it with copying \\ref{LABEL-NAME} to kill-ring."
1327 (cond
1328 ((= argp 1)
1329 (let*((chmode (boundp (intern-soft "old")))
1330 (dlab (if chmode old ;if called via YaTeX-change-section (tricky...)
1331 (YaTeX::ref-default-label)))
1332 (label (read-string-with-history
1333 (format "New %s name: " (or labname "label"))
1334 (cons dlab 1))))
1335 (if (string< "" label)
1336 (let ((refstr (format "\\%s{%s}" (or refname "ref") label)))
1337 (YaTeX-push-to-kill-ring refstr)
1338 (and chmode
1339 (not (equal old label))
1340 (YaTeX::label-rename-refs old label))))
1341 label))))
1344 (fset 'YaTeX::pageref 'YaTeX::ref)
1345 (fset 'YaTeX::cref 'YaTeX::ref)
1346 (defun YaTeX::tabref (argp) ; For the style file of IPSJ journal
1347 (YaTeX::ref
1348 argp nil nil
1349 (function
1350 (lambda ()
1351 (YaTeX-quick-in-environment-p "table")))))
1352 (defun YaTeX::figref (argp) ; For the style file of IPSJ journal
1353 (YaTeX::ref
1354 argp nil nil
1355 (function
1356 (lambda ()
1357 (YaTeX-quick-in-environment-p "figure")))))
1358 (defun YaTeX::eqref (argp)
1359 (YaTeX::ref
1360 argp nil nil
1361 (function
1362 (lambda ()
1363 (YaTeX-in-math-mode-p)))))
1365 (defun YaTeX::cite-collect-bibs-external (bibptn &rest files)
1366 "Collect bibentry from FILES(variable length argument) ;
1367 and print them to standard output."
1368 ;;Thanks; http://icarus.ilcs.hokudai.ac.jp/comp/biblio.html
1369 (let*((tb (get-buffer-create " *bibtmp*"))
1370 (bibitemsep "^\\s *@[A-Za-z]")
1371 (target (if (string< "" bibptn) bibptn bibitemsep))
1372 (checkrx (concat "\\(" bibptn "\\)\\|" bibitemsep))
1373 beg
1374 (searchnext
1375 (if (string< "" bibptn)
1376 (function
1377 (lambda()
1378 (setq beg (point))
1379 (and
1380 (prog1
1381 (re-search-forward target nil t)
1382 (end-of-line))
1383 (re-search-backward bibitemsep beg t))))
1384 (function
1385 (lambda()
1386 (re-search-forward target nil t)))))
1388 (save-excursion
1389 (set-buffer tb)
1390 (princ (format "%sbegin{thebibliography}\n" YaTeX-ec))
1391 (while files
1392 (erase-buffer)
1393 (cond
1394 ((file-exists-p (car files))
1395 (insert-file-contents (car files)))
1396 ((file-exists-p (concat (car files) ".bib"))
1397 (insert-file-contents (concat (car files) ".bib"))))
1398 (save-excursion
1399 (goto-char (point-min))
1400 (while (funcall searchnext)
1401 (skip-chars-forward "^{,")
1402 (setq beg (point))
1403 (if (= (char-after (point)) ?{)
1404 (princ (format "%sbibitem{%s}%s\n"
1405 YaTeX-ec
1406 (buffer-substring
1407 (1+ (point))
1408 (progn (skip-chars-forward "^,\n")
1409 (point)))
1410 (mapconcat
1411 (function
1412 (lambda (kwd)
1413 (goto-char beg)
1414 (if (re-search-forward
1415 (concat kwd "\\s *=") nil t)
1416 (buffer-substring
1417 (progn
1418 (goto-char (match-end 0))
1419 (skip-chars-forward " \t\n")
1420 (point))
1421 (progn
1422 (if (looking-at "[{\"]")
1423 (forward-sexp 1)
1424 (forward-char 1)
1425 (skip-chars-forward "^,}"))
1426 (point))))))
1427 '("author" "year" "title" )
1428 ";"))))
1429 (and (re-search-forward bibitemsep nil t)
1430 (forward-line -1))))
1431 (setq files (cdr files)))
1432 (princ (format "%sbegin{thebibliography}\n" YaTeX-ec)))))
1434 (defvar YaTeX::cite-bibitem-macro-regexp "bibitem\\|harvarditem"
1435 "*Regexp of macro name of bibitem definition")
1437 (defun YaTeX::cite-collect-bibs-internal (bibptn)
1438 "Collect bibentry in the current buffer and print them to standard output."
1439 (let ((ptn (concat YaTeX-ec-regexp
1440 "\\(" YaTeX::cite-bibitem-macro-regexp "\\)\\b"))
1441 (lim (concat YaTeX-ec-regexp
1442 "\\(" YaTeX::cite-bibitem-macro-regexp "\\b\\)"
1443 "\\|\\(end{\\)"))
1444 (pcnt (regexp-quote YaTeX-comment-prefix)))
1445 ;; Using bibptn not yet implemented.
1446 ;; Do you need it?? 2005/11/22
1447 (save-excursion
1448 (while (YaTeX-re-search-active-forward ptn pcnt nil t)
1449 (skip-chars-forward "^{\n")
1450 (or (eolp)
1451 (princ (format "%sbibitem%s %s\n"
1452 YaTeX-ec
1453 (buffer-substring
1454 (point)
1455 (progn (forward-sexp 1) (point)))
1456 (buffer-substring
1457 (progn (skip-chars-forward "\n \t") (point))
1458 (save-excursion
1459 (if (YaTeX-re-search-active-forward
1460 lim pcnt nil t)
1461 (progn
1462 (goto-char (match-beginning 0))
1463 (skip-chars-backward "\n \t")
1464 (point))
1465 (point-end-of-line)))))))))))
1467 (defun YaTeX::cite (argp &rest dummy)
1468 (cond
1469 ((eq argp 1)
1470 (let* ((cb (current-buffer))
1471 (f (file-name-nondirectory buffer-file-name))
1472 (d default-directory)
1473 (hilit-auto-highlight nil)
1474 (pcnt (regexp-quote YaTeX-comment-prefix))
1475 (bibrx (concat YaTeX-ec-regexp "bibliography{\\([^}]+\\)}"))
1476 (bibptn (YaTeX-read-string-or-skip "Pattern: "))
1477 (bbuf (get-buffer-create " *bibitems*"))
1478 (standard-output bbuf)
1479 (me 'YaTeX::cite) ;shuld set this for using YaTeX::ref
1480 bibs files)
1481 (set-buffer bbuf)(erase-buffer)(set-buffer cb)
1482 (save-excursion
1483 (goto-char (point-min))
1484 ;;(1)search external bibdata
1485 (while (YaTeX-re-search-active-forward bibrx pcnt nil t)
1486 (apply 'YaTeX::cite-collect-bibs-external
1487 bibptn
1488 (YaTeX-split-string
1489 (YaTeX-match-string 1) ",")))
1490 ;;(2)search direct \bibitem usage
1491 (YaTeX::cite-collect-bibs-internal bibptn)
1492 (if (progn
1493 (YaTeX-visit-main t)
1494 (not (eq (current-buffer) cb)))
1495 (save-excursion
1496 (goto-char (point-min))
1497 ;;(1)search external bibdata
1498 (while (YaTeX-re-search-active-forward bibrx pcnt nil t)
1499 (apply 'YaTeX::cite-collect-bibs-external
1500 bibptn
1501 (YaTeX-split-string
1502 (YaTeX-match-string 1) ",")))
1503 ;;(2)search internal
1504 (YaTeX::cite-collect-bibs-internal bibptn)))
1505 ;;Now bbuf holds the list of bibitem
1506 (set-buffer bbuf)
1507 ;;;(switch-to-buffer bbuf)
1508 (if (fboundp 'font-lock-fontify-buffer) (font-lock-fontify-buffer))
1509 (YaTeX::ref
1510 argp
1511 (concat "\\\\\\("
1512 YaTeX::cite-bibitem-macro-regexp
1513 "\\)\\(\\[.*\\]\\)?")
1514 "cite"))))
1516 (t nil)))
1518 (defun YaTeX::bibitem (argp)
1519 "Add-in function to insert argument of \\bibitem."
1520 (YaTeX::label argp "label" "cite"))
1522 ;;; for Harvard citation style
1523 (fset 'YaTeX::citeasnoun 'YaTeX::cite)
1524 (fset 'YaTeX::possessivecite 'YaTeX::cite)
1525 (fset 'YaTeX::citeyear 'YaTeX::cite)
1526 (fset 'YaTeX::citename 'YaTeX::cite)
1527 (fset 'YaTeX::citep 'YaTeX::cite)
1528 (fset 'YaTeX::citet 'YaTeX::cite)
1530 (defun YaTeX-select-other-yatex-buffer ()
1531 "Select buffer from all yatex-mode's buffers interactivelly."
1532 (interactive)
1533 (let ((lbuf "*YaTeX mode buffers*") (blist (YaTeX-yatex-buffer-list))
1534 (lnum -1) buf rv
1535 (ff "**find-file**"))
1536 (YaTeX-showup-buffer
1537 lbuf (function (lambda (x) 1))) ;;Select next window surely.
1538 (save-excursion
1539 (set-buffer (get-buffer lbuf))
1540 (setq buffer-read-only nil)
1541 (erase-buffer))
1542 (let ((standard-output (get-buffer lbuf)))
1543 (while blist
1544 (princ
1545 (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A)
1546 (buffer-name (car blist))))
1547 (setq blist (cdr blist)))
1548 (princ (format "':{%s}" ff)))
1549 (YaTeX-showup-buffer lbuf nil t)
1550 (YaTeX::label-setup-key-map)
1551 (setq buffer-read-only t)
1552 (use-local-map YaTeX-label-select-map)
1553 (message YaTeX-label-guide-msg)
1554 (unwind-protect
1555 (progn
1556 (recursive-edit)
1557 (set-buffer lbuf)
1558 (beginning-of-line)
1559 (setq rv
1560 (if (re-search-forward "{\\([^\\}]+\\)}" (point-end-of-line) t)
1561 (buffer-substring (match-beginning 1) (match-end 1)) nil)))
1562 (kill-buffer lbuf))
1563 (if (string= rv ff)
1564 (progn
1565 (call-interactively 'find-file)
1566 (current-buffer))
1567 rv)))
1569 (defun YaTeX-label-other ()
1570 (let ((rv (YaTeX-select-other-yatex-buffer)))
1571 (cond
1572 ((null rv) "")
1573 (t
1574 (set-buffer rv)
1575 (funcall me argp labelcmd refcmd)))))
1577 ;;
1578 ; completion for the arguments of \newcommand
1579 ;;
1580 (defun YaTeX::newcommand (&optional argp)
1581 (cond
1582 ((= argp 1)
1583 (let ((command (read-string-with-history "Define newcommand: " "\\")))
1584 (put 'YaTeX::newcommand 'command (substring command 1))
1585 command))
1586 ((= argp 2)
1587 (let ((argc
1588 (YaTeX-str2int
1589 (read-string-with-history "Number of arguments(Default 0): ")))
1590 (def (YaTeX-read-string-or-skip "Definition: "))
1591 (command (get 'YaTeX::newcommand 'command)))
1592 ;;!!! It's illegal to insert string in the add-in function !!!
1593 (if (> argc 0) (insert (format "[%d]" argc)))
1594 (if (and (stringp command)
1595 (string< "" command)
1596 (y-or-n-p "Update dictionary?"))
1597 (cond
1598 ((= argc 0)
1599 (YaTeX-update-table
1600 (list command)
1601 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table))
1602 ((= argc 1)
1603 (YaTeX-update-table
1604 (list command)
1605 'section-table 'user-section-table 'tmp-section-table))
1606 (t (YaTeX-update-table
1607 (list command argc)
1608 'section-table 'user-section-table 'tmp-section-table))))
1609 (message "")
1610 def ;return command name
1611 ))
1612 (t "")))
1614 (defun YaTeX::newcounter (&optional argp)
1615 (cond
1616 ((= argp 1)
1617 (read-string-with-history "New counter name: "))
1618 (t "")))
1620 ;;
1621 ; completion for the arguments of \pagestyle
1622 ;;
1623 (defun YaTeX::pagestyle (&optional argp)
1624 "Read the pagestyle with completion."
1625 (completing-read
1626 "Page style: "
1627 '(("plain") ("empty") ("headings") ("myheadings") ("normal") nil)))
1629 (fset 'YaTeX::thispagestyle 'YaTeX::pagestyle)
1631 ;;
1632 ; completion for the arguments of \pagenumbering
1633 ;;
1634 (defun YaTeX::pagenumbering (&optional argp)
1635 "Read the numbering style."
1636 (completing-read
1637 "Page numbering style: "
1638 '(("arabic") ("Alpha") ("alpha") ("Roman") ("roman"))))
1640 ;;
1641 ; Length
1642 ;;
1643 (defvar YaTeX:style-parameters-default
1644 '(("\\arraycolsep")
1645 ("\\arrayrulewidth")
1646 ("\\baselineskip")
1647 ("\\columnsep")
1648 ("\\columnseprule")
1649 ("\\doublerulesep")
1650 ("\\evensidemargin")
1651 ("\\footheight")
1652 ("\\footskip")
1653 ("\\headheight")
1654 ("\\headsep")
1655 ("\\itemindent")
1656 ("\\itemsep")
1657 ("\\labelsep")
1658 ("\\labelwidth")
1659 ("\\leftmargin")
1660 ("\\linewidth")
1661 ("\\listparindent")
1662 ("\\marginparsep")
1663 ("\\marginparwidth")
1664 ("\\mathindent")
1665 ("\\oddsidemargin")
1666 ("\\parindent")
1667 ("\\parsep")
1668 ("\\parskip")
1669 ("\\partopsep")
1670 ("\\rightmargin")
1671 ("\\tabcolsep")
1672 ("\\textheight")
1673 ("\\textwidth")
1674 ("\\columnwidth")
1675 ("\\topmargin")
1676 ("\\topsep")
1677 ("\\topskip")
1679 "Alist of LaTeX style parameters.")
1680 (defvar YaTeX:style-parameters-private nil
1681 "*User definable alist of style parameters.")
1682 (defvar YaTeX:style-parameters-local nil
1683 "*User definable alist of local style parameters.")
1685 (defvar YaTeX:length-history nil "Holds history of length.")
1686 (put 'YaTeX:length-history 'no-default t)
1687 (defun YaTeX::setlength (&optional argp)
1688 "YaTeX add-in function for arguments of \\setlength."
1689 (cond
1690 ((equal 1 argp)
1691 ;;(completing-read "Length variable: " YaTeX:style-parameters nil nil "\\")
1692 (YaTeX-cplread-with-learning
1693 "Length variable: "
1694 'YaTeX:style-parameters-default
1695 'YaTeX:style-parameters-private
1696 'YaTeX:style-parameters-local
1697 nil nil "\\")
1699 ((equal 2 argp)
1700 (YaTeX-read-string-or-skip "Length: " nil 'YaTeX:length-history))))
1702 (fset 'YaTeX::addtolength 'YaTeX::setlength)
1704 (defun YaTeX::settowidth (&optional argp)
1705 "YaTeX add-in function for arguments of \\settowidth."
1706 (cond
1707 ((equal 1 argp)
1708 (YaTeX-cplread-with-learning
1709 "Length variable: "
1710 'YaTeX:style-parameters-default
1711 'YaTeX:style-parameters-private
1712 'YaTeX:style-parameters-local
1713 nil nil "\\"))
1714 ((equal 2 argp)
1715 (YaTeX-read-string-or-skip "Text: "))))
1717 (defun YaTeX::newlength (&optional argp)
1718 "YaTeX add-in function for arguments of \\newlength"
1719 (cond
1720 ((equal argp 1)
1721 (let ((length (read-string-with-history "Length variable: " "\\")))
1722 (if (string< "" length)
1723 (YaTeX-update-table
1724 (list length)
1725 'YaTeX:style-parameters-default
1726 'YaTeX:style-parameters-private
1727 'YaTeX:style-parameters-local))
1728 length))))
1730 ;; \multicolumn's arguments
1731 (defun YaTeX::multicolumn (&optional argp)
1732 "YaTeX add-in function for arguments of \\multicolumn."
1733 (cond
1734 ((equal 1 argp)
1735 (read-string-with-history "Number of columns: "))
1736 ((equal 2 argp)
1737 (YaTeX:read-oneof "|lrc" nil t))
1738 ((equal 3 argp)
1739 (YaTeX-read-string-or-skip "Item: "))))
1741 (defvar YaTeX:documentstyles-default
1742 '(("article") ("jarticle") ("j-article")
1743 ("book") ("jbook") ("j-book")
1744 ("report") ("jreport") ("j-report")
1745 ("letter") ("ascjletter"))
1746 "List of LaTeX documentstyles.")
1747 (defvar YaTeX:documentstyles-private nil
1748 "*User defined list of LaTeX documentstyles.")
1749 (defvar YaTeX:documentstyles-local nil
1750 "*User defined list of local LaTeX documentstyles.")
1751 (defvar YaTeX:documentstyle-options-default
1752 '(("a4j") ("a5j") ("b4j") ("b5j")
1753 ("twocolumn") ("jtwocolumn") ("epsf") ("epsfig") ("epsbox") ("nfig"))
1754 "List of LaTeX documentstyle options.")
1755 (defvar YaTeX:documentstyle-options-private nil
1756 "*User defined list of LaTeX documentstyle options.")
1757 (defvar YaTeX:documentstyle-options-local nil
1758 "List of LaTeX local documentstyle options.")
1760 (defun YaTeX:documentstyle ()
1761 (let*((delim ",")
1762 (dt (append YaTeX:documentstyle-options-local
1763 YaTeX:documentstyle-options-private
1764 YaTeX:documentstyle-options-default))
1765 (minibuffer-completion-table dt)
1766 (opt (read-from-minibuffer
1767 "Style options ([opt1,opt2,...]): "
1768 nil YaTeX-minibuffer-completion-map nil))
1769 (substr opt) o)
1770 (if (string< "" opt)
1771 (progn
1772 (while substr
1773 (setq o (substring substr 0 (string-match delim substr)))
1774 (or (assoc o dt)
1775 (YaTeX-update-table
1776 (list o)
1777 'YaTeX:documentstyle-options-default
1778 'YaTeX:documentstyle-options-private
1779 'YaTeX:documentstyle-options-local))
1780 (setq substr
1781 (if (string-match delim substr)
1782 (substring substr (1+ (string-match delim substr))))))
1783 (concat "[" opt "]"))
1784 "")))
1786 (defun YaTeX::documentstyle (&optional argp)
1787 "YaTeX add-in function for arguments of \\documentstyle."
1788 (cond
1789 ((equal argp 1)
1790 (setq YaTeX-env-name "document")
1791 (let ((sname
1792 (YaTeX-cplread-with-learning
1793 (format "Documentstyle (default %s): "
1794 YaTeX-default-document-style)
1795 'YaTeX:documentstyles-default
1796 'YaTeX:documentstyles-private
1797 'YaTeX:documentstyles-local)))
1798 (if (string= "" sname) (setq sname YaTeX-default-document-style))
1799 (setq YaTeX-default-document-style sname)))))
1801 (defun YaTeX::include (argp &optional prompt)
1802 "Read file name setting default directory to that of main file."
1803 (cond
1804 ((= argp 1)
1805 (save-excursion
1806 (YaTeX-visit-main t)
1807 (let*((insert-default-directory)
1808 (default (and (boundp 'old) (stringp old) old))
1809 (file (read-file-name (or prompt "Input file: ") ""
1810 default nil default)))
1811 (setq file (substring file 0 (string-match "\\.tex$" file))))))))
1813 (fset 'YaTeX::input 'YaTeX::include)
1816 ;;; -------------------- LaTeX2e stuff --------------------
1817 (defvar YaTeX:documentclass-options-default
1818 '(("a4paper") ("a5paper") ("b4paper") ("b5paper") ("10pt") ("11pt") ("12pt")
1819 ("latterpaper") ("legalpaper") ("executivepaper") ("landscape")
1820 ("oneside") ("twoside") ("draft") ("final") ("leqno") ("fleqn") ("openbib")
1821 ("tombow") ("titlepage") ("notitlepage") ("dvips")
1822 ("mingoth") ;for jsarticle
1823 ("clock") ;for slides class only
1825 "Default options list for documentclass")
1826 (defvar YaTeX:documentclass-options-private nil
1827 "*User defined options list for documentclass")
1828 (defvar YaTeX:documentclass-options-local nil
1829 "*User defined options list for local documentclass")
1831 (defun YaTeX:documentclass ()
1832 (let*((delim ",")
1833 (dt (append YaTeX:documentclass-options-local
1834 YaTeX:documentclass-options-private
1835 YaTeX:documentclass-options-default))
1836 (minibuffer-completion-table dt)
1837 (opt (read-from-minibuffer
1838 "Documentclass options ([opt1,opt2,...]): "
1839 nil YaTeX-minibuffer-completion-map nil))
1840 (substr opt) o)
1841 (if (string< "" opt)
1842 (progn
1843 (while substr
1845 (setq o (substring substr 0 (string-match delim substr)))
1846 (or (assoc o dt)
1847 (YaTeX-update-table
1848 (list o)
1849 'YaTeX:documentclass-options-default
1850 'YaTeX:documentclass-options-private
1851 'YaTeX:documentclass-options-local))
1852 (setq substr
1853 (if (string-match delim substr)
1854 (substring substr (1+ (string-match delim substr))))))
1855 (concat "[" opt "]"))
1856 "")))
1858 (defvar YaTeX:documentclasses-default
1859 '(("article") ("jarticle") ("report") ("jreport") ("book") ("jbook")
1860 ("jsarticle") ("jsbook")
1861 ("j-article") ("j-report") ("j-book")
1862 ("letter") ("slides") ("ltxdoc") ("ltxguide") ("ltnews") ("proc"))
1863 "Default documentclass alist")
1864 (defvar YaTeX:documentclasses-private nil
1865 "*User defined documentclass alist")
1866 (defvar YaTeX:documentclasses-local nil
1867 "*User defined local documentclass alist")
1868 (defvar YaTeX-default-documentclass (if YaTeX-japan "jarticle" "article")
1869 "*Default documentclass")
1871 (defun YaTeX::documentclass (&optional argp)
1872 (cond
1873 ((equal argp 1)
1874 (setq YaTeX-env-name "document")
1875 (let ((sname
1876 (YaTeX-cplread-with-learning
1877 (format "Documentclass (default %s): " YaTeX-default-documentclass)
1878 'YaTeX:documentclasses-default
1879 'YaTeX:documentclasses-private
1880 'YaTeX:documentclasses-local)))
1881 (if (string= "" sname) (setq sname YaTeX-default-documentclass))
1882 (setq YaTeX-section-name "title"
1883 YaTeX-default-documentclass sname)))))
1885 (defun YaTeX::title (&optional argp)
1886 (prog1 (YaTeX-read-string-or-skip "Document Title: ")
1887 (setq YaTeX-section-name "author"
1888 YaTeX-single-command "maketitle")))
1890 (defun YaTeX::author (&optional argp)
1891 (prog1 (YaTeX-read-string-or-skip "Document Author: ")
1892 (setq YaTeX-section-name "date"
1893 YaTeX-single-command "maketitle")))
1895 (defun YaTeX:document ()
1896 (setq YaTeX-section-name
1897 (if (string-match "book\\|bk" YaTeX-default-documentclass)
1898 "chapter"
1899 "section"))
1900 "")
1903 (defvar YaTeX:latex2e-named-color-alist
1904 '(("GreenYellow") ("Yellow") ("Goldenrod") ("Dandelion") ("Apricot")
1905 ("Peach") ("Melon") ("YellowOrange") ("Orange") ("BurntOrange")
1906 ("Bittersweet") ("RedOrange") ("Mahogany") ("Maroon") ("BrickRed")
1907 ("Red") ("OrangeRed") ("RubineRed") ("WildStrawberry") ("Salmon")
1908 ("CarnationPink") ("Magenta") ("VioletRed") ("Rhodamine") ("Mulberry")
1909 ("RedViolet") ("Fuchsia") ("Lavender") ("Thistle") ("Orchid")("DarkOrchid")
1910 ("Purple") ("Plum") ("Violet") ("RoyalPurple") ("BlueViolet")
1911 ("Periwinkle") ("CadetBlue") ("CornflowerBlue") ("MidnightBlue")
1912 ("NavyBlue") ("RoyalBlue") ("Blue") ("Cerulean") ("Cyan") ("ProcessBlue")
1913 ("SkyBlue") ("Turquoise") ("TealBlue") ("Aquamarine") ("BlueGreen")
1914 ("Emerald") ("JungleGreen") ("SeaGreen") ("Green") ("ForestGreen")
1915 ("PineGreen") ("LimeGreen") ("YellowGreen") ("SpringGreen") ("OliveGreen")
1916 ("RawSienna") ("Sepia") ("Brown") ("Tan") ("Gray") ("Black") ("White"))
1917 "Colors defined in $TEXMF/tex/plain/dvips/colordvi.tex")
1919 (defvar YaTeX:latex2e-basic-color-alist
1920 '(("black") ("white") ("red") ("blue") ("yellow") ("green") ("cyan")
1921 ("magenta"))
1922 "Basic colors")
1924 (defun YaTeX:textcolor ()
1925 "Add-in for \\color's option"
1926 (if (y-or-n-p "Use `named' color? ")
1927 "[named]"))
1929 (defun YaTeX::color-completing-read (prompt)
1930 (let ((completion-ignore-case t)
1931 (namedp (save-excursion
1932 (skip-chars-backward "^\n\\[\\\\")
1933 (looking-at "named"))))
1934 (completing-read
1935 prompt
1936 (if namedp
1937 YaTeX:latex2e-named-color-alist
1938 YaTeX:latex2e-basic-color-alist)
1939 nil t)))
1941 (defun YaTeX::textcolor (argp)
1942 "Add-in for \\color's argument"
1943 (cond
1944 ((= argp 1) (YaTeX::color-completing-read "Color: "))
1945 ((= argp 2) (YaTeX-read-string-or-skip "Colored string: "))))
1947 (fset 'YaTeX:color 'YaTeX:textcolor)
1948 (fset 'YaTeX::color 'YaTeX::textcolor)
1949 (fset 'YaTeX:colorbox 'YaTeX:textcolor)
1950 (fset 'YaTeX::colorbox 'YaTeX::textcolor)
1951 (fset 'YaTeX:fcolorbox 'YaTeX:textcolor)
1952 (fset 'YaTeX:pagecolor 'YaTeX:textcolor)
1953 (fset 'YaTeX::pagecolor 'YaTeX::textcolor)
1955 (defun YaTeX::fcolorbox (argp)
1956 (cond
1957 ((= argp 1) (YaTeX::color-completing-read "Frame color: "))
1958 ((= argp 2) (YaTeX::color-completing-read "Inner color: "))
1959 ((= argp 3) (YaTeX-read-string-or-skip "Colored string: "))))
1961 (defun YaTeX:scalebox ()
1962 "Add-in for \\scalebox"
1963 (let ((vmag (YaTeX-read-string-or-skip (if YaTeX-japan "倍率(負で反転): "
1964 "Magnification(Negative for flipped): ")))
1965 (hmag (YaTeX-read-string-or-skip (if YaTeX-japan "縦倍率(省略可): "
1966 "Vertical magnification(Optional): "))))
1967 (if (and hmag (string< "" hmag))
1968 (format "{%s}[%s]" vmag hmag)
1969 (format "{%s}" vmag))))
1971 (defun YaTeX:rotatebox ()
1972 "Optional argument add-in for \\rotatebox"
1973 (message "Rotate origin? (N)one (O)rigin (X)-Y: ")
1974 (let ((c (read-char)) r (defx "x=mm") x (defy "y=mm") y something)
1975 (cond
1976 ((memq c '(?O ?o))
1977 (if (string< "" (setq r (YaTeX:read-oneof "htbpB")))
1978 (concat "[origin=" r "]")))
1979 ((memq c '(?X ?x ?Y ?y))
1980 (setq r (read-string-with-history
1981 "" (if YaTeX-emacs-19 (cons defx 3) defx))
1982 x (if (string< "x=" r) r)
1983 r (read-string-with-history
1984 "" (if YaTeX-emacs-19 (cons defy 3) defy))
1985 y (if (string< "y=" r) r)
1986 something (or x y))
1987 (format "%s%s%s%s%s"
1988 (if something "[" "")
1989 (if x x "")
1990 (if (and x y) "," "")
1991 (if y y "")
1992 (if something "]" ""))))))
1994 (defun YaTeX::rotatebox (argp)
1995 "Argument add-in for \\rotatebox"
1996 (cond
1997 ((= argp 1)
1998 (read-string-with-history (if YaTeX-japan "回転角(度; 左回り): "
1999 "Angle in degree(unclockwise): ")))
2000 ((= argp 2)
2001 (YaTeX-read-string-or-skip (if YaTeX-japan "テキスト: " "Text: ")))))
2003 (defun YaTeX:includegraphics ()
2004 "Add-in for \\includegraphics's option"
2005 (let (width height (scale "") angle str)
2006 (setq width (YaTeX:read-length "Width: ")
2007 height (YaTeX:read-length "Height: "))
2008 (or (string< "" width) (string< "" height)
2009 (setq scale (YaTeX-read-string-or-skip "Scale: ")))
2010 (setq angle (YaTeX-read-string-or-skip "Angle(0-359): "))
2011 (setq str
2012 (mapconcat
2013 'concat
2014 (delq nil
2015 (mapcar (function (lambda (s)
2016 (and (stringp (symbol-value s))
2017 (string< "" (symbol-value s))
2018 (format "%s=%s" s (symbol-value s)))))
2019 '(width height scale angle)))
2020 ","))
2021 (if (string= "" str) ""
2022 (concat "[" str "]"))))
2024 (defvar YaTeX::get-boundingbox-cmd YaTeX-cmd-gs
2025 "Command to get bounding box from PDF files.
2026 Possible values are `gs' and `extractbb'.")
2028 (defun YaTeX::get-boundingbox (file)
2029 "Return the bound box as a string
2030 This function relies on gs(ghostscript) command installed."
2031 (let ((str (YaTeX-command-to-string
2032 (format
2033 (cond
2034 ((string-match "extractbb" YaTeX::get-boundingbox-cmd)
2035 "%s -O %s")
2036 ((string-match "gs" YaTeX::get-boundingbox-cmd)
2037 "%s -sDEVICE=bbox -dBATCH -dNOPAUSE %s")
2038 (t "echo %s %s"))
2039 YaTeX::get-boundingbox-cmd file))))
2040 (if (string-match
2041 "%%BoundingBox:\\s \\([0-9]+\\s [0-9]+\\s [0-9]+\\s [0-9]+\\)"
2042 str)
2043 (substring str (match-beginning 1) (match-end 1)))))
2045 (defun YaTeX::includegraphics (argp &optional file doclip)
2046 "Add-in for \\includegraphics"
2047 (let*((imgfile (or file (YaTeX::include argp "Image File: ")))
2048 (imgfilepath
2049 (save-excursion
2050 (YaTeX-visit-main t)
2051 (expand-file-name imgfile default-directory)))
2052 (case-fold-search t) info bb noupdate needclose c)
2053 (and (string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\|pdf\\)$" imgfile)
2054 (file-exists-p imgfilepath)
2055 (or (fboundp 'yahtml-get-image-info)
2056 (progn
2057 (load "yahtml" t) (featurep 'yahtml))) ;(require 'yahtml nil t)
2058 (if (string-match "\\.pdf" imgfile)
2059 (and
2060 (setq info (YaTeX::get-boundingbox imgfilepath))
2061 (stringp info)
2062 (string< "" info)
2063 (setq bb (format "bb=%s" info)))
2064 (setq info (yahtml-get-image-info imgfilepath))
2065 (car info) ;if has width value
2066 (car (cdr info)) ;if has height value
2067 (setq bb (format "bb=%d %d %d %d" 0 0 (car info) (car (cdr info)))))
2068 (save-excursion
2069 (cond
2070 ((and (save-excursion
2071 (YaTeX-re-search-active-backward
2072 "\\\\\\(includegraphics\\)\\|\\(bb=[-+ \t0-9]+\\)"
2073 YaTeX-comment-prefix nil t))
2074 (match-beginning 2)
2075 (not (setq noupdate (equal (YaTeX-match-string 2) bb)))
2076 (y-or-n-p (format "Update `bb=' line to `%s'?: " bb)))
2077 (message "")
2078 (replace-match bb))
2079 (noupdate nil)
2080 ((and (match-beginning 1)
2081 (or doclip
2082 (prog2
2083 (message "Insert `%s'? Y)es N)o C)yes+`clip': " bb)
2084 (memq (setq c (read-char)) '(?y ?Y ?\ ?c ?C))
2085 (setq doclip (memq c '(?c ?C)))
2086 (message ""))))
2087 (goto-char (match-end 0))
2088 (message "`bb=' %s"
2089 (format
2090 (if YaTeX-japan
2091 "の値はファイル名の上で `%s' を押してファイル名を再入力して更新できます。"
2092 "values can be update by typing `%s' on file name.")
2093 (key-description
2094 (car (where-is-internal 'YaTeX-change-*)))))
2095 (if (looking-at "\\[") (forward-char 1)
2096 (insert-before-markers "[")
2097 (setq needclose t))
2098 (insert-before-markers bb)
2099 (if doclip (insert-before-markers ",clip"))
2100 (if needclose (insert-before-markers "]")
2101 (or (looking-at "\\]") (insert-before-markers ","))))
2102 (t (YaTeX-push-to-kill-ring bb)))))
2103 (setq YaTeX-section-name "caption")
2104 imgfile))
2106 (defun YaTeX::verbfile (argp)
2107 "Add-in for \\verbfile"
2108 (YaTeX::include argp "Virbatim File: "))
2110 (defun YaTeX:caption ()
2111 (setq YaTeX-section-name "label")
2112 nil)
2115 (defvar YaTeX::usepackage-alist-default
2116 '(("version") ("plext") ("url") ("fancybox") ("pifont") ("longtable")
2117 ("ascmac") ("bm") ("graphics") ("graphicx") ("alltt") ("misc") ("eclbkbox")
2118 ("amsmath") ("amssymb") ("xymtex") ("chemist")
2119 ("a4j") ("array") ("epsf") ("color") ("xcolor") ("epsfig") ("floatfig")
2120 ("landscape") ("path") ("supertabular") ("twocolumn")
2121 ("latexsym") ("times") ("makeidx") ("geometry") ("type1cm"))
2122 "Default completion table for arguments of \\usepackage")
2124 (defvar YaTeX::usepackage-alist-private nil
2125 "*Private completion list of the argument for usepackage")
2127 (defvar YaTeX::usepackage-alist-local nil
2128 "Directory local completion list of the argument for usepackage")
2130 (defun YaTeX::usepackage (&optional argp)
2131 (cond
2132 ((equal argp 1)
2133 (setq YaTeX-env-name "document")
2134 (let ((minibuffer-local-completion-map YaTeX-minibuffer-completion-map)
2135 (delim ","))
2136 (YaTeX-cplread-with-learning
2137 (if YaTeX-japan "Use package(カンマで区切ってOK): "
2138 "Use package(delimitable by comma): ")
2139 'YaTeX::usepackage-alist-default
2140 'YaTeX::usepackage-alist-private
2141 'YaTeX::usepackage-alist-local)))))
2143 (defun YaTeX::mask (argp)
2144 (cond
2145 ((equal argp 1)
2146 (YaTeX-read-string-or-skip "String: "))
2147 ((equal argp 2)
2148 (let (c)
2149 (while (not (memq c '(?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K)))
2150 (message "Mask type(A..K): ")
2151 (setq c (upcase (read-char))))
2152 (format "%c" c)))))
2154 (defun YaTeX::maskbox (argp)
2155 (cond
2156 ((equal argp 1)
2157 (YaTeX:read-length "Width: "))
2158 ((equal argp 2)
2159 (YaTeX:read-length "Height: "))
2160 ((equal argp 3)
2161 (let (c)
2162 (while (not (memq c '(?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K)))
2163 (message "Mask type(A..K): ")
2164 (setq c (upcase (read-char))))
2165 (format "%c" c)))
2166 ((equal argp 4)
2167 (YaTeX:read-oneof "lcr" 'quick))
2168 ((equal argp 5)
2169 (YaTeX-read-string-or-skip "String: "))))
2171 (defun YaTeX::textcircled (argp)
2172 (cond
2173 ((equal argp 1)
2174 (let ((char (read-string-with-history "Circled char: "))
2175 (left "") (right "") c)
2176 (setq c (read-char
2177 "Enclose also with (s)mall (t)iny s(C)riptsize (N)one:"))
2178 (cond
2179 ((memq c '(?s ?S)) (setq left "{\\small " right "}"))
2180 ((memq c '(?t ?T)) (setq left "{\\tiny " right "}"))
2181 ((memq c '(?c ?C)) (setq left "{\\scriptsize " right "}")))
2182 (format "%s%s%s" left char right)))))
2184 ;;; -------------------- beamer stuff --------------------
2185 (defvar YaTeX:frame-option-alist-default
2186 '(("plain") ("containsverbatim") ("shrink") ("squeeze")
2187 ("allowframebreaks") ("label=")))
2188 (defvar YaTeX:frame-option-alist-private nil
2189 "*Alist for completion list of the argument for `frame' environemnt")
2190 (defvar YaTeX:frame-option-alist
2191 (append YaTeX:frame-option-alist-private YaTeX:frame-option-alist-default))
2193 (defun YaTeX:frame ()
2194 (let*((minibuffer-local-completion-map YaTeX-minibuffer-completion-map)
2195 (delim ",")
2196 (opt (YaTeX-completing-read-or-skip
2197 "Frame option: " YaTeX:frame-option-alist))
2198 (title (YaTeX-read-string-or-skip "Title: "))
2199 (subtitle (YaTeX-read-string-or-skip "Subtitle: ")))
2200 (setq YaTeX-env-name "columns")
2201 (concat
2202 (if (string< "" opt) (concat "[" opt "]"))
2203 (if (string< "" title) (concat "{" title "}"))
2204 (if (string< "" subtitle) (concat "{" subtitle "}")))))
2206 (defun YaTeX:column-read-width ()
2207 "Completing function for column environment/macro of Beamer"
2208 (let ((md (match-data)) (colsinf (YaTeX-quick-in-environment-p "columns"))
2209 (totalw (float 1)) restw (ww "\\textwidth") defw cw)
2210 (unwind-protect
2211 (progn
2212 (if (save-excursion
2213 (YaTeX-re-search-active-backward
2214 "totalwidth=\\([.0-9]+\\)\\(\\\\.*width\\)"
2215 YaTeX-comment-prefix (cdr colsinf) t))
2216 (setq totalw (float (string-to-number (YaTeX-match-string 1)))
2217 ww (YaTeX-match-string 2)))
2218 (setq restw totalw)
2219 (save-excursion
2220 (while (YaTeX-re-search-active-backward
2221 (concat
2222 "\\\\begin{column}{\\([.0-9]+\\)\\(\\\\.*width\\)}"
2223 "\\|"
2224 "\\\\column{\\([.0-9]+\\)\\(\\\\.*width\\)}")
2225 YaTeX-comment-prefix
2226 (cdr colsinf) t)
2227 (setq restw (- restw (string-to-number
2228 (or (YaTeX-match-string 1)
2229 (YaTeX-match-string 3)))))))
2230 (setq defw (format "%.2f%s"
2231 (if (= totalw restw) (/ totalw 2) restw)
2232 (or (YaTeX-match-string 2)
2233 (YaTeX-match-string 4)
2234 ww))
2235 cw (YaTeX:read-length
2236 (format "Column width(default: %s): " defw)))
2237 (if (string= "" cw) (setq cw defw))
2238 (prog1
2239 cw
2240 (setq YaTeX-section-name "column")))
2241 (store-match-data md))))
2243 (defun YaTeX:column ()
2244 (if (eq YaTeX-current-completion-type 'begin)
2245 (concat "{" (YaTeX:column-read-width) "}")))
2246 (defun YaTeX::column (argp)
2247 (cond
2248 ((= argp 1) (YaTeX:column-read-width))))
2249 (defvar YaTeX:columns-option-alist
2250 '(("t") ("T") ("b") ("c") ("onlytextwidth") ("totalwidth=0.9\\textwidth"))
2251 "*Default option alist for completing columns environment of Beamer")
2253 (defun YaTeX:columns ()
2254 (setq YaTeX-section-name "column"
2255 YaTeX-env-name "column")
2256 (let*((minibuffer-local-completion-map YaTeX-minibuffer-completion-map)
2257 (delim ",=")
2258 (tbl (append YaTeX:columns-option-alist)) ;XX
2259 (opt (YaTeX-completing-read-or-skip "columns option: " tbl)))
2260 (if (string< "" opt)
2261 (concat "[" opt "]"))))
2263 ;;; -------------------- math-mode stuff --------------------
2264 (defun YaTeX::tilde (&optional pos)
2265 "For accent macros in mathmode"
2266 (cond
2267 ((equal pos 1)
2268 (message "Put accent on variable: ")
2269 (let ((v (char-to-string (read-char))) (case-fold-search nil))
2270 (message "")
2271 (cond
2272 ((string-match "i\\|j" v)
2273 (concat "\\" v "math"))
2274 ((string-match "[\r\n\t ]" v)
2275 "")
2276 (t v))))
2277 (nil "")))
2279 (fset 'YaTeX::hat 'YaTeX::tilde)
2280 (fset 'YaTeX::check 'YaTeX::tilde)
2281 (fset 'YaTeX::bar 'YaTeX::tilde)
2282 (fset 'YaTeX::dot 'YaTeX::tilde)
2283 (fset 'YaTeX::ddot 'YaTeX::tilde)
2284 (fset 'YaTeX::vec 'YaTeX::tilde)
2286 (defun YaTeX::widetilde (&optional pos)
2287 "For multichar accent macros in mathmode"
2288 (cond
2289 ((equal pos 1)
2290 (let ((m "Put over chars[%s ]: ") v v2)
2291 (message m " ")
2292 (setq v (char-to-string (read-char)))
2293 (message "")
2294 (if (string-match "[\r\n\t ]" v)
2295 ""
2296 (message m v)
2297 (setq v2 (char-to-string (read-char)))
2298 (message "")
2299 (if (string-match "[\r\n\t ]" v2)
2301 (concat v v2)))))
2302 (nil "")))
2304 (fset 'YaTeX::widehat 'YaTeX::widetilde)
2305 (fset 'YaTeX::overline 'YaTeX::widetilde)
2306 (fset 'YaTeX::overrightarrow 'YaTeX::widetilde)
2309 ; for \frac{}{} region
2310 (defun YaTeX::frac-region (beg end)
2311 (if (catch 'done
2312 (while (re-search-forward "\\s *\\(\\\\over\\|/\\)\\s *" end t)
2313 (goto-char (match-beginning 0))
2314 (if (y-or-n-p
2315 (format "Replace this `%s' with `}{'" (YaTeX-match-string 0)))
2316 (throw 'done t))
2317 (goto-char (match-end 0))))
2318 (let (p (b0 (match-beginning 0)) e0)
2319 (replace-match "}{")
2320 (setq e0 (point))
2321 (save-restriction
2322 (narrow-to-region beg end)
2323 (goto-char e0)
2324 (skip-chars-forward " \t")
2325 (setq p (point))
2326 (YaTeX-goto-corresponding-paren)
2327 (forward-char 1)
2328 (skip-chars-forward " \t\r\n")
2329 (if (= end (1+ (point)))
2330 (progn
2331 (goto-char p)
2332 (if (looking-at "\\\\") (forward-char 1))
2333 (YaTeX-kill-paren nil)))
2334 (goto-char beg)
2335 (skip-chars-forward " \t")
2336 (setq p (point))
2337 (YaTeX-goto-corresponding-paren)
2338 (forward-char 1)
2339 (skip-chars-forward " \t\r\n")
2340 (if (>= (point) b0)
2341 (progn
2342 (goto-char p)
2343 (if (looking-at "\\\\") (forward-char 1))
2344 (YaTeX-kill-paren nil))))))
2345 (message ""))
2347 (defun YaTeX::DeclareMathOperator (argp)
2348 (cond
2349 ((equal argp 1)
2350 (YaTeX-read-string-or-skip "Operator: " "\\"))))
2352 ;;;
2353 ;; Add-in functions for large-type command.
2354 ;;;
2355 (defun YaTeX:em ()
2356 (cond
2357 ((eq YaTeX-current-completion-type 'large) "\\/")
2358 (t nil)))
2359 (fset 'YaTeX:it 'YaTeX:em)
2361 ;;; -------------------- End of yatexadd --------------------
2362 (provide 'yatexadd)
2363 ; Local variables:
2364 ; fill-prefix: ";;; "
2365 ; paragraph-start: "^$\\| \\|;;;$"
2366 ; paragraph-separate: "^$\\| \\|;;;$"
2367 ; coding: sjis
2368 ; End: