yatex

annotate yatexadd.el @ 584:907de32064c9

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