yatex

view yatexadd.el @ 68:0eb6997bee16

More adjustment for Emacs20 and XEmacs [prefix] g for <applet> <!--#include> <!--#exec>
author yuuji
date Mon, 26 Oct 1998 12:05:32 +0000
parents 36a48185b95a
children 807c1e7e68b7
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX add-in functions.
3 ;;; yatexadd.el rev.14
4 ;;; (c )1991-1997 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
5 ;;; Last modified Mon Sep 28 13:03:37 1998 on firestorm
6 ;;; $Id$
8 ;;;
9 ;;Sample functions for LaTeX environment.
10 ;;;
11 (defvar YaTeX:tabular-default-rule
12 "@{\\vrule width 1pt\\ }c|c|c@{\\ \\vrule width 1pt}"
13 "*Your favorite default rule format."
14 )
15 (defvar YaTeX:tabular-thick-vrule "\\vrule width %s"
16 "*Vertical thick line format (without @{}). %s'll be replaced by its width."
17 )
18 (defvar YaTeX:tabular-thick-hrule "\\noalign{\\hrule height %s}"
19 "*Horizontal thick line format. %s will be replaced by its width."
20 )
21 (defun YaTeX:tabular ()
22 "YaTeX add-in function for tabular environment.
23 Notice that this function refers the let-variable `env' in
24 YaTeX-make-begin-end."
25 (let ((width "") bars (rule "") (and "") (j 1) loc ans (hline "\\hline"))
26 (if (string= env "tabular*")
27 (setq width (concat "{" (read-string "Width: ") "}")))
28 (setq loc (YaTeX:read-position "tb")
29 bars (string-to-int
30 (read-string "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 "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 (read-string "rule format: " rule))
54 (setq single-command "hline")
56 (format "%s%s{%s}" width loc rule))
57 )
58 (fset 'YaTeX:tabular* 'YaTeX:tabular)
59 (defun YaTeX:array ()
60 (concat (YaTeX:read-position "tb")
61 "{" (read-string "Column format: ") "}")
62 )
64 (defun YaTeX:read-oneof (oneof)
65 (let ((pos "") loc (guide ""))
66 (and (boundp 'name) name (setq guide (format "%s " name)))
67 (while (not (string-match
68 (setq loc (read-key-sequence
69 (format "%s position (`%s') [%s]: "
70 guide oneof pos));name is in YaTeX-addin
71 loc (if (fboundp 'events-to-keys)
72 (events-to-keys loc) loc))
73 "\r\^g\n"))
74 (cond
75 ((string-match loc oneof)
76 (if (not (string-match loc pos))
77 (setq pos (concat pos loc))))
78 ((and (string-match loc "\C-h\C-?") (> (length pos) 0))
79 (setq pos (substring pos 0 (1- (length pos)))))
80 (t
81 (ding)
82 (message "Please input one of `%s'." oneof)
83 (sit-for 3))))
84 (message "")
85 pos)
86 )
88 (defun YaTeX:read-position (oneof)
89 "Read a LaTeX (optional) position format such as `[htbp]'."
90 (let ((pos (YaTeX:read-oneof oneof)))
91 (if (string= pos "") "" (concat "[" pos "]")))
92 )
94 (defun YaTeX:table ()
95 "YaTeX add-in function for table environment."
96 (setq env-name "tabular"
97 section-name "caption")
98 (YaTeX:read-position "htbp")
99 )
101 (fset 'YaTeX:figure 'YaTeX:table)
102 (fset 'YaTeX:figure* 'YaTeX:table)
105 (defun YaTeX:description ()
106 "Truly poor service:-)"
107 (setq single-command "item[]")
108 ""
109 )
111 (defun YaTeX:itemize ()
112 "It's also poor service."
113 (setq single-command "item")
114 ""
115 )
117 (fset 'YaTeX:enumerate 'YaTeX:itemize)
119 (defun YaTeX:picture ()
120 "Ask the size of coordinates of picture environment."
121 (concat (YaTeX:read-coordinates "Picture size")
122 (YaTeX:read-coordinates "Initial position"))
123 )
125 (defun YaTeX:equation ()
126 (YaTeX-jmode-off)
127 (if (fboundp 'YaTeX-toggle-math-mode)
128 (YaTeX-toggle-math-mode t)) ;force math-mode ON.
129 )
130 (mapcar '(lambda (f) (fset f 'YaTeX:equation))
131 '(YaTeX:eqnarray YaTeX:eqnarray* YaTeX:align YaTeX:align*
132 YaTeX:split YaTeX:multline YaTeX:multline* YaTeX:gather YaTeX:gather*
133 YaTeX:aligned* YaTeX:gathered YaTeX:gathered*
134 YaTeX:alignat YaTeX:alignat* YaTeX:xalignat YaTeX:xalignat*
135 YaTeX:xxalignat YaTeX:xxalignat*))
137 (defun YaTeX:list ()
138 "%\n{} %default label\n{} %formatting parameter"
139 )
141 (defun YaTeX:minipage ()
142 (concat (YaTeX:read-position "cbt")
143 "{" (read-string "Width: ") "}")
144 )
146 (defun YaTeX:thebibliography ()
147 (setq section-name "bibitem")
148 ""
149 )
151 ;;;
152 ;;Sample functions for section-type command.
153 ;;;
154 (defun YaTeX:multiput ()
155 (concat (YaTeX:read-coordinates "Pos")
156 (YaTeX:read-coordinates "Step")
157 "{" (read-string "How many times: ") "}")
158 )
160 (defun YaTeX:put ()
161 (YaTeX:read-coordinates "Pos")
162 )
164 (defun YaTeX:makebox ()
165 (cond
166 ((YaTeX-in-environment-p "picture")
167 (concat (YaTeX:read-coordinates "Dimension")
168 (YaTeX:read-position "lrtb")))
169 (t
170 (let ((width (read-string "Width: ")))
171 (if (string< "" width)
172 (progn
173 (or (equal (aref width 0) ?\[)
174 (setq width (concat "[" width "]")))
175 (concat width (YaTeX:read-position "lr")))))))
176 )
178 (defun YaTeX:framebox ()
179 (if (YaTeX-quick-in-environment-p "picture")
180 (YaTeX:makebox))
181 )
183 (defun YaTeX:dashbox ()
184 (concat "{" (read-string "Dash dimension: ") "}"
185 (YaTeX:read-coordinates "Dimension"))
186 )
188 (defvar YaTeX-minibuffer-quick-map nil)
189 (if YaTeX-minibuffer-quick-map nil
190 (setq YaTeX-minibuffer-quick-map
191 (copy-keymap minibuffer-local-completion-map))
192 (let ((ch (1+ ? )))
193 (while (< ch 127)
194 (define-key YaTeX-minibuffer-quick-map (char-to-string ch)
195 'YaTeX-minibuffer-quick-complete)
196 (setq ch (1+ ch)))))
198 (defvar YaTeX:left-right-delimiters
199 '(("(" . ")") (")" . "(") ("[" . "]") ("]" . "[")
200 ("\\{" . "\\}") ("\\}" . "\\{") ("|") ("\\|")
201 ("\\lfloor" . "\\rfloor") ("\\lceil" . "\\rceil")
202 ("\\langle" . "\\rangle") ("/") (".")
203 ("\\rfloor" . "\\rfloor") ("\\rceil" . "\\lceil")
204 ("\\rangle" . "\\langle") ("\\backslash")
205 ("\\uparrow") ("\\downarrow") ("\\updownarrow") ("\\Updownarrow"))
206 "TeX math delimiter, which can be completed after \\right or \\left.")
208 (defvar YaTeX:left-right-default nil "Default string of YaTeX:right.")
210 (defun YaTeX:left ()
211 (let ((minibuffer-completion-table YaTeX:left-right-delimiters)
212 delimiter (leftp (string= single-command "left")))
213 (setq delimiter
214 (read-from-minibuffer
215 (format "Delimiter%s: "
216 (if YaTeX:left-right-default
217 (format "(default=`%s')" YaTeX:left-right-default)
218 "(SPC for menu)"))
219 nil YaTeX-minibuffer-quick-map))
220 (if (string= "" delimiter) (setq delimiter YaTeX:left-right-default))
221 (setq single-command (if leftp "right" "left")
222 YaTeX:left-right-default
223 (or (cdr (assoc delimiter YaTeX:left-right-delimiters)) delimiter))
224 delimiter))
226 (fset 'YaTeX:right 'YaTeX:left)
229 (defun YaTeX:read-coordinates (&optional mes varX varY)
230 (concat
231 "("
232 (read-string (format "%s %s: " (or mes "Dimension") (or varX "X")))
233 ","
234 (read-string (format "%s %s: " (or mes "Dimension") (or varY "Y")))
235 ")")
236 )
238 ;;;
239 ;;Sample functions for maketitle-type command.
240 ;;;
241 (defun YaTeX:sum ()
242 "Read range of summation."
243 (YaTeX:check-completion-type 'maketitle)
244 (concat (YaTeX:read-boundary "_") (YaTeX:read-boundary "^"))
245 )
247 (fset 'YaTeX:int 'YaTeX:sum)
249 (defun YaTeX:lim ()
250 "Insert limit notation of \\lim."
251 (YaTeX:check-completion-type 'maketitle)
252 (let ((var (read-string "Variable: ")) limit)
253 (if (string= "" var) ""
254 (setq limit (read-string "Limit ($ means infinity): "))
255 (if (string= "$" limit) (setq limit "\\infty"))
256 (concat "_{" var " \\rightarrow " limit "}")))
257 )
259 (defun YaTeX:gcd ()
260 "Add-in function for \\gcd(m,n)."
261 (YaTeX:check-completion-type 'maketitle)
262 (YaTeX:read-coordinates "\\gcd" "(?,)" "(,?)")
263 )
265 (defun YaTeX:read-boundary (ULchar)
266 "Read boundary usage by _ or ^. _ or ^ is indicated by argument ULchar."
267 (let ((bndry (read-string (concat ULchar "{???} ($ for infinity): "))))
268 (if (string= bndry "") ""
269 (if (string= bndry "$") (setq bndry "\\infty"))
270 (concat ULchar "{" bndry "}")))
271 )
273 (defun YaTeX:verb ()
274 "Enclose \\verb's contents with the same characters."
275 (let ((quote-char (read-string "Quoting char: " "|"))
276 (contents (read-string "Quoted contents: ")))
277 (concat quote-char contents quote-char))
278 )
279 (fset 'YaTeX:verb* 'YaTeX:verb)
281 (defun YaTeX:footnotemark ()
282 (setq section-name "footnotetext")
283 nil
284 )
286 (defun YaTeX:cite ()
287 (let ((comment (read-string "Comment for citation: ")))
288 (if (string= comment "") ""
289 (concat "[" comment "]")))
290 )
292 (defun YaTeX:bibitem ()
293 (let ((label (read-string "Citation label for bibitem: ")))
294 (if (string= label "") ""
295 (concat "[" label "]")))
296 )
298 (defun YaTeX:item ()
299 (YaTeX-indent-line)
300 (setq section-name "label")
301 " ")
302 (fset 'YaTeX:item\[\] 'YaTeX:item)
303 (fset 'YaTeX:subitem 'YaTeX:item)
304 (fset 'YaTeX:subsubitem 'YaTeX:item)
306 (defun YaTeX:linebreak ()
307 (let (obl)
308 (message "Break strength 0,1,2,3,4 (default: 4): ")
309 (setq obl (char-to-string (read-char)))
310 (if (string-match "[0-4]" obl)
311 (concat "[" obl "]")
312 ""))
313 )
314 (fset 'YaTeX:pagebreak 'YaTeX:linebreak)
316 ;;;
317 ;;Subroutine
318 ;;;
320 (defun YaTeX:check-completion-type (type)
321 "Check valid completion type."
322 (if (not (eq type YaTeX-current-completion-type))
323 (error "This should be completed with %s-type completion." type))
324 )
327 ;;;
328 ;;; [[Add-in functions for reading section arguments]]
329 ;;;
330 ;; All of add-in functions for reading sections arguments should
331 ;; take an argument ARGP that specify the argument position.
332 ;; If argument position is out of range, nil should be returned,
333 ;; else nil should NOT be returned.
335 ;;
336 ; Label selection
337 ;;
338 (defvar YaTeX-label-menu-other
339 (if YaTeX-japan "':他のバッファのラベル\n" "':LABEL IN OTHER BUFFER.\n"))
340 (defvar YaTeX-label-menu-repeat
341 (if YaTeX-japan ".:直前の\\refと同じ\n" "/:REPEAT LAST \ref{}\n"))
342 (defvar YaTeX-label-menu-any
343 (if YaTeX-japan "*:任意の文字列\n" "*:ANY STRING.\n"))
344 (defvar YaTeX-label-buffer "*Label completions*")
345 (defvar YaTeX-label-guide-msg "Select label and hit RETURN.")
346 (defvar YaTeX-label-select-map nil
347 "Key map used in label selection buffer.")
348 (defun YaTeX::label-setup-key-map ()
349 (if YaTeX-label-select-map nil
350 (message "Setting up label selection mode map...")
351 ;(setq YaTeX-label-select-map (copy-keymap global-map))
352 (setq YaTeX-label-select-map (make-keymap))
353 (suppress-keymap YaTeX-label-select-map)
354 (substitute-all-key-definition
355 'previous-line 'YaTeX::label-previous YaTeX-label-select-map)
356 (substitute-all-key-definition
357 'next-line 'YaTeX::label-next YaTeX-label-select-map)
358 (define-key YaTeX-label-select-map "\C-n" 'YaTeX::label-next)
359 (define-key YaTeX-label-select-map "\C-p" 'YaTeX::label-previous)
360 (define-key YaTeX-label-select-map "<" 'beginning-of-buffer)
361 (define-key YaTeX-label-select-map ">" 'end-of-buffer)
362 (define-key YaTeX-label-select-map "\C-m" 'exit-recursive-edit)
363 (define-key YaTeX-label-select-map "\C-j" 'exit-recursive-edit)
364 (define-key YaTeX-label-select-map " " 'exit-recursive-edit)
365 (define-key YaTeX-label-select-map "\C-g" 'abort-recursive-edit)
366 (define-key YaTeX-label-select-map "/" 'isearch-forward)
367 (define-key YaTeX-label-select-map "?" 'isearch-backward)
368 (define-key YaTeX-label-select-map "'" 'YaTeX::label-search-tag)
369 (define-key YaTeX-label-select-map "." 'YaTeX::label-search-tag)
370 (define-key YaTeX-label-select-map "*" 'YaTeX::label-search-tag)
371 (message "Setting up label selection mode map...Done")
372 (let ((key ?A))
373 (while (<= key ?Z)
374 (define-key YaTeX-label-select-map (char-to-string key)
375 'YaTeX::label-search-tag)
376 (define-key YaTeX-label-select-map (char-to-string (+ key (- ?a ?A)))
377 'YaTeX::label-search-tag)
378 (setq key (1+ key)))))
379 )
380 (defun YaTeX::label-next ()
381 (interactive) (forward-line 1) (message YaTeX-label-guide-msg))
382 (defun YaTeX::label-previous ()
383 (interactive) (forward-line -1) (message YaTeX-label-guide-msg))
384 (defun YaTeX::label-search-tag ()
385 (interactive)
386 (let ((case-fold-search t)
387 (tag (regexp-quote (char-to-string last-command-char))))
388 (cond
389 ((save-excursion
390 (forward-char 1)
391 (re-search-forward (concat "^" tag) nil t))
392 (goto-char (match-beginning 0)))
393 ((save-excursion
394 (goto-char (point-min))
395 (re-search-forward (concat "^" tag) nil t))
396 (goto-char (match-beginning 0))))
397 (message YaTeX-label-guide-msg))
398 )
399 (defun YaTeX::ref (argp &optional labelcmd refcmd)
400 (cond
401 ((= argp 1)
402 (let ((lnum 0) e0 label label-list (buf (current-buffer))
403 (labelcmd (or labelcmd "label")) (refcmd (or refcmd "ref"))
404 (p (point)) initl line cf)
405 (message "Collecting labels...")
406 (save-window-excursion
407 (YaTeX-showup-buffer
408 YaTeX-label-buffer (function (lambda (x) (window-width x))))
409 (if (fboundp 'select-frame) (setq cf (selected-frame)))
410 (if (eq (window-buffer (minibuffer-window)) buf)
411 (progn
412 (other-window 1)
413 (setq buf (current-buffer))
414 (set-buffer buf)
415 ;(message "cb=%s" buf)(sit-for 3)
416 ))
417 (save-excursion
418 (goto-char (point-min))
419 (with-output-to-temp-buffer YaTeX-label-buffer
420 (princ (format "=== LABELS in [%s] ===\n" (buffer-name buf)))
421 (while (YaTeX-re-search-active-forward
422 (concat "\\\\" labelcmd "\\b")
423 (regexp-quote YaTeX-comment-prefix) nil t)
424 (goto-char (match-beginning 0))
425 (skip-chars-forward "^{")
426 (setq label
427 (buffer-substring
428 (1+ (point))
429 (prog2 (forward-list 1) (setq e0 (1- (point)))))
430 label-list (cons label label-list))
431 (or initl
432 (if (< p (point)) (setq initl lnum)))
433 (beginning-of-line)
434 (skip-chars-forward " \t\n" nil)
435 (princ (format "%c:{%s}\t<<%s>>\n" (+ (% lnum 26) ?A) label
436 (buffer-substring (point) (point-end-of-line))))
437 (setq lnum (1+ lnum))
438 (message "Collecting \\%s{}... %d" labelcmd lnum)
439 (goto-char e0))
440 (princ YaTeX-label-menu-other)
441 (princ YaTeX-label-menu-repeat)
442 (princ YaTeX-label-menu-any)
443 );with
444 (goto-char p)
445 (or initl (setq initl lnum))
446 (message "Collecting %s...Done" labelcmd)
447 (if (fboundp 'select-frame) (select-frame cf))
448 (YaTeX-showup-buffer YaTeX-label-buffer nil t)
449 (YaTeX::label-setup-key-map)
450 (setq truncate-lines t)
451 (setq buffer-read-only t)
452 (use-local-map YaTeX-label-select-map)
453 (message YaTeX-label-guide-msg)
454 (goto-line (1+ initl)) ;goto recently defined label line
455 (switch-to-buffer (current-buffer))
456 (unwind-protect
457 (progn
458 (recursive-edit)
459 (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
460 (beginning-of-line)
461 (setq line (1- (count-lines (point-min)(point))))
462 (cond
463 ((= line -1) (setq label ""))
464 ((= line lnum) (setq label (YaTeX-label-other)))
465 ((= line (1+ lnum))
466 (save-excursion
467 (switch-to-buffer buf)
468 (goto-char p)
469 (if (re-search-backward
470 (concat "\\\\" refcmd "{\\([^}]+\\)}") nil t)
471 (setq label (YaTeX-match-string 1))
472 (setq label ""))))
473 ((>= line (+ lnum 2))
474 (setq label (read-string (format "\\%s{???}: " refcmd))))
475 (t (setq label (nth (- lnum line 1) label-list)))))
476 (bury-buffer YaTeX-label-buffer)))
477 label
478 ))
479 ))
480 )
481 (fset 'YaTeX::pageref 'YaTeX::ref)
482 (defun YaTeX::cite (argp)
483 (cond
484 ((eq argp 1)
485 (YaTeX::ref argp "bibitem\\(\\[.*\\]\\)?" "cite"))
486 (t nil)))
488 (defun YaTeX-yatex-buffer-list ()
489 (save-excursion
490 (delq nil (mapcar (function (lambda (buf)
491 (set-buffer buf)
492 (if (eq major-mode 'yatex-mode) buf)))
493 (buffer-list))))
494 )
496 (defun YaTeX-select-other-yatex-buffer ()
497 "Select buffer from all yatex-mode's buffers interactivelly."
498 (interactive)
499 (let ((lbuf "*YaTeX mode buffers*") (blist (YaTeX-yatex-buffer-list))
500 (lnum -1) buf rv
501 (ff "**find-file**"))
502 (YaTeX-showup-buffer
503 lbuf (function (lambda (x) 1))) ;;Select next window surely.
504 (with-output-to-temp-buffer lbuf
505 (while blist
506 (princ
507 (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A)
508 (buffer-name (car blist))))
509 (setq blist (cdr blist)))
510 (princ (format "':{%s}" ff)))
511 (YaTeX-showup-buffer lbuf nil t)
512 (YaTeX::label-setup-key-map)
513 (setq buffer-read-only t)
514 (use-local-map YaTeX-label-select-map)
515 (message YaTeX-label-guide-msg)
516 (unwind-protect
517 (progn
518 (recursive-edit)
519 (set-buffer lbuf)
520 (beginning-of-line)
521 (setq rv
522 (if (re-search-forward "{\\([^\\}]+\\)}" (point-end-of-line) t)
523 (buffer-substring (match-beginning 1) (match-end 1)) nil)))
524 (kill-buffer lbuf))
525 (if (string= rv ff)
526 (progn
527 (call-interactively 'find-file)
528 (current-buffer))
529 rv))
530 )
532 (defun YaTeX-label-other ()
533 (let ((rv (YaTeX-select-other-yatex-buffer)))
534 (cond
535 ((null rv) "")
536 (t
537 (set-buffer rv)
538 (YaTeX::ref argp labelcmd refcmd)))
539 )
540 )
542 ;;
543 ; completion for the arguments of \newcommand
544 ;;
545 (defun YaTeX::newcommand (&optional argp)
546 (cond
547 ((= argp 1)
548 (let ((command (read-string "Define newcommand: " "\\")))
549 (put 'YaTeX::newcommand 'command (substring command 1))
550 command))
551 ((= argp 2)
552 (let ((argc
553 (string-to-int (read-string "Number of arguments(Default 0): ")))
554 (def (read-string "Definition: "))
555 (command (get 'YaTeX::newcommand 'command)))
556 ;;!!! It's illegal to insert string in the add-in function !!!
557 (if (> argc 0) (insert (format "[%d]" argc)))
558 (if (and (stringp command)
559 (string< "" command)
560 (y-or-n-p "Update dictionary?"))
561 (cond
562 ((= argc 0)
563 (YaTeX-update-table
564 (list command)
565 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table))
566 ((= argc 1)
567 (YaTeX-update-table
568 (list command)
569 'section-table 'user-section-table 'tmp-section-table))
570 (t (YaTeX-update-table
571 (list command argc)
572 'section-table 'user-section-table 'tmp-section-table))))
573 (message "")
574 def ;return command name
575 ))
576 (t ""))
577 )
579 ;;
580 ; completion for the arguments of \pagestyle
581 ;;
582 (defun YaTeX::pagestyle (&optional argp)
583 "Read the pagestyle with completion."
584 (completing-read
585 "Page style: "
586 '(("plain") ("empty") ("headings") ("myheadings") ("normal") nil))
587 )
588 (fset 'YaTeX::thispagestyle 'YaTeX::pagestyle)
590 ;;
591 ; completion for the arguments of \pagenumbering
592 ;;
593 (defun YaTeX::pagenumbering (&optional argp)
594 "Read the numbering style."
595 (completing-read
596 "Page numbering style: "
597 '(("arabic") ("Alpha") ("alpha") ("Roman") ("roman")))
598 )
600 ;;
601 ; Length
602 ;;
603 (defvar YaTeX:style-parameters-default
604 '(("\\arraycolsep")
605 ("\\arrayrulewidth")
606 ("\\baselineskip")
607 ("\\columnsep")
608 ("\\columnseprule")
609 ("\\doublerulesep")
610 ("\\evensidemargin")
611 ("\\footheight")
612 ("\\footskip")
613 ("\\headheight")
614 ("\\headsep")
615 ("\\itemindent")
616 ("\\itemsep")
617 ("\\labelsep")
618 ("\\labelwidth")
619 ("\\leftmargin")
620 ("\\linewidth")
621 ("\\listparindent")
622 ("\\marginparsep")
623 ("\\marginparwidth")
624 ("\\mathindent")
625 ("\\oddsidemargin")
626 ("\\parindent")
627 ("\\parsep")
628 ("\\parskip")
629 ("\\partopsep")
630 ("\\rightmargin")
631 ("\\tabcolsep")
632 ("\\textheight")
633 ("\\textwidth")
634 ("\\topmargin")
635 ("\\topsep")
636 ("\\topskip")
637 )
638 "Alist of LaTeX style parameters.")
639 (defvar YaTeX:style-parameters-private nil
640 "*User definable alist of style parameters.")
641 (defvar YaTeX:style-parameters-local nil
642 "*User definable alist of local style parameters.")
644 (defvar YaTeX:length-history nil "Holds history of length.")
645 (put 'YaTeX:length-history 'no-default t)
646 (defun YaTeX::setlength (&optional argp)
647 "YaTeX add-in function for arguments of \\setlength."
648 (cond
649 ((equal 1 argp)
650 ;;(completing-read "Length variable: " YaTeX:style-parameters nil nil "\\")
651 (YaTeX-cplread-with-learning
652 "Length variable: "
653 'YaTeX:style-parameters-default
654 'YaTeX:style-parameters-private
655 'YaTeX:style-parameters-local
656 nil nil "\\")
657 )
658 ((equal 2 argp)
659 (read-string-with-history "Length: " nil 'YaTeX:length-history)))
660 )
661 (fset 'YaTeX::addtolength 'YaTeX::setlength)
663 (defun YaTeX::settowidth (&optional argp)
664 "YaTeX add-in function for arguments of \\settowidth."
665 (cond
666 ((equal 1 argp)
667 (YaTeX-cplread-with-learning
668 "Length variable: "
669 'YaTeX:style-parameters-default
670 'YaTeX:style-parameters-private
671 'YaTeX:style-parameters-local
672 nil nil "\\"))
673 ((equal 2 argp)
674 (read-string "Text: ")))
675 )
676 (defun YaTeX::newlength (&optional argp)
677 "YaTeX add-in function for arguments of \\newlength"
678 (cond
679 ((equal argp 1)
680 (let ((length (read-string "Length variable: " "\\")))
681 (if (string< "" length)
682 (YaTeX-update-table
683 (list length)
684 'YaTeX:style-parameters-default
685 'YaTeX:style-parameters-private
686 'YaTeX:style-parameters-local))
687 length)
688 ))
689 )
691 ;; \multicolumn's arguments
692 (defun YaTeX::multicolumn (&optional argp)
693 "YaTeX add-in function for arguments of \\multicolumn."
694 (cond
695 ((equal 1 argp)
696 (read-string "Number of columns: "))
697 ((equal 2 argp)
698 (let (c)
699 (while (not (string-match
700 (progn (message "Format(one of l,r,c): ")
701 (setq c (char-to-string (read-char))))
702 "lrc")))
703 c))
704 ((equal 3 argp)
705 (read-string "Item: ")))
706 )
708 (defvar YaTeX:documentstyles-default
709 '(("article") ("jarticle") ("j-article")
710 ("book") ("jbook") ("j-book")
711 ("report") ("jreport") ("j-report")
712 ("letter") ("ascjletter"))
713 "List of LaTeX documentstyles.")
714 (defvar YaTeX:documentstyles-private nil
715 "*User defined list of LaTeX documentstyles.")
716 (defvar YaTeX:documentstyles-local nil
717 "*User defined list of local LaTeX documentstyles.")
718 (defvar YaTeX:documentstyle-options-default
719 '(("a4j") ("a5j") ("b4j") ("b5j")
720 ("twocolumn") ("jtwocolumn") ("epsf") ("epsfig") ("epsbox") ("nfig"))
721 "List of LaTeX documentstyle options.")
722 (defvar YaTeX:documentstyle-options-private nil
723 "*User defined list of LaTeX documentstyle options.")
724 (defvar YaTeX:documentstyle-options-local nil
725 "List of LaTeX local documentstyle options.")
727 (defvar YaTeX-minibuffer-completion-map nil
728 "Minibuffer completion key map that allows comma completion.")
729 (if YaTeX-minibuffer-completion-map nil
730 (setq YaTeX-minibuffer-completion-map
731 (copy-keymap minibuffer-local-completion-map))
732 (define-key YaTeX-minibuffer-completion-map " "
733 'YaTeX-minibuffer-complete)
734 (define-key YaTeX-minibuffer-completion-map "\t"
735 'YaTeX-minibuffer-complete))
737 (defun YaTeX:documentstyle ()
738 (let*((delim ",")
739 (dt (append YaTeX:documentstyle-options-local
740 YaTeX:documentstyle-options-private
741 YaTeX:documentstyle-options-default))
742 (minibuffer-completion-table dt)
743 (opt (read-from-minibuffer
744 "Style options ([opt1,opt2,...]): "
745 nil YaTeX-minibuffer-completion-map nil))
746 (substr opt) o)
747 (if (string< "" opt)
748 (progn
749 (while substr
750 (setq o (substring substr 0 (string-match delim substr)))
751 (or (assoc o dt)
752 (YaTeX-update-table
753 (list o)
754 'YaTeX:documentstyle-options-default
755 'YaTeX:documentstyle-options-private
756 'YaTeX:documentstyle-options-local))
757 (setq substr
758 (if (string-match delim substr)
759 (substring substr (1+ (string-match delim substr))))))
760 (concat "[" opt "]"))
761 "")))
763 (defun YaTeX::documentstyle (&optional argp)
764 "YaTeX add-in function for arguments of \\documentstyle."
765 (cond
766 ((equal argp 1)
767 (setq env-name "document")
768 (let ((sname
769 (YaTeX-cplread-with-learning
770 (format "Documentstyle (default %s): "
771 YaTeX-default-document-style)
772 'YaTeX:documentstyles-default
773 'YaTeX:documentstyles-private
774 'YaTeX:documentstyles-local)))
775 (if (string= "" sname) (setq sname YaTeX-default-document-style))
776 (setq YaTeX-default-document-style sname))))
777 )
779 ;;; -------------------- LaTeX2e stuff --------------------
780 (defvar YaTeX:documentclass-options-default
781 '(("a4paper") ("a5paper") ("b5paper") ("10pt") ("11pt") ("12pt")
782 ("latterpaper") ("legalpaper") ("executivepaper") ("landscape")
783 ("oneside") ("twoside") ("draft") ("final") ("leqno") ("fleqn") ("openbib")
784 ("clock") ;for slides class only
785 )
786 "Default options list for documentclass")
787 (defvar YaTeX:documentclass-options-private nil
788 "*User defined options list for documentclass")
789 (defvar YaTeX:documentclass-options-local nil
790 "*User defined options list for local documentclass")
792 (defun YaTeX:documentclass ()
793 (let*((delim ",")
794 (dt (append YaTeX:documentclass-options-local
795 YaTeX:documentclass-options-private
796 YaTeX:documentclass-options-default))
797 (minibuffer-completion-table dt)
798 (opt (read-from-minibuffer
799 "Documentclass options ([opt1,opt2,...]): "
800 nil YaTeX-minibuffer-completion-map nil))
801 (substr opt) o)
802 (if (string< "" opt)
803 (progn
804 (while substr
805 (setq o (substring substr 0 (string-match delim substr)))
806 (or (assoc o dt)
807 (YaTeX-update-table
808 (list o)
809 'YaTeX:documentclass-options-default
810 'YaTeX:documentclass-options-private
811 'YaTeX:documentclass-options-local))
812 (setq substr
813 (if (string-match delim substr)
814 (substring substr (1+ (string-match delim substr))))))
815 (concat "[" opt "]"))
816 "")))
818 (defvar YaTeX:documentclasses-default
819 '(("article") ("jarticle") ("report") ("jreport") ("book") ("jbook")
820 ("j-article") ("j-report") ("j-book")
821 ("letter") ("slides") ("ltxdoc") ("ltxguide") ("ltnews") ("proc"))
822 "Default documentclass alist")
823 (defvar YaTeX:documentclasses-private nil
824 "*User defined documentclass alist")
825 (defvar YaTeX:documentclasses-local nil
826 "*User defined local documentclass alist")
827 (defvar YaTeX-default-documentclass (if YaTeX-japan "jarticle" "article")
828 "*Default documentclass")
830 (defun YaTeX::documentclass (&optional argp)
831 (cond
832 ((equal argp 1)
833 (setq env-name "document")
834 (let ((sname
835 (YaTeX-cplread-with-learning
836 (format "Documentclass (default %s): " YaTeX-default-documentclass)
837 'YaTeX:documentclasses-default
838 'YaTeX:documentclasses-private
839 'YaTeX:documentclasses-local)))
840 (if (string= "" sname) (setq sname YaTeX-default-documentclass))
841 (setq YaTeX-default-documentclass sname)))))
843 (defun YaTeX:caption ()
844 (setq section-name "label")
845 nil)
847 ;;; -------------------- math-mode stuff --------------------
848 (defun YaTeX::tilde (&optional pos)
849 "For accent macros in mathmode"
850 (cond
851 ((equal pos 1)
852 (message "Put accent on variable: ")
853 (let ((v (char-to-string (read-char))) (case-fold-search nil))
854 (message "")
855 (cond
856 ((string-match "i\\|j" v)
857 (concat "\\" v "math"))
858 ((string-match "[\r\n\t ]" v)
859 "")
860 (t v))))
861 (nil "")))
863 (fset 'YaTeX::hat 'YaTeX::tilde)
864 (fset 'YaTeX::check 'YaTeX::tilde)
865 (fset 'YaTeX::bar 'YaTeX::tilde)
866 (fset 'YaTeX::dot 'YaTeX::tilde)
867 (fset 'YaTeX::ddot 'YaTeX::tilde)
868 (fset 'YaTeX::vec 'YaTeX::tilde)
870 (defun YaTeX::widetilde (&optional pos)
871 "For multichar accent macros in mathmode"
872 (cond
873 ((equal pos 1)
874 (let ((m "Put over chars[%s ]: ") v v2)
875 (message m " ")
876 (setq v (char-to-string (read-char)))
877 (message "")
878 (if (string-match "[\r\n\t ]" v)
879 ""
880 (message m v)
881 (setq v2 (char-to-string (read-char)))
882 (message "")
883 (if (string-match "[\r\n\t ]" v2)
884 v
885 (concat v v2)))))
886 (nil "")))
888 (fset 'YaTeX::widehat 'YaTeX::widetilde)
889 (fset 'YaTeX::overline 'YaTeX::widetilde)
890 (fset 'YaTeX::overrightarrow 'YaTeX::widetilde)
893 ;;;
894 ;; Add-in functions for large-type command.
895 ;;;
896 (defun YaTeX:em ()
897 (cond
898 ((eq YaTeX-current-completion-type 'large) "\\/")
899 (t nil)))
900 (fset 'YaTeX:it 'YaTeX:em)
902 ;;; -------------------- End of yatexadd --------------------
903 (provide 'yatexadd)