yatex

view yatexpkg.el @ 556:fbb636ff0fe3

Update version string for RELEASE version
author HIROSE Yuuji <yuuji@gentei.org>
date Mon, 24 Dec 2018 20:56:58 +0900
parents ae0b9fe6372a
children 71697ec66240
line source
1 ;;; yatexpkg.el --- YaTeX package manager -*- coding: sjis -*-
2 ;;;
3 ;;; (c)2003-2018 by HIROSE, Yuuji [yuuji@yatex.org]
4 ;;; Last modified Wed Nov 7 08:57:36 2018 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 ("verbatim" (section "verbatiminput"))
31 ("eclbkbox" (env "breakbox"))
32 ("supertabular" (env "supertabular"))
33 ("amsmath" (env . YaTeX-package-ams-envs)
34 (section "tag" "tag*"))
35 ("amssymb" (maketitle "leqq" "geqq" "mathbb" "mathfrak"
36 "fallingdotseq" "therefore" "because"
37 "varDelta" "varTheta" "varLambda" "varXi" "varPi"
38 "varSigma" "varUpsilon" "varPhi" "varPsi" "varOmega"
39 "lll" "ggg")) ;very few. Please tell us!
40 ("mathrsfs" (section "mathscr"))
41 ("graphicx" (section "includegraphics"
42 "rotatebox" "scalebox" "resizebox" "reflectbox")
43 (option . YaTeX-package-graphics-driver-alist))
44 ("svg" (section "includesvg"))
45 ("color" (section "textcolor" "colorbox" "pagecolor" "color")
46 (option . YaTeX-package-graphics-driver-alist)
47 (default-option . "usenames,dvipsnames"))
48 ("xcolor" (same-as . "color"))
49 ("ulem" (section "uline" "uuline" "uwave")
50 (option ("normalem")))
51 ("multicol" (env "multicols"))
52 ("cref" (section "cleveref"))
53 ("crefrange" (same-as . "cref"))
54 ("cpageref" (same-as . "cref"))
55 ("labelcref" (same-as . "cref"))
56 ("labelcpageref" (same-as . "cref"))
57 ("wrapfig" (env "wrapfigure" "wraptable"))
58 ("setspace" (env "spacing") (section "setstretch"))
59 ("cases" (env "numcases" "subnumcases"))
60 ("subfigure" (section "subfigure"))
61 ("okumacro" (section "ruby" "kenten"))
62 )
63 "Default package vs. macro list.
64 Alists contains '(PACKAGENAME . MACROLIST)
65 PACKAGENAME Basename of package(String).
66 MACROLIST List of '(TYPE . MACROS)
67 TYPE One of 'env, 'section or 'maketitle according to completion-type
68 MACROS List of macros
70 If TYPE is 'option, its cdr is alist of completion candidates for that
71 package. Its cdr can be a symbol whose value is alist.
73 An good example is the value of YaTeX-package-alist-default.")
75 (defvar YaTeX-package-graphics-driver-alist
76 '(("dvips") ("dvipsnames") ("usenames")
77 ("xdvi") ("dvipdfmx") ("pdftex") ("dvipsone") ("dviwindo")
78 ("emtex") ("dviwin") ("oztex") ("textures") ("pctexps") ("pctexwin")
79 ("pctexhp") ("pctex32") ("truetex") ("tcidvi") ("vtex"))
80 "Drivers alist of graphics/color stylefile's supporting devices.
81 This list is taken from
82 %% graphics.dtx Copyright (C) 1994 David Carlisle Sebastian Rahtz
83 %% Copyright (C) 1995 1996 1997 1998 David Carlisle
84 as of 2004/1/19. Thanks.")
86 (defvar YaTeX-package-alist-private nil
87 "*User defined package vs. macro list. See also YaTeX-package-alist-default")
89 (defun YaTeX-package-lookup (macro &optional type)
90 "Look up a package which contains a definition of MACRO.
91 Optional second argument TYPE limits the macro type.
92 TYPE is a symbol, one of 'env, 'section, 'maketitle."
93 (let ((list (append YaTeX-package-alist-private YaTeX-package-alist-default))
94 origlist element x sameas val pkg pkglist r)
95 (setq origlist list)
96 (while list
97 (setq element (car list)
98 pkg (car element)
99 element (cdr element))
100 (if (setq sameas (assq 'same-as element)) ;non-recursive retrieval
101 (setq element (cdr (assoc (cdr sameas) origlist))))
102 (if (setq r (catch 'found
103 (while element
104 (setq x (car element)
105 val (cdr x))
106 (if (symbolp val) (setq val (symbol-value val)))
107 (and (or (null type)
108 (eq type (car x)))
109 (YaTeX-member macro val)
110 (throw 'found (car x))) ;car x is type
111 (setq element (cdr element)))))
112 (setq pkglist (cons (cons pkg r) pkglist)))
113 (setq list (cdr list)))
114 pkglist))
116 (defun YaTeX-package-option-lookup (pkg &optional key)
117 "Look up options for specified pkg and returne them in alist form.
118 Just only associng against the alist of YaTeX-package-alist-*"
119 (let*((list (append YaTeX-package-alist-private YaTeX-package-alist-default))
120 (l (cdr (assq (or key 'option) (assoc pkg list))))
121 (recur (cdr (assq 'same-as (assoc pkg list)))))
122 (cond
123 (recur (YaTeX-package-option-lookup recur key))
124 ((symbolp l) (symbol-value l))
125 (t l))))
127 (defvar YaTeX-package-resolved-list nil
128 "List of macros whose package is confirmed to be loaded.")
130 (defun YaTeX-package-auto-usepackage (macro type &optional autopkg autoopt)
131 "(Semi)Automatically add the \\usepackage line to main-file.
132 Search the usepackage for MACRO of the TYPE.
133 Optional second and third argument AUTOPKG, AUTOOPT are selected
134 without query. Thus those two argument (Full)automatically add
135 a \\usepackage line."
136 (let ((cb (current-buffer))
137 (wc (current-window-configuration))
138 (usepackage (concat YaTeX-ec "usepackage"))
139 (pkglist (YaTeX-package-lookup macro type))
140 (usepkgrx (concat
141 YaTeX-ec-regexp
142 "\\(usepackage\\|include\\)\\b"))
143 (register (function
144 (lambda () (set-buffer cb)
145 (set (make-local-variable 'YaTeX-package-resolved-list)
146 (cons macro YaTeX-package-resolved-list)))))
147 (begdoc (concat YaTeX-ec "begin{document}"))
148 pb pkg optlist (option "") mb0 uspkgargs)
149 (if (or (YaTeX-member macro YaTeX-package-resolved-list)
150 (null pkglist))
151 nil ;nothing to do
152 ;; Search `usepackage' into main-file
153 (YaTeX-visit-main t) ;set buffer to parent file
154 (setq pb (current-buffer))
155 (save-excursion
156 (save-restriction
157 (if (catch 'found
158 (goto-char (point-min))
159 (YaTeX-search-active-forward ;if search fails, goto eob
160 begdoc YaTeX-comment-prefix nil 1)
161 (while ;(YaTeX-re-search-active-backward
162 ;usepkgrx YaTeX-comment-prefix nil t)
163 ;;allow commented out \usepackages 2004/3/16
164 (re-search-backward usepkgrx nil t)
165 (setq mb0 (match-beginning 0))
166 (skip-chars-forward "^{")
167 (setq uspkgargs (YaTeX-buffer-substring
168 (point)
169 (progn
170 ;;(forward-list 1) is more precise,
171 ;; but higher risk.
172 (skip-chars-forward "^}\n")(point))))
173 (let ((pl pkglist))
174 (while pl ;(car pl)'s car is package, cdr is type
175 (if (string-match
176 (concat "[{,]\\s *"
177 (regexp-quote (car (car pl)))
178 "\\>")
179 uspkgargs)
180 (throw 'found t))
181 (setq pl (cdr pl)))
182 (goto-char mb0))))
183 ;;corresponding \usepackage found
184 (funcall register)
185 ;; not found, insert it.
186 (if (or
187 autopkg
188 (y-or-n-p
189 (format "`%s' requires package. Put \\usepackage now?"
190 macro)))
191 (progn
192 (require 'yatexadd)
193 (setq pkg
194 (or autopkg
195 (completing-read
196 "Load which package?(TAB for list): "
197 pkglist nil nil
198 ;;initial input
199 (if (= (length pkglist) 1)
200 (let ((w (car (car pkglist))))
201 (if YaTeX-emacs-19 (cons w 0) w)))))
202 optlist
203 (YaTeX-package-option-lookup pkg))
204 (if optlist
205 (let ((minibuffer-completion-table optlist)
206 (delim ",") (w (car (car optlist)))
207 (dflt (YaTeX-package-option-lookup
208 pkg 'default-option)))
209 (setq option
210 (or
211 autoopt
212 (read-from-minibuffer
213 (format "Any option for {%s}?: " pkg)
214 (let ((v (or dflt
215 (and (= (length optlist) 1) w))))
216 (and v (if YaTeX-emacs-19 (cons v 0) v)))
217 YaTeX-minibuffer-completion-map))
218 option (if (string< "" option)
219 (concat "[" option "]")
220 ""))))
221 (set-buffer pb)
222 (goto-char (point-min))
223 (if (YaTeX-re-search-active-forward
224 (concat YaTeX-ec-regexp
225 "document\\(style\\|class\\){")
226 YaTeX-comment-prefix nil t)
227 (forward-line 1))
228 (if (YaTeX-search-active-forward
229 begdoc YaTeX-comment-prefix nil t)
230 (goto-char (match-beginning 0)))
231 (insert
232 usepackage
233 (format "%s{%s}\t%% required for `\\%s' (yatex added)\n"
234 option pkg macro))
235 (funcall register))
236 (funcall register)
237 (message "Don't forget to put \\usepackage{%s} yourself later"
238 (car (car pkglist)))) ;doing car car is negligence...
239 ))))))