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