yatex

view yatexpkg.el @ 615:f039d15cdba8

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