yatex

view yatexadd.el @ 60:9e08ed569d80

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