yatex

view yatexadd.el @ 611:e87c3271b8fd

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