yatex

annotate yatexadd.el @ 64:36a48185b95a

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