6
|
1 ;;; -*- Emacs-Lisp -*-
|
8
|
2 ;;; YaTeX add-in functions.
|
14
|
3 ;;; yatexadd.el rev.7
|
|
4 ;;; (c )1991-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
|
|
5 ;;; Last modified Sat Apr 23 02:26:47 1994 on pajero
|
8
|
6 ;;; $Id$
|
6
|
7
|
|
8 (provide 'yatexadd)
|
|
9
|
|
10 ;;;
|
|
11 ;;Sample functions for LaTeX environment.
|
|
12 ;;;
|
|
13 (defvar YaTeX:tabular-default-rule
|
|
14 "@{\\vrule width 1pt\\ }c|c|c@{\\ \\vrule width 1pt}"
|
|
15 "*Your favorite default rule format."
|
|
16 )
|
|
17 (defun YaTeX:tabular ()
|
8
|
18 "YaTeX add-in function for tabular environment."
|
|
19 (let (bars (rule "") (j 0) (loc (YaTeX:read-position "tb")))
|
6
|
20 (setq bars (string-to-int (read-string "Number of `|': ")))
|
|
21 (if (> bars 0)
|
|
22 (while (< j bars) (setq rule (concat rule "|")) (setq j (1+ j)))
|
|
23 (setq rule YaTeX:tabular-default-rule))
|
|
24 (setq rule (read-string "rule format: " rule))
|
|
25
|
8
|
26 (message "")
|
|
27 (format "%s{%s}" loc rule))
|
6
|
28 )
|
|
29
|
8
|
30 (defun YaTeX:read-position (oneof)
|
|
31 (let ((pos "") loc)
|
6
|
32 (while (not (string-match
|
8
|
33 (setq loc (read-key-sequence
|
|
34 (format "Position (`%s') [%s]: " oneof pos)))
|
6
|
35 "\r\^g\n"))
|
|
36 (cond
|
8
|
37 ((string-match loc oneof)
|
6
|
38 (if (not (string-match loc pos))
|
|
39 (setq pos (concat pos loc))))
|
|
40 ((and (string-match loc "\C-h\C-?") (> (length pos) 0))
|
|
41 (setq pos (substring pos 0 (1- (length pos)))))
|
|
42 (t
|
|
43 (ding)
|
8
|
44 (message "Please input one of `%s'." oneof)
|
6
|
45 (sit-for 3))))
|
8
|
46 (message "")
|
|
47 (if (string= pos "") ""
|
|
48 (concat "[" pos "]")))
|
|
49 )
|
|
50
|
|
51 (defun YaTeX:table ()
|
|
52 "YaTeX add-in function for table environment."
|
|
53 (YaTeX:read-position "htbp")
|
6
|
54 )
|
|
55
|
|
56 (defun YaTeX:description ()
|
|
57 "Truly poor service:-)"
|
|
58 (setq single-command "item[]")
|
8
|
59 ""
|
6
|
60 )
|
|
61
|
|
62 (defun YaTeX:itemize ()
|
|
63 "It's also poor service."
|
|
64 (setq single-command "item")
|
8
|
65 ""
|
6
|
66 )
|
|
67
|
|
68 (fset 'YaTeX:enumerate 'YaTeX:itemize)
|
8
|
69
|
11
|
70 (defun YaTeX:picture ()
|
|
71 "Ask the size of coordinates of picture environment."
|
|
72 (concat (YaTeX:read-coordinates "Picture size")
|
|
73 (YaTeX:read-coordinates "Initial position"))
|
|
74 )
|
|
75
|
12
|
76 (defun YaTeX:equation ()
|
|
77 (if (fboundp 'YaTeX-toggle-math-mode)
|
|
78 (YaTeX-toggle-math-mode t)) ;force math-mode ON.
|
|
79 )
|
|
80 (fset 'YaTeX:eqnarray 'YaTeX:equation)
|
|
81 (fset 'YaTeX:displaymath 'YaTeX:equation)
|
|
82
|
8
|
83 ;;;
|
|
84 ;;Sample functions for section-type command.
|
|
85 ;;;
|
|
86 (defun YaTeX:multiput ()
|
|
87 (concat (YaTeX:read-coordinates "Pos")
|
|
88 (YaTeX:read-coordinates "Step")
|
|
89 "{" (read-string "How many times: ") "}")
|
|
90 )
|
|
91
|
|
92 (defun YaTeX:put ()
|
|
93 (YaTeX:read-coordinates "Pos")
|
|
94 )
|
|
95
|
|
96 (defun YaTeX:makebox ()
|
|
97 (concat (YaTeX:read-coordinates "Dimension")
|
|
98 (YaTeX:read-position "lrtb"))
|
|
99 )
|
|
100
|
|
101 (defun YaTeX:framebox ()
|
|
102 (if (YaTeX-quick-in-environment-p "picture")
|
|
103 (YaTeX:makebox))
|
|
104 )
|
|
105
|
|
106 (defun YaTeX:dashbox ()
|
|
107 (concat "{" (read-string "Dash dimension: ") "}"
|
|
108 (YaTeX:read-coordinates "Dimension"))
|
|
109 )
|
|
110
|
|
111 (defun YaTeX:read-coordinates (&optional mes varX varY)
|
|
112 (concat
|
|
113 "("
|
|
114 (read-string (format "%s %s: " (or mes "Dimension") (or varX "X")))
|
|
115 ","
|
|
116 (read-string (format "%s %s: " (or mes "Dimension") (or varY "Y")))
|
|
117 ")")
|
|
118 )
|
|
119
|
|
120 ;;;
|
|
121 ;;Sample functions for maketitle-type command.
|
|
122 ;;;
|
|
123 (defun YaTeX:sum ()
|
|
124 "Read range of summation."
|
|
125 (YaTeX:check-completion-type 'maketitle)
|
|
126 (concat (YaTeX:read-boundary "_") (YaTeX:read-boundary "^"))
|
|
127 )
|
|
128
|
|
129 (fset 'YaTeX:int 'YaTeX:sum)
|
|
130
|
|
131 (defun YaTeX:lim ()
|
|
132 "Insert limit notation of \\lim."
|
|
133 (YaTeX:check-completion-type 'maketitle)
|
|
134 (let ((var (read-string "Variable: ")) limit)
|
|
135 (if (string= "" var) ""
|
|
136 (setq limit (read-string "Limit ($ means infinity): "))
|
|
137 (if (string= "$" limit) (setq limit "\\infty"))
|
|
138 (concat "_{" var " \\rightarrow " limit "}")))
|
|
139 )
|
|
140
|
|
141 (defun YaTeX:gcd ()
|
|
142 "Add-in function for \\gcd(m,n)."
|
|
143 (YaTeX:check-completion-type 'maketitle)
|
|
144 (YaTeX:read-coordinates "\\gcd" "(?,)" "(,?)")
|
|
145 )
|
|
146
|
|
147 (defun YaTeX:read-boundary (ULchar)
|
|
148 "Read boundary usage by _ or ^. _ or ^ is indicated by argument ULchar."
|
11
|
149 (let ((bndry (read-string (concat ULchar "{???} ($ for infinity): "))))
|
8
|
150 (if (string= bndry "") ""
|
11
|
151 (if (string= bndry "$") (setq bndry "\\infty"))
|
8
|
152 (concat ULchar "{" bndry "}")))
|
|
153 )
|
|
154
|
14
|
155 (defun YaTeX:verb ()
|
|
156 "Enclose \\verb's contents with the same characters."
|
|
157 (let ((quote-char (read-string "Quoting char: " "|"))
|
|
158 (contents (read-string "Quoted contents: ")))
|
|
159 (concat quote-char contents quote-char))
|
|
160 )
|
|
161
|
|
162 ;;;
|
|
163 ;;Subroutine
|
|
164 ;;;
|
|
165
|
8
|
166 (defun YaTeX:check-completion-type (type)
|
|
167 "Check valid completion type."
|
|
168 (if (not (eq type YaTeX-current-completion-type))
|
|
169 (error "This should be completed with %s-type completion." type))
|
|
170 )
|
11
|
171
|
|
172
|
|
173 ;;;
|
|
174 ;;; [[Add-in functions for reading section arguments]]
|
|
175 ;;;
|
|
176 ;; All of add-in functions for reading sections arguments should
|
|
177 ;; take an argument ARGP that specify the argument position.
|
|
178 ;; If argument position is out of range, nil should be returned,
|
|
179 ;; else nil should NOT be returned.
|
13
|
180
|
|
181 ;;
|
|
182 ; Label selection
|
|
183 ;;
|
11
|
184 (defvar YaTeX-label-menu-other
|
|
185 (if YaTeX-japan "':‘¼‚̃oƒbƒtƒ@‚̃‰ƒxƒ‹\n" "':LABEL IN OTHER BUFFER.\n"))
|
|
186 (defvar YaTeX-label-menu-any
|
|
187 (if YaTeX-japan "*:”CˆÓ‚Ì•¶Žš—ñ\n" "*:ANY STRING.\n"))
|
|
188 (defvar YaTeX-label-buffer "*Label completions*")
|
|
189 (defvar YaTeX-label-guide-msg "Select label and hit RETURN.")
|
|
190 (defvar YaTeX-label-select-map nil
|
|
191 "Key map used in label selection buffer.")
|
|
192 (defun YaTeX::label-setup-key-map ()
|
|
193 (if YaTeX-label-select-map nil
|
|
194 (message "Setting up label selection mode map...")
|
|
195 (setq YaTeX-label-select-map (copy-keymap global-map))
|
|
196 (suppress-keymap YaTeX-label-select-map)
|
|
197 (substitute-all-key-definition
|
|
198 'previous-line 'YaTeX::label-previous YaTeX-label-select-map)
|
|
199 (substitute-all-key-definition
|
|
200 'next-line 'YaTeX::label-next YaTeX-label-select-map)
|
|
201 (define-key YaTeX-label-select-map "\C-n" 'YaTeX::label-next)
|
|
202 (define-key YaTeX-label-select-map "\C-p" 'YaTeX::label-previous)
|
|
203 (define-key YaTeX-label-select-map "<" 'beginning-of-buffer)
|
|
204 (define-key YaTeX-label-select-map ">" 'end-of-buffer)
|
|
205 (define-key YaTeX-label-select-map "\C-m" 'exit-recursive-edit)
|
|
206 (define-key YaTeX-label-select-map "\C-j" 'exit-recursive-edit)
|
|
207 (define-key YaTeX-label-select-map " " 'exit-recursive-edit)
|
|
208 (define-key YaTeX-label-select-map "\C-g" 'abort-recursive-edit)
|
|
209 (define-key YaTeX-label-select-map "/" 'isearch-forward)
|
|
210 (define-key YaTeX-label-select-map "?" 'isearch-backward)
|
|
211 (define-key YaTeX-label-select-map "'" 'YaTeX::label-search-tag)
|
|
212 (define-key YaTeX-label-select-map "*" 'YaTeX::label-search-tag)
|
|
213 (message "Setting up label selection mode map...Done")
|
|
214 (let ((key ?A))
|
|
215 (while (<= key ?Z)
|
|
216 (define-key YaTeX-label-select-map (char-to-string key)
|
|
217 'YaTeX::label-search-tag)
|
|
218 (define-key YaTeX-label-select-map (char-to-string (+ key (- ?a ?A)))
|
|
219 'YaTeX::label-search-tag)
|
|
220 (setq key (1+ key)))))
|
|
221 )
|
|
222 (defun YaTeX::label-next ()
|
|
223 (interactive) (forward-line 1) (message YaTeX-label-guide-msg))
|
|
224 (defun YaTeX::label-previous ()
|
|
225 (interactive) (forward-line -1) (message YaTeX-label-guide-msg))
|
|
226 (defun YaTeX::label-search-tag ()
|
|
227 (interactive)
|
|
228 (let ((case-fold-search t))
|
|
229 (cond
|
|
230 ((save-excursion
|
|
231 (forward-char 1)
|
|
232 (re-search-forward (concat "^" (this-command-keys)) nil t))
|
|
233 (goto-char (match-beginning 0)))
|
|
234 ((save-excursion
|
|
235 (goto-char (point-min))
|
|
236 (re-search-forward (concat "^" (this-command-keys)) nil t))
|
|
237 (goto-char (match-beginning 0))))
|
|
238 (message YaTeX-label-guide-msg))
|
|
239 )
|
|
240 (defun YaTeX::ref (argp)
|
|
241 (cond
|
|
242 ((= argp 1)
|
|
243 (save-excursion
|
|
244 (let ((lnum 0) e0 m1 e1 label label-list (buf (current-buffer))
|
|
245 (p (point)) initl line)
|
|
246 (goto-char (point-min))
|
|
247 (message "Collecting labels...")
|
|
248 (save-window-excursion
|
12
|
249 (YaTeX-showup-buffer
|
|
250 YaTeX-label-buffer (function (lambda (x) (window-width x))))
|
11
|
251 (with-output-to-temp-buffer YaTeX-label-buffer
|
|
252 (while (re-search-forward "\\label{\\([^}]+\\)}" nil t)
|
|
253 (setq e0 (match-end 0) m1 (match-beginning 1) e1 (match-end 1))
|
|
254 (if (search-backward
|
|
255 YaTeX-comment-prefix (point-beginning-of-line) t) nil
|
|
256 (setq label (buffer-substring m1 e1)
|
|
257 label-list (cons label label-list))
|
|
258 (or initl
|
|
259 (if (< p (point)) (setq initl lnum)))
|
|
260 (beginning-of-line)
|
|
261 (skip-chars-forward " \t\n" nil)
|
|
262 (princ (format "%c:{%s}\t<<%s>>\n" (+ (% lnum 26) ?A) label
|
|
263 (buffer-substring (point) (point-end-of-line))))
|
|
264 (setq lnum (1+ lnum))
|
|
265 (message "Collecting \\label{}... %d" lnum))
|
|
266 (goto-char e0))
|
|
267 (princ YaTeX-label-menu-other)
|
|
268 (princ YaTeX-label-menu-any)
|
|
269 );with
|
|
270 (goto-char p)
|
|
271 (message "Collecting labels...Done")
|
|
272 (pop-to-buffer YaTeX-label-buffer)
|
|
273 (YaTeX::label-setup-key-map)
|
|
274 (setq truncate-lines t)
|
|
275 (setq buffer-read-only t)
|
|
276 (use-local-map YaTeX-label-select-map)
|
|
277 (message YaTeX-label-guide-msg)
|
|
278 (goto-line (or initl lnum)) ;goto recently defined label line
|
|
279 (unwind-protect
|
|
280 (progn
|
|
281 (recursive-edit)
|
|
282 (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
|
|
283 (beginning-of-line)
|
|
284 (setq line (count-lines (point-min)(point)))
|
|
285 (cond
|
|
286 ((= line lnum) (setq label (YaTeX-label-other)))
|
|
287 ((>= line (1+ lnum ))
|
|
288 (setq label (read-string "\\ref{???}: ")))
|
|
289 (t (setq label (nth (- lnum line 1) label-list)))))
|
|
290 (bury-buffer YaTeX-label-buffer)))
|
|
291 label
|
|
292 ))
|
|
293 ))
|
|
294 )
|
|
295
|
|
296 (defun YaTeX-label-other ()
|
|
297 (let ((lbuf "*YaTeX mode buffers*") (blist (buffer-list)) (lnum -1) buf rv
|
|
298 (ff "**find-file**"))
|
12
|
299 (YaTeX-showup-buffer
|
|
300 lbuf (function (lambda (x) 1))) ;;Select next window surely.
|
11
|
301 (with-output-to-temp-buffer lbuf
|
|
302 (while blist
|
|
303 (if (and (buffer-file-name (setq buf (car blist)))
|
|
304 (progn (set-buffer buf) (eq major-mode 'yatex-mode)))
|
|
305 (princ
|
|
306 (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A)
|
|
307 (buffer-name buf))))
|
|
308 (setq blist (cdr blist)))
|
|
309 (princ (format "':{%s}" ff)))
|
|
310 (pop-to-buffer lbuf)
|
|
311 (YaTeX::label-setup-key-map)
|
|
312 (setq buffer-read-only t)
|
|
313 (use-local-map YaTeX-label-select-map)
|
|
314 (message YaTeX-label-guide-msg)
|
|
315 (unwind-protect
|
|
316 (progn
|
|
317 (recursive-edit)
|
|
318 (set-buffer lbuf)
|
|
319 (beginning-of-line)
|
|
320 (setq rv
|
|
321 (if (re-search-forward "{\\([^\\}]+\\)}" (point-end-of-line) t)
|
|
322 (buffer-substring (match-beginning 1) (match-end 1)) nil)))
|
|
323 (kill-buffer lbuf))
|
|
324 (cond
|
|
325 ((null rv) "")
|
|
326 ((string= rv ff)
|
|
327 (call-interactively 'find-file)
|
|
328 (YaTeX::ref argp))
|
|
329 (t
|
|
330 (set-buffer rv)
|
|
331 (YaTeX::ref argp)))
|
|
332 )
|
|
333 )
|
|
334
|
13
|
335 ;;
|
|
336 ; completion for the arguments of \newcommand
|
|
337 ;;
|
|
338 (defun YaTeX::newcommand (&optional argp)
|
|
339 (cond
|
|
340 ((= argp 1)
|
|
341 (let ((command (read-string "Define newcommand: " "\\")))
|
|
342 (put 'YaTeX::newcommand 'command (substring command 1))
|
|
343 command))
|
|
344 ((= argp 2)
|
|
345 (let ((argc
|
|
346 (string-to-int (read-string "Number of arguments(Default 0): ")))
|
|
347 (def (read-string "Definition: "))
|
|
348 (command (get 'YaTeX::newcommand 'command)))
|
|
349 ;;!!! It's illegal to insert string in the add-in function !!!
|
|
350 (if (> argc 0) (insert (format "[%d]" argc)))
|
|
351 (if (and (stringp command)
|
|
352 (string< "" command)
|
|
353 (y-or-n-p "Update user completion table?"))
|
|
354 (YaTeX-update-table
|
|
355 (if (> argc 1) (list command argc) (list command))
|
|
356 'section-table 'user-section-table 'tmp-section-table))
|
|
357 (message "")
|
|
358 def ;return command name
|
|
359 ))
|
|
360 (t ""))
|
|
361 )
|
|
362
|
|
363
|
11
|
364 ;;;
|
|
365 ;; global subroutines
|
|
366 ;;;
|
|
367 (defun substitute-all-key-definition (olddef newdef keymap)
|
|
368 "Replace recursively OLDDEF with NEWDEF for any keys in KEYMAP now
|
|
369 defined as OLDDEF. In other words, OLDDEF is replaced with NEWDEF
|
|
370 where ever it appears."
|
|
371 (if (arrayp keymap)
|
|
372 (let ((len (length keymap))
|
|
373 (i 0))
|
|
374 (while (< i len)
|
|
375 (let ((map (aref keymap i)))
|
|
376 (cond
|
|
377 ((arrayp map) (substitute-key-definition olddef newdef map))
|
|
378 ((equal map olddef)
|
|
379 (aset keymap i newdef)))
|
|
380 (setq i (1+ i)))))
|
|
381 (while keymap
|
|
382 (if (equal (cdr-safe (car-safe keymap)) olddef)
|
|
383 (setcdr (car keymap) newdef))
|
|
384 (setq keymap (cdr keymap)))))
|