yatex

view yatexpkg.el @ 582:f4c2dca86202

Add "mcfamily" and "gtfamily"
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 08 Feb 2020 18:31:52 +0900
parents 6c09561c22f0
children
line source
1 ;;; yatexpkg.el --- YaTeX package manager -*- coding: sjis -*-
2 ;;;
3 ;;; (c)2003-2019 by HIROSE, Yuuji [yuuji@yatex.org]
4 ;;; Last modified Sat May 25 14:46:27 2019 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 ("tabularx" (env "tabularx"))
34 ("amsmath" (env . YaTeX-package-ams-envs)
35 (section "tag" "tag*"))
36 ("amsart" (same-as . "amsmath"))
37 ("amsbook" (same-as . "amsmath"))
38 ("amsproc" (same-as . "amsmath"))
39 ("amssymb" (maketitle "leqq" "geqq" "mathbb" "mathfrak"
40 "fallingdotseq" "therefore" "because"
41 "varDelta" "varTheta" "varLambda" "varXi" "varPi"
42 "varSigma" "varUpsilon" "varPhi" "varPsi" "varOmega"
43 "lll" "ggg")) ;very few. Please tell us!
44 ("latexsym" (maketitle "mho" "Join" "Box" "Diamond" "leadsto"
45 "sqsubset" "sqsupset" "lhd" "unlhd" "rhd" "unrhd"))
46 ("mathrsfs" (section "mathscr"))
47 ("graphicx" (section "includegraphics"
48 "rotatebox" "scalebox" "resizebox" "reflectbox")
49 (option . YaTeX-package-graphics-driver-alist))
50 ("xymtex" (section "Ycyclohexaneh")) ;;XXX we need more and more...
51 ("chemist" nil) ;;XXX we need completions...
52 ("a4j" nil)
53 ("array" nil)
54 ("times" nil)
55 ("newtx" nil)
56 ("makeidx" nil)
57 ("geometry" (section "geometry"))
58 ("lscape" (env "landscape"))
59 ("path" (section "path"))
60 ("epsf" (section "epsfbox"))
61 ("epsfig" (section "epsfig"))
62 ("floatflt" (env "floatingfigure"))
63 ("type1cm" (section "fontsize"))
64 ("svg" (section "includesvg"))
65 ("color" (section "textcolor" "colorbox" "pagecolor" "color")
66 (option . YaTeX-package-graphics-driver-alist)
67 (default-option . "usenames,dvipsnames"))
68 ("xcolor" (same-as . "color"))
69 ("ulem" (section "uline" "uuline" "uwave")
70 (option ("normalem")))
71 ("multicol" (env "multicols"))
72 ("cleveref" (section "cref" "crefrange" "cpageref" "labelcref"
73 "labelpageref"))
74 ("wrapfig" (env "wrapfigure" "wraptable"))
75 ("setspace" (env "spacing") (section "setstretch"))
76 ("cases" (env "numcases" "subnumcases"))
77 ("subfigure" (section "subfigure"))
78 ("okumacro" (section "ruby" "kenten"))
79 )
80 "Default package vs. macro list.
81 Alists contains '(PACKAGENAME . MACROLIST)
82 PACKAGENAME Basename of package(String).
83 MACROLIST List of '(TYPE . MACROS)
84 TYPE One of 'env, 'section or 'maketitle according to completion-type
85 MACROS List of macros
87 If TYPE is 'option, its cdr is alist of completion candidates for that
88 package. Its cdr can be a symbol whose value is alist.
90 An good example is the value of YaTeX-package-alist-default.")
92 (defvar YaTeX-package-graphics-driver-alist
93 '(("dvips") ("dvipsnames") ("usenames")
94 ("xdvi") ("dvipdfmx") ("pdftex") ("dvipsone") ("dviwindo")
95 ("emtex") ("dviwin") ("oztex") ("textures") ("pctexps") ("pctexwin")
96 ("pctexhp") ("pctex32") ("truetex") ("tcidvi") ("vtex"))
97 "Drivers alist of graphics/color stylefile's supporting devices.
98 This list is taken from
99 %% graphics.dtx Copyright (C) 1994 David Carlisle Sebastian Rahtz
100 %% Copyright (C) 1995 1996 1997 1998 David Carlisle
101 as of 2004/1/19. Thanks.")
103 (defvar YaTeX-package-alist-private nil
104 "*User defined package vs. macro list. See also YaTeX-package-alist-default")
106 (defun YaTeX-package-lookup (macro &optional type)
107 "Look up a package which contains a definition of MACRO.
108 Optional second argument TYPE limits the macro type.
109 TYPE is a symbol, one of 'env, 'section, 'maketitle."
110 (let ((list (append YaTeX-package-alist-private YaTeX-package-alist-default))
111 origlist element x sameas val pkg pkglist r)
112 (setq origlist list)
113 (while list
114 (setq element (car list)
115 pkg (car element)
116 element (cdr element))
117 (if (setq sameas (assq 'same-as element)) ;non-recursive retrieval
118 (setq element (cdr (assoc (cdr sameas) origlist))))
119 (if (setq r (catch 'found
120 (while element
121 (setq x (car element)
122 val (cdr x))
123 (if (symbolp val) (setq val (symbol-value val)))
124 (and (or (null type)
125 (eq type (car x)))
126 (YaTeX-member macro val)
127 (throw 'found (car x))) ;car x is type
128 (setq element (cdr element)))))
129 (setq pkglist (cons (cons pkg r) pkglist)))
130 (setq list (cdr list)))
131 pkglist))
133 (defun YaTeX-package-option-lookup (pkg &optional key)
134 "Look up options for specified pkg and returne them in alist form.
135 Just only associng against the alist of YaTeX-package-alist-*"
136 (let*((list (append YaTeX-package-alist-private YaTeX-package-alist-default))
137 (l (cdr (assq (or key 'option) (assoc pkg list))))
138 (recur (cdr (assq 'same-as (assoc pkg list)))))
139 (cond
140 (recur (YaTeX-package-option-lookup recur key))
141 ((symbolp l) (symbol-value l))
142 (t l))))
144 (defvar YaTeX-package-resolved-list nil
145 "List of macros whose package is confirmed to be loaded.")
147 (defun YaTeX-package-auto-usepackage (macro type &optional autopkg autoopt)
148 "(Semi)Automatically add the \\usepackage line to main-file.
149 Search the usepackage for MACRO of the TYPE.
150 Optional second and third argument AUTOPKG, AUTOOPT are selected
151 without query. Thus those two argument (Full)automatically add
152 a \\usepackage line."
153 (let ((cb (current-buffer))
154 (wc (current-window-configuration))
155 (usepackage (concat YaTeX-ec "usepackage"))
156 (pkglist (YaTeX-package-lookup macro type))
157 (usepkgrx (concat
158 YaTeX-ec-regexp
159 "\\(usepackage\\|include\\|documentclass\\)\\b"))
160 (register (function
161 (lambda () (set-buffer cb)
162 (set (make-local-variable 'YaTeX-package-resolved-list)
163 (cons macro YaTeX-package-resolved-list)))))
164 (begdoc (concat YaTeX-ec "begin{document}"))
165 pb pkg optlist (option "") mb0 uspkgargs)
166 (if (or (YaTeX-member macro YaTeX-package-resolved-list)
167 (null pkglist))
168 nil ;nothing to do
169 ;; Search `usepackage' into main-file
170 (YaTeX-visit-main t) ;set buffer to parent file
171 (setq pb (current-buffer))
172 (save-excursion
173 (save-restriction
174 (if (catch 'found
175 (goto-char (point-min))
176 (YaTeX-search-active-forward ;if search fails, goto eob
177 begdoc YaTeX-comment-prefix nil 1)
178 (while (re-search-backward usepkgrx nil t)
179 ;;allow commented out \usepackages
180 (setq mb0 (match-beginning 0))
181 (skip-chars-forward "^{")
182 (setq uspkgargs (YaTeX-buffer-substring
183 (point)
184 (progn
185 ;;(forward-list 1) is more precise,
186 ;; but higher risk.
187 (skip-chars-forward "^}\n")(point))))
188 (let ((pl pkglist))
189 (while pl ;(car pl)'s car is package, cdr is type
190 (if (string-match
191 (concat "[{,]\\s *"
192 (regexp-quote (car (car pl)))
193 "\\>")
194 uspkgargs)
195 (throw 'found t))
196 (setq pl (cdr pl)))
197 (goto-char mb0))))
198 ;;corresponding \usepackage found
199 (funcall register)
200 ;; not found, insert it.
201 (if (or
202 autopkg
203 (y-or-n-p
204 (format "`%s' requires package. Put \\usepackage now?"
205 macro)))
206 (progn
207 (require 'yatexadd)
208 (setq pkg
209 (or autopkg
210 (completing-read
211 "Load which package?(TAB for list): "
212 pkglist nil nil
213 ;;initial input
214 (if (= (length pkglist) 1)
215 (let ((w (car (car pkglist))))
216 (if YaTeX-emacs-19 (cons w 0) w)))))
217 optlist
218 (YaTeX-package-option-lookup pkg))
219 (if optlist
220 (let ((minibuffer-completion-table optlist)
221 (delim ",") (w (car (car optlist)))
222 (dflt (YaTeX-package-option-lookup
223 pkg 'default-option)))
224 (setq option
225 (or
226 autoopt
227 (read-from-minibuffer
228 (format "Any option for {%s}?: " pkg)
229 (let ((v (or dflt
230 (and (= (length optlist) 1) w))))
231 (and v (if YaTeX-emacs-19 (cons v 0) v)))
232 YaTeX-minibuffer-completion-map))
233 option (if (string< "" option)
234 (concat "[" option "]")
235 ""))))
236 (set-buffer pb)
237 (goto-char (point-min))
238 (if (YaTeX-re-search-active-forward
239 (concat YaTeX-ec-regexp
240 "document\\(style\\|class\\){")
241 YaTeX-comment-prefix nil t)
242 (forward-line 1))
243 (if (YaTeX-search-active-forward
244 begdoc YaTeX-comment-prefix nil t)
245 (goto-char (match-beginning 0)))
246 (insert
247 usepackage
248 (format "%s{%s}\t%% required for `\\%s' (yatex added)\n"
249 option pkg macro))
250 (funcall register))
251 (funcall register)
252 (message "Don't forget to put \\usepackage{%s} yourself later"
253 (car (car pkglist)))) ;doing car car is negligence...
254 ))))))
256 (defvar YaTeX::usepackage-alist-private nil
257 "*Private completion list of the argument for usepackage")
259 (defvar YaTeX::usepackage-alist-local nil
260 "Directory local completion list of the argument for usepackage")
262 (defun YaTeX::usepackage (&optional argp)
263 (cond
264 ((equal argp 1)
265 (setq YaTeX-env-name "document")
266 (let ((minibuffer-local-completion-map YaTeX-minibuffer-completion-map)
267 (delim ","))
268 (YaTeX-cplread-with-learning
269 (if YaTeX-japan "Use package(カンマで区切ってOK): "
270 "Use package(delimitable by comma): ")
271 ;; 'YaTeX::usepackage-alist-default ;; OBSOLETED at 1.82
272 'YaTeX-package-alist-default
273 'YaTeX::usepackage-alist-private
274 'YaTeX::usepackage-alist-local)))))
277 ;;;
278 ;; Add-ins for auxiliary package handled here
279 ;;;
280 (defun YaTeX:floatingfigure ()
281 (concat (YaTeX:read-position "rlpv")
282 (YaTeX:read-length "Width: ")))
284 (defvar YaTeX:geometry-default "margin=1.5cm,includeheadfoot,includemp"
285 "*Default options for \\geometry{}")
286 (defun YaTeX::geometry (argp)
287 "Add-in for \\geometry's option"
288 ;; cf. https://dayinthelife.at.webry.info/201401/article_2.html
289 (cond
290 ((= argp 1)
291 (YaTeX-help "geometry")
292 (message "Change default by setting YaTeX:geometry-default")
293 (if (string= YaTeX:geometry-default "") ""
294 YaTeX:geometry-default))))
296 (provide 'yatexpkg)