yatex

annotate yatexadd.el @ 79:0734be649cb8

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