1 ;;; graphicx.el --- AUCTeX style file for graphicx.sty
3 ;; Copyright (C) 2000, 2004, 2005 by Free Software Foundation, Inc.
5 ;; Author: Ryuichi Arafune <arafune@debian.org>
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)
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.
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.
26 ;; This package supports the includegraphcics macro in graphicx style.
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>
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))
46 (when (and (featurep 'font-latex)
47 (eq TeX-install-font-lock 'font-latex-setup))
48 (font-latex-add-keywords '(("reflectbox" "{")
53 (font-latex-add-keywords '(("includegraphics" "*[[{")) 'reference))))
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.
60 (or list LaTeX-includegraphics-extensions)
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.
71 (TeX-delete-dups-by-car
73 (TeX-search-files nil LaTeX-includegraphics-extensions t t)))
76 (defun LaTeX-includegraphics-read-file-relative ()
77 "Read image file for \\includegraphics.
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."
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).
89 (or (file-directory-p fname)
90 (string-match (LaTeX-includegraphics-extensions) fname))))
91 (TeX-master-directory)))
93 (defun LaTeX-arg-includegraphics (prefix)
94 "Ask for mandantory and optional arguments for the \\includegraphics command.
96 The extent of the optional arguments is determined by the prefix argument and
97 `LaTeX-includegraphics-options-alist'."
98 (let* ((maybe-left-brace "[")
101 (image-file (funcall LaTeX-includegraphics-read-file))
105 (if (listp current-prefix-arg)
106 (setq current-prefix-arg (car current-prefix-arg))
109 (assq current-prefix-arg LaTeX-includegraphics-options-alist)))
110 ;; If no prefix is given, use `0' and tell the user about the
112 ((eq current-prefix-arg nil)
114 (cdr (assq 0 LaTeX-includegraphics-options-alist)))
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'
121 ;; Options from Table 1 (epslatex.ps, page 14):
124 'totalheight incl-opts
126 (concat "Total Height (" TeX-default-unit-for-image "): "))))
130 ;; Either totalheight or height make sense:
131 '(when (zerop (length totalheight))
133 (concat "Figure height (" TeX-default-unit-for-image "): ")))))
138 (concat "Figure width (" TeX-default-unit-for-image "): "))))
142 ;; If size is already specified, don't ask for scale:
143 '(when (zerop (+ (length totalheight)
146 (read-string "Scale: "))))
150 '(read-string "Rotation angle: ")))
156 "Origin (any combination of `lcr' (horizontal) "
157 "and `tcbB' (vertical)): "))))
158 (page ;; Not in any table; Only for PDF.
161 '(read-string "Page: ")))
165 '(y-or-n-p "Set Bounding Box? ")))
170 '(y-or-n-p "Set viewport? ")))
175 (y-or-n-p "Set trim? "))))
180 ;; If viewport, we also use clip.
182 (y-or-n-p "Clipping figure? "))))
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, ...:
193 ;; Now insert stuff...
194 (when (not (zerop (length totalheight)))
196 maybe-left-brace maybe-comma "totalheight="
197 (car (TeX-string-divide-number-unit totalheight))
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))
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))
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 ""))
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 ""))
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 ""))
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 ""))
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 ""))
275 (when (not (zerop (length page)))
276 (insert maybe-left-brace maybe-comma "page=" page)
277 (setq maybe-comma ",")
278 (setq maybe-left-brace ""))
280 (if (zerop (length maybe-left-brace))
282 (TeX-insert-braces 0)
284 (if LaTeX-includegraphics-strip-extension-flag
285 ;; We don't have `replace-regexp-in-string' in all (X)Emacs versions:
288 (goto-char (point-max))
289 (when (search-backward-regexp (LaTeX-includegraphics-extensions)
297 "Adding `C-u C-u' before the command asks for more optional arguments."
298 "\nSee `LaTeX-includegraphics-options-alist' for details."))
302 ;;; graphicx.el ends here