yatex

annotate yatexadd.el @ 627:f294195d0d3f

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