yatex
view yatexpkg.el @ 329:fdbc3b60a09d
Description about %#DVIPDF
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Wed, 26 Nov 2014 09:41:56 +0900 |
parents | fcdb9189cd9c |
children | 30a8f68abe0a |
line source
1 ;;; yatexpkg.el --- YaTeX package manager
2 ;;;
3 ;;; (c)2003-2014 by HIROSE, Yuuji [yuuji@yatex.org]
4 ;;; Last modified Wed Jan 8 08:18:12 2014 on firestorm
5 ;;; $Id$
7 ;;; Code:
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<at>pine.kuee.kyoto-u.ac.jp
13 (section "includeversion" "excludeversion"))
15 ("plext" (section "bou")) ;by yas.axis<at>ma.mni.ne.jp
17 ("url" (section "url")) ;by fujieda<at>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<at>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 "fallingdotseq" "therefore" "because"
36 "lll" "ggg")) ;very few. Please tell us!
37 ("graphicx" (section "includegraphics"
38 "rotatebox" "scalebox" "resizebox" "reflectbox")
39 (option . YaTeX-package-graphics-driver-alist))
40 ("color" (section "textcolor" "colorbox" "pagecolor" "color")
41 (option . YaTeX-package-graphics-driver-alist)
42 (default-option . "usenames,dvipsnames"))
43 ("xcolor" (same-as . "color"))
44 ("ulem" (section "uline" "uuline" "uwave")
45 (option ("normalem")))
46 ("multicol" (env "multicols"))
47 ("cref" (section "cleveref"))
48 ("crefrange" (same-as . "cref"))
49 ("cpageref" (same-as . "cref"))
50 ("labelcref" (same-as . "cref"))
51 ("labelcpageref" (same-as . "cref"))
52 )
53 "Default package vs. macro list.
54 Alists contains '(PACKAGENAME . MACROLIST)
55 PACKAGENAME Basename of package(String).
56 MACROLIST List of '(TYPE . MACROS)
57 TYPE One of 'env, 'section or 'maketitle according to completion-type
58 MACROS List of macros
60 If TYPE is 'option, its cdr is alist of completion candidates for that
61 package. Its cdr can be a symbol whose value is alist.
63 An good example is the value of YaTeX-package-alist-default.")
65 (defvar YaTeX-package-graphics-driver-alist
66 '(("dvips") ("dvipsnames") ("usenames")
67 ("xdvi") ("dvipdf") ("pdftex") ("dvipsone") ("dviwindo")
68 ("emtex") ("dviwin") ("oztex") ("textures") ("pctexps") ("pctexwin")
69 ("pctexhp") ("pctex32") ("truetex") ("tcidvi") ("vtex"))
70 "Drivers alist of graphics/color stylefile's supporting deveces.
71 This list is taken from
72 %% graphics.dtx Copyright (C) 1994 David Carlisle Sebastian Rahtz
73 %% Copyright (C) 1995 1996 1997 1998 David Carlisle
74 as of 2004/1/19. Thanks.")
76 (defvar YaTeX-package-alist-private nil
77 "*User defined package vs. macro list. See also YaTeX-package-alist-default")
79 (defun YaTeX-package-lookup (macro &optional type)
80 "Look up a package which contains a definition of MACRO.
81 Optional second argument TYPE limits the macro type.
82 TYPE is a symbol, one of 'env, 'section, 'maketitle."
83 (let ((list (append YaTeX-package-alist-private YaTeX-package-alist-default))
84 origlist element x sameas val pkg pkglist r)
85 (setq origlist list)
86 (while list
87 (setq element (car list)
88 pkg (car element)
89 element (cdr element))
90 (if (setq sameas (assq 'same-as element)) ;non-recursive retrieval
91 (setq element (cdr (assoc (cdr sameas) origlist))))
92 (if (setq r (catch 'found
93 (while element
94 (setq x (car element)
95 val (cdr x))
96 (if (symbolp val) (setq val (symbol-value val)))
97 (and (or (null type)
98 (eq type (car x)))
99 (YaTeX-member macro val)
100 (throw 'found (car x))) ;car x is type
101 (setq element (cdr element)))))
102 (setq pkglist (cons (cons pkg r) pkglist)))
103 (setq list (cdr list)))
104 pkglist))
106 (defun YaTeX-package-option-lookup (pkg &optional key)
107 "Look up options for specified pkg and returne them in alist form.
108 Just only associng against the alist of YaTeX-package-alist-*"
109 (let*((list (append YaTeX-package-alist-private YaTeX-package-alist-default))
110 (l (cdr (assq (or key 'option) (assoc pkg list))))
111 (recur (cdr (assq 'same-as (assoc pkg list)))))
112 (cond
113 (recur (YaTeX-package-option-lookup recur key))
114 ((symbolp l) (symbol-value l))
115 (t l))))
117 (defvar YaTeX-package-resolved-list nil
118 "List of macros whose package is confirmed to be loaded.")
120 (defun YaTeX-package-auto-usepackage (macro type)
121 "(Semi)Automatically add the \\usepackage line to main-file.
122 Search the usepackage for MACRO of the TYPE."
123 (let ((cb (current-buffer))
124 (wc (current-window-configuration))
125 (usepackage (concat YaTeX-ec "usepackage"))
126 (pkglist (YaTeX-package-lookup macro type))
127 (usepkgrx (concat
128 YaTeX-ec-regexp
129 "\\(usepackage\\|include\\)\\b"))
130 (register '(lambda () (set-buffer cb)
131 (set (make-local-variable 'YaTeX-package-resolved-list)
132 (cons macro YaTeX-package-resolved-list))))
133 (begdoc (concat YaTeX-ec "begin{document}"))
134 pb pkg optlist (option "") mb0 uspkgargs)
135 (if (or (YaTeX-member macro YaTeX-package-resolved-list)
136 (null pkglist))
137 nil ;nothing to do
138 ;; Search `usepackage' into main-file
139 (YaTeX-visit-main t) ;set buffer to parent file
140 (setq pb (current-buffer))
141 (save-excursion
142 (save-restriction
143 (if (catch 'found
144 (goto-char (point-min))
145 (YaTeX-search-active-forward ;if search fails, goto eob
146 begdoc YaTeX-comment-prefix nil 1)
147 (while ;(YaTeX-re-search-active-backward
148 ;usepkgrx YaTeX-comment-prefix nil t)
149 ;;allow commented out \usepackages 2004/3/16
150 (re-search-backward usepkgrx nil t)
151 (setq mb0 (match-beginning 0))
152 (skip-chars-forward "^{")
153 (setq uspkgargs (YaTeX-buffer-substring
154 (point)
155 (progn
156 ;;(forward-list 1) is more precise,
157 ;; but higher risk.
158 (skip-chars-forward "^}\n")(point))))
159 (let ((pl pkglist))
160 (while pl ;(car pl)'s car is package, cdr is type
161 (if (string-match
162 (concat "[{,]\\s *"
163 (regexp-quote (car (car pl)))
164 "\\>")
165 uspkgargs)
166 (throw 'found t))
167 (setq pl (cdr pl)))
168 (goto-char mb0))))
169 ;;corresponding \usepackage found
170 (funcall register)
171 ;; not found, insert it.
172 (if (y-or-n-p
173 (format "`%s' requires package. Put \\usepackage now?" macro))
174 (progn
175 (require 'yatexadd)
176 (setq pkg
177 (completing-read
178 "Load which package?(TAB for list): "
179 pkglist nil nil
180 ;;initial input
181 (if (= (length pkglist) 1)
182 (let ((w (car (car pkglist))))
183 (if YaTeX-emacs-19 (cons w 0) w))))
184 optlist
185 (YaTeX-package-option-lookup pkg))
186 (if optlist
187 (let ((minibuffer-completion-table optlist)
188 (delim ",") (w (car (car optlist)))
189 (dflt (YaTeX-package-option-lookup
190 pkg 'default-option)))
191 (setq option
192 (read-from-minibuffer
193 (format "Any option for {%s}?: " pkg)
194 (let ((v (or dflt
195 (and (= (length optlist) 1) w))))
196 (and v (if YaTeX-emacs-19 (cons v 0) v)))
197 YaTeX-minibuffer-completion-map)
198 option (if (string< "" option)
199 (concat "[" option "]")
200 ""))))
201 (set-buffer pb)
202 (goto-char (point-min))
203 (if (YaTeX-re-search-active-forward
204 (concat YaTeX-ec-regexp
205 "document\\(style\\|class\\){")
206 YaTeX-comment-prefix nil t)
207 (forward-line 1))
208 (if (YaTeX-search-active-forward
209 begdoc YaTeX-comment-prefix nil t)
210 (goto-char (match-beginning 0)))
211 (insert
212 usepackage
213 (format "%s{%s}\t%% required for `\\%s' (yatex added)\n"
214 option pkg macro))
215 (funcall register))
216 (funcall register)
217 (message "Don't forget to put \\usepackage{%s} yourself later"
218 (car (car pkglist)))) ;doing car car is negligence...
219 ))))))