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