# Export beamer handout or presentation function in org-mode?

I'd like to be able to call a function to export to pdf (via latex beamer) from an org subtree. Right now I have properties set up like so:

:PROPERTIES:
:EXPORT_LATEX_COMPILER: xelatex
:EXPORT_OPTIONS: H:2
:EXPORT_FILE_NAME: path/to/pdf
:EXPORT_LATEX_CLASS: beamer-presentation
:END:


I have two latex classes I've added to org-latex-classes -- "beamer-presentation", which allows notes and incremental lists, and "beamer-handout", which has no notes and collapses all incremental slides to single slides. Right now if I want to change to presentation or handout I change the :EXPORT_LATEX_CLASS: property to the relevant class. Everything works fine. However, I'd like to be able to do this from an elisp function I could just call to export the subtree, and without having the :EXPORT_LATEX_CLASS: property set manually. But I can't seem to find any way to do this. I would have thought the following would work:

(defun cpm/org-export-beamer-presentation ()
(interactive)
(progn
(setq org-latex-default-class "beamer-presentation")
(org-open-file (org-beamer-export-to-pdf nil t))))

(defun cpm/org-export-beamer-handout ()
(interactive)
(progn
(setq org-latex-default-class "beamer-handout")
(org-open-file (org-beamer-export-to-pdf nil t))))



However, in both cases the function simply export the subtree with the default (i.e. not either of my custom classes) beamer presentation class. Any tips on what to do here are appreciated (and I know that there is at least one other way to deal with this issue. But I'm curious why my approach fails. I am not adept with elisp, so that may be the explanation. Advice appreciated.

I've only done a quick read through some of ox-beamer.el, so take this with a large grain of salt.

In the definition of the beamer derived backend, in the options-alist, it says:

(:latex-class "LATEX_CLASS" nil "beamer" t)


I read this as: if there is a #+LATEX_CLASS keyword or an EXPORT_LATEX_CLASS property, then the value of the :latex-class option is whatever the value of the keyword or property is; otherwise, the value of the option is beamer - no other choice.

So trying to influence things by setting org-latex-default-class does nothing: ox-beamer does not even look at the value of that variable.

A possible way out is to call org-beamer-export-to-pdf and make sure to pass an ext-list argument to it:

;;(org-beamer-export-to-pdf &optional ASYNC SUBTREEP VISIBLE-ONLY BODY-ONLY EXT-PLIST)
(org-beamer-export-to-pdf nil t nil nil '(:latex-class "beamer-handout"))


I believe that will at least influence the course of action - and who knows? it might even work - but if it does, it will be a matter of (some) luck, since this is completely untested!

• Thanks very much! I had tried a version of this but for some reason it didn't work -- maybe I didn't properly quote it. ¯\_(ツ)_/¯ Jun 25, 2020 at 3:36
• You mean it actually worked? Miracles never cease :-) Jun 25, 2020 at 3:39
• This was a case where (excepting stackexchange) looking online for org info was completely unhelpful -- thanks again! Jun 25, 2020 at 3:40
• You are welcome! Jun 25, 2020 at 3:44