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

1

6

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.

Veator answered 17/8, 2013 at 16:44 Comment(0)
A
3

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.

Amelina answered 17/8, 2013 at 16:53 Comment(5)
I'm using Skim which auto-refreshes the .pdf file, so (I think) org-export-as-pdf (without -and-open) would suffice. Still, I tried your solution verbatim and got the Symbol's function definition is void: org-latex-export-to-pdf error.Veator
You must use an older version of Org. Upgrade to 8.Hyperdulia
I would put your function in the after-save-hook, to answer the OP's question: (add-hook 'after-save-hook 'org-export-as-pdf-and-open)Hyperdulia
It's not very productive to export every org file on save. I'm sure that OP would find it very annoying. Saving and exporting and opening with one button is better IMO.Amelina
You were right with Org 7. Though, now, thanks to the asynchronous export (in Org 8), you're not blocked anymore when exporting to PDF.Hyperdulia

© 2022 - 2024 — McMap. All rights reserved.