yatex

annotate yatexadd.el @ 175:6e959a05ae19

Add `jsarticle' and `jsbook' to YaTeX:documentclasses-default.
author yuuji@gentei.org
date Mon, 07 Mar 2011 12:15:36 +0900
parents 7dc3c2332da5
children ad4e0a008972
rev   line source
yuuji@6 1 ;;; -*- Emacs-Lisp -*-
yuuji@8 2 ;;; YaTeX add-in functions.
yuuji@166 3 ;;; yatexadd.el rev.19
yuuji@166 4 ;;; (c)1991-2011 by HIROSE Yuuji.[yuuji@yatex.org]
yuuji@175 5 ;;; Last modified Mon Mar 7 12:12:11 2011 on firestorm
yuuji@141 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@80 59 (fset 'YaTeX:supertabular 'YaTeX:tabular)
yuuji@80 60 (defun YaTeX:alignat ()
yuuji@80 61 (concat "{" (read-string "Number of columns: ") "}"))
yuuji@18 62 (defun YaTeX:array ()
yuuji@18 63 (concat (YaTeX:read-position "tb")
yuuji@69 64 "{" (read-string "Column format: ") "}"))
yuuji@80 65 (defun YaTeX:subequations ()
yuuji@80 66 (message (if YaTeX-japan "分かりやすいコメントに変えるとref補完が楽よ"
yuuji@80 67 "Changing comment string reduces effort at `ref' completion"))
yuuji@80 68 (concat " " YaTeX-comment-prefix
yuuji@80 69 (YaTeX::ref-default-label "%H:%M")
yuuji@80 70 (if YaTeX-japan "の式群" "equations")))
yuuji@6 71
yuuji@79 72 (defun YaTeX:read-oneof (oneof &optional quick allow-dup)
yuuji@23 73 (let ((pos "") loc (guide ""))
yuuji@23 74 (and (boundp 'name) name (setq guide (format "%s " name)))
yuuji@79 75 (catch 'quick
yuuji@79 76 (while (not (string-match
yuuji@79 77 (setq loc (read-key-sequence
yuuji@79 78 (format "%s position (`%s') [%s]: "
yuuji@79 79 guide oneof pos));name is in YaTeX-addin
yuuji@79 80 loc (if (fboundp 'events-to-keys)
yuuji@79 81 (events-to-keys loc) loc))
yuuji@79 82 "\r\^g\n"))
yuuji@79 83 (cond
yuuji@79 84 ((string-match loc oneof)
yuuji@79 85 (if (or allow-dup (not (string-match loc pos)))
yuuji@79 86 (setq pos (concat pos loc)))
yuuji@79 87 (if quick (throw 'quick t)))
yuuji@79 88 ((and (string-match loc "\C-h\C-?") (> (length pos) 0))
yuuji@79 89 (setq pos (substring pos 0 (1- (length pos)))))
yuuji@79 90 (t
yuuji@79 91 (ding)
yuuji@79 92 (message "Please input one of `%s'." oneof)
yuuji@79 93 (sit-for 3)))))
yuuji@8 94 (message "")
yuuji@69 95 pos))
yuuji@23 96
yuuji@23 97 (defun YaTeX:read-position (oneof)
yuuji@23 98 "Read a LaTeX (optional) position format such as `[htbp]'."
yuuji@23 99 (let ((pos (YaTeX:read-oneof oneof)))
yuuji@69 100 (if (string= pos "") "" (concat "[" pos "]"))))
yuuji@8 101
yuuji@8 102 (defun YaTeX:table ()
yuuji@8 103 "YaTeX add-in function for table environment."
yuuji@73 104 (cond
yuuji@73 105 ((eq major-mode 'yatex-mode)
yuuji@73 106 (setq YaTeX-env-name "tabular"
yuuji@73 107 YaTeX-section-name "caption")
yuuji@73 108 (YaTeX:read-position "htbp"))
yuuji@73 109 ((eq major-mode 'texinfo-mode)
yuuji@73 110 (concat " "
yuuji@73 111 (completing-read
yuuji@73 112 "Highlights with: "
yuuji@73 113 '(("@samp")("@kbd")("@code")("@asis")("@file")("@var"))
yuuji@73 114 nil nil "@")))))
yuuji@6 115
yuuji@46 116 (fset 'YaTeX:figure 'YaTeX:table)
yuuji@46 117 (fset 'YaTeX:figure* 'YaTeX:table)
yuuji@46 118
yuuji@46 119
yuuji@6 120 (defun YaTeX:description ()
yuuji@6 121 "Truly poor service:-)"
yuuji@72 122 (setq YaTeX-single-command "item[]")
yuuji@69 123 "")
yuuji@6 124
yuuji@6 125 (defun YaTeX:itemize ()
yuuji@6 126 "It's also poor service."
yuuji@72 127 (setq YaTeX-single-command "item")
yuuji@69 128 "")
yuuji@6 129
yuuji@6 130 (fset 'YaTeX:enumerate 'YaTeX:itemize)
yuuji@8 131
yuuji@11 132 (defun YaTeX:picture ()
yuuji@11 133 "Ask the size of coordinates of picture environment."
yuuji@11 134 (concat (YaTeX:read-coordinates "Picture size")
yuuji@69 135 (YaTeX:read-coordinates "Initial position")))
yuuji@11 136
yuuji@12 137 (defun YaTeX:equation ()
yuuji@59 138 (YaTeX-jmode-off)
yuuji@12 139 (if (fboundp 'YaTeX-toggle-math-mode)
yuuji@69 140 (YaTeX-toggle-math-mode t))) ;force math-mode ON.
yuuji@69 141
yuuji@59 142 (mapcar '(lambda (f) (fset f 'YaTeX:equation))
yuuji@59 143 '(YaTeX:eqnarray YaTeX:eqnarray* YaTeX:align YaTeX:align*
yuuji@59 144 YaTeX:split YaTeX:multline YaTeX:multline* YaTeX:gather YaTeX:gather*
yuuji@59 145 YaTeX:aligned* YaTeX:gathered YaTeX:gathered*
yuuji@59 146 YaTeX:alignat YaTeX:alignat* YaTeX:xalignat YaTeX:xalignat*
yuuji@59 147 YaTeX:xxalignat YaTeX:xxalignat*))
yuuji@12 148
yuuji@80 149 (defun YaTeX:alignat ()
yuuji@80 150 (YaTeX:equation)
yuuji@80 151 (concat "{" (read-string "Number of cols: ") "}"))
yuuji@80 152
yuuji@80 153
yuuji@80 154
yuuji@16 155 (defun YaTeX:list ()
yuuji@69 156 "%\n{} %default label\n{} %formatting parameter")
yuuji@16 157
yuuji@18 158 (defun YaTeX:minipage ()
yuuji@18 159 (concat (YaTeX:read-position "cbt")
yuuji@69 160 "{" (read-string "Width: ") "}"))
yuuji@18 161
yuuji@64 162 (defun YaTeX:thebibliography ()
yuuji@72 163 (setq YaTeX-section-name "bibitem")
yuuji@77 164 (concat "{" (read-string "Longest label: ") "}"))
yuuji@64 165
yuuji@80 166 (defun YaTeX:multicols ()
yuuji@80 167 (concat "{" (read-string "Number of columns: ") "}"))
yuuji@80 168
yuuji@8 169 ;;;
yuuji@8 170 ;;Sample functions for section-type command.
yuuji@8 171 ;;;
yuuji@8 172 (defun YaTeX:multiput ()
yuuji@8 173 (concat (YaTeX:read-coordinates "Pos")
yuuji@8 174 (YaTeX:read-coordinates "Step")
yuuji@69 175 "{" (read-string "How many times: ") "}"))
yuuji@8 176
yuuji@8 177 (defun YaTeX:put ()
yuuji@69 178 (YaTeX:read-coordinates "Pos"))
yuuji@8 179
yuuji@8 180 (defun YaTeX:makebox ()
yuuji@23 181 (cond
yuuji@23 182 ((YaTeX-in-environment-p "picture")
yuuji@23 183 (concat (YaTeX:read-coordinates "Dimension")
yuuji@80 184 (YaTeX:read-position "lsrtb")))
yuuji@23 185 (t
yuuji@23 186 (let ((width (read-string "Width: ")))
yuuji@23 187 (if (string< "" width)
yuuji@23 188 (progn
yuuji@23 189 (or (equal (aref width 0) ?\[)
yuuji@23 190 (setq width (concat "[" width "]")))
yuuji@80 191 (concat width (YaTeX:read-position
yuuji@80 192 (if YaTeX-use-LaTeX2e "lrs" "lr")))))))))
yuuji@8 193
yuuji@80 194 ;; (defun YaTeX:framebox ()
yuuji@80 195 ;; (if (YaTeX-quick-in-environment-p "picture")
yuuji@80 196 ;; (YaTeX:makebox)))
yuuji@80 197 (fset 'YaTeX:framebox 'YaTeX:makebox)
yuuji@80 198
yuuji@80 199 (defun YaTeX:parbox ()
yuuji@80 200 (YaTeX:read-position "tbc"))
yuuji@104 201 (defun YaTeX::parbox (argp)
yuuji@104 202 (cond
yuuji@104 203 ((= argp 1) (read-string "Width: "))
yuuji@104 204 ((= argp 2) (read-string "Text: "))))
yuuji@8 205
yuuji@105 206 (defun YaTeX::dashbox ()
yuuji@8 207 (concat "{" (read-string "Dash dimension: ") "}"
yuuji@69 208 (YaTeX:read-coordinates "Dimension")))
yuuji@8 209
yuuji@105 210 (defun YaTeX::savebox (argp)
yuuji@80 211 (cond
yuuji@80 212 ((= argp 1) (read-string "Saved into name: " "\\"))
yuuji@80 213 ((= argp 2) (read-string "Text: "))))
yuuji@80 214
yuuji@51 215 (defvar YaTeX-minibuffer-quick-map nil)
yuuji@51 216 (if YaTeX-minibuffer-quick-map nil
yuuji@51 217 (setq YaTeX-minibuffer-quick-map
yuuji@51 218 (copy-keymap minibuffer-local-completion-map))
yuuji@51 219 (let ((ch (1+ ? )))
yuuji@51 220 (while (< ch 127)
yuuji@51 221 (define-key YaTeX-minibuffer-quick-map (char-to-string ch)
yuuji@51 222 'YaTeX-minibuffer-quick-complete)
yuuji@51 223 (setq ch (1+ ch)))))
yuuji@51 224
yuuji@51 225 (defvar YaTeX:left-right-delimiters
yuuji@51 226 '(("(" . ")") (")" . "(") ("[" . "]") ("]" . "[")
yuuji@51 227 ("\\{" . "\\}") ("\\}" . "\\{") ("|") ("\\|")
yuuji@51 228 ("\\lfloor" . "\\rfloor") ("\\lceil" . "\\rceil")
yuuji@51 229 ("\\langle" . "\\rangle") ("/") (".")
yuuji@51 230 ("\\rfloor" . "\\rfloor") ("\\rceil" . "\\lceil")
yuuji@51 231 ("\\rangle" . "\\langle") ("\\backslash")
yuuji@51 232 ("\\uparrow") ("\\downarrow") ("\\updownarrow") ("\\Updownarrow"))
yuuji@51 233 "TeX math delimiter, which can be completed after \\right or \\left.")
yuuji@51 234
yuuji@51 235 (defvar YaTeX:left-right-default nil "Default string of YaTeX:right.")
yuuji@51 236
yuuji@23 237 (defun YaTeX:left ()
yuuji@51 238 (let ((minibuffer-completion-table YaTeX:left-right-delimiters)
yuuji@72 239 delimiter (leftp (string= YaTeX-single-command "left")))
yuuji@51 240 (setq delimiter
yuuji@51 241 (read-from-minibuffer
yuuji@51 242 (format "Delimiter%s: "
yuuji@51 243 (if YaTeX:left-right-default
yuuji@51 244 (format "(default=`%s')" YaTeX:left-right-default)
yuuji@51 245 "(SPC for menu)"))
yuuji@51 246 nil YaTeX-minibuffer-quick-map))
yuuji@51 247 (if (string= "" delimiter) (setq delimiter YaTeX:left-right-default))
yuuji@72 248 (setq YaTeX-single-command (if leftp "right" "left")
yuuji@51 249 YaTeX:left-right-default
yuuji@51 250 (or (cdr (assoc delimiter YaTeX:left-right-delimiters)) delimiter))
yuuji@51 251 delimiter))
yuuji@51 252
yuuji@23 253 (fset 'YaTeX:right 'YaTeX:left)
yuuji@23 254
yuuji@80 255 (defun YaTeX:langle ()
yuuji@80 256 (setq YaTeX-single-command "rangle")
yuuji@80 257 nil)
yuuji@80 258
yuuji@8 259 (defun YaTeX:read-coordinates (&optional mes varX varY)
yuuji@8 260 (concat
yuuji@8 261 "("
yuuji@8 262 (read-string (format "%s %s: " (or mes "Dimension") (or varX "X")))
yuuji@8 263 ","
yuuji@8 264 (read-string (format "%s %s: " (or mes "Dimension") (or varY "Y")))
yuuji@69 265 ")"))
yuuji@8 266
yuuji@79 267 (defun YaTeX:itembox ()
yuuji@79 268 (concat "{" (read-string "Item heading string: ") "}"))
yuuji@79 269
yuuji@8 270 ;;;
yuuji@8 271 ;;Sample functions for maketitle-type command.
yuuji@8 272 ;;;
yuuji@8 273 (defun YaTeX:sum ()
yuuji@8 274 "Read range of summation."
yuuji@8 275 (YaTeX:check-completion-type 'maketitle)
yuuji@69 276 (concat (YaTeX:read-boundary "_") (YaTeX:read-boundary "^")))
yuuji@8 277
yuuji@8 278 (fset 'YaTeX:int 'YaTeX:sum)
yuuji@8 279
yuuji@8 280 (defun YaTeX:lim ()
yuuji@8 281 "Insert limit notation of \\lim."
yuuji@8 282 (YaTeX:check-completion-type 'maketitle)
yuuji@8 283 (let ((var (read-string "Variable: ")) limit)
yuuji@8 284 (if (string= "" var) ""
yuuji@8 285 (setq limit (read-string "Limit ($ means infinity): "))
yuuji@8 286 (if (string= "$" limit) (setq limit "\\infty"))
yuuji@69 287 (concat "_{" var " \\rightarrow " limit "}"))))
yuuji@8 288
yuuji@8 289 (defun YaTeX:gcd ()
yuuji@8 290 "Add-in function for \\gcd(m,n)."
yuuji@8 291 (YaTeX:check-completion-type 'maketitle)
yuuji@69 292 (YaTeX:read-coordinates "\\gcd" "(?,)" "(,?)"))
yuuji@8 293
yuuji@8 294 (defun YaTeX:read-boundary (ULchar)
yuuji@8 295 "Read boundary usage by _ or ^. _ or ^ is indicated by argument ULchar."
yuuji@11 296 (let ((bndry (read-string (concat ULchar "{???} ($ for infinity): "))))
yuuji@8 297 (if (string= bndry "") ""
yuuji@11 298 (if (string= bndry "$") (setq bndry "\\infty"))
yuuji@69 299 (concat ULchar "{" bndry "}"))))
yuuji@8 300
yuuji@14 301 (defun YaTeX:verb ()
yuuji@14 302 "Enclose \\verb's contents with the same characters."
yuuji@14 303 (let ((quote-char (read-string "Quoting char: " "|"))
yuuji@14 304 (contents (read-string "Quoted contents: ")))
yuuji@69 305 (concat quote-char contents quote-char)))
yuuji@69 306
yuuji@23 307 (fset 'YaTeX:verb* 'YaTeX:verb)
yuuji@14 308
yuuji@43 309 (defun YaTeX:footnotemark ()
yuuji@72 310 (setq YaTeX-section-name "footnotetext")
yuuji@69 311 nil)
yuuji@43 312
yuuji@48 313 (defun YaTeX:cite ()
yuuji@48 314 (let ((comment (read-string "Comment for citation: ")))
yuuji@48 315 (if (string= comment "") ""
yuuji@69 316 (concat "[" comment "]"))))
yuuji@48 317
yuuji@48 318 (defun YaTeX:bibitem ()
yuuji@64 319 (let ((label (read-string "Citation label for bibitem: ")))
yuuji@48 320 (if (string= label "") ""
yuuji@69 321 (concat "[" label "]"))))
yuuji@48 322
yuuji@53 323 (defun YaTeX:item ()
yuuji@73 324 (cond
yuuji@73 325 ((eq major-mode 'yatex-mode)
yuuji@73 326 (YaTeX-indent-line)
yuuji@73 327 (setq YaTeX-section-name "label"))
yuuji@73 328 ((eq major-mode 'texinfo-mode)
yuuji@73 329 (setq YaTeX-section-name "dots"))) ;??
yuuji@53 330 " ")
yuuji@52 331 (fset 'YaTeX:item\[\] 'YaTeX:item)
yuuji@52 332 (fset 'YaTeX:subitem 'YaTeX:item)
yuuji@52 333 (fset 'YaTeX:subsubitem 'YaTeX:item)
yuuji@52 334
yuuji@58 335 (defun YaTeX:linebreak ()
yuuji@58 336 (let (obl)
yuuji@58 337 (message "Break strength 0,1,2,3,4 (default: 4): ")
yuuji@58 338 (setq obl (char-to-string (read-char)))
yuuji@58 339 (if (string-match "[0-4]" obl)
yuuji@58 340 (concat "[" obl "]")
yuuji@69 341 "")))
yuuji@58 342 (fset 'YaTeX:pagebreak 'YaTeX:linebreak)
yuuji@58 343
yuuji@14 344 ;;;
yuuji@14 345 ;;Subroutine
yuuji@14 346 ;;;
yuuji@14 347
yuuji@8 348 (defun YaTeX:check-completion-type (type)
yuuji@8 349 "Check valid completion type."
yuuji@8 350 (if (not (eq type YaTeX-current-completion-type))
yuuji@69 351 (error "This should be completed with %s-type completion." type)))
yuuji@11 352
yuuji@11 353
yuuji@11 354 ;;;
yuuji@11 355 ;;; [[Add-in functions for reading section arguments]]
yuuji@11 356 ;;;
yuuji@11 357 ;; All of add-in functions for reading sections arguments should
yuuji@11 358 ;; take an argument ARGP that specify the argument position.
yuuji@11 359 ;; If argument position is out of range, nil should be returned,
yuuji@11 360 ;; else nil should NOT be returned.
yuuji@13 361
yuuji@13 362 ;;
yuuji@13 363 ; Label selection
yuuji@13 364 ;;
yuuji@11 365 (defvar YaTeX-label-menu-other
yuuji@11 366 (if YaTeX-japan "':他のバッファのラベル\n" "':LABEL IN OTHER BUFFER.\n"))
yuuji@23 367 (defvar YaTeX-label-menu-repeat
yuuji@23 368 (if YaTeX-japan ".:直前の\\refと同じ\n" "/:REPEAT LAST \ref{}\n"))
yuuji@11 369 (defvar YaTeX-label-menu-any
yuuji@11 370 (if YaTeX-japan "*:任意の文字列\n" "*:ANY STRING.\n"))
yuuji@11 371 (defvar YaTeX-label-buffer "*Label completions*")
yuuji@11 372 (defvar YaTeX-label-guide-msg "Select label and hit RETURN.")
yuuji@11 373 (defvar YaTeX-label-select-map nil
yuuji@11 374 "Key map used in label selection buffer.")
yuuji@11 375 (defun YaTeX::label-setup-key-map ()
yuuji@11 376 (if YaTeX-label-select-map nil
yuuji@11 377 (message "Setting up label selection mode map...")
yuuji@68 378 ;(setq YaTeX-label-select-map (copy-keymap global-map))
yuuji@68 379 (setq YaTeX-label-select-map (make-keymap))
yuuji@11 380 (suppress-keymap YaTeX-label-select-map)
yuuji@11 381 (substitute-all-key-definition
yuuji@11 382 'previous-line 'YaTeX::label-previous YaTeX-label-select-map)
yuuji@11 383 (substitute-all-key-definition
yuuji@11 384 'next-line 'YaTeX::label-next YaTeX-label-select-map)
yuuji@11 385 (define-key YaTeX-label-select-map "\C-n" 'YaTeX::label-next)
yuuji@11 386 (define-key YaTeX-label-select-map "\C-p" 'YaTeX::label-previous)
yuuji@11 387 (define-key YaTeX-label-select-map "<" 'beginning-of-buffer)
yuuji@11 388 (define-key YaTeX-label-select-map ">" 'end-of-buffer)
yuuji@11 389 (define-key YaTeX-label-select-map "\C-m" 'exit-recursive-edit)
yuuji@11 390 (define-key YaTeX-label-select-map "\C-j" 'exit-recursive-edit)
yuuji@11 391 (define-key YaTeX-label-select-map " " 'exit-recursive-edit)
yuuji@11 392 (define-key YaTeX-label-select-map "\C-g" 'abort-recursive-edit)
yuuji@11 393 (define-key YaTeX-label-select-map "/" 'isearch-forward)
yuuji@11 394 (define-key YaTeX-label-select-map "?" 'isearch-backward)
yuuji@11 395 (define-key YaTeX-label-select-map "'" 'YaTeX::label-search-tag)
yuuji@23 396 (define-key YaTeX-label-select-map "." 'YaTeX::label-search-tag)
yuuji@11 397 (define-key YaTeX-label-select-map "*" 'YaTeX::label-search-tag)
yuuji@11 398 (message "Setting up label selection mode map...Done")
yuuji@11 399 (let ((key ?A))
yuuji@11 400 (while (<= key ?Z)
yuuji@11 401 (define-key YaTeX-label-select-map (char-to-string key)
yuuji@11 402 'YaTeX::label-search-tag)
yuuji@11 403 (define-key YaTeX-label-select-map (char-to-string (+ key (- ?a ?A)))
yuuji@11 404 'YaTeX::label-search-tag)
yuuji@69 405 (setq key (1+ key))))))
yuuji@69 406
yuuji@11 407 (defun YaTeX::label-next ()
yuuji@11 408 (interactive) (forward-line 1) (message YaTeX-label-guide-msg))
yuuji@11 409 (defun YaTeX::label-previous ()
yuuji@11 410 (interactive) (forward-line -1) (message YaTeX-label-guide-msg))
yuuji@11 411 (defun YaTeX::label-search-tag ()
yuuji@11 412 (interactive)
yuuji@68 413 (let ((case-fold-search t)
yuuji@68 414 (tag (regexp-quote (char-to-string last-command-char))))
yuuji@11 415 (cond
yuuji@11 416 ((save-excursion
yuuji@11 417 (forward-char 1)
yuuji@23 418 (re-search-forward (concat "^" tag) nil t))
yuuji@11 419 (goto-char (match-beginning 0)))
yuuji@11 420 ((save-excursion
yuuji@11 421 (goto-char (point-min))
yuuji@23 422 (re-search-forward (concat "^" tag) nil t))
yuuji@11 423 (goto-char (match-beginning 0))))
yuuji@69 424 (message YaTeX-label-guide-msg)))
yuuji@69 425
yuuji@70 426 ; (defun YaTeX::ref (argp &optional labelcmd refcmd)
yuuji@70 427 ; (cond
yuuji@70 428 ; ((= argp 1)
yuuji@70 429 ; (let ((lnum 0) e0 label label-list (buf (current-buffer))
yuuji@70 430 ; (labelcmd (or labelcmd "label")) (refcmd (or refcmd "ref"))
yuuji@70 431 ; (p (point)) initl line cf)
yuuji@70 432 ; (message "Collecting labels...")
yuuji@70 433 ; (save-window-excursion
yuuji@70 434 ; (YaTeX-showup-buffer
yuuji@70 435 ; YaTeX-label-buffer (function (lambda (x) (window-width x))))
yuuji@70 436 ; (if (fboundp 'select-frame) (setq cf (selected-frame)))
yuuji@70 437 ; (if (eq (window-buffer (minibuffer-window)) buf)
yuuji@70 438 ; (progn
yuuji@70 439 ; (other-window 1)
yuuji@70 440 ; (setq buf (current-buffer))
yuuji@70 441 ; (set-buffer buf)
yuuji@70 442 ; ;(message "cb=%s" buf)(sit-for 3)
yuuji@70 443 ; ))
yuuji@70 444 ; (save-excursion
yuuji@70 445 ; (set-buffer (get-buffer-create YaTeX-label-buffer))
yuuji@70 446 ; (setq buffer-read-only nil)
yuuji@70 447 ; (erase-buffer))
yuuji@70 448 ; (save-excursion
yuuji@70 449 ; (goto-char (point-min))
yuuji@70 450 ; (let ((standard-output (get-buffer YaTeX-label-buffer)))
yuuji@70 451 ; (princ (format "=== LABELS in [%s] ===\n" (buffer-name buf)))
yuuji@70 452 ; (while (YaTeX-re-search-active-forward
yuuji@70 453 ; (concat "\\\\" labelcmd "\\b")
yuuji@70 454 ; (regexp-quote YaTeX-comment-prefix) nil t)
yuuji@70 455 ; (goto-char (match-beginning 0))
yuuji@70 456 ; (skip-chars-forward "^{")
yuuji@70 457 ; (setq label
yuuji@70 458 ; (buffer-substring
yuuji@70 459 ; (1+ (point))
yuuji@70 460 ; (prog2 (forward-list 1) (setq e0 (1- (point)))))
yuuji@70 461 ; label-list (cons label label-list))
yuuji@70 462 ; (or initl
yuuji@70 463 ; (if (< p (point)) (setq initl lnum)))
yuuji@70 464 ; (beginning-of-line)
yuuji@70 465 ; (skip-chars-forward " \t\n" nil)
yuuji@70 466 ; (princ (format "%c:{%s}\t<<%s>>\n" (+ (% lnum 26) ?A) label
yuuji@70 467 ; (buffer-substring (point) (point-end-of-line))))
yuuji@70 468 ; (setq lnum (1+ lnum))
yuuji@70 469 ; (message "Collecting \\%s{}... %d" labelcmd lnum)
yuuji@70 470 ; (goto-char e0))
yuuji@70 471 ; (princ YaTeX-label-menu-other)
yuuji@70 472 ; (princ YaTeX-label-menu-repeat)
yuuji@70 473 ; (princ YaTeX-label-menu-any)
yuuji@70 474 ; );standard-output
yuuji@70 475 ; (goto-char p)
yuuji@70 476 ; (or initl (setq initl lnum))
yuuji@70 477 ; (message "Collecting %s...Done" labelcmd)
yuuji@70 478 ; (if (fboundp 'select-frame) (select-frame cf))
yuuji@70 479 ; (YaTeX-showup-buffer YaTeX-label-buffer nil t)
yuuji@70 480 ; (YaTeX::label-setup-key-map)
yuuji@70 481 ; (setq truncate-lines t)
yuuji@70 482 ; (setq buffer-read-only t)
yuuji@70 483 ; (use-local-map YaTeX-label-select-map)
yuuji@70 484 ; (message YaTeX-label-guide-msg)
yuuji@70 485 ; (goto-line (1+ initl)) ;goto recently defined label line
yuuji@70 486 ; (switch-to-buffer (current-buffer))
yuuji@70 487 ; (unwind-protect
yuuji@70 488 ; (progn
yuuji@70 489 ; (recursive-edit)
yuuji@70 490 ; (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
yuuji@70 491 ; (beginning-of-line)
yuuji@70 492 ; (setq line (1- (count-lines (point-min)(point))))
yuuji@70 493 ; (cond
yuuji@70 494 ; ((= line -1) (setq label ""))
yuuji@70 495 ; ((= line lnum) (setq label (YaTeX-label-other)))
yuuji@70 496 ; ((= line (1+ lnum))
yuuji@70 497 ; (save-excursion
yuuji@70 498 ; (switch-to-buffer buf)
yuuji@70 499 ; (goto-char p)
yuuji@70 500 ; (if (re-search-backward
yuuji@70 501 ; (concat "\\\\" refcmd "{\\([^}]+\\)}") nil t)
yuuji@70 502 ; (setq label (YaTeX-match-string 1))
yuuji@70 503 ; (setq label ""))))
yuuji@70 504 ; ((>= line (+ lnum 2))
yuuji@70 505 ; (setq label (read-string (format "\\%s{???}: " refcmd))))
yuuji@70 506 ; (t (setq label (nth (- lnum line 1) label-list)))))
yuuji@70 507 ; (bury-buffer YaTeX-label-buffer)))
yuuji@70 508 ; label)))))
yuuji@70 509
yuuji@80 510 (defvar YaTeX-ref-default-label-string "%H%M%S_%d%b%y"
yuuji@80 511 "*Default \\ref time string format.
yuuji@80 512 This format is like strftime(3) but allowed conversion char are as follows;
yuuji@80 513 %y -> Last 2 digit of year, %b -> Month name, %m -> Monthe number(1-12),
yuuji@80 514 %d -> Day, %H -> Hour, %M -> Minute, %S -> Second,
yuuji@80 515 %qx -> alphabetical-decimal conversion of yymmdd.
yuuji@80 516 %qX -> alphabetical-decimal conversion of HHMMSS.
yuuji@80 517 Beware defualt label-string should be always unique. So this format string
yuuji@80 518 should have both time part (%H+%M+%S or %qX) and date
yuuji@80 519 part (%y+(%b|%m)+%d or %qx).")
yuuji@80 520
yuuji@80 521 (defun YaTeX::ref-alphabex (n)
yuuji@80 522 (let ((alphabex ""))
yuuji@80 523 (while (> n 0)
yuuji@80 524 (setq alphabex (concat (char-to-string (+ ?a (% n 26))) alphabex)
yuuji@80 525 n (/ n 26)))
yuuji@80 526 alphabex))
yuuji@80 527
yuuji@80 528 (defun YaTeX::ref-default-label (&optional format)
yuuji@80 529 "Default auto-genarated label string."
yuuji@80 530 ;; We do not use (format-time-string) for emacs-19
yuuji@80 531 (let*((ts (substring (current-time-string) 4))
yuuji@80 532 (y (substring ts -2))
yuuji@80 533 (b (substring ts 0 3))
yuuji@80 534 (d (format "%d" (string-to-int (substring ts 4 6))))
yuuji@80 535 (H (substring ts 7 9))
yuuji@80 536 (M (substring ts 10 12))
yuuji@80 537 (S (substring ts 13 15))
yuuji@80 538 (HMS (+ (* 10000 (string-to-int H))
yuuji@80 539 (* 100 (string-to-int M))
yuuji@80 540 (string-to-int S)))
yuuji@80 541 (talphabex (YaTeX::ref-alphabex HMS))
yuuji@80 542 (mnames "JanFebMarAprMayJunJulAugSepOctNovDec")
yuuji@80 543 (m (format "%02d" (/ (string-match b mnames) 3)))
yuuji@80 544 (ymd (+ (* 10000 (string-to-int y))
yuuji@80 545 (* 100 (string-to-int m))
yuuji@80 546 (string-to-int d)))
yuuji@80 547 (dalphabex (YaTeX::ref-alphabex ymd)))
yuuji@80 548 (YaTeX-replace-formats
yuuji@80 549 (or format YaTeX-ref-default-label-string)
yuuji@80 550 (list (cons "y" y)
yuuji@80 551 (cons "b" b)
yuuji@80 552 (cons "m" m)
yuuji@80 553 (cons "d" d)
yuuji@80 554 (cons "H" H)
yuuji@80 555 (cons "M" M)
yuuji@80 556 (cons "S" S)
yuuji@80 557 (cons "qX" talphabex)
yuuji@80 558 (cons "qx" dalphabex)))))
yuuji@80 559
yuuji@80 560 (defvar YaTeX-ref-generate-label-function 'YaTeX::ref-generate-label
yuuji@80 561 "*Function to generate default label for unnamed \\label{}s.
yuuji@80 562 The function pointed to this value should take two arguments.
yuuji@80 563 First argument is LaTeX macro's name, second is macro's argument.")
yuuji@80 564
yuuji@80 565 (defun YaTeX::ref-generate-label (command arg)
yuuji@70 566 "Generate a label string which is unique in current buffer."
yuuji@80 567 (let ((default (condition-case nil
yuuji@80 568 (YaTeX::ref-default-label)
yuuji@80 569 (error (substring (current-time-string) 4)))))
yuuji@70 570 (read-string "Give a label for this line: "
yuuji@70 571 (if YaTeX-emacs-19 (cons default 1) default))))
yuuji@70 572
yuuji@80 573 (defun YaTeX::ref-getset-label (buffer point &optional noset)
yuuji@70 574 "Get label string in the BUFFER near the POINT.
yuuji@80 575 Make \\label{xx} if no label.
yuuji@80 576 If optional third argument NOSET is non-nil, do not generate new label."
yuuji@73 577 ;;Here, we rewrite the LaTeX source. Therefore we should be careful
yuuji@73 578 ;;to decide the location suitable for \label. Do straightforward!
yuuji@80 579 (let (boundary inspoint cc newlabel (labelholder "label") mathp exp1 env
yuuji@80 580 (r-escape (regexp-quote YaTeX-comment-prefix))
yuuji@80 581 command arg alreadysought foundpoint)
yuuji@80 582 (set-buffer buffer)
yuuji@70 583 (save-excursion
yuuji@70 584 (goto-char point)
yuuji@70 585 (setq cc (current-column))
yuuji@70 586 (if (= (char-after (point)) ?\\) (forward-char 1))
yuuji@70 587 (cond
yuuji@70 588 ((looking-at YaTeX-sectioning-regexp)
yuuji@80 589 (setq command (YaTeX-match-string 0))
yuuji@70 590 (skip-chars-forward "^{")
yuuji@80 591 (setq arg (buffer-substring
yuuji@80 592 (1+ (point))
yuuji@80 593 (progn (forward-list 1) (1- (point)))))
yuuji@70 594 (skip-chars-forward " \t\n")
yuuji@73 595 ;(setq boundary "[^\\]")
yuuji@77 596 (setq inspoint (point))
yuuji@73 597 (setq boundary
yuuji@73 598 (save-excursion
yuuji@77 599 (if (YaTeX-re-search-active-forward
yuuji@77 600 (concat YaTeX-ec-regexp
yuuji@77 601 "\\(" YaTeX-sectioning-regexp "\\|"
yuuji@77 602 "begin\\|item\\)")
yuuji@77 603 r-escape nil 1)
yuuji@73 604 (match-beginning 0)
yuuji@73 605 (1- (point))))))
yuuji@70 606 ((looking-at "item\\s ")
yuuji@80 607 (setq command "item"
yuuji@80 608 cc (+ cc 6))
yuuji@73 609 ;(setq boundary (concat YaTeX-ec-regexp "\\(item\\|begin\\|end\\)\\b"))
yuuji@73 610 (setq boundary
yuuji@73 611 (save-excursion
yuuji@73 612 (if (YaTeX-re-search-active-forward
yuuji@73 613 (concat YaTeX-ec-regexp "\\(item\\|begin\\|end\\)\\b")
yuuji@73 614 r-escape nil 1)
yuuji@73 615 (match-beginning 0)
yuuji@77 616 (1- (point))))
yuuji@77 617 inspoint boundary))
yuuji@70 618 ((looking-at "bibitem")
yuuji@80 619 (setq labelholder "bibitem" ; label holder is bibitem itself
yuuji@80 620 command "bibitem")
yuuji@73 621 (setq boundary
yuuji@73 622 (save-excursion
yuuji@73 623 (if (YaTeX-re-search-active-forward
yuuji@73 624 (concat YaTeX-ec-regexp "\\(bibitem\\|end\\)\\b")
yuuji@73 625 r-escape nil 1)
yuuji@73 626 (match-beginning 0)
yuuji@77 627 (1- (point))))
yuuji@77 628 inspoint boundary))
yuuji@80 629 ((string-match YaTeX::ref-nestable-counter-regexp
yuuji@70 630 (setq env (or (YaTeX-inner-environment t) "document")))
yuuji@80 631 (let ((curtop (get 'YaTeX-inner-environment 'point))
yuuji@80 632 (end (point-max)) label)
yuuji@80 633 (skip-chars-forward " \t\n")
yuuji@80 634 (setq inspoint (point) ;initial candidate
yuuji@80 635 cc (current-column)
yuuji@80 636 command env
yuuji@80 637 alreadysought t)
yuuji@80 638 (if (condition-case nil
yuuji@80 639 (progn
yuuji@80 640 (goto-char curtop)
yuuji@80 641 (YaTeX-goto-corresponding-environment))
yuuji@80 642 (error nil))
yuuji@80 643 (setq end (point)))
yuuji@80 644 (goto-char inspoint)
yuuji@80 645 (while (YaTeX-re-search-active-forward
yuuji@80 646 (concat YaTeX-ec-regexp "label{\\([^}]+\\)}" )
yuuji@80 647 r-escape end t)
yuuji@80 648 (setq label (YaTeX-match-string 1))
yuuji@80 649 (if (and (equal env (YaTeX-inner-environment t))
yuuji@80 650 (= curtop (get 'YaTeX-inner-environment 'point)))
yuuji@80 651 ;;I found the label
yuuji@80 652 (setq alreadysought label
yuuji@80 653 foundpoint (match-end 0))))
yuuji@80 654 ))
yuuji@80 655 ((string-match YaTeX::ref-mathenv-regexp env) ;env is set in above case
yuuji@80 656 (setq command env
yuuji@80 657 mathp t
yuuji@80 658 exp1 (string-match YaTeX::ref-mathenv-exp1-regexp env))
yuuji@73 659 ;;(setq boundary (concat YaTeX-ec-regexp "\\(\\\\\\|end{" env "}\\)"))
yuuji@73 660 (setq boundary
yuuji@73 661 (save-excursion
yuuji@73 662 (if (YaTeX-re-search-active-forward
yuuji@80 663 (concat
yuuji@80 664 YaTeX-ec-regexp "\\("
yuuji@80 665 (if exp1 "" "\\\\\\|")
yuuji@80 666 "end{" env "}\\)")
yuuji@73 667 r-escape nil 1)
yuuji@73 668 (match-beginning 0)
yuuji@77 669 (1- (point))))
yuuji@77 670 inspoint boundary))
yuuji@73 671 ((looking-at "footnote\\s *{")
yuuji@80 672 (setq command "footnote")
yuuji@73 673 (skip-chars-forward "^{") ;move onto `{'
yuuji@73 674 (setq boundary
yuuji@73 675 (save-excursion
yuuji@73 676 (condition-case err
yuuji@73 677 (forward-list 1)
yuuji@73 678 (error (error "\\\\footnote at point %s's brace not closed"
yuuji@73 679 (point))))
yuuji@77 680 (1- (point)))
yuuji@77 681 inspoint boundary))
yuuji@70 682 ((looking-at "caption\\|\\(begin\\)")
yuuji@80 683 (setq command (YaTeX-match-string 0))
yuuji@70 684 (skip-chars-forward "^{")
yuuji@77 685 ;;;;;;(if (match-beginning 1) (forward-list 1))
yuuji@77 686 ;; caption can be treated as mathenv, is it right??
yuuji@80 687 (setq arg (buffer-substring
yuuji@80 688 (1+ (point))
yuuji@80 689 (progn (forward-list 1) (1- (point)))))
yuuji@73 690 ;;(setq boundary (concat YaTeX-ec-regexp "\\(begin\\|end\\)\\b"))
yuuji@77 691 (setq inspoint (point))
yuuji@73 692 (setq boundary
yuuji@73 693 (save-excursion
yuuji@73 694 (if (YaTeX-re-search-active-forward
yuuji@73 695 (concat YaTeX-ec-regexp "\\(begin\\|end\\)\\b")
yuuji@73 696 r-escape nil 1)
yuuji@73 697 (match-beginning 0)
yuuji@73 698 (1- (point))))))
yuuji@70 699 (t ))
yuuji@70 700 (if (save-excursion (skip-chars-forward " \t") (looking-at "%"))
yuuji@70 701 (forward-line 1))
yuuji@80 702 (cond
yuuji@80 703 ((stringp alreadysought)
yuuji@80 704 (put 'YaTeX::ref-getset-label 'foundpoint foundpoint) ;ugly...
yuuji@80 705 alreadysought)
yuuji@80 706 ((and (null alreadysought)
yuuji@80 707 (> boundary (point))
yuuji@80 708 (save-excursion
yuuji@80 709 (YaTeX-re-search-active-forward
yuuji@80 710 ;;(concat "\\(" labelholder "\\)\\|\\(" boundary "\\)")
yuuji@80 711 labelholder
yuuji@80 712 (regexp-quote YaTeX-comment-prefix)
yuuji@80 713 boundary 1))
yuuji@80 714 (match-beginning 0))
yuuji@70 715 ;; if \label{hoge} found, return it
yuuji@80 716 (put 'YaTeX::ref-getset-label 'foundpoint (1- (match-beginning 0)))
yuuji@80 717 (buffer-substring
yuuji@80 718 (progn
yuuji@80 719 (goto-char (match-end 0))
yuuji@80 720 (skip-chars-forward "^{") (1+ (point)))
yuuji@80 721 (progn
yuuji@80 722 (forward-sexp 1) (1- (point)))))
yuuji@70 723 ;;else make a label
yuuji@73 724 ;(goto-char (match-beginning 0))
yuuji@80 725 (noset nil) ;do not set label if noset
yuuji@80 726 (t
yuuji@77 727 (goto-char inspoint)
yuuji@70 728 (skip-chars-backward " \t\n")
yuuji@80 729 (save-excursion
yuuji@80 730 (setq newlabel
yuuji@80 731 (funcall YaTeX-ref-generate-label-function command arg)))
yuuji@70 732 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
yuuji@70 733 (if mathp nil
yuuji@70 734 (insert "\n")
yuuji@70 735 (YaTeX-reindent cc))
yuuji@70 736 (insert (format "\\label{%s}" newlabel))
yuuji@80 737 newlabel)))))
yuuji@70 738
yuuji@80 739 (defvar YaTeX::ref-labeling-regexp-alist-default
yuuji@80 740 '(("\\\\begin{\\(java\\|program\\)}{\\([^}]+\\)}" . 2)
yuuji@80 741 ("\\\\label{\\([^}]+\\)}" . 1))
yuuji@80 742 "Alist of labeling regexp vs. its group number points to label string.
yuuji@80 743 This alist is used in \\ref's argument's completion.")
yuuji@80 744 (defvar YaTeX::ref-labeling-regexp-alist-private nil
yuuji@168 745 "*Private extension to YaTeX::ref-labeling-regexp-alist.
yuuji@80 746 See the documetation of YaTeX::ref-labeling-regexp-alist.")
yuuji@70 747 (defvar YaTeX::ref-labeling-regexp-alist
yuuji@80 748 (append YaTeX::ref-labeling-regexp-alist-default
yuuji@80 749 YaTeX::ref-labeling-regexp-alist-private))
yuuji@70 750 (defvar YaTeX::ref-labeling-regexp
yuuji@70 751 (mapconcat 'car YaTeX::ref-labeling-regexp-alist "\\|"))
yuuji@70 752 (defvar YaTeX::ref-mathenv-regexp
yuuji@80 753 ;; See also YaTeX-ams-math-begin-alist in yatex.el
yuuji@80 754 ;; Define only envs which has counter.(without *)
yuuji@80 755 "equation\\|eqnarray\\|align\\(at\\)?\\|flalign\\|gather\\|xx?alignat\\|multline")
yuuji@80 756 (defvar YaTeX::ref-mathenv-exp1-regexp
yuuji@80 757 "\\(equation\\|multline\\)\\b"
yuuji@80 758 "*Regexp of math-envname which has only one math-expression.")
yuuji@70 759 (defvar YaTeX::ref-enumerateenv-regexp
yuuji@70 760 "enumerate")
yuuji@80 761 (defvar YaTeX::ref-nestable-counter-regexp
yuuji@80 762 "subequations")
yuuji@70 763
yuuji@70 764 (defvar YaTeX::ref-labeling-section-level 2
yuuji@72 765 "*ref補完で収集するセクショニングコマンドの下限レベル
yuuji@70 766 YaTeX-sectioning-levelの数値で指定.")
yuuji@70 767
yuuji@80 768 (defun YaTeX::ref (argp &optional labelcmd refcmd predf)
yuuji@70 769 (setplist 'YaTeX::ref-labeling-regexp nil) ;erase memory cache
yuuji@70 770 (require 'yatexsec)
yuuji@11 771 (cond
yuuji@11 772 ((= argp 1)
yuuji@80 773 (let*((lnum 0) m0 e0 x cmd label match-point point-list boundary
yuuji@70 774 (buf (current-buffer))
yuuji@70 775 (llv YaTeX::ref-labeling-section-level)
yuuji@80 776 (mathenvs YaTeX::ref-mathenv-regexp) envname endrx
yuuji@70 777 (enums YaTeX::ref-enumerateenv-regexp)
yuuji@70 778 (counter
yuuji@70 779 (or labelcmd
yuuji@70 780 (concat
yuuji@70 781 YaTeX-ec-regexp "\\(\\("
yuuji@70 782 (mapconcat
yuuji@70 783 'concat
yuuji@70 784 (delq nil
yuuji@70 785 (mapcar
yuuji@72 786 (function
yuuji@72 787 (lambda (s)
yuuji@72 788 (if (>= llv (cdr s))
yuuji@72 789 (car s))))
yuuji@70 790 YaTeX-sectioning-level))
yuuji@70 791 "\\|")
yuuji@77 792 "\\|caption\\(\\[[^]]+\\]\\)?\\|footnote\\){"
yuuji@80 793 "\\|\\(begin{\\(" mathenvs "\\|" enums "\\)}\\)"
yuuji@80 794 (if YaTeX-use-AMS-LaTeX
yuuji@80 795 (concat
yuuji@80 796 "\\|\\(begin{"
yuuji@80 797 YaTeX::ref-nestable-counter-regexp "}\\)"))
yuuji@80 798 "\\)")))
yuuji@70 799 (regexp (concat "\\(" counter
yuuji@70 800 "\\)\\|\\(" YaTeX::ref-labeling-regexp "\\)"))
yuuji@70 801 (itemsep (concat YaTeX-ec-regexp
yuuji@70 802 "\\(\\(bib\\)?item\\|begin\\|end\\)"))
yuuji@86 803 (refcmd (or refcmd "\\(page\\)?ref"))
yuuji@70 804 (p (point)) initl line cf
yuuji@70 805 (percent (regexp-quote YaTeX-comment-prefix))
yuuji@70 806 (output
yuuji@70 807 (function
yuuji@70 808 (lambda (label p)
yuuji@80 809 (while (setq x (string-match "[\n\t]" label))
yuuji@70 810 (aset label x ? ))
yuuji@80 811 (while (setq x (string-match " +" label))
yuuji@70 812 (setq label (concat
yuuji@70 813 (substring label 0 (1+ (match-beginning 0)))
yuuji@70 814 (substring label (match-end 0)))))
yuuji@70 815 (princ (format "%c: <<%s>>\n" (+ (% lnum 26) ?A) label))
yuuji@70 816 (setq point-list (cons p point-list))
yuuji@70 817 (message "Collecting labels... %d" lnum)
yuuji@70 818 (setq lnum (1+ lnum)))))
yuuji@80 819 (me (if (boundp 'me) me 'YaTeX::ref))
yuuji@70 820 )
yuuji@60 821 (message "Collecting labels...")
yuuji@60 822 (save-window-excursion
yuuji@60 823 (YaTeX-showup-buffer
yuuji@60 824 YaTeX-label-buffer (function (lambda (x) (window-width x))))
yuuji@60 825 (if (fboundp 'select-frame) (setq cf (selected-frame)))
yuuji@60 826 (if (eq (window-buffer (minibuffer-window)) buf)
yuuji@60 827 (progn
yuuji@60 828 (other-window 1)
yuuji@60 829 (setq buf (current-buffer))
yuuji@70 830 (set-buffer buf)))
yuuji@60 831 (save-excursion
yuuji@69 832 (set-buffer (get-buffer-create YaTeX-label-buffer))
yuuji@80 833 (condition-case ()
yuuji@80 834 (if (and YaTeX-use-font-lock (fboundp 'font-lock-mode))
yuuji@80 835 (font-lock-mode 1))
yuuji@80 836 (error nil))
yuuji@69 837 (setq buffer-read-only nil)
yuuji@69 838 (erase-buffer))
yuuji@69 839 (save-excursion
yuuji@70 840 (set-buffer buf)
yuuji@60 841 (goto-char (point-min))
yuuji@80 842 (let ((standard-output (get-buffer YaTeX-label-buffer)) existlabel)
yuuji@60 843 (princ (format "=== LABELS in [%s] ===\n" (buffer-name buf)))
yuuji@48 844 (while (YaTeX-re-search-active-forward
yuuji@70 845 regexp ;;counter
yuuji@70 846 percent nil t)
yuuji@70 847 ;(goto-char (match-beginning 0))
yuuji@70 848 (setq e0 (match-end 0))
yuuji@70 849 (cond
yuuji@80 850 ;;
yuuji@80 851 ;;2005/10/21 Skip it if predicate function returns nil
yuuji@80 852 ((and predf
yuuji@80 853 (let ((md (match-data)))
yuuji@80 854 (prog1
yuuji@80 855 (condition-case nil
yuuji@80 856 (not (funcall predf))
yuuji@80 857 (error nil))
yuuji@80 858 (store-match-data md)))))
yuuji@73 859 ((YaTeX-literal-p) nil)
yuuji@72 860 ((YaTeX-match-string 1)
yuuji@70 861 ;;if standard counter commands found
yuuji@80 862 (setq cmd (YaTeX-match-string 2)
yuuji@80 863 m0 (match-beginning 0))
yuuji@70 864 (setq match-point (match-beginning 0))
yuuji@70 865 (or initl
yuuji@70 866 (if (< p (point)) (setq initl lnum)))
yuuji@70 867 (cond
yuuji@80 868 ;; In any case, variables e0 should be set
yuuji@80 869 ((and YaTeX-use-AMS-LaTeX
yuuji@80 870 (string-match YaTeX::ref-nestable-counter-regexp cmd))
yuuji@80 871 (let (label)
yuuji@80 872 (skip-chars-forward "}")
yuuji@80 873 (setq label (buffer-substring
yuuji@80 874 (point) (min (+ 80 (point)) (point-max))))
yuuji@80 875 ;; to skip (maybe)auto-generated comment
yuuji@80 876 (skip-chars-forward " \t")
yuuji@80 877 (if (looking-at YaTeX-comment-prefix)
yuuji@80 878 (forward-line 1))
yuuji@80 879 (setq e0 (point))
yuuji@80 880 (skip-chars-forward " \t\n")
yuuji@80 881 (if (looking-at "\\\\label{\\([^}]+\\)}")
yuuji@80 882 (setq label (format "(labe:%s)" (YaTeX-match-string 1))
yuuji@80 883 e0 (match-end 1)))
yuuji@80 884 (funcall output (format "--subequation--%s" label) e0)))
yuuji@70 885 ((string-match mathenvs cmd) ;;if matches mathematical env
yuuji@70 886 ;(skip-chars-forward "} \t\n")
yuuji@80 887 ;(forward-line 1) ;2004/1/25
yuuji@80 888 (skip-chars-forward "}")
yuuji@80 889 (setq x (point)
yuuji@80 890 envname (substring
yuuji@80 891 cmd (match-beginning 0) (match-end 0)))
yuuji@80 892 (save-restriction
yuuji@80 893 (narrow-to-region
yuuji@80 894 m0
yuuji@80 895 (save-excursion
yuuji@80 896 (YaTeX-re-search-active-forward
yuuji@80 897 (setq endrx (format "%send{%s}" YaTeX-ec-regexp
yuuji@80 898 (regexp-quote envname)))
yuuji@80 899 percent nil t)))
yuuji@80 900 (catch 'scan
yuuji@80 901 (while (YaTeX-re-search-active-forward
yuuji@80 902 (concat
yuuji@80 903 "\\\\end{\\(" (regexp-quote envname) "\\)";;(1)
yuuji@80 904 (if YaTeX-use-AMS-LaTeX
yuuji@80 905 "\\|\\\\\\(notag\\)") ;;2
yuuji@80 906 (if (string-match
yuuji@80 907 YaTeX::ref-mathenv-exp1-regexp cmd)
yuuji@80 908 "" "\\|\\\\\\\\$")
yuuji@80 909 )
yuuji@80 910 percent nil t)
yuuji@80 911 (let*((quit (match-beginning 1))
yuuji@80 912 (notag (match-beginning 2))
yuuji@80 913 (label ".......................") l2
yuuji@80 914 (e (point)) (m0 (match-beginning 0))
yuuji@80 915 (ln (YaTeX-string-width label)))
yuuji@80 916 (cond
yuuji@80 917 (notag
yuuji@80 918 (YaTeX-re-search-active-forward
yuuji@80 919 "\\\\\\\\" percent nil 1)
yuuji@80 920 (setq x (point)))
yuuji@80 921 (t
yuuji@80 922 (if (YaTeX-re-search-active-backward
yuuji@80 923 YaTeX::ref-labeling-regexp
yuuji@80 924 percent x t)
yuuji@80 925 ;; if \label{x} in math-expression, display it
yuuji@80 926 ;; because formula source is hard to recognize
yuuji@80 927 (progn
yuuji@80 928 (goto-char (match-end 0))
yuuji@80 929 (setq l2 (format "\"label:%s\""
yuuji@80 930 (buffer-substring
yuuji@80 931 (1- (point))
yuuji@80 932 (progn (forward-sexp -1)
yuuji@80 933 (1+ (point))))))
yuuji@80 934 (setq label
yuuji@80 935 (if (< (YaTeX-string-width l2) ln)
yuuji@80 936 (concat
yuuji@80 937 l2
yuuji@80 938 (substring
yuuji@80 939 label
yuuji@80 940 0 (- ln (YaTeX-string-width l2))))
yuuji@80 941 l2))
yuuji@80 942 (goto-char e)))
yuuji@80 943 (funcall output
yuuji@80 944 (concat
yuuji@80 945 label " "
yuuji@80 946 (buffer-substring x m0))
yuuji@80 947 x)
yuuji@80 948 (cond
yuuji@80 949 ((YaTeX-quick-in-environment-p
yuuji@80 950 YaTeX-math-gathering-list)
yuuji@80 951 ;; if here is inner split/cases/gathered env.,
yuuji@80 952 ;; counter for here is only one.
yuuji@80 953 ;; Go out this environment and,
yuuji@80 954 (YaTeX-end-of-environment)
yuuji@80 955 ;; search next expression unit boundary.
yuuji@80 956 (YaTeX-re-search-active-forward
yuuji@80 957 (concat endrx "\\|\\\\begin{")
yuuji@80 958 percent nil 1)
yuuji@80 959 (end-of-line)))
yuuji@80 960 (if quit (throw 'scan t)))))
yuuji@80 961 (setq x (point)))))
yuuji@70 962 (setq e0 (point)))
yuuji@70 963 ((string-match enums cmd)
yuuji@70 964 ;(skip-chars-forward "} \t\n")
yuuji@70 965 (save-restriction
yuuji@70 966 (narrow-to-region
yuuji@70 967 (point)
yuuji@70 968 (save-excursion
yuuji@70 969 (YaTeX-goto-corresponding-environment) (point)))
yuuji@70 970 (forward-line 1)
yuuji@70 971 (while (YaTeX-re-search-active-forward
yuuji@70 972 (concat YaTeX-ec-regexp "item\\s ")
yuuji@70 973 percent nil t)
yuuji@70 974 (setq x (match-beginning 0))
yuuji@70 975 (funcall
yuuji@70 976 output
yuuji@80 977 (concat
yuuji@80 978 existlabel
yuuji@80 979 (buffer-substring
yuuji@80 980 (match-beginning 0)
yuuji@80 981 (if (re-search-forward itemsep nil t)
yuuji@80 982 (progn (goto-char (match-beginning 0))
yuuji@80 983 (skip-chars-backward " \t")
yuuji@80 984 (1- (point)))
yuuji@80 985 (point-end-of-line))))
yuuji@77 986 x))
yuuji@77 987 (setq e0 (point-max))))
yuuji@80 988 ((string-match "bibitem" cmd) ;maybe generated by myself
yuuji@80 989 (setq label "")
yuuji@80 990 (skip-chars-forward " \t")
yuuji@80 991 (if (looking-at "{") ;sure to be true!!
yuuji@80 992 (forward-list 1))
yuuji@80 993 (let ((list '(30 10 65))
yuuji@80 994 (delim ";") q lim len l str)
yuuji@80 995 (save-excursion
yuuji@80 996 (setq lim (if (re-search-forward itemsep nil 1)
yuuji@80 997 (match-beginning 0) (point))))
yuuji@80 998 (while list
yuuji@80 999 (skip-chars-forward " \t\n\\")
yuuji@80 1000 (setq q (looking-at "[\"'{]")
yuuji@80 1001 len (car list)
yuuji@80 1002 str
yuuji@80 1003 (buffer-substring
yuuji@80 1004 (point)
yuuji@80 1005 (progn
yuuji@80 1006 (if q (forward-sexp 1)
yuuji@80 1007 (search-forward delim lim 1)
yuuji@80 1008 (forward-char -1))
yuuji@80 1009 (point))))
yuuji@80 1010 (if (> (setq l (YaTeX-string-width str)) len)
yuuji@80 1011 (setq str (concat
yuuji@80 1012 (YaTeX-truncate-string-width
yuuji@80 1013 str (- len (if q 5 4)))
yuuji@80 1014 "... "
yuuji@80 1015 (if q (substring str -1)))))
yuuji@80 1016 (if (< (setq l (YaTeX-string-width str)) len)
yuuji@80 1017 (setq str (concat str (make-string (- len l) ? ))))
yuuji@80 1018 (if (looking-at delim) (goto-char (match-end 0)))
yuuji@80 1019 (setq label (concat label " " str)
yuuji@80 1020 list (cdr list)))
yuuji@80 1021 (funcall output label match-point)))
yuuji@77 1022 ;;else, simple section-type counter
yuuji@70 1023 ((= (char-after (1- (point))) ?{)
yuuji@70 1024 (setq label (buffer-substring
yuuji@70 1025 (match-beginning 0)
yuuji@70 1026 (progn (forward-char -1)
yuuji@70 1027 (forward-list 1)
yuuji@70 1028 (point))))
yuuji@77 1029 (funcall output label match-point)
yuuji@77 1030 ;; Skip preceding label if exists
yuuji@80 1031 (if (YaTeX::ref-getset-label (current-buffer) match-point t)
yuuji@80 1032 (goto-char (get 'YaTeX::ref-getset-label 'foundpoint)))
yuuji@77 1033 (if (save-excursion
yuuji@77 1034 (skip-chars-forward "\t \n")
yuuji@77 1035 (looking-at YaTeX::ref-labeling-regexp))
yuuji@77 1036 (setq e0 (match-end 0))))
yuuji@70 1037 (t
yuuji@70 1038 (skip-chars-forward " \t")
yuuji@70 1039 (setq label (buffer-substring
yuuji@70 1040 (match-beginning 0)
yuuji@70 1041 (if (re-search-forward
yuuji@70 1042 itemsep
yuuji@70 1043 nil t)
yuuji@70 1044 (progn
yuuji@70 1045 (goto-char (match-beginning 0))
yuuji@70 1046 (skip-chars-backward " \t")
yuuji@70 1047 (1- (point)))
yuuji@70 1048 (point-end-of-line))))
yuuji@70 1049 (funcall output label match-point)
yuuji@77 1050 (if (save-excursion
yuuji@77 1051 (skip-chars-forward "\t \n")
yuuji@77 1052 (looking-at YaTeX::ref-labeling-regexp))
yuuji@77 1053 (setq e0 (match-end 0)))))
yuuji@70 1054 ) ;;put label buffer
yuuji@70 1055 ;;
yuuji@70 1056 ;; if user defined label found
yuuji@70 1057 (t
yuuji@70 1058 ;; memorize line number and label into property
yuuji@70 1059 (goto-char (match-beginning 0))
yuuji@70 1060 (let ((list YaTeX::ref-labeling-regexp-alist)
yuuji@70 1061 (cache (symbol-plist 'YaTeX::ref-labeling-regexp)))
yuuji@70 1062 (while list
yuuji@70 1063 (if (looking-at (car (car list)))
yuuji@70 1064 (progn
yuuji@70 1065 (setq label (YaTeX-match-string 0))
yuuji@70 1066 (put 'YaTeX::ref-labeling-regexp lnum
yuuji@70 1067 (YaTeX-match-string (cdr (car list))))
yuuji@70 1068 (funcall output label 0) ;;0 is dummy, never used
yuuji@70 1069 (setq list nil)))
yuuji@70 1070 (setq list (cdr list))))
yuuji@70 1071 ))
yuuji@11 1072 (goto-char e0))
yuuji@11 1073 (princ YaTeX-label-menu-other)
yuuji@23 1074 (princ YaTeX-label-menu-repeat)
yuuji@11 1075 (princ YaTeX-label-menu-any)
yuuji@69 1076 );standard-output
yuuji@11 1077 (goto-char p)
yuuji@60 1078 (or initl (setq initl lnum))
yuuji@70 1079 (message "Collecting labels...Done")
yuuji@60 1080 (if (fboundp 'select-frame) (select-frame cf))
yuuji@59 1081 (YaTeX-showup-buffer YaTeX-label-buffer nil t)
yuuji@11 1082 (YaTeX::label-setup-key-map)
yuuji@11 1083 (setq truncate-lines t)
yuuji@11 1084 (setq buffer-read-only t)
yuuji@11 1085 (use-local-map YaTeX-label-select-map)
yuuji@11 1086 (message YaTeX-label-guide-msg)
yuuji@60 1087 (goto-line (1+ initl)) ;goto recently defined label line
yuuji@68 1088 (switch-to-buffer (current-buffer))
yuuji@11 1089 (unwind-protect
yuuji@11 1090 (progn
yuuji@11 1091 (recursive-edit)
yuuji@70 1092
yuuji@11 1093 (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
yuuji@11 1094 (beginning-of-line)
yuuji@60 1095 (setq line (1- (count-lines (point-min)(point))))
yuuji@11 1096 (cond
yuuji@60 1097 ((= line -1) (setq label ""))
yuuji@11 1098 ((= line lnum) (setq label (YaTeX-label-other)))
yuuji@23 1099 ((= line (1+ lnum))
yuuji@23 1100 (save-excursion
yuuji@23 1101 (switch-to-buffer buf)
yuuji@23 1102 (goto-char p)
yuuji@48 1103 (if (re-search-backward
yuuji@86 1104 (concat "\\\\" refcmd "{") nil t)
yuuji@86 1105 (setq label (YaTeX-buffer-substring
yuuji@86 1106 (progn (goto-char (1- (match-end 0)))
yuuji@86 1107 (1+ (point)))
yuuji@86 1108 (progn (forward-list 1)
yuuji@86 1109 (1- (point)))))
yuuji@23 1110 (setq label ""))))
yuuji@23 1111 ((>= line (+ lnum 2))
yuuji@48 1112 (setq label (read-string (format "\\%s{???}: " refcmd))))
yuuji@70 1113 (t ;(setq label (nth (- lnum line 1) label-list))
yuuji@70 1114 (setq label
yuuji@70 1115 (or (get 'YaTeX::ref-labeling-regexp line)
yuuji@70 1116 (YaTeX::ref-getset-label
yuuji@70 1117 buf (nth (- lnum line 1) point-list))))
yuuji@70 1118 )))
yuuji@11 1119 (bury-buffer YaTeX-label-buffer)))
yuuji@69 1120 label)))))
yuuji@69 1121
yuuji@168 1122 (defun YaTeX::label-rename-refs (old new &optional def ref)
yuuji@168 1123 "Rename reference tag from OLD to NEW.
yuuji@168 1124 Optional arguments DEF and REF specify defining command and
yuuji@168 1125 referring command respectively.
yuuji@168 1126 ---------------------------------------------------------
yuuji@168 1127 CONTROL KEYS - キーの説明
yuuji@168 1128 y Replace 置換する
yuuji@168 1129 n Do not replace 置換しない
yuuji@168 1130 ! Replace All w/o query 残る全部を確認なしで置換
yuuji@168 1131 r Enter Recursive-edit 再帰編集モードへ
yuuji@168 1132 q Quit from replacing ここまでで置換をやめる
yuuji@168 1133
yuuji@168 1134 Don't forget to exit from recursive edit by typing \\[exit-recursive-edit]
yuuji@168 1135 再帰編集に入ったら \\[exit-recursive-edit] で抜け忘れなきよう。"
yuuji@168 1136 (save-window-excursion
yuuji@168 1137 (catch 'exit
yuuji@168 1138 (let*((bufs (YaTeX-yatex-buffer-list)) buf b e
yuuji@168 1139 (oldptn (regexp-quote old))
yuuji@168 1140 (sw (selected-window))
yuuji@168 1141 (ptn (concat
yuuji@168 1142 "\\(" YaTeX-refcommand-ref-regexp "\\)"
yuuji@168 1143 "\\s *{" oldptn "}"))
yuuji@170 1144 (repface (and (fboundp 'make-overlay)
yuuji@170 1145 (fboundp 'internal-find-face)
yuuji@170 1146 (if (internal-find-face 'isearch) 'isearch 'region)))
yuuji@170 1147 ov
yuuji@173 1148 (qmsg "Replace to `%s'? [yn!rq?]")
yuuji@168 1149 continue ch)
yuuji@168 1150 (while bufs
yuuji@168 1151 (set-buffer (setq buf (car bufs)))
yuuji@168 1152 (save-excursion
yuuji@168 1153 (goto-char (point-min))
yuuji@168 1154 (while (re-search-forward ptn nil t)
yuuji@168 1155 (goto-char (match-end 1))
yuuji@168 1156 (skip-chars-forward " \t\n{")
yuuji@168 1157 (unwind-protect
yuuji@168 1158 (if (and
yuuji@168 1159 (looking-at oldptn)
yuuji@168 1160 (setq b (match-beginning 0)
yuuji@168 1161 e (match-end 0))
yuuji@168 1162 (or continue
yuuji@168 1163 (catch 'query
yuuji@170 1164 (if repface
yuuji@168 1165 (if ov (move-overlay ov b e)
yuuji@168 1166 (overlay-put
yuuji@168 1167 (setq ov (make-overlay b e))
yuuji@170 1168 'face repface)))
yuuji@168 1169 (switch-to-buffer buf)
yuuji@168 1170 (while t
yuuji@168 1171 (message qmsg new)
yuuji@168 1172 (setq ch (read-char))
yuuji@168 1173 (cond
yuuji@168 1174 ((= ch ?q) (throw 'exit t))
yuuji@168 1175 ((= ch ?r)
yuuji@168 1176 (message
yuuji@173 1177 "Don't forget to exit recursive-edit by `%s'"
yuuji@168 1178 (key-description
yuuji@168 1179 (where-is-internal
yuuji@168 1180 'exit-recursive-edit '(keymap) t)))
yuuji@168 1181 (sleep-for 2)
yuuji@168 1182 (recursive-edit))
yuuji@168 1183 ((= ch ?y) (throw 'query t))
yuuji@168 1184 ((= ch ?!) (throw 'query (setq continue t)))
yuuji@168 1185 ((= ch ??)
yuuji@168 1186 (describe-function
yuuji@168 1187 'YaTeX::label-rename-refs)
yuuji@168 1188 (select-window (get-buffer-window "*Help*"))
yuuji@168 1189 (search-forward "----")
yuuji@168 1190 (forward-line 1)
yuuji@168 1191 (set-window-start (selected-window) (point))
yuuji@168 1192 (sit-for 0)
yuuji@168 1193 (select-window sw))
yuuji@168 1194 ((= ch ?n) (throw 'query nil)))))))
yuuji@168 1195 (replace-match new))
yuuji@168 1196 (and ov (delete-overlay ov)))))
yuuji@168 1197 (setq bufs (cdr bufs)))))))
yuuji@168 1198
yuuji@167 1199 (defun YaTeX::label (argp &optional labname refname)
yuuji@163 1200 "Read label name and return it with copying \\ref{LABEL-NAME} to kill-ring."
yuuji@163 1201 (cond
yuuji@163 1202 ((= argp 1)
yuuji@168 1203 (let*((chmode (boundp (intern-soft "old")))
yuuji@168 1204 (dlab (if chmode old ;if called via YaTeX-change-section (tricky...)
yuuji@163 1205 (YaTeX::ref-default-label)))
yuuji@167 1206 (label (read-string
yuuji@167 1207 (format "New %s name: " (or labname "label"))
yuuji@167 1208 (cons dlab 1))))
yuuji@163 1209 (if (string< "" label)
yuuji@163 1210 (let ((refstr (format "\\%s{%s}" (or refname "ref") label))
yuuji@163 1211 (key (key-description (where-is-internal 'yank nil t)))
yuuji@163 1212 (msg
yuuji@163 1213 (if YaTeX-japan
yuuji@163 1214 "をkill-ringに入れました。yank(%s)で取り出せます。"
yuuji@163 1215 " is stored into kill-ring. Paste it by yank(%s).")))
yuuji@163 1216 (kill-new refstr)
yuuji@170 1217 (and chmode
yuuji@170 1218 (not (equal old label))
yuuji@173 1219 (YaTeX::label-rename-refs old label))
yuuji@173 1220 (message (concat "`%s'" msg) refstr key)))
yuuji@163 1221 label))))
yuuji@163 1222
yuuji@163 1223
yuuji@16 1224 (fset 'YaTeX::pageref 'YaTeX::ref)
yuuji@80 1225 (defun YaTeX::tabref (argp) ; For the style file of IPSJ journal
yuuji@80 1226 (YaTeX::ref
yuuji@80 1227 argp nil nil
yuuji@80 1228 (function
yuuji@80 1229 (lambda ()
yuuji@80 1230 (YaTeX-quick-in-environment-p "table")))))
yuuji@80 1231 (defun YaTeX::figref (argp) ; For the style file of IPSJ journal
yuuji@80 1232 (YaTeX::ref
yuuji@80 1233 argp nil nil
yuuji@80 1234 (function
yuuji@80 1235 (lambda ()
yuuji@80 1236 (YaTeX-quick-in-environment-p "figure")))))
yuuji@70 1237
yuuji@80 1238 (defun YaTeX::cite-collect-bibs-external (bibptn &rest files)
yuuji@80 1239 "Collect bibentry from FILES(variable length argument) ;
yuuji@70 1240 and print them to standard output."
yuuji@70 1241 ;;Thanks; http://icarus.ilcs.hokudai.ac.jp/comp/biblio.html
yuuji@80 1242 (let*((tb (get-buffer-create " *bibtmp*"))
yuuji@80 1243 (bibitemsep "^\\s *@[A-Za-z]")
yuuji@80 1244 (target (if (string< "" bibptn) bibptn bibitemsep))
yuuji@80 1245 (checkrx (concat "\\(" bibptn "\\)\\|" bibitemsep))
yuuji@80 1246 beg
yuuji@80 1247 (searchnext
yuuji@80 1248 (if (string< "" bibptn)
yuuji@80 1249 (function
yuuji@80 1250 (lambda()
yuuji@80 1251 (setq beg (point))
yuuji@80 1252 (and
yuuji@80 1253 (prog1
yuuji@80 1254 (re-search-forward target nil t)
yuuji@80 1255 (end-of-line))
yuuji@80 1256 (re-search-backward bibitemsep beg t))))
yuuji@80 1257 (function
yuuji@80 1258 (lambda()
yuuji@80 1259 (re-search-forward target nil t)))))
yuuji@80 1260 )
yuuji@70 1261 (save-excursion
yuuji@70 1262 (set-buffer tb)
yuuji@80 1263 (princ (format "%sbegin{thebibliography}\n" YaTeX-ec))
yuuji@70 1264 (while files
yuuji@70 1265 (erase-buffer)
yuuji@70 1266 (cond
yuuji@70 1267 ((file-exists-p (car files))
yuuji@70 1268 (insert-file-contents (car files)))
yuuji@70 1269 ((file-exists-p (concat (car files) ".bib"))
yuuji@70 1270 (insert-file-contents (concat (car files) ".bib"))))
yuuji@70 1271 (save-excursion
yuuji@70 1272 (goto-char (point-min))
yuuji@80 1273 (while (funcall searchnext)
yuuji@70 1274 (skip-chars-forward "^{,")
yuuji@80 1275 (setq beg (point))
yuuji@70 1276 (if (= (char-after (point)) ?{)
yuuji@70 1277 (princ (format "%sbibitem{%s}%s\n"
yuuji@70 1278 YaTeX-ec
yuuji@70 1279 (buffer-substring
yuuji@70 1280 (1+ (point))
yuuji@70 1281 (progn (skip-chars-forward "^,\n")
yuuji@70 1282 (point)))
yuuji@80 1283 (mapconcat
yuuji@80 1284 (function
yuuji@80 1285 (lambda (kwd)
yuuji@80 1286 (goto-char beg)
yuuji@80 1287 (if (re-search-forward
yuuji@80 1288 (concat kwd "\\s *=") nil t)
yuuji@80 1289 (buffer-substring
yuuji@80 1290 (progn
yuuji@80 1291 (goto-char (match-end 0))
yuuji@80 1292 (skip-chars-forward " \t\n")
yuuji@80 1293 (point))
yuuji@80 1294 (progn
yuuji@80 1295 (if (looking-at "[{\"]")
yuuji@80 1296 (forward-sexp 1)
yuuji@80 1297 (forward-char 1)
yuuji@80 1298 (skip-chars-forward "^,}"))
yuuji@80 1299 (point))))))
yuuji@80 1300 '("author" "year" "title" )
yuuji@80 1301 ";"))))
yuuji@80 1302 (and (re-search-forward bibitemsep nil t)
yuuji@80 1303 (forward-line -1))))
yuuji@80 1304 (setq files (cdr files)))
yuuji@80 1305 (princ (format "%sbegin{thebibliography}\n" YaTeX-ec)))))
yuuji@70 1306
yuuji@77 1307 (defvar YaTeX::cite-bibitem-macro-regexp "bibitem\\|harvarditem"
yuuji@77 1308 "*Regexp of macro name of bibitem definition")
yuuji@77 1309
yuuji@80 1310 (defun YaTeX::cite-collect-bibs-internal (bibptn)
yuuji@70 1311 "Collect bibentry in the current buffer and print them to standard output."
yuuji@77 1312 (let ((ptn (concat YaTeX-ec-regexp
yuuji@77 1313 "\\(" YaTeX::cite-bibitem-macro-regexp "\\)\\b"))
yuuji@80 1314 (lim (concat YaTeX-ec-regexp
yuuji@80 1315 "\\(" YaTeX::cite-bibitem-macro-regexp "\\b\\)"
yuuji@80 1316 "\\|\\(end{\\)"))
yuuji@70 1317 (pcnt (regexp-quote YaTeX-comment-prefix)))
yuuji@80 1318 ;; Using bibptn not yet implemented.
yuuji@80 1319 ;; Do you need it?? 2005/11/22
yuuji@70 1320 (save-excursion
yuuji@70 1321 (while (YaTeX-re-search-active-forward ptn pcnt nil t)
yuuji@70 1322 (skip-chars-forward "^{\n")
yuuji@70 1323 (or (eolp)
yuuji@80 1324 (princ (format "%sbibitem%s %s\n"
yuuji@70 1325 YaTeX-ec
yuuji@70 1326 (buffer-substring
yuuji@80 1327 (point)
yuuji@80 1328 (progn (forward-sexp 1) (point)))
yuuji@80 1329 (buffer-substring
yuuji@80 1330 (progn (skip-chars-forward "\n \t") (point))
yuuji@80 1331 (save-excursion
yuuji@80 1332 (if (YaTeX-re-search-active-forward
yuuji@80 1333 lim pcnt nil t)
yuuji@80 1334 (progn
yuuji@80 1335 (goto-char (match-beginning 0))
yuuji@80 1336 (skip-chars-backward "\n \t")
yuuji@80 1337 (point))
yuuji@80 1338 (point-end-of-line)))))))))))
yuuji@70 1339
yuuji@80 1340 (defun YaTeX::cite (argp &rest dummy)
yuuji@48 1341 (cond
yuuji@48 1342 ((eq argp 1)
yuuji@70 1343 (let* ((cb (current-buffer))
yuuji@70 1344 (f (file-name-nondirectory buffer-file-name))
yuuji@70 1345 (d default-directory)
yuuji@70 1346 (hilit-auto-highlight nil)
yuuji@70 1347 (pcnt (regexp-quote YaTeX-comment-prefix))
yuuji@70 1348 (bibrx (concat YaTeX-ec-regexp "bibliography{\\([^}]+\\)}"))
yuuji@80 1349 (bibptn (read-string "Pattern: "))
yuuji@70 1350 (bbuf (get-buffer-create " *bibitems*"))
yuuji@70 1351 (standard-output bbuf)
yuuji@80 1352 (me 'YaTeX::cite) ;shuld set this for using YaTeX::ref
yuuji@70 1353 bibs files)
yuuji@70 1354 (set-buffer bbuf)(erase-buffer)(set-buffer cb)
yuuji@70 1355 (save-excursion
yuuji@70 1356 (goto-char (point-min))
yuuji@70 1357 ;;(1)search external bibdata
yuuji@70 1358 (while (YaTeX-re-search-active-forward bibrx pcnt nil t)
yuuji@70 1359 (apply 'YaTeX::cite-collect-bibs-external
yuuji@80 1360 bibptn
yuuji@70 1361 (YaTeX-split-string
yuuji@70 1362 (YaTeX-match-string 1) ",")))
yuuji@70 1363 ;;(2)search direct \bibitem usage
yuuji@80 1364 (YaTeX::cite-collect-bibs-internal bibptn)
yuuji@70 1365 (if (progn
yuuji@70 1366 (YaTeX-visit-main t)
yuuji@70 1367 (not (eq (current-buffer) cb)))
yuuji@70 1368 (save-excursion
yuuji@70 1369 (goto-char (point-min))
yuuji@70 1370 ;;(1)search external bibdata
yuuji@70 1371 (while (YaTeX-re-search-active-forward bibrx pcnt nil t)
yuuji@70 1372 (apply 'YaTeX::cite-collect-bibs-external
yuuji@80 1373 bibptn
yuuji@70 1374 (YaTeX-split-string
yuuji@70 1375 (YaTeX-match-string 1) ",")))
yuuji@70 1376 ;;(2)search internal
yuuji@80 1377 (YaTeX::cite-collect-bibs-internal bibptn)))
yuuji@70 1378 ;;Now bbuf holds the list of bibitem
yuuji@70 1379 (set-buffer bbuf)
yuuji@80 1380 ;;;(switch-to-buffer bbuf)
yuuji@80 1381 (if (fboundp 'font-lock-fontify-buffer) (font-lock-fontify-buffer))
yuuji@77 1382 (YaTeX::ref
yuuji@77 1383 argp
yuuji@77 1384 (concat "\\\\\\("
yuuji@77 1385 YaTeX::cite-bibitem-macro-regexp
yuuji@77 1386 "\\)\\(\\[.*\\]\\)?")
yuuji@77 1387 "cite"))))
yuuji@77 1388
yuuji@48 1389 (t nil)))
yuuji@11 1390
yuuji@167 1391 (defun YaTeX::bibitem (argp)
yuuji@167 1392 "Add-in function to insert argument of \\bibitem."
yuuji@167 1393 (YaTeX::label argp "label" "cite"))
yuuji@167 1394
yuuji@77 1395 ;;; for AMS-LaTeX
yuuji@70 1396 (and YaTeX-use-AMS-LaTeX (fset 'YaTeX::eqref 'YaTeX::ref))
yuuji@77 1397 ;;; for Harvard citation style
yuuji@77 1398 (fset 'YaTeX::citeasnoun 'YaTeX::cite)
yuuji@77 1399 (fset 'YaTeX::possessivecite 'YaTeX::cite)
yuuji@77 1400 (fset 'YaTeX::citeyear 'YaTeX::cite)
yuuji@77 1401 (fset 'YaTeX::citename 'YaTeX::cite)
yuuji@80 1402 (fset 'YaTeX::citep 'YaTeX::cite)
yuuji@80 1403 (fset 'YaTeX::citet 'YaTeX::cite)
yuuji@70 1404
yuuji@48 1405 (defun YaTeX-select-other-yatex-buffer ()
yuuji@48 1406 "Select buffer from all yatex-mode's buffers interactivelly."
yuuji@48 1407 (interactive)
yuuji@48 1408 (let ((lbuf "*YaTeX mode buffers*") (blist (YaTeX-yatex-buffer-list))
yuuji@48 1409 (lnum -1) buf rv
yuuji@11 1410 (ff "**find-file**"))
yuuji@12 1411 (YaTeX-showup-buffer
yuuji@12 1412 lbuf (function (lambda (x) 1))) ;;Select next window surely.
yuuji@69 1413 (save-excursion
yuuji@69 1414 (set-buffer (get-buffer lbuf))
yuuji@69 1415 (setq buffer-read-only nil)
yuuji@69 1416 (erase-buffer))
yuuji@69 1417 (let ((standard-output (get-buffer lbuf)))
yuuji@11 1418 (while blist
yuuji@48 1419 (princ
yuuji@48 1420 (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A)
yuuji@48 1421 (buffer-name (car blist))))
yuuji@11 1422 (setq blist (cdr blist)))
yuuji@11 1423 (princ (format "':{%s}" ff)))
yuuji@59 1424 (YaTeX-showup-buffer lbuf nil t)
yuuji@11 1425 (YaTeX::label-setup-key-map)
yuuji@11 1426 (setq buffer-read-only t)
yuuji@11 1427 (use-local-map YaTeX-label-select-map)
yuuji@11 1428 (message YaTeX-label-guide-msg)
yuuji@11 1429 (unwind-protect
yuuji@11 1430 (progn
yuuji@11 1431 (recursive-edit)
yuuji@11 1432 (set-buffer lbuf)
yuuji@11 1433 (beginning-of-line)
yuuji@11 1434 (setq rv
yuuji@11 1435 (if (re-search-forward "{\\([^\\}]+\\)}" (point-end-of-line) t)
yuuji@11 1436 (buffer-substring (match-beginning 1) (match-end 1)) nil)))
yuuji@11 1437 (kill-buffer lbuf))
yuuji@48 1438 (if (string= rv ff)
yuuji@48 1439 (progn
yuuji@48 1440 (call-interactively 'find-file)
yuuji@48 1441 (current-buffer))
yuuji@69 1442 rv)))
yuuji@48 1443
yuuji@48 1444 (defun YaTeX-label-other ()
yuuji@48 1445 (let ((rv (YaTeX-select-other-yatex-buffer)))
yuuji@11 1446 (cond
yuuji@11 1447 ((null rv) "")
yuuji@11 1448 (t
yuuji@11 1449 (set-buffer rv)
yuuji@80 1450 (funcall me argp labelcmd refcmd)))))
yuuji@11 1451
yuuji@13 1452 ;;
yuuji@13 1453 ; completion for the arguments of \newcommand
yuuji@13 1454 ;;
yuuji@13 1455 (defun YaTeX::newcommand (&optional argp)
yuuji@13 1456 (cond
yuuji@13 1457 ((= argp 1)
yuuji@13 1458 (let ((command (read-string "Define newcommand: " "\\")))
yuuji@13 1459 (put 'YaTeX::newcommand 'command (substring command 1))
yuuji@13 1460 command))
yuuji@13 1461 ((= argp 2)
yuuji@13 1462 (let ((argc
yuuji@13 1463 (string-to-int (read-string "Number of arguments(Default 0): ")))
yuuji@13 1464 (def (read-string "Definition: "))
yuuji@13 1465 (command (get 'YaTeX::newcommand 'command)))
yuuji@13 1466 ;;!!! It's illegal to insert string in the add-in function !!!
yuuji@13 1467 (if (> argc 0) (insert (format "[%d]" argc)))
yuuji@13 1468 (if (and (stringp command)
yuuji@13 1469 (string< "" command)
yuuji@51 1470 (y-or-n-p "Update dictionary?"))
yuuji@18 1471 (cond
yuuji@18 1472 ((= argc 0)
yuuji@18 1473 (YaTeX-update-table
yuuji@18 1474 (list command)
yuuji@18 1475 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table))
yuuji@18 1476 ((= argc 1)
yuuji@18 1477 (YaTeX-update-table
yuuji@18 1478 (list command)
yuuji@18 1479 'section-table 'user-section-table 'tmp-section-table))
yuuji@18 1480 (t (YaTeX-update-table
yuuji@18 1481 (list command argc)
yuuji@18 1482 'section-table 'user-section-table 'tmp-section-table))))
yuuji@13 1483 (message "")
yuuji@13 1484 def ;return command name
yuuji@13 1485 ))
yuuji@69 1486 (t "")))
yuuji@13 1487
yuuji@80 1488 (defun YaTeX::newcounter (&optional argp)
yuuji@80 1489 (cond
yuuji@80 1490 ((= argp 1)
yuuji@80 1491 (read-string "New counter name: "))
yuuji@80 1492 (t "")))
yuuji@80 1493
yuuji@16 1494 ;;
yuuji@16 1495 ; completion for the arguments of \pagestyle
yuuji@16 1496 ;;
yuuji@16 1497 (defun YaTeX::pagestyle (&optional argp)
yuuji@16 1498 "Read the pagestyle with completion."
yuuji@16 1499 (completing-read
yuuji@16 1500 "Page style: "
yuuji@69 1501 '(("plain") ("empty") ("headings") ("myheadings") ("normal") nil)))
yuuji@69 1502
yuuji@51 1503 (fset 'YaTeX::thispagestyle 'YaTeX::pagestyle)
yuuji@51 1504
yuuji@16 1505 ;;
yuuji@16 1506 ; completion for the arguments of \pagenumbering
yuuji@16 1507 ;;
yuuji@16 1508 (defun YaTeX::pagenumbering (&optional argp)
yuuji@16 1509 "Read the numbering style."
yuuji@16 1510 (completing-read
yuuji@16 1511 "Page numbering style: "
yuuji@69 1512 '(("arabic") ("Alpha") ("alpha") ("Roman") ("roman"))))
yuuji@13 1513
yuuji@23 1514 ;;
yuuji@23 1515 ; Length
yuuji@23 1516 ;;
yuuji@23 1517 (defvar YaTeX:style-parameters-default
yuuji@23 1518 '(("\\arraycolsep")
yuuji@23 1519 ("\\arrayrulewidth")
yuuji@23 1520 ("\\baselineskip")
yuuji@23 1521 ("\\columnsep")
yuuji@23 1522 ("\\columnseprule")
yuuji@23 1523 ("\\doublerulesep")
yuuji@23 1524 ("\\evensidemargin")
yuuji@23 1525 ("\\footheight")
yuuji@23 1526 ("\\footskip")
yuuji@23 1527 ("\\headheight")
yuuji@23 1528 ("\\headsep")
yuuji@23 1529 ("\\itemindent")
yuuji@23 1530 ("\\itemsep")
yuuji@23 1531 ("\\labelsep")
yuuji@23 1532 ("\\labelwidth")
yuuji@23 1533 ("\\leftmargin")
yuuji@23 1534 ("\\linewidth")
yuuji@23 1535 ("\\listparindent")
yuuji@23 1536 ("\\marginparsep")
yuuji@23 1537 ("\\marginparwidth")
yuuji@23 1538 ("\\mathindent")
yuuji@23 1539 ("\\oddsidemargin")
yuuji@23 1540 ("\\parindent")
yuuji@23 1541 ("\\parsep")
yuuji@23 1542 ("\\parskip")
yuuji@23 1543 ("\\partopsep")
yuuji@23 1544 ("\\rightmargin")
yuuji@23 1545 ("\\tabcolsep")
yuuji@23 1546 ("\\textheight")
yuuji@23 1547 ("\\textwidth")
yuuji@23 1548 ("\\topmargin")
yuuji@23 1549 ("\\topsep")
yuuji@23 1550 ("\\topskip")
yuuji@23 1551 )
yuuji@23 1552 "Alist of LaTeX style parameters.")
yuuji@23 1553 (defvar YaTeX:style-parameters-private nil
yuuji@23 1554 "*User definable alist of style parameters.")
yuuji@49 1555 (defvar YaTeX:style-parameters-local nil
yuuji@49 1556 "*User definable alist of local style parameters.")
yuuji@23 1557
yuuji@23 1558 (defvar YaTeX:length-history nil "Holds history of length.")
yuuji@51 1559 (put 'YaTeX:length-history 'no-default t)
yuuji@23 1560 (defun YaTeX::setlength (&optional argp)
yuuji@23 1561 "YaTeX add-in function for arguments of \\setlength."
yuuji@23 1562 (cond
yuuji@23 1563 ((equal 1 argp)
yuuji@49 1564 ;;(completing-read "Length variable: " YaTeX:style-parameters nil nil "\\")
yuuji@49 1565 (YaTeX-cplread-with-learning
yuuji@49 1566 "Length variable: "
yuuji@49 1567 'YaTeX:style-parameters-default
yuuji@49 1568 'YaTeX:style-parameters-private
yuuji@49 1569 'YaTeX:style-parameters-local
yuuji@49 1570 nil nil "\\")
yuuji@49 1571 )
yuuji@23 1572 ((equal 2 argp)
yuuji@69 1573 (read-string-with-history "Length: " nil 'YaTeX:length-history))))
yuuji@69 1574
yuuji@23 1575 (fset 'YaTeX::addtolength 'YaTeX::setlength)
yuuji@23 1576
yuuji@23 1577 (defun YaTeX::settowidth (&optional argp)
yuuji@23 1578 "YaTeX add-in function for arguments of \\settowidth."
yuuji@23 1579 (cond
yuuji@23 1580 ((equal 1 argp)
yuuji@49 1581 (YaTeX-cplread-with-learning
yuuji@49 1582 "Length variable: "
yuuji@49 1583 'YaTeX:style-parameters-default
yuuji@49 1584 'YaTeX:style-parameters-private
yuuji@49 1585 'YaTeX:style-parameters-local
yuuji@49 1586 nil nil "\\"))
yuuji@23 1587 ((equal 2 argp)
yuuji@69 1588 (read-string "Text: "))))
yuuji@69 1589
yuuji@23 1590 (defun YaTeX::newlength (&optional argp)
yuuji@23 1591 "YaTeX add-in function for arguments of \\newlength"
yuuji@23 1592 (cond
yuuji@23 1593 ((equal argp 1)
yuuji@23 1594 (let ((length (read-string "Length variable: " "\\")))
yuuji@49 1595 (if (string< "" length)
yuuji@49 1596 (YaTeX-update-table
yuuji@49 1597 (list length)
yuuji@49 1598 'YaTeX:style-parameters-default
yuuji@49 1599 'YaTeX:style-parameters-private
yuuji@49 1600 'YaTeX:style-parameters-local))
yuuji@69 1601 length))))
yuuji@23 1602
yuuji@23 1603 ;; \multicolumn's arguments
yuuji@23 1604 (defun YaTeX::multicolumn (&optional argp)
yuuji@23 1605 "YaTeX add-in function for arguments of \\multicolumn."
yuuji@23 1606 (cond
yuuji@23 1607 ((equal 1 argp)
yuuji@23 1608 (read-string "Number of columns: "))
yuuji@23 1609 ((equal 2 argp)
yuuji@79 1610 (YaTeX:read-oneof "|lrc" nil t))
yuuji@23 1611 ((equal 3 argp)
yuuji@69 1612 (read-string "Item: "))))
yuuji@23 1613
yuuji@49 1614 (defvar YaTeX:documentstyles-default
yuuji@49 1615 '(("article") ("jarticle") ("j-article")
yuuji@49 1616 ("book") ("jbook") ("j-book")
yuuji@49 1617 ("report") ("jreport") ("j-report")
yuuji@49 1618 ("letter") ("ascjletter"))
yuuji@49 1619 "List of LaTeX documentstyles.")
yuuji@49 1620 (defvar YaTeX:documentstyles-private nil
yuuji@49 1621 "*User defined list of LaTeX documentstyles.")
yuuji@49 1622 (defvar YaTeX:documentstyles-local nil
yuuji@49 1623 "*User defined list of local LaTeX documentstyles.")
yuuji@49 1624 (defvar YaTeX:documentstyle-options-default
yuuji@49 1625 '(("a4j") ("a5j") ("b4j") ("b5j")
yuuji@49 1626 ("twocolumn") ("jtwocolumn") ("epsf") ("epsfig") ("epsbox") ("nfig"))
yuuji@49 1627 "List of LaTeX documentstyle options.")
yuuji@49 1628 (defvar YaTeX:documentstyle-options-private nil
yuuji@49 1629 "*User defined list of LaTeX documentstyle options.")
yuuji@49 1630 (defvar YaTeX:documentstyle-options-local nil
yuuji@49 1631 "List of LaTeX local documentstyle options.")
yuuji@49 1632
yuuji@49 1633 (defun YaTeX:documentstyle ()
yuuji@49 1634 (let*((delim ",")
yuuji@49 1635 (dt (append YaTeX:documentstyle-options-local
yuuji@49 1636 YaTeX:documentstyle-options-private
yuuji@49 1637 YaTeX:documentstyle-options-default))
yuuji@49 1638 (minibuffer-completion-table dt)
yuuji@49 1639 (opt (read-from-minibuffer
yuuji@49 1640 "Style options ([opt1,opt2,...]): "
yuuji@51 1641 nil YaTeX-minibuffer-completion-map nil))
yuuji@49 1642 (substr opt) o)
yuuji@49 1643 (if (string< "" opt)
yuuji@49 1644 (progn
yuuji@49 1645 (while substr
yuuji@49 1646 (setq o (substring substr 0 (string-match delim substr)))
yuuji@49 1647 (or (assoc o dt)
yuuji@49 1648 (YaTeX-update-table
yuuji@49 1649 (list o)
yuuji@49 1650 'YaTeX:documentstyle-options-default
yuuji@49 1651 'YaTeX:documentstyle-options-private
yuuji@49 1652 'YaTeX:documentstyle-options-local))
yuuji@49 1653 (setq substr
yuuji@49 1654 (if (string-match delim substr)
yuuji@49 1655 (substring substr (1+ (string-match delim substr))))))
yuuji@49 1656 (concat "[" opt "]"))
yuuji@49 1657 "")))
yuuji@49 1658
yuuji@49 1659 (defun YaTeX::documentstyle (&optional argp)
yuuji@51 1660 "YaTeX add-in function for arguments of \\documentstyle."
yuuji@49 1661 (cond
yuuji@49 1662 ((equal argp 1)
yuuji@72 1663 (setq YaTeX-env-name "document")
yuuji@49 1664 (let ((sname
yuuji@49 1665 (YaTeX-cplread-with-learning
yuuji@49 1666 (format "Documentstyle (default %s): "
yuuji@49 1667 YaTeX-default-document-style)
yuuji@49 1668 'YaTeX:documentstyles-default
yuuji@49 1669 'YaTeX:documentstyles-private
yuuji@49 1670 'YaTeX:documentstyles-local)))
yuuji@49 1671 (if (string= "" sname) (setq sname YaTeX-default-document-style))
yuuji@69 1672 (setq YaTeX-default-document-style sname)))))
yuuji@49 1673
yuuji@80 1674 (defun YaTeX::include (argp &optional prompt)
yuuji@86 1675 "Read file name setting default directory to that of main file."
yuuji@80 1676 (cond
yuuji@80 1677 ((= argp 1)
yuuji@86 1678 (save-excursion
yuuji@86 1679 (YaTeX-visit-main t)
yuuji@86 1680 (let*((insert-default-directory)
yuuji@86 1681 (file (read-file-name (or prompt "Input file: ") "")))
yuuji@86 1682 (setq file (substring file 0 (string-match "\\.tex$" file))))))))
yuuji@80 1683
yuuji@80 1684 (fset 'YaTeX::input 'YaTeX::include)
yuuji@80 1685
yuuji@80 1686
yuuji@57 1687 ;;; -------------------- LaTeX2e stuff --------------------
yuuji@57 1688 (defvar YaTeX:documentclass-options-default
yuuji@70 1689 '(("a4paper") ("a5paper") ("b4paper") ("b5paper") ("10pt") ("11pt") ("12pt")
yuuji@57 1690 ("latterpaper") ("legalpaper") ("executivepaper") ("landscape")
yuuji@57 1691 ("oneside") ("twoside") ("draft") ("final") ("leqno") ("fleqn") ("openbib")
yuuji@70 1692 ("tombow") ("titlepage") ("notitlepage") ("dvips")
yuuji@175 1693 ("mingoth") ;for jsarticle
yuuji@57 1694 ("clock") ;for slides class only
yuuji@57 1695 )
yuuji@57 1696 "Default options list for documentclass")
yuuji@57 1697 (defvar YaTeX:documentclass-options-private nil
yuuji@57 1698 "*User defined options list for documentclass")
yuuji@57 1699 (defvar YaTeX:documentclass-options-local nil
yuuji@57 1700 "*User defined options list for local documentclass")
yuuji@57 1701
yuuji@57 1702 (defun YaTeX:documentclass ()
yuuji@57 1703 (let*((delim ",")
yuuji@57 1704 (dt (append YaTeX:documentclass-options-local
yuuji@57 1705 YaTeX:documentclass-options-private
yuuji@57 1706 YaTeX:documentclass-options-default))
yuuji@57 1707 (minibuffer-completion-table dt)
yuuji@57 1708 (opt (read-from-minibuffer
yuuji@57 1709 "Documentclass options ([opt1,opt2,...]): "
yuuji@57 1710 nil YaTeX-minibuffer-completion-map nil))
yuuji@57 1711 (substr opt) o)
yuuji@57 1712 (if (string< "" opt)
yuuji@57 1713 (progn
yuuji@57 1714 (while substr
yuuji@70 1715
yuuji@57 1716 (setq o (substring substr 0 (string-match delim substr)))
yuuji@57 1717 (or (assoc o dt)
yuuji@57 1718 (YaTeX-update-table
yuuji@57 1719 (list o)
yuuji@57 1720 'YaTeX:documentclass-options-default
yuuji@57 1721 'YaTeX:documentclass-options-private
yuuji@57 1722 'YaTeX:documentclass-options-local))
yuuji@57 1723 (setq substr
yuuji@57 1724 (if (string-match delim substr)
yuuji@57 1725 (substring substr (1+ (string-match delim substr))))))
yuuji@57 1726 (concat "[" opt "]"))
yuuji@57 1727 "")))
yuuji@57 1728
yuuji@57 1729 (defvar YaTeX:documentclasses-default
yuuji@57 1730 '(("article") ("jarticle") ("report") ("jreport") ("book") ("jbook")
yuuji@175 1731 ("jsarticle") ("jsbook")
yuuji@57 1732 ("j-article") ("j-report") ("j-book")
yuuji@57 1733 ("letter") ("slides") ("ltxdoc") ("ltxguide") ("ltnews") ("proc"))
yuuji@57 1734 "Default documentclass alist")
yuuji@57 1735 (defvar YaTeX:documentclasses-private nil
yuuji@57 1736 "*User defined documentclass alist")
yuuji@57 1737 (defvar YaTeX:documentclasses-local nil
yuuji@57 1738 "*User defined local documentclass alist")
yuuji@57 1739 (defvar YaTeX-default-documentclass (if YaTeX-japan "jarticle" "article")
yuuji@57 1740 "*Default documentclass")
yuuji@57 1741
yuuji@57 1742 (defun YaTeX::documentclass (&optional argp)
yuuji@57 1743 (cond
yuuji@57 1744 ((equal argp 1)
yuuji@72 1745 (setq YaTeX-env-name "document")
yuuji@57 1746 (let ((sname
yuuji@57 1747 (YaTeX-cplread-with-learning
yuuji@57 1748 (format "Documentclass (default %s): " YaTeX-default-documentclass)
yuuji@57 1749 'YaTeX:documentclasses-default
yuuji@57 1750 'YaTeX:documentclasses-private
yuuji@57 1751 'YaTeX:documentclasses-local)))
yuuji@57 1752 (if (string= "" sname) (setq sname YaTeX-default-documentclass))
yuuji@57 1753 (setq YaTeX-default-documentclass sname)))))
yuuji@57 1754
yuuji@70 1755 (defvar YaTeX:latex2e-named-color-alist
yuuji@70 1756 '(("GreenYellow") ("Yellow") ("Goldenrod") ("Dandelion") ("Apricot")
yuuji@70 1757 ("Peach") ("Melon") ("YellowOrange") ("Orange") ("BurntOrange")
yuuji@70 1758 ("Bittersweet") ("RedOrange") ("Mahogany") ("Maroon") ("BrickRed")
yuuji@70 1759 ("Red") ("OrangeRed") ("RubineRed") ("WildStrawberry") ("Salmon")
yuuji@70 1760 ("CarnationPink") ("Magenta") ("VioletRed") ("Rhodamine") ("Mulberry")
yuuji@70 1761 ("RedViolet") ("Fuchsia") ("Lavender") ("Thistle") ("Orchid")("DarkOrchid")
yuuji@70 1762 ("Purple") ("Plum") ("Violet") ("RoyalPurple") ("BlueViolet")
yuuji@70 1763 ("Periwinkle") ("CadetBlue") ("CornflowerBlue") ("MidnightBlue")
yuuji@70 1764 ("NavyBlue") ("RoyalBlue") ("Blue") ("Cerulean") ("Cyan") ("ProcessBlue")
yuuji@70 1765 ("SkyBlue") ("Turquoise") ("TealBlue") ("Aquamarine") ("BlueGreen")
yuuji@70 1766 ("Emerald") ("JungleGreen") ("SeaGreen") ("Green") ("ForestGreen")
yuuji@70 1767 ("PineGreen") ("LimeGreen") ("YellowGreen") ("SpringGreen") ("OliveGreen")
yuuji@70 1768 ("RawSienna") ("Sepia") ("Brown") ("Tan") ("Gray") ("Black") ("White"))
yuuji@141 1769 "Colors defined in $TEXMF/tex/plain/dvips/colordvi.tex")
yuuji@70 1770
yuuji@70 1771 (defvar YaTeX:latex2e-basic-color-alist
yuuji@70 1772 '(("black") ("white") ("red") ("blue") ("yellow") ("green") ("cyan")
yuuji@70 1773 ("magenta"))
yuuji@70 1774 "Basic colors")
yuuji@70 1775
yuuji@70 1776 (defun YaTeX:textcolor ()
yuuji@70 1777 "Add-in for \\color's option"
yuuji@70 1778 (if (y-or-n-p "Use `named' color? ")
yuuji@70 1779 "[named]"))
yuuji@70 1780
yuuji@70 1781 (defun YaTeX::color-completing-read (prompt)
yuuji@70 1782 (let ((completion-ignore-case t)
yuuji@70 1783 (namedp (save-excursion
yuuji@70 1784 (skip-chars-backward "^\n\\[\\\\")
yuuji@70 1785 (looking-at "named"))))
yuuji@70 1786 (completing-read
yuuji@70 1787 prompt
yuuji@70 1788 (if namedp
yuuji@70 1789 YaTeX:latex2e-named-color-alist
yuuji@70 1790 YaTeX:latex2e-basic-color-alist)
yuuji@70 1791 nil t)))
yuuji@70 1792
yuuji@70 1793 (defun YaTeX::textcolor (argp)
yuuji@70 1794 "Add-in for \\color's argument"
yuuji@70 1795 (cond
yuuji@70 1796 ((= argp 1) (YaTeX::color-completing-read "Color: "))
yuuji@70 1797 ((= argp 2) (read-string "Colored string: "))))
yuuji@70 1798
yuuji@70 1799 (fset 'YaTeX:color 'YaTeX:textcolor)
yuuji@70 1800 (fset 'YaTeX::color 'YaTeX::textcolor)
yuuji@70 1801 (fset 'YaTeX:colorbox 'YaTeX:textcolor)
yuuji@70 1802 (fset 'YaTeX::colorbox 'YaTeX::textcolor)
yuuji@70 1803 (fset 'YaTeX:fcolorbox 'YaTeX:textcolor)
yuuji@80 1804 (fset 'YaTeX:pagecolor 'YaTeX:textcolor)
yuuji@80 1805 (fset 'YaTeX::pagecolor 'YaTeX::textcolor)
yuuji@70 1806
yuuji@70 1807 (defun YaTeX::fcolorbox (argp)
yuuji@70 1808 (cond
yuuji@70 1809 ((= argp 1) (YaTeX::color-completing-read "Frame color: "))
yuuji@70 1810 ((= argp 2) (YaTeX::color-completing-read "Inner color: "))
yuuji@70 1811 ((= argp 3) (read-string "Colored string: "))))
yuuji@70 1812
yuuji@70 1813 (defun YaTeX:scalebox ()
yuuji@80 1814 "Add-in for \\scalebox"
yuuji@80 1815 (let ((vmag (read-string
yuuji@80 1816 (if YaTeX-japan "倍率(負で反転): "
yuuji@80 1817 "Magnification(Negative for flipped): ")))
yuuji@80 1818 (hmag (read-string (if YaTeX-japan "縦倍率(省略可): "
yuuji@80 1819 "Vertical magnification(Optional): "))))
yuuji@70 1820 (if (and hmag (string< "" hmag))
yuuji@70 1821 (format "{%s}[%s]" vmag hmag)
yuuji@70 1822 (format "{%s}" vmag))))
yuuji@70 1823
yuuji@80 1824 (defun YaTeX:rotatebox ()
yuuji@80 1825 "Optional argument add-in for \\rotatebox"
yuuji@80 1826 (message "Rotate origin? (N)one (O)rigin (X)-Y: ")
yuuji@80 1827 (let ((c (read-char)) r (defx "x=mm") x (defy "y=mm") y something)
yuuji@80 1828 (cond
yuuji@80 1829 ((memq c '(?O ?o))
yuuji@80 1830 (if (string< "" (setq r (YaTeX:read-oneof "htbpB")))
yuuji@80 1831 (concat "[origin=" r "]")))
yuuji@80 1832 ((memq c '(?X ?x ?Y ?y))
yuuji@80 1833 (setq r (read-string "" (if YaTeX-emacs-19 (cons defx 3) defx))
yuuji@80 1834 x (if (string< "x=" r) r)
yuuji@80 1835 r (read-string "" (if YaTeX-emacs-19 (cons defy 3) defy))
yuuji@80 1836 y (if (string< "y=" r) r)
yuuji@80 1837 something (or x y))
yuuji@80 1838 (format "%s%s%s%s%s"
yuuji@80 1839 (if something "[" "")
yuuji@80 1840 (if x x "")
yuuji@80 1841 (if (and x y) "," "")
yuuji@80 1842 (if y y "")
yuuji@80 1843 (if something "]" ""))))))
yuuji@80 1844
yuuji@80 1845 (defun YaTeX::rotatebox (argp)
yuuji@80 1846 "Argument add-in for \\rotatebox"
yuuji@80 1847 (cond
yuuji@80 1848 ((= argp 1)
yuuji@80 1849 (read-string (if YaTeX-japan "回転角(度; 左回り): "
yuuji@80 1850 "Angle in degree(unclockwise): ")))
yuuji@80 1851 ((= argp 2)
yuuji@80 1852 (read-string (if YaTeX-japan "テキスト: " "Text: ")))))
yuuji@80 1853
yuuji@73 1854 (defun YaTeX:includegraphics ()
yuuji@73 1855 "Add-in for \\includegraphics's option"
yuuji@73 1856 (let (width height (scale "") angle str)
yuuji@73 1857 (setq width (read-string "Width: ")
yuuji@73 1858 height (read-string "Height: "))
yuuji@73 1859 (or (string< width "") (string< "" height)
yuuji@73 1860 (setq scale (read-string "Scale: ")))
yuuji@73 1861 (setq angle (read-string "Angle(0-359): "))
yuuji@73 1862 (setq str
yuuji@73 1863 (mapconcat
yuuji@73 1864 'concat
yuuji@73 1865 (delq nil
yuuji@73 1866 (mapcar '(lambda (s)
yuuji@73 1867 (and (stringp (symbol-value s))
yuuji@73 1868 (string< "" (symbol-value s))
yuuji@73 1869 (format "%s=%s" s (symbol-value s))))
yuuji@73 1870 '(width height scale angle)))
yuuji@73 1871 ","))
yuuji@73 1872 (if (string= "" str) ""
yuuji@73 1873 (concat "[" str "]"))))
yuuji@73 1874
yuuji@70 1875 (defun YaTeX::includegraphics (argp)
yuuji@70 1876 "Add-in for \\includegraphics"
yuuji@80 1877 (YaTeX::include argp "Image File: "))
yuuji@70 1878
yuuji@86 1879 (defun YaTeX::verbfile (argp)
yuuji@86 1880 "Add-in for \\verbfile"
yuuji@86 1881 (YaTeX::include argp "Virbatim File: "))
yuuji@86 1882
yuuji@68 1883 (defun YaTeX:caption ()
yuuji@72 1884 (setq YaTeX-section-name "label")
yuuji@68 1885 nil)
yuuji@68 1886
yuuji@80 1887
yuuji@79 1888 (defvar YaTeX::usepackage-alist-default
yuuji@79 1889 '(("version") ("plext") ("url") ("fancybox") ("pifont") ("longtable")
yuuji@79 1890 ("ascmac") ("bm") ("graphics") ("graphicx") ("alltt") ("misc") ("eclbkbox")
yuuji@79 1891 ("amsmath") ("amssymb") ("xymtex") ("chemist")
yuuji@79 1892 ("a4j") ("array") ("epsf") ("color") ("epsfig") ("floatfig")
yuuji@80 1893 ("landscape") ("path") ("supertabular") ("twocolumn")
yuuji@80 1894 ("latexsym") ("times") ("makeidx"))
yuuji@80 1895 "Default completion table for arguments of \\usepackage")
yuuji@79 1896
yuuji@79 1897 (defvar YaTeX::usepackage-alist-private nil
yuuji@79 1898 "*Private completion list of the argument for usepackage")
yuuji@79 1899
yuuji@79 1900 (defvar YaTeX::usepackage-alist-local nil
yuuji@79 1901 "Directory local completion list of the argument for usepackage")
yuuji@79 1902
yuuji@79 1903 (defun YaTeX::usepackage (&optional argp)
yuuji@79 1904 (cond
yuuji@79 1905 ((equal argp 1)
yuuji@79 1906 (setq YaTeX-env-name "document")
yuuji@80 1907 (let ((minibuffer-local-completion-map YaTeX-minibuffer-completion-map)
yuuji@80 1908 (delim ","))
yuuji@80 1909 (YaTeX-cplread-with-learning
yuuji@80 1910 (if YaTeX-japan "Use package(カンマで区切ってOK): "
yuuji@80 1911 "Use package(delimitable by comma): ")
yuuji@80 1912 'YaTeX::usepackage-alist-default
yuuji@80 1913 'YaTeX::usepackage-alist-private
yuuji@80 1914 'YaTeX::usepackage-alist-local)))))
yuuji@79 1915
yuuji@79 1916 (defun YaTeX::mask (argp)
yuuji@79 1917 (cond
yuuji@79 1918 ((equal argp 1)
yuuji@79 1919 (read-string "String: "))
yuuji@79 1920 ((equal argp 2)
yuuji@79 1921 (let (c)
yuuji@79 1922 (while (not (memq c '(?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K)))
yuuji@79 1923 (message "Mask type(A..K): ")
yuuji@79 1924 (setq c (upcase (read-char))))
yuuji@79 1925 (format "%c" c)))))
yuuji@79 1926
yuuji@79 1927 (defun YaTeX::maskbox (argp)
yuuji@79 1928 (cond
yuuji@79 1929 ((equal argp 1)
yuuji@79 1930 (read-string "Width: "))
yuuji@79 1931 ((equal argp 2)
yuuji@79 1932 (read-string "Height: "))
yuuji@79 1933 ((equal argp 3)
yuuji@79 1934 (let (c)
yuuji@79 1935 (while (not (memq c '(?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K)))
yuuji@79 1936 (message "Mask type(A..K): ")
yuuji@79 1937 (setq c (upcase (read-char))))
yuuji@79 1938 (format "%c" c)))
yuuji@79 1939 ((equal argp 4)
yuuji@79 1940 (YaTeX:read-oneof "lcr" 'quick))
yuuji@79 1941 ((equal argp 5)
yuuji@80 1942 (read-string "String: "))))
yuuji@80 1943
yuuji@80 1944 (defun YaTeX::textcircled (argp)
yuuji@80 1945 (cond
yuuji@80 1946 ((equal argp 1)
yuuji@80 1947 (let ((char (read-string "Circled char: "))
yuuji@80 1948 (left "") (right "") c)
yuuji@80 1949 (setq c (read-char
yuuji@80 1950 "Enclose also with (s)mall (t)iny s(C)riptsize (N)one:"))
yuuji@80 1951 (cond
yuuji@80 1952 ((memq c '(?s ?S)) (setq left "{\\small " right "}"))
yuuji@80 1953 ((memq c '(?t ?T)) (setq left "{\\tiny " right "}"))
yuuji@80 1954 ((memq c '(?c ?C)) (setq left "{\\scriptsize " right "}")))
yuuji@80 1955 (format "%s%s%s" left char right)))))
yuuji@79 1956
yuuji@68 1957 ;;; -------------------- math-mode stuff --------------------
yuuji@68 1958 (defun YaTeX::tilde (&optional pos)
yuuji@68 1959 "For accent macros in mathmode"
yuuji@68 1960 (cond
yuuji@68 1961 ((equal pos 1)
yuuji@68 1962 (message "Put accent on variable: ")
yuuji@68 1963 (let ((v (char-to-string (read-char))) (case-fold-search nil))
yuuji@68 1964 (message "")
yuuji@68 1965 (cond
yuuji@68 1966 ((string-match "i\\|j" v)
yuuji@68 1967 (concat "\\" v "math"))
yuuji@68 1968 ((string-match "[\r\n\t ]" v)
yuuji@68 1969 "")
yuuji@68 1970 (t v))))
yuuji@68 1971 (nil "")))
yuuji@68 1972
yuuji@68 1973 (fset 'YaTeX::hat 'YaTeX::tilde)
yuuji@68 1974 (fset 'YaTeX::check 'YaTeX::tilde)
yuuji@68 1975 (fset 'YaTeX::bar 'YaTeX::tilde)
yuuji@68 1976 (fset 'YaTeX::dot 'YaTeX::tilde)
yuuji@68 1977 (fset 'YaTeX::ddot 'YaTeX::tilde)
yuuji@68 1978 (fset 'YaTeX::vec 'YaTeX::tilde)
yuuji@68 1979
yuuji@68 1980 (defun YaTeX::widetilde (&optional pos)
yuuji@68 1981 "For multichar accent macros in mathmode"
yuuji@68 1982 (cond
yuuji@68 1983 ((equal pos 1)
yuuji@68 1984 (let ((m "Put over chars[%s ]: ") v v2)
yuuji@68 1985 (message m " ")
yuuji@68 1986 (setq v (char-to-string (read-char)))
yuuji@68 1987 (message "")
yuuji@68 1988 (if (string-match "[\r\n\t ]" v)
yuuji@68 1989 ""
yuuji@68 1990 (message m v)
yuuji@68 1991 (setq v2 (char-to-string (read-char)))
yuuji@68 1992 (message "")
yuuji@68 1993 (if (string-match "[\r\n\t ]" v2)
yuuji@68 1994 v
yuuji@68 1995 (concat v v2)))))
yuuji@68 1996 (nil "")))
yuuji@68 1997
yuuji@68 1998 (fset 'YaTeX::widehat 'YaTeX::widetilde)
yuuji@68 1999 (fset 'YaTeX::overline 'YaTeX::widetilde)
yuuji@68 2000 (fset 'YaTeX::overrightarrow 'YaTeX::widetilde)
yuuji@68 2001
yuuji@79 2002 ;
yuuji@79 2003 ; for \frac{}{} region
yuuji@79 2004 (defun YaTeX::frac-region (beg end)
yuuji@79 2005 (if (catch 'done
yuuji@79 2006 (while (re-search-forward "\\s *\\(\\\\over\\|/\\)\\s *" end t)
yuuji@79 2007 (goto-char (match-beginning 0))
yuuji@79 2008 (if (y-or-n-p
yuuji@79 2009 (format "Replace this `%s' with `}{'" (YaTeX-match-string 0)))
yuuji@79 2010 (throw 'done t))
yuuji@79 2011 (goto-char (match-end 0))))
yuuji@79 2012 (let (p (b0 (match-beginning 0)) e0)
yuuji@79 2013 (replace-match "}{")
yuuji@79 2014 (setq e0 (point))
yuuji@79 2015 (save-restriction
yuuji@79 2016 (narrow-to-region beg end)
yuuji@79 2017 (goto-char e0)
yuuji@79 2018 (skip-chars-forward " \t")
yuuji@79 2019 (setq p (point))
yuuji@79 2020 (YaTeX-goto-corresponding-paren)
yuuji@79 2021 (forward-char 1)
yuuji@79 2022 (skip-chars-forward " \t\r\n")
yuuji@79 2023 (if (= end (1+ (point)))
yuuji@79 2024 (progn
yuuji@79 2025 (goto-char p)
yuuji@79 2026 (if (looking-at "\\\\") (forward-char 1))
yuuji@79 2027 (YaTeX-kill-paren nil)))
yuuji@79 2028 (goto-char beg)
yuuji@79 2029 (skip-chars-forward " \t")
yuuji@79 2030 (setq p (point))
yuuji@79 2031 (YaTeX-goto-corresponding-paren)
yuuji@79 2032 (forward-char 1)
yuuji@79 2033 (skip-chars-forward " \t\r\n")
yuuji@79 2034 (if (>= (point) b0)
yuuji@79 2035 (progn
yuuji@79 2036 (goto-char p)
yuuji@79 2037 (if (looking-at "\\\\") (forward-char 1))
yuuji@79 2038 (YaTeX-kill-paren nil))))))
yuuji@79 2039 (message ""))
yuuji@68 2040
yuuji@80 2041 (defun YaTeX::DeclareMathOperator (argp)
yuuji@80 2042 (cond
yuuji@80 2043 ((equal argp 1)
yuuji@80 2044 (read-string "Operator: " "\\"))))
yuuji@80 2045
yuuji@68 2046 ;;;
yuuji@68 2047 ;; Add-in functions for large-type command.
yuuji@68 2048 ;;;
yuuji@68 2049 (defun YaTeX:em ()
yuuji@68 2050 (cond
yuuji@68 2051 ((eq YaTeX-current-completion-type 'large) "\\/")
yuuji@68 2052 (t nil)))
yuuji@68 2053 (fset 'YaTeX:it 'YaTeX:em)
yuuji@68 2054
yuuji@23 2055 ;;; -------------------- End of yatexadd --------------------
yuuji@23 2056 (provide 'yatexadd)
yuuji@72 2057 ; Local variables:
yuuji@72 2058 ; fill-prefix: ";;; "
yuuji@72 2059 ; paragraph-start: "^$\\| \\|;;;$"
yuuji@72 2060 ; paragraph-separate: "^$\\| \\|;;;$"
yuuji@80 2061 ; coding: sjis
yuuji@72 2062 ; End: