yatex

annotate yatexadd.el @ 51:b0371b6ed799

Created `ChangeLog'. Log hereafter will be written in `ChangeLog'.
author yuuji
date Tue, 20 Dec 1994 21:00:21 +0000
parents eb0512bfcb7f
children 5d94deabb9f9
rev   line source
yuuji@6 1 ;;; -*- Emacs-Lisp -*-
yuuji@8 2 ;;; YaTeX add-in functions.
yuuji@51 3 ;;; yatexadd.el rev.11
yuuji@14 4 ;;; (c )1991-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
yuuji@51 5 ;;; Last modified Mon Dec 19 03:07:01 1994 on landcruiser
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@51 179 (defvar YaTeX-minibuffer-quick-map nil)
yuuji@51 180 (if YaTeX-minibuffer-quick-map nil
yuuji@51 181 (setq YaTeX-minibuffer-quick-map
yuuji@51 182 (copy-keymap minibuffer-local-completion-map))
yuuji@51 183 (let ((ch (1+ ? )))
yuuji@51 184 (while (< ch 127)
yuuji@51 185 (define-key YaTeX-minibuffer-quick-map (char-to-string ch)
yuuji@51 186 'YaTeX-minibuffer-quick-complete)
yuuji@51 187 (setq ch (1+ ch)))))
yuuji@51 188
yuuji@51 189 (defvar YaTeX:left-right-delimiters
yuuji@51 190 '(("(" . ")") (")" . "(") ("[" . "]") ("]" . "[")
yuuji@51 191 ("\\{" . "\\}") ("\\}" . "\\{") ("|") ("\\|")
yuuji@51 192 ("\\lfloor" . "\\rfloor") ("\\lceil" . "\\rceil")
yuuji@51 193 ("\\langle" . "\\rangle") ("/") (".")
yuuji@51 194 ("\\rfloor" . "\\rfloor") ("\\rceil" . "\\lceil")
yuuji@51 195 ("\\rangle" . "\\langle") ("\\backslash")
yuuji@51 196 ("\\uparrow") ("\\downarrow") ("\\updownarrow") ("\\Updownarrow"))
yuuji@51 197 "TeX math delimiter, which can be completed after \\right or \\left.")
yuuji@51 198
yuuji@51 199 (defvar YaTeX:left-right-default nil "Default string of YaTeX:right.")
yuuji@51 200
yuuji@23 201 (defun YaTeX:left ()
yuuji@51 202 (let ((minibuffer-completion-table YaTeX:left-right-delimiters)
yuuji@51 203 delimiter (leftp (string= single-command "left")))
yuuji@51 204 (setq delimiter
yuuji@51 205 (read-from-minibuffer
yuuji@51 206 (format "Delimiter%s: "
yuuji@51 207 (if YaTeX:left-right-default
yuuji@51 208 (format "(default=`%s')" YaTeX:left-right-default)
yuuji@51 209 "(SPC for menu)"))
yuuji@51 210 nil YaTeX-minibuffer-quick-map))
yuuji@51 211 (if (string= "" delimiter) (setq delimiter YaTeX:left-right-default))
yuuji@51 212 (setq single-command (if leftp "right" "left")
yuuji@51 213 YaTeX:left-right-default
yuuji@51 214 (or (cdr (assoc delimiter YaTeX:left-right-delimiters)) delimiter))
yuuji@51 215 delimiter))
yuuji@51 216
yuuji@23 217 (fset 'YaTeX:right 'YaTeX:left)
yuuji@23 218
yuuji@51 219
yuuji@8 220 (defun YaTeX:read-coordinates (&optional mes varX varY)
yuuji@8 221 (concat
yuuji@8 222 "("
yuuji@8 223 (read-string (format "%s %s: " (or mes "Dimension") (or varX "X")))
yuuji@8 224 ","
yuuji@8 225 (read-string (format "%s %s: " (or mes "Dimension") (or varY "Y")))
yuuji@8 226 ")")
yuuji@8 227 )
yuuji@8 228
yuuji@8 229 ;;;
yuuji@8 230 ;;Sample functions for maketitle-type command.
yuuji@8 231 ;;;
yuuji@8 232 (defun YaTeX:sum ()
yuuji@8 233 "Read range of summation."
yuuji@8 234 (YaTeX:check-completion-type 'maketitle)
yuuji@8 235 (concat (YaTeX:read-boundary "_") (YaTeX:read-boundary "^"))
yuuji@8 236 )
yuuji@8 237
yuuji@8 238 (fset 'YaTeX:int 'YaTeX:sum)
yuuji@8 239
yuuji@8 240 (defun YaTeX:lim ()
yuuji@8 241 "Insert limit notation of \\lim."
yuuji@8 242 (YaTeX:check-completion-type 'maketitle)
yuuji@8 243 (let ((var (read-string "Variable: ")) limit)
yuuji@8 244 (if (string= "" var) ""
yuuji@8 245 (setq limit (read-string "Limit ($ means infinity): "))
yuuji@8 246 (if (string= "$" limit) (setq limit "\\infty"))
yuuji@8 247 (concat "_{" var " \\rightarrow " limit "}")))
yuuji@8 248 )
yuuji@8 249
yuuji@8 250 (defun YaTeX:gcd ()
yuuji@8 251 "Add-in function for \\gcd(m,n)."
yuuji@8 252 (YaTeX:check-completion-type 'maketitle)
yuuji@8 253 (YaTeX:read-coordinates "\\gcd" "(?,)" "(,?)")
yuuji@8 254 )
yuuji@8 255
yuuji@8 256 (defun YaTeX:read-boundary (ULchar)
yuuji@8 257 "Read boundary usage by _ or ^. _ or ^ is indicated by argument ULchar."
yuuji@11 258 (let ((bndry (read-string (concat ULchar "{???} ($ for infinity): "))))
yuuji@8 259 (if (string= bndry "") ""
yuuji@11 260 (if (string= bndry "$") (setq bndry "\\infty"))
yuuji@8 261 (concat ULchar "{" bndry "}")))
yuuji@8 262 )
yuuji@8 263
yuuji@14 264 (defun YaTeX:verb ()
yuuji@14 265 "Enclose \\verb's contents with the same characters."
yuuji@14 266 (let ((quote-char (read-string "Quoting char: " "|"))
yuuji@14 267 (contents (read-string "Quoted contents: ")))
yuuji@14 268 (concat quote-char contents quote-char))
yuuji@14 269 )
yuuji@23 270 (fset 'YaTeX:verb* 'YaTeX:verb)
yuuji@14 271
yuuji@43 272 (defun YaTeX:footnotemark ()
yuuji@43 273 (setq section-name "footnotetext")
yuuji@43 274 nil
yuuji@43 275 )
yuuji@43 276
yuuji@48 277 (defun YaTeX:cite ()
yuuji@48 278 (let ((comment (read-string "Comment for citation: ")))
yuuji@48 279 (if (string= comment "") ""
yuuji@48 280 (concat "[" comment "]")))
yuuji@48 281 )
yuuji@48 282
yuuji@48 283 (defun YaTeX:bibitem ()
yuuji@48 284 (let ((label (read-string "Citation label: ")))
yuuji@48 285 (if (string= label "") ""
yuuji@48 286 (concat "[" label "]")))
yuuji@48 287 )
yuuji@48 288
yuuji@14 289 ;;;
yuuji@14 290 ;;Subroutine
yuuji@14 291 ;;;
yuuji@14 292
yuuji@8 293 (defun YaTeX:check-completion-type (type)
yuuji@8 294 "Check valid completion type."
yuuji@8 295 (if (not (eq type YaTeX-current-completion-type))
yuuji@8 296 (error "This should be completed with %s-type completion." type))
yuuji@8 297 )
yuuji@11 298
yuuji@11 299
yuuji@11 300 ;;;
yuuji@11 301 ;;; [[Add-in functions for reading section arguments]]
yuuji@11 302 ;;;
yuuji@11 303 ;; All of add-in functions for reading sections arguments should
yuuji@11 304 ;; take an argument ARGP that specify the argument position.
yuuji@11 305 ;; If argument position is out of range, nil should be returned,
yuuji@11 306 ;; else nil should NOT be returned.
yuuji@13 307
yuuji@13 308 ;;
yuuji@13 309 ; Label selection
yuuji@13 310 ;;
yuuji@11 311 (defvar YaTeX-label-menu-other
yuuji@11 312 (if YaTeX-japan "':‘¼‚̃oƒbƒtƒ@‚̃‰ƒxƒ‹\n" "':LABEL IN OTHER BUFFER.\n"))
yuuji@23 313 (defvar YaTeX-label-menu-repeat
yuuji@23 314 (if YaTeX-japan ".:’¼‘O‚Ì\\ref‚Æ“¯‚¶\n" "/:REPEAT LAST \ref{}\n"))
yuuji@11 315 (defvar YaTeX-label-menu-any
yuuji@11 316 (if YaTeX-japan "*:”CˆÓ‚Ì•¶Žš—ñ\n" "*:ANY STRING.\n"))
yuuji@11 317 (defvar YaTeX-label-buffer "*Label completions*")
yuuji@11 318 (defvar YaTeX-label-guide-msg "Select label and hit RETURN.")
yuuji@11 319 (defvar YaTeX-label-select-map nil
yuuji@11 320 "Key map used in label selection buffer.")
yuuji@11 321 (defun YaTeX::label-setup-key-map ()
yuuji@11 322 (if YaTeX-label-select-map nil
yuuji@11 323 (message "Setting up label selection mode map...")
yuuji@11 324 (setq YaTeX-label-select-map (copy-keymap global-map))
yuuji@11 325 (suppress-keymap YaTeX-label-select-map)
yuuji@11 326 (substitute-all-key-definition
yuuji@11 327 'previous-line 'YaTeX::label-previous YaTeX-label-select-map)
yuuji@11 328 (substitute-all-key-definition
yuuji@11 329 'next-line 'YaTeX::label-next YaTeX-label-select-map)
yuuji@11 330 (define-key YaTeX-label-select-map "\C-n" 'YaTeX::label-next)
yuuji@11 331 (define-key YaTeX-label-select-map "\C-p" 'YaTeX::label-previous)
yuuji@11 332 (define-key YaTeX-label-select-map "<" 'beginning-of-buffer)
yuuji@11 333 (define-key YaTeX-label-select-map ">" 'end-of-buffer)
yuuji@11 334 (define-key YaTeX-label-select-map "\C-m" 'exit-recursive-edit)
yuuji@11 335 (define-key YaTeX-label-select-map "\C-j" 'exit-recursive-edit)
yuuji@11 336 (define-key YaTeX-label-select-map " " 'exit-recursive-edit)
yuuji@11 337 (define-key YaTeX-label-select-map "\C-g" 'abort-recursive-edit)
yuuji@11 338 (define-key YaTeX-label-select-map "/" 'isearch-forward)
yuuji@11 339 (define-key YaTeX-label-select-map "?" 'isearch-backward)
yuuji@11 340 (define-key YaTeX-label-select-map "'" 'YaTeX::label-search-tag)
yuuji@23 341 (define-key YaTeX-label-select-map "." 'YaTeX::label-search-tag)
yuuji@11 342 (define-key YaTeX-label-select-map "*" 'YaTeX::label-search-tag)
yuuji@11 343 (message "Setting up label selection mode map...Done")
yuuji@11 344 (let ((key ?A))
yuuji@11 345 (while (<= key ?Z)
yuuji@11 346 (define-key YaTeX-label-select-map (char-to-string key)
yuuji@11 347 'YaTeX::label-search-tag)
yuuji@11 348 (define-key YaTeX-label-select-map (char-to-string (+ key (- ?a ?A)))
yuuji@11 349 'YaTeX::label-search-tag)
yuuji@11 350 (setq key (1+ key)))))
yuuji@11 351 )
yuuji@11 352 (defun YaTeX::label-next ()
yuuji@11 353 (interactive) (forward-line 1) (message YaTeX-label-guide-msg))
yuuji@11 354 (defun YaTeX::label-previous ()
yuuji@11 355 (interactive) (forward-line -1) (message YaTeX-label-guide-msg))
yuuji@11 356 (defun YaTeX::label-search-tag ()
yuuji@11 357 (interactive)
yuuji@23 358 (let ((case-fold-search t) (tag (regexp-quote (this-command-keys))))
yuuji@11 359 (cond
yuuji@11 360 ((save-excursion
yuuji@11 361 (forward-char 1)
yuuji@23 362 (re-search-forward (concat "^" tag) nil t))
yuuji@11 363 (goto-char (match-beginning 0)))
yuuji@11 364 ((save-excursion
yuuji@11 365 (goto-char (point-min))
yuuji@23 366 (re-search-forward (concat "^" tag) nil t))
yuuji@11 367 (goto-char (match-beginning 0))))
yuuji@11 368 (message YaTeX-label-guide-msg))
yuuji@11 369 )
yuuji@48 370 (defun YaTeX::ref (argp &optional labelcmd refcmd)
yuuji@11 371 (cond
yuuji@11 372 ((= argp 1)
yuuji@11 373 (save-excursion
yuuji@48 374 (let ((lnum 0) e0 label label-list (buf (current-buffer))
yuuji@48 375 (labelcmd (or labelcmd "label")) (refcmd (or refcmd "ref"))
yuuji@11 376 (p (point)) initl line)
yuuji@11 377 (goto-char (point-min))
yuuji@11 378 (message "Collecting labels...")
yuuji@11 379 (save-window-excursion
yuuji@12 380 (YaTeX-showup-buffer
yuuji@12 381 YaTeX-label-buffer (function (lambda (x) (window-width x))))
yuuji@11 382 (with-output-to-temp-buffer YaTeX-label-buffer
yuuji@48 383 (while (YaTeX-re-search-active-forward
yuuji@48 384 (concat "\\\\" labelcmd)
yuuji@48 385 (regexp-quote YaTeX-comment-prefix) nil t)
yuuji@48 386 (goto-char (match-beginning 0))
yuuji@48 387 (skip-chars-forward "^{")
yuuji@48 388 (setq label
yuuji@48 389 (buffer-substring
yuuji@48 390 (1+ (point))
yuuji@48 391 (prog2 (forward-list 1) (setq e0 (1- (point)))))
yuuji@48 392 label-list (cons label label-list))
yuuji@48 393 (or initl
yuuji@48 394 (if (< p (point)) (setq initl lnum)))
yuuji@48 395 (beginning-of-line)
yuuji@48 396 (skip-chars-forward " \t\n" nil)
yuuji@48 397 (princ (format "%c:{%s}\t<<%s>>\n" (+ (% lnum 26) ?A) label
yuuji@48 398 (buffer-substring (point) (point-end-of-line))))
yuuji@48 399 (setq lnum (1+ lnum))
yuuji@48 400 (message "Collecting \\%s{}... %d" labelcmd lnum)
yuuji@11 401 (goto-char e0))
yuuji@11 402 (princ YaTeX-label-menu-other)
yuuji@23 403 (princ YaTeX-label-menu-repeat)
yuuji@11 404 (princ YaTeX-label-menu-any)
yuuji@11 405 );with
yuuji@11 406 (goto-char p)
yuuji@48 407 (message "Collecting %s...Done" labelcmd)
yuuji@11 408 (pop-to-buffer YaTeX-label-buffer)
yuuji@11 409 (YaTeX::label-setup-key-map)
yuuji@11 410 (setq truncate-lines t)
yuuji@11 411 (setq buffer-read-only t)
yuuji@11 412 (use-local-map YaTeX-label-select-map)
yuuji@11 413 (message YaTeX-label-guide-msg)
yuuji@11 414 (goto-line (or initl lnum)) ;goto recently defined label line
yuuji@11 415 (unwind-protect
yuuji@11 416 (progn
yuuji@11 417 (recursive-edit)
yuuji@11 418 (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
yuuji@11 419 (beginning-of-line)
yuuji@11 420 (setq line (count-lines (point-min)(point)))
yuuji@11 421 (cond
yuuji@11 422 ((= line lnum) (setq label (YaTeX-label-other)))
yuuji@23 423 ((= line (1+ lnum))
yuuji@23 424 (save-excursion
yuuji@23 425 (switch-to-buffer buf)
yuuji@23 426 (goto-char p)
yuuji@48 427 (if (re-search-backward
yuuji@48 428 (concat "\\\\" refcmd "{\\([^}]+\\)}") nil t)
yuuji@48 429 (setq label (YaTeX-match-string 1))
yuuji@23 430 (setq label ""))))
yuuji@23 431 ((>= line (+ lnum 2))
yuuji@48 432 (setq label (read-string (format "\\%s{???}: " refcmd))))
yuuji@11 433 (t (setq label (nth (- lnum line 1) label-list)))))
yuuji@11 434 (bury-buffer YaTeX-label-buffer)))
yuuji@11 435 label
yuuji@11 436 ))
yuuji@11 437 ))
yuuji@11 438 )
yuuji@16 439 (fset 'YaTeX::pageref 'YaTeX::ref)
yuuji@48 440 (defun YaTeX::cite (argp)
yuuji@48 441 (cond
yuuji@48 442 ((eq argp 1)
yuuji@48 443 (YaTeX::ref argp "bibitem\\(\\[.*\\]\\)?" "cite"))
yuuji@48 444 (t nil)))
yuuji@11 445
yuuji@48 446 (defun YaTeX-yatex-buffer-list ()
yuuji@48 447 (save-excursion
yuuji@48 448 (delq nil (mapcar (function (lambda (buf)
yuuji@48 449 (set-buffer buf)
yuuji@48 450 (if (eq major-mode 'yatex-mode) buf)))
yuuji@48 451 (buffer-list))))
yuuji@48 452 )
yuuji@48 453
yuuji@48 454 (defun YaTeX-select-other-yatex-buffer ()
yuuji@48 455 "Select buffer from all yatex-mode's buffers interactivelly."
yuuji@48 456 (interactive)
yuuji@48 457 (let ((lbuf "*YaTeX mode buffers*") (blist (YaTeX-yatex-buffer-list))
yuuji@48 458 (lnum -1) buf rv
yuuji@11 459 (ff "**find-file**"))
yuuji@12 460 (YaTeX-showup-buffer
yuuji@12 461 lbuf (function (lambda (x) 1))) ;;Select next window surely.
yuuji@11 462 (with-output-to-temp-buffer lbuf
yuuji@11 463 (while blist
yuuji@48 464 (princ
yuuji@48 465 (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A)
yuuji@48 466 (buffer-name (car blist))))
yuuji@11 467 (setq blist (cdr blist)))
yuuji@11 468 (princ (format "':{%s}" ff)))
yuuji@11 469 (pop-to-buffer lbuf)
yuuji@11 470 (YaTeX::label-setup-key-map)
yuuji@11 471 (setq buffer-read-only t)
yuuji@11 472 (use-local-map YaTeX-label-select-map)
yuuji@11 473 (message YaTeX-label-guide-msg)
yuuji@11 474 (unwind-protect
yuuji@11 475 (progn
yuuji@11 476 (recursive-edit)
yuuji@11 477 (set-buffer lbuf)
yuuji@11 478 (beginning-of-line)
yuuji@11 479 (setq rv
yuuji@11 480 (if (re-search-forward "{\\([^\\}]+\\)}" (point-end-of-line) t)
yuuji@11 481 (buffer-substring (match-beginning 1) (match-end 1)) nil)))
yuuji@11 482 (kill-buffer lbuf))
yuuji@48 483 (if (string= rv ff)
yuuji@48 484 (progn
yuuji@48 485 (call-interactively 'find-file)
yuuji@48 486 (current-buffer))
yuuji@48 487 rv))
yuuji@48 488 )
yuuji@48 489
yuuji@48 490 (defun YaTeX-label-other ()
yuuji@48 491 (let ((rv (YaTeX-select-other-yatex-buffer)))
yuuji@11 492 (cond
yuuji@11 493 ((null rv) "")
yuuji@11 494 (t
yuuji@11 495 (set-buffer rv)
yuuji@48 496 (YaTeX::ref argp labelcmd refcmd)))
yuuji@11 497 )
yuuji@11 498 )
yuuji@11 499
yuuji@13 500 ;;
yuuji@13 501 ; completion for the arguments of \newcommand
yuuji@13 502 ;;
yuuji@13 503 (defun YaTeX::newcommand (&optional argp)
yuuji@13 504 (cond
yuuji@13 505 ((= argp 1)
yuuji@13 506 (let ((command (read-string "Define newcommand: " "\\")))
yuuji@13 507 (put 'YaTeX::newcommand 'command (substring command 1))
yuuji@13 508 command))
yuuji@13 509 ((= argp 2)
yuuji@13 510 (let ((argc
yuuji@13 511 (string-to-int (read-string "Number of arguments(Default 0): ")))
yuuji@13 512 (def (read-string "Definition: "))
yuuji@13 513 (command (get 'YaTeX::newcommand 'command)))
yuuji@13 514 ;;!!! It's illegal to insert string in the add-in function !!!
yuuji@13 515 (if (> argc 0) (insert (format "[%d]" argc)))
yuuji@13 516 (if (and (stringp command)
yuuji@13 517 (string< "" command)
yuuji@51 518 (y-or-n-p "Update dictionary?"))
yuuji@18 519 (cond
yuuji@18 520 ((= argc 0)
yuuji@18 521 (YaTeX-update-table
yuuji@18 522 (list command)
yuuji@18 523 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table))
yuuji@18 524 ((= argc 1)
yuuji@18 525 (YaTeX-update-table
yuuji@18 526 (list command)
yuuji@18 527 'section-table 'user-section-table 'tmp-section-table))
yuuji@18 528 (t (YaTeX-update-table
yuuji@18 529 (list command argc)
yuuji@18 530 'section-table 'user-section-table 'tmp-section-table))))
yuuji@13 531 (message "")
yuuji@13 532 def ;return command name
yuuji@13 533 ))
yuuji@13 534 (t ""))
yuuji@13 535 )
yuuji@13 536
yuuji@16 537 ;;
yuuji@16 538 ; completion for the arguments of \pagestyle
yuuji@16 539 ;;
yuuji@16 540 (defun YaTeX::pagestyle (&optional argp)
yuuji@16 541 "Read the pagestyle with completion."
yuuji@16 542 (completing-read
yuuji@16 543 "Page style: "
yuuji@16 544 '(("plain") ("empty") ("headings") ("myheadings") ("normal") nil))
yuuji@16 545 )
yuuji@51 546 (fset 'YaTeX::thispagestyle 'YaTeX::pagestyle)
yuuji@51 547
yuuji@16 548 ;;
yuuji@16 549 ; completion for the arguments of \pagenumbering
yuuji@16 550 ;;
yuuji@16 551 (defun YaTeX::pagenumbering (&optional argp)
yuuji@16 552 "Read the numbering style."
yuuji@16 553 (completing-read
yuuji@16 554 "Page numbering style: "
yuuji@16 555 '(("arabic") ("Alpha") ("alpha") ("Roman") ("roman")))
yuuji@16 556 )
yuuji@13 557
yuuji@23 558 ;;
yuuji@23 559 ; Length
yuuji@23 560 ;;
yuuji@23 561 (defvar YaTeX:style-parameters-default
yuuji@23 562 '(("\\arraycolsep")
yuuji@23 563 ("\\arrayrulewidth")
yuuji@23 564 ("\\baselineskip")
yuuji@23 565 ("\\columnsep")
yuuji@23 566 ("\\columnseprule")
yuuji@23 567 ("\\doublerulesep")
yuuji@23 568 ("\\evensidemargin")
yuuji@23 569 ("\\footheight")
yuuji@23 570 ("\\footskip")
yuuji@23 571 ("\\headheight")
yuuji@23 572 ("\\headsep")
yuuji@23 573 ("\\itemindent")
yuuji@23 574 ("\\itemsep")
yuuji@23 575 ("\\labelsep")
yuuji@23 576 ("\\labelwidth")
yuuji@23 577 ("\\leftmargin")
yuuji@23 578 ("\\linewidth")
yuuji@23 579 ("\\listparindent")
yuuji@23 580 ("\\marginparsep")
yuuji@23 581 ("\\marginparwidth")
yuuji@23 582 ("\\mathindent")
yuuji@23 583 ("\\oddsidemargin")
yuuji@23 584 ("\\parindent")
yuuji@23 585 ("\\parsep")
yuuji@23 586 ("\\parskip")
yuuji@23 587 ("\\partopsep")
yuuji@23 588 ("\\rightmargin")
yuuji@23 589 ("\\tabcolsep")
yuuji@23 590 ("\\textheight")
yuuji@23 591 ("\\textwidth")
yuuji@23 592 ("\\topmargin")
yuuji@23 593 ("\\topsep")
yuuji@23 594 ("\\topskip")
yuuji@23 595 )
yuuji@23 596 "Alist of LaTeX style parameters.")
yuuji@23 597 (defvar YaTeX:style-parameters-private nil
yuuji@23 598 "*User definable alist of style parameters.")
yuuji@49 599 (defvar YaTeX:style-parameters-local nil
yuuji@49 600 "*User definable alist of local style parameters.")
yuuji@23 601
yuuji@23 602 (defvar YaTeX:length-history nil "Holds history of length.")
yuuji@51 603 (put 'YaTeX:length-history 'no-default t)
yuuji@23 604 (defun YaTeX::setlength (&optional argp)
yuuji@23 605 "YaTeX add-in function for arguments of \\setlength."
yuuji@23 606 (cond
yuuji@23 607 ((equal 1 argp)
yuuji@49 608 ;;(completing-read "Length variable: " YaTeX:style-parameters nil nil "\\")
yuuji@49 609 (YaTeX-cplread-with-learning
yuuji@49 610 "Length variable: "
yuuji@49 611 'YaTeX:style-parameters-default
yuuji@49 612 'YaTeX:style-parameters-private
yuuji@49 613 'YaTeX:style-parameters-local
yuuji@49 614 nil nil "\\")
yuuji@49 615 )
yuuji@23 616 ((equal 2 argp)
yuuji@51 617 (read-string-with-history "Length: " nil 'YaTeX:length-history)))
yuuji@23 618 )
yuuji@23 619 (fset 'YaTeX::addtolength 'YaTeX::setlength)
yuuji@23 620
yuuji@23 621 (defun YaTeX::settowidth (&optional argp)
yuuji@23 622 "YaTeX add-in function for arguments of \\settowidth."
yuuji@23 623 (cond
yuuji@23 624 ((equal 1 argp)
yuuji@49 625 (YaTeX-cplread-with-learning
yuuji@49 626 "Length variable: "
yuuji@49 627 'YaTeX:style-parameters-default
yuuji@49 628 'YaTeX:style-parameters-private
yuuji@49 629 'YaTeX:style-parameters-local
yuuji@49 630 nil nil "\\"))
yuuji@23 631 ((equal 2 argp)
yuuji@23 632 (read-string "Text: ")))
yuuji@23 633 )
yuuji@23 634 (defun YaTeX::newlength (&optional argp)
yuuji@23 635 "YaTeX add-in function for arguments of \\newlength"
yuuji@23 636 (cond
yuuji@23 637 ((equal argp 1)
yuuji@23 638 (let ((length (read-string "Length variable: " "\\")))
yuuji@49 639 (if (string< "" length)
yuuji@49 640 (YaTeX-update-table
yuuji@49 641 (list length)
yuuji@49 642 'YaTeX:style-parameters-default
yuuji@49 643 'YaTeX:style-parameters-private
yuuji@49 644 'YaTeX:style-parameters-local))
yuuji@49 645 length)
yuuji@49 646 ))
yuuji@23 647 )
yuuji@23 648
yuuji@23 649 ;; \multicolumn's arguments
yuuji@23 650 (defun YaTeX::multicolumn (&optional argp)
yuuji@23 651 "YaTeX add-in function for arguments of \\multicolumn."
yuuji@23 652 (cond
yuuji@23 653 ((equal 1 argp)
yuuji@23 654 (read-string "Number of columns: "))
yuuji@23 655 ((equal 2 argp)
yuuji@23 656 (let (c)
yuuji@23 657 (while (not (string-match
yuuji@23 658 (progn (message "Format(one of l,r,c): ")
yuuji@23 659 (setq c (char-to-string (read-char))))
yuuji@23 660 "lrc")))
yuuji@23 661 c))
yuuji@23 662 ((equal 3 argp)
yuuji@23 663 (read-string "Item: ")))
yuuji@23 664 )
yuuji@23 665
yuuji@49 666 (defvar YaTeX:documentstyles-default
yuuji@49 667 '(("article") ("jarticle") ("j-article")
yuuji@49 668 ("book") ("jbook") ("j-book")
yuuji@49 669 ("report") ("jreport") ("j-report")
yuuji@49 670 ("letter") ("ascjletter"))
yuuji@49 671 "List of LaTeX documentstyles.")
yuuji@49 672 (defvar YaTeX:documentstyles-private nil
yuuji@49 673 "*User defined list of LaTeX documentstyles.")
yuuji@49 674 (defvar YaTeX:documentstyles-local nil
yuuji@49 675 "*User defined list of local LaTeX documentstyles.")
yuuji@49 676 (defvar YaTeX:documentstyle-options-default
yuuji@49 677 '(("a4j") ("a5j") ("b4j") ("b5j")
yuuji@49 678 ("twocolumn") ("jtwocolumn") ("epsf") ("epsfig") ("epsbox") ("nfig"))
yuuji@49 679 "List of LaTeX documentstyle options.")
yuuji@49 680 (defvar YaTeX:documentstyle-options-private nil
yuuji@49 681 "*User defined list of LaTeX documentstyle options.")
yuuji@49 682 (defvar YaTeX:documentstyle-options-local nil
yuuji@49 683 "List of LaTeX local documentstyle options.")
yuuji@49 684
yuuji@49 685 (defvar YaTeX-minibuffer-completion-map nil
yuuji@49 686 "Minibuffer completion key map that allows comma completion.")
yuuji@49 687 (if YaTeX-minibuffer-completion-map nil
yuuji@49 688 (setq YaTeX-minibuffer-completion-map
yuuji@49 689 (copy-keymap minibuffer-local-completion-map))
yuuji@49 690 (define-key YaTeX-minibuffer-completion-map " "
yuuji@49 691 'YaTeX-minibuffer-complete)
yuuji@49 692 (define-key YaTeX-minibuffer-completion-map "\t"
yuuji@49 693 'YaTeX-minibuffer-complete))
yuuji@49 694
yuuji@49 695 (defun YaTeX:documentstyle ()
yuuji@49 696 (let*((delim ",")
yuuji@49 697 (dt (append YaTeX:documentstyle-options-local
yuuji@49 698 YaTeX:documentstyle-options-private
yuuji@49 699 YaTeX:documentstyle-options-default))
yuuji@49 700 (minibuffer-completion-table dt)
yuuji@49 701 (opt (read-from-minibuffer
yuuji@49 702 "Style options ([opt1,opt2,...]): "
yuuji@51 703 nil YaTeX-minibuffer-completion-map nil))
yuuji@49 704 (substr opt) o)
yuuji@49 705 (if (string< "" opt)
yuuji@49 706 (progn
yuuji@49 707 (while substr
yuuji@49 708 (setq o (substring substr 0 (string-match delim substr)))
yuuji@49 709 (or (assoc o dt)
yuuji@49 710 (YaTeX-update-table
yuuji@49 711 (list o)
yuuji@49 712 'YaTeX:documentstyle-options-default
yuuji@49 713 'YaTeX:documentstyle-options-private
yuuji@49 714 'YaTeX:documentstyle-options-local))
yuuji@49 715 (setq substr
yuuji@49 716 (if (string-match delim substr)
yuuji@49 717 (substring substr (1+ (string-match delim substr))))))
yuuji@49 718 (concat "[" opt "]"))
yuuji@49 719 "")))
yuuji@49 720
yuuji@49 721 (defun YaTeX::documentstyle (&optional argp)
yuuji@51 722 "YaTeX add-in function for arguments of \\documentstyle."
yuuji@49 723 (cond
yuuji@49 724 ((equal argp 1)
yuuji@51 725 (setq env-name "document")
yuuji@49 726 (let ((sname
yuuji@49 727 (YaTeX-cplread-with-learning
yuuji@49 728 (format "Documentstyle (default %s): "
yuuji@49 729 YaTeX-default-document-style)
yuuji@49 730 'YaTeX:documentstyles-default
yuuji@49 731 'YaTeX:documentstyles-private
yuuji@49 732 'YaTeX:documentstyles-local)))
yuuji@49 733 (if (string= "" sname) (setq sname YaTeX-default-document-style))
yuuji@49 734 (setq YaTeX-default-document-style sname))))
yuuji@49 735 )
yuuji@49 736
yuuji@23 737 ;;; -------------------- End of yatexadd --------------------
yuuji@23 738 (provide 'yatexadd)