yatex

annotate yatexpkg.el @ 146:78803eda24b8

Change the method of creating a command line for dvipdfm. ([prefix] t d)
author HIROSE Yuuji <yuuji@koeki-u.ac.jp>
date Mon, 27 Sep 2010 17:05:03 +0900
parents 8772bd5d1f02
children 53ff0560fc7d
rev   line source
yuuji@78 1 ;;; -*- Emacs-Lisp -*-
yuuji@78 2 ;;; YaTeX package manager
yuuji@78 3 ;;; yatexpkg.el
yuuji@134 4 ;;; (c)2003-2010 by HIROSE, Yuuji [yuuji@yatex.org]
yuuji@134 5 ;;; Last modified Fri May 28 15:16:04 2010 on firestorm
yuuji@78 6 ;;; $Id$
yuuji@78 7
yuuji@80 8 (defvar YaTeX-package-ams-envs
yuuji@80 9 (mapcar 'car YaTeX-ams-env-table))
yuuji@80 10
yuuji@78 11 (defvar YaTeX-package-alist-default
yuuji@79 12 '(("version" (env "comment") ;by tsuchiya@pine.kuee.kyoto-u.ac.jp
yuuji@79 13 (section "includeversion" "excludeversion"))
yuuji@78 14
yuuji@78 15 ("plext" (section "bou")) ;by yas.axis@ma.mni.ne.jp
yuuji@78 16
yuuji@78 17 ("url" (section "url")) ;by fujieda@jaist.ac.jp
yuuji@78 18
yuuji@78 19 ("fancybox" (section "shadowbox" "doublebox" "ovalbox" "Ovalbox"))
yuuji@80 20 ("slashbox" (section "slashbox" "backslashbox"))
yuuji@78 21 ("pifont" (section "ding"))
yuuji@78 22 ("longtable" (env "longtable"))
yuuji@78 23 ("ascmac" (env "screen" "boxnote" "shadebox" "itembox")
yuuji@78 24 (maketitle "return" "Return" "yen")
yuuji@79 25 (section "keytop") ("mask") ("maskbox"))
yuuji@78 26 ("bm" (section "bm")) ;by aoyama@le.chiba-u.ac.jp
yuuji@78 27
yuuji@78 28 ("alltt" (env "alltt"))
yuuji@78 29 ("misc" (section "verbfile" "listing"))
yuuji@80 30 ("eclbkbox" (env "breakbox"))
yuuji@80 31 ("supertabular" (env "supertabular"))
yuuji@80 32 ("amsmath" (env . YaTeX-package-ams-envs)
yuuji@80 33 (section "tag" "tag*"))
yuuji@134 34 ("amssymb" (maketitle "leqq" "geqq" "mathbb" "mathfrak"
yuuji@134 35 "lll" "ggg")) ;very few. Please tell us!
yuuji@80 36 ("graphicx" (section "includegraphics"
yuuji@80 37 "rotatebox" "scalebox" "resizebox" "reflectbox")
yuuji@80 38 (option . YaTeX-package-graphics-driver-alist))
yuuji@80 39 ("color" (section "textcolor" "colorbox" "pagecolor" "color")
yuuji@80 40 (option . YaTeX-package-graphics-driver-alist))
yuuji@80 41 ("ulem" (section "uline" "uuline" "uwave")
yuuji@80 42 (option ("normalem")))
yuuji@80 43 ("multicol" (env "multicols")))
yuuji@79 44 "Default package vs. macro list.
yuuji@79 45 Alists contains '(PACKAGENAME . MACROLIST)
yuuji@79 46 PACKAGENAME Basename of package(String).
yuuji@79 47 MACROLIST List of '(TYPE . MACROS)
yuuji@79 48 TYPE One of 'env, 'section or 'maketitle according to completion-type
yuuji@79 49 MACROS List of macros
yuuji@79 50
yuuji@80 51 If TYPE is 'option, its cdr is alist of completion candidates for that
yuuji@80 52 package. Its cdr can be a symbol whose value is alist.
yuuji@80 53
yuuji@79 54 An good example is the value of YaTeX-package-alist-default.")
yuuji@78 55
yuuji@80 56 (defvar YaTeX-package-graphics-driver-alist
yuuji@80 57 '(("dvips") ("xdvi") ("dvipdf") ("pdftex") ("dvipsone") ("dviwindo")
yuuji@80 58 ("emtex") ("dviwin") ("oztex") ("textures") ("pctexps") ("pctexwin")
yuuji@80 59 ("pctexhp") ("pctex32") ("truetex") ("tcidvi") ("vtex"))
yuuji@80 60 "Drivers alist of graphics/color stylefile's supporting deveces.
yuuji@80 61 This list is taken from
yuuji@80 62 %% graphics.dtx Copyright (C) 1994 David Carlisle Sebastian Rahtz
yuuji@80 63 %% Copyright (C) 1995 1996 1997 1998 David Carlisle
yuuji@80 64 as of 2004/1/19. Thanks.")
yuuji@80 65
yuuji@78 66 (defvar YaTeX-package-alist-private nil
yuuji@78 67 "*User defined package vs. macro list. See also YaTeX-package-alist-default")
yuuji@78 68
yuuji@78 69 (defun YaTeX-package-lookup (macro &optional type)
yuuji@78 70 "Look up a package which contains a definition of MACRO.
yuuji@78 71 Optional second argument TYPE limits the macro type.
yuuji@78 72 TYPE is a symbol, one of 'env, 'section, 'maketitle."
yuuji@78 73 (let ((list (append YaTeX-package-alist-private YaTeX-package-alist-default))
yuuji@80 74 element x val pkg pkglist r)
yuuji@78 75 (while list
yuuji@78 76 (setq element (car list)
yuuji@78 77 pkg (car element)
yuuji@78 78 element (cdr element))
yuuji@78 79 (if (setq r (catch 'found
yuuji@78 80 (while element
yuuji@80 81 (setq x (car element)
yuuji@80 82 val (cdr x))
yuuji@80 83 (if (symbolp val) (setq val (symbol-value val)))
yuuji@80 84 (and (or (null type)
yuuji@78 85 (eq type (car x)))
yuuji@80 86 (YaTeX-member macro val)
yuuji@78 87 (throw 'found (car x))) ;car x is type
yuuji@78 88 (setq element (cdr element)))))
yuuji@78 89 (setq pkglist (cons (cons pkg r) pkglist)))
yuuji@78 90 (setq list (cdr list)))
yuuji@78 91 pkglist))
yuuji@78 92
yuuji@80 93 (defun YaTeX-package-option-lookup (pkg)
yuuji@80 94 "Look up options for specified pkg and returne them in alist form.
yuuji@80 95 Just only accocing against the alist of YaTeX-package-alist-*"
yuuji@80 96 (let ((l (cdr (assq 'option
yuuji@80 97 (assoc pkg (append YaTeX-package-alist-private
yuuji@80 98 YaTeX-package-alist-default))))))
yuuji@80 99 (if (symbolp l) (symbol-value l) l)))
yuuji@80 100
yuuji@78 101 (defvar YaTeX-package-resolved-list nil
yuuji@78 102 "List of macros whose package is confirmed to be loaded.")
yuuji@78 103
yuuji@78 104 (defun YaTeX-package-auto-usepackage (macro type)
yuuji@78 105 "(Semi)Automatically add the \\usepackage line to main-file.
yuuji@78 106 Search the usepackage for MACRO of the TYPE."
yuuji@78 107 (let ((cb (current-buffer))
yuuji@78 108 (wc (current-window-configuration))
yuuji@78 109 (usepackage (concat YaTeX-ec "usepackage"))
yuuji@80 110 (pkglist (YaTeX-package-lookup macro type))
yuuji@78 111 (usepkgrx (concat
yuuji@78 112 YaTeX-ec-regexp
yuuji@78 113 "\\(usepackage\\|include\\)\\b"))
yuuji@78 114 (register '(lambda () (set-buffer cb)
yuuji@78 115 (set (make-local-variable 'YaTeX-package-resolved-list)
yuuji@78 116 (cons macro YaTeX-package-resolved-list))))
yuuji@78 117 (begdoc (concat YaTeX-ec "begin{document}"))
yuuji@80 118 pb pkg optlist (option "") mb0 uspkgargs)
yuuji@78 119 (if (or (YaTeX-member macro YaTeX-package-resolved-list)
yuuji@78 120 (null pkglist))
yuuji@78 121 nil ;nothing to do
yuuji@78 122 ;; Search `usepackage' into main-file
yuuji@78 123 (YaTeX-visit-main t) ;set buffer to parent file
yuuji@78 124 (setq pb (current-buffer))
yuuji@78 125 (save-excursion
yuuji@78 126 (save-restriction
yuuji@78 127 (if (catch 'found
yuuji@78 128 (goto-char (point-min))
yuuji@78 129 (YaTeX-search-active-forward ;if search fails, goto eob
yuuji@78 130 begdoc YaTeX-comment-prefix nil 1)
yuuji@80 131 (while ;(YaTeX-re-search-active-backward
yuuji@80 132 ;usepkgrx YaTeX-comment-prefix nil t)
yuuji@80 133 ;;allow commented out \usepackages 2004/3/16
yuuji@80 134 (re-search-backward usepkgrx nil t)
yuuji@78 135 (setq mb0 (match-beginning 0))
yuuji@78 136 (skip-chars-forward "^{")
yuuji@80 137 (setq uspkgargs (YaTeX-buffer-substring
yuuji@80 138 (point)
yuuji@80 139 (progn
yuuji@80 140 ;;(forward-list 1) is more precise,
yuuji@80 141 ;; but higher risk.
yuuji@80 142 (skip-chars-forward "^}\n")(point))))
yuuji@78 143 (let ((pl pkglist))
yuuji@78 144 (while pl ;(car pl)'s car is package, cdr is type
yuuji@80 145 (if (string-match
yuuji@80 146 (concat "[{,]\\s *"
yuuji@80 147 (regexp-quote (car (car pl)))
yuuji@80 148 "\\>")
yuuji@80 149 uspkgargs)
yuuji@78 150 (throw 'found t))
yuuji@78 151 (setq pl (cdr pl)))
yuuji@78 152 (goto-char mb0))))
yuuji@78 153 ;;corresponding \usepackage found
yuuji@78 154 (funcall register)
yuuji@78 155 ;; not found, insert it.
yuuji@78 156 (if (y-or-n-p
yuuji@78 157 (format "`%s' requires package. Put \\usepackage now?" macro))
yuuji@78 158 (progn
yuuji@80 159 (require 'yatexadd)
yuuji@78 160 (setq pkg
yuuji@78 161 (completing-read
yuuji@78 162 "Load which package?(TAB for list): "
yuuji@79 163 pkglist nil nil
yuuji@79 164 ;;initial input
yuuji@79 165 (if (= (length pkglist) 1)
yuuji@79 166 (let ((w (car (car pkglist))))
yuuji@80 167 (if YaTeX-emacs-19 (cons w 0) w))))
yuuji@80 168 optlist
yuuji@80 169 (YaTeX-package-option-lookup pkg))
yuuji@80 170 (if optlist
yuuji@80 171 (let ((minibuffer-completion-table optlist)
yuuji@80 172 (delim ",") (w (car (car optlist))))
yuuji@80 173 (setq option
yuuji@80 174 (read-from-minibuffer
yuuji@80 175 (format "Any option for {%s}?: " pkg)
yuuji@80 176 (if (= (length optlist) 1)
yuuji@80 177 (if YaTeX-emacs-19 (cons w 0) w))
yuuji@80 178 YaTeX-minibuffer-completion-map)
yuuji@80 179 option (if (string< "" option)
yuuji@80 180 (concat "[" option "]")
yuuji@80 181 ""))))
yuuji@78 182 (set-buffer pb)
yuuji@78 183 (goto-char (point-min))
yuuji@78 184 (if (YaTeX-re-search-active-forward
yuuji@78 185 (concat YaTeX-ec-regexp
yuuji@78 186 "document\\(style\\|class\\){")
yuuji@78 187 YaTeX-comment-prefix nil t)
yuuji@78 188 (forward-line 1))
yuuji@78 189 (if (YaTeX-search-active-forward
yuuji@78 190 begdoc YaTeX-comment-prefix nil t)
yuuji@78 191 (goto-char (match-beginning 0)))
yuuji@78 192 (insert
yuuji@78 193 usepackage
yuuji@80 194 (format "%s{%s}\t%% required for `\\%s' (yatex added)\n"
yuuji@80 195 option pkg macro))
yuuji@78 196 (funcall register))
yuuji@120 197 (funcall register)
yuuji@78 198 (message "Don't forget to put \\usepackage{%s} yourself later"
yuuji@78 199 (car (car pkglist)))) ;doing car car is negligence...
yuuji@78 200 ))))))