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.

Blaz
  • 3,548
  • 5
  • 26
  • 40

1 Answers1

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.

abo-abo
  • 20,038
  • 3
  • 50
  • 71
  • 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. – Blaz Aug 17 '13 at 17:18
  • 1
    You must use an older version of Org. Upgrade to 8. – fniessen Aug 17 '13 at 18:43
  • 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) – fniessen Aug 18 '13 at 06:54
  • 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. – abo-abo Aug 18 '13 at 08:19
  • 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. – fniessen Aug 18 '13 at 09:01