yatex

annotate yatexpkg.el @ 566:2ef9f21dd13b

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