yatex

annotate yatexadd.el @ 454:aaa655456752

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