yatex

annotate yatexadd.el @ 73:f41b01fef5d6

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