yatex

view yatexadd.el @ 544:ab6c176c676a

Move all dot-filter definitions to yatexflt.el
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 02 Jun 2018 10:39:58 +0900
parents 523f54775325
children e7356faf50df
line source
1 ;;; yatexadd.el --- YaTeX add-in functions -*- coding: sjis -*-
2 ;;; (c)1991-2018 by HIROSE Yuuji.[yuuji@yatex.org]
3 ;;; Last modified Wed May 30 13:35:42 2018 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))
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 (set-window-buffer nil buf) ;Emacs26
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)))))
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 (defvar YaTeX::bibliographystyle-alist-default
1523 '(("unsrt")("junsrt")("plain")("jplain")("alpha")("jalpha")
1524 ("abbrv")("jabbrv")("jipsj")("jname")("tieice")("tipsj")
1525 ("apalike")("ieeetr")("siam")))
1526 (defvar YaTeX::bibliographystyle-alist-private
1527 nil
1528 "*Completion table for bibliographystyle")
1530 (defun YaTeX::bibliographystyle(argp)
1531 (cond
1532 ((= argp 1)
1533 (YaTeX-completing-read-or-skip
1534 "BibStyle: "
1535 (append YaTeX::bibliographystyle-alist-private
1536 YaTeX::bibliographystyle-alist-default)
1537 nil))))
1539 (defun YaTeX::bibitem (argp)
1540 "Add-in function to insert argument of \\bibitem."
1541 (YaTeX::label argp "label" "cite"))
1543 ;;; for Harvard citation style
1544 (fset 'YaTeX::citeasnoun 'YaTeX::cite)
1545 (fset 'YaTeX::possessivecite 'YaTeX::cite)
1546 (fset 'YaTeX::citeyear 'YaTeX::cite)
1547 (fset 'YaTeX::citename 'YaTeX::cite)
1548 (fset 'YaTeX::citep 'YaTeX::cite)
1549 (fset 'YaTeX::citet 'YaTeX::cite)
1551 (defun YaTeX-select-other-yatex-buffer ()
1552 "Select buffer from all yatex-mode's buffers interactivelly."
1553 (interactive)
1554 (let ((lbuf "*YaTeX mode buffers*") (blist (YaTeX-yatex-buffer-list))
1555 (lnum -1) buf rv
1556 (ff "**find-file**"))
1557 (YaTeX-showup-buffer
1558 lbuf (function (lambda (x) 1))) ;;Select next window surely.
1559 (save-excursion
1560 (set-buffer (get-buffer lbuf))
1561 (setq buffer-read-only nil)
1562 (erase-buffer))
1563 (let ((standard-output (get-buffer lbuf)))
1564 (while blist
1565 (princ
1566 (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A)
1567 (buffer-name (car blist))))
1568 (setq blist (cdr blist)))
1569 (princ (format "':{%s}" ff)))
1570 (YaTeX-showup-buffer lbuf nil t)
1571 (YaTeX::label-setup-key-map)
1572 (setq buffer-read-only t)
1573 (use-local-map YaTeX-label-select-map)
1574 (message YaTeX-label-guide-msg)
1575 (unwind-protect
1576 (progn
1577 (recursive-edit)
1578 (set-buffer lbuf)
1579 (beginning-of-line)
1580 (setq rv
1581 (if (re-search-forward "{\\([^\\}]+\\)}" (point-end-of-line) t)
1582 (buffer-substring (match-beginning 1) (match-end 1)) nil)))
1583 (kill-buffer lbuf))
1584 (if (string= rv ff)
1585 (progn
1586 (call-interactively 'find-file)
1587 (current-buffer))
1588 rv)))
1590 (defun YaTeX-label-other ()
1591 (let ((rv (YaTeX-select-other-yatex-buffer)))
1592 (cond
1593 ((null rv) "")
1594 (t
1595 (set-buffer rv)
1596 (funcall me argp labelcmd refcmd)))))
1598 ;;
1599 ; completion for the arguments of \newcommand
1600 ;;
1601 (defun YaTeX::newcommand (&optional argp)
1602 (cond
1603 ((= argp 1)
1604 (let ((command (read-string-with-history "Define newcommand: " "\\")))
1605 (put 'YaTeX::newcommand 'command (substring command 1))
1606 command))
1607 ((= argp 2)
1608 (let ((argc
1609 (YaTeX-str2int
1610 (read-string-with-history "Number of arguments(Default 0): ")))
1611 (def (YaTeX-read-string-or-skip "Definition: "))
1612 (command (get 'YaTeX::newcommand 'command)))
1613 ;;!!! It's illegal to insert string in the add-in function !!!
1614 (if (> argc 0) (insert (format "[%d]" argc)))
1615 (if (and (stringp command)
1616 (string< "" command)
1617 (y-or-n-p "Update dictionary?"))
1618 (cond
1619 ((= argc 0)
1620 (YaTeX-update-table
1621 (list command)
1622 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table))
1623 ((= argc 1)
1624 (YaTeX-update-table
1625 (list command)
1626 'section-table 'user-section-table 'tmp-section-table))
1627 (t (YaTeX-update-table
1628 (list command argc)
1629 'section-table 'user-section-table 'tmp-section-table))))
1630 (message "")
1631 def ;return command name
1632 ))
1633 (t "")))
1635 (defun YaTeX::newcounter (&optional argp)
1636 (cond
1637 ((= argp 1)
1638 (read-string-with-history "New counter name: "))
1639 (t "")))
1641 ;;
1642 ; completion for the arguments of \pagestyle
1643 ;;
1644 (defun YaTeX::pagestyle (&optional argp)
1645 "Read the pagestyle with completion."
1646 (completing-read
1647 "Page style: "
1648 '(("plain") ("empty") ("headings") ("myheadings") ("normal") nil)))
1650 (fset 'YaTeX::thispagestyle 'YaTeX::pagestyle)
1652 ;;
1653 ; completion for the arguments of \pagenumbering
1654 ;;
1655 (defun YaTeX::pagenumbering (&optional argp)
1656 "Read the numbering style."
1657 (completing-read
1658 "Page numbering style: "
1659 '(("arabic") ("Alpha") ("alpha") ("Roman") ("roman"))))
1661 ;;
1662 ; Length
1663 ;;
1664 (defvar YaTeX:style-parameters-default
1665 '(("\\arraycolsep")
1666 ("\\arrayrulewidth")
1667 ("\\baselineskip")
1668 ("\\columnsep")
1669 ("\\columnseprule")
1670 ("\\doublerulesep")
1671 ("\\evensidemargin")
1672 ("\\footheight")
1673 ("\\footskip")
1674 ("\\headheight")
1675 ("\\headsep")
1676 ("\\itemindent")
1677 ("\\itemsep")
1678 ("\\labelsep")
1679 ("\\labelwidth")
1680 ("\\leftmargin")
1681 ("\\linewidth")
1682 ("\\listparindent")
1683 ("\\marginparsep")
1684 ("\\marginparwidth")
1685 ("\\mathindent")
1686 ("\\oddsidemargin")
1687 ("\\parindent")
1688 ("\\parsep")
1689 ("\\parskip")
1690 ("\\partopsep")
1691 ("\\rightmargin")
1692 ("\\tabcolsep")
1693 ("\\textheight")
1694 ("\\textwidth")
1695 ("\\columnwidth")
1696 ("\\topmargin")
1697 ("\\topsep")
1698 ("\\topskip")
1700 "Alist of LaTeX style parameters.")
1701 (defvar YaTeX:style-parameters-private nil
1702 "*User definable alist of style parameters.")
1703 (defvar YaTeX:style-parameters-local nil
1704 "*User definable alist of local style parameters.")
1706 (defvar YaTeX:length-history nil "Holds history of length.")
1707 (put 'YaTeX:length-history 'no-default t)
1708 (defun YaTeX::setlength (&optional argp)
1709 "YaTeX add-in function for arguments of \\setlength."
1710 (cond
1711 ((equal 1 argp)
1712 ;;(completing-read "Length variable: " YaTeX:style-parameters nil nil "\\")
1713 (YaTeX-cplread-with-learning
1714 "Length variable: "
1715 'YaTeX:style-parameters-default
1716 'YaTeX:style-parameters-private
1717 'YaTeX:style-parameters-local
1718 nil nil "\\")
1720 ((equal 2 argp)
1721 (YaTeX-read-string-or-skip "Length: " nil 'YaTeX:length-history))))
1723 (fset 'YaTeX::addtolength 'YaTeX::setlength)
1725 (defun YaTeX::settowidth (&optional argp)
1726 "YaTeX add-in function for arguments of \\settowidth."
1727 (cond
1728 ((equal 1 argp)
1729 (YaTeX-cplread-with-learning
1730 "Length variable: "
1731 'YaTeX:style-parameters-default
1732 'YaTeX:style-parameters-private
1733 'YaTeX:style-parameters-local
1734 nil nil "\\"))
1735 ((equal 2 argp)
1736 (YaTeX-read-string-or-skip "Text: "))))
1738 (defun YaTeX::newlength (&optional argp)
1739 "YaTeX add-in function for arguments of \\newlength"
1740 (cond
1741 ((equal argp 1)
1742 (let ((length (read-string-with-history "Length variable: " "\\")))
1743 (if (string< "" length)
1744 (YaTeX-update-table
1745 (list length)
1746 'YaTeX:style-parameters-default
1747 'YaTeX:style-parameters-private
1748 'YaTeX:style-parameters-local))
1749 length))))
1751 ;; \multicolumn's arguments
1752 (defun YaTeX::multicolumn (&optional argp)
1753 "YaTeX add-in function for arguments of \\multicolumn."
1754 (cond
1755 ((equal 1 argp)
1756 (read-string-with-history "Number of columns: "))
1757 ((equal 2 argp)
1758 (YaTeX:read-oneof "|lrc" nil t))
1759 ((equal 3 argp)
1760 (YaTeX-read-string-or-skip "Item: "))))
1762 (defvar YaTeX:documentstyles-default
1763 '(("article") ("jarticle") ("j-article")
1764 ("book") ("jbook") ("j-book")
1765 ("report") ("jreport") ("j-report")
1766 ("letter") ("ascjletter"))
1767 "List of LaTeX documentstyles.")
1768 (defvar YaTeX:documentstyles-private nil
1769 "*User defined list of LaTeX documentstyles.")
1770 (defvar YaTeX:documentstyles-local nil
1771 "*User defined list of local LaTeX documentstyles.")
1772 (defvar YaTeX:documentstyle-options-default
1773 '(("a4j") ("a5j") ("b4j") ("b5j")
1774 ("twocolumn") ("jtwocolumn") ("epsf") ("epsfig") ("epsbox") ("nfig"))
1775 "List of LaTeX documentstyle options.")
1776 (defvar YaTeX:documentstyle-options-private nil
1777 "*User defined list of LaTeX documentstyle options.")
1778 (defvar YaTeX:documentstyle-options-local nil
1779 "List of LaTeX local documentstyle options.")
1781 (defun YaTeX:documentstyle ()
1782 (let*((delim ",")
1783 (dt (append YaTeX:documentstyle-options-local
1784 YaTeX:documentstyle-options-private
1785 YaTeX:documentstyle-options-default))
1786 (minibuffer-completion-table dt)
1787 (opt (read-from-minibuffer
1788 "Style options ([opt1,opt2,...]): "
1789 nil YaTeX-minibuffer-completion-map nil))
1790 (substr opt) o)
1791 (if (string< "" opt)
1792 (progn
1793 (while substr
1794 (setq o (substring substr 0 (string-match delim substr)))
1795 (or (assoc o dt)
1796 (YaTeX-update-table
1797 (list o)
1798 'YaTeX:documentstyle-options-default
1799 'YaTeX:documentstyle-options-private
1800 'YaTeX:documentstyle-options-local))
1801 (setq substr
1802 (if (string-match delim substr)
1803 (substring substr (1+ (string-match delim substr))))))
1804 (concat "[" opt "]"))
1805 "")))
1807 (defun YaTeX::documentstyle (&optional argp)
1808 "YaTeX add-in function for arguments of \\documentstyle."
1809 (cond
1810 ((equal argp 1)
1811 (setq YaTeX-env-name "document")
1812 (let ((sname
1813 (YaTeX-cplread-with-learning
1814 (format "Documentstyle (default %s): "
1815 YaTeX-default-document-style)
1816 'YaTeX:documentstyles-default
1817 'YaTeX:documentstyles-private
1818 'YaTeX:documentstyles-local)))
1819 (if (string= "" sname) (setq sname YaTeX-default-document-style))
1820 (setq YaTeX-default-document-style sname)))))
1822 (defun YaTeX::include (argp &optional prompt)
1823 "Read file name setting default directory to that of main file."
1824 (cond
1825 ((= argp 1)
1826 (save-excursion
1827 (YaTeX-visit-main t)
1828 (let*((insert-default-directory)
1829 (default (and (boundp 'old) (stringp old) old))
1830 (file (read-file-name (or prompt "Input file: ") ""
1831 default nil default)))
1832 (setq file (substring file 0 (string-match "\\.tex$" file))))))))
1834 (fset 'YaTeX::input 'YaTeX::include)
1835 (fset 'YaTeX::svg 'YaTeX::include)
1838 ;;; -------------------- LaTeX2e stuff --------------------
1839 (defvar YaTeX:documentclass-options-default
1840 '(("a4paper") ("a5paper") ("b4paper") ("b5paper") ("10pt") ("11pt") ("12pt")
1841 ("latterpaper") ("legalpaper") ("executivepaper") ("landscape")
1842 ("oneside") ("twoside") ("draft") ("final") ("leqno") ("fleqn") ("openbib")
1843 ("tombow") ("titlepage") ("notitlepage") ("dvips")
1844 ("mingoth") ;for jsarticle
1845 ("clock") ;for slides class only
1847 "Default options list for documentclass")
1848 (defvar YaTeX:documentclass-options-private nil
1849 "*User defined options list for documentclass")
1850 (defvar YaTeX:documentclass-options-local nil
1851 "*User defined options list for local documentclass")
1853 (defun YaTeX:documentclass ()
1854 (let*((delim ",")
1855 (dt (append YaTeX:documentclass-options-local
1856 YaTeX:documentclass-options-private
1857 YaTeX:documentclass-options-default))
1858 (minibuffer-completion-table dt)
1859 (opt (read-from-minibuffer
1860 "Documentclass options ([opt1,opt2,...]): "
1861 nil YaTeX-minibuffer-completion-map nil))
1862 (substr opt) o)
1863 (if (string< "" opt)
1864 (progn
1865 (while substr
1867 (setq o (substring substr 0 (string-match delim substr)))
1868 (or (assoc o dt)
1869 (YaTeX-update-table
1870 (list o)
1871 'YaTeX:documentclass-options-default
1872 'YaTeX:documentclass-options-private
1873 'YaTeX:documentclass-options-local))
1874 (setq substr
1875 (if (string-match delim substr)
1876 (substring substr (1+ (string-match delim substr))))))
1877 (concat "[" opt "]"))
1878 "")))
1880 (defvar YaTeX:documentclasses-default
1881 '(("article") ("jarticle") ("report") ("jreport") ("book") ("jbook")
1882 ("jsarticle") ("jsbook")
1883 ("j-article") ("j-report") ("j-book")
1884 ("letter") ("slides") ("ltxdoc") ("ltxguide") ("ltnews") ("proc"))
1885 "Default documentclass alist")
1886 (defvar YaTeX:documentclasses-private nil
1887 "*User defined documentclass alist")
1888 (defvar YaTeX:documentclasses-local nil
1889 "*User defined local documentclass alist")
1890 (defvar YaTeX-default-documentclass (if YaTeX-japan "jarticle" "article")
1891 "*Default documentclass")
1893 (defun YaTeX::documentclass (&optional argp)
1894 (cond
1895 ((equal argp 1)
1896 (setq YaTeX-env-name "document")
1897 (let ((sname
1898 (YaTeX-cplread-with-learning
1899 (format "Documentclass (default %s): " YaTeX-default-documentclass)
1900 'YaTeX:documentclasses-default
1901 'YaTeX:documentclasses-private
1902 'YaTeX:documentclasses-local)))
1903 (if (string= "" sname) (setq sname YaTeX-default-documentclass))
1904 (setq YaTeX-section-name "title"
1905 YaTeX-default-documentclass sname)))))
1907 (defun YaTeX::title (&optional argp)
1908 (prog1 (YaTeX-read-string-or-skip "Document Title: ")
1909 (setq YaTeX-section-name "author"
1910 YaTeX-single-command "maketitle")))
1912 (defun YaTeX::author (&optional argp)
1913 (prog1 (YaTeX-read-string-or-skip "Document Author: ")
1914 (setq YaTeX-section-name "date"
1915 YaTeX-single-command "maketitle")))
1917 (defun YaTeX:document ()
1918 (setq YaTeX-section-name
1919 (if (string-match "book\\|bk" YaTeX-default-documentclass)
1920 "chapter"
1921 "section"))
1922 "")
1925 (defvar YaTeX:latex2e-named-color-alist
1926 '(("GreenYellow") ("Yellow") ("Goldenrod") ("Dandelion") ("Apricot")
1927 ("Peach") ("Melon") ("YellowOrange") ("Orange") ("BurntOrange")
1928 ("Bittersweet") ("RedOrange") ("Mahogany") ("Maroon") ("BrickRed")
1929 ("Red") ("OrangeRed") ("RubineRed") ("WildStrawberry") ("Salmon")
1930 ("CarnationPink") ("Magenta") ("VioletRed") ("Rhodamine") ("Mulberry")
1931 ("RedViolet") ("Fuchsia") ("Lavender") ("Thistle") ("Orchid")("DarkOrchid")
1932 ("Purple") ("Plum") ("Violet") ("RoyalPurple") ("BlueViolet")
1933 ("Periwinkle") ("CadetBlue") ("CornflowerBlue") ("MidnightBlue")
1934 ("NavyBlue") ("RoyalBlue") ("Blue") ("Cerulean") ("Cyan") ("ProcessBlue")
1935 ("SkyBlue") ("Turquoise") ("TealBlue") ("Aquamarine") ("BlueGreen")
1936 ("Emerald") ("JungleGreen") ("SeaGreen") ("Green") ("ForestGreen")
1937 ("PineGreen") ("LimeGreen") ("YellowGreen") ("SpringGreen") ("OliveGreen")
1938 ("RawSienna") ("Sepia") ("Brown") ("Tan") ("Gray") ("Black") ("White"))
1939 "Colors defined in $TEXMF/tex/plain/dvips/colordvi.tex")
1941 (defvar YaTeX:latex2e-basic-color-alist
1942 '(("black") ("white") ("red") ("blue") ("yellow") ("green") ("cyan")
1943 ("magenta"))
1944 "Basic colors")
1946 (defun YaTeX:textcolor ()
1947 "Add-in for \\color's option"
1948 (if (y-or-n-p "Use `named' color? ")
1949 "[named]"))
1951 (defun YaTeX::color-completing-read (prompt)
1952 (let ((completion-ignore-case t)
1953 (namedp (save-excursion
1954 (skip-chars-backward "^\n\\[\\\\")
1955 (looking-at "named"))))
1956 (completing-read
1957 prompt
1958 (if namedp
1959 YaTeX:latex2e-named-color-alist
1960 YaTeX:latex2e-basic-color-alist)
1961 nil t)))
1963 (defun YaTeX::textcolor (argp)
1964 "Add-in for \\color's argument"
1965 (cond
1966 ((= argp 1) (YaTeX::color-completing-read "Color: "))
1967 ((= argp 2) (YaTeX-read-string-or-skip "Colored string: "))))
1969 (fset 'YaTeX:color 'YaTeX:textcolor)
1970 (fset 'YaTeX::color 'YaTeX::textcolor)
1971 (fset 'YaTeX:colorbox 'YaTeX:textcolor)
1972 (fset 'YaTeX::colorbox 'YaTeX::textcolor)
1973 (fset 'YaTeX:fcolorbox 'YaTeX:textcolor)
1974 (fset 'YaTeX:pagecolor 'YaTeX:textcolor)
1975 (fset 'YaTeX::pagecolor 'YaTeX::textcolor)
1977 (defun YaTeX::fcolorbox (argp)
1978 (cond
1979 ((= argp 1) (YaTeX::color-completing-read "Frame color: "))
1980 ((= argp 2) (YaTeX::color-completing-read "Inner color: "))
1981 ((= argp 3) (YaTeX-read-string-or-skip "Colored string: "))))
1983 (defun YaTeX:scalebox ()
1984 "Add-in for \\scalebox"
1985 (let ((vmag (YaTeX-read-string-or-skip (if YaTeX-japan "倍率(負で反転): "
1986 "Magnification(Negative for flipped): ")))
1987 (hmag (YaTeX-read-string-or-skip (if YaTeX-japan "縦倍率(省略可): "
1988 "Vertical magnification(Optional): "))))
1989 (if (and hmag (string< "" hmag))
1990 (format "{%s}[%s]" vmag hmag)
1991 (format "{%s}" vmag))))
1993 (defun YaTeX:rotatebox ()
1994 "Optional argument add-in for \\rotatebox"
1995 (message "Rotate origin? (N)one (O)rigin (X)-Y: ")
1996 (let ((c (read-char)) r (defx "x=mm") x (defy "y=mm") y something)
1997 (cond
1998 ((memq c '(?O ?o))
1999 (if (string< "" (setq r (YaTeX:read-oneof "htbpB")))
2000 (concat "[origin=" r "]")))
2001 ((memq c '(?X ?x ?Y ?y))
2002 (setq r (read-string-with-history
2003 "" (if YaTeX-emacs-19 (cons defx 3) defx))
2004 x (if (string< "x=" r) r)
2005 r (read-string-with-history
2006 "" (if YaTeX-emacs-19 (cons defy 3) defy))
2007 y (if (string< "y=" r) r)
2008 something (or x y))
2009 (format "%s%s%s%s%s"
2010 (if something "[" "")
2011 (if x x "")
2012 (if (and x y) "," "")
2013 (if y y "")
2014 (if something "]" ""))))))
2016 (defun YaTeX::rotatebox (argp)
2017 "Argument add-in for \\rotatebox"
2018 (cond
2019 ((= argp 1)
2020 (read-string-with-history (if YaTeX-japan "回転角(度; 左回り): "
2021 "Angle in degree(unclockwise): ")))
2022 ((= argp 2)
2023 (YaTeX-read-string-or-skip (if YaTeX-japan "テキスト: " "Text: ")))))
2025 (defun YaTeX:includegraphics ()
2026 "Add-in for \\includegraphics's option"
2027 (let (width height (scale "") angle str)
2028 (setq width (YaTeX:read-length "Width: ")
2029 height (YaTeX:read-length "Height: "))
2030 (or (string< "" width) (string< "" height)
2031 (setq scale (YaTeX-read-string-or-skip "Scale: ")))
2032 (setq angle (YaTeX-read-string-or-skip "Angle(0-359): "))
2033 (setq str
2034 (mapconcat
2035 'concat
2036 (delq nil
2037 (mapcar (function (lambda (s)
2038 (and (stringp (symbol-value s))
2039 (string< "" (symbol-value s))
2040 (format "%s=%s" s (symbol-value s)))))
2041 '(width height scale angle)))
2042 ","))
2043 (if (string= "" str) ""
2044 (concat "[" str "]"))))
2046 (defvar YaTeX::get-boundingbox-cmd YaTeX-cmd-gs
2047 "Command to get bounding box from PDF files.
2048 Possible values are `gs' and `extractbb'.")
2050 (defun YaTeX::get-boundingbox (file)
2051 "Return the bound box as a string
2052 This function relies on gs(ghostscript) command installed."
2053 (let ((str (YaTeX-command-to-string
2054 (format
2055 (cond
2056 ((string-match "extractbb" YaTeX::get-boundingbox-cmd)
2057 "%s -O %s")
2058 ((string-match "gs" YaTeX::get-boundingbox-cmd)
2059 "%s -sDEVICE=bbox -dBATCH -dNOPAUSE %s")
2060 (t "echo %s %s"))
2061 YaTeX::get-boundingbox-cmd file))))
2062 (if (string-match
2063 "%%BoundingBox:\\s \\([0-9]+\\s [0-9]+\\s [0-9]+\\s [0-9]+\\)"
2064 str)
2065 (substring str (match-beginning 1) (match-end 1)))))
2067 (defun YaTeX::includegraphics (argp &optional file doclip)
2068 "Add-in for \\includegraphics"
2069 (let*((imgfile (or file (YaTeX::include argp "Image File: ")))
2070 (imgfilepath
2071 (save-excursion
2072 (YaTeX-visit-main t)
2073 (expand-file-name imgfile default-directory)))
2074 (case-fold-search t) info bb noupdate needclose c)
2075 (and (string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\|pdf\\)$" imgfile)
2076 (file-exists-p imgfilepath)
2077 (or (fboundp 'yahtml-get-image-info)
2078 (progn
2079 (load "yahtml" t) (featurep 'yahtml))) ;(require 'yahtml nil t)
2080 (if (string-match "\\.pdf" imgfile)
2081 (and
2082 (setq info (YaTeX::get-boundingbox imgfilepath))
2083 (stringp info)
2084 (string< "" info)
2085 (setq bb (format "bb=%s" info)))
2086 (setq info (yahtml-get-image-info imgfilepath))
2087 (car info) ;if has width value
2088 (car (cdr info)) ;if has height value
2089 (setq bb (format "bb=%d %d %d %d" 0 0 (car info) (car (cdr info)))))
2090 (save-excursion
2091 (cond
2092 ((and (save-excursion
2093 (YaTeX-re-search-active-backward
2094 "\\\\\\(includegraphics\\)\\|\\(bb=[-+ \t0-9]+\\)"
2095 YaTeX-comment-prefix nil t))
2096 (match-beginning 2)
2097 (not (setq noupdate (equal (YaTeX-match-string 2) bb)))
2098 (y-or-n-p (format "Update `bb=' line to `%s'?: " bb)))
2099 (message "")
2100 (replace-match bb))
2101 (noupdate nil)
2102 ((and (match-beginning 1)
2103 (or doclip
2104 (prog2
2105 (message "Insert `%s'? Y)es N)o C)yes+`clip': " bb)
2106 (memq (setq c (read-char)) '(?y ?Y ?\ ?c ?C))
2107 (setq doclip (memq c '(?c ?C)))
2108 (message ""))))
2109 (goto-char (match-end 0))
2110 (message "`bb=' %s"
2111 (format
2112 (if YaTeX-japan
2113 "の値はファイル名の上で `%s' を押してファイル名を再入力して更新できます。"
2114 "values can be update by typing `%s' on file name.")
2115 (key-description
2116 (car (where-is-internal 'YaTeX-change-*)))))
2117 (if (looking-at "\\[") (forward-char 1)
2118 (insert-before-markers "[")
2119 (setq needclose t))
2120 (insert-before-markers bb)
2121 (if doclip (insert-before-markers ",clip"))
2122 (if needclose (insert-before-markers "]")
2123 (or (looking-at "\\]") (insert-before-markers ","))))
2124 (t (YaTeX-push-to-kill-ring bb)))))
2125 (setq YaTeX-section-name "caption")
2126 imgfile))
2128 (defun YaTeX::verbfile (argp)
2129 "Add-in for \\verbfile"
2130 (YaTeX::include argp "Virbatim File: "))
2132 (defun YaTeX:caption ()
2133 (setq YaTeX-section-name "label")
2134 nil)
2137 (defvar YaTeX::usepackage-alist-default
2138 '(("version") ("plext") ("url") ("fancybox") ("pifont") ("longtable")
2139 ("ascmac") ("bm") ("graphics") ("graphicx") ("alltt") ("misc") ("eclbkbox")
2140 ("amsmath") ("amssymb") ("xymtex") ("chemist")
2141 ("a4j") ("array") ("epsf") ("color") ("xcolor") ("epsfig") ("floatfig")
2142 ("landscape") ("path") ("supertabular") ("twocolumn")
2143 ("latexsym") ("times") ("makeidx") ("geometry") ("type1cm"))
2144 "Default completion table for arguments of \\usepackage")
2146 (defvar YaTeX::usepackage-alist-private nil
2147 "*Private completion list of the argument for usepackage")
2149 (defvar YaTeX::usepackage-alist-local nil
2150 "Directory local completion list of the argument for usepackage")
2152 (defun YaTeX::usepackage (&optional argp)
2153 (cond
2154 ((equal argp 1)
2155 (setq YaTeX-env-name "document")
2156 (let ((minibuffer-local-completion-map YaTeX-minibuffer-completion-map)
2157 (delim ","))
2158 (YaTeX-cplread-with-learning
2159 (if YaTeX-japan "Use package(カンマで区切ってOK): "
2160 "Use package(delimitable by comma): ")
2161 'YaTeX::usepackage-alist-default
2162 'YaTeX::usepackage-alist-private
2163 'YaTeX::usepackage-alist-local)))))
2165 (defun YaTeX::mask (argp)
2166 (cond
2167 ((equal argp 1)
2168 (YaTeX-read-string-or-skip "String: "))
2169 ((equal argp 2)
2170 (let (c)
2171 (while (not (memq c '(?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K)))
2172 (message "Mask type(A..K): ")
2173 (setq c (upcase (read-char))))
2174 (format "%c" c)))))
2176 (defun YaTeX::maskbox (argp)
2177 (cond
2178 ((equal argp 1)
2179 (YaTeX:read-length "Width: "))
2180 ((equal argp 2)
2181 (YaTeX:read-length "Height: "))
2182 ((equal argp 3)
2183 (let (c)
2184 (while (not (memq c '(?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K)))
2185 (message "Mask type(A..K): ")
2186 (setq c (upcase (read-char))))
2187 (format "%c" c)))
2188 ((equal argp 4)
2189 (YaTeX:read-oneof "lcr" 'quick))
2190 ((equal argp 5)
2191 (YaTeX-read-string-or-skip "String: "))))
2193 (defun YaTeX::textcircled (argp)
2194 (cond
2195 ((equal argp 1)
2196 (let ((char (read-string-with-history "Circled char: "))
2197 (left "") (right "") c)
2198 (setq c (read-char
2199 "Enclose also with (s)mall (t)iny s(C)riptsize (N)one:"))
2200 (cond
2201 ((memq c '(?s ?S)) (setq left "{\\small " right "}"))
2202 ((memq c '(?t ?T)) (setq left "{\\tiny " right "}"))
2203 ((memq c '(?c ?C)) (setq left "{\\scriptsize " right "}")))
2204 (format "%s%s%s" left char right)))))
2206 ;;; -------------------- beamer stuff --------------------
2207 (defvar YaTeX:frame-option-alist-default
2208 '(("plain") ("containsverbatim") ("shrink") ("squeeze")
2209 ("allowframebreaks") ("label=")))
2210 (defvar YaTeX:frame-option-alist-private nil
2211 "*Alist for completion list of the argument for `frame' environemnt")
2212 (defvar YaTeX:frame-option-alist
2213 (append YaTeX:frame-option-alist-private YaTeX:frame-option-alist-default))
2215 (defun YaTeX:frame ()
2216 (let*((minibuffer-local-completion-map YaTeX-minibuffer-completion-map)
2217 (delim ",")
2218 (opt (YaTeX-completing-read-or-skip
2219 "Frame option: " YaTeX:frame-option-alist))
2220 (title (YaTeX-read-string-or-skip "Title: "))
2221 (subtitle (YaTeX-read-string-or-skip "Subtitle: ")))
2222 (setq YaTeX-env-name "columns")
2223 (concat
2224 (if (string< "" opt) (concat "[" opt "]"))
2225 (if (string< "" title) (concat "{" title "}"))
2226 (if (string< "" subtitle) (concat "{" subtitle "}")))))
2228 (defun YaTeX:column-read-width ()
2229 "Completing function for column environment/macro of Beamer"
2230 (let ((md (match-data)) (colsinf (YaTeX-quick-in-environment-p "columns"))
2231 (totalw (float 1)) restw (ww "\\textwidth") defw cw)
2232 (unwind-protect
2233 (progn
2234 (if (save-excursion
2235 (YaTeX-re-search-active-backward
2236 "totalwidth=\\([.0-9]+\\)\\(\\\\.*width\\)"
2237 YaTeX-comment-prefix (cdr colsinf) t))
2238 (setq totalw (float (string-to-number (YaTeX-match-string 1)))
2239 ww (YaTeX-match-string 2)))
2240 (setq restw totalw)
2241 (save-excursion
2242 (while (YaTeX-re-search-active-backward
2243 (concat
2244 "\\\\begin{column}{\\([.0-9]+\\)\\(\\\\.*width\\)}"
2245 "\\|"
2246 "\\\\column{\\([.0-9]+\\)\\(\\\\.*width\\)}")
2247 YaTeX-comment-prefix
2248 (cdr colsinf) t)
2249 (setq restw (- restw (string-to-number
2250 (or (YaTeX-match-string 1)
2251 (YaTeX-match-string 3)))))))
2252 (setq defw (format "%.2f%s"
2253 (if (= totalw restw) (/ totalw 2) restw)
2254 (or (YaTeX-match-string 2)
2255 (YaTeX-match-string 4)
2256 ww))
2257 cw (YaTeX:read-length
2258 (format "Column width(default: %s): " defw)))
2259 (if (string= "" cw) (setq cw defw))
2260 (prog1
2261 cw
2262 (setq YaTeX-section-name "column")))
2263 (store-match-data md))))
2265 (defun YaTeX:column ()
2266 (if (eq YaTeX-current-completion-type 'begin)
2267 (concat "{" (YaTeX:column-read-width) "}")))
2268 (defun YaTeX::column (argp)
2269 (cond
2270 ((= argp 1) (YaTeX:column-read-width))))
2271 (defvar YaTeX:columns-option-alist
2272 '(("t") ("T") ("b") ("c") ("onlytextwidth") ("totalwidth=0.9\\textwidth"))
2273 "*Default option alist for completing columns environment of Beamer")
2275 (defun YaTeX:columns ()
2276 (setq YaTeX-section-name "column"
2277 YaTeX-env-name "column")
2278 (let*((minibuffer-local-completion-map YaTeX-minibuffer-completion-map)
2279 (delim ",=")
2280 (tbl (append YaTeX:columns-option-alist)) ;XX
2281 (opt (YaTeX-completing-read-or-skip "columns option: " tbl)))
2282 (if (string< "" opt)
2283 (concat "[" opt "]"))))
2285 ;;; -------------------- math-mode stuff --------------------
2286 (defun YaTeX::tilde (&optional pos)
2287 "For accent macros in mathmode"
2288 (cond
2289 ((equal pos 1)
2290 (message "Put accent on variable: ")
2291 (let ((v (char-to-string (read-char))) (case-fold-search nil))
2292 (message "")
2293 (cond
2294 ((string-match "i\\|j" v)
2295 (concat "\\" v "math"))
2296 ((string-match "[\r\n\t ]" v)
2297 "")
2298 (t v))))
2299 (nil "")))
2301 (fset 'YaTeX::hat 'YaTeX::tilde)
2302 (fset 'YaTeX::check 'YaTeX::tilde)
2303 (fset 'YaTeX::bar 'YaTeX::tilde)
2304 (fset 'YaTeX::dot 'YaTeX::tilde)
2305 (fset 'YaTeX::ddot 'YaTeX::tilde)
2306 (fset 'YaTeX::vec 'YaTeX::tilde)
2308 (defun YaTeX::widetilde (&optional pos)
2309 "For multichar accent macros in mathmode"
2310 (cond
2311 ((equal pos 1)
2312 (let ((m "Put over chars[%s ]: ") v v2)
2313 (message m " ")
2314 (setq v (char-to-string (read-char)))
2315 (message "")
2316 (if (string-match "[\r\n\t ]" v)
2317 ""
2318 (message m v)
2319 (setq v2 (char-to-string (read-char)))
2320 (message "")
2321 (if (string-match "[\r\n\t ]" v2)
2323 (concat v v2)))))
2324 (nil "")))
2326 (fset 'YaTeX::widehat 'YaTeX::widetilde)
2327 (fset 'YaTeX::overline 'YaTeX::widetilde)
2328 (fset 'YaTeX::overrightarrow 'YaTeX::widetilde)
2331 ; for \frac{}{} region
2332 (defun YaTeX::frac-region (beg end)
2333 (if (catch 'done
2334 (while (re-search-forward "\\s *\\(\\\\over\\|/\\)\\s *" end t)
2335 (goto-char (match-beginning 0))
2336 (if (y-or-n-p
2337 (format "Replace this `%s' with `}{'" (YaTeX-match-string 0)))
2338 (throw 'done t))
2339 (goto-char (match-end 0))))
2340 (let (p (b0 (match-beginning 0)) e0)
2341 (replace-match "}{")
2342 (setq e0 (point))
2343 (save-restriction
2344 (narrow-to-region beg end)
2345 (goto-char e0)
2346 (skip-chars-forward " \t")
2347 (setq p (point))
2348 (YaTeX-goto-corresponding-paren)
2349 (forward-char 1)
2350 (skip-chars-forward " \t\r\n")
2351 (if (= end (1+ (point)))
2352 (progn
2353 (goto-char p)
2354 (if (looking-at "\\\\") (forward-char 1))
2355 (YaTeX-kill-paren nil)))
2356 (goto-char beg)
2357 (skip-chars-forward " \t")
2358 (setq p (point))
2359 (YaTeX-goto-corresponding-paren)
2360 (forward-char 1)
2361 (skip-chars-forward " \t\r\n")
2362 (if (>= (point) b0)
2363 (progn
2364 (goto-char p)
2365 (if (looking-at "\\\\") (forward-char 1))
2366 (YaTeX-kill-paren nil))))))
2367 (message ""))
2369 (defun YaTeX::DeclareMathOperator (argp)
2370 (cond
2371 ((equal argp 1)
2372 (YaTeX-read-string-or-skip "Operator: " "\\"))))
2374 ;;;
2375 ;; Add-in functions for large-type command.
2376 ;;;
2377 (defun YaTeX:em ()
2378 (cond
2379 ((eq YaTeX-current-completion-type 'large) "\\/")
2380 (t nil)))
2381 (fset 'YaTeX:it 'YaTeX:em)
2383 ;;; -------------------- End of yatexadd --------------------
2384 (provide 'yatexadd)
2385 ; Local variables:
2386 ; fill-prefix: ";;; "
2387 ; paragraph-start: "^$\\| \\|;;;$"
2388 ; paragraph-separate: "^$\\| \\|;;;$"
2389 ; End: