yatex

annotate yatexpkg.el @ 611:e87c3271b8fd

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