7

If I insert an image into a latex file (via \includegraphics) auctex lets me select the file and inserts the filename.

However using this dialogue, I can only choose the filename and cannot see previews of images as in file chooser dialogues of usual GUI programs.

How can I get this in emacs too? I.e. have image thumbnail previews when selecting an image for my tex file.

Edit I just discovered icicles mode which generates thumbnails for find-file. However it doesn't seem to work with auctex and completion in \includegraphics out of the box.

student
  • 1,007
  • 9
  • 29
  • If you use [`helm`](https://emacs-helm.github.io/helm/) and set `LaTeX-includegraphics-read-file` to `LaTeX-includegraphics-read-file-relative` you'll have previews. Let me know if this satisfies you and I'll write an answer. – giordano Jul 15 '15 at 11:45
  • I don't know how to set it up so I didn't try it, but it sounds as it would satisfiy my needs (if it is not too slow and if the thumbnails are not too small) – student Jul 15 '15 at 18:32

1 Answers1

10

If you set LaTeX-includegraphics-read-file to LaTeX-includegraphics-read-file-relative, autocompletion with helm provides this feature:

enter image description here


Setting up AUCTeX

You can either customize LaTeX-includegraphics-read-file (M-x customize-variable RET LaTeX-includegraphics-read-file RET) and select the relative option or add the following to your init file:

(setq LaTeX-includegraphics-read-file 'LaTeX-includegraphics-read-file-relative)

Installing and setting up helm

You can install helm from Melpa repository, here are the instructions on how to add it. When you're done, issue M-x list-packages RET, go to the helm entry and hit i x.

Now you need to setup helm. Here is a good starting tutorial. You can choose between a minimal configuration:

(require 'helm-config)
(helm-mode 1)

and an extended configuration:

(require 'helm)
(require 'helm-config)

;; The default "C-x c" is quite close to "C-x C-c", which quits Emacs.
;; Changed to "C-c h". Note: We must set "C-c h" globally, because we
;; cannot change `helm-command-prefix-key' once `helm-config' is loaded.
(global-set-key (kbd "C-c h") 'helm-command-prefix)
(global-unset-key (kbd "C-x c"))
(global-set-key (kbd "M-x") 'helm-M-x) ; This was not present in the suggested extended config

(define-key helm-map (kbd "<tab>") 'helm-execute-persistent-action) ; rebind tab to run persistent action
(define-key helm-map (kbd "C-i") 'helm-execute-persistent-action) ; make TAB works in terminal
(define-key helm-map (kbd "C-z")  'helm-select-action) ; list actions using C-z

(when (executable-find "curl")
  (setq helm-google-suggest-use-curl-p t))

(setq helm-split-window-in-side-p           t ; open helm buffer inside current window, not occupy whole other window
      helm-move-to-line-cycle-in-source     t ; move to end or beginning of source when reaching top or bottom of source.
      helm-ff-search-library-in-sexp        t ; search for library in `require' and `declare-function' sexp.
      helm-scroll-amount                    8 ; scroll 8 lines other window using M-<next>/M-<prior>
      helm-ff-file-name-history-use-recentf t)

(helm-mode 1)

Please, be aware of the differences between Emacs default completion and helm's one.


Start using the new feature

Restart Emacs and you'll be ready. In an LaTeX buffer, issue C-c RET includegraphics RET (note you can exploit helm autocompletion) and select the picture you want to include. In order to see the preview, as shown at the beginning, press twice the keybinding associated to helm-execute-persistent-action (C-z by default, or TAB in the above extended configuration) or move up and down in the file list with C-up and C-down (see this answer).

giordano
  • 3,245
  • 13
  • 19
  • Great answer, thanks a lot! The only annoying thing is that you have to press tab twice (and afterwards another shortcut to go back). Ideally the previews should show up just when the point is over the corresponding filename in the file list (so that you can just navigate up and down the file list and instantly see the corresponding previews without pressing any additional keys) – student Jul 16 '15 at 11:19
  • I think you should ask this a feature request to helm project, but I'm not sure it'll be implemented. – giordano Jul 17 '15 at 09:47
  • It seems be helm `helm-follow` mode what is needed. Just press `C-c C-f` when beeing in `helm-find-file` menu, then you can browse through your files with preview. However can I activate helm follow mode as default when entering the helm find file menu? I.E. that I don't need to press `C-c C-f`? – student Aug 01 '15 at 09:44
  • I'd suggest you to ask this as a new question `;-)` – giordano Aug 02 '15 at 08:29