yatex

view yatexadd.el @ 59:48ac97a6b6ce

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