yatex

view yatexadd.el @ 34:c61405ef1bd1

Change the message of dictionary selection menu.
author yuuji
date Wed, 13 Jul 1994 16:11:27 +0000
parents adc2f1472409
children ef686a35472d
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX add-in functions.
3 ;;; yatexadd.el rev.9
4 ;;; (c )1991-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
5 ;;; Last modified Mon Jun 27 17:00:19 1994 on figaro
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))
55 (message "Dont forget to remove null line at the end of tabular.")
56 (format "%s%s{%s}%s"
57 width loc rule
58 (if (and (boundp 'region-mode) region-mode)
59 "" ;do nothing in region-mode
60 (format "\n%s\n%s \\\\ \\hline\n%s\n\\\\ %s"
61 hline and and hline))))
62 )
63 (fset 'YaTeX:tabular* 'YaTeX:tabular)
64 (defun YaTeX:array ()
65 (concat (YaTeX:read-position "tb")
66 "{" (read-string "Column format: ") "}")
67 )
69 (defun YaTeX:read-oneof (oneof)
70 (let ((pos "") loc (guide ""))
71 (and (boundp 'name) name (setq guide (format "%s " name)))
72 (while (not (string-match
73 (setq loc (read-key-sequence
74 (format "%s position (`%s') [%s]: "
75 guide oneof pos)));name is in YaTeX-addin
76 "\r\^g\n"))
77 (cond
78 ((string-match loc oneof)
79 (if (not (string-match loc pos))
80 (setq pos (concat pos loc))))
81 ((and (string-match loc "\C-h\C-?") (> (length pos) 0))
82 (setq pos (substring pos 0 (1- (length pos)))))
83 (t
84 (ding)
85 (message "Please input one of `%s'." oneof)
86 (sit-for 3))))
87 (message "")
88 pos)
89 )
91 (defun YaTeX:read-position (oneof)
92 "Read a LaTeX (optional) position format such as `[htbp]'."
93 (let ((pos (YaTeX:read-oneof oneof)))
94 (if (string= pos "") "" (concat "[" pos "]")))
95 )
97 (defun YaTeX:table ()
98 "YaTeX add-in function for table environment."
99 (YaTeX:read-position "htbp")
100 )
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 (if (fboundp 'YaTeX-toggle-math-mode)
124 (YaTeX-toggle-math-mode t)) ;force math-mode ON.
125 )
126 (fset 'YaTeX:eqnarray 'YaTeX:equation)
127 (fset 'YaTeX:displaymath 'YaTeX:equation)
129 (defun YaTeX:list ()
130 "%\n{} %default label\n{} %formatting parameter"
131 )
133 (defun YaTeX:minipage ()
134 (concat (YaTeX:read-position "cbt")
135 "{" (read-string "Width: ") "}")
136 )
138 ;;;
139 ;;Sample functions for section-type command.
140 ;;;
141 (defun YaTeX:multiput ()
142 (concat (YaTeX:read-coordinates "Pos")
143 (YaTeX:read-coordinates "Step")
144 "{" (read-string "How many times: ") "}")
145 )
147 (defun YaTeX:put ()
148 (YaTeX:read-coordinates "Pos")
149 )
151 (defun YaTeX:makebox ()
152 (cond
153 ((YaTeX-in-environment-p "picture")
154 (concat (YaTeX:read-coordinates "Dimension")
155 (YaTeX:read-position "lrtb")))
156 (t
157 (let ((width (read-string "Width: ")))
158 (if (string< "" width)
159 (progn
160 (or (equal (aref width 0) ?\[)
161 (setq width (concat "[" width "]")))
162 (concat width (YaTeX:read-position "lr")))))))
163 )
165 (defun YaTeX:framebox ()
166 (if (YaTeX-quick-in-environment-p "picture")
167 (YaTeX:makebox))
168 )
170 (defun YaTeX:dashbox ()
171 (concat "{" (read-string "Dash dimension: ") "}"
172 (YaTeX:read-coordinates "Dimension"))
173 )
175 (defun YaTeX:left ()
176 (let (c)
177 (while (not (string-match
178 (progn (message "Which parenthesis? One of [{(|)}]: ")
179 (setq c (regexp-quote (char-to-string (read-char)))))
180 "[{(|)}]")))
181 (setq single-command "right")
182 (cond
183 ((string-match c "[(|)]") c)
184 (t (concat "\\" c))))
185 )
186 (fset 'YaTeX:right 'YaTeX:left)
188 (defun YaTeX:read-coordinates (&optional mes varX varY)
189 (concat
190 "("
191 (read-string (format "%s %s: " (or mes "Dimension") (or varX "X")))
192 ","
193 (read-string (format "%s %s: " (or mes "Dimension") (or varY "Y")))
194 ")")
195 )
197 ;;;
198 ;;Sample functions for maketitle-type command.
199 ;;;
200 (defun YaTeX:sum ()
201 "Read range of summation."
202 (YaTeX:check-completion-type 'maketitle)
203 (concat (YaTeX:read-boundary "_") (YaTeX:read-boundary "^"))
204 )
206 (fset 'YaTeX:int 'YaTeX:sum)
208 (defun YaTeX:lim ()
209 "Insert limit notation of \\lim."
210 (YaTeX:check-completion-type 'maketitle)
211 (let ((var (read-string "Variable: ")) limit)
212 (if (string= "" var) ""
213 (setq limit (read-string "Limit ($ means infinity): "))
214 (if (string= "$" limit) (setq limit "\\infty"))
215 (concat "_{" var " \\rightarrow " limit "}")))
216 )
218 (defun YaTeX:gcd ()
219 "Add-in function for \\gcd(m,n)."
220 (YaTeX:check-completion-type 'maketitle)
221 (YaTeX:read-coordinates "\\gcd" "(?,)" "(,?)")
222 )
224 (defun YaTeX:read-boundary (ULchar)
225 "Read boundary usage by _ or ^. _ or ^ is indicated by argument ULchar."
226 (let ((bndry (read-string (concat ULchar "{???} ($ for infinity): "))))
227 (if (string= bndry "") ""
228 (if (string= bndry "$") (setq bndry "\\infty"))
229 (concat ULchar "{" bndry "}")))
230 )
232 (defun YaTeX:verb ()
233 "Enclose \\verb's contents with the same characters."
234 (let ((quote-char (read-string "Quoting char: " "|"))
235 (contents (read-string "Quoted contents: ")))
236 (concat quote-char contents quote-char))
237 )
238 (fset 'YaTeX:verb* 'YaTeX:verb)
240 ;;;
241 ;;Subroutine
242 ;;;
244 (defun YaTeX:check-completion-type (type)
245 "Check valid completion type."
246 (if (not (eq type YaTeX-current-completion-type))
247 (error "This should be completed with %s-type completion." type))
248 )
251 ;;;
252 ;;; [[Add-in functions for reading section arguments]]
253 ;;;
254 ;; All of add-in functions for reading sections arguments should
255 ;; take an argument ARGP that specify the argument position.
256 ;; If argument position is out of range, nil should be returned,
257 ;; else nil should NOT be returned.
259 ;;
260 ; Label selection
261 ;;
262 (defvar YaTeX-label-menu-other
263 (if YaTeX-japan "':他のバッファのラベル\n" "':LABEL IN OTHER BUFFER.\n"))
264 (defvar YaTeX-label-menu-repeat
265 (if YaTeX-japan ".:直前の\\refと同じ\n" "/:REPEAT LAST \ref{}\n"))
266 (defvar YaTeX-label-menu-any
267 (if YaTeX-japan "*:任意の文字列\n" "*:ANY STRING.\n"))
268 (defvar YaTeX-label-buffer "*Label completions*")
269 (defvar YaTeX-label-guide-msg "Select label and hit RETURN.")
270 (defvar YaTeX-label-select-map nil
271 "Key map used in label selection buffer.")
272 (defun YaTeX::label-setup-key-map ()
273 (if YaTeX-label-select-map nil
274 (message "Setting up label selection mode map...")
275 (setq YaTeX-label-select-map (copy-keymap global-map))
276 (suppress-keymap YaTeX-label-select-map)
277 (substitute-all-key-definition
278 'previous-line 'YaTeX::label-previous YaTeX-label-select-map)
279 (substitute-all-key-definition
280 'next-line 'YaTeX::label-next YaTeX-label-select-map)
281 (define-key YaTeX-label-select-map "\C-n" 'YaTeX::label-next)
282 (define-key YaTeX-label-select-map "\C-p" 'YaTeX::label-previous)
283 (define-key YaTeX-label-select-map "<" 'beginning-of-buffer)
284 (define-key YaTeX-label-select-map ">" 'end-of-buffer)
285 (define-key YaTeX-label-select-map "\C-m" 'exit-recursive-edit)
286 (define-key YaTeX-label-select-map "\C-j" 'exit-recursive-edit)
287 (define-key YaTeX-label-select-map " " 'exit-recursive-edit)
288 (define-key YaTeX-label-select-map "\C-g" 'abort-recursive-edit)
289 (define-key YaTeX-label-select-map "/" 'isearch-forward)
290 (define-key YaTeX-label-select-map "?" 'isearch-backward)
291 (define-key YaTeX-label-select-map "'" 'YaTeX::label-search-tag)
292 (define-key YaTeX-label-select-map "." 'YaTeX::label-search-tag)
293 (define-key YaTeX-label-select-map "*" 'YaTeX::label-search-tag)
294 (message "Setting up label selection mode map...Done")
295 (let ((key ?A))
296 (while (<= key ?Z)
297 (define-key YaTeX-label-select-map (char-to-string key)
298 'YaTeX::label-search-tag)
299 (define-key YaTeX-label-select-map (char-to-string (+ key (- ?a ?A)))
300 'YaTeX::label-search-tag)
301 (setq key (1+ key)))))
302 )
303 (defun YaTeX::label-next ()
304 (interactive) (forward-line 1) (message YaTeX-label-guide-msg))
305 (defun YaTeX::label-previous ()
306 (interactive) (forward-line -1) (message YaTeX-label-guide-msg))
307 (defun YaTeX::label-search-tag ()
308 (interactive)
309 (let ((case-fold-search t) (tag (regexp-quote (this-command-keys))))
310 (cond
311 ((save-excursion
312 (forward-char 1)
313 (re-search-forward (concat "^" tag) nil t))
314 (goto-char (match-beginning 0)))
315 ((save-excursion
316 (goto-char (point-min))
317 (re-search-forward (concat "^" tag) nil t))
318 (goto-char (match-beginning 0))))
319 (message YaTeX-label-guide-msg))
320 )
321 (defun YaTeX::ref (argp)
322 (cond
323 ((= argp 1)
324 (save-excursion
325 (let ((lnum 0) e0 m1 e1 label label-list (buf (current-buffer))
326 (p (point)) initl line)
327 (goto-char (point-min))
328 (message "Collecting labels...")
329 (save-window-excursion
330 (YaTeX-showup-buffer
331 YaTeX-label-buffer (function (lambda (x) (window-width x))))
332 (with-output-to-temp-buffer YaTeX-label-buffer
333 (while (re-search-forward "\\label{\\([^}]+\\)}" nil t)
334 (setq e0 (match-end 0) m1 (match-beginning 1) e1 (match-end 1))
335 (if (search-backward
336 YaTeX-comment-prefix (point-beginning-of-line) t) nil
337 (setq label (buffer-substring m1 e1)
338 label-list (cons label label-list))
339 (or initl
340 (if (< p (point)) (setq initl lnum)))
341 (beginning-of-line)
342 (skip-chars-forward " \t\n" nil)
343 (princ (format "%c:{%s}\t<<%s>>\n" (+ (% lnum 26) ?A) label
344 (buffer-substring (point) (point-end-of-line))))
345 (setq lnum (1+ lnum))
346 (message "Collecting \\label{}... %d" lnum))
347 (goto-char e0))
348 (princ YaTeX-label-menu-other)
349 (princ YaTeX-label-menu-repeat)
350 (princ YaTeX-label-menu-any)
351 );with
352 (goto-char p)
353 (message "Collecting labels...Done")
354 (pop-to-buffer YaTeX-label-buffer)
355 (YaTeX::label-setup-key-map)
356 (setq truncate-lines t)
357 (setq buffer-read-only t)
358 (use-local-map YaTeX-label-select-map)
359 (message YaTeX-label-guide-msg)
360 (goto-line (or initl lnum)) ;goto recently defined label line
361 (unwind-protect
362 (progn
363 (recursive-edit)
364 (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
365 (beginning-of-line)
366 (setq line (count-lines (point-min)(point)))
367 (cond
368 ((= line lnum) (setq label (YaTeX-label-other)))
369 ((= line (1+ lnum))
370 (save-excursion
371 (switch-to-buffer buf)
372 (goto-char p)
373 (if (re-search-backward "\\\\ref{\\([^}]+\\)}" nil t)
374 (setq label (buffer-substring
375 (match-beginning 1) (match-end 1)))
376 (setq label ""))))
377 ((>= line (+ lnum 2))
378 (setq label (read-string "\\ref{???}: ")))
379 (t (setq label (nth (- lnum line 1) label-list)))))
380 (bury-buffer YaTeX-label-buffer)))
381 label
382 ))
383 ))
384 )
385 (fset 'YaTeX::pageref 'YaTeX::ref)
387 (defun YaTeX-label-other ()
388 (let ((lbuf "*YaTeX mode buffers*") (blist (buffer-list)) (lnum -1) buf rv
389 (ff "**find-file**"))
390 (YaTeX-showup-buffer
391 lbuf (function (lambda (x) 1))) ;;Select next window surely.
392 (with-output-to-temp-buffer lbuf
393 (while blist
394 (if (and (buffer-file-name (setq buf (car blist)))
395 (progn (set-buffer buf) (eq major-mode 'yatex-mode)))
396 (princ
397 (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A)
398 (buffer-name buf))))
399 (setq blist (cdr blist)))
400 (princ (format "':{%s}" ff)))
401 (pop-to-buffer lbuf)
402 (YaTeX::label-setup-key-map)
403 (setq buffer-read-only t)
404 (use-local-map YaTeX-label-select-map)
405 (message YaTeX-label-guide-msg)
406 (unwind-protect
407 (progn
408 (recursive-edit)
409 (set-buffer lbuf)
410 (beginning-of-line)
411 (setq rv
412 (if (re-search-forward "{\\([^\\}]+\\)}" (point-end-of-line) t)
413 (buffer-substring (match-beginning 1) (match-end 1)) nil)))
414 (kill-buffer lbuf))
415 (cond
416 ((null rv) "")
417 ((string= rv ff)
418 (call-interactively 'find-file)
419 (YaTeX::ref argp))
420 (t
421 (set-buffer rv)
422 (YaTeX::ref argp)))
423 )
424 )
426 ;;
427 ; completion for the arguments of \newcommand
428 ;;
429 (defun YaTeX::newcommand (&optional argp)
430 (cond
431 ((= argp 1)
432 (let ((command (read-string "Define newcommand: " "\\")))
433 (put 'YaTeX::newcommand 'command (substring command 1))
434 command))
435 ((= argp 2)
436 (let ((argc
437 (string-to-int (read-string "Number of arguments(Default 0): ")))
438 (def (read-string "Definition: "))
439 (command (get 'YaTeX::newcommand 'command)))
440 ;;!!! It's illegal to insert string in the add-in function !!!
441 (if (> argc 0) (insert (format "[%d]" argc)))
442 (if (and (stringp command)
443 (string< "" command)
444 (y-or-n-p "Update user completion table?"))
445 (cond
446 ((= argc 0)
447 (YaTeX-update-table
448 (list command)
449 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table))
450 ((= argc 1)
451 (YaTeX-update-table
452 (list command)
453 'section-table 'user-section-table 'tmp-section-table))
454 (t (YaTeX-update-table
455 (list command argc)
456 'section-table 'user-section-table 'tmp-section-table))))
457 (message "")
458 def ;return command name
459 ))
460 (t ""))
461 )
463 ;;
464 ; completion for the arguments of \pagestyle
465 ;;
466 (defun YaTeX::pagestyle (&optional argp)
467 "Read the pagestyle with completion."
468 (completing-read
469 "Page style: "
470 '(("plain") ("empty") ("headings") ("myheadings") ("normal") nil))
471 )
472 ;;
473 ; completion for the arguments of \pagenumbering
474 ;;
475 (defun YaTeX::pagenumbering (&optional argp)
476 "Read the numbering style."
477 (completing-read
478 "Page numbering style: "
479 '(("arabic") ("Alpha") ("alpha") ("Roman") ("roman")))
480 )
482 ;;
483 ; Length
484 ;;
485 (defvar YaTeX:style-parameters-default
486 '(("\\arraycolsep")
487 ("\\arrayrulewidth")
488 ("\\baselineskip")
489 ("\\columnsep")
490 ("\\columnseprule")
491 ("\\doublerulesep")
492 ("\\evensidemargin")
493 ("\\footheight")
494 ("\\footskip")
495 ("\\headheight")
496 ("\\headsep")
497 ("\\itemindent")
498 ("\\itemsep")
499 ("\\labelsep")
500 ("\\labelwidth")
501 ("\\leftmargin")
502 ("\\linewidth")
503 ("\\listparindent")
504 ("\\marginparsep")
505 ("\\marginparwidth")
506 ("\\mathindent")
507 ("\\oddsidemargin")
508 ("\\parindent")
509 ("\\parsep")
510 ("\\parskip")
511 ("\\partopsep")
512 ("\\rightmargin")
513 ("\\tabcolsep")
514 ("\\textheight")
515 ("\\textwidth")
516 ("\\topmargin")
517 ("\\topsep")
518 ("\\topskip")
519 )
520 "Alist of LaTeX style parameters.")
521 (defvar YaTeX:style-parameters-private nil
522 "*User definable alist of style parameters.")
523 (defvar YaTeX:style-parameters-private nil
524 "Holds the union of LaTeX style parameters.")
525 (setq YaTeX:style-parameters
526 (append YaTeX:style-parameters-private YaTeX:style-parameters-default))
528 (defvar YaTeX:length-history nil "Holds history of length.")
529 (defun YaTeX::setlength (&optional argp)
530 "YaTeX add-in function for arguments of \\setlength."
531 (cond
532 ((equal 1 argp)
533 (completing-read "Length variable: " YaTeX:style-parameters nil nil "\\"))
534 ((equal 2 argp)
535 (let ((minibuffer-history-symbol 'YaTeX:length-history))
536 (read-string "Length: "))))
537 )
538 (fset 'YaTeX::addtolength 'YaTeX::setlength)
540 (defun YaTeX::settowidth (&optional argp)
541 "YaTeX add-in function for arguments of \\settowidth."
542 (cond
543 ((equal 1 argp)
544 (completing-read "Length variable: " YaTeX:style-parameters nil nil "\\"))
545 ((equal 2 argp)
546 (read-string "Text: ")))
547 )
548 (defun YaTeX::newlength (&optional argp)
549 "YaTeX add-in function for arguments of \\newlength"
550 (cond
551 ((equal argp 1)
552 (let ((length (read-string "Length variable: " "\\")))
553 (or (assoc length YaTeX:style-parameters-private)
554 (setq YaTeX:style-parameters-private
555 (cons (list length) YaTeX:style-parameters-private)
556 YaTeX:style-parameters
557 (cons (list length) YaTeX:style-parameters)))
558 length)))
559 )
561 ;; \multicolumn's arguments
562 (defun YaTeX::multicolumn (&optional argp)
563 "YaTeX add-in function for arguments of \\multicolumn."
564 (cond
565 ((equal 1 argp)
566 (read-string "Number of columns: "))
567 ((equal 2 argp)
568 (let (c)
569 (while (not (string-match
570 (progn (message "Format(one of l,r,c): ")
571 (setq c (char-to-string (read-char))))
572 "lrc")))
573 c))
574 ((equal 3 argp)
575 (read-string "Item: ")))
576 )
578 ;;; -------------------- End of yatexadd --------------------
579 (provide 'yatexadd)