yatex

annotate yatexadd.el @ 575:777d17c07759

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