I am using org mode to build teaching presentations (through beamer export) and I have a global document containing all the slides I use. Each slide has a tag to indicate the corresponding teaching session. For example (file sample.org) :
* My document
*** Item 1 :s1:
- First slide of session 1
*** Item 2 :s2:
- First slide of session 2
*** Item 3 :s1:
- Second slide of session 1
I want to build per session presentations i.e. to build a specific export file for a given set of tags (in the example, a file s1.pdf for tag s1 and another one s2.pdf for tag s2). I currently use the following code block to to this:
#+BEGIN_SRC emacs-lisp :results none
(let ((org-export-select-tags '("s1")) (async nil) (subtreep nil) (visible-only nil) (body-only nil) (ext-plist '())) (org-beamer-export-to-pdf async subtreep visible-only body-only ext-plist))
(cond ((file-exists-p "s1.pdf") (delete-file "s1.pdf")))
(rename-file "sample.pdf" "s1.pdf")
(let ((org-export-select-tags '("s2")) (async nil) (subtreep nil) (visible-only nil) (body-only nil) (ext-plist '())) (org-beamer-export-to-pdf async subtreep visible-only body-only ext-plist))
(cond ((file-exists-p "s2.pdf") (delete-file "s2.pdf")))
(rename-file "sample.pdf" "s2.pdf")
#+END_SRC
I would like to know if it is possible to launch org-beamer-export-to-pdf
directly with a target file name (to avoid the delete/rename instructions) and also if it could be possible to launch the exports in parallel.
EDIT:
As suggested by @Nick in his comment, I wrote a function to simplify the code and make it easier to read/use:
(defun export (tagname)
"Export to a file named tagname.pdf all the headlines tagged with tagname"
(let ((org-export-select-tags (list tagname)) (async nil) (subtreep nil) (visible-only nil) (body-only nil) (ext-plist '()))
(org-beamer-export-to-pdf async subtreep visible-only body-only ext-plist)
)
(cond ((file-exists-p (concat tagname ".pdf")) (delete-file (concat tagname ".pdf"))))
(rename-file "sample.pdf" (concat tagname ".pdf"))
)
(export "s1")
(export "s2")
However the problem for the asynchronous call is that all exports build a single file called sample.pdf
and this makes it necessary to make the exports successively. I was wondering if there is a way to give directly a target file name to the exporter to make asynchronous call possible.
EDIT2:
Following the recommendations of Nick, I now do not have to use the intermediate sample.pdf file:
(defun export2 (tagname)
"Export to a file named tagname.pdf all the headlines tagged with tagname"
(let ((org-export-select-tags (list tagname)) (async nil) (subtreep nil) (visible-only nil) (body-only nil) (ext-plist '()))
(org-export-to-file 'beamer (concat tagname ".tex") async subtreep visible-only body-only ext-plist (lambda (file) (org-latex-compile file))))
)
(export2 "s1")
(export2 "s2")
(let ...) (cond ...) (rename-file ...)
in a function and then call it with arguments"s1"
and"s2"
. And maybe settingasync
tot
in thelet
will do them in parallel: you just do each call in a loop. – NickD Oct 6 '17 at 8:44(org-export-to-file 'beamer file ...)
- see the source fororg-beamer-export-to-pdf
to see how to use it. – NickD Oct 6 '17 at 9:17