yatex

view yatexadd.el @ 577:117a846879bc

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