yatex

view yatexpkg.el @ 134:94a1370956a4

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