branch: elpa commit 50b63b0329d598121d69546838af1632d87f8f23 Author: Arash Esbati <arash.esb...@gmail.com> Commit: Arash Esbati <arash.esb...@gmail.com>
Improve style/graphicx.el * doc/changes.texi: Document the changes about graphicx.el. * tex-style.el (LaTeX-includegraphics-options-alist): Remove the now no-op variable. * style/graphics.el ("graphics"): Set `LaTeX-graphics-package-options' after running hooks for graphicx.el. * style/graphicx.el (LaTeX-graphicx-key-val-options) (LaTeX-includegraphics-dvips-extensions) (LaTeX-includegraphics-pdftex-extensions) (LaTeX-includegraphics-xetex-extensions) (LaTeX-graphicx-package-options): New variables. (LaTeX-arg-graphicx-includegraphics-key-val): New function. (LaTeX-includegraphics-extensions): Return extensions for input files depending on the used engine. (LaTeX-arg-includegraphics): Only query for the image file to include. The query for the optional key-val argument is now done by `LaTeX-arg-graphicx-includegraphics-key-val'. ("graphicx"): Extend the query for commands \resizebox[*]. Commands shared with graphics.el are guarded respectively. Add missing commands \graphicspath, \DeclareGraphicsExtensions and \DeclareGraphicsRule. --- doc/changes.texi | 11 ++ style/graphics.el | 3 +- style/graphicx.el | 428 +++++++++++++++++++++++++---------------------------- tex-style.el | 42 ------ 4 files changed, 216 insertions(+), 268 deletions(-) diff --git a/doc/changes.texi b/doc/changes.texi index a14ff2e..16f96be 100644 --- a/doc/changes.texi +++ b/doc/changes.texi @@ -12,6 +12,17 @@ @itemize @bullet @item +The style @file{graphicx.el} went through a bigger overhaul. The +optional argument of command @samp{\includegraphics} now supports +key-val query; keys can independently be chosen anytime by pressing the +@key{,} key. As a side effect, the variable +@code{LaTeX-includegraphics-options-alist} is now no-op and is removed +from @file{tex-style.el}. You can safely remove any customization of it +from your init file. The mandatory argument of @samp{\includegraphics} +knows about image file extensions supported by the used engine and +offers them for inclusion. + +@item @AUCTeX{} has a new Ispell dictionary @file{tex-ispell.el} for macros and environments which will be skipped during spell checking. The activiation of this feature is controlled by a new customize option diff --git a/style/graphics.el b/style/graphics.el index ffe5bd1..a48e612 100644 --- a/style/graphics.el +++ b/style/graphics.el @@ -5,7 +5,8 @@ (TeX-add-style-hook "graphics" (function (lambda () - (TeX-run-style-hooks "graphicx"))) + (TeX-run-style-hooks "graphicx") + (setq LaTeX-graphics-package-options LaTeX-graphicx-package-options))) LaTeX-dialect) ;;; graphics.el ends here. diff --git a/style/graphicx.el b/style/graphicx.el index a894dad..f7e1230 100644 --- a/style/graphicx.el +++ b/style/graphicx.el @@ -1,6 +1,6 @@ ;;; graphicx.el --- AUCTeX style file for graphicx.sty -;; Copyright (C) 2000, 2004, 2005, 2014 by Free Software Foundation, Inc. +;; Copyright (C) 2000, 2004, 2005, 2014, 2016 by Free Software Foundation, Inc. ;; Author: Ryuichi Arafune <araf...@debian.org> ;; Created: 1999/3/20 @@ -32,41 +32,123 @@ ;;; Code: -(TeX-add-style-hook - "graphicx" - (lambda () - (TeX-add-symbols - '("reflectbox" "Argument") - '("resizebox" "Width" "Height" "Argument") - '("resizebox*" "Width" "Total height" "Argument") - '("rotatebox" [ "Options" ] "Angle" "Argument") - '("scalebox" "Horizontal scale" [ "Vertical scale" ] "Argument") - '("includegraphics" LaTeX-arg-includegraphics)) - ;; Fontification - (when (and (featurep 'font-latex) - (eq TeX-install-font-lock 'font-latex-setup)) - (font-latex-add-keywords '(("reflectbox" "{") - ("resizebox" "*{{{") - ("rotatebox" "[{{") - ("scalebox" "{[{")) - 'textual) - (font-latex-add-keywords '(("includegraphics" "*[[{")) 'reference))) - LaTeX-dialect) +(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. +If OPTIONAL is non-nil, insert argument in square brackets. +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 (while +`TeX-PDF-from-DVI' is set to nil) 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 + (if (and (or (and (eq TeX-engine 'default) + (not (TeX-PDF-from-DVI))) + (eq TeX-engine 'luatex)) + TeX-PDF-mode) + (append '(("page")) LaTeX-graphicx-key-val-options) + LaTeX-graphicx-key-val-options)) + optional))) (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 (;; 'default TeX-engine: + (if (and (eq TeX-engine 'default) + ;; we want to produce a pdf + (if TeX-PDF-mode + ;; Return t if default compiler produces PDF, + ;; nil for "Dvips" or "Dvipdfmx" + (not (TeX-PDF-from-DVI)) + ;; t if pdftex is used in dvi-mode + TeX-DVI-via-PDFTeX)) + ;; We're using pdflatex in pdf-mode + (delete-dups + (append LaTeX-includegraphics-pdftex-extensions + LaTeX-includegraphics-extensions)) + ;; We're generating a .dvi to process with dvips or dvipdfmx + (progn + (dolist (x '("jpe?g" "pdf" "png")) + (setq temp (remove x temp))) + (delete-dups + (append LaTeX-includegraphics-dvips-extensions + temp))))) + ;; Running luatex in pdf or dvi-mode: + ((eq TeX-engine 'luatex) + (if TeX-PDF-mode + (delete-dups + (append LaTeX-includegraphics-pdftex-extensions + LaTeX-includegraphics-extensions)) + (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. Offers all graphic files found in the TeX search path. See `LaTeX-includegraphics-read-file' for more." - ;; Drop latex/pdflatex differences for now. Might be (re-)included later. (completing-read "Image file: " (TeX-delete-dups-by-car @@ -88,198 +170,12 @@ 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) - "Ask for mandantory and optional arguments for the \\includegraphics command. - -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 "]")) + "Ask for mandantory argument for the \\includegraphics command." + (let* ((image-file (funcall LaTeX-includegraphics-read-file))) (TeX-insert-braces 0) (insert (if LaTeX-includegraphics-strip-extension-flag @@ -291,13 +187,95 @@ 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)))) + +(TeX-add-style-hook + "graphicx" + (lambda () + (TeX-add-symbols + '("reflectbox" "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-conditional (member "graphics" (TeX-style-list)) + () + ([ TeX-arg-key-val (("x") ("y") ("origin") ("units")) ])) + "Angle" "Argument") + + '("scalebox" "Horizontal scale" [ "Vertical scale" ] "Argument") + + '("includegraphics" (TeX-arg-conditional (member "graphics" (TeX-style-list)) + (["llx,lly"] ["urx,ury"]) + ([ LaTeX-arg-graphicx-includegraphics-key-val ])) + LaTeX-arg-includegraphics) + + '("includegraphics*" (TeX-arg-conditional (member "graphics" (TeX-style-list)) + (["llx,lly"] ["urx,ury"]) + ([ LaTeX-arg-graphicx-includegraphics-key-val ])) + LaTeX-arg-includegraphics) + + '("graphicspath" t) + + '("DeclareGraphicsExtensions" t) + + '("DeclareGraphicsRule" 4)) + + ;; Fontification + (when (and (featurep 'font-latex) + (eq TeX-install-font-lock 'font-latex-setup)) + (font-latex-add-keywords '(("reflectbox" "{") + ("resizebox" "*{{{") + ("rotatebox" "[{{") + ("scalebox" "{[{")) + 'textual) + (font-latex-add-keywords '(("includegraphics" "*[[{")) + 'reference) + (font-latex-add-keywords '(("graphicspath" "{") + ("DeclareGraphicsExtensions" "{") + ("DeclareGraphicsRule" "{{{{")) + 'function))) + LaTeX-dialect) + +(defvar LaTeX-graphicx-package-options + '("draft" "final" "debugshow" + "hiderotate" "hidescale" "hiresbb" + "setpagesize" "nosetpagesize" "demo" + "dvips" "xdvi" + "dvipdf" "dvipdfm" "dvipdfmx" + "xetex" "pdftex" "luatex" + "dvisvgm" "dvipsone" "dviwindo" + "emtex" "dviwin" "oztex" + "textures" "pctexps" "pctexwin" + "pctexhp" "pctex32" "truetex" + "tcidvi" "vtex") + "Package options for the graphicx package.") ;;; graphicx.el ends here diff --git a/tex-style.el b/tex-style.el index d25bccc..b6e2e4d 100644 --- a/tex-style.el +++ b/tex-style.el @@ -312,48 +312,6 @@ automatically get the list of fonts. This requires :tag "Other" (string)))) -(defcustom LaTeX-includegraphics-options-alist - '((0 width) - ;; (1 width height clip) - ;; (2 width height keepaspectratio clip) - (4) ;; --> (4 nil) - (5 trim) - (16 - ;; Table 1 in epslatex.ps: ``includegraphics Options'' - height totalheight width scale angle origin bb - ;; Table 2 in epslatex.ps: ``cropping Options'' - viewport trim - ;; Table 3 in epslatex.ps: ``Boolean Options'' - ;; [not implemented:] noclip draft final - clip keepaspectratio - ;; Only for PDF: - page)) - "Controls for which optional arguments of \\includegraphics you get prompted. - -An alist, consisting of \(NUMBER . LIST\) pairs. Valid elements of LIST are -`width', `height', `keepaspectratio', `clip', `angle', `totalheight', `trim' -and `bb' \(Bounding Box\). - -The list corresponding to 0 is used if no prefix is given. Note that 4 \(one -\\[universal-argument]\) and 16 \(two \\[universal-argument]'s\) are easy to -type and should be used for frequently needed combinations." - :group 'LaTeX-style - :type '(repeat (cons (integer :tag "Argument") - (list (set :inline t - (const height) - (const totalheight) - (const width) - (const scale) - (const angle) - (const origin) - (const :tag "Bounding Box" bb) - ;; - (const viewport) - (const trim) - ;; - (const clip) - (const keepaspectratio)))))) - (defcustom LaTeX-includegraphics-strip-extension-flag t "Non-nil means to strip known extensions from image file name." :group 'LaTeX-style