Hi Mosè, Mosè Giordano <[email protected]> writes:
> 2016-09-07 12:56 GMT+02:00 Arash Esbati <[email protected]>: >> Hi all, >> >> I would like to suggest a bigger change to graphicx.el in order to add >> real key-val query in the optional argument of \includegraphics. This >> style has a sort of pseudo key-val and I think it should be fixed. >> Please find attached a first draft for discussion. WDYT? > > 1 file changed, 86 insertions(+), 197 deletions(-) is very appealing > ;-) I've added some compensation for the deletions, see below ;-) > However, even if they were baked in a hackish way (they key-val list > is certainly easier to read and maintain), this patch is going to > remove some completion features for the optional argument of > \includegraphics, isn't it? Not really, all options are there, only the way one inserts the input is different. For instance, take the `bb' key: with the current implementation, AUCTeX asks for 4 values and insert them. With the new implementation, one does `bb=0 0 40 40' and hits `RET' if finished or `TAB' for another key. I think the major issue with the current implementation is you don't have a control on which key is coming next (well you have (cf. `LaTeX-includegraphics-options-alist'), but for me, I actually miss the key I want on a regular basis since I hit `RET' too often. >> I also have a question: How can I figure out which engine/binary is >> ultimaltely used when compiling a document? I would like to address the > > The relevant variables should be `TeX-engine', `TeX-PDF-mode', > `TeX-PDF-from-DVI', `TeX-DVI-via-PDFTeX'. Thank you, `TeX-engine', `TeX-PDF-mode' do the job, I think. Please find attached a new draft of graphicx.el. This incarnation has support for file extensions depending on the engine. From tex-style.el, only `LaTeX-includegraphics-options-alist' will become no-op; all other custom variables are preserved. Any comments welcome. Best, Arash
graphicx.el
Description: application/emacs-lisp
diff --git a/style/graphicx.el b/style/graphicx.el
index a894dad..c613556 100644
--- a/style/graphicx.el
+++ b/style/graphicx.el
@@ -32,16 +32,122 @@
;;; Code:
+(defvar LaTeX-graphicx-package-options
+ '("draft" "final" "debugshow"
+ "hiderotate" "hidescale" "hiresbb"
+ "setpagesize" "nosetpagesize" "demo" )
+ "Package options for the graphicx package.")
+
+(defvar LaTeX-graphicx-key-val-options
+ '(("bb")
+ ("bbllx")
+ ("bblly")
+ ("bburx")
+ ("bbury")
+ ("natheight")
+ ("natwidth")
+ ("viewport")
+ ("trim")
+ ("hiresbb" ("true" "false"))
+ ("angle")
+ ("origin")
+ ("width" ("\\textwidth" "\\columnwidth" "\\linewidth"))
+ ("height" ("\\textheight"))
+ ("totalheight" ("\\textheight"))
+ ("keepaspectratio" ("true" "false"))
+ ("scale")
+ ("clip" ("true" "false"))
+ ("draft" ("true" "false")))
+ "Key=value options for graphicx macros.")
+
+(defvar LaTeX-includegraphics-dvips-extensions
+ '("eps" "mps" "EPS")
+ "List of extensions for image files supported by \"dvips\".")
+
+(defvar LaTeX-includegraphics-pdftex-extensions
+ '("png" "pdf" "jpe?g" "jbig2" "jb2" "mps"
+ "PNG" "PDF" "JPE?G" "JBIG2" "JB2")
+ "List of extensions for image files supported by \"pdftex\" and \"luatex\".")
+
+(defvar LaTeX-includegraphics-xetex-extensions
+ '("pdf" "eps" "mps" "ps" "png" "jpe?g" "jp2" "jpf"
+ "PDF" "EPS" "MPS" "PS" "PNG" "JPE?G" "JP2" "JPF"
+ "bmp" "pict" "psd" "mac" "tga" "gif" "tif" "tiff"
+ "BMP" "PICT" "PSD" "MAC" "TGA" "GIF" "TIF" "TIFF")
+ "List of extensions for image files supported by \"xetex\".")
+
+(defun LaTeX-arg-graphicx-includegraphics-key-val (optional)
+ "Insert key-val for optional argument of \\includegraphics macro.
+Temporarily remove \"space\" from `crm-local-completion-map' and
+`minibuffer-local-completion-map' in order to be able to insert
+spaces conveniently.
+
+If `TeX-engine' is set to symbol 'default or 'luatex and
+`TeX-PDF-mode' is non-nil, add the key \"page\" to list of
+key-val's."
+ (let ((crm-local-completion-map
+ (remove (assoc 32 crm-local-completion-map)
+ crm-local-completion-map))
+ (minibuffer-local-completion-map
+ (remove (assoc 32 minibuffer-local-completion-map)
+ minibuffer-local-completion-map)))
+ (TeX-argument-insert
+ (TeX-read-key-val optional
+ (cond ((and (or (eq TeX-engine 'default)
+ (eq TeX-engine 'luatex))
+ TeX-PDF-mode)
+ (append '(("page"))
+ LaTeX-graphicx-key-val-options))
+ (t
+ LaTeX-graphicx-key-val-options)))
+ optional)))
+
(TeX-add-style-hook
"graphicx"
(lambda ()
(TeX-add-symbols
'("reflectbox" "Argument")
- '("resizebox" "Width" "Height" "Argument")
- '("resizebox*" "Width" "Total height" "Argument")
- '("rotatebox" [ "Options" ] "Angle" "Argument")
+
+ '("resizebox"
+ (TeX-arg-eval completing-read
+ (TeX-argument-prompt optional nil "Width")
+ (append '("\\width" "!")
+ (mapcar
+ (lambda (x) (concat TeX-esc (car x)))
+ (LaTeX-length-list))))
+ (TeX-arg-eval completing-read
+ (TeX-argument-prompt optional nil "Height")
+ (append '("\\height" "\\totalheight" "\\depth" "!")
+ (mapcar
+ (lambda (x) (concat TeX-esc (car x)))
+ (LaTeX-length-list))))
+ "Argument")
+
+ '("resizebox*"
+ (TeX-arg-eval completing-read
+ (TeX-argument-prompt optional nil "Width")
+ (append '("\\width" "!")
+ (mapcar
+ (lambda (x) (concat TeX-esc (car x)))
+ (LaTeX-length-list))))
+ (TeX-arg-eval completing-read
+ (TeX-argument-prompt optional nil "Height")
+ (append '("\\height" "\\totalheight" "\\depth" "!")
+ (mapcar
+ (lambda (x) (concat TeX-esc (car x)))
+ (LaTeX-length-list))))
+ "Argument")
+
+ '("rotatebox"
+ [ TeX-arg-key-val (("x") ("y") ("origin") ("units")) ]
+ "Angle" "Argument")
+
'("scalebox" "Horizontal scale" [ "Vertical scale" ] "Argument")
- '("includegraphics" LaTeX-arg-includegraphics))
+
+ '("includegraphics"
+ [ LaTeX-arg-graphicx-includegraphics-key-val ]
+ LaTeX-arg-includegraphics))
+
;; Fontification
(when (and (featurep 'font-latex)
(eq TeX-install-font-lock 'font-latex-setup))
@@ -56,11 +162,37 @@
(defun LaTeX-includegraphics-extensions (&optional list)
"Return appropriate extensions for input files to \\includegraphics."
;; FIXME: This function may check for latex/pdflatex later.
- (concat "\\."
- (mapconcat 'identity
- (or list LaTeX-includegraphics-extensions)
- "$\\|\\.")
- "$"))
+ (let* ((temp (copy-sequence LaTeX-includegraphics-extensions))
+ (LaTeX-includegraphics-extensions
+ (cond (;; Running pdflatex or luatex in pdf-mode:
+ (and (or (eq TeX-engine 'default)
+ (eq TeX-engine 'luatex))
+ TeX-PDF-mode)
+ (delete-dups
+ (append LaTeX-includegraphics-pdftex-extensions
+ (remove "eps" LaTeX-includegraphics-extensions))))
+ ;; Running pdflatex or luatex in dvi-mode:
+ ((and (or (eq TeX-engine 'default)
+ (eq TeX-engine 'luatex))
+ (not TeX-PDF-mode))
+ (progn
+ (dolist (x '("jpe?g" "pdf" "png"))
+ (setq temp (remove x temp)))
+ (delete-dups
+ (append LaTeX-includegraphics-dvips-extensions
+ temp))))
+ ;; Running xetex in any mode:
+ ((eq TeX-engine 'xetex)
+ (delete-dups (append LaTeX-includegraphics-xetex-extensions
+ LaTeX-includegraphics-extensions)))
+ ;; For anything else
+ (t
+ LaTeX-includegraphics-extensions))))
+ (concat "\\."
+ (mapconcat 'identity
+ (or list LaTeX-includegraphics-extensions)
+ "$\\|\\.")
+ "$")))
(defun LaTeX-includegraphics-read-file-TeX ()
"Read image file for \\includegraphics.
@@ -88,7 +220,7 @@ doesn't works with Emacs 21.3 or XEmacs. See
;; argument (Emacs 21.3: five args; XEmacs 21.4.15: sixth is HISTORY).
(lambda (fname)
(or (file-directory-p fname)
- (string-match (LaTeX-includegraphics-extensions) fname))))
+ (string-match (LaTeX-includegraphics-extensions) fname))))
(TeX-master-directory)))
(defun LaTeX-arg-includegraphics (_prefix)
@@ -96,190 +228,7 @@ doesn't works with Emacs 21.3 or XEmacs. See
The extent of the optional arguments is determined by the prefix argument and
`LaTeX-includegraphics-options-alist'."
- (let* ((maybe-left-brace "[")
- (maybe-comma "")
- show-hint
- (image-file (funcall LaTeX-includegraphics-read-file))
- (incl-opts
- (cond
- ((numberp
- (if (listp current-prefix-arg)
- (setq current-prefix-arg (car current-prefix-arg))
- current-prefix-arg))
- (cdr
- (assq current-prefix-arg LaTeX-includegraphics-options-alist)))
- ;; If no prefix is given, use `0' and tell the user about the
- ;; prefix.
- ((eq current-prefix-arg nil)
- (setq show-hint t)
- (cdr (assq 0 LaTeX-includegraphics-options-alist)))
- (t
- (cdr (assq 0 LaTeX-includegraphics-options-alist)))))
- ;; Order the optional aruments like in the tables in epslatex.ps,
- ;; page 14. But collect y-or-n options at the end, so that the use
- ;; can skip some options by typing `RET RET ... RET n n n ... n'
- ;;
- ;; Options from Table 1 (epslatex.ps, page 14):
- (totalheight
- (TeX-arg-maybe
- 'totalheight incl-opts
- '(TeX-read-string
- (concat "Total Height (" TeX-default-unit-for-image "): "))))
- (height
- (TeX-arg-maybe
- 'height incl-opts
- ;; Either totalheight or height make sense:
- '(when (zerop (length totalheight))
- (TeX-read-string
- (concat "Figure height (" TeX-default-unit-for-image "): ")))))
- (width
- (TeX-arg-maybe
- 'width incl-opts
- '(TeX-read-string
- (concat "Figure width (" TeX-default-unit-for-image "): "))))
- (scale
- (TeX-arg-maybe
- 'angle incl-opts
- ;; If size is already specified, don't ask for scale:
- '(when (zerop (+ (length totalheight)
- (length height)
- (length width)))
- (TeX-read-string "Scale: "))))
- (angle
- (TeX-arg-maybe
- 'angle incl-opts
- '(TeX-read-string "Rotation angle: ")))
- (origin
- (TeX-arg-maybe
- 'origin incl-opts
- '(TeX-read-string
- (concat
- "Origin (any combination of `lcr' (horizontal) "
- "and `tcbB' (vertical)): "))))
- (page ;; Not in any table; Only for PDF.
- (TeX-arg-maybe
- 'page incl-opts
- '(TeX-read-string "Page: ")))
- (bb
- (TeX-arg-maybe
- 'bb incl-opts
- '(y-or-n-p "Set Bounding Box? ")))
- ;; Table 2:
- (viewport
- (TeX-arg-maybe
- 'viewport incl-opts
- '(y-or-n-p "Set viewport? ")))
- (trim
- (TeX-arg-maybe
- 'trim incl-opts
- '(and (not viewport)
- (y-or-n-p "Set trim? "))))
- ;; Table 3:
- (clip
- (TeX-arg-maybe
- 'clip incl-opts
- ;; If viewport, we also use clip.
- '(or viewport
- (y-or-n-p "Clipping figure? "))))
- (keepaspectratio
- (TeX-arg-maybe
- 'keepaspectratio incl-opts
- ;; If we have width and [total]height...
- '(or (and (not (zerop (length width)))
- (or (not (zerop (length totalheight)))
- (not (zerop (length height)))))
- (y-or-n-p "Keep Aspectratio? "))))
- ;; Used for bb, trim, viewport, ...:
- llx lly urx ury)
- ;; Now insert stuff...
- (when (not (zerop (length totalheight)))
- (insert
- maybe-left-brace maybe-comma "totalheight="
- (car (TeX-string-divide-number-unit totalheight))
- (if (zerop
- (length
- (car (cdr (TeX-string-divide-number-unit totalheight)))))
- TeX-default-unit-for-image
- (car (cdr (TeX-string-divide-number-unit totalheight)))))
- (setq maybe-comma ",")
- (setq maybe-left-brace ""))
- (when (not (zerop (length height)))
- (insert maybe-left-brace maybe-comma
- "height=" (car (TeX-string-divide-number-unit height))
- (if (zerop
- (length
- (car (cdr (TeX-string-divide-number-unit height)))))
- TeX-default-unit-for-image
- (car (cdr (TeX-string-divide-number-unit height)))))
- (setq maybe-comma ",")
- (setq maybe-left-brace ""))
- (when (not (zerop (length width)))
- (insert maybe-left-brace maybe-comma
- "width=" (car (TeX-string-divide-number-unit width))
- (if (zerop
- (length
- (car (cdr (TeX-string-divide-number-unit width)))))
- TeX-default-unit-for-image
- (car (cdr (TeX-string-divide-number-unit width)))))
- (setq maybe-comma ",")
- (setq maybe-left-brace ""))
- (when (not (zerop (length scale)))
- (insert maybe-left-brace maybe-comma "scale=" scale)
- (setq maybe-comma ",")
- (setq maybe-left-brace ""))
- (when (not (zerop (length angle)))
- (insert maybe-left-brace maybe-comma "angle=" angle)
- (setq maybe-comma ",")
- (setq maybe-left-brace ""))
- (when (not (zerop (length origin)))
- (insert maybe-left-brace maybe-comma "origin=" origin)
- (setq maybe-comma ",")
- (setq maybe-left-brace ""))
- (when bb
- (setq llx (TeX-read-string "Bounding Box lower left x: "))
- (setq lly (TeX-read-string "Bounding Box lower left y: "))
- (setq urx (TeX-read-string "Bounding Box upper right x: "))
- (setq ury (TeX-read-string "Bounding Box upper right y: "))
- (insert maybe-left-brace maybe-comma
- "bb=" llx " " lly " " urx " " ury)
- (setq maybe-comma ",")
- (setq maybe-left-brace ""))
- ;;
- (when viewport
- (setq llx (TeX-read-string "Viewport lower left x: "))
- (setq lly (TeX-read-string "Viewport lower left y: "))
- (setq urx (TeX-read-string "Viewport upper right x: "))
- (setq ury (TeX-read-string "Viewport upper right y: "))
- (insert maybe-left-brace maybe-comma
- "viewport=" llx " " lly " " urx " " ury)
- (setq maybe-comma ",")
- (setq maybe-left-brace ""))
- (when trim
- (setq llx (TeX-read-string "Trim lower left x: "))
- (setq lly (TeX-read-string "Trim lower left y: "))
- (setq urx (TeX-read-string "Trim Upper right x: "))
- (setq ury (TeX-read-string "Trim Upper right y: "))
- (insert maybe-left-brace maybe-comma
- "trim=" llx " " lly " " urx " " ury)
- (setq maybe-comma ",")
- (setq maybe-left-brace ""))
- ;;
- (when clip
- (insert maybe-left-brace maybe-comma "clip")
- (setq maybe-comma ",")
- (setq maybe-left-brace ""))
- (when keepaspectratio
- (insert maybe-left-brace maybe-comma "keepaspectratio")
- (setq maybe-comma ",")
- (setq maybe-left-brace ""))
- ;;
- (when (not (zerop (length page)))
- (insert maybe-left-brace maybe-comma "page=" page)
- (setq maybe-comma ",")
- (setq maybe-left-brace ""))
- ;;
- (if (zerop (length maybe-left-brace))
- (insert "]"))
+ (let* ((image-file (funcall LaTeX-includegraphics-read-file)))
(TeX-insert-braces 0)
(insert
(if LaTeX-includegraphics-strip-extension-flag
@@ -291,13 +240,6 @@ The extent of the optional arguments is determined by the prefix argument and
nil t 1)
(replace-match ""))
(buffer-string))
- image-file))
- (when show-hint
- (message
- (concat
- "Adding `C-u C-u' before the command asks for more optional arguments."
- "\nSee `LaTeX-includegraphics-options-alist' for details."))
- (sit-for 3))
- t))
+ image-file))))
;;; graphicx.el ends here
_______________________________________________ auctex-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/auctex-devel
