Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make Org-mode open PDF files in Evince?

In Org-mode when I try to open a link to a PDF file nothing happens. Also, when I do C-c C-e d to export as LaTeX and process to PDF and open the PDF is generated but not opened. How do I make Org-mode open PDF files in Evince?

I am using Org-mode 7.6 in GNU Emacs 23.3.1 and Evince 3.2.1 in Ubuntu 11.10.

like image 207
N.N. Avatar asked Jan 12 '12 11:01

N.N.


2 Answers

M-x customize-variable [RET] org-file-apps [RET] 

If org uses your system defaults, you have to edit your ./mailcap file.

Try adding this line:

application/pdf; /usr/bin/evince %s 
like image 69
certainly Avatar answered Sep 28 '22 03:09

certainly


Another possible construct that could work for this would be to use eval-after-load rather than add-hook. It will only set the values once on startup, you won't have to worry about entries being added or not (unless you regularly reload org).

Combine that with setcdr and you can avoid having to delete from the list and then re-add, add if and you'll ensure that you either add or change the value. The if is only needed for values that aren't in the list by default, just to make sure you don't end up with conflicts somewhere down the line.

(eval-after-load "org"   '(progn      ;; .txt files aren't in the list initially, but in case that changes      ;; in a future version of org, use if to avoid errors      (if (assoc "\\.txt\\'" org-file-apps)          (setcdr (assoc "\\.txt\\'" org-file-apps) "notepad.exe %s")        (add-to-list 'org-file-apps '("\\.txt\\'" . "notepad.exe %s") t))      ;; Change .pdf association directly within the alist      (setcdr (assoc "\\.pdf\\'" org-file-apps) "evince %s"))) 

Edit for clarification

eval-after-load only evaluates the block when (require 'org) is called. If org is already loaded it will evaluate immediately (I mistakenly thought it ran each time a library was loaded, but it seems to be only the first time). The difference between add-hook and eval-after-load is explained here.

Since org-file-apps is a defcustom it won't change the values if you set them before org is loaded, if you build the list from scratch (including default values as in your second (uglier) solution) you could simply setq in your init.el and everything would work. It also means it won't overwrite your changes.

Adding (if (assoc to the PDF entry won't hurt anything, it will simply ensure that if PDFs are ever removed from the default org-file-apps that it will still be added. The only solution that would not fail if PDFs were removed is your second one. The others all assume the entry exists in one form or another.

like image 39
Jonathan Leech-Pepin Avatar answered Sep 28 '22 04:09

Jonathan Leech-Pepin