yatex

annotate yatexadd.el @ 72:0aaebd07dad0

Support font-lock on XEmacs-21, Emacs-20, Emacs-21. Support Emacs-21.
author yuuji
date Mon, 25 Dec 2000 10:19:28 +0000
parents 44e3a5e1e883
children f41b01fef5d6
rev   line source
yuuji@6 1 ;;; -*- Emacs-Lisp -*-
yuuji@8 2 ;;; YaTeX add-in functions.
yuuji@68 3 ;;; yatexadd.el rev.14
yuuji@72 4 ;;; (c )1991-2000 by HIROSE Yuuji.[yuuji@yatex.org]
yuuji@72 5 ;;; Last modified Mon Dec 25 19:17:09 2000 on firestorm
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@69 13 "*Your favorite default rule format.")
yuuji@69 14
yuuji@23 15 (defvar YaTeX:tabular-thick-vrule "\\vrule width %s"
yuuji@69 16 "*Vertical thick line format (without @{}). %s'll be replaced by its width.")
yuuji@69 17
yuuji@23 18 (defvar YaTeX:tabular-thick-hrule "\\noalign{\\hrule height %s}"
yuuji@69 19 "*Horizontal thick line format. %s will be replaced by its width.")
yuuji@69 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@72 26 (if (string= YaTeX-env-name "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@72 54 (setq YaTeX-single-command "hline")
yuuji@6 55
yuuji@69 56 (format "%s%s{%s}" width loc rule)))
yuuji@69 57
yuuji@18 58 (fset 'YaTeX:tabular* 'YaTeX:tabular)
yuuji@18 59 (defun YaTeX:array ()
yuuji@18 60 (concat (YaTeX:read-position "tb")
yuuji@69 61 "{" (read-string "Column format: ") "}"))
yuuji@6 62
yuuji@23 63 (defun YaTeX:read-oneof (oneof)
yuuji@23 64 (let ((pos "") loc (guide ""))
yuuji@23 65 (and (boundp 'name) name (setq guide (format "%s " name)))
yuuji@6 66 (while (not (string-match
yuuji@8 67 (setq loc (read-key-sequence
yuuji@23 68 (format "%s position (`%s') [%s]: "
yuuji@68 69 guide oneof pos));name is in YaTeX-addin
yuuji@68 70 loc (if (fboundp 'events-to-keys)
yuuji@68 71 (events-to-keys loc) loc))
yuuji@6 72 "\r\^g\n"))
yuuji@6 73 (cond
yuuji@8 74 ((string-match loc oneof)
yuuji@6 75 (if (not (string-match loc pos))
yuuji@6 76 (setq pos (concat pos loc))))
yuuji@6 77 ((and (string-match loc "\C-h\C-?") (> (length pos) 0))
yuuji@6 78 (setq pos (substring pos 0 (1- (length pos)))))
yuuji@6 79 (t
yuuji@6 80 (ding)
yuuji@8 81 (message "Please input one of `%s'." oneof)
yuuji@6 82 (sit-for 3))))
yuuji@8 83 (message "")
yuuji@69 84 pos))
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@69 89 (if (string= pos "") "" (concat "[" pos "]"))))
yuuji@8 90
yuuji@8 91 (defun YaTeX:table ()
yuuji@8 92 "YaTeX add-in function for table environment."
yuuji@72 93 (setq YaTeX-env-name "tabular"
yuuji@72 94 YaTeX-section-name "caption")
yuuji@69 95 (YaTeX:read-position "htbp"))
yuuji@6 96
yuuji@46 97 (fset 'YaTeX:figure 'YaTeX:table)
yuuji@46 98 (fset 'YaTeX:figure* 'YaTeX:table)
yuuji@46 99
yuuji@46 100
yuuji@6 101 (defun YaTeX:description ()
yuuji@6 102 "Truly poor service:-)"
yuuji@72 103 (setq YaTeX-single-command "item[]")
yuuji@69 104 "")
yuuji@6 105
yuuji@6 106 (defun YaTeX:itemize ()
yuuji@6 107 "It's also poor service."
yuuji@72 108 (setq YaTeX-single-command "item")
yuuji@69 109 "")
yuuji@6 110
yuuji@6 111 (fset 'YaTeX:enumerate 'YaTeX:itemize)
yuuji@8 112
yuuji@11 113 (defun YaTeX:picture ()
yuuji@11 114 "Ask the size of coordinates of picture environment."
yuuji@11 115 (concat (YaTeX:read-coordinates "Picture size")
yuuji@69 116 (YaTeX:read-coordinates "Initial position")))
yuuji@11 117
yuuji@12 118 (defun YaTeX:equation ()
yuuji@59 119 (YaTeX-jmode-off)
yuuji@12 120 (if (fboundp 'YaTeX-toggle-math-mode)
yuuji@69 121 (YaTeX-toggle-math-mode t))) ;force math-mode ON.
yuuji@69 122
yuuji@59 123 (mapcar '(lambda (f) (fset f 'YaTeX:equation))
yuuji@59 124 '(YaTeX:eqnarray YaTeX:eqnarray* YaTeX:align YaTeX:align*
yuuji@59 125 YaTeX:split YaTeX:multline YaTeX:multline* YaTeX:gather YaTeX:gather*
yuuji@59 126 YaTeX:aligned* YaTeX:gathered YaTeX:gathered*
yuuji@59 127 YaTeX:alignat YaTeX:alignat* YaTeX:xalignat YaTeX:xalignat*
yuuji@59 128 YaTeX:xxalignat YaTeX:xxalignat*))
yuuji@12 129
yuuji@16 130 (defun YaTeX:list ()
yuuji@69 131 "%\n{} %default label\n{} %formatting parameter")
yuuji@16 132
yuuji@18 133 (defun YaTeX:minipage ()
yuuji@18 134 (concat (YaTeX:read-position "cbt")
yuuji@69 135 "{" (read-string "Width: ") "}"))
yuuji@18 136
yuuji@64 137 (defun YaTeX:thebibliography ()
yuuji@72 138 (setq YaTeX-section-name "bibitem")
yuuji@69 139 "")
yuuji@64 140
yuuji@8 141 ;;;
yuuji@8 142 ;;Sample functions for section-type command.
yuuji@8 143 ;;;
yuuji@8 144 (defun YaTeX:multiput ()
yuuji@8 145 (concat (YaTeX:read-coordinates "Pos")
yuuji@8 146 (YaTeX:read-coordinates "Step")
yuuji@69 147 "{" (read-string "How many times: ") "}"))
yuuji@8 148
yuuji@8 149 (defun YaTeX:put ()
yuuji@69 150 (YaTeX:read-coordinates "Pos"))
yuuji@8 151
yuuji@8 152 (defun YaTeX:makebox ()
yuuji@23 153 (cond
yuuji@23 154 ((YaTeX-in-environment-p "picture")
yuuji@23 155 (concat (YaTeX:read-coordinates "Dimension")
yuuji@23 156 (YaTeX:read-position "lrtb")))
yuuji@23 157 (t
yuuji@23 158 (let ((width (read-string "Width: ")))
yuuji@23 159 (if (string< "" width)
yuuji@23 160 (progn
yuuji@23 161 (or (equal (aref width 0) ?\[)
yuuji@23 162 (setq width (concat "[" width "]")))
yuuji@69 163 (concat width (YaTeX:read-position "lr"))))))))
yuuji@8 164
yuuji@8 165 (defun YaTeX:framebox ()
yuuji@8 166 (if (YaTeX-quick-in-environment-p "picture")
yuuji@69 167 (YaTeX:makebox)))
yuuji@8 168
yuuji@8 169 (defun YaTeX:dashbox ()
yuuji@8 170 (concat "{" (read-string "Dash dimension: ") "}"
yuuji@69 171 (YaTeX:read-coordinates "Dimension")))
yuuji@8 172
yuuji@51 173 (defvar YaTeX-minibuffer-quick-map nil)
yuuji@51 174 (if YaTeX-minibuffer-quick-map nil
yuuji@51 175 (setq YaTeX-minibuffer-quick-map
yuuji@51 176 (copy-keymap minibuffer-local-completion-map))
yuuji@51 177 (let ((ch (1+ ? )))
yuuji@51 178 (while (< ch 127)
yuuji@51 179 (define-key YaTeX-minibuffer-quick-map (char-to-string ch)
yuuji@51 180 'YaTeX-minibuffer-quick-complete)
yuuji@51 181 (setq ch (1+ ch)))))
yuuji@51 182
yuuji@51 183 (defvar YaTeX:left-right-delimiters
yuuji@51 184 '(("(" . ")") (")" . "(") ("[" . "]") ("]" . "[")
yuuji@51 185 ("\\{" . "\\}") ("\\}" . "\\{") ("|") ("\\|")
yuuji@51 186 ("\\lfloor" . "\\rfloor") ("\\lceil" . "\\rceil")
yuuji@51 187 ("\\langle" . "\\rangle") ("/") (".")
yuuji@51 188 ("\\rfloor" . "\\rfloor") ("\\rceil" . "\\lceil")
yuuji@51 189 ("\\rangle" . "\\langle") ("\\backslash")
yuuji@51 190 ("\\uparrow") ("\\downarrow") ("\\updownarrow") ("\\Updownarrow"))
yuuji@51 191 "TeX math delimiter, which can be completed after \\right or \\left.")
yuuji@51 192
yuuji@51 193 (defvar YaTeX:left-right-default nil "Default string of YaTeX:right.")
yuuji@51 194
yuuji@23 195 (defun YaTeX:left ()
yuuji@51 196 (let ((minibuffer-completion-table YaTeX:left-right-delimiters)
yuuji@72 197 delimiter (leftp (string= YaTeX-single-command "left")))
yuuji@51 198 (setq delimiter
yuuji@51 199 (read-from-minibuffer
yuuji@51 200 (format "Delimiter%s: "
yuuji@51 201 (if YaTeX:left-right-default
yuuji@51 202 (format "(default=`%s')" YaTeX:left-right-default)
yuuji@51 203 "(SPC for menu)"))
yuuji@51 204 nil YaTeX-minibuffer-quick-map))
yuuji@51 205 (if (string= "" delimiter) (setq delimiter YaTeX:left-right-default))
yuuji@72 206 (setq YaTeX-single-command (if leftp "right" "left")
yuuji@51 207 YaTeX:left-right-default
yuuji@51 208 (or (cdr (assoc delimiter YaTeX:left-right-delimiters)) delimiter))
yuuji@51 209 delimiter))
yuuji@51 210
yuuji@23 211 (fset 'YaTeX:right 'YaTeX:left)
yuuji@23 212
yuuji@51 213
yuuji@8 214 (defun YaTeX:read-coordinates (&optional mes varX varY)
yuuji@8 215 (concat
yuuji@8 216 "("
yuuji@8 217 (read-string (format "%s %s: " (or mes "Dimension") (or varX "X")))
yuuji@8 218 ","
yuuji@8 219 (read-string (format "%s %s: " (or mes "Dimension") (or varY "Y")))
yuuji@69 220 ")"))
yuuji@8 221
yuuji@8 222 ;;;
yuuji@8 223 ;;Sample functions for maketitle-type command.
yuuji@8 224 ;;;
yuuji@8 225 (defun YaTeX:sum ()
yuuji@8 226 "Read range of summation."
yuuji@8 227 (YaTeX:check-completion-type 'maketitle)
yuuji@69 228 (concat (YaTeX:read-boundary "_") (YaTeX:read-boundary "^")))
yuuji@8 229
yuuji@8 230 (fset 'YaTeX:int 'YaTeX:sum)
yuuji@8 231
yuuji@8 232 (defun YaTeX:lim ()
yuuji@8 233 "Insert limit notation of \\lim."
yuuji@8 234 (YaTeX:check-completion-type 'maketitle)
yuuji@8 235 (let ((var (read-string "Variable: ")) limit)
yuuji@8 236 (if (string= "" var) ""
yuuji@8 237 (setq limit (read-string "Limit ($ means infinity): "))
yuuji@8 238 (if (string= "$" limit) (setq limit "\\infty"))
yuuji@69 239 (concat "_{" var " \\rightarrow " limit "}"))))
yuuji@8 240
yuuji@8 241 (defun YaTeX:gcd ()
yuuji@8 242 "Add-in function for \\gcd(m,n)."
yuuji@8 243 (YaTeX:check-completion-type 'maketitle)
yuuji@69 244 (YaTeX:read-coordinates "\\gcd" "(?,)" "(,?)"))
yuuji@8 245
yuuji@8 246 (defun YaTeX:read-boundary (ULchar)
yuuji@8 247 "Read boundary usage by _ or ^. _ or ^ is indicated by argument ULchar."
yuuji@11 248 (let ((bndry (read-string (concat ULchar "{???} ($ for infinity): "))))
yuuji@8 249 (if (string= bndry "") ""
yuuji@11 250 (if (string= bndry "$") (setq bndry "\\infty"))
yuuji@69 251 (concat ULchar "{" bndry "}"))))
yuuji@8 252
yuuji@14 253 (defun YaTeX:verb ()
yuuji@14 254 "Enclose \\verb's contents with the same characters."
yuuji@14 255 (let ((quote-char (read-string "Quoting char: " "|"))
yuuji@14 256 (contents (read-string "Quoted contents: ")))
yuuji@69 257 (concat quote-char contents quote-char)))
yuuji@69 258
yuuji@23 259 (fset 'YaTeX:verb* 'YaTeX:verb)
yuuji@14 260
yuuji@43 261 (defun YaTeX:footnotemark ()
yuuji@72 262 (setq YaTeX-section-name "footnotetext")
yuuji@69 263 nil)
yuuji@43 264
yuuji@48 265 (defun YaTeX:cite ()
yuuji@48 266 (let ((comment (read-string "Comment for citation: ")))
yuuji@48 267 (if (string= comment "") ""
yuuji@69 268 (concat "[" comment "]"))))
yuuji@48 269
yuuji@48 270 (defun YaTeX:bibitem ()
yuuji@64 271 (let ((label (read-string "Citation label for bibitem: ")))
yuuji@48 272 (if (string= label "") ""
yuuji@69 273 (concat "[" label "]"))))
yuuji@48 274
yuuji@53 275 (defun YaTeX:item ()
yuuji@53 276 (YaTeX-indent-line)
yuuji@72 277 (setq YaTeX-section-name "label")
yuuji@53 278 " ")
yuuji@52 279 (fset 'YaTeX:item\[\] 'YaTeX:item)
yuuji@52 280 (fset 'YaTeX:subitem 'YaTeX:item)
yuuji@52 281 (fset 'YaTeX:subsubitem 'YaTeX:item)
yuuji@52 282
yuuji@58 283 (defun YaTeX:linebreak ()
yuuji@58 284 (let (obl)
yuuji@58 285 (message "Break strength 0,1,2,3,4 (default: 4): ")
yuuji@58 286 (setq obl (char-to-string (read-char)))
yuuji@58 287 (if (string-match "[0-4]" obl)
yuuji@58 288 (concat "[" obl "]")
yuuji@69 289 "")))
yuuji@58 290 (fset 'YaTeX:pagebreak 'YaTeX:linebreak)
yuuji@58 291
yuuji@14 292 ;;;
yuuji@14 293 ;;Subroutine
yuuji@14 294 ;;;
yuuji@14 295
yuuji@8 296 (defun YaTeX:check-completion-type (type)
yuuji@8 297 "Check valid completion type."
yuuji@8 298 (if (not (eq type YaTeX-current-completion-type))
yuuji@69 299 (error "This should be completed with %s-type completion." type)))
yuuji@11 300
yuuji@11 301
yuuji@11 302 ;;;
yuuji@11 303 ;;; [[Add-in functions for reading section arguments]]
yuuji@11 304 ;;;
yuuji@11 305 ;; All of add-in functions for reading sections arguments should
yuuji@11 306 ;; take an argument ARGP that specify the argument position.
yuuji@11 307 ;; If argument position is out of range, nil should be returned,
yuuji@11 308 ;; else nil should NOT be returned.
yuuji@13 309
yuuji@13 310 ;;
yuuji@13 311 ; Label selection
yuuji@13 312 ;;
yuuji@11 313 (defvar YaTeX-label-menu-other
yuuji@11 314 (if YaTeX-japan "':̃obt@̃x\n" "':LABEL IN OTHER BUFFER.\n"))
yuuji@23 315 (defvar YaTeX-label-menu-repeat
yuuji@23 316 (if YaTeX-japan ".:O\\refƓ\n" "/:REPEAT LAST \ref{}\n"))
yuuji@11 317 (defvar YaTeX-label-menu-any
yuuji@11 318 (if YaTeX-japan "*:Cӂ̕\n" "*:ANY STRING.\n"))
yuuji@11 319 (defvar YaTeX-label-buffer "*Label completions*")
yuuji@11 320 (defvar YaTeX-label-guide-msg "Select label and hit RETURN.")
yuuji@11 321 (defvar YaTeX-label-select-map nil
yuuji@11 322 "Key map used in label selection buffer.")
yuuji@11 323 (defun YaTeX::label-setup-key-map ()
yuuji@11 324 (if YaTeX-label-select-map nil
yuuji@11 325 (message "Setting up label selection mode map...")
yuuji@68 326 ;(setq YaTeX-label-select-map (copy-keymap global-map))
yuuji@68 327 (setq YaTeX-label-select-map (make-keymap))
yuuji@11 328 (suppress-keymap YaTeX-label-select-map)
yuuji@11 329 (substitute-all-key-definition
yuuji@11 330 'previous-line 'YaTeX::label-previous YaTeX-label-select-map)
yuuji@11 331 (substitute-all-key-definition
yuuji@11 332 'next-line 'YaTeX::label-next YaTeX-label-select-map)
yuuji@11 333 (define-key YaTeX-label-select-map "\C-n" 'YaTeX::label-next)
yuuji@11 334 (define-key YaTeX-label-select-map "\C-p" 'YaTeX::label-previous)
yuuji@11 335 (define-key YaTeX-label-select-map "<" 'beginning-of-buffer)
yuuji@11 336 (define-key YaTeX-label-select-map ">" 'end-of-buffer)
yuuji@11 337 (define-key YaTeX-label-select-map "\C-m" 'exit-recursive-edit)
yuuji@11 338 (define-key YaTeX-label-select-map "\C-j" 'exit-recursive-edit)
yuuji@11 339 (define-key YaTeX-label-select-map " " 'exit-recursive-edit)
yuuji@11 340 (define-key YaTeX-label-select-map "\C-g" 'abort-recursive-edit)
yuuji@11 341 (define-key YaTeX-label-select-map "/" 'isearch-forward)
yuuji@11 342 (define-key YaTeX-label-select-map "?" 'isearch-backward)
yuuji@11 343 (define-key YaTeX-label-select-map "'" 'YaTeX::label-search-tag)
yuuji@23 344 (define-key YaTeX-label-select-map "." 'YaTeX::label-search-tag)
yuuji@11 345 (define-key YaTeX-label-select-map "*" 'YaTeX::label-search-tag)
yuuji@11 346 (message "Setting up label selection mode map...Done")
yuuji@11 347 (let ((key ?A))
yuuji@11 348 (while (<= key ?Z)
yuuji@11 349 (define-key YaTeX-label-select-map (char-to-string key)
yuuji@11 350 'YaTeX::label-search-tag)
yuuji@11 351 (define-key YaTeX-label-select-map (char-to-string (+ key (- ?a ?A)))
yuuji@11 352 'YaTeX::label-search-tag)
yuuji@69 353 (setq key (1+ key))))))
yuuji@69 354
yuuji@11 355 (defun YaTeX::label-next ()
yuuji@11 356 (interactive) (forward-line 1) (message YaTeX-label-guide-msg))
yuuji@11 357 (defun YaTeX::label-previous ()
yuuji@11 358 (interactive) (forward-line -1) (message YaTeX-label-guide-msg))
yuuji@11 359 (defun YaTeX::label-search-tag ()
yuuji@11 360 (interactive)
yuuji@68 361 (let ((case-fold-search t)
yuuji@68 362 (tag (regexp-quote (char-to-string last-command-char))))
yuuji@11 363 (cond
yuuji@11 364 ((save-excursion
yuuji@11 365 (forward-char 1)
yuuji@23 366 (re-search-forward (concat "^" tag) nil t))
yuuji@11 367 (goto-char (match-beginning 0)))
yuuji@11 368 ((save-excursion
yuuji@11 369 (goto-char (point-min))
yuuji@23 370 (re-search-forward (concat "^" tag) nil t))
yuuji@11 371 (goto-char (match-beginning 0))))
yuuji@69 372 (message YaTeX-label-guide-msg)))
yuuji@69 373
yuuji@70 374 ; (defun YaTeX::ref (argp &optional labelcmd refcmd)
yuuji@70 375 ; (cond
yuuji@70 376 ; ((= argp 1)
yuuji@70 377 ; (let ((lnum 0) e0 label label-list (buf (current-buffer))
yuuji@70 378 ; (labelcmd (or labelcmd "label")) (refcmd (or refcmd "ref"))
yuuji@70 379 ; (p (point)) initl line cf)
yuuji@70 380 ; (message "Collecting labels...")
yuuji@70 381 ; (save-window-excursion
yuuji@70 382 ; (YaTeX-showup-buffer
yuuji@70 383 ; YaTeX-label-buffer (function (lambda (x) (window-width x))))
yuuji@70 384 ; (if (fboundp 'select-frame) (setq cf (selected-frame)))
yuuji@70 385 ; (if (eq (window-buffer (minibuffer-window)) buf)
yuuji@70 386 ; (progn
yuuji@70 387 ; (other-window 1)
yuuji@70 388 ; (setq buf (current-buffer))
yuuji@70 389 ; (set-buffer buf)
yuuji@70 390 ; ;(message "cb=%s" buf)(sit-for 3)
yuuji@70 391 ; ))
yuuji@70 392 ; (save-excursion
yuuji@70 393 ; (set-buffer (get-buffer-create YaTeX-label-buffer))
yuuji@70 394 ; (setq buffer-read-only nil)
yuuji@70 395 ; (erase-buffer))
yuuji@70 396 ; (save-excursion
yuuji@70 397 ; (goto-char (point-min))
yuuji@70 398 ; (let ((standard-output (get-buffer YaTeX-label-buffer)))
yuuji@70 399 ; (princ (format "=== LABELS in [%s] ===\n" (buffer-name buf)))
yuuji@70 400 ; (while (YaTeX-re-search-active-forward
yuuji@70 401 ; (concat "\\\\" labelcmd "\\b")
yuuji@70 402 ; (regexp-quote YaTeX-comment-prefix) nil t)
yuuji@70 403 ; (goto-char (match-beginning 0))
yuuji@70 404 ; (skip-chars-forward "^{")
yuuji@70 405 ; (setq label
yuuji@70 406 ; (buffer-substring
yuuji@70 407 ; (1+ (point))
yuuji@70 408 ; (prog2 (forward-list 1) (setq e0 (1- (point)))))
yuuji@70 409 ; label-list (cons label label-list))
yuuji@70 410 ; (or initl
yuuji@70 411 ; (if (< p (point)) (setq initl lnum)))
yuuji@70 412 ; (beginning-of-line)
yuuji@70 413 ; (skip-chars-forward " \t\n" nil)
yuuji@70 414 ; (princ (format "%c:{%s}\t<<%s>>\n" (+ (% lnum 26) ?A) label
yuuji@70 415 ; (buffer-substring (point) (point-end-of-line))))
yuuji@70 416 ; (setq lnum (1+ lnum))
yuuji@70 417 ; (message "Collecting \\%s{}... %d" labelcmd lnum)
yuuji@70 418 ; (goto-char e0))
yuuji@70 419 ; (princ YaTeX-label-menu-other)
yuuji@70 420 ; (princ YaTeX-label-menu-repeat)
yuuji@70 421 ; (princ YaTeX-label-menu-any)
yuuji@70 422 ; );standard-output
yuuji@70 423 ; (goto-char p)
yuuji@70 424 ; (or initl (setq initl lnum))
yuuji@70 425 ; (message "Collecting %s...Done" labelcmd)
yuuji@70 426 ; (if (fboundp 'select-frame) (select-frame cf))
yuuji@70 427 ; (YaTeX-showup-buffer YaTeX-label-buffer nil t)
yuuji@70 428 ; (YaTeX::label-setup-key-map)
yuuji@70 429 ; (setq truncate-lines t)
yuuji@70 430 ; (setq buffer-read-only t)
yuuji@70 431 ; (use-local-map YaTeX-label-select-map)
yuuji@70 432 ; (message YaTeX-label-guide-msg)
yuuji@70 433 ; (goto-line (1+ initl)) ;goto recently defined label line
yuuji@70 434 ; (switch-to-buffer (current-buffer))
yuuji@70 435 ; (unwind-protect
yuuji@70 436 ; (progn
yuuji@70 437 ; (recursive-edit)
yuuji@70 438 ; (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
yuuji@70 439 ; (beginning-of-line)
yuuji@70 440 ; (setq line (1- (count-lines (point-min)(point))))
yuuji@70 441 ; (cond
yuuji@70 442 ; ((= line -1) (setq label ""))
yuuji@70 443 ; ((= line lnum) (setq label (YaTeX-label-other)))
yuuji@70 444 ; ((= line (1+ lnum))
yuuji@70 445 ; (save-excursion
yuuji@70 446 ; (switch-to-buffer buf)
yuuji@70 447 ; (goto-char p)
yuuji@70 448 ; (if (re-search-backward
yuuji@70 449 ; (concat "\\\\" refcmd "{\\([^}]+\\)}") nil t)
yuuji@70 450 ; (setq label (YaTeX-match-string 1))
yuuji@70 451 ; (setq label ""))))
yuuji@70 452 ; ((>= line (+ lnum 2))
yuuji@70 453 ; (setq label (read-string (format "\\%s{???}: " refcmd))))
yuuji@70 454 ; (t (setq label (nth (- lnum line 1) label-list)))))
yuuji@70 455 ; (bury-buffer YaTeX-label-buffer)))
yuuji@70 456 ; label)))))
yuuji@70 457
yuuji@70 458 (defun YaTeX::ref-generate-label ()
yuuji@70 459 "Generate a label string which is unique in current buffer."
yuuji@70 460 (let ((default (substring (current-time-string) 4)))
yuuji@70 461 (read-string "Give a label for this line: "
yuuji@70 462 (if YaTeX-emacs-19 (cons default 1) default))))
yuuji@70 463
yuuji@70 464 (defun YaTeX::ref-getset-label (buffer point)
yuuji@70 465 "Get label string in the BUFFER near the POINT.
yuuji@70 466 Make \\label{xx} if no label."
yuuji@70 467 (let (boundary inspoint cc newlabel (labelholder "label") mathp env)
yuuji@70 468 ;(set-buffer buffer)
yuuji@70 469 (switch-to-buffer buffer)
yuuji@70 470 (save-excursion
yuuji@70 471 (goto-char point)
yuuji@70 472 (setq cc (current-column))
yuuji@70 473 (if (= (char-after (point)) ?\\) (forward-char 1))
yuuji@70 474 (cond
yuuji@70 475 ((looking-at YaTeX-sectioning-regexp)
yuuji@70 476 (skip-chars-forward "^{")
yuuji@70 477 (forward-list 1)
yuuji@70 478 (skip-chars-forward " \t\n")
yuuji@72 479 (setq boundary "[^\\]"))
yuuji@70 480 ((looking-at "item\\s ")
yuuji@70 481 (setq cc (+ cc 6))
yuuji@70 482 (setq boundary (concat YaTeX-ec-regexp "\\(item\\|begin\\|end\\)\\b")))
yuuji@70 483 ((looking-at "bibitem")
yuuji@70 484 (setq labelholder "bibitem")) ; label holder is bibitem itself
yuuji@70 485 ((string-match YaTeX::ref-mathenv-regexp
yuuji@70 486 (setq env (or (YaTeX-inner-environment t) "document")))
yuuji@70 487 (setq mathp t)
yuuji@70 488 (setq boundary (concat YaTeX-ec-regexp "\\(\\\\\\|end{" env "}\\)")))
yuuji@70 489 ((looking-at "caption\\|\\(begin\\)")
yuuji@70 490 (skip-chars-forward "^{")
yuuji@70 491 (if (match-beginning 1) (forward-list 1))
yuuji@70 492 (setq boundary (concat YaTeX-ec-regexp "\\(begin\\|end\\)\\b")))
yuuji@70 493 (t ))
yuuji@70 494 (if (save-excursion (skip-chars-forward " \t") (looking-at "%"))
yuuji@70 495 (forward-line 1))
yuuji@70 496 (if (and (save-excursion
yuuji@70 497 (YaTeX-re-search-active-forward
yuuji@70 498 (concat "\\(" labelholder "\\)\\|\\(" boundary "\\)")
yuuji@70 499 (regexp-quote YaTeX-comment-prefix)
yuuji@70 500 nil 1))
yuuji@70 501 (match-beginning 1))
yuuji@70 502 ;; if \label{hoge} found, return it
yuuji@70 503 (buffer-substring
yuuji@70 504 (progn
yuuji@70 505 (goto-char (match-end 0))
yuuji@70 506 (skip-chars-forward "^{") (1+ (point)))
yuuji@70 507 (progn
yuuji@70 508 (forward-sexp 1) (1- (point))))
yuuji@70 509 ;;else make a label
yuuji@70 510 (goto-char (match-beginning 0))
yuuji@70 511 (skip-chars-backward " \t\n")
yuuji@70 512 (save-excursion (setq newlabel (YaTeX::ref-generate-label)))
yuuji@70 513 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
yuuji@70 514 (if mathp nil
yuuji@70 515 (insert "\n")
yuuji@70 516 (YaTeX-reindent cc))
yuuji@70 517 (insert (format "\\label{%s}" newlabel))
yuuji@70 518 newlabel))))
yuuji@70 519
yuuji@70 520 (defvar YaTeX::ref-labeling-regexp-alist
yuuji@70 521 '(("\\\\begin{java}{\\([^}]+\\)}" . 1)
yuuji@70 522 ("\\\\elabel{\\([^}]+\\)}" . 1)))
yuuji@70 523 (defvar YaTeX::ref-labeling-regexp
yuuji@70 524 (mapconcat 'car YaTeX::ref-labeling-regexp-alist "\\|"))
yuuji@70 525 (defvar YaTeX::ref-mathenv-regexp
yuuji@70 526 "equation\\|eqnarray\\|align\\|gather\\|alignat\\|xalignat")
yuuji@70 527 (defvar YaTeX::ref-enumerateenv-regexp
yuuji@70 528 "enumerate")
yuuji@70 529
yuuji@70 530 (defvar YaTeX::ref-labeling-section-level 2
yuuji@72 531 "*ref⊮ŎWZNVjOR}h̉x
yuuji@70 532 YaTeX-sectioning-level̐lŎw.")
yuuji@70 533
yuuji@48 534 (defun YaTeX::ref (argp &optional labelcmd refcmd)
yuuji@70 535 (setplist 'YaTeX::ref-labeling-regexp nil) ;erase memory cache
yuuji@70 536 (require 'yatexsec)
yuuji@11 537 (cond
yuuji@11 538 ((= argp 1)
yuuji@70 539 (let*((lnum 0) e0 x cmd label match-point point-list boundary
yuuji@70 540 (buf (current-buffer))
yuuji@70 541 (llv YaTeX::ref-labeling-section-level)
yuuji@70 542 (mathenvs YaTeX::ref-mathenv-regexp)
yuuji@70 543 (enums YaTeX::ref-enumerateenv-regexp)
yuuji@70 544 (counter
yuuji@70 545 (or labelcmd
yuuji@70 546 (concat
yuuji@70 547 YaTeX-ec-regexp "\\(\\("
yuuji@70 548 (mapconcat
yuuji@70 549 'concat
yuuji@70 550 (delq nil
yuuji@70 551 (mapcar
yuuji@72 552 (function
yuuji@72 553 (lambda (s)
yuuji@72 554 (if (>= llv (cdr s))
yuuji@72 555 (car s))))
yuuji@70 556 YaTeX-sectioning-level))
yuuji@70 557 "\\|")
yuuji@70 558 "\\|caption\\){"
yuuji@70 559 "\\|\\(begin{\\(" mathenvs "\\|" enums "\\)\\)\\)")))
yuuji@70 560 (regexp (concat "\\(" counter
yuuji@70 561 "\\)\\|\\(" YaTeX::ref-labeling-regexp "\\)"))
yuuji@70 562 (itemsep (concat YaTeX-ec-regexp
yuuji@70 563 "\\(\\(bib\\)?item\\|begin\\|end\\)"))
yuuji@70 564 (refcmd (or refcmd "ref"))
yuuji@70 565 (p (point)) initl line cf
yuuji@70 566 (percent (regexp-quote YaTeX-comment-prefix))
yuuji@70 567 (output
yuuji@70 568 (function
yuuji@70 569 (lambda (label p)
yuuji@70 570 (while (setq x (string-match "\n" label))
yuuji@70 571 (aset label x ? ))
yuuji@70 572 (while (setq x (string-match "[ \t\n][ \t\n]+" label))
yuuji@70 573 (setq label (concat
yuuji@70 574 (substring label 0 (1+ (match-beginning 0)))
yuuji@70 575 (substring label (match-end 0)))))
yuuji@70 576 (princ (format "%c: <<%s>>\n" (+ (% lnum 26) ?A) label))
yuuji@70 577 (setq point-list (cons p point-list))
yuuji@70 578 (message "Collecting labels... %d" lnum)
yuuji@70 579 (setq lnum (1+ lnum)))))
yuuji@70 580 )
yuuji@60 581 (message "Collecting labels...")
yuuji@60 582 (save-window-excursion
yuuji@60 583 (YaTeX-showup-buffer
yuuji@60 584 YaTeX-label-buffer (function (lambda (x) (window-width x))))
yuuji@60 585 (if (fboundp 'select-frame) (setq cf (selected-frame)))
yuuji@60 586 (if (eq (window-buffer (minibuffer-window)) buf)
yuuji@60 587 (progn
yuuji@60 588 (other-window 1)
yuuji@60 589 (setq buf (current-buffer))
yuuji@70 590 (set-buffer buf)))
yuuji@60 591 (save-excursion
yuuji@69 592 (set-buffer (get-buffer-create YaTeX-label-buffer))
yuuji@69 593 (setq buffer-read-only nil)
yuuji@69 594 (erase-buffer))
yuuji@69 595 (save-excursion
yuuji@70 596 (set-buffer buf)
yuuji@60 597 (goto-char (point-min))
yuuji@69 598 (let ((standard-output (get-buffer YaTeX-label-buffer)))
yuuji@60 599 (princ (format "=== LABELS in [%s] ===\n" (buffer-name buf)))
yuuji@48 600 (while (YaTeX-re-search-active-forward
yuuji@70 601 regexp ;;counter
yuuji@70 602 percent nil t)
yuuji@70 603 ;(goto-char (match-beginning 0))
yuuji@70 604 (setq e0 (match-end 0))
yuuji@70 605 (cond
yuuji@72 606 ((YaTeX-match-string 1)
yuuji@70 607 ;;if standard counter commands found
yuuji@70 608 (setq cmd (YaTeX-match-string 2))
yuuji@70 609 (setq match-point (match-beginning 0))
yuuji@70 610 (or initl
yuuji@70 611 (if (< p (point)) (setq initl lnum)))
yuuji@70 612 (cond
yuuji@70 613 ((string-match mathenvs cmd) ;;if matches mathematical env
yuuji@70 614 ;(skip-chars-forward "} \t\n")
yuuji@70 615 (forward-line 1)
yuuji@70 616 (setq x (point))
yuuji@70 617 (catch 'scan
yuuji@70 618 (while (YaTeX-re-search-active-forward
yuuji@70 619 (concat "\\\\\\\\$\\|\\\\end{\\(" mathenvs "\\)")
yuuji@70 620 percent nil t)
yuuji@70 621 (let ((quit (match-beginning 1)))
yuuji@70 622 (funcall output
yuuji@70 623 (buffer-substring x (match-beginning 0))
yuuji@70 624 x)
yuuji@70 625 (if quit (throw 'scan t)))
yuuji@70 626 (setq x (point))))
yuuji@70 627 (setq e0 (point)))
yuuji@70 628 ((string-match enums cmd)
yuuji@70 629 ;(skip-chars-forward "} \t\n")
yuuji@70 630 (save-restriction
yuuji@70 631 (narrow-to-region
yuuji@70 632 (point)
yuuji@70 633 (save-excursion
yuuji@70 634 (YaTeX-goto-corresponding-environment) (point)))
yuuji@70 635 (forward-line 1)
yuuji@70 636 (while (YaTeX-re-search-active-forward
yuuji@70 637 (concat YaTeX-ec-regexp "item\\s ")
yuuji@70 638 percent nil t)
yuuji@70 639 (setq x (match-beginning 0))
yuuji@70 640 (funcall
yuuji@70 641 output
yuuji@70 642 (buffer-substring
yuuji@70 643 (match-beginning 0)
yuuji@70 644 (if (re-search-forward itemsep nil t)
yuuji@70 645 (progn (goto-char (match-beginning 0))
yuuji@70 646 (skip-chars-backward " \t")
yuuji@70 647 (1- (point)))
yuuji@70 648 (point-end-of-line)))
yuuji@70 649 x))))
yuuji@70 650
yuuji@70 651 ((= (char-after (1- (point))) ?{)
yuuji@70 652 (setq label (buffer-substring
yuuji@70 653 (match-beginning 0)
yuuji@70 654 (progn (forward-char -1)
yuuji@70 655 (forward-list 1)
yuuji@70 656 (point))))
yuuji@70 657 (funcall output label match-point))
yuuji@70 658 (t
yuuji@70 659 (skip-chars-forward " \t")
yuuji@70 660 (setq label (buffer-substring
yuuji@70 661 (match-beginning 0)
yuuji@70 662 (if (re-search-forward
yuuji@70 663 itemsep
yuuji@70 664 nil t)
yuuji@70 665 (progn
yuuji@70 666 (goto-char (match-beginning 0))
yuuji@70 667 (skip-chars-backward " \t")
yuuji@70 668 (1- (point)))
yuuji@70 669 (point-end-of-line))))
yuuji@70 670 (funcall output label match-point)
yuuji@70 671 ))
yuuji@70 672 ) ;;put label buffer
yuuji@70 673 ;;
yuuji@70 674 ;; if user defined label found
yuuji@70 675 (t
yuuji@70 676 ;; memorize line number and label into property
yuuji@70 677 (goto-char (match-beginning 0))
yuuji@70 678 (let ((list YaTeX::ref-labeling-regexp-alist)
yuuji@70 679 (cache (symbol-plist 'YaTeX::ref-labeling-regexp)))
yuuji@70 680 (while list
yuuji@70 681 (if (looking-at (car (car list)))
yuuji@70 682 (progn
yuuji@70 683 (setq label (YaTeX-match-string 0))
yuuji@70 684 (put 'YaTeX::ref-labeling-regexp lnum
yuuji@70 685 (YaTeX-match-string (cdr (car list))))
yuuji@70 686 (funcall output label 0) ;;0 is dummy, never used
yuuji@70 687 (setq list nil)))
yuuji@70 688 (setq list (cdr list))))
yuuji@70 689 ))
yuuji@11 690 (goto-char e0))
yuuji@11 691 (princ YaTeX-label-menu-other)
yuuji@23 692 (princ YaTeX-label-menu-repeat)
yuuji@11 693 (princ YaTeX-label-menu-any)
yuuji@69 694 );standard-output
yuuji@11 695 (goto-char p)
yuuji@60 696 (or initl (setq initl lnum))
yuuji@70 697 (message "Collecting labels...Done")
yuuji@60 698 (if (fboundp 'select-frame) (select-frame cf))
yuuji@59 699 (YaTeX-showup-buffer YaTeX-label-buffer nil t)
yuuji@11 700 (YaTeX::label-setup-key-map)
yuuji@11 701 (setq truncate-lines t)
yuuji@11 702 (setq buffer-read-only t)
yuuji@11 703 (use-local-map YaTeX-label-select-map)
yuuji@11 704 (message YaTeX-label-guide-msg)
yuuji@60 705 (goto-line (1+ initl)) ;goto recently defined label line
yuuji@68 706 (switch-to-buffer (current-buffer))
yuuji@11 707 (unwind-protect
yuuji@11 708 (progn
yuuji@11 709 (recursive-edit)
yuuji@70 710
yuuji@11 711 (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
yuuji@11 712 (beginning-of-line)
yuuji@60 713 (setq line (1- (count-lines (point-min)(point))))
yuuji@11 714 (cond
yuuji@60 715 ((= line -1) (setq label ""))
yuuji@11 716 ((= line lnum) (setq label (YaTeX-label-other)))
yuuji@23 717 ((= line (1+ lnum))
yuuji@23 718 (save-excursion
yuuji@23 719 (switch-to-buffer buf)
yuuji@23 720 (goto-char p)
yuuji@48 721 (if (re-search-backward
yuuji@48 722 (concat "\\\\" refcmd "{\\([^}]+\\)}") nil t)
yuuji@48 723 (setq label (YaTeX-match-string 1))
yuuji@23 724 (setq label ""))))
yuuji@23 725 ((>= line (+ lnum 2))
yuuji@48 726 (setq label (read-string (format "\\%s{???}: " refcmd))))
yuuji@70 727 (t ;(setq label (nth (- lnum line 1) label-list))
yuuji@70 728 (setq label
yuuji@70 729 (or (get 'YaTeX::ref-labeling-regexp line)
yuuji@70 730 (YaTeX::ref-getset-label
yuuji@70 731 buf (nth (- lnum line 1) point-list))))
yuuji@70 732 )))
yuuji@11 733 (bury-buffer YaTeX-label-buffer)))
yuuji@69 734 label)))))
yuuji@69 735
yuuji@16 736 (fset 'YaTeX::pageref 'YaTeX::ref)
yuuji@70 737
yuuji@70 738 (defun YaTeX::cite-collect-bibs-external (&rest files)
yuuji@70 739 "Collect bibentry from FILES(variable length argument);
yuuji@70 740 and print them to standard output."
yuuji@70 741 ;;Thanks; http://icarus.ilcs.hokudai.ac.jp/comp/biblio.html
yuuji@70 742 (let ((tb (get-buffer-create " *bibtmp*")))
yuuji@70 743 (save-excursion
yuuji@70 744 (set-buffer tb)
yuuji@70 745 (while files
yuuji@70 746 (erase-buffer)
yuuji@70 747 (cond
yuuji@70 748 ((file-exists-p (car files))
yuuji@70 749 (insert-file-contents (car files)))
yuuji@70 750 ((file-exists-p (concat (car files) ".bib"))
yuuji@70 751 (insert-file-contents (concat (car files) ".bib"))))
yuuji@70 752 (save-excursion
yuuji@70 753 (goto-char (point-min))
yuuji@70 754 (while (re-search-forward "^\\s *@[A-Za-z]" nil t)
yuuji@70 755 (skip-chars-forward "^{,")
yuuji@70 756 (if (= (char-after (point)) ?{)
yuuji@70 757 (princ (format "%sbibitem{%s}%s\n"
yuuji@70 758 YaTeX-ec
yuuji@70 759 (buffer-substring
yuuji@70 760 (1+ (point))
yuuji@70 761 (progn (skip-chars-forward "^,\n")
yuuji@70 762 (point)))
yuuji@70 763 (if (re-search-forward "title\\s *=" nil t)
yuuji@70 764 (buffer-substring
yuuji@70 765 (progn
yuuji@70 766 (goto-char (match-end 0))
yuuji@70 767 (skip-chars-forward " \t\n")
yuuji@70 768 (point))
yuuji@70 769 (progn
yuuji@70 770 (if (looking-at "[{\"]")
yuuji@70 771 (forward-sexp 1)
yuuji@70 772 (forward-char 1)
yuuji@70 773 (skip-chars-forward "^,"))
yuuji@70 774 (point)))))))))
yuuji@70 775 (setq files (cdr files))))))
yuuji@70 776
yuuji@70 777 (defun YaTeX::cite-collect-bibs-internal ()
yuuji@70 778 "Collect bibentry in the current buffer and print them to standard output."
yuuji@70 779 (let ((ptn (concat YaTeX-ec-regexp "bibitem\\b"))
yuuji@70 780 (pcnt (regexp-quote YaTeX-comment-prefix)))
yuuji@70 781 (save-excursion
yuuji@70 782 (while (YaTeX-re-search-active-forward ptn pcnt nil t)
yuuji@70 783 (skip-chars-forward "^{\n")
yuuji@70 784 (or (eolp)
yuuji@70 785 (princ (format "%sbibitem{%s}\n"
yuuji@70 786 YaTeX-ec
yuuji@70 787 (buffer-substring
yuuji@70 788 (1+ (point))
yuuji@70 789 (progn (forward-sexp 1) (point))))))))))
yuuji@70 790
yuuji@48 791 (defun YaTeX::cite (argp)
yuuji@48 792 (cond
yuuji@48 793 ((eq argp 1)
yuuji@70 794 (let* ((cb (current-buffer))
yuuji@70 795 (f (file-name-nondirectory buffer-file-name))
yuuji@70 796 (d default-directory)
yuuji@70 797 (hilit-auto-highlight nil)
yuuji@70 798 (pcnt (regexp-quote YaTeX-comment-prefix))
yuuji@70 799 (bibrx (concat YaTeX-ec-regexp "bibliography{\\([^}]+\\)}"))
yuuji@70 800 (bbuf (get-buffer-create " *bibitems*"))
yuuji@70 801 (standard-output bbuf)
yuuji@70 802 bibs files)
yuuji@70 803 (set-buffer bbuf)(erase-buffer)(set-buffer cb)
yuuji@70 804 (save-excursion
yuuji@70 805 (goto-char (point-min))
yuuji@70 806 ;;(1)search external bibdata
yuuji@70 807 (while (YaTeX-re-search-active-forward bibrx pcnt nil t)
yuuji@70 808 (apply 'YaTeX::cite-collect-bibs-external
yuuji@70 809 (YaTeX-split-string
yuuji@70 810 (YaTeX-match-string 1) ",")))
yuuji@70 811 ;;(2)search direct \bibitem usage
yuuji@70 812 (YaTeX::cite-collect-bibs-internal)
yuuji@70 813 (if (progn
yuuji@70 814 (YaTeX-visit-main t)
yuuji@70 815 (not (eq (current-buffer) cb)))
yuuji@70 816 (save-excursion
yuuji@70 817 (goto-char (point-min))
yuuji@70 818 ;;(1)search external bibdata
yuuji@70 819 (while (YaTeX-re-search-active-forward bibrx pcnt nil t)
yuuji@70 820 (apply 'YaTeX::cite-collect-bibs-external
yuuji@70 821 (YaTeX-split-string
yuuji@70 822 (YaTeX-match-string 1) ",")))
yuuji@70 823 ;;(2)search internal
yuuji@70 824 (YaTeX::cite-collect-bibs-internal)))
yuuji@70 825 ;;Now bbuf holds the list of bibitem
yuuji@70 826 (set-buffer bbuf)
yuuji@70 827 (YaTeX::ref argp "\\\\\\(bibitem\\)\\(\\[.*\\]\\)?" "cite"))))
yuuji@70 828
yuuji@48 829 (t nil)))
yuuji@11 830
yuuji@70 831 (and YaTeX-use-AMS-LaTeX (fset 'YaTeX::eqref 'YaTeX::ref))
yuuji@70 832
yuuji@48 833 (defun YaTeX-yatex-buffer-list ()
yuuji@48 834 (save-excursion
yuuji@48 835 (delq nil (mapcar (function (lambda (buf)
yuuji@48 836 (set-buffer buf)
yuuji@48 837 (if (eq major-mode 'yatex-mode) buf)))
yuuji@69 838 (buffer-list)))))
yuuji@48 839
yuuji@48 840 (defun YaTeX-select-other-yatex-buffer ()
yuuji@48 841 "Select buffer from all yatex-mode's buffers interactivelly."
yuuji@48 842 (interactive)
yuuji@48 843 (let ((lbuf "*YaTeX mode buffers*") (blist (YaTeX-yatex-buffer-list))
yuuji@48 844 (lnum -1) buf rv
yuuji@11 845 (ff "**find-file**"))
yuuji@12 846 (YaTeX-showup-buffer
yuuji@12 847 lbuf (function (lambda (x) 1))) ;;Select next window surely.
yuuji@69 848 (save-excursion
yuuji@69 849 (set-buffer (get-buffer lbuf))
yuuji@69 850 (setq buffer-read-only nil)
yuuji@69 851 (erase-buffer))
yuuji@69 852 (let ((standard-output (get-buffer lbuf)))
yuuji@11 853 (while blist
yuuji@48 854 (princ
yuuji@48 855 (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A)
yuuji@48 856 (buffer-name (car blist))))
yuuji@11 857 (setq blist (cdr blist)))
yuuji@11 858 (princ (format "':{%s}" ff)))
yuuji@59 859 (YaTeX-showup-buffer lbuf nil t)
yuuji@11 860 (YaTeX::label-setup-key-map)
yuuji@11 861 (setq buffer-read-only t)
yuuji@11 862 (use-local-map YaTeX-label-select-map)
yuuji@11 863 (message YaTeX-label-guide-msg)
yuuji@11 864 (unwind-protect
yuuji@11 865 (progn
yuuji@11 866 (recursive-edit)
yuuji@11 867 (set-buffer lbuf)
yuuji@11 868 (beginning-of-line)
yuuji@11 869 (setq rv
yuuji@11 870 (if (re-search-forward "{\\([^\\}]+\\)}" (point-end-of-line) t)
yuuji@11 871 (buffer-substring (match-beginning 1) (match-end 1)) nil)))
yuuji@11 872 (kill-buffer lbuf))
yuuji@48 873 (if (string= rv ff)
yuuji@48 874 (progn
yuuji@48 875 (call-interactively 'find-file)
yuuji@48 876 (current-buffer))
yuuji@69 877 rv)))
yuuji@48 878
yuuji@48 879 (defun YaTeX-label-other ()
yuuji@48 880 (let ((rv (YaTeX-select-other-yatex-buffer)))
yuuji@11 881 (cond
yuuji@11 882 ((null rv) "")
yuuji@11 883 (t
yuuji@11 884 (set-buffer rv)
yuuji@69 885 (YaTeX::ref argp labelcmd refcmd)))))
yuuji@11 886
yuuji@13 887 ;;
yuuji@13 888 ; completion for the arguments of \newcommand
yuuji@13 889 ;;
yuuji@13 890 (defun YaTeX::newcommand (&optional argp)
yuuji@13 891 (cond
yuuji@13 892 ((= argp 1)
yuuji@13 893 (let ((command (read-string "Define newcommand: " "\\")))
yuuji@13 894 (put 'YaTeX::newcommand 'command (substring command 1))
yuuji@13 895 command))
yuuji@13 896 ((= argp 2)
yuuji@13 897 (let ((argc
yuuji@13 898 (string-to-int (read-string "Number of arguments(Default 0): ")))
yuuji@13 899 (def (read-string "Definition: "))
yuuji@13 900 (command (get 'YaTeX::newcommand 'command)))
yuuji@13 901 ;;!!! It's illegal to insert string in the add-in function !!!
yuuji@13 902 (if (> argc 0) (insert (format "[%d]" argc)))
yuuji@13 903 (if (and (stringp command)
yuuji@13 904 (string< "" command)
yuuji@51 905 (y-or-n-p "Update dictionary?"))
yuuji@18 906 (cond
yuuji@18 907 ((= argc 0)
yuuji@18 908 (YaTeX-update-table
yuuji@18 909 (list command)
yuuji@18 910 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table))
yuuji@18 911 ((= argc 1)
yuuji@18 912 (YaTeX-update-table
yuuji@18 913 (list command)
yuuji@18 914 'section-table 'user-section-table 'tmp-section-table))
yuuji@18 915 (t (YaTeX-update-table
yuuji@18 916 (list command argc)
yuuji@18 917 'section-table 'user-section-table 'tmp-section-table))))
yuuji@13 918 (message "")
yuuji@13 919 def ;return command name
yuuji@13 920 ))
yuuji@69 921 (t "")))
yuuji@13 922
yuuji@16 923 ;;
yuuji@16 924 ; completion for the arguments of \pagestyle
yuuji@16 925 ;;
yuuji@16 926 (defun YaTeX::pagestyle (&optional argp)
yuuji@16 927 "Read the pagestyle with completion."
yuuji@16 928 (completing-read
yuuji@16 929 "Page style: "
yuuji@69 930 '(("plain") ("empty") ("headings") ("myheadings") ("normal") nil)))
yuuji@69 931
yuuji@51 932 (fset 'YaTeX::thispagestyle 'YaTeX::pagestyle)
yuuji@51 933
yuuji@16 934 ;;
yuuji@16 935 ; completion for the arguments of \pagenumbering
yuuji@16 936 ;;
yuuji@16 937 (defun YaTeX::pagenumbering (&optional argp)
yuuji@16 938 "Read the numbering style."
yuuji@16 939 (completing-read
yuuji@16 940 "Page numbering style: "
yuuji@69 941 '(("arabic") ("Alpha") ("alpha") ("Roman") ("roman"))))
yuuji@13 942
yuuji@23 943 ;;
yuuji@23 944 ; Length
yuuji@23 945 ;;
yuuji@23 946 (defvar YaTeX:style-parameters-default
yuuji@23 947 '(("\\arraycolsep")
yuuji@23 948 ("\\arrayrulewidth")
yuuji@23 949 ("\\baselineskip")
yuuji@23 950 ("\\columnsep")
yuuji@23 951 ("\\columnseprule")
yuuji@23 952 ("\\doublerulesep")
yuuji@23 953 ("\\evensidemargin")
yuuji@23 954 ("\\footheight")
yuuji@23 955 ("\\footskip")
yuuji@23 956 ("\\headheight")
yuuji@23 957 ("\\headsep")
yuuji@23 958 ("\\itemindent")
yuuji@23 959 ("\\itemsep")
yuuji@23 960 ("\\labelsep")
yuuji@23 961 ("\\labelwidth")
yuuji@23 962 ("\\leftmargin")
yuuji@23 963 ("\\linewidth")
yuuji@23 964 ("\\listparindent")
yuuji@23 965 ("\\marginparsep")
yuuji@23 966 ("\\marginparwidth")
yuuji@23 967 ("\\mathindent")
yuuji@23 968 ("\\oddsidemargin")
yuuji@23 969 ("\\parindent")
yuuji@23 970 ("\\parsep")
yuuji@23 971 ("\\parskip")
yuuji@23 972 ("\\partopsep")
yuuji@23 973 ("\\rightmargin")
yuuji@23 974 ("\\tabcolsep")
yuuji@23 975 ("\\textheight")
yuuji@23 976 ("\\textwidth")
yuuji@23 977 ("\\topmargin")
yuuji@23 978 ("\\topsep")
yuuji@23 979 ("\\topskip")
yuuji@23 980 )
yuuji@23 981 "Alist of LaTeX style parameters.")
yuuji@23 982 (defvar YaTeX:style-parameters-private nil
yuuji@23 983 "*User definable alist of style parameters.")
yuuji@49 984 (defvar YaTeX:style-parameters-local nil
yuuji@49 985 "*User definable alist of local style parameters.")
yuuji@23 986
yuuji@23 987 (defvar YaTeX:length-history nil "Holds history of length.")
yuuji@51 988 (put 'YaTeX:length-history 'no-default t)
yuuji@23 989 (defun YaTeX::setlength (&optional argp)
yuuji@23 990 "YaTeX add-in function for arguments of \\setlength."
yuuji@23 991 (cond
yuuji@23 992 ((equal 1 argp)
yuuji@49 993 ;;(completing-read "Length variable: " YaTeX:style-parameters nil nil "\\")
yuuji@49 994 (YaTeX-cplread-with-learning
yuuji@49 995 "Length variable: "
yuuji@49 996 'YaTeX:style-parameters-default
yuuji@49 997 'YaTeX:style-parameters-private
yuuji@49 998 'YaTeX:style-parameters-local
yuuji@49 999 nil nil "\\")
yuuji@49 1000 )
yuuji@23 1001 ((equal 2 argp)
yuuji@69 1002 (read-string-with-history "Length: " nil 'YaTeX:length-history))))
yuuji@69 1003
yuuji@23 1004 (fset 'YaTeX::addtolength 'YaTeX::setlength)
yuuji@23 1005
yuuji@23 1006 (defun YaTeX::settowidth (&optional argp)
yuuji@23 1007 "YaTeX add-in function for arguments of \\settowidth."
yuuji@23 1008 (cond
yuuji@23 1009 ((equal 1 argp)
yuuji@49 1010 (YaTeX-cplread-with-learning
yuuji@49 1011 "Length variable: "
yuuji@49 1012 'YaTeX:style-parameters-default
yuuji@49 1013 'YaTeX:style-parameters-private
yuuji@49 1014 'YaTeX:style-parameters-local
yuuji@49 1015 nil nil "\\"))
yuuji@23 1016 ((equal 2 argp)
yuuji@69 1017 (read-string "Text: "))))
yuuji@69 1018
yuuji@23 1019 (defun YaTeX::newlength (&optional argp)
yuuji@23 1020 "YaTeX add-in function for arguments of \\newlength"
yuuji@23 1021 (cond
yuuji@23 1022 ((equal argp 1)
yuuji@23 1023 (let ((length (read-string "Length variable: " "\\")))
yuuji@49 1024 (if (string< "" length)
yuuji@49 1025 (YaTeX-update-table
yuuji@49 1026 (list length)
yuuji@49 1027 'YaTeX:style-parameters-default
yuuji@49 1028 'YaTeX:style-parameters-private
yuuji@49 1029 'YaTeX:style-parameters-local))
yuuji@69 1030 length))))
yuuji@23 1031
yuuji@23 1032 ;; \multicolumn's arguments
yuuji@23 1033 (defun YaTeX::multicolumn (&optional argp)
yuuji@23 1034 "YaTeX add-in function for arguments of \\multicolumn."
yuuji@23 1035 (cond
yuuji@23 1036 ((equal 1 argp)
yuuji@23 1037 (read-string "Number of columns: "))
yuuji@23 1038 ((equal 2 argp)
yuuji@23 1039 (let (c)
yuuji@23 1040 (while (not (string-match
yuuji@23 1041 (progn (message "Format(one of l,r,c): ")
yuuji@23 1042 (setq c (char-to-string (read-char))))
yuuji@23 1043 "lrc")))
yuuji@23 1044 c))
yuuji@23 1045 ((equal 3 argp)
yuuji@69 1046 (read-string "Item: "))))
yuuji@23 1047
yuuji@49 1048 (defvar YaTeX:documentstyles-default
yuuji@49 1049 '(("article") ("jarticle") ("j-article")
yuuji@49 1050 ("book") ("jbook") ("j-book")
yuuji@49 1051 ("report") ("jreport") ("j-report")
yuuji@49 1052 ("letter") ("ascjletter"))
yuuji@49 1053 "List of LaTeX documentstyles.")
yuuji@49 1054 (defvar YaTeX:documentstyles-private nil
yuuji@49 1055 "*User defined list of LaTeX documentstyles.")
yuuji@49 1056 (defvar YaTeX:documentstyles-local nil
yuuji@49 1057 "*User defined list of local LaTeX documentstyles.")
yuuji@49 1058 (defvar YaTeX:documentstyle-options-default
yuuji@49 1059 '(("a4j") ("a5j") ("b4j") ("b5j")
yuuji@49 1060 ("twocolumn") ("jtwocolumn") ("epsf") ("epsfig") ("epsbox") ("nfig"))
yuuji@49 1061 "List of LaTeX documentstyle options.")
yuuji@49 1062 (defvar YaTeX:documentstyle-options-private nil
yuuji@49 1063 "*User defined list of LaTeX documentstyle options.")
yuuji@49 1064 (defvar YaTeX:documentstyle-options-local nil
yuuji@49 1065 "List of LaTeX local documentstyle options.")
yuuji@49 1066
yuuji@49 1067 (defvar YaTeX-minibuffer-completion-map nil
yuuji@49 1068 "Minibuffer completion key map that allows comma completion.")
yuuji@49 1069 (if YaTeX-minibuffer-completion-map nil
yuuji@49 1070 (setq YaTeX-minibuffer-completion-map
yuuji@49 1071 (copy-keymap minibuffer-local-completion-map))
yuuji@49 1072 (define-key YaTeX-minibuffer-completion-map " "
yuuji@49 1073 'YaTeX-minibuffer-complete)
yuuji@49 1074 (define-key YaTeX-minibuffer-completion-map "\t"
yuuji@49 1075 'YaTeX-minibuffer-complete))
yuuji@49 1076
yuuji@49 1077 (defun YaTeX:documentstyle ()
yuuji@49 1078 (let*((delim ",")
yuuji@49 1079 (dt (append YaTeX:documentstyle-options-local
yuuji@49 1080 YaTeX:documentstyle-options-private
yuuji@49 1081 YaTeX:documentstyle-options-default))
yuuji@49 1082 (minibuffer-completion-table dt)
yuuji@49 1083 (opt (read-from-minibuffer
yuuji@49 1084 "Style options ([opt1,opt2,...]): "
yuuji@51 1085 nil YaTeX-minibuffer-completion-map nil))
yuuji@49 1086 (substr opt) o)
yuuji@49 1087 (if (string< "" opt)
yuuji@49 1088 (progn
yuuji@49 1089 (while substr
yuuji@49 1090 (setq o (substring substr 0 (string-match delim substr)))
yuuji@49 1091 (or (assoc o dt)
yuuji@49 1092 (YaTeX-update-table
yuuji@49 1093 (list o)
yuuji@49 1094 'YaTeX:documentstyle-options-default
yuuji@49 1095 'YaTeX:documentstyle-options-private
yuuji@49 1096 'YaTeX:documentstyle-options-local))
yuuji@49 1097 (setq substr
yuuji@49 1098 (if (string-match delim substr)
yuuji@49 1099 (substring substr (1+ (string-match delim substr))))))
yuuji@49 1100 (concat "[" opt "]"))
yuuji@49 1101 "")))
yuuji@49 1102
yuuji@49 1103 (defun YaTeX::documentstyle (&optional argp)
yuuji@51 1104 "YaTeX add-in function for arguments of \\documentstyle."
yuuji@49 1105 (cond
yuuji@49 1106 ((equal argp 1)
yuuji@72 1107 (setq YaTeX-env-name "document")
yuuji@49 1108 (let ((sname
yuuji@49 1109 (YaTeX-cplread-with-learning
yuuji@49 1110 (format "Documentstyle (default %s): "
yuuji@49 1111 YaTeX-default-document-style)
yuuji@49 1112 'YaTeX:documentstyles-default
yuuji@49 1113 'YaTeX:documentstyles-private
yuuji@49 1114 'YaTeX:documentstyles-local)))
yuuji@49 1115 (if (string= "" sname) (setq sname YaTeX-default-document-style))
yuuji@69 1116 (setq YaTeX-default-document-style sname)))))
yuuji@49 1117
yuuji@57 1118 ;;; -------------------- LaTeX2e stuff --------------------
yuuji@57 1119 (defvar YaTeX:documentclass-options-default
yuuji@70 1120 '(("a4paper") ("a5paper") ("b4paper") ("b5paper") ("10pt") ("11pt") ("12pt")
yuuji@57 1121 ("latterpaper") ("legalpaper") ("executivepaper") ("landscape")
yuuji@57 1122 ("oneside") ("twoside") ("draft") ("final") ("leqno") ("fleqn") ("openbib")
yuuji@70 1123 ("tombow") ("titlepage") ("notitlepage") ("dvips")
yuuji@57 1124 ("clock") ;for slides class only
yuuji@57 1125 )
yuuji@57 1126 "Default options list for documentclass")
yuuji@57 1127 (defvar YaTeX:documentclass-options-private nil
yuuji@57 1128 "*User defined options list for documentclass")
yuuji@57 1129 (defvar YaTeX:documentclass-options-local nil
yuuji@57 1130 "*User defined options list for local documentclass")
yuuji@57 1131
yuuji@57 1132 (defun YaTeX:documentclass ()
yuuji@57 1133 (let*((delim ",")
yuuji@57 1134 (dt (append YaTeX:documentclass-options-local
yuuji@57 1135 YaTeX:documentclass-options-private
yuuji@57 1136 YaTeX:documentclass-options-default))
yuuji@57 1137 (minibuffer-completion-table dt)
yuuji@57 1138 (opt (read-from-minibuffer
yuuji@57 1139 "Documentclass options ([opt1,opt2,...]): "
yuuji@57 1140 nil YaTeX-minibuffer-completion-map nil))
yuuji@57 1141 (substr opt) o)
yuuji@57 1142 (if (string< "" opt)
yuuji@57 1143 (progn
yuuji@57 1144 (while substr
yuuji@70 1145
yuuji@57 1146 (setq o (substring substr 0 (string-match delim substr)))
yuuji@57 1147 (or (assoc o dt)
yuuji@57 1148 (YaTeX-update-table
yuuji@57 1149 (list o)
yuuji@57 1150 'YaTeX:documentclass-options-default
yuuji@57 1151 'YaTeX:documentclass-options-private
yuuji@57 1152 'YaTeX:documentclass-options-local))
yuuji@57 1153 (setq substr
yuuji@57 1154 (if (string-match delim substr)
yuuji@57 1155 (substring substr (1+ (string-match delim substr))))))
yuuji@57 1156 (concat "[" opt "]"))
yuuji@57 1157 "")))
yuuji@57 1158
yuuji@57 1159 (defvar YaTeX:documentclasses-default
yuuji@57 1160 '(("article") ("jarticle") ("report") ("jreport") ("book") ("jbook")
yuuji@57 1161 ("j-article") ("j-report") ("j-book")
yuuji@57 1162 ("letter") ("slides") ("ltxdoc") ("ltxguide") ("ltnews") ("proc"))
yuuji@57 1163 "Default documentclass alist")
yuuji@57 1164 (defvar YaTeX:documentclasses-private nil
yuuji@57 1165 "*User defined documentclass alist")
yuuji@57 1166 (defvar YaTeX:documentclasses-local nil
yuuji@57 1167 "*User defined local documentclass alist")
yuuji@57 1168 (defvar YaTeX-default-documentclass (if YaTeX-japan "jarticle" "article")
yuuji@57 1169 "*Default documentclass")
yuuji@57 1170
yuuji@57 1171 (defun YaTeX::documentclass (&optional argp)
yuuji@57 1172 (cond
yuuji@57 1173 ((equal argp 1)
yuuji@72 1174 (setq YaTeX-env-name "document")
yuuji@57 1175 (let ((sname
yuuji@57 1176 (YaTeX-cplread-with-learning
yuuji@57 1177 (format "Documentclass (default %s): " YaTeX-default-documentclass)
yuuji@57 1178 'YaTeX:documentclasses-default
yuuji@57 1179 'YaTeX:documentclasses-private
yuuji@57 1180 'YaTeX:documentclasses-local)))
yuuji@57 1181 (if (string= "" sname) (setq sname YaTeX-default-documentclass))
yuuji@57 1182 (setq YaTeX-default-documentclass sname)))))
yuuji@57 1183
yuuji@70 1184 (defvar YaTeX:latex2e-named-color-alist
yuuji@70 1185 '(("GreenYellow") ("Yellow") ("Goldenrod") ("Dandelion") ("Apricot")
yuuji@70 1186 ("Peach") ("Melon") ("YellowOrange") ("Orange") ("BurntOrange")
yuuji@70 1187 ("Bittersweet") ("RedOrange") ("Mahogany") ("Maroon") ("BrickRed")
yuuji@70 1188 ("Red") ("OrangeRed") ("RubineRed") ("WildStrawberry") ("Salmon")
yuuji@70 1189 ("CarnationPink") ("Magenta") ("VioletRed") ("Rhodamine") ("Mulberry")
yuuji@70 1190 ("RedViolet") ("Fuchsia") ("Lavender") ("Thistle") ("Orchid")("DarkOrchid")
yuuji@70 1191 ("Purple") ("Plum") ("Violet") ("RoyalPurple") ("BlueViolet")
yuuji@70 1192 ("Periwinkle") ("CadetBlue") ("CornflowerBlue") ("MidnightBlue")
yuuji@70 1193 ("NavyBlue") ("RoyalBlue") ("Blue") ("Cerulean") ("Cyan") ("ProcessBlue")
yuuji@70 1194 ("SkyBlue") ("Turquoise") ("TealBlue") ("Aquamarine") ("BlueGreen")
yuuji@70 1195 ("Emerald") ("JungleGreen") ("SeaGreen") ("Green") ("ForestGreen")
yuuji@70 1196 ("PineGreen") ("LimeGreen") ("YellowGreen") ("SpringGreen") ("OliveGreen")
yuuji@70 1197 ("RawSienna") ("Sepia") ("Brown") ("Tan") ("Gray") ("Black") ("White"))
yuuji@70 1198 "Colors defined in $TEXMF/tex/plain/colordvi.tex")
yuuji@70 1199
yuuji@70 1200 (defvar YaTeX:latex2e-basic-color-alist
yuuji@70 1201 '(("black") ("white") ("red") ("blue") ("yellow") ("green") ("cyan")
yuuji@70 1202 ("magenta"))
yuuji@70 1203 "Basic colors")
yuuji@70 1204
yuuji@70 1205 (defun YaTeX:textcolor ()
yuuji@70 1206 "Add-in for \\color's option"
yuuji@70 1207 (if (y-or-n-p "Use `named' color? ")
yuuji@70 1208 "[named]"))
yuuji@70 1209
yuuji@70 1210 (defun YaTeX::color-completing-read (prompt)
yuuji@70 1211 (let ((completion-ignore-case t)
yuuji@70 1212 (namedp (save-excursion
yuuji@70 1213 (skip-chars-backward "^\n\\[\\\\")
yuuji@70 1214 (looking-at "named"))))
yuuji@70 1215 (completing-read
yuuji@70 1216 prompt
yuuji@70 1217 (if namedp
yuuji@70 1218 YaTeX:latex2e-named-color-alist
yuuji@70 1219 YaTeX:latex2e-basic-color-alist)
yuuji@70 1220 nil t)))
yuuji@70 1221
yuuji@70 1222 (defun YaTeX::textcolor (argp)
yuuji@70 1223 "Add-in for \\color's argument"
yuuji@70 1224 (cond
yuuji@70 1225 ((= argp 1) (YaTeX::color-completing-read "Color: "))
yuuji@70 1226 ((= argp 2) (read-string "Colored string: "))))
yuuji@70 1227
yuuji@70 1228 (fset 'YaTeX:color 'YaTeX:textcolor)
yuuji@70 1229 (fset 'YaTeX::color 'YaTeX::textcolor)
yuuji@70 1230 (fset 'YaTeX:colorbox 'YaTeX:textcolor)
yuuji@70 1231 (fset 'YaTeX::colorbox 'YaTeX::textcolor)
yuuji@70 1232 (fset 'YaTeX:fcolorbox 'YaTeX:textcolor)
yuuji@70 1233
yuuji@70 1234 (defun YaTeX::fcolorbox (argp)
yuuji@70 1235 (cond
yuuji@70 1236 ((= argp 1) (YaTeX::color-completing-read "Frame color: "))
yuuji@70 1237 ((= argp 2) (YaTeX::color-completing-read "Inner color: "))
yuuji@70 1238 ((= argp 3) (read-string "Colored string: "))))
yuuji@70 1239
yuuji@70 1240 (defun YaTeX:scalebox ()
yuuji@70 1241 "Add-in for \\rotatebox"
yuuji@70 1242 (let ((vmag (read-string (if YaTeX-japan "{: " "Magnification: ")))
yuuji@70 1243 (hmag (read-string (if YaTeX-japan "{(ȗ): "
yuuji@70 1244 "Horizontal magnification(Optional): "))))
yuuji@70 1245 (if (and hmag (string< "" hmag))
yuuji@70 1246 (format "{%s}[%s]" vmag hmag)
yuuji@70 1247 (format "{%s}" vmag))))
yuuji@70 1248
yuuji@70 1249 (defun YaTeX::includegraphics (argp)
yuuji@70 1250 "Add-in for \\includegraphics"
yuuji@70 1251 (cond
yuuji@70 1252 ((= argp 1)
yuuji@70 1253 (read-file-name "EPS File: " ""))))
yuuji@70 1254
yuuji@68 1255 (defun YaTeX:caption ()
yuuji@72 1256 (setq YaTeX-section-name "label")
yuuji@68 1257 nil)
yuuji@68 1258
yuuji@68 1259 ;;; -------------------- math-mode stuff --------------------
yuuji@68 1260 (defun YaTeX::tilde (&optional pos)
yuuji@68 1261 "For accent macros in mathmode"
yuuji@68 1262 (cond
yuuji@68 1263 ((equal pos 1)
yuuji@68 1264 (message "Put accent on variable: ")
yuuji@68 1265 (let ((v (char-to-string (read-char))) (case-fold-search nil))
yuuji@68 1266 (message "")
yuuji@68 1267 (cond
yuuji@68 1268 ((string-match "i\\|j" v)
yuuji@68 1269 (concat "\\" v "math"))
yuuji@68 1270 ((string-match "[\r\n\t ]" v)
yuuji@68 1271 "")
yuuji@68 1272 (t v))))
yuuji@68 1273 (nil "")))
yuuji@68 1274
yuuji@68 1275 (fset 'YaTeX::hat 'YaTeX::tilde)
yuuji@68 1276 (fset 'YaTeX::check 'YaTeX::tilde)
yuuji@68 1277 (fset 'YaTeX::bar 'YaTeX::tilde)
yuuji@68 1278 (fset 'YaTeX::dot 'YaTeX::tilde)
yuuji@68 1279 (fset 'YaTeX::ddot 'YaTeX::tilde)
yuuji@68 1280 (fset 'YaTeX::vec 'YaTeX::tilde)
yuuji@68 1281
yuuji@68 1282 (defun YaTeX::widetilde (&optional pos)
yuuji@68 1283 "For multichar accent macros in mathmode"
yuuji@68 1284 (cond
yuuji@68 1285 ((equal pos 1)
yuuji@68 1286 (let ((m "Put over chars[%s ]: ") v v2)
yuuji@68 1287 (message m " ")
yuuji@68 1288 (setq v (char-to-string (read-char)))
yuuji@68 1289 (message "")
yuuji@68 1290 (if (string-match "[\r\n\t ]" v)
yuuji@68 1291 ""
yuuji@68 1292 (message m v)
yuuji@68 1293 (setq v2 (char-to-string (read-char)))
yuuji@68 1294 (message "")
yuuji@68 1295 (if (string-match "[\r\n\t ]" v2)
yuuji@68 1296 v
yuuji@68 1297 (concat v v2)))))
yuuji@68 1298 (nil "")))
yuuji@68 1299
yuuji@68 1300 (fset 'YaTeX::widehat 'YaTeX::widetilde)
yuuji@68 1301 (fset 'YaTeX::overline 'YaTeX::widetilde)
yuuji@68 1302 (fset 'YaTeX::overrightarrow 'YaTeX::widetilde)
yuuji@68 1303
yuuji@68 1304
yuuji@68 1305 ;;;
yuuji@68 1306 ;; Add-in functions for large-type command.
yuuji@68 1307 ;;;
yuuji@68 1308 (defun YaTeX:em ()
yuuji@68 1309 (cond
yuuji@68 1310 ((eq YaTeX-current-completion-type 'large) "\\/")
yuuji@68 1311 (t nil)))
yuuji@68 1312 (fset 'YaTeX:it 'YaTeX:em)
yuuji@68 1313
yuuji@23 1314 ;;; -------------------- End of yatexadd --------------------
yuuji@23 1315 (provide 'yatexadd)
yuuji@72 1316 ; Local variables:
yuuji@72 1317 ; fill-prefix: ";;; "
yuuji@72 1318 ; paragraph-start: "^$\\| \\|;;;$"
yuuji@72 1319 ; paragraph-separate: "^$\\| \\|;;;$"
yuuji@72 1320 ; buffer-file-coding-system: sjis
yuuji@72 1321 ; End: