Suppose I do helm-do-grep or helm-do-ag on my tex-files, I can select a file on the results list and get a preview in another buffer by pressing tab. Is there a way (by pressing another key, not by redefining tab), to preview the corresponding pdf-file (if available) instead?

Another idea would be to define a variant of 'helm-follow-mode' say 'helm-tex-pdf-follow-mode' which previews the compiled pdf of the corresponding tex file if existend.

You may say that I could use pdfgrep, but with grep on the source files, I can for example find files containing specific comments (for example tags), not contained in the pdf-file or you can better search for math formulas.


Here is an example where you can use C-c C-c to bring up the pdf file in evince pdf viewer:

(defun my-custom-grep-cmd ()
  (let* ((candidate      (helm-get-selection))
         (split          (helm-grep-split-line candidate))         
         (lineno         (string-to-number (nth 1 split)))
         (full-name      (substring-no-properties (car split)))
         (pdf-file       (concat (file-name-sans-extension full-name) ".pdf")))
    (start-process "viewpdf" nil "setsid" "/usr/bin/evince" pdf-file)))

(define-key helm-grep-map (kbd "C-c C-c") 'my-custom-grep-cmd)

I tested this on Ubuntu 16.04 using Emacs 25.1 and helm-do-grep-ag.

  • Thanks a lot. Is it also possible to get something like helm-follow-mode for this? I.e. activating this pdf-follow-mode and then previewing the pdf-files in emacs using pdf-tools just like in helm-follow-mode?
    – student
    Nov 20 '16 at 19:24

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.