0

I tried to customize my .emacs file adding the options to the macro command \includegraphics.

I use Emacs 25.3.1 on MacOS.

My .emacsfile is as follows:

(package-initialize)
(custom-set-variables
'(custom-enabled-themes (quote (wombat)))
'(doc-view-continuous t))
(custom-set-faces
)

;; touche meta
(setq ns-alternate-modifier 'meta)
(setq ns-right-alternate-modifier 'none)
(setq mac-right-option-modifier 'none)

(setq mac-command-modifier 'meta
  mac-option-modifier 'none
  default-input-method "MacOSX")

;; alignement
(defun bjm/align-whitespace (start end)
"Align columns by whitespace"
(interactive "r")
(align-regexp start end
            "\\(\\s-*\\)\\s-" 1 0 t))

(defun bjm/align-& (start end)
"Align columns by ampersand"
(interactive "r")
(align-regexp start end
            "\\(\\s-*\\)&" 1 1 t))
(put 'upcase-region 'disabled nil)

;; customized hooks
(require 'tex-site)

(defun my-LaTeX-mode-hook ()
(TeX-add-style-hook
"essai_classe"
(lambda ()
 (TeX-run-style-hooks
  "latex2e"
  "beamer"
  "booktabs"
  "graphicx"
  "icone"
  "citation")
 LaTeX-dialect)))

(add-hook 'LaTeX-mode-hook 'my-LaTeX-mode-hook)

(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"))
("quiet")
("interpolate" ("true" "false")))
"Key=value options for graphicx macros.")

 (defun LaTeX-arg-graphicx-includegraphics-key-val (optional)
(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")
                 ("pagebox" ("mediabox"
                     "cropbox"
                     "bleedbox"
                     "trimbox"
                     "artbox")))
               LaTeX-graphicx-key-val-options)
         LaTeX-graphicx-key-val-options))
 optional)))

(defun LaTeX-includegraphics-extensions (&Optional list)
(let* ((temp (copy-sequence LaTeX-includegraphics-extensions))
 (LaTeX-includegraphics-extensions
  (cond (;; 'default TeX-engine:
     (eq TeX-engine 'default)
     (if ;; 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
         (TeX-delete-duplicate-strings
          (append LaTeX-includegraphics-pdftex-extensions
              temp))
       ;; We're generating a .dvi to process with dvips or dvipdfmx
       (progn
         (dolist (x '("jpe?g" "pdf" "png"))
           (setq temp (delete x temp)))
         (TeX-delete-duplicate-strings
          (append LaTeX-includegraphics-dvips-extensions
              temp)))))
    ;; Running luatex in pdf or dvi-mode:
    ((eq TeX-engine 'luatex)
     (if TeX-PDF-mode
         (TeX-delete-duplicate-strings
          (append LaTeX-includegraphics-pdftex-extensions
              temp))
       (progn
         (dolist (x '("jpe?g" "pdf" "png"))
           (setq temp (delete x temp)))
         (TeX-delete-duplicate-strings
          (append LaTeX-includegraphics-dvips-extensions
              temp)))))
    ;; Running xetex in any mode:
    ((eq TeX-engine 'xetex)
     (TeX-delete-duplicate-strings (append LaTeX-includegraphics-xetex-extensions
                  temp)))
    ;; For anything else
    (t
     temp))))
(concat "\\."
    (mapconcat 'identity
           (or list LaTeX-includegraphics-extensions)
           "$\\|\\.")
    "$")))


(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)

When I use the \includegraphicscommand, Emacs only suggest [llx, lly] and [urx, ury] options.

How can I do to make Emacs to ask for all the options

  • I guess the version information is faulty. The emacs major version is most probably some number between 24 and 27. I think you gave the version number of the operating system instead. Also I don't know of Max. Did you mean MacOS 10.9.5? – Tobias Jun 27 '18 at 8:28
  • Yes you're right, it's Emacs 25.3.1, and of course MacOS. I edited the typos in my initial post – Guillaume Jun 27 '18 at 11:12
  • Please edit your question to actually pose a question. Thx. – Drew Jun 27 '18 at 13:15
  • done, hope it's clearer – Guillaume Jun 27 '18 at 17:11
0

I presume you're using the latest AUCTeX version and installed it from ELPA. In this case, you can delete your entire AUCTeX configuration, incl. (require 'tex-site) since you don't need those lines.

AUCTeX provides style files which correspond to LaTeX packages, e.g. graphicx.el adds specific macro support for graphicx.sty. AUCTeX usually loads its style files on demand.

In your case, I think you are using a .cls or .sty called essai_classe which loads some LaTeX packages via \RequirePackage{<package>}. You can tell AUCTeX about <package> by:

  1. Customizing the variable TeX-style-private to a directory your choice.

  2. Creating a file called essai_classe.el in that directory looking like this:

    (TeX-add-style-hook
     "essai_classe"
     (lambda ()
       (TeX-run-style-hooks
        "latex2e"
        "beamer"
        "booktabs"
        "graphicx"
        "icone"
        "citation")
     LaTeX-dialect))
  1. Restarting Emacs and loading your .tex file. AUCTeX should now load graphicx.el and you should get the correct macro completion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.