yatex

annotate yatexadd.el @ 48:a0640ff3f72f

Inter-file ref/label, cite/bibitem jump.
author yuuji
date Mon, 31 Oct 1994 17:49:43 +0000
parents cd1b63102eed
children eb0512bfcb7f
rev   line source
yuuji@6 1 ;;; -*- Emacs-Lisp -*-
yuuji@8 2 ;;; YaTeX add-in functions.
yuuji@23 3 ;;; yatexadd.el rev.9
yuuji@14 4 ;;; (c )1991-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
yuuji@48 5 ;;; Last modified Mon Oct 31 12:55:54 1994 on pajero
yuuji@8 6 ;;; $Id$
yuuji@6 7
yuuji@6 8 ;;;
yuuji@6 9 ;;Sample functions for LaTeX environment.
yuuji@6 10 ;;;
yuuji@6 11 (defvar YaTeX:tabular-default-rule
yuuji@6 12 "@{\\vrule width 1pt\\ }c|c|c@{\\ \\vrule width 1pt}"
yuuji@6 13 "*Your favorite default rule format."
yuuji@6 14 )
yuuji@23 15 (defvar YaTeX:tabular-thick-vrule "\\vrule width %s"
yuuji@23 16 "*Vertical thick line format (without @{}). %s'll be replaced by its width."
yuuji@23 17 )
yuuji@23 18 (defvar YaTeX:tabular-thick-hrule "\\noalign{\\hrule height %s}"
yuuji@23 19 "*Horizontal thick line format. %s will be replaced by its width."
yuuji@23 20 )
yuuji@6 21 (defun YaTeX:tabular ()
yuuji@18 22 "YaTeX add-in function for tabular environment.
yuuji@18 23 Notice that this function refers the let-variable `env' in
yuuji@18 24 YaTeX-make-begin-end."
yuuji@23 25 (let ((width "") bars (rule "") (and "") (j 1) loc ans (hline "\\hline"))
yuuji@18 26 (if (string= env "tabular*")
yuuji@18 27 (setq width (concat "{" (read-string "Width: ") "}")))
yuuji@18 28 (setq loc (YaTeX:read-position "tb")
yuuji@23 29 bars (string-to-int
yuuji@23 30 (read-string "Number of columns(0 for default format): " "3")))
yuuji@23 31 (if (<= bars 0)
yuuji@23 32 (setq ;if 0, simple format
yuuji@23 33 rule YaTeX:tabular-default-rule
yuuji@23 34 and "& &")
yuuji@23 35 (while (< j bars) ;repeat bars-1 times
yuuji@23 36 (setq rule (concat rule "c|")
yuuji@23 37 and (concat and "& ")
yuuji@23 38 j (1+ j)))
yuuji@23 39 (setq rule (concat rule "c"))
yuuji@23 40 (message "(N)ormal-frame or (T)hick frame? [nt]")
yuuji@23 41 (setq ans (read-char))
yuuji@23 42 (cond
yuuji@23 43 ((or (equal ans ?t) (equal ans ?T))
yuuji@23 44 (setq ans (read-string "Rule width: " "1pt")
yuuji@23 45 rule (concat
yuuji@23 46 "@{" (format YaTeX:tabular-thick-vrule ans) "}"
yuuji@23 47 rule
yuuji@23 48 "@{\\ " (format YaTeX:tabular-thick-vrule ans) "}")
yuuji@23 49 hline (format YaTeX:tabular-thick-hrule ans)))
yuuji@23 50 (t (setq rule (concat "|" rule "|")
yuuji@23 51 hline "\\hline"))))
yuuji@23 52
yuuji@6 53 (setq rule (read-string "rule format: " rule))
yuuji@6 54
yuuji@23 55 (message "Dont forget to remove null line at the end of tabular.")
yuuji@23 56 (format "%s%s{%s}%s"
yuuji@23 57 width loc rule
yuuji@23 58 (if (and (boundp 'region-mode) region-mode)
yuuji@23 59 "" ;do nothing in region-mode
yuuji@23 60 (format "\n%s\n%s \\\\ \\hline\n%s\n\\\\ %s"
yuuji@23 61 hline and and hline))))
yuuji@18 62 )
yuuji@18 63 (fset 'YaTeX:tabular* 'YaTeX:tabular)
yuuji@18 64 (defun YaTeX:array ()
yuuji@18 65 (concat (YaTeX:read-position "tb")
yuuji@18 66 "{" (read-string "Column format: ") "}")
yuuji@6 67 )
yuuji@6 68
yuuji@23 69 (defun YaTeX:read-oneof (oneof)
yuuji@23 70 (let ((pos "") loc (guide ""))
yuuji@23 71 (and (boundp 'name) name (setq guide (format "%s " name)))
yuuji@6 72 (while (not (string-match
yuuji@8 73 (setq loc (read-key-sequence
yuuji@23 74 (format "%s position (`%s') [%s]: "
yuuji@23 75 guide oneof pos)));name is in YaTeX-addin
yuuji@6 76 "\r\^g\n"))
yuuji@6 77 (cond
yuuji@8 78 ((string-match loc oneof)
yuuji@6 79 (if (not (string-match loc pos))
yuuji@6 80 (setq pos (concat pos loc))))
yuuji@6 81 ((and (string-match loc "\C-h\C-?") (> (length pos) 0))
yuuji@6 82 (setq pos (substring pos 0 (1- (length pos)))))
yuuji@6 83 (t
yuuji@6 84 (ding)
yuuji@8 85 (message "Please input one of `%s'." oneof)
yuuji@6 86 (sit-for 3))))
yuuji@8 87 (message "")
yuuji@23 88 pos)
yuuji@23 89 )
yuuji@23 90
yuuji@23 91 (defun YaTeX:read-position (oneof)
yuuji@23 92 "Read a LaTeX (optional) position format such as `[htbp]'."
yuuji@23 93 (let ((pos (YaTeX:read-oneof oneof)))
yuuji@23 94 (if (string= pos "") "" (concat "[" pos "]")))
yuuji@8 95 )
yuuji@8 96
yuuji@8 97 (defun YaTeX:table ()
yuuji@8 98 "YaTeX add-in function for table environment."
yuuji@8 99 (YaTeX:read-position "htbp")
yuuji@6 100 )
yuuji@6 101
yuuji@46 102 (fset 'YaTeX:figure 'YaTeX:table)
yuuji@46 103 (fset 'YaTeX:figure* 'YaTeX:table)
yuuji@46 104
yuuji@46 105
yuuji@6 106 (defun YaTeX:description ()
yuuji@6 107 "Truly poor service:-)"
yuuji@6 108 (setq single-command "item[]")
yuuji@8 109 ""
yuuji@6 110 )
yuuji@6 111
yuuji@6 112 (defun YaTeX:itemize ()
yuuji@6 113 "It's also poor service."
yuuji@6 114 (setq single-command "item")
yuuji@8 115 ""
yuuji@6 116 )
yuuji@6 117
yuuji@6 118 (fset 'YaTeX:enumerate 'YaTeX:itemize)
yuuji@8 119
yuuji@11 120 (defun YaTeX:picture ()
yuuji@11 121 "Ask the size of coordinates of picture environment."
yuuji@11 122 (concat (YaTeX:read-coordinates "Picture size")
yuuji@11 123 (YaTeX:read-coordinates "Initial position"))
yuuji@11 124 )
yuuji@11 125
yuuji@12 126 (defun YaTeX:equation ()
yuuji@12 127 (if (fboundp 'YaTeX-toggle-math-mode)
yuuji@12 128 (YaTeX-toggle-math-mode t)) ;force math-mode ON.
yuuji@12 129 )
yuuji@12 130 (fset 'YaTeX:eqnarray 'YaTeX:equation)
yuuji@12 131 (fset 'YaTeX:displaymath 'YaTeX:equation)
yuuji@12 132
yuuji@16 133 (defun YaTeX:list ()
yuuji@16 134 "%\n{} %default label\n{} %formatting parameter"
yuuji@16 135 )
yuuji@16 136
yuuji@18 137 (defun YaTeX:minipage ()
yuuji@18 138 (concat (YaTeX:read-position "cbt")
yuuji@18 139 "{" (read-string "Width: ") "}")
yuuji@18 140 )
yuuji@18 141
yuuji@8 142 ;;;
yuuji@8 143 ;;Sample functions for section-type command.
yuuji@8 144 ;;;
yuuji@8 145 (defun YaTeX:multiput ()
yuuji@8 146 (concat (YaTeX:read-coordinates "Pos")
yuuji@8 147 (YaTeX:read-coordinates "Step")
yuuji@8 148 "{" (read-string "How many times: ") "}")
yuuji@8 149 )
yuuji@8 150
yuuji@8 151 (defun YaTeX:put ()
yuuji@8 152 (YaTeX:read-coordinates "Pos")
yuuji@8 153 )
yuuji@8 154
yuuji@8 155 (defun YaTeX:makebox ()
yuuji@23 156 (cond
yuuji@23 157 ((YaTeX-in-environment-p "picture")
yuuji@23 158 (concat (YaTeX:read-coordinates "Dimension")
yuuji@23 159 (YaTeX:read-position "lrtb")))
yuuji@23 160 (t
yuuji@23 161 (let ((width (read-string "Width: ")))
yuuji@23 162 (if (string< "" width)
yuuji@23 163 (progn
yuuji@23 164 (or (equal (aref width 0) ?\[)
yuuji@23 165 (setq width (concat "[" width "]")))
yuuji@23 166 (concat width (YaTeX:read-position "lr")))))))
yuuji@8 167 )
yuuji@8 168
yuuji@8 169 (defun YaTeX:framebox ()
yuuji@8 170 (if (YaTeX-quick-in-environment-p "picture")
yuuji@8 171 (YaTeX:makebox))
yuuji@8 172 )
yuuji@8 173
yuuji@8 174 (defun YaTeX:dashbox ()
yuuji@8 175 (concat "{" (read-string "Dash dimension: ") "}"
yuuji@8 176 (YaTeX:read-coordinates "Dimension"))
yuuji@8 177 )
yuuji@8 178
yuuji@23 179 (defun YaTeX:left ()
yuuji@23 180 (let (c)
yuuji@23 181 (while (not (string-match
yuuji@23 182 (progn (message "Which parenthesis? One of [{(|)}]: ")
yuuji@23 183 (setq c (regexp-quote (char-to-string (read-char)))))
yuuji@23 184 "[{(|)}]")))
yuuji@23 185 (setq single-command "right")
yuuji@23 186 (cond
yuuji@23 187 ((string-match c "[(|)]") c)
yuuji@23 188 (t (concat "\\" c))))
yuuji@23 189 )
yuuji@23 190 (fset 'YaTeX:right 'YaTeX:left)
yuuji@23 191
yuuji@8 192 (defun YaTeX:read-coordinates (&optional mes varX varY)
yuuji@8 193 (concat
yuuji@8 194 "("
yuuji@8 195 (read-string (format "%s %s: " (or mes "Dimension") (or varX "X")))
yuuji@8 196 ","
yuuji@8 197 (read-string (format "%s %s: " (or mes "Dimension") (or varY "Y")))
yuuji@8 198 ")")
yuuji@8 199 )
yuuji@8 200
yuuji@8 201 ;;;
yuuji@8 202 ;;Sample functions for maketitle-type command.
yuuji@8 203 ;;;
yuuji@8 204 (defun YaTeX:sum ()
yuuji@8 205 "Read range of summation."
yuuji@8 206 (YaTeX:check-completion-type 'maketitle)
yuuji@8 207 (concat (YaTeX:read-boundary "_") (YaTeX:read-boundary "^"))
yuuji@8 208 )
yuuji@8 209
yuuji@8 210 (fset 'YaTeX:int 'YaTeX:sum)
yuuji@8 211
yuuji@8 212 (defun YaTeX:lim ()
yuuji@8 213 "Insert limit notation of \\lim."
yuuji@8 214 (YaTeX:check-completion-type 'maketitle)
yuuji@8 215 (let ((var (read-string "Variable: ")) limit)
yuuji@8 216 (if (string= "" var) ""
yuuji@8 217 (setq limit (read-string "Limit ($ means infinity): "))
yuuji@8 218 (if (string= "$" limit) (setq limit "\\infty"))
yuuji@8 219 (concat "_{" var " \\rightarrow " limit "}")))
yuuji@8 220 )
yuuji@8 221
yuuji@8 222 (defun YaTeX:gcd ()
yuuji@8 223 "Add-in function for \\gcd(m,n)."
yuuji@8 224 (YaTeX:check-completion-type 'maketitle)
yuuji@8 225 (YaTeX:read-coordinates "\\gcd" "(?,)" "(,?)")
yuuji@8 226 )
yuuji@8 227
yuuji@8 228 (defun YaTeX:read-boundary (ULchar)
yuuji@8 229 "Read boundary usage by _ or ^. _ or ^ is indicated by argument ULchar."
yuuji@11 230 (let ((bndry (read-string (concat ULchar "{???} ($ for infinity): "))))
yuuji@8 231 (if (string= bndry "") ""
yuuji@11 232 (if (string= bndry "$") (setq bndry "\\infty"))
yuuji@8 233 (concat ULchar "{" bndry "}")))
yuuji@8 234 )
yuuji@8 235
yuuji@14 236 (defun YaTeX:verb ()
yuuji@14 237 "Enclose \\verb's contents with the same characters."
yuuji@14 238 (let ((quote-char (read-string "Quoting char: " "|"))
yuuji@14 239 (contents (read-string "Quoted contents: ")))
yuuji@14 240 (concat quote-char contents quote-char))
yuuji@14 241 )
yuuji@23 242 (fset 'YaTeX:verb* 'YaTeX:verb)
yuuji@14 243
yuuji@43 244 (defun YaTeX:footnotemark ()
yuuji@43 245 (setq section-name "footnotetext")
yuuji@43 246 nil
yuuji@43 247 )
yuuji@43 248
yuuji@48 249 (defun YaTeX:cite ()
yuuji@48 250 (let ((comment (read-string "Comment for citation: ")))
yuuji@48 251 (if (string= comment "") ""
yuuji@48 252 (concat "[" comment "]")))
yuuji@48 253 )
yuuji@48 254
yuuji@48 255 (defun YaTeX:bibitem ()
yuuji@48 256 (let ((label (read-string "Citation label: ")))
yuuji@48 257 (if (string= label "") ""
yuuji@48 258 (concat "[" label "]")))
yuuji@48 259 )
yuuji@48 260
yuuji@14 261 ;;;
yuuji@14 262 ;;Subroutine
yuuji@14 263 ;;;
yuuji@14 264
yuuji@8 265 (defun YaTeX:check-completion-type (type)
yuuji@8 266 "Check valid completion type."
yuuji@8 267 (if (not (eq type YaTeX-current-completion-type))
yuuji@8 268 (error "This should be completed with %s-type completion." type))
yuuji@8 269 )
yuuji@11 270
yuuji@11 271
yuuji@11 272 ;;;
yuuji@11 273 ;;; [[Add-in functions for reading section arguments]]
yuuji@11 274 ;;;
yuuji@11 275 ;; All of add-in functions for reading sections arguments should
yuuji@11 276 ;; take an argument ARGP that specify the argument position.
yuuji@11 277 ;; If argument position is out of range, nil should be returned,
yuuji@11 278 ;; else nil should NOT be returned.
yuuji@13 279
yuuji@13 280 ;;
yuuji@13 281 ; Label selection
yuuji@13 282 ;;
yuuji@11 283 (defvar YaTeX-label-menu-other
yuuji@11 284 (if YaTeX-japan "':‘¼‚̃oƒbƒtƒ@‚̃‰ƒxƒ‹\n" "':LABEL IN OTHER BUFFER.\n"))
yuuji@23 285 (defvar YaTeX-label-menu-repeat
yuuji@23 286 (if YaTeX-japan ".:’¼‘O‚Ì\\ref‚Æ“¯‚¶\n" "/:REPEAT LAST \ref{}\n"))
yuuji@11 287 (defvar YaTeX-label-menu-any
yuuji@11 288 (if YaTeX-japan "*:”CˆÓ‚Ì•¶Žš—ñ\n" "*:ANY STRING.\n"))
yuuji@11 289 (defvar YaTeX-label-buffer "*Label completions*")
yuuji@11 290 (defvar YaTeX-label-guide-msg "Select label and hit RETURN.")
yuuji@11 291 (defvar YaTeX-label-select-map nil
yuuji@11 292 "Key map used in label selection buffer.")
yuuji@11 293 (defun YaTeX::label-setup-key-map ()
yuuji@11 294 (if YaTeX-label-select-map nil
yuuji@11 295 (message "Setting up label selection mode map...")
yuuji@11 296 (setq YaTeX-label-select-map (copy-keymap global-map))
yuuji@11 297 (suppress-keymap YaTeX-label-select-map)
yuuji@11 298 (substitute-all-key-definition
yuuji@11 299 'previous-line 'YaTeX::label-previous YaTeX-label-select-map)
yuuji@11 300 (substitute-all-key-definition
yuuji@11 301 'next-line 'YaTeX::label-next YaTeX-label-select-map)
yuuji@11 302 (define-key YaTeX-label-select-map "\C-n" 'YaTeX::label-next)
yuuji@11 303 (define-key YaTeX-label-select-map "\C-p" 'YaTeX::label-previous)
yuuji@11 304 (define-key YaTeX-label-select-map "<" 'beginning-of-buffer)
yuuji@11 305 (define-key YaTeX-label-select-map ">" 'end-of-buffer)
yuuji@11 306 (define-key YaTeX-label-select-map "\C-m" 'exit-recursive-edit)
yuuji@11 307 (define-key YaTeX-label-select-map "\C-j" 'exit-recursive-edit)
yuuji@11 308 (define-key YaTeX-label-select-map " " 'exit-recursive-edit)
yuuji@11 309 (define-key YaTeX-label-select-map "\C-g" 'abort-recursive-edit)
yuuji@11 310 (define-key YaTeX-label-select-map "/" 'isearch-forward)
yuuji@11 311 (define-key YaTeX-label-select-map "?" 'isearch-backward)
yuuji@11 312 (define-key YaTeX-label-select-map "'" 'YaTeX::label-search-tag)
yuuji@23 313 (define-key YaTeX-label-select-map "." 'YaTeX::label-search-tag)
yuuji@11 314 (define-key YaTeX-label-select-map "*" 'YaTeX::label-search-tag)
yuuji@11 315 (message "Setting up label selection mode map...Done")
yuuji@11 316 (let ((key ?A))
yuuji@11 317 (while (<= key ?Z)
yuuji@11 318 (define-key YaTeX-label-select-map (char-to-string key)
yuuji@11 319 'YaTeX::label-search-tag)
yuuji@11 320 (define-key YaTeX-label-select-map (char-to-string (+ key (- ?a ?A)))
yuuji@11 321 'YaTeX::label-search-tag)
yuuji@11 322 (setq key (1+ key)))))
yuuji@11 323 )
yuuji@11 324 (defun YaTeX::label-next ()
yuuji@11 325 (interactive) (forward-line 1) (message YaTeX-label-guide-msg))
yuuji@11 326 (defun YaTeX::label-previous ()
yuuji@11 327 (interactive) (forward-line -1) (message YaTeX-label-guide-msg))
yuuji@11 328 (defun YaTeX::label-search-tag ()
yuuji@11 329 (interactive)
yuuji@23 330 (let ((case-fold-search t) (tag (regexp-quote (this-command-keys))))
yuuji@11 331 (cond
yuuji@11 332 ((save-excursion
yuuji@11 333 (forward-char 1)
yuuji@23 334 (re-search-forward (concat "^" tag) nil t))
yuuji@11 335 (goto-char (match-beginning 0)))
yuuji@11 336 ((save-excursion
yuuji@11 337 (goto-char (point-min))
yuuji@23 338 (re-search-forward (concat "^" tag) nil t))
yuuji@11 339 (goto-char (match-beginning 0))))
yuuji@11 340 (message YaTeX-label-guide-msg))
yuuji@11 341 )
yuuji@48 342 (defun YaTeX::ref (argp &optional labelcmd refcmd)
yuuji@11 343 (cond
yuuji@11 344 ((= argp 1)
yuuji@11 345 (save-excursion
yuuji@48 346 (let ((lnum 0) e0 label label-list (buf (current-buffer))
yuuji@48 347 (labelcmd (or labelcmd "label")) (refcmd (or refcmd "ref"))
yuuji@11 348 (p (point)) initl line)
yuuji@11 349 (goto-char (point-min))
yuuji@11 350 (message "Collecting labels...")
yuuji@11 351 (save-window-excursion
yuuji@12 352 (YaTeX-showup-buffer
yuuji@12 353 YaTeX-label-buffer (function (lambda (x) (window-width x))))
yuuji@11 354 (with-output-to-temp-buffer YaTeX-label-buffer
yuuji@48 355 (while (YaTeX-re-search-active-forward
yuuji@48 356 (concat "\\\\" labelcmd)
yuuji@48 357 (regexp-quote YaTeX-comment-prefix) nil t)
yuuji@48 358 (goto-char (match-beginning 0))
yuuji@48 359 (skip-chars-forward "^{")
yuuji@48 360 (setq label
yuuji@48 361 (buffer-substring
yuuji@48 362 (1+ (point))
yuuji@48 363 (prog2 (forward-list 1) (setq e0 (1- (point)))))
yuuji@48 364 label-list (cons label label-list))
yuuji@48 365 (or initl
yuuji@48 366 (if (< p (point)) (setq initl lnum)))
yuuji@48 367 (beginning-of-line)
yuuji@48 368 (skip-chars-forward " \t\n" nil)
yuuji@48 369 (princ (format "%c:{%s}\t<<%s>>\n" (+ (% lnum 26) ?A) label
yuuji@48 370 (buffer-substring (point) (point-end-of-line))))
yuuji@48 371 (setq lnum (1+ lnum))
yuuji@48 372 (message "Collecting \\%s{}... %d" labelcmd lnum)
yuuji@11 373 (goto-char e0))
yuuji@11 374 (princ YaTeX-label-menu-other)
yuuji@23 375 (princ YaTeX-label-menu-repeat)
yuuji@11 376 (princ YaTeX-label-menu-any)
yuuji@11 377 );with
yuuji@11 378 (goto-char p)
yuuji@48 379 (message "Collecting %s...Done" labelcmd)
yuuji@11 380 (pop-to-buffer YaTeX-label-buffer)
yuuji@11 381 (YaTeX::label-setup-key-map)
yuuji@11 382 (setq truncate-lines t)
yuuji@11 383 (setq buffer-read-only t)
yuuji@11 384 (use-local-map YaTeX-label-select-map)
yuuji@11 385 (message YaTeX-label-guide-msg)
yuuji@11 386 (goto-line (or initl lnum)) ;goto recently defined label line
yuuji@11 387 (unwind-protect
yuuji@11 388 (progn
yuuji@11 389 (recursive-edit)
yuuji@11 390 (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
yuuji@11 391 (beginning-of-line)
yuuji@11 392 (setq line (count-lines (point-min)(point)))
yuuji@11 393 (cond
yuuji@11 394 ((= line lnum) (setq label (YaTeX-label-other)))
yuuji@23 395 ((= line (1+ lnum))
yuuji@23 396 (save-excursion
yuuji@23 397 (switch-to-buffer buf)
yuuji@23 398 (goto-char p)
yuuji@48 399 (if (re-search-backward
yuuji@48 400 (concat "\\\\" refcmd "{\\([^}]+\\)}") nil t)
yuuji@48 401 (setq label (YaTeX-match-string 1))
yuuji@23 402 (setq label ""))))
yuuji@23 403 ((>= line (+ lnum 2))
yuuji@48 404 (setq label (read-string (format "\\%s{???}: " refcmd))))
yuuji@11 405 (t (setq label (nth (- lnum line 1) label-list)))))
yuuji@11 406 (bury-buffer YaTeX-label-buffer)))
yuuji@11 407 label
yuuji@11 408 ))
yuuji@11 409 ))
yuuji@11 410 )
yuuji@16 411 (fset 'YaTeX::pageref 'YaTeX::ref)
yuuji@48 412 (defun YaTeX::cite (argp)
yuuji@48 413 (cond
yuuji@48 414 ((eq argp 1)
yuuji@48 415 (YaTeX::ref argp "bibitem\\(\\[.*\\]\\)?" "cite"))
yuuji@48 416 (t nil)))
yuuji@11 417
yuuji@48 418 (defun YaTeX-yatex-buffer-list ()
yuuji@48 419 (save-excursion
yuuji@48 420 (delq nil (mapcar (function (lambda (buf)
yuuji@48 421 (set-buffer buf)
yuuji@48 422 (if (eq major-mode 'yatex-mode) buf)))
yuuji@48 423 (buffer-list))))
yuuji@48 424 )
yuuji@48 425
yuuji@48 426 (defun YaTeX-select-other-yatex-buffer ()
yuuji@48 427 "Select buffer from all yatex-mode's buffers interactivelly."
yuuji@48 428 (interactive)
yuuji@48 429 (let ((lbuf "*YaTeX mode buffers*") (blist (YaTeX-yatex-buffer-list))
yuuji@48 430 (lnum -1) buf rv
yuuji@11 431 (ff "**find-file**"))
yuuji@12 432 (YaTeX-showup-buffer
yuuji@12 433 lbuf (function (lambda (x) 1))) ;;Select next window surely.
yuuji@11 434 (with-output-to-temp-buffer lbuf
yuuji@11 435 (while blist
yuuji@48 436 (princ
yuuji@48 437 (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A)
yuuji@48 438 (buffer-name (car blist))))
yuuji@11 439 (setq blist (cdr blist)))
yuuji@11 440 (princ (format "':{%s}" ff)))
yuuji@11 441 (pop-to-buffer lbuf)
yuuji@11 442 (YaTeX::label-setup-key-map)
yuuji@11 443 (setq buffer-read-only t)
yuuji@11 444 (use-local-map YaTeX-label-select-map)
yuuji@11 445 (message YaTeX-label-guide-msg)
yuuji@11 446 (unwind-protect
yuuji@11 447 (progn
yuuji@11 448 (recursive-edit)
yuuji@11 449 (set-buffer lbuf)
yuuji@11 450 (beginning-of-line)
yuuji@11 451 (setq rv
yuuji@11 452 (if (re-search-forward "{\\([^\\}]+\\)}" (point-end-of-line) t)
yuuji@11 453 (buffer-substring (match-beginning 1) (match-end 1)) nil)))
yuuji@11 454 (kill-buffer lbuf))
yuuji@48 455 (if (string= rv ff)
yuuji@48 456 (progn
yuuji@48 457 (call-interactively 'find-file)
yuuji@48 458 (current-buffer))
yuuji@48 459 rv))
yuuji@48 460 )
yuuji@48 461
yuuji@48 462 (defun YaTeX-label-other ()
yuuji@48 463 (let ((rv (YaTeX-select-other-yatex-buffer)))
yuuji@11 464 (cond
yuuji@11 465 ((null rv) "")
yuuji@11 466 (t
yuuji@11 467 (set-buffer rv)
yuuji@48 468 (YaTeX::ref argp labelcmd refcmd)))
yuuji@11 469 )
yuuji@11 470 )
yuuji@11 471
yuuji@13 472 ;;
yuuji@13 473 ; completion for the arguments of \newcommand
yuuji@13 474 ;;
yuuji@13 475 (defun YaTeX::newcommand (&optional argp)
yuuji@13 476 (cond
yuuji@13 477 ((= argp 1)
yuuji@13 478 (let ((command (read-string "Define newcommand: " "\\")))
yuuji@13 479 (put 'YaTeX::newcommand 'command (substring command 1))
yuuji@13 480 command))
yuuji@13 481 ((= argp 2)
yuuji@13 482 (let ((argc
yuuji@13 483 (string-to-int (read-string "Number of arguments(Default 0): ")))
yuuji@13 484 (def (read-string "Definition: "))
yuuji@13 485 (command (get 'YaTeX::newcommand 'command)))
yuuji@13 486 ;;!!! It's illegal to insert string in the add-in function !!!
yuuji@13 487 (if (> argc 0) (insert (format "[%d]" argc)))
yuuji@13 488 (if (and (stringp command)
yuuji@13 489 (string< "" command)
yuuji@13 490 (y-or-n-p "Update user completion table?"))
yuuji@18 491 (cond
yuuji@18 492 ((= argc 0)
yuuji@18 493 (YaTeX-update-table
yuuji@18 494 (list command)
yuuji@18 495 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table))
yuuji@18 496 ((= argc 1)
yuuji@18 497 (YaTeX-update-table
yuuji@18 498 (list command)
yuuji@18 499 'section-table 'user-section-table 'tmp-section-table))
yuuji@18 500 (t (YaTeX-update-table
yuuji@18 501 (list command argc)
yuuji@18 502 'section-table 'user-section-table 'tmp-section-table))))
yuuji@13 503 (message "")
yuuji@13 504 def ;return command name
yuuji@13 505 ))
yuuji@13 506 (t ""))
yuuji@13 507 )
yuuji@13 508
yuuji@16 509 ;;
yuuji@16 510 ; completion for the arguments of \pagestyle
yuuji@16 511 ;;
yuuji@16 512 (defun YaTeX::pagestyle (&optional argp)
yuuji@16 513 "Read the pagestyle with completion."
yuuji@16 514 (completing-read
yuuji@16 515 "Page style: "
yuuji@16 516 '(("plain") ("empty") ("headings") ("myheadings") ("normal") nil))
yuuji@16 517 )
yuuji@16 518 ;;
yuuji@16 519 ; completion for the arguments of \pagenumbering
yuuji@16 520 ;;
yuuji@16 521 (defun YaTeX::pagenumbering (&optional argp)
yuuji@16 522 "Read the numbering style."
yuuji@16 523 (completing-read
yuuji@16 524 "Page numbering style: "
yuuji@16 525 '(("arabic") ("Alpha") ("alpha") ("Roman") ("roman")))
yuuji@16 526 )
yuuji@13 527
yuuji@23 528 ;;
yuuji@23 529 ; Length
yuuji@23 530 ;;
yuuji@23 531 (defvar YaTeX:style-parameters-default
yuuji@23 532 '(("\\arraycolsep")
yuuji@23 533 ("\\arrayrulewidth")
yuuji@23 534 ("\\baselineskip")
yuuji@23 535 ("\\columnsep")
yuuji@23 536 ("\\columnseprule")
yuuji@23 537 ("\\doublerulesep")
yuuji@23 538 ("\\evensidemargin")
yuuji@23 539 ("\\footheight")
yuuji@23 540 ("\\footskip")
yuuji@23 541 ("\\headheight")
yuuji@23 542 ("\\headsep")
yuuji@23 543 ("\\itemindent")
yuuji@23 544 ("\\itemsep")
yuuji@23 545 ("\\labelsep")
yuuji@23 546 ("\\labelwidth")
yuuji@23 547 ("\\leftmargin")
yuuji@23 548 ("\\linewidth")
yuuji@23 549 ("\\listparindent")
yuuji@23 550 ("\\marginparsep")
yuuji@23 551 ("\\marginparwidth")
yuuji@23 552 ("\\mathindent")
yuuji@23 553 ("\\oddsidemargin")
yuuji@23 554 ("\\parindent")
yuuji@23 555 ("\\parsep")
yuuji@23 556 ("\\parskip")
yuuji@23 557 ("\\partopsep")
yuuji@23 558 ("\\rightmargin")
yuuji@23 559 ("\\tabcolsep")
yuuji@23 560 ("\\textheight")
yuuji@23 561 ("\\textwidth")
yuuji@23 562 ("\\topmargin")
yuuji@23 563 ("\\topsep")
yuuji@23 564 ("\\topskip")
yuuji@23 565 )
yuuji@23 566 "Alist of LaTeX style parameters.")
yuuji@23 567 (defvar YaTeX:style-parameters-private nil
yuuji@23 568 "*User definable alist of style parameters.")
yuuji@23 569 (defvar YaTeX:style-parameters-private nil
yuuji@23 570 "Holds the union of LaTeX style parameters.")
yuuji@23 571 (setq YaTeX:style-parameters
yuuji@23 572 (append YaTeX:style-parameters-private YaTeX:style-parameters-default))
yuuji@23 573
yuuji@23 574 (defvar YaTeX:length-history nil "Holds history of length.")
yuuji@23 575 (defun YaTeX::setlength (&optional argp)
yuuji@23 576 "YaTeX add-in function for arguments of \\setlength."
yuuji@23 577 (cond
yuuji@23 578 ((equal 1 argp)
yuuji@23 579 (completing-read "Length variable: " YaTeX:style-parameters nil nil "\\"))
yuuji@23 580 ((equal 2 argp)
yuuji@23 581 (let ((minibuffer-history-symbol 'YaTeX:length-history))
yuuji@23 582 (read-string "Length: "))))
yuuji@23 583 )
yuuji@23 584 (fset 'YaTeX::addtolength 'YaTeX::setlength)
yuuji@23 585
yuuji@23 586 (defun YaTeX::settowidth (&optional argp)
yuuji@23 587 "YaTeX add-in function for arguments of \\settowidth."
yuuji@23 588 (cond
yuuji@23 589 ((equal 1 argp)
yuuji@23 590 (completing-read "Length variable: " YaTeX:style-parameters nil nil "\\"))
yuuji@23 591 ((equal 2 argp)
yuuji@23 592 (read-string "Text: ")))
yuuji@23 593 )
yuuji@23 594 (defun YaTeX::newlength (&optional argp)
yuuji@23 595 "YaTeX add-in function for arguments of \\newlength"
yuuji@23 596 (cond
yuuji@23 597 ((equal argp 1)
yuuji@23 598 (let ((length (read-string "Length variable: " "\\")))
yuuji@23 599 (or (assoc length YaTeX:style-parameters-private)
yuuji@23 600 (setq YaTeX:style-parameters-private
yuuji@23 601 (cons (list length) YaTeX:style-parameters-private)
yuuji@23 602 YaTeX:style-parameters
yuuji@23 603 (cons (list length) YaTeX:style-parameters)))
yuuji@23 604 length)))
yuuji@23 605 )
yuuji@23 606
yuuji@23 607 ;; \multicolumn's arguments
yuuji@23 608 (defun YaTeX::multicolumn (&optional argp)
yuuji@23 609 "YaTeX add-in function for arguments of \\multicolumn."
yuuji@23 610 (cond
yuuji@23 611 ((equal 1 argp)
yuuji@23 612 (read-string "Number of columns: "))
yuuji@23 613 ((equal 2 argp)
yuuji@23 614 (let (c)
yuuji@23 615 (while (not (string-match
yuuji@23 616 (progn (message "Format(one of l,r,c): ")
yuuji@23 617 (setq c (char-to-string (read-char))))
yuuji@23 618 "lrc")))
yuuji@23 619 c))
yuuji@23 620 ((equal 3 argp)
yuuji@23 621 (read-string "Item: ")))
yuuji@23 622 )
yuuji@23 623
yuuji@23 624 ;;; -------------------- End of yatexadd --------------------
yuuji@23 625 (provide 'yatexadd)