yatex

view yatexpkg.el @ 599:e73e41509124

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