yatex

annotate yatexadd.el @ 571:26d14d8bc834

Update copyright line
author HIROSE Yuuji <yuuji@gentei.org>
date Tue, 30 Apr 2019 23:45:10 +0900
parents 6c09561c22f0
children 714f3527b4a1
rev   line source
yuuji@395 1 ;;; yatexadd.el --- YaTeX add-in functions -*- coding: sjis -*-
yuuji@510 2 ;;; (c)1991-2018 by HIROSE Yuuji.[yuuji@yatex.org]
yuuji@567 3 ;;; Last modified Tue Feb 26 22:10:53 2019 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@458 856 (defun YaTeX::ref-1 (&optional nest-level)
yuuji@454 857 ;; Sub-function of YaTeX::ref() for recursive call
yuuji@454 858 ;; DO NOT CALL FROM OTHER FUNCTIONS but YaTeX:ref()
yuuji@458 859 (setq nest-level (or nest-level 0))
yuuji@458 860 (let ((labelleader (substring " " 0 nest-level))
yuuji@458 861 label)
yuuji@458 862 (while (YaTeX-re-search-active-forward
yuuji@458 863 regexp ;;counter
yuuji@458 864 percent nil t)
yuuji@454 865 ;(goto-char (match-beginning 0))
yuuji@458 866 (setq e0 (match-end 0))
yuuji@454 867 (cond
yuuji@458 868 ;;
yuuji@458 869 ;;2005/10/21 Skip it if predicate function returns nil
yuuji@458 870 ((and predf
yuuji@458 871 (let ((md (match-data)))
yuuji@458 872 (prog1
yuuji@458 873 (condition-case nil
yuuji@458 874 (not (funcall predf))
yuuji@458 875 (error nil))
yuuji@458 876 (store-match-data md)))))
yuuji@458 877 ((YaTeX-literal-p) nil)
yuuji@458 878 ((YaTeX-match-string 1)
yuuji@458 879 ;;if standard counter commands found
yuuji@458 880 (setq cmd (YaTeX-match-string 2)
yuuji@458 881 m0 (match-beginning 0))
yuuji@458 882 (setq match-point (match-beginning 0))
yuuji@458 883 (or initl
yuuji@458 884 (if (< p (point)) (setq initl lnum)))
yuuji@458 885 (cond
yuuji@458 886 ;; In any case, variables e0 should be set
yuuji@458 887 ((and YaTeX-use-AMS-LaTeX
yuuji@458 888 (string-match YaTeX::ref-nestable-counter-regexp cmd))
yuuji@454 889 (skip-chars-forward "}")
yuuji@454 890 (setq label (buffer-substring
yuuji@454 891 (point) (min (+ 80 (point)) (point-max))))
yuuji@454 892 ;; to skip (maybe)auto-generated comment
yuuji@454 893 (skip-chars-forward " \t")
yuuji@454 894 (if (looking-at YaTeX-comment-prefix)
yuuji@454 895 (forward-line 1))
yuuji@454 896 (setq e0 (point))
yuuji@454 897 (skip-chars-forward " \t\n")
yuuji@454 898 (if (looking-at "\\\\label{\\([^}]+\\)}")
yuuji@454 899 (setq label (format "(labe:%s)" (YaTeX-match-string 1))
yuuji@454 900 e0 (match-end 1)))
yuuji@458 901 (funcall output
yuuji@458 902 (format "--subequation--%s%s" labelleader label)
yuuji@458 903 e0 'eqn))
yuuji@458 904 ((string-match mathenvs cmd) ;;if matches mathematical env
yuuji@458 905 (skip-chars-forward "}")
yuuji@458 906 (setq x (point)
yuuji@458 907 envname (substring
yuuji@458 908 cmd (match-beginning 0) (match-end 0)))
yuuji@458 909 (save-restriction
yuuji@458 910 (narrow-to-region
yuuji@458 911 m0
yuuji@458 912 (save-excursion
yuuji@458 913 (YaTeX-re-search-active-forward
yuuji@458 914 (setq endrx (format "%send{%s}" YaTeX-ec-regexp
yuuji@458 915 (regexp-quote envname)))
yuuji@458 916 percent nil t)))
yuuji@458 917 (catch 'scan
yuuji@458 918 (while (YaTeX-re-search-active-forward
yuuji@458 919 (concat
yuuji@458 920 "\\\\end{\\(" (regexp-quote envname) "\\)" ;;(1)
yuuji@458 921 "\\|\\\\\\(notag\\)" ;;2
yuuji@458 922 (if (string-match
yuuji@458 923 YaTeX::ref-mathenv-exp1-regexp cmd)
yuuji@458 924 "" "\\|\\(\\\\\\\\\\)$") ;;3
yuuji@458 925 )
yuuji@458 926 percent nil t)
yuuji@458 927 (let*((quit (match-beginning 1))
yuuji@458 928 (notag (match-beginning 2))
yuuji@458 929 (newln (match-beginning 3))
yuuji@458 930 (label ".......................") l2
yuuji@458 931 (e (point)) (m0 (match-beginning 0))
yuuji@458 932 (ln (YaTeX-string-width label)))
yuuji@454 933 (cond
yuuji@458 934 (notag
yuuji@458 935 (YaTeX-re-search-active-forward
yuuji@458 936 "\\\\\\\\" percent nil 1)
yuuji@458 937 (setq x (point))) ;use x as \label search bound
yuuji@458 938 ((and newln ; `\\' found
yuuji@458 939 (not (equal (YaTeX-inner-environment)
yuuji@458 940 envname)))
yuuji@454 941 (YaTeX-end-of-environment)
yuuji@458 942 (goto-char (match-end 0)))
yuuji@458 943 (t
yuuji@458 944 (if (YaTeX-re-search-active-backward
yuuji@458 945 YaTeX::ref-labeling-regexp
yuuji@458 946 percent x t)
yuuji@458 947 ;; if \label{x} in math-expression, display it
yuuji@458 948 ;; because formula source is hard to recognize
yuuji@458 949 (progn
yuuji@458 950 (goto-char (match-end 0))
yuuji@458 951 (setq l2 (format "\"label:%s\""
yuuji@458 952 (buffer-substring
yuuji@458 953 (1- (point))
yuuji@458 954 (progn (forward-sexp -1)
yuuji@458 955 (1+ (point))))))
yuuji@458 956 (setq label
yuuji@458 957 (if (< (YaTeX-string-width l2) ln)
yuuji@458 958 (concat
yuuji@458 959 l2
yuuji@458 960 (substring
yuuji@458 961 label
yuuji@458 962 0 (- ln (YaTeX-string-width l2))))
yuuji@458 963 l2))
yuuji@458 964 (goto-char e)))
yuuji@458 965 (funcall output
yuuji@458 966 (concat
yuuji@458 967 labelleader label " "
yuuji@458 968 (buffer-substring x m0))
yuuji@458 969 x 'eqn)
yuuji@458 970 (cond
yuuji@458 971 ((YaTeX-quick-in-environment-p
yuuji@458 972 YaTeX-math-gathering-list)
yuuji@458 973 ;; if here is inner split/cases/gathered env.,
yuuji@458 974 ;; counter for here is only one.
yuuji@458 975 ;; Go out this environment and,
yuuji@458 976 (YaTeX-end-of-environment)
yuuji@458 977 ;; search next expression unit boundary.
yuuji@458 978 (YaTeX-re-search-active-forward
yuuji@458 979 (concat endrx "\\|\\\\begin{")
yuuji@458 980 percent nil 1)
yuuji@458 981 (end-of-line)))
yuuji@458 982 (if quit (throw 'scan t)))))
yuuji@458 983 (setq x (point)))))
yuuji@458 984 (setq e0 (point)))
yuuji@458 985 ((string-match enums cmd)
yuuji@454 986 ;(skip-chars-forward "} \t\n")
yuuji@458 987 (save-restriction
yuuji@458 988 (narrow-to-region
yuuji@458 989 (point)
yuuji@458 990 (save-excursion
yuuji@458 991 (YaTeX-goto-corresponding-environment nil t 'nonstop) (point)))
yuuji@458 992 (forward-line 1)
yuuji@458 993 (let ((b0 nil) mb0)
yuuji@458 994 (while (not (eobp))
yuuji@458 995 (setq x (and
yuuji@458 996 (YaTeX-re-search-active-forward
yuuji@458 997 (concat YaTeX-ec-regexp "item\\s ")
yuuji@458 998 percent nil 1)
yuuji@458 999 (match-beginning 0)))
yuuji@454 1000
yuuji@458 1001 (if b0 ;Inspect sentence after previous \item
yuuji@458 1002 (save-excursion
yuuji@458 1003 (save-restriction
yuuji@458 1004 (let ((md (match-data))) ;save-match-data
yuuji@458 1005 (unwind-protect
yuuji@458 1006 (progn
yuuji@458 1007 (narrow-to-region b0 (or x (point)))
yuuji@458 1008 (goto-char (point-min))
yuuji@458 1009 (let ((x x)) (YaTeX::ref-1 (1+ nest-level)))
yuuji@458 1010 (goto-char (point-max)))
yuuji@458 1011 (store-match-data md))))))
yuuji@458 1012 (if x ;Output THIS \item line
yuuji@458 1013 (funcall
yuuji@458 1014 output
yuuji@458 1015 (concat
yuuji@458 1016 labelleader existlabel
yuuji@458 1017 (buffer-substring
yuuji@458 1018 (match-beginning 0)
yuuji@458 1019 (if (re-search-forward itemsep nil 1)
yuuji@458 1020 (progn (goto-char (match-beginning 0))
yuuji@458 1021 (skip-chars-backward " \t")
yuuji@458 1022 (1- (point)))
yuuji@458 1023 (point-end-of-line))))
yuuji@458 1024 x 'item))
yuuji@458 1025 (setq b0 (point))
yuuji@458 1026 ))
yuuji@458 1027 (setq e0 (point-max))))
yuuji@458 1028 ((string-match "bibitem" cmd) ;maybe generated by myself
yuuji@458 1029 (setq label "")
yuuji@458 1030 (skip-chars-forward " \t")
yuuji@458 1031 (if (looking-at "{") ;sure to be true!!
yuuji@458 1032 (forward-list 1))
yuuji@458 1033 (let ((list '(30 10 65))
yuuji@458 1034 (delim ";") q lim len l str)
yuuji@458 1035 (save-excursion
yuuji@458 1036 (setq lim (if (re-search-forward itemsep nil 1)
yuuji@458 1037 (match-beginning 0) (point))))
yuuji@458 1038 (while list
yuuji@458 1039 (skip-chars-forward " \t\n\\")
yuuji@458 1040 (setq q (looking-at "[\"'{]")
yuuji@458 1041 len (car list)
yuuji@458 1042 str
yuuji@454 1043 (buffer-substring
yuuji@458 1044 (point)
yuuji@458 1045 (progn
yuuji@458 1046 (if q (forward-sexp 1)
yuuji@458 1047 (search-forward delim lim 1)
yuuji@458 1048 (forward-char -1))
yuuji@458 1049 (point))))
yuuji@458 1050 (if (> (setq l (YaTeX-string-width str)) len)
yuuji@458 1051 (setq str (concat
yuuji@458 1052 (YaTeX-truncate-string-width
yuuji@458 1053 str (- len (if q 5 4)))
yuuji@458 1054 "... "
yuuji@458 1055 (if q (substring str -1)))))
yuuji@458 1056 (if (< (setq l (YaTeX-string-width str)) len)
yuuji@458 1057 (setq str (concat str (make-string (- len l) ? ))))
yuuji@458 1058 (if (looking-at delim) (goto-char (match-end 0)))
yuuji@458 1059 (setq label (concat label " " str)
yuuji@458 1060 list (cdr list)))
yuuji@463 1061 (funcall output (concat labelleader label) match-point 'bib)))
yuuji@458 1062 ;;else, simple section-type counter
yuuji@458 1063 ((= (char-after (1- (point))) ?{)
yuuji@458 1064 (setq label (buffer-substring
yuuji@458 1065 (match-beginning 0)
yuuji@458 1066 (progn (forward-char -1)
yuuji@458 1067 (forward-list 1)
yuuji@458 1068 (point))))
yuuji@463 1069 (funcall output (concat labelleader label) match-point
yuuji@458 1070 (if (string-match "caption" cmd) 'cap 'sec))
yuuji@458 1071 ;; Skip preceding label if exists
yuuji@458 1072 (if (YaTeX::ref-getset-label (current-buffer) match-point t)
yuuji@458 1073 (goto-char (get 'YaTeX::ref-getset-label 'foundpoint)))
yuuji@458 1074 (if (save-excursion
yuuji@458 1075 (skip-chars-forward "\t \n")
yuuji@458 1076 (looking-at YaTeX::ref-labeling-regexp))
yuuji@458 1077 (setq e0 (match-end 0))))
yuuji@458 1078 (t
yuuji@458 1079 (skip-chars-forward " \t")
yuuji@458 1080 (setq label (buffer-substring
yuuji@458 1081 (match-beginning 0)
yuuji@458 1082 (if (re-search-forward
yuuji@458 1083 itemsep
yuuji@458 1084 nil t)
yuuji@458 1085 (progn
yuuji@458 1086 (goto-char (match-beginning 0))
yuuji@458 1087 (skip-chars-backward " \t")
yuuji@458 1088 (1- (point)))
yuuji@458 1089 (point-end-of-line))))
yuuji@463 1090 (funcall output (concat labelleader label) match-point 'misc)
yuuji@458 1091 (if (save-excursion
yuuji@458 1092 (skip-chars-forward "\t \n")
yuuji@458 1093 (looking-at YaTeX::ref-labeling-regexp))
yuuji@458 1094 (setq e0 (match-end 0)))))
yuuji@458 1095 ) ;;put label buffer
yuuji@458 1096 ;;
yuuji@458 1097 ;; if user defined label found
yuuji@458 1098 (t
yuuji@458 1099 ;; memorize line number and label into property
yuuji@458 1100 (goto-char (match-beginning 0))
yuuji@458 1101 (let ((list YaTeX::ref-labeling-regexp-alist)
yuuji@458 1102 (cache (symbol-plist 'YaTeX::ref-labeling-regexp)))
yuuji@454 1103 (while list
yuuji@458 1104 (if (looking-at (car (car list)))
yuuji@458 1105 (progn
yuuji@458 1106 (setq label (YaTeX-match-string 0))
yuuji@458 1107 (put 'YaTeX::ref-labeling-regexp lnum
yuuji@458 1108 (YaTeX-match-string (cdr (car list))))
yuuji@464 1109 (funcall output (concat labelleader label) 0) ;;0 is dummy
yuuji@458 1110 (setq list nil)))
yuuji@458 1111 (setq list (cdr list))))
yuuji@458 1112 ))
yuuji@458 1113 (goto-char e0))))
yuuji@454 1114
yuuji@80 1115 (defun YaTeX::ref (argp &optional labelcmd refcmd predf)
yuuji@70 1116 (setplist 'YaTeX::ref-labeling-regexp nil) ;erase memory cache
yuuji@70 1117 (require 'yatexsec)
yuuji@11 1118 (cond
yuuji@11 1119 ((= argp 1)
yuuji@80 1120 (let*((lnum 0) m0 e0 x cmd label match-point point-list boundary
yuuji@70 1121 (buf (current-buffer))
yuuji@70 1122 (llv YaTeX::ref-labeling-section-level)
yuuji@80 1123 (mathenvs YaTeX::ref-mathenv-regexp) envname endrx
yuuji@70 1124 (enums YaTeX::ref-enumerateenv-regexp)
yuuji@70 1125 (counter
yuuji@70 1126 (or labelcmd
yuuji@70 1127 (concat
yuuji@70 1128 YaTeX-ec-regexp "\\(\\("
yuuji@70 1129 (mapconcat
yuuji@70 1130 'concat
yuuji@70 1131 (delq nil
yuuji@70 1132 (mapcar
yuuji@72 1133 (function
yuuji@72 1134 (lambda (s)
yuuji@72 1135 (if (>= llv (cdr s))
yuuji@72 1136 (car s))))
yuuji@70 1137 YaTeX-sectioning-level))
yuuji@70 1138 "\\|")
yuuji@77 1139 "\\|caption\\(\\[[^]]+\\]\\)?\\|footnote\\){"
yuuji@80 1140 "\\|\\(begin{\\(" mathenvs "\\|" enums "\\)}\\)"
yuuji@80 1141 (if YaTeX-use-AMS-LaTeX
yuuji@80 1142 (concat
yuuji@80 1143 "\\|\\(begin{"
yuuji@80 1144 YaTeX::ref-nestable-counter-regexp "}\\)"))
yuuji@80 1145 "\\)")))
yuuji@70 1146 (regexp (concat "\\(" counter
yuuji@70 1147 "\\)\\|\\(" YaTeX::ref-labeling-regexp "\\)"))
yuuji@70 1148 (itemsep (concat YaTeX-ec-regexp
yuuji@70 1149 "\\(\\(bib\\)?item\\|begin\\|end\\)"))
yuuji@86 1150 (refcmd (or refcmd "\\(page\\)?ref"))
yuuji@70 1151 (p (point)) initl line cf
yuuji@70 1152 (percent (regexp-quote YaTeX-comment-prefix))
yuuji@70 1153 (output
yuuji@70 1154 (function
yuuji@454 1155 (lambda (label p &optional type) ;type: 'eqn 'item 'cap 'sec 'misc
yuuji@80 1156 (while (setq x (string-match "[\n\t]" label))
yuuji@70 1157 (aset label x ? ))
yuuji@80 1158 (while (setq x (string-match " +" label))
yuuji@70 1159 (setq label (concat
yuuji@70 1160 (substring label 0 (1+ (match-beginning 0)))
yuuji@70 1161 (substring label (match-end 0)))))
yuuji@454 1162 (save-excursion
yuuji@454 1163 (set-buffer standard-output)
yuuji@454 1164 (overlay-put
yuuji@454 1165 (make-overlay
yuuji@454 1166 (point)
yuuji@454 1167 (progn
yuuji@454 1168 (insert (format "%c: <<%s>>\n" (+ (% lnum 26) ?A) label))
yuuji@454 1169 (point)))
yuuji@454 1170 'type type))
yuuji@70 1171 (setq point-list (cons p point-list))
yuuji@70 1172 (message "Collecting labels... %d" lnum)
yuuji@70 1173 (setq lnum (1+ lnum)))))
yuuji@80 1174 (me (if (boundp 'me) me 'YaTeX::ref))
yuuji@70 1175 )
yuuji@60 1176 (message "Collecting labels...")
yuuji@60 1177 (save-window-excursion
yuuji@60 1178 (YaTeX-showup-buffer
yuuji@60 1179 YaTeX-label-buffer (function (lambda (x) (window-width x))))
yuuji@60 1180 (if (fboundp 'select-frame) (setq cf (selected-frame)))
yuuji@60 1181 (if (eq (window-buffer (minibuffer-window)) buf)
yuuji@60 1182 (progn
yuuji@60 1183 (other-window 1)
yuuji@60 1184 (setq buf (current-buffer))
yuuji@70 1185 (set-buffer buf)))
yuuji@60 1186 (save-excursion
yuuji@69 1187 (set-buffer (get-buffer-create YaTeX-label-buffer))
yuuji@80 1188 (condition-case ()
yuuji@80 1189 (if (and YaTeX-use-font-lock (fboundp 'font-lock-mode))
yuuji@80 1190 (font-lock-mode 1))
yuuji@80 1191 (error nil))
yuuji@69 1192 (setq buffer-read-only nil)
yuuji@69 1193 (erase-buffer))
yuuji@69 1194 (save-excursion
yuuji@70 1195 (set-buffer buf)
yuuji@60 1196 (goto-char (point-min))
yuuji@80 1197 (let ((standard-output (get-buffer YaTeX-label-buffer)) existlabel)
yuuji@60 1198 (princ (format "=== LABELS in [%s] ===\n" (buffer-name buf)))
yuuji@454 1199
yuuji@454 1200 (YaTeX::ref-1)
yuuji@454 1201
yuuji@454 1202
yuuji@11 1203 (princ YaTeX-label-menu-other)
yuuji@23 1204 (princ YaTeX-label-menu-repeat)
yuuji@11 1205 (princ YaTeX-label-menu-any)
yuuji@69 1206 );standard-output
yuuji@11 1207 (goto-char p)
yuuji@60 1208 (or initl (setq initl lnum))
yuuji@70 1209 (message "Collecting labels...Done")
yuuji@60 1210 (if (fboundp 'select-frame) (select-frame cf))
yuuji@59 1211 (YaTeX-showup-buffer YaTeX-label-buffer nil t)
yuuji@11 1212 (YaTeX::label-setup-key-map)
yuuji@11 1213 (setq truncate-lines t)
yuuji@11 1214 (setq buffer-read-only t)
yuuji@11 1215 (use-local-map YaTeX-label-select-map)
yuuji@11 1216 (message YaTeX-label-guide-msg)
yuuji@60 1217 (goto-line (1+ initl)) ;goto recently defined label line
yuuji@68 1218 (switch-to-buffer (current-buffer))
yuuji@11 1219 (unwind-protect
yuuji@11 1220 (progn
yuuji@11 1221 (recursive-edit)
yuuji@70 1222
yuuji@11 1223 (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
yuuji@11 1224 (beginning-of-line)
yuuji@60 1225 (setq line (1- (count-lines (point-min)(point))))
yuuji@11 1226 (cond
yuuji@60 1227 ((= line -1) (setq label ""))
yuuji@11 1228 ((= line lnum) (setq label (YaTeX-label-other)))
yuuji@23 1229 ((= line (1+ lnum))
yuuji@23 1230 (save-excursion
yuuji@23 1231 (switch-to-buffer buf)
yuuji@23 1232 (goto-char p)
yuuji@48 1233 (if (re-search-backward
yuuji@86 1234 (concat "\\\\" refcmd "{") nil t)
yuuji@86 1235 (setq label (YaTeX-buffer-substring
yuuji@86 1236 (progn (goto-char (1- (match-end 0)))
yuuji@86 1237 (1+ (point)))
yuuji@86 1238 (progn (forward-list 1)
yuuji@86 1239 (1- (point)))))
yuuji@23 1240 (setq label ""))))
yuuji@23 1241 ((>= line (+ lnum 2))
yuuji@48 1242 (setq label (read-string (format "\\%s{???}: " refcmd))))
yuuji@70 1243 (t ;(setq label (nth (- lnum line 1) label-list))
yuuji@70 1244 (setq label
yuuji@70 1245 (or (get 'YaTeX::ref-labeling-regexp line)
yuuji@70 1246 (YaTeX::ref-getset-label
yuuji@70 1247 buf (nth (- lnum line 1) point-list))))
yuuji@70 1248 )))
yuuji@11 1249 (bury-buffer YaTeX-label-buffer)))
yuuji@69 1250 label)))))
yuuji@69 1251
yuuji@168 1252 (defun YaTeX::label-rename-refs (old new &optional def ref)
yuuji@168 1253 "Rename reference tag from OLD to NEW.
yuuji@168 1254 Optional arguments DEF and REF specify defining command and
yuuji@168 1255 referring command respectively.
yuuji@168 1256 ---------------------------------------------------------
yuuji@168 1257 CONTROL KEYS - キーの説明
yuuji@168 1258 y Replace 置換する
yuuji@168 1259 n Do not replace 置換しない
yuuji@168 1260 ! Replace All w/o query 残る全部を確認なしで置換
yuuji@168 1261 r Enter Recursive-edit 再帰編集モードへ
yuuji@168 1262 q Quit from replacing ここまでで置換をやめる
yuuji@168 1263
yuuji@168 1264 Don't forget to exit from recursive edit by typing \\[exit-recursive-edit]
yuuji@168 1265 再帰編集に入ったら \\[exit-recursive-edit] で抜け忘れなきよう。"
yuuji@168 1266 (save-window-excursion
yuuji@168 1267 (catch 'exit
yuuji@168 1268 (let*((bufs (YaTeX-yatex-buffer-list)) buf b e
yuuji@168 1269 (oldptn (regexp-quote old))
yuuji@168 1270 (sw (selected-window))
yuuji@168 1271 (ptn (concat
yuuji@168 1272 "\\(" YaTeX-refcommand-ref-regexp "\\)"
yuuji@168 1273 "\\s *{" oldptn "}"))
yuuji@170 1274 (repface (and (fboundp 'make-overlay)
yuuji@170 1275 (fboundp 'internal-find-face)
yuuji@170 1276 (if (internal-find-face 'isearch) 'isearch 'region)))
yuuji@170 1277 ov
yuuji@173 1278 (qmsg "Replace to `%s'? [yn!rq?]")
yuuji@168 1279 continue ch)
yuuji@168 1280 (while bufs
yuuji@168 1281 (set-buffer (setq buf (car bufs)))
yuuji@168 1282 (save-excursion
yuuji@168 1283 (goto-char (point-min))
yuuji@168 1284 (while (re-search-forward ptn nil t)
yuuji@168 1285 (goto-char (match-end 1))
yuuji@168 1286 (skip-chars-forward " \t\n{")
yuuji@168 1287 (unwind-protect
yuuji@168 1288 (if (and
yuuji@168 1289 (looking-at oldptn)
yuuji@168 1290 (setq b (match-beginning 0)
yuuji@168 1291 e (match-end 0))
yuuji@168 1292 (or continue
yuuji@168 1293 (catch 'query
yuuji@170 1294 (if repface
yuuji@168 1295 (if ov (move-overlay ov b e)
yuuji@168 1296 (overlay-put
yuuji@168 1297 (setq ov (make-overlay b e))
yuuji@170 1298 'face repface)))
yuuji@532 1299 (set-window-buffer nil buf) ;Emacs26
yuuji@168 1300 (while t
yuuji@168 1301 (message qmsg new)
yuuji@168 1302 (setq ch (read-char))
yuuji@168 1303 (cond
yuuji@168 1304 ((= ch ?q) (throw 'exit t))
yuuji@168 1305 ((= ch ?r)
yuuji@168 1306 (message
yuuji@173 1307 "Don't forget to exit recursive-edit by `%s'"
yuuji@168 1308 (key-description
yuuji@168 1309 (where-is-internal
yuuji@168 1310 'exit-recursive-edit '(keymap) t)))
yuuji@168 1311 (sleep-for 2)
yuuji@168 1312 (recursive-edit))
yuuji@255 1313 ((memq ch '(?y ?\ )) (throw 'query t))
yuuji@168 1314 ((= ch ?!) (throw 'query (setq continue t)))
yuuji@168 1315 ((= ch ??)
yuuji@168 1316 (describe-function
yuuji@168 1317 'YaTeX::label-rename-refs)
yuuji@168 1318 (select-window (get-buffer-window "*Help*"))
yuuji@168 1319 (search-forward "----")
yuuji@168 1320 (forward-line 1)
yuuji@168 1321 (set-window-start (selected-window) (point))
yuuji@168 1322 (sit-for 0)
yuuji@168 1323 (select-window sw))
yuuji@168 1324 ((= ch ?n) (throw 'query nil)))))))
yuuji@267 1325 (replace-match new t))
yuuji@168 1326 (and ov (delete-overlay ov)))))
yuuji@168 1327 (setq bufs (cdr bufs)))))))
yuuji@168 1328
yuuji@167 1329 (defun YaTeX::label (argp &optional labname refname)
yuuji@163 1330 "Read label name and return it with copying \\ref{LABEL-NAME} to kill-ring."
yuuji@163 1331 (cond
yuuji@163 1332 ((= argp 1)
yuuji@168 1333 (let*((chmode (boundp (intern-soft "old")))
yuuji@168 1334 (dlab (if chmode old ;if called via YaTeX-change-section (tricky...)
yuuji@163 1335 (YaTeX::ref-default-label)))
yuuji@394 1336 (label (read-string-with-history
yuuji@167 1337 (format "New %s name: " (or labname "label"))
yuuji@167 1338 (cons dlab 1))))
yuuji@163 1339 (if (string< "" label)
yuuji@247 1340 (let ((refstr (format "\\%s{%s}" (or refname "ref") label)))
yuuji@247 1341 (YaTeX-push-to-kill-ring refstr)
yuuji@170 1342 (and chmode
yuuji@170 1343 (not (equal old label))
yuuji@247 1344 (YaTeX::label-rename-refs old label))))
yuuji@163 1345 label))))
yuuji@163 1346
yuuji@163 1347
yuuji@16 1348 (fset 'YaTeX::pageref 'YaTeX::ref)
yuuji@312 1349 (fset 'YaTeX::cref 'YaTeX::ref)
yuuji@80 1350 (defun YaTeX::tabref (argp) ; For the style file of IPSJ journal
yuuji@80 1351 (YaTeX::ref
yuuji@80 1352 argp nil nil
yuuji@80 1353 (function
yuuji@80 1354 (lambda ()
yuuji@80 1355 (YaTeX-quick-in-environment-p "table")))))
yuuji@80 1356 (defun YaTeX::figref (argp) ; For the style file of IPSJ journal
yuuji@80 1357 (YaTeX::ref
yuuji@80 1358 argp nil nil
yuuji@80 1359 (function
yuuji@80 1360 (lambda ()
yuuji@80 1361 (YaTeX-quick-in-environment-p "figure")))))
yuuji@232 1362 (defun YaTeX::eqref (argp)
yuuji@232 1363 (YaTeX::ref
yuuji@232 1364 argp nil nil
yuuji@232 1365 (function
yuuji@232 1366 (lambda ()
yuuji@232 1367 (YaTeX-in-math-mode-p)))))
yuuji@70 1368
yuuji@80 1369 (defun YaTeX::cite-collect-bibs-external (bibptn &rest files)
yuuji@80 1370 "Collect bibentry from FILES(variable length argument) ;
yuuji@70 1371 and print them to standard output."
yuuji@70 1372 ;;Thanks; http://icarus.ilcs.hokudai.ac.jp/comp/biblio.html
yuuji@80 1373 (let*((tb (get-buffer-create " *bibtmp*"))
yuuji@80 1374 (bibitemsep "^\\s *@[A-Za-z]")
yuuji@80 1375 (target (if (string< "" bibptn) bibptn bibitemsep))
yuuji@80 1376 (checkrx (concat "\\(" bibptn "\\)\\|" bibitemsep))
yuuji@80 1377 beg
yuuji@80 1378 (searchnext
yuuji@80 1379 (if (string< "" bibptn)
yuuji@80 1380 (function
yuuji@80 1381 (lambda()
yuuji@80 1382 (setq beg (point))
yuuji@80 1383 (and
yuuji@80 1384 (prog1
yuuji@80 1385 (re-search-forward target nil t)
yuuji@80 1386 (end-of-line))
yuuji@80 1387 (re-search-backward bibitemsep beg t))))
yuuji@80 1388 (function
yuuji@80 1389 (lambda()
yuuji@80 1390 (re-search-forward target nil t)))))
yuuji@80 1391 )
yuuji@70 1392 (save-excursion
yuuji@70 1393 (set-buffer tb)
yuuji@80 1394 (princ (format "%sbegin{thebibliography}\n" YaTeX-ec))
yuuji@70 1395 (while files
yuuji@70 1396 (erase-buffer)
yuuji@70 1397 (cond
yuuji@70 1398 ((file-exists-p (car files))
yuuji@70 1399 (insert-file-contents (car files)))
yuuji@70 1400 ((file-exists-p (concat (car files) ".bib"))
yuuji@70 1401 (insert-file-contents (concat (car files) ".bib"))))
yuuji@70 1402 (save-excursion
yuuji@70 1403 (goto-char (point-min))
yuuji@80 1404 (while (funcall searchnext)
yuuji@70 1405 (skip-chars-forward "^{,")
yuuji@80 1406 (setq beg (point))
yuuji@70 1407 (if (= (char-after (point)) ?{)
yuuji@70 1408 (princ (format "%sbibitem{%s}%s\n"
yuuji@70 1409 YaTeX-ec
yuuji@70 1410 (buffer-substring
yuuji@70 1411 (1+ (point))
yuuji@70 1412 (progn (skip-chars-forward "^,\n")
yuuji@70 1413 (point)))
yuuji@80 1414 (mapconcat
yuuji@80 1415 (function
yuuji@80 1416 (lambda (kwd)
yuuji@80 1417 (goto-char beg)
yuuji@80 1418 (if (re-search-forward
yuuji@80 1419 (concat kwd "\\s *=") nil t)
yuuji@80 1420 (buffer-substring
yuuji@80 1421 (progn
yuuji@80 1422 (goto-char (match-end 0))
yuuji@80 1423 (skip-chars-forward " \t\n")
yuuji@80 1424 (point))
yuuji@80 1425 (progn
yuuji@80 1426 (if (looking-at "[{\"]")
yuuji@80 1427 (forward-sexp 1)
yuuji@80 1428 (forward-char 1)
yuuji@80 1429 (skip-chars-forward "^,}"))
yuuji@80 1430 (point))))))
yuuji@80 1431 '("author" "year" "title" )
yuuji@80 1432 ";"))))
yuuji@80 1433 (and (re-search-forward bibitemsep nil t)
yuuji@80 1434 (forward-line -1))))
yuuji@80 1435 (setq files (cdr files)))
yuuji@80 1436 (princ (format "%sbegin{thebibliography}\n" YaTeX-ec)))))
yuuji@70 1437
yuuji@77 1438 (defvar YaTeX::cite-bibitem-macro-regexp "bibitem\\|harvarditem"
yuuji@77 1439 "*Regexp of macro name of bibitem definition")
yuuji@77 1440
yuuji@80 1441 (defun YaTeX::cite-collect-bibs-internal (bibptn)
yuuji@70 1442 "Collect bibentry in the current buffer and print them to standard output."
yuuji@77 1443 (let ((ptn (concat YaTeX-ec-regexp
yuuji@77 1444 "\\(" YaTeX::cite-bibitem-macro-regexp "\\)\\b"))
yuuji@80 1445 (lim (concat YaTeX-ec-regexp
yuuji@80 1446 "\\(" YaTeX::cite-bibitem-macro-regexp "\\b\\)"
yuuji@80 1447 "\\|\\(end{\\)"))
yuuji@70 1448 (pcnt (regexp-quote YaTeX-comment-prefix)))
yuuji@80 1449 ;; Using bibptn not yet implemented.
yuuji@80 1450 ;; Do you need it?? 2005/11/22
yuuji@70 1451 (save-excursion
yuuji@70 1452 (while (YaTeX-re-search-active-forward ptn pcnt nil t)
yuuji@70 1453 (skip-chars-forward "^{\n")
yuuji@70 1454 (or (eolp)
yuuji@80 1455 (princ (format "%sbibitem%s %s\n"
yuuji@70 1456 YaTeX-ec
yuuji@70 1457 (buffer-substring
yuuji@80 1458 (point)
yuuji@80 1459 (progn (forward-sexp 1) (point)))
yuuji@80 1460 (buffer-substring
yuuji@80 1461 (progn (skip-chars-forward "\n \t") (point))
yuuji@80 1462 (save-excursion
yuuji@80 1463 (if (YaTeX-re-search-active-forward
yuuji@80 1464 lim pcnt nil t)
yuuji@80 1465 (progn
yuuji@80 1466 (goto-char (match-beginning 0))
yuuji@80 1467 (skip-chars-backward "\n \t")
yuuji@80 1468 (point))
yuuji@80 1469 (point-end-of-line)))))))))))
yuuji@70 1470
yuuji@80 1471 (defun YaTeX::cite (argp &rest dummy)
yuuji@48 1472 (cond
yuuji@48 1473 ((eq argp 1)
yuuji@70 1474 (let* ((cb (current-buffer))
yuuji@70 1475 (f (file-name-nondirectory buffer-file-name))
yuuji@70 1476 (d default-directory)
yuuji@70 1477 (hilit-auto-highlight nil)
yuuji@70 1478 (pcnt (regexp-quote YaTeX-comment-prefix))
yuuji@70 1479 (bibrx (concat YaTeX-ec-regexp "bibliography{\\([^}]+\\)}"))
yuuji@397 1480 (bibptn (YaTeX-read-string-or-skip "Pattern: "))
yuuji@70 1481 (bbuf (get-buffer-create " *bibitems*"))
yuuji@70 1482 (standard-output bbuf)
yuuji@80 1483 (me 'YaTeX::cite) ;shuld set this for using YaTeX::ref
yuuji@70 1484 bibs files)
yuuji@70 1485 (set-buffer bbuf)(erase-buffer)(set-buffer cb)
yuuji@70 1486 (save-excursion
yuuji@70 1487 (goto-char (point-min))
yuuji@70 1488 ;;(1)search external bibdata
yuuji@70 1489 (while (YaTeX-re-search-active-forward bibrx pcnt nil t)
yuuji@70 1490 (apply 'YaTeX::cite-collect-bibs-external
yuuji@80 1491 bibptn
yuuji@70 1492 (YaTeX-split-string
yuuji@70 1493 (YaTeX-match-string 1) ",")))
yuuji@70 1494 ;;(2)search direct \bibitem usage
yuuji@80 1495 (YaTeX::cite-collect-bibs-internal bibptn)
yuuji@70 1496 (if (progn
yuuji@70 1497 (YaTeX-visit-main t)
yuuji@70 1498 (not (eq (current-buffer) cb)))
yuuji@70 1499 (save-excursion
yuuji@70 1500 (goto-char (point-min))
yuuji@70 1501 ;;(1)search external bibdata
yuuji@70 1502 (while (YaTeX-re-search-active-forward bibrx pcnt nil t)
yuuji@70 1503 (apply 'YaTeX::cite-collect-bibs-external
yuuji@80 1504 bibptn
yuuji@70 1505 (YaTeX-split-string
yuuji@70 1506 (YaTeX-match-string 1) ",")))
yuuji@70 1507 ;;(2)search internal
yuuji@80 1508 (YaTeX::cite-collect-bibs-internal bibptn)))
yuuji@70 1509 ;;Now bbuf holds the list of bibitem
yuuji@70 1510 (set-buffer bbuf)
yuuji@80 1511 ;;;(switch-to-buffer bbuf)
yuuji@80 1512 (if (fboundp 'font-lock-fontify-buffer) (font-lock-fontify-buffer))
yuuji@77 1513 (YaTeX::ref
yuuji@77 1514 argp
yuuji@77 1515 (concat "\\\\\\("
yuuji@77 1516 YaTeX::cite-bibitem-macro-regexp
yuuji@77 1517 "\\)\\(\\[.*\\]\\)?")
yuuji@77 1518 "cite"))))
yuuji@77 1519
yuuji@48 1520 (t nil)))
yuuji@11 1521
yuuji@528 1522 (defvar YaTeX::bibliographystyle-alist-default
yuuji@528 1523 '(("unsrt")("junsrt")("plain")("jplain")("alpha")("jalpha")
yuuji@528 1524 ("abbrv")("jabbrv")("jipsj")("jname")("tieice")("tipsj")
yuuji@528 1525 ("apalike")("ieeetr")("siam")))
yuuji@528 1526 (defvar YaTeX::bibliographystyle-alist-private
yuuji@528 1527 nil
yuuji@528 1528 "*Completion table for bibliographystyle")
yuuji@528 1529
yuuji@528 1530 (defun YaTeX::bibliographystyle(argp)
yuuji@528 1531 (cond
yuuji@528 1532 ((= argp 1)
yuuji@528 1533 (YaTeX-completing-read-or-skip
yuuji@528 1534 "BibStyle: "
yuuji@528 1535 (append YaTeX::bibliographystyle-alist-private
yuuji@528 1536 YaTeX::bibliographystyle-alist-default)
yuuji@528 1537 nil))))
yuuji@528 1538
yuuji@167 1539 (defun YaTeX::bibitem (argp)
yuuji@167 1540 "Add-in function to insert argument of \\bibitem."
yuuji@167 1541 (YaTeX::label argp "label" "cite"))
yuuji@167 1542
yuuji@77 1543 ;;; for Harvard citation style
yuuji@77 1544 (fset 'YaTeX::citeasnoun 'YaTeX::cite)
yuuji@77 1545 (fset 'YaTeX::possessivecite 'YaTeX::cite)
yuuji@77 1546 (fset 'YaTeX::citeyear 'YaTeX::cite)
yuuji@77 1547 (fset 'YaTeX::citename 'YaTeX::cite)
yuuji@80 1548 (fset 'YaTeX::citep 'YaTeX::cite)
yuuji@80 1549 (fset 'YaTeX::citet 'YaTeX::cite)
yuuji@70 1550
yuuji@48 1551 (defun YaTeX-select-other-yatex-buffer ()
yuuji@48 1552 "Select buffer from all yatex-mode's buffers interactivelly."
yuuji@48 1553 (interactive)
yuuji@48 1554 (let ((lbuf "*YaTeX mode buffers*") (blist (YaTeX-yatex-buffer-list))
yuuji@48 1555 (lnum -1) buf rv
yuuji@11 1556 (ff "**find-file**"))
yuuji@12 1557 (YaTeX-showup-buffer
yuuji@12 1558 lbuf (function (lambda (x) 1))) ;;Select next window surely.
yuuji@69 1559 (save-excursion
yuuji@69 1560 (set-buffer (get-buffer lbuf))
yuuji@69 1561 (setq buffer-read-only nil)
yuuji@69 1562 (erase-buffer))
yuuji@69 1563 (let ((standard-output (get-buffer lbuf)))
yuuji@11 1564 (while blist
yuuji@48 1565 (princ
yuuji@48 1566 (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A)
yuuji@48 1567 (buffer-name (car blist))))
yuuji@11 1568 (setq blist (cdr blist)))
yuuji@11 1569 (princ (format "':{%s}" ff)))
yuuji@59 1570 (YaTeX-showup-buffer lbuf nil t)
yuuji@11 1571 (YaTeX::label-setup-key-map)
yuuji@11 1572 (setq buffer-read-only t)
yuuji@11 1573 (use-local-map YaTeX-label-select-map)
yuuji@11 1574 (message YaTeX-label-guide-msg)
yuuji@11 1575 (unwind-protect
yuuji@11 1576 (progn
yuuji@11 1577 (recursive-edit)
yuuji@11 1578 (set-buffer lbuf)
yuuji@11 1579 (beginning-of-line)
yuuji@11 1580 (setq rv
yuuji@11 1581 (if (re-search-forward "{\\([^\\}]+\\)}" (point-end-of-line) t)
yuuji@11 1582 (buffer-substring (match-beginning 1) (match-end 1)) nil)))
yuuji@11 1583 (kill-buffer lbuf))
yuuji@48 1584 (if (string= rv ff)
yuuji@48 1585 (progn
yuuji@48 1586 (call-interactively 'find-file)
yuuji@48 1587 (current-buffer))
yuuji@69 1588 rv)))
yuuji@48 1589
yuuji@48 1590 (defun YaTeX-label-other ()
yuuji@48 1591 (let ((rv (YaTeX-select-other-yatex-buffer)))
yuuji@11 1592 (cond
yuuji@11 1593 ((null rv) "")
yuuji@11 1594 (t
yuuji@11 1595 (set-buffer rv)
yuuji@80 1596 (funcall me argp labelcmd refcmd)))))
yuuji@11 1597
yuuji@13 1598 ;;
yuuji@13 1599 ; completion for the arguments of \newcommand
yuuji@13 1600 ;;
yuuji@13 1601 (defun YaTeX::newcommand (&optional argp)
yuuji@13 1602 (cond
yuuji@13 1603 ((= argp 1)
yuuji@394 1604 (let ((command (read-string-with-history "Define newcommand: " "\\")))
yuuji@13 1605 (put 'YaTeX::newcommand 'command (substring command 1))
yuuji@13 1606 command))
yuuji@13 1607 ((= argp 2)
yuuji@13 1608 (let ((argc
yuuji@452 1609 (YaTeX-str2int
yuuji@394 1610 (read-string-with-history "Number of arguments(Default 0): ")))
yuuji@397 1611 (def (YaTeX-read-string-or-skip "Definition: "))
yuuji@13 1612 (command (get 'YaTeX::newcommand 'command)))
yuuji@13 1613 ;;!!! It's illegal to insert string in the add-in function !!!
yuuji@13 1614 (if (> argc 0) (insert (format "[%d]" argc)))
yuuji@13 1615 (if (and (stringp command)
yuuji@13 1616 (string< "" command)
yuuji@51 1617 (y-or-n-p "Update dictionary?"))
yuuji@18 1618 (cond
yuuji@18 1619 ((= argc 0)
yuuji@18 1620 (YaTeX-update-table
yuuji@18 1621 (list command)
yuuji@18 1622 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table))
yuuji@18 1623 ((= argc 1)
yuuji@18 1624 (YaTeX-update-table
yuuji@18 1625 (list command)
yuuji@18 1626 'section-table 'user-section-table 'tmp-section-table))
yuuji@18 1627 (t (YaTeX-update-table
yuuji@18 1628 (list command argc)
yuuji@18 1629 'section-table 'user-section-table 'tmp-section-table))))
yuuji@13 1630 (message "")
yuuji@13 1631 def ;return command name
yuuji@13 1632 ))
yuuji@69 1633 (t "")))
yuuji@13 1634
yuuji@80 1635 (defun YaTeX::newcounter (&optional argp)
yuuji@80 1636 (cond
yuuji@80 1637 ((= argp 1)
yuuji@394 1638 (read-string-with-history "New counter name: "))
yuuji@80 1639 (t "")))
yuuji@80 1640
yuuji@16 1641 ;;
yuuji@16 1642 ; completion for the arguments of \pagestyle
yuuji@16 1643 ;;
yuuji@16 1644 (defun YaTeX::pagestyle (&optional argp)
yuuji@16 1645 "Read the pagestyle with completion."
yuuji@16 1646 (completing-read
yuuji@16 1647 "Page style: "
yuuji@69 1648 '(("plain") ("empty") ("headings") ("myheadings") ("normal") nil)))
yuuji@69 1649
yuuji@51 1650 (fset 'YaTeX::thispagestyle 'YaTeX::pagestyle)
yuuji@51 1651
yuuji@16 1652 ;;
yuuji@16 1653 ; completion for the arguments of \pagenumbering
yuuji@16 1654 ;;
yuuji@16 1655 (defun YaTeX::pagenumbering (&optional argp)
yuuji@16 1656 "Read the numbering style."
yuuji@16 1657 (completing-read
yuuji@16 1658 "Page numbering style: "
yuuji@69 1659 '(("arabic") ("Alpha") ("alpha") ("Roman") ("roman"))))
yuuji@13 1660
yuuji@23 1661 ;;
yuuji@23 1662 ; Length
yuuji@23 1663 ;;
yuuji@23 1664 (defvar YaTeX:style-parameters-default
yuuji@23 1665 '(("\\arraycolsep")
yuuji@23 1666 ("\\arrayrulewidth")
yuuji@23 1667 ("\\baselineskip")
yuuji@23 1668 ("\\columnsep")
yuuji@23 1669 ("\\columnseprule")
yuuji@23 1670 ("\\doublerulesep")
yuuji@23 1671 ("\\evensidemargin")
yuuji@23 1672 ("\\footheight")
yuuji@23 1673 ("\\footskip")
yuuji@23 1674 ("\\headheight")
yuuji@23 1675 ("\\headsep")
yuuji@23 1676 ("\\itemindent")
yuuji@23 1677 ("\\itemsep")
yuuji@23 1678 ("\\labelsep")
yuuji@23 1679 ("\\labelwidth")
yuuji@23 1680 ("\\leftmargin")
yuuji@23 1681 ("\\linewidth")
yuuji@23 1682 ("\\listparindent")
yuuji@23 1683 ("\\marginparsep")
yuuji@23 1684 ("\\marginparwidth")
yuuji@23 1685 ("\\mathindent")
yuuji@23 1686 ("\\oddsidemargin")
yuuji@23 1687 ("\\parindent")
yuuji@23 1688 ("\\parsep")
yuuji@23 1689 ("\\parskip")
yuuji@23 1690 ("\\partopsep")
yuuji@23 1691 ("\\rightmargin")
yuuji@23 1692 ("\\tabcolsep")
yuuji@23 1693 ("\\textheight")
yuuji@23 1694 ("\\textwidth")
yuuji@324 1695 ("\\columnwidth")
yuuji@23 1696 ("\\topmargin")
yuuji@23 1697 ("\\topsep")
yuuji@23 1698 ("\\topskip")
yuuji@23 1699 )
yuuji@23 1700 "Alist of LaTeX style parameters.")
yuuji@23 1701 (defvar YaTeX:style-parameters-private nil
yuuji@23 1702 "*User definable alist of style parameters.")
yuuji@49 1703 (defvar YaTeX:style-parameters-local nil
yuuji@49 1704 "*User definable alist of local style parameters.")
yuuji@23 1705
yuuji@23 1706 (defvar YaTeX:length-history nil "Holds history of length.")
yuuji@51 1707 (put 'YaTeX:length-history 'no-default t)
yuuji@23 1708 (defun YaTeX::setlength (&optional argp)
yuuji@23 1709 "YaTeX add-in function for arguments of \\setlength."
yuuji@23 1710 (cond
yuuji@23 1711 ((equal 1 argp)
yuuji@49 1712 ;;(completing-read "Length variable: " YaTeX:style-parameters nil nil "\\")
yuuji@49 1713 (YaTeX-cplread-with-learning
yuuji@49 1714 "Length variable: "
yuuji@49 1715 'YaTeX:style-parameters-default
yuuji@49 1716 'YaTeX:style-parameters-private
yuuji@49 1717 'YaTeX:style-parameters-local
yuuji@49 1718 nil nil "\\")
yuuji@49 1719 )
yuuji@23 1720 ((equal 2 argp)
yuuji@397 1721 (YaTeX-read-string-or-skip "Length: " nil 'YaTeX:length-history))))
yuuji@69 1722
yuuji@23 1723 (fset 'YaTeX::addtolength 'YaTeX::setlength)
yuuji@23 1724
yuuji@23 1725 (defun YaTeX::settowidth (&optional argp)
yuuji@23 1726 "YaTeX add-in function for arguments of \\settowidth."
yuuji@23 1727 (cond
yuuji@23 1728 ((equal 1 argp)
yuuji@49 1729 (YaTeX-cplread-with-learning
yuuji@49 1730 "Length variable: "
yuuji@49 1731 'YaTeX:style-parameters-default
yuuji@49 1732 'YaTeX:style-parameters-private
yuuji@49 1733 'YaTeX:style-parameters-local
yuuji@49 1734 nil nil "\\"))
yuuji@23 1735 ((equal 2 argp)
yuuji@397 1736 (YaTeX-read-string-or-skip "Text: "))))
yuuji@69 1737
yuuji@23 1738 (defun YaTeX::newlength (&optional argp)
yuuji@23 1739 "YaTeX add-in function for arguments of \\newlength"
yuuji@23 1740 (cond
yuuji@23 1741 ((equal argp 1)
yuuji@394 1742 (let ((length (read-string-with-history "Length variable: " "\\")))
yuuji@49 1743 (if (string< "" length)
yuuji@49 1744 (YaTeX-update-table
yuuji@49 1745 (list length)
yuuji@49 1746 'YaTeX:style-parameters-default
yuuji@49 1747 'YaTeX:style-parameters-private
yuuji@49 1748 'YaTeX:style-parameters-local))
yuuji@69 1749 length))))
yuuji@23 1750
yuuji@23 1751 ;; \multicolumn's arguments
yuuji@23 1752 (defun YaTeX::multicolumn (&optional argp)
yuuji@23 1753 "YaTeX add-in function for arguments of \\multicolumn."
yuuji@23 1754 (cond
yuuji@23 1755 ((equal 1 argp)
yuuji@394 1756 (read-string-with-history "Number of columns: "))
yuuji@23 1757 ((equal 2 argp)
yuuji@79 1758 (YaTeX:read-oneof "|lrc" nil t))
yuuji@23 1759 ((equal 3 argp)
yuuji@397 1760 (YaTeX-read-string-or-skip "Item: "))))
yuuji@23 1761
yuuji@49 1762 (defvar YaTeX:documentstyles-default
yuuji@49 1763 '(("article") ("jarticle") ("j-article")
yuuji@49 1764 ("book") ("jbook") ("j-book")
yuuji@49 1765 ("report") ("jreport") ("j-report")
yuuji@49 1766 ("letter") ("ascjletter"))
yuuji@49 1767 "List of LaTeX documentstyles.")
yuuji@49 1768 (defvar YaTeX:documentstyles-private nil
yuuji@49 1769 "*User defined list of LaTeX documentstyles.")
yuuji@49 1770 (defvar YaTeX:documentstyles-local nil
yuuji@49 1771 "*User defined list of local LaTeX documentstyles.")
yuuji@49 1772 (defvar YaTeX:documentstyle-options-default
yuuji@49 1773 '(("a4j") ("a5j") ("b4j") ("b5j")
yuuji@49 1774 ("twocolumn") ("jtwocolumn") ("epsf") ("epsfig") ("epsbox") ("nfig"))
yuuji@49 1775 "List of LaTeX documentstyle options.")
yuuji@49 1776 (defvar YaTeX:documentstyle-options-private nil
yuuji@49 1777 "*User defined list of LaTeX documentstyle options.")
yuuji@49 1778 (defvar YaTeX:documentstyle-options-local nil
yuuji@49 1779 "List of LaTeX local documentstyle options.")
yuuji@49 1780
yuuji@49 1781 (defun YaTeX:documentstyle ()
yuuji@49 1782 (let*((delim ",")
yuuji@49 1783 (dt (append YaTeX:documentstyle-options-local
yuuji@49 1784 YaTeX:documentstyle-options-private
yuuji@49 1785 YaTeX:documentstyle-options-default))
yuuji@49 1786 (minibuffer-completion-table dt)
yuuji@49 1787 (opt (read-from-minibuffer
yuuji@49 1788 "Style options ([opt1,opt2,...]): "
yuuji@51 1789 nil YaTeX-minibuffer-completion-map nil))
yuuji@49 1790 (substr opt) o)
yuuji@49 1791 (if (string< "" opt)
yuuji@49 1792 (progn
yuuji@49 1793 (while substr
yuuji@49 1794 (setq o (substring substr 0 (string-match delim substr)))
yuuji@49 1795 (or (assoc o dt)
yuuji@49 1796 (YaTeX-update-table
yuuji@49 1797 (list o)
yuuji@49 1798 'YaTeX:documentstyle-options-default
yuuji@49 1799 'YaTeX:documentstyle-options-private
yuuji@49 1800 'YaTeX:documentstyle-options-local))
yuuji@49 1801 (setq substr
yuuji@49 1802 (if (string-match delim substr)
yuuji@49 1803 (substring substr (1+ (string-match delim substr))))))
yuuji@49 1804 (concat "[" opt "]"))
yuuji@49 1805 "")))
yuuji@49 1806
yuuji@49 1807 (defun YaTeX::documentstyle (&optional argp)
yuuji@51 1808 "YaTeX add-in function for arguments of \\documentstyle."
yuuji@49 1809 (cond
yuuji@49 1810 ((equal argp 1)
yuuji@72 1811 (setq YaTeX-env-name "document")
yuuji@49 1812 (let ((sname
yuuji@49 1813 (YaTeX-cplread-with-learning
yuuji@49 1814 (format "Documentstyle (default %s): "
yuuji@49 1815 YaTeX-default-document-style)
yuuji@49 1816 'YaTeX:documentstyles-default
yuuji@49 1817 'YaTeX:documentstyles-private
yuuji@49 1818 'YaTeX:documentstyles-local)))
yuuji@49 1819 (if (string= "" sname) (setq sname YaTeX-default-document-style))
yuuji@69 1820 (setq YaTeX-default-document-style sname)))))
yuuji@49 1821
yuuji@80 1822 (defun YaTeX::include (argp &optional prompt)
yuuji@86 1823 "Read file name setting default directory to that of main file."
yuuji@80 1824 (cond
yuuji@80 1825 ((= argp 1)
yuuji@86 1826 (save-excursion
yuuji@86 1827 (YaTeX-visit-main t)
yuuji@86 1828 (let*((insert-default-directory)
yuuji@321 1829 (default (and (boundp 'old) (stringp old) old))
yuuji@321 1830 (file (read-file-name (or prompt "Input file: ") ""
yuuji@321 1831 default nil default)))
yuuji@86 1832 (setq file (substring file 0 (string-match "\\.tex$" file))))))))
yuuji@80 1833
yuuji@80 1834 (fset 'YaTeX::input 'YaTeX::include)
yuuji@510 1835 (fset 'YaTeX::svg 'YaTeX::include)
yuuji@80 1836
yuuji@80 1837
yuuji@57 1838 ;;; -------------------- LaTeX2e stuff --------------------
yuuji@57 1839 (defvar YaTeX:documentclass-options-default
yuuji@70 1840 '(("a4paper") ("a5paper") ("b4paper") ("b5paper") ("10pt") ("11pt") ("12pt")
yuuji@57 1841 ("latterpaper") ("legalpaper") ("executivepaper") ("landscape")
yuuji@57 1842 ("oneside") ("twoside") ("draft") ("final") ("leqno") ("fleqn") ("openbib")
yuuji@70 1843 ("tombow") ("titlepage") ("notitlepage") ("dvips")
yuuji@175 1844 ("mingoth") ;for jsarticle
yuuji@57 1845 ("clock") ;for slides class only
yuuji@57 1846 )
yuuji@57 1847 "Default options list for documentclass")
yuuji@57 1848 (defvar YaTeX:documentclass-options-private nil
yuuji@57 1849 "*User defined options list for documentclass")
yuuji@57 1850 (defvar YaTeX:documentclass-options-local nil
yuuji@57 1851 "*User defined options list for local documentclass")
yuuji@57 1852
yuuji@57 1853 (defun YaTeX:documentclass ()
yuuji@57 1854 (let*((delim ",")
yuuji@57 1855 (dt (append YaTeX:documentclass-options-local
yuuji@57 1856 YaTeX:documentclass-options-private
yuuji@57 1857 YaTeX:documentclass-options-default))
yuuji@57 1858 (minibuffer-completion-table dt)
yuuji@57 1859 (opt (read-from-minibuffer
yuuji@57 1860 "Documentclass options ([opt1,opt2,...]): "
yuuji@57 1861 nil YaTeX-minibuffer-completion-map nil))
yuuji@57 1862 (substr opt) o)
yuuji@57 1863 (if (string< "" opt)
yuuji@57 1864 (progn
yuuji@57 1865 (while substr
yuuji@70 1866
yuuji@57 1867 (setq o (substring substr 0 (string-match delim substr)))
yuuji@57 1868 (or (assoc o dt)
yuuji@57 1869 (YaTeX-update-table
yuuji@57 1870 (list o)
yuuji@57 1871 'YaTeX:documentclass-options-default
yuuji@57 1872 'YaTeX:documentclass-options-private
yuuji@57 1873 'YaTeX:documentclass-options-local))
yuuji@57 1874 (setq substr
yuuji@57 1875 (if (string-match delim substr)
yuuji@57 1876 (substring substr (1+ (string-match delim substr))))))
yuuji@57 1877 (concat "[" opt "]"))
yuuji@57 1878 "")))
yuuji@57 1879
yuuji@57 1880 (defvar YaTeX:documentclasses-default
yuuji@57 1881 '(("article") ("jarticle") ("report") ("jreport") ("book") ("jbook")
yuuji@175 1882 ("jsarticle") ("jsbook")
yuuji@57 1883 ("j-article") ("j-report") ("j-book")
yuuji@57 1884 ("letter") ("slides") ("ltxdoc") ("ltxguide") ("ltnews") ("proc"))
yuuji@57 1885 "Default documentclass alist")
yuuji@57 1886 (defvar YaTeX:documentclasses-private nil
yuuji@57 1887 "*User defined documentclass alist")
yuuji@57 1888 (defvar YaTeX:documentclasses-local nil
yuuji@57 1889 "*User defined local documentclass alist")
yuuji@563 1890 (defvar YaTeX-default-documentclass (if YaTeX-japan "jsarticle" "article")
yuuji@57 1891 "*Default documentclass")
yuuji@57 1892
yuuji@57 1893 (defun YaTeX::documentclass (&optional argp)
yuuji@57 1894 (cond
yuuji@57 1895 ((equal argp 1)
yuuji@72 1896 (setq YaTeX-env-name "document")
yuuji@57 1897 (let ((sname
yuuji@57 1898 (YaTeX-cplread-with-learning
yuuji@57 1899 (format "Documentclass (default %s): " YaTeX-default-documentclass)
yuuji@57 1900 'YaTeX:documentclasses-default
yuuji@57 1901 'YaTeX:documentclasses-private
yuuji@57 1902 'YaTeX:documentclasses-local)))
yuuji@57 1903 (if (string= "" sname) (setq sname YaTeX-default-documentclass))
yuuji@252 1904 (setq YaTeX-section-name "title"
yuuji@252 1905 YaTeX-default-documentclass sname)))))
yuuji@57 1906
yuuji@249 1907 (defun YaTeX::title (&optional argp)
yuuji@397 1908 (prog1 (YaTeX-read-string-or-skip "Document Title: ")
yuuji@249 1909 (setq YaTeX-section-name "author"
yuuji@249 1910 YaTeX-single-command "maketitle")))
yuuji@249 1911
yuuji@249 1912 (defun YaTeX::author (&optional argp)
yuuji@397 1913 (prog1 (YaTeX-read-string-or-skip "Document Author: ")
yuuji@249 1914 (setq YaTeX-section-name "date"
yuuji@249 1915 YaTeX-single-command "maketitle")))
yuuji@249 1916
yuuji@252 1917 (defun YaTeX:document ()
yuuji@252 1918 (setq YaTeX-section-name
yuuji@252 1919 (if (string-match "book\\|bk" YaTeX-default-documentclass)
yuuji@252 1920 "chapter"
yuuji@252 1921 "section"))
yuuji@252 1922 "")
yuuji@252 1923
yuuji@252 1924
yuuji@70 1925 (defvar YaTeX:latex2e-named-color-alist
yuuji@70 1926 '(("GreenYellow") ("Yellow") ("Goldenrod") ("Dandelion") ("Apricot")
yuuji@70 1927 ("Peach") ("Melon") ("YellowOrange") ("Orange") ("BurntOrange")
yuuji@70 1928 ("Bittersweet") ("RedOrange") ("Mahogany") ("Maroon") ("BrickRed")
yuuji@70 1929 ("Red") ("OrangeRed") ("RubineRed") ("WildStrawberry") ("Salmon")
yuuji@70 1930 ("CarnationPink") ("Magenta") ("VioletRed") ("Rhodamine") ("Mulberry")
yuuji@70 1931 ("RedViolet") ("Fuchsia") ("Lavender") ("Thistle") ("Orchid")("DarkOrchid")
yuuji@70 1932 ("Purple") ("Plum") ("Violet") ("RoyalPurple") ("BlueViolet")
yuuji@70 1933 ("Periwinkle") ("CadetBlue") ("CornflowerBlue") ("MidnightBlue")
yuuji@70 1934 ("NavyBlue") ("RoyalBlue") ("Blue") ("Cerulean") ("Cyan") ("ProcessBlue")
yuuji@70 1935 ("SkyBlue") ("Turquoise") ("TealBlue") ("Aquamarine") ("BlueGreen")
yuuji@70 1936 ("Emerald") ("JungleGreen") ("SeaGreen") ("Green") ("ForestGreen")
yuuji@70 1937 ("PineGreen") ("LimeGreen") ("YellowGreen") ("SpringGreen") ("OliveGreen")
yuuji@70 1938 ("RawSienna") ("Sepia") ("Brown") ("Tan") ("Gray") ("Black") ("White"))
yuuji@141 1939 "Colors defined in $TEXMF/tex/plain/dvips/colordvi.tex")
yuuji@70 1940
yuuji@70 1941 (defvar YaTeX:latex2e-basic-color-alist
yuuji@70 1942 '(("black") ("white") ("red") ("blue") ("yellow") ("green") ("cyan")
yuuji@70 1943 ("magenta"))
yuuji@70 1944 "Basic colors")
yuuji@70 1945
yuuji@70 1946 (defun YaTeX:textcolor ()
yuuji@70 1947 "Add-in for \\color's option"
yuuji@70 1948 (if (y-or-n-p "Use `named' color? ")
yuuji@70 1949 "[named]"))
yuuji@70 1950
yuuji@70 1951 (defun YaTeX::color-completing-read (prompt)
yuuji@70 1952 (let ((completion-ignore-case t)
yuuji@70 1953 (namedp (save-excursion
yuuji@70 1954 (skip-chars-backward "^\n\\[\\\\")
yuuji@70 1955 (looking-at "named"))))
yuuji@70 1956 (completing-read
yuuji@70 1957 prompt
yuuji@70 1958 (if namedp
yuuji@70 1959 YaTeX:latex2e-named-color-alist
yuuji@70 1960 YaTeX:latex2e-basic-color-alist)
yuuji@70 1961 nil t)))
yuuji@70 1962
yuuji@70 1963 (defun YaTeX::textcolor (argp)
yuuji@70 1964 "Add-in for \\color's argument"
yuuji@70 1965 (cond
yuuji@70 1966 ((= argp 1) (YaTeX::color-completing-read "Color: "))
yuuji@397 1967 ((= argp 2) (YaTeX-read-string-or-skip "Colored string: "))))
yuuji@70 1968
yuuji@70 1969 (fset 'YaTeX:color 'YaTeX:textcolor)
yuuji@70 1970 (fset 'YaTeX::color 'YaTeX::textcolor)
yuuji@70 1971 (fset 'YaTeX:colorbox 'YaTeX:textcolor)
yuuji@70 1972 (fset 'YaTeX::colorbox 'YaTeX::textcolor)
yuuji@70 1973 (fset 'YaTeX:fcolorbox 'YaTeX:textcolor)
yuuji@80 1974 (fset 'YaTeX:pagecolor 'YaTeX:textcolor)
yuuji@80 1975 (fset 'YaTeX::pagecolor 'YaTeX::textcolor)
yuuji@70 1976
yuuji@70 1977 (defun YaTeX::fcolorbox (argp)
yuuji@70 1978 (cond
yuuji@70 1979 ((= argp 1) (YaTeX::color-completing-read "Frame color: "))
yuuji@70 1980 ((= argp 2) (YaTeX::color-completing-read "Inner color: "))
yuuji@397 1981 ((= argp 3) (YaTeX-read-string-or-skip "Colored string: "))))
yuuji@70 1982
yuuji@70 1983 (defun YaTeX:scalebox ()
yuuji@80 1984 "Add-in for \\scalebox"
yuuji@397 1985 (let ((vmag (YaTeX-read-string-or-skip (if YaTeX-japan "倍率(負で反転): "
yuuji@80 1986 "Magnification(Negative for flipped): ")))
yuuji@397 1987 (hmag (YaTeX-read-string-or-skip (if YaTeX-japan "縦倍率(省略可): "
yuuji@80 1988 "Vertical magnification(Optional): "))))
yuuji@70 1989 (if (and hmag (string< "" hmag))
yuuji@70 1990 (format "{%s}[%s]" vmag hmag)
yuuji@70 1991 (format "{%s}" vmag))))
yuuji@70 1992
yuuji@80 1993 (defun YaTeX:rotatebox ()
yuuji@80 1994 "Optional argument add-in for \\rotatebox"
yuuji@80 1995 (message "Rotate origin? (N)one (O)rigin (X)-Y: ")
yuuji@80 1996 (let ((c (read-char)) r (defx "x=mm") x (defy "y=mm") y something)
yuuji@80 1997 (cond
yuuji@80 1998 ((memq c '(?O ?o))
yuuji@80 1999 (if (string< "" (setq r (YaTeX:read-oneof "htbpB")))
yuuji@80 2000 (concat "[origin=" r "]")))
yuuji@80 2001 ((memq c '(?X ?x ?Y ?y))
yuuji@394 2002 (setq r (read-string-with-history
yuuji@394 2003 "" (if YaTeX-emacs-19 (cons defx 3) defx))
yuuji@80 2004 x (if (string< "x=" r) r)
yuuji@394 2005 r (read-string-with-history
yuuji@394 2006 "" (if YaTeX-emacs-19 (cons defy 3) defy))
yuuji@80 2007 y (if (string< "y=" r) r)
yuuji@80 2008 something (or x y))
yuuji@80 2009 (format "%s%s%s%s%s"
yuuji@80 2010 (if something "[" "")
yuuji@80 2011 (if x x "")
yuuji@80 2012 (if (and x y) "," "")
yuuji@80 2013 (if y y "")
yuuji@80 2014 (if something "]" ""))))))
yuuji@80 2015
yuuji@80 2016 (defun YaTeX::rotatebox (argp)
yuuji@80 2017 "Argument add-in for \\rotatebox"
yuuji@80 2018 (cond
yuuji@80 2019 ((= argp 1)
yuuji@394 2020 (read-string-with-history (if YaTeX-japan "回転角(度; 左回り): "
yuuji@80 2021 "Angle in degree(unclockwise): ")))
yuuji@80 2022 ((= argp 2)
yuuji@397 2023 (YaTeX-read-string-or-skip (if YaTeX-japan "テキスト: " "Text: ")))))
yuuji@80 2024
yuuji@73 2025 (defun YaTeX:includegraphics ()
yuuji@73 2026 "Add-in for \\includegraphics's option"
yuuji@342 2027 (let (width height (scale "") angle str)
yuuji@342 2028 (setq width (YaTeX:read-length "Width: ")
yuuji@342 2029 height (YaTeX:read-length "Height: "))
yuuji@254 2030 (or (string< "" width) (string< "" height)
yuuji@237 2031 (setq scale (YaTeX-read-string-or-skip "Scale: ")))
yuuji@237 2032 (setq angle (YaTeX-read-string-or-skip "Angle(0-359): "))
yuuji@73 2033 (setq str
yuuji@73 2034 (mapconcat
yuuji@73 2035 'concat
yuuji@73 2036 (delq nil
yuuji@342 2037 (mapcar (function (lambda (s)
yuuji@73 2038 (and (stringp (symbol-value s))
yuuji@73 2039 (string< "" (symbol-value s))
yuuji@349 2040 (format "%s=%s" s (symbol-value s)))))
yuuji@349 2041 '(width height scale angle)))
yuuji@73 2042 ","))
yuuji@567 2043 (if (string= "" str) ""
yuuji@567 2044 (concat "[" str "]"))))
yuuji@73 2045
yuuji@413 2046 (defvar YaTeX::get-boundingbox-cmd YaTeX-cmd-gs
yuuji@413 2047 "Command to get bounding box from PDF files.
yuuji@413 2048 Possible values are `gs' and `extractbb'.")
yuuji@413 2049
yuuji@308 2050 (defun YaTeX::get-boundingbox (file)
yuuji@308 2051 "Return the bound box as a string
yuuji@308 2052 This function relies on gs(ghostscript) command installed."
yuuji@308 2053 (let ((str (YaTeX-command-to-string
yuuji@413 2054 (format
yuuji@413 2055 (cond
yuuji@413 2056 ((string-match "extractbb" YaTeX::get-boundingbox-cmd)
yuuji@413 2057 "%s -O %s")
yuuji@413 2058 ((string-match "gs" YaTeX::get-boundingbox-cmd)
yuuji@413 2059 "%s -sDEVICE=bbox -dBATCH -dNOPAUSE %s")
yuuji@413 2060 (t "echo %s %s"))
yuuji@413 2061 YaTeX::get-boundingbox-cmd file))))
yuuji@308 2062 (if (string-match
yuuji@308 2063 "%%BoundingBox:\\s \\([0-9]+\\s [0-9]+\\s [0-9]+\\s [0-9]+\\)"
yuuji@308 2064 str)
yuuji@308 2065 (substring str (match-beginning 1) (match-end 1)))))
yuuji@308 2066
yuuji@330 2067 (defun YaTeX::includegraphics (argp &optional file doclip)
yuuji@70 2068 "Add-in for \\includegraphics"
yuuji@340 2069 (let*((imgfile (or file (YaTeX::include argp "Image File: ")))
yuuji@338 2070 (imgfilepath
yuuji@338 2071 (save-excursion
yuuji@338 2072 (YaTeX-visit-main t)
yuuji@338 2073 (expand-file-name imgfile default-directory)))
yuuji@254 2074 (case-fold-search t) info bb noupdate needclose c)
yuuji@308 2075 (and (string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\|pdf\\)$" imgfile)
yuuji@338 2076 (file-exists-p imgfilepath)
yuuji@247 2077 (or (fboundp 'yahtml-get-image-info)
yuuji@247 2078 (progn
yuuji@247 2079 (load "yahtml" t) (featurep 'yahtml))) ;(require 'yahtml nil t)
yuuji@308 2080 (if (string-match "\\.pdf" imgfile)
yuuji@308 2081 (and
yuuji@338 2082 (setq info (YaTeX::get-boundingbox imgfilepath))
yuuji@308 2083 (stringp info)
yuuji@308 2084 (string< "" info)
yuuji@308 2085 (setq bb (format "bb=%s" info)))
yuuji@338 2086 (setq info (yahtml-get-image-info imgfilepath))
yuuji@308 2087 (car info) ;if has width value
yuuji@308 2088 (car (cdr info)) ;if has height value
yuuji@308 2089 (setq bb (format "bb=%d %d %d %d" 0 0 (car info) (car (cdr info)))))
yuuji@248 2090 (save-excursion
yuuji@248 2091 (cond
yuuji@254 2092 ((and (save-excursion
yuuji@254 2093 (YaTeX-re-search-active-backward
yuuji@254 2094 "\\\\\\(includegraphics\\)\\|\\(bb=[-+ \t0-9]+\\)"
yuuji@254 2095 YaTeX-comment-prefix nil t))
yuuji@248 2096 (match-beginning 2)
yuuji@248 2097 (not (setq noupdate (equal (YaTeX-match-string 2) bb)))
yuuji@248 2098 (y-or-n-p (format "Update `bb=' line to `%s'?: " bb)))
yuuji@248 2099 (message "")
yuuji@248 2100 (replace-match bb))
yuuji@248 2101 (noupdate nil)
yuuji@248 2102 ((and (match-beginning 1)
yuuji@330 2103 (or doclip
yuuji@330 2104 (prog2
yuuji@330 2105 (message "Insert `%s'? Y)es N)o C)yes+`clip': " bb)
yuuji@330 2106 (memq (setq c (read-char)) '(?y ?Y ?\ ?c ?C))
yuuji@332 2107 (setq doclip (memq c '(?c ?C)))
yuuji@330 2108 (message ""))))
yuuji@248 2109 (goto-char (match-end 0))
yuuji@308 2110 (message "`bb=' %s"
yuuji@308 2111 (format
yuuji@308 2112 (if YaTeX-japan
yuuji@308 2113 "の値はファイル名の上で `%s' を押してファイル名を再入力して更新できます。"
yuuji@308 2114 "values can be update by typing `%s' on file name.")
yuuji@308 2115 (key-description
yuuji@308 2116 (car (where-is-internal 'YaTeX-change-*)))))
yuuji@248 2117 (if (looking-at "\\[") (forward-char 1)
yuuji@248 2118 (insert-before-markers "[")
yuuji@248 2119 (setq needclose t))
yuuji@248 2120 (insert-before-markers bb)
yuuji@332 2121 (if doclip (insert-before-markers ",clip"))
yuuji@248 2122 (if needclose (insert-before-markers "]")
yuuji@248 2123 (or (looking-at "\\]") (insert-before-markers ","))))
yuuji@248 2124 (t (YaTeX-push-to-kill-ring bb)))))
yuuji@248 2125 (setq YaTeX-section-name "caption")
yuuji@247 2126 imgfile))
yuuji@70 2127
yuuji@86 2128 (defun YaTeX::verbfile (argp)
yuuji@86 2129 "Add-in for \\verbfile"
yuuji@86 2130 (YaTeX::include argp "Virbatim File: "))
yuuji@86 2131
yuuji@68 2132 (defun YaTeX:caption ()
yuuji@72 2133 (setq YaTeX-section-name "label")
yuuji@68 2134 nil)
yuuji@68 2135
yuuji@551 2136 (defun YaTeX:subfigure ()
yuuji@551 2137 (let ((subcap (YaTeX-read-string-or-skip "Sub-caption: ")))
yuuji@551 2138 (if (string= "" subcap) ""
yuuji@551 2139 (concat "[" subcap "]"))))
yuuji@551 2140
yuuji@552 2141 (defun YaTeX::subfigure (argp)
yuuji@551 2142 (setq YaTeX-section-name "includegraphics")
yuuji@551 2143 nil)
yuuji@551 2144
yuuji@554 2145 ;; for okumacro
yuuji@554 2146 (defun YaTeX::ruby (argp)
yuuji@554 2147 (cond
yuuji@554 2148 ((= argp 1) (YaTeX-read-string-or-skip "Kanji: "))
yuuji@554 2149 ((= argp 2) (YaTeX-read-string-or-skip "Yomi: "))))
yuuji@80 2150
yuuji@565 2151 ;;(require 'yatexpkg)
yuuji@565 2152 (autoload 'YaTeX::usepackage "yatexpkg" "Add-in for \\usepackage{}")
yuuji@565 2153 ;;; (defun YaTeX::usepackage()...) MOVED to yatexpkg.el
yuuji@565 2154 ;;; See yatexpkg.el
yuuji@79 2155
yuuji@79 2156
yuuji@79 2157 (defun YaTeX::mask (argp)
yuuji@79 2158 (cond
yuuji@79 2159 ((equal argp 1)
yuuji@397 2160 (YaTeX-read-string-or-skip "String: "))
yuuji@79 2161 ((equal argp 2)
yuuji@79 2162 (let (c)
yuuji@79 2163 (while (not (memq c '(?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K)))
yuuji@79 2164 (message "Mask type(A..K): ")
yuuji@79 2165 (setq c (upcase (read-char))))
yuuji@79 2166 (format "%c" c)))))
yuuji@79 2167
yuuji@79 2168 (defun YaTeX::maskbox (argp)
yuuji@79 2169 (cond
yuuji@79 2170 ((equal argp 1)
yuuji@342 2171 (YaTeX:read-length "Width: "))
yuuji@79 2172 ((equal argp 2)
yuuji@342 2173 (YaTeX:read-length "Height: "))
yuuji@79 2174 ((equal argp 3)
yuuji@79 2175 (let (c)
yuuji@79 2176 (while (not (memq c '(?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K)))
yuuji@79 2177 (message "Mask type(A..K): ")
yuuji@79 2178 (setq c (upcase (read-char))))
yuuji@79 2179 (format "%c" c)))
yuuji@79 2180 ((equal argp 4)
yuuji@79 2181 (YaTeX:read-oneof "lcr" 'quick))
yuuji@79 2182 ((equal argp 5)
yuuji@397 2183 (YaTeX-read-string-or-skip "String: "))))
yuuji@80 2184
yuuji@80 2185 (defun YaTeX::textcircled (argp)
yuuji@80 2186 (cond
yuuji@80 2187 ((equal argp 1)
yuuji@394 2188 (let ((char (read-string-with-history "Circled char: "))
yuuji@80 2189 (left "") (right "") c)
yuuji@80 2190 (setq c (read-char
yuuji@80 2191 "Enclose also with (s)mall (t)iny s(C)riptsize (N)one:"))
yuuji@80 2192 (cond
yuuji@80 2193 ((memq c '(?s ?S)) (setq left "{\\small " right "}"))
yuuji@80 2194 ((memq c '(?t ?T)) (setq left "{\\tiny " right "}"))
yuuji@80 2195 ((memq c '(?c ?C)) (setq left "{\\scriptsize " right "}")))
yuuji@80 2196 (format "%s%s%s" left char right)))))
yuuji@79 2197
yuuji@422 2198 ;;; -------------------- beamer stuff --------------------
yuuji@422 2199 (defvar YaTeX:frame-option-alist-default
yuuji@423 2200 '(("plain") ("containsverbatim") ("shrink") ("squeeze")
yuuji@422 2201 ("allowframebreaks") ("label=")))
yuuji@422 2202 (defvar YaTeX:frame-option-alist-private nil
yuuji@422 2203 "*Alist for completion list of the argument for `frame' environemnt")
yuuji@422 2204 (defvar YaTeX:frame-option-alist
yuuji@422 2205 (append YaTeX:frame-option-alist-private YaTeX:frame-option-alist-default))
yuuji@422 2206
yuuji@422 2207 (defun YaTeX:frame ()
yuuji@422 2208 (let*((minibuffer-local-completion-map YaTeX-minibuffer-completion-map)
yuuji@422 2209 (delim ",")
yuuji@422 2210 (opt (YaTeX-completing-read-or-skip
yuuji@422 2211 "Frame option: " YaTeX:frame-option-alist))
yuuji@422 2212 (title (YaTeX-read-string-or-skip "Title: "))
yuuji@422 2213 (subtitle (YaTeX-read-string-or-skip "Subtitle: ")))
yuuji@424 2214 (setq YaTeX-env-name "columns")
yuuji@422 2215 (concat
yuuji@422 2216 (if (string< "" opt) (concat "[" opt "]"))
yuuji@422 2217 (if (string< "" title) (concat "{" title "}"))
yuuji@422 2218 (if (string< "" subtitle) (concat "{" subtitle "}")))))
yuuji@422 2219
yuuji@424 2220 (defun YaTeX:column-read-width ()
yuuji@424 2221 "Completing function for column environment/macro of Beamer"
yuuji@424 2222 (let ((md (match-data)) (colsinf (YaTeX-quick-in-environment-p "columns"))
yuuji@427 2223 (totalw (float 1)) restw (ww "\\textwidth") defw cw)
yuuji@424 2224 (unwind-protect
yuuji@424 2225 (progn
yuuji@427 2226 (if (save-excursion
yuuji@427 2227 (YaTeX-re-search-active-backward
yuuji@427 2228 "totalwidth=\\([.0-9]+\\)\\(\\\\.*width\\)"
yuuji@427 2229 YaTeX-comment-prefix (cdr colsinf) t))
yuuji@427 2230 (setq totalw (float (string-to-number (YaTeX-match-string 1)))
yuuji@427 2231 ww (YaTeX-match-string 2)))
yuuji@427 2232 (setq restw totalw)
yuuji@424 2233 (save-excursion
yuuji@424 2234 (while (YaTeX-re-search-active-backward
yuuji@424 2235 (concat
yuuji@424 2236 "\\\\begin{column}{\\([.0-9]+\\)\\(\\\\.*width\\)}"
yuuji@424 2237 "\\|"
yuuji@424 2238 "\\\\column{\\([.0-9]+\\)\\(\\\\.*width\\)}")
yuuji@424 2239 YaTeX-comment-prefix
yuuji@424 2240 (cdr colsinf) t)
yuuji@427 2241 (setq restw (- restw (string-to-number
yuuji@427 2242 (or (YaTeX-match-string 1)
yuuji@427 2243 (YaTeX-match-string 3)))))))
yuuji@427 2244 (setq defw (format "%.2f%s"
yuuji@427 2245 (if (= totalw restw) (/ totalw 2) restw)
yuuji@424 2246 (or (YaTeX-match-string 2)
yuuji@424 2247 (YaTeX-match-string 4)
yuuji@427 2248 ww))
yuuji@424 2249 cw (YaTeX:read-length
yuuji@424 2250 (format "Column width(default: %s): " defw)))
yuuji@424 2251 (if (string= "" cw) (setq cw defw))
yuuji@424 2252 (prog1
yuuji@424 2253 cw
yuuji@424 2254 (setq YaTeX-section-name "column")))
yuuji@424 2255 (store-match-data md))))
yuuji@424 2256
yuuji@424 2257 (defun YaTeX:column ()
yuuji@424 2258 (if (eq YaTeX-current-completion-type 'begin)
yuuji@424 2259 (concat "{" (YaTeX:column-read-width) "}")))
yuuji@424 2260 (defun YaTeX::column (argp)
yuuji@424 2261 (cond
yuuji@424 2262 ((= argp 1) (YaTeX:column-read-width))))
yuuji@424 2263 (defvar YaTeX:columns-option-alist
yuuji@426 2264 '(("t") ("T") ("b") ("c") ("onlytextwidth") ("totalwidth=0.9\\textwidth"))
yuuji@424 2265 "*Default option alist for completing columns environment of Beamer")
yuuji@424 2266
yuuji@424 2267 (defun YaTeX:columns ()
yuuji@424 2268 (setq YaTeX-section-name "column"
yuuji@424 2269 YaTeX-env-name "column")
yuuji@424 2270 (let*((minibuffer-local-completion-map YaTeX-minibuffer-completion-map)
yuuji@424 2271 (delim ",=")
yuuji@424 2272 (tbl (append YaTeX:columns-option-alist)) ;XX
yuuji@424 2273 (opt (YaTeX-completing-read-or-skip "columns option: " tbl)))
yuuji@424 2274 (if (string< "" opt)
yuuji@424 2275 (concat "[" opt "]"))))
yuuji@424 2276
yuuji@68 2277 ;;; -------------------- math-mode stuff --------------------
yuuji@68 2278 (defun YaTeX::tilde (&optional pos)
yuuji@68 2279 "For accent macros in mathmode"
yuuji@68 2280 (cond
yuuji@68 2281 ((equal pos 1)
yuuji@68 2282 (message "Put accent on variable: ")
yuuji@68 2283 (let ((v (char-to-string (read-char))) (case-fold-search nil))
yuuji@68 2284 (message "")
yuuji@68 2285 (cond
yuuji@68 2286 ((string-match "i\\|j" v)
yuuji@68 2287 (concat "\\" v "math"))
yuuji@68 2288 ((string-match "[\r\n\t ]" v)
yuuji@68 2289 "")
yuuji@68 2290 (t v))))
yuuji@68 2291 (nil "")))
yuuji@68 2292
yuuji@68 2293 (fset 'YaTeX::hat 'YaTeX::tilde)
yuuji@68 2294 (fset 'YaTeX::check 'YaTeX::tilde)
yuuji@68 2295 (fset 'YaTeX::bar 'YaTeX::tilde)
yuuji@68 2296 (fset 'YaTeX::dot 'YaTeX::tilde)
yuuji@68 2297 (fset 'YaTeX::ddot 'YaTeX::tilde)
yuuji@68 2298 (fset 'YaTeX::vec 'YaTeX::tilde)
yuuji@68 2299
yuuji@68 2300 (defun YaTeX::widetilde (&optional pos)
yuuji@68 2301 "For multichar accent macros in mathmode"
yuuji@68 2302 (cond
yuuji@68 2303 ((equal pos 1)
yuuji@68 2304 (let ((m "Put over chars[%s ]: ") v v2)
yuuji@68 2305 (message m " ")
yuuji@68 2306 (setq v (char-to-string (read-char)))
yuuji@68 2307 (message "")
yuuji@68 2308 (if (string-match "[\r\n\t ]" v)
yuuji@68 2309 ""
yuuji@68 2310 (message m v)
yuuji@68 2311 (setq v2 (char-to-string (read-char)))
yuuji@68 2312 (message "")
yuuji@68 2313 (if (string-match "[\r\n\t ]" v2)
yuuji@68 2314 v
yuuji@68 2315 (concat v v2)))))
yuuji@68 2316 (nil "")))
yuuji@68 2317
yuuji@68 2318 (fset 'YaTeX::widehat 'YaTeX::widetilde)
yuuji@68 2319 (fset 'YaTeX::overline 'YaTeX::widetilde)
yuuji@68 2320 (fset 'YaTeX::overrightarrow 'YaTeX::widetilde)
yuuji@68 2321
yuuji@79 2322 ;
yuuji@79 2323 ; for \frac{}{} region
yuuji@79 2324 (defun YaTeX::frac-region (beg end)
yuuji@79 2325 (if (catch 'done
yuuji@79 2326 (while (re-search-forward "\\s *\\(\\\\over\\|/\\)\\s *" end t)
yuuji@79 2327 (goto-char (match-beginning 0))
yuuji@79 2328 (if (y-or-n-p
yuuji@79 2329 (format "Replace this `%s' with `}{'" (YaTeX-match-string 0)))
yuuji@79 2330 (throw 'done t))
yuuji@79 2331 (goto-char (match-end 0))))
yuuji@79 2332 (let (p (b0 (match-beginning 0)) e0)
yuuji@79 2333 (replace-match "}{")
yuuji@79 2334 (setq e0 (point))
yuuji@79 2335 (save-restriction
yuuji@79 2336 (narrow-to-region beg end)
yuuji@79 2337 (goto-char e0)
yuuji@79 2338 (skip-chars-forward " \t")
yuuji@79 2339 (setq p (point))
yuuji@79 2340 (YaTeX-goto-corresponding-paren)
yuuji@79 2341 (forward-char 1)
yuuji@79 2342 (skip-chars-forward " \t\r\n")
yuuji@79 2343 (if (= end (1+ (point)))
yuuji@79 2344 (progn
yuuji@79 2345 (goto-char p)
yuuji@79 2346 (if (looking-at "\\\\") (forward-char 1))
yuuji@79 2347 (YaTeX-kill-paren nil)))
yuuji@79 2348 (goto-char beg)
yuuji@79 2349 (skip-chars-forward " \t")
yuuji@79 2350 (setq p (point))
yuuji@79 2351 (YaTeX-goto-corresponding-paren)
yuuji@79 2352 (forward-char 1)
yuuji@79 2353 (skip-chars-forward " \t\r\n")
yuuji@79 2354 (if (>= (point) b0)
yuuji@79 2355 (progn
yuuji@79 2356 (goto-char p)
yuuji@79 2357 (if (looking-at "\\\\") (forward-char 1))
yuuji@79 2358 (YaTeX-kill-paren nil))))))
yuuji@79 2359 (message ""))
yuuji@68 2360
yuuji@80 2361 (defun YaTeX::DeclareMathOperator (argp)
yuuji@80 2362 (cond
yuuji@80 2363 ((equal argp 1)
yuuji@397 2364 (YaTeX-read-string-or-skip "Operator: " "\\"))))
yuuji@80 2365
yuuji@68 2366 ;;;
yuuji@68 2367 ;; Add-in functions for large-type command.
yuuji@68 2368 ;;;
yuuji@68 2369 (defun YaTeX:em ()
yuuji@68 2370 (cond
yuuji@68 2371 ((eq YaTeX-current-completion-type 'large) "\\/")
yuuji@68 2372 (t nil)))
yuuji@68 2373 (fset 'YaTeX:it 'YaTeX:em)
yuuji@68 2374
yuuji@23 2375 ;;; -------------------- End of yatexadd --------------------
yuuji@23 2376 (provide 'yatexadd)
yuuji@72 2377 ; Local variables:
yuuji@72 2378 ; fill-prefix: ";;; "
yuuji@72 2379 ; paragraph-start: "^$\\| \\|;;;$"
yuuji@72 2380 ; paragraph-separate: "^$\\| \\|;;;$"
yuuji@72 2381 ; End: