4

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")
  • You can encapsulate the (let ...) (cond ...) (rename-file ...) in a function and then call it with arguments "s1" and "s2". And maybe setting async to t in the let will do them in parallel: you just do each call in a loop. – NickD Oct 6 '17 at 8:44
  • @Nick; thanks for your suggestion: I wrote a function as you suggest and it is improving the readability and use of the code. However, for the asynchronous call, the problem is that all exports build a single file called sample.pdf in mys example and this makes it necessary to make the exports successively. That is why I was wondering if there is a way to give directly a target file name to the exporter to make asynchronous call possible. – Lgen Oct 6 '17 at 9:11
  • I see - I should have read some more of your code. BTW, the progn in your function is unnecessary. For the async, you have to go one level down and use (org-export-to-file 'beamer file ...) - see the source for org-beamer-export-to-pdf to see how to use it. – NickD Oct 6 '17 at 9:17
  • @Nick: thanks again for your help. I removed the progn call in my function (I rediscover lisp programming...). I will explore the source code you suggest, it seems exactly what I need. – Lgen Oct 6 '17 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.