On Tue, 31 Jan 2017, Giacomo M wrote:

Dear all,

I was wondering what is the best way to include pdf images on latex export and png images on odt export (assuming same path, only extension changes). A macro like this one:
#+MACRO: figext @@latex:.pdf@@@@odt:.png@@
doesn't seem to work.


No, it won't work as Babel runs before the exporter handles the snippets.

Something like this should do.

Run this block or put the code in your init file:

#+BEGIN_SRC emacs-lisp
  (defun org-pdf-if-latex ()
    (if (eq (org-bound-and-true-p
            org-export-current-backend)
           'latex) "pdf" "png"))
#+END_SRC


This generates pdf for latex and png for all other backends (or no backend at all).

#+name: pdf-or-png
#+BEGIN_SRC R :exports both :results graphics :file-ext (org-pdf-if-latex)
plot(rnorm(50))
#+END_SRC

See (info "(org) file-ext")

HTH,

Chuck

Reply via email to