yatex

view yatexpkg.el @ 569:e3209b30680c

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