yatex

annotate yatexadd.el @ 423:e1e67b1b70e6

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