]> code.delx.au - gnu-emacs-elpa/blob - packages/auctex-11.86/style/graphicx.el
(debbugs-emacs): New function and modes for listing the Emacs bugs, reading them...
[gnu-emacs-elpa] / packages / auctex-11.86 / style / graphicx.el
1 ;;; graphicx.el --- AUCTeX style file for graphicx.sty
2
3 ;; Copyright (C) 2000, 2004, 2005 by Free Software Foundation, Inc.
4
5 ;; Author: Ryuichi Arafune <arafune@debian.org>
6 ;; Created: 1999/3/20
7 ;; Keywords: tex
8
9 ;; This file is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 3, or (at your option)
12 ;; any later version.
13
14 ;; This file is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
21 ;; the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
23
24 ;;; Commentary:
25
26 ;; This package supports the includegraphcics macro in graphicx style.
27
28 ;; Acknowledgements
29 ;; Dr. Thomas Baumann <thomas.baumann@ch.tum.de>
30 ;; David Kastrup <David.Kastrup@t-online.de>
31 ;; Masayuki Akata <ataka@milk.freemail.ne.jp>
32
33 ;;; Code:
34
35 (TeX-add-style-hook
36 "graphicx"
37 (lambda ()
38 (TeX-add-symbols
39 '("reflectbox" "Argument")
40 '("resizebox" "Width" "Height" "Argument")
41 '("resizebox*" "Width" "Total height" "Argument")
42 '("rotatebox" [ "Options" ] "Angle" "Argument")
43 '("scalebox" "Horizontal scale" [ "Vertical scale" ] "Argument")
44 '("includegraphics" LaTeX-arg-includegraphics))
45 ;; Fontification
46 (when (and (featurep 'font-latex)
47 (eq TeX-install-font-lock 'font-latex-setup))
48 (font-latex-add-keywords '(("reflectbox" "{")
49 ("resizebox" "*{{{")
50 ("rotatebox" "[{{")
51 ("scalebox" "{[{"))
52 'textual)
53 (font-latex-add-keywords '(("includegraphics" "*[[{")) 'reference))))
54
55 (defun LaTeX-includegraphics-extensions (&optional list)
56 "Return appropriate extensions for input files to \\includegraphics."
57 ;; FIXME: This function may check for latex/pdflatex later.
58 (concat "\\."
59 (mapconcat 'identity
60 (or list LaTeX-includegraphics-extensions)
61 "$\\|\\.")
62 "$"))
63
64 (defun LaTeX-includegraphics-read-file-TeX ()
65 "Read image file for \\includegraphics.
66 Offers all graphic files found in the TeX search path. See
67 `LaTeX-includegraphics-read-file' for more."
68 ;; Drop latex/pdflatex differences for now. Might be (re-)included later.
69 (completing-read
70 "Image file: "
71 (TeX-delete-dups-by-car
72 (mapcar 'list
73 (TeX-search-files nil LaTeX-includegraphics-extensions t t)))
74 nil nil nil))
75
76 (defun LaTeX-includegraphics-read-file-relative ()
77 "Read image file for \\includegraphics.
78
79 Lists all graphic files in the master directory and its
80 subdirectories and inserts the relative file name. This option
81 doesn't works with Emacs 21.3 or XEmacs. See
82 `LaTeX-includegraphics-read-file' for more."
83 (file-relative-name
84 (read-file-name
85 "Image file: " nil nil nil nil
86 ;; FIXME: Emacs 21.3 and XEmacs 21.4.15 dont have PREDICATE as the sixth
87 ;; argument (Emacs 21.3: five args; XEmacs 21.4.15: sixth is HISTORY).
88 (lambda (fname)
89 (or (file-directory-p fname)
90 (string-match (LaTeX-includegraphics-extensions) fname))))
91 (TeX-master-directory)))
92
93 (defun LaTeX-arg-includegraphics (prefix)
94 "Ask for mandantory and optional arguments for the \\includegraphics command.
95
96 The extent of the optional arguments is determined by the prefix argument and
97 `LaTeX-includegraphics-options-alist'."
98 (let* ((maybe-left-brace "[")
99 (maybe-comma "")
100 show-hint
101 (image-file (funcall LaTeX-includegraphics-read-file))
102 (incl-opts
103 (cond
104 ((numberp
105 (if (listp current-prefix-arg)
106 (setq current-prefix-arg (car current-prefix-arg))
107 current-prefix-arg))
108 (cdr
109 (assq current-prefix-arg LaTeX-includegraphics-options-alist)))
110 ;; If no prefix is given, use `0' and tell the user about the
111 ;; prefix.
112 ((eq current-prefix-arg nil)
113 (setq show-hint t)
114 (cdr (assq 0 LaTeX-includegraphics-options-alist)))
115 (t
116 (cdr (assq 0 LaTeX-includegraphics-options-alist)))))
117 ;; Order the optional aruments like in the tables in epslatex.ps,
118 ;; page 14. But collect y-or-n options at the end, so that the use
119 ;; can skip some options by typing `RET RET ... RET n n n ... n'
120 ;;
121 ;; Options from Table 1 (epslatex.ps, page 14):
122 (totalheight
123 (TeX-arg-maybe
124 'totalheight incl-opts
125 '(read-string
126 (concat "Total Height (" TeX-default-unit-for-image "): "))))
127 (height
128 (TeX-arg-maybe
129 'height incl-opts
130 ;; Either totalheight or height make sense:
131 '(when (zerop (length totalheight))
132 (read-string
133 (concat "Figure height (" TeX-default-unit-for-image "): ")))))
134 (width
135 (TeX-arg-maybe
136 'width incl-opts
137 '(read-string
138 (concat "Figure width (" TeX-default-unit-for-image "): "))))
139 (scale
140 (TeX-arg-maybe
141 'angle incl-opts
142 ;; If size is already specified, don't ask for scale:
143 '(when (zerop (+ (length totalheight)
144 (length height)
145 (length width)))
146 (read-string "Scale: "))))
147 (angle
148 (TeX-arg-maybe
149 'angle incl-opts
150 '(read-string "Rotation angle: ")))
151 (origin
152 (TeX-arg-maybe
153 'origin incl-opts
154 '(read-string
155 (concat
156 "Origin (any combination of `lcr' (horizontal) "
157 "and `tcbB' (vertical)): "))))
158 (page ;; Not in any table; Only for PDF.
159 (TeX-arg-maybe
160 'page incl-opts
161 '(read-string "Page: ")))
162 (bb
163 (TeX-arg-maybe
164 'bb incl-opts
165 '(y-or-n-p "Set Bounding Box? ")))
166 ;; Table 2:
167 (viewport
168 (TeX-arg-maybe
169 'viewport incl-opts
170 '(y-or-n-p "Set viewport? ")))
171 (trim
172 (TeX-arg-maybe
173 'trim incl-opts
174 '(and (not viewport)
175 (y-or-n-p "Set trim? "))))
176 ;; Table 3:
177 (clip
178 (TeX-arg-maybe
179 'clip incl-opts
180 ;; If viewport, we also use clip.
181 '(or viewport
182 (y-or-n-p "Clipping figure? "))))
183 (keepaspectratio
184 (TeX-arg-maybe
185 'keepaspectratio incl-opts
186 ;; If we have width and [total]height...
187 '(or (and (not (zerop (length width)))
188 (or (not (zerop (length totalheight)))
189 (not (zerop (length height)))))
190 (y-or-n-p "Keep Aspectratio? "))))
191 ;; Used for bb, trim, viewport, ...:
192 llx lly urx ury)
193 ;; Now insert stuff...
194 (when (not (zerop (length totalheight)))
195 (insert
196 maybe-left-brace maybe-comma "totalheight="
197 (car (TeX-string-divide-number-unit totalheight))
198 (if (zerop
199 (length
200 (car (cdr (TeX-string-divide-number-unit totalheight)))))
201 TeX-default-unit-for-image
202 (car (cdr (TeX-string-divide-number-unit totalheight)))))
203 (setq maybe-comma ",")
204 (setq maybe-left-brace ""))
205 (when (not (zerop (length height)))
206 (insert maybe-left-brace maybe-comma
207 "height=" (car (TeX-string-divide-number-unit height))
208 (if (zerop
209 (length
210 (car (cdr (TeX-string-divide-number-unit height)))))
211 TeX-default-unit-for-image
212 (car (cdr (TeX-string-divide-number-unit height)))))
213 (setq maybe-comma ",")
214 (setq maybe-left-brace ""))
215 (when (not (zerop (length width)))
216 (insert maybe-left-brace maybe-comma
217 "width=" (car (TeX-string-divide-number-unit width))
218 (if (zerop
219 (length
220 (car (cdr (TeX-string-divide-number-unit width)))))
221 TeX-default-unit-for-image
222 (car (cdr (TeX-string-divide-number-unit width)))))
223 (setq maybe-comma ",")
224 (setq maybe-left-brace ""))
225 (when (not (zerop (length scale)))
226 (insert maybe-left-brace maybe-comma "scale=" scale)
227 (setq maybe-comma ",")
228 (setq maybe-left-brace ""))
229 (when (not (zerop (length angle)))
230 (insert maybe-left-brace maybe-comma "angle=" angle)
231 (setq maybe-comma ",")
232 (setq maybe-left-brace ""))
233 (when (not (zerop (length origin)))
234 (insert maybe-left-brace maybe-comma "origin=" origin)
235 (setq maybe-comma ",")
236 (setq maybe-left-brace ""))
237 (when bb
238 (setq llx (read-string "Bounding Box lower left x: "))
239 (setq lly (read-string "Bounding Box lower left y: "))
240 (setq urx (read-string "Bounding Box upper right x: "))
241 (setq ury (read-string "Bounding Box upper right y: "))
242 (insert maybe-left-brace maybe-comma
243 "bb=" llx " " lly " " urx " " ury)
244 (setq maybe-comma ",")
245 (setq maybe-left-brace ""))
246 ;;
247 (when viewport
248 (setq llx (read-string "Viewport lower left x: "))
249 (setq lly (read-string "Viewport lower left y: "))
250 (setq urx (read-string "Viewport upper right x: "))
251 (setq ury (read-string "Viewport upper right y: "))
252 (insert maybe-left-brace maybe-comma
253 "viewport=" llx " " lly " " urx " " ury)
254 (setq maybe-comma ",")
255 (setq maybe-left-brace ""))
256 (when trim
257 (setq llx (read-string "Trim lower left x: "))
258 (setq lly (read-string "Trim lower left y: "))
259 (setq urx (read-string "Trim Upper right x: "))
260 (setq ury (read-string "Trim Upper right y: "))
261 (insert maybe-left-brace maybe-comma
262 "trim=" llx " " lly " " urx " " ury)
263 (setq maybe-comma ",")
264 (setq maybe-left-brace ""))
265 ;;
266 (when clip
267 (insert maybe-left-brace maybe-comma "clip")
268 (setq maybe-comma ",")
269 (setq maybe-left-brace ""))
270 (when keepaspectratio
271 (insert maybe-left-brace maybe-comma "keepaspectratio")
272 (setq maybe-comma ",")
273 (setq maybe-left-brace ""))
274 ;;
275 (when (not (zerop (length page)))
276 (insert maybe-left-brace maybe-comma "page=" page)
277 (setq maybe-comma ",")
278 (setq maybe-left-brace ""))
279 ;;
280 (if (zerop (length maybe-left-brace))
281 (insert "]"))
282 (TeX-insert-braces 0)
283 (insert
284 (if LaTeX-includegraphics-strip-extension-flag
285 ;; We don't have `replace-regexp-in-string' in all (X)Emacs versions:
286 (with-temp-buffer
287 (insert image-file)
288 (goto-char (point-max))
289 (when (search-backward-regexp (LaTeX-includegraphics-extensions)
290 nil t 1)
291 (replace-match ""))
292 (buffer-string))
293 image-file))
294 (when show-hint
295 (message
296 (concat
297 "Adding `C-u C-u' before the command asks for more optional arguments."
298 "\nSee `LaTeX-includegraphics-options-alist' for details."))
299 (sit-for 3))
300 t))
301
302 ;;; graphicx.el ends here