Mercurial > hgrepos > hgweb.cgi > yatex
annotate yatexpkg.el @ 270:1b4e0acd0106 dev
Include newpage.rb.
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Thu, 10 May 2012 11:10:13 +0900 |
parents | cf7352dfa40c |
children | 5921f28ef77c |
rev | line source |
---|---|
78 | 1 ;;; -*- Emacs-Lisp -*- |
2 ;;; YaTeX package manager | |
3 ;;; yatexpkg.el | |
195 | 4 ;;; (c)2003-2012 by HIROSE, Yuuji [yuuji@yatex.org] |
5 ;;; Last modified Mon Jan 9 20:13:53 2012 on firestorm | |
78 | 6 ;;; $Id$ |
7 | |
80 | 8 (defvar YaTeX-package-ams-envs |
9 (mapcar 'car YaTeX-ams-env-table)) | |
10 | |
78 | 11 (defvar YaTeX-package-alist-default |
193 | 12 '(("version" (env "comment") ;by tsuchiya<at>pine.kuee.kyoto-u.ac.jp |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
13 (section "includeversion" "excludeversion")) |
78 | 14 |
193 | 15 ("plext" (section "bou")) ;by yas.axis<at>ma.mni.ne.jp |
78 | 16 |
193 | 17 ("url" (section "url")) ;by fujieda<at>jaist.ac.jp |
78 | 18 |
19 ("fancybox" (section "shadowbox" "doublebox" "ovalbox" "Ovalbox")) | |
80 | 20 ("slashbox" (section "slashbox" "backslashbox")) |
78 | 21 ("pifont" (section "ding")) |
22 ("longtable" (env "longtable")) | |
23 ("ascmac" (env "screen" "boxnote" "shadebox" "itembox") | |
24 (maketitle "return" "Return" "yen") | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
25 (section "keytop") ("mask") ("maskbox")) |
193 | 26 ("bm" (section "bm")) ;by aoyama<at>le.chiba-u.ac.jp |
78 | 27 |
28 ("alltt" (env "alltt")) | |
29 ("misc" (section "verbfile" "listing")) | |
80 | 30 ("eclbkbox" (env "breakbox")) |
31 ("supertabular" (env "supertabular")) | |
32 ("amsmath" (env . YaTeX-package-ams-envs) | |
33 (section "tag" "tag*")) | |
134 | 34 ("amssymb" (maketitle "leqq" "geqq" "mathbb" "mathfrak" |
144 | 35 "fallingdotseq" |
134 | 36 "lll" "ggg")) ;very few. Please tell us! |
80 | 37 ("graphicx" (section "includegraphics" |
38 "rotatebox" "scalebox" "resizebox" "reflectbox") | |
39 (option . YaTeX-package-graphics-driver-alist)) | |
40 ("color" (section "textcolor" "colorbox" "pagecolor" "color") | |
41 (option . YaTeX-package-graphics-driver-alist)) | |
42 ("ulem" (section "uline" "uuline" "uwave") | |
43 (option ("normalem"))) | |
44 ("multicol" (env "multicols"))) | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
45 "Default package vs. macro list. |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
46 Alists contains '(PACKAGENAME . MACROLIST) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
47 PACKAGENAME Basename of package(String). |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
48 MACROLIST List of '(TYPE . MACROS) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
49 TYPE One of 'env, 'section or 'maketitle according to completion-type |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
50 MACROS List of macros |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
51 |
80 | 52 If TYPE is 'option, its cdr is alist of completion candidates for that |
53 package. Its cdr can be a symbol whose value is alist. | |
54 | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
55 An good example is the value of YaTeX-package-alist-default.") |
78 | 56 |
80 | 57 (defvar YaTeX-package-graphics-driver-alist |
58 '(("dvips") ("xdvi") ("dvipdf") ("pdftex") ("dvipsone") ("dviwindo") | |
59 ("emtex") ("dviwin") ("oztex") ("textures") ("pctexps") ("pctexwin") | |
60 ("pctexhp") ("pctex32") ("truetex") ("tcidvi") ("vtex")) | |
61 "Drivers alist of graphics/color stylefile's supporting deveces. | |
62 This list is taken from | |
63 %% graphics.dtx Copyright (C) 1994 David Carlisle Sebastian Rahtz | |
64 %% Copyright (C) 1995 1996 1997 1998 David Carlisle | |
65 as of 2004/1/19. Thanks.") | |
66 | |
78 | 67 (defvar YaTeX-package-alist-private nil |
68 "*User defined package vs. macro list. See also YaTeX-package-alist-default") | |
69 | |
70 (defun YaTeX-package-lookup (macro &optional type) | |
71 "Look up a package which contains a definition of MACRO. | |
72 Optional second argument TYPE limits the macro type. | |
73 TYPE is a symbol, one of 'env, 'section, 'maketitle." | |
74 (let ((list (append YaTeX-package-alist-private YaTeX-package-alist-default)) | |
80 | 75 element x val pkg pkglist r) |
78 | 76 (while list |
77 (setq element (car list) | |
78 pkg (car element) | |
79 element (cdr element)) | |
80 (if (setq r (catch 'found | |
81 (while element | |
80 | 82 (setq x (car element) |
83 val (cdr x)) | |
84 (if (symbolp val) (setq val (symbol-value val))) | |
85 (and (or (null type) | |
78 | 86 (eq type (car x))) |
80 | 87 (YaTeX-member macro val) |
78 | 88 (throw 'found (car x))) ;car x is type |
89 (setq element (cdr element))))) | |
90 (setq pkglist (cons (cons pkg r) pkglist))) | |
91 (setq list (cdr list))) | |
92 pkglist)) | |
93 | |
80 | 94 (defun YaTeX-package-option-lookup (pkg) |
95 "Look up options for specified pkg and returne them in alist form. | |
96 Just only accocing against the alist of YaTeX-package-alist-*" | |
97 (let ((l (cdr (assq 'option | |
98 (assoc pkg (append YaTeX-package-alist-private | |
99 YaTeX-package-alist-default)))))) | |
100 (if (symbolp l) (symbol-value l) l))) | |
101 | |
78 | 102 (defvar YaTeX-package-resolved-list nil |
103 "List of macros whose package is confirmed to be loaded.") | |
104 | |
105 (defun YaTeX-package-auto-usepackage (macro type) | |
106 "(Semi)Automatically add the \\usepackage line to main-file. | |
107 Search the usepackage for MACRO of the TYPE." | |
108 (let ((cb (current-buffer)) | |
109 (wc (current-window-configuration)) | |
110 (usepackage (concat YaTeX-ec "usepackage")) | |
80 | 111 (pkglist (YaTeX-package-lookup macro type)) |
78 | 112 (usepkgrx (concat |
113 YaTeX-ec-regexp | |
114 "\\(usepackage\\|include\\)\\b")) | |
115 (register '(lambda () (set-buffer cb) | |
116 (set (make-local-variable 'YaTeX-package-resolved-list) | |
117 (cons macro YaTeX-package-resolved-list)))) | |
118 (begdoc (concat YaTeX-ec "begin{document}")) | |
80 | 119 pb pkg optlist (option "") mb0 uspkgargs) |
78 | 120 (if (or (YaTeX-member macro YaTeX-package-resolved-list) |
121 (null pkglist)) | |
122 nil ;nothing to do | |
123 ;; Search `usepackage' into main-file | |
124 (YaTeX-visit-main t) ;set buffer to parent file | |
125 (setq pb (current-buffer)) | |
126 (save-excursion | |
127 (save-restriction | |
128 (if (catch 'found | |
129 (goto-char (point-min)) | |
130 (YaTeX-search-active-forward ;if search fails, goto eob | |
131 begdoc YaTeX-comment-prefix nil 1) | |
80 | 132 (while ;(YaTeX-re-search-active-backward |
133 ;usepkgrx YaTeX-comment-prefix nil t) | |
134 ;;allow commented out \usepackages 2004/3/16 | |
135 (re-search-backward usepkgrx nil t) | |
78 | 136 (setq mb0 (match-beginning 0)) |
137 (skip-chars-forward "^{") | |
80 | 138 (setq uspkgargs (YaTeX-buffer-substring |
139 (point) | |
140 (progn | |
141 ;;(forward-list 1) is more precise, | |
142 ;; but higher risk. | |
143 (skip-chars-forward "^}\n")(point)))) | |
78 | 144 (let ((pl pkglist)) |
145 (while pl ;(car pl)'s car is package, cdr is type | |
80 | 146 (if (string-match |
147 (concat "[{,]\\s *" | |
148 (regexp-quote (car (car pl))) | |
149 "\\>") | |
150 uspkgargs) | |
78 | 151 (throw 'found t)) |
152 (setq pl (cdr pl))) | |
153 (goto-char mb0)))) | |
154 ;;corresponding \usepackage found | |
155 (funcall register) | |
156 ;; not found, insert it. | |
157 (if (y-or-n-p | |
158 (format "`%s' requires package. Put \\usepackage now?" macro)) | |
159 (progn | |
80 | 160 (require 'yatexadd) |
78 | 161 (setq pkg |
162 (completing-read | |
163 "Load which package?(TAB for list): " | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
164 pkglist nil nil |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
165 ;;initial input |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
166 (if (= (length pkglist) 1) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
78
diff
changeset
|
167 (let ((w (car (car pkglist)))) |
80 | 168 (if YaTeX-emacs-19 (cons w 0) w)))) |
169 optlist | |
170 (YaTeX-package-option-lookup pkg)) | |
171 (if optlist | |
172 (let ((minibuffer-completion-table optlist) | |
173 (delim ",") (w (car (car optlist)))) | |
174 (setq option | |
175 (read-from-minibuffer | |
176 (format "Any option for {%s}?: " pkg) | |
177 (if (= (length optlist) 1) | |
178 (if YaTeX-emacs-19 (cons w 0) w)) | |
179 YaTeX-minibuffer-completion-map) | |
180 option (if (string< "" option) | |
181 (concat "[" option "]") | |
182 "")))) | |
78 | 183 (set-buffer pb) |
184 (goto-char (point-min)) | |
185 (if (YaTeX-re-search-active-forward | |
186 (concat YaTeX-ec-regexp | |
187 "document\\(style\\|class\\){") | |
188 YaTeX-comment-prefix nil t) | |
189 (forward-line 1)) | |
190 (if (YaTeX-search-active-forward | |
191 begdoc YaTeX-comment-prefix nil t) | |
192 (goto-char (match-beginning 0))) | |
193 (insert | |
194 usepackage | |
80 | 195 (format "%s{%s}\t%% required for `\\%s' (yatex added)\n" |
196 option pkg macro)) | |
78 | 197 (funcall register)) |
120
8772bd5d1f02
Do not ask again when user answer n to usepackage addition.
yuuji@gentei.org
parents:
80
diff
changeset
|
198 (funcall register) |
78 | 199 (message "Don't forget to put \\usepackage{%s} yourself later" |
200 (car (car pkglist)))) ;doing car car is negligence... | |
201 )))))) |