yatex

view yatexadd.el @ 584:907de32064c9

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