Search code examples
osx-mountain-lionorg-modeemacs24auctex

Emacs' org-mode: how to automatically "process to PDF" on save?


Org-mode's C-cep does export as LaTeX and process to PDF. How can C-cep be executed on each C-xs?

Also, in all likelihood this probably isn't the optimal solution, so feel free to propose something better. As it is now, I have to do both C-cep and C-xs.

Final solution

A tiny modification of abo-abo's answer below that doesn't open the PDF, lets Skim pick up any change, and thus keeps the focus on Emacs.

(defun org-export-as-pdf ()
  (interactive)
  (save-buffer)
  (org-latex-export-to-pdf))

(add-hook 
 'org-mode-hook
 (lambda()
   (define-key org-mode-map 
       (kbd "<f5>") 'org-export-as-pdf)))

Also, one should upgrade Org to version 8 from a fresh Emacs session: that is, no Org-command should be executed prior to installing with the package-manager. Otherwise you'll hit the Invalid function: org-with-silent-modifications bug.


Solution

  • You can use this:

    (defun org-export-as-pdf-and-open ()
      (interactive)
      (save-buffer)
      (org-open-file (org-latex-export-to-pdf)))
    
    (add-hook 
     'org-mode-hook
     (lambda()
       (define-key org-mode-map 
           (kbd "<f5>") 'org-export-as-pdf-and-open)))
    

    UPD

    This requires org-mode 8.0.0 and up. It's easily installed with list-packages.