0

When exporting org to pdf (LaTeX) I want to export plots as pdf, while the preview inside emacs should be exported to png. I am currently using a function for generating the export path already. This function should be able to detect if exporting, and if so, change the file extension (as emacs can not display inline PDF).

I am using it like this:

#+begin_src gnuplot :file (org-babel-tmp-file)
...

where org-babel-tmp-file generates a file path using a uuid.

I am looking for something like (is-org-export-p).

3
  • I don't really understand your question. Can you show the "function for generating the export path already"? How and where is it to be used?
    – NickD
    Jun 30, 2022 at 15:02
  • 1
    Yes, I am using it like this: #+begin_src gnuplot :file (org-babel-tmp-file) where (org-babel-tmp-file) generates a file path using a uuid. Jun 30, 2022 at 20:01
  • I see - thank you!
    – NickD
    Jul 1, 2022 at 0:41

2 Answers 2

1

You can use the variable org-export-current-backend. It is set to the current backend during export, so you can check which backend is used as well. Read its doc string with C-h v org-export-current-backend:


Its value is a symbol such as ‘html’, ‘latex’, ‘ascii’, or nil if
the back-end is anonymous (see ‘org-export-create-backend’) or if
there is no export process in progress.

It can be used to teach Babel blocks how to act differently
according to the back-end used.

The last paragraph is particularly apt, given your question. Note that the value of the variable is a symbol, not a string.

EDIT: In this case, there was an existing variable, but @TianshuWang's answer would be useful if there was no existing variable and you wanted to pass information from the top-level export function down to the lower level.

1

I don't know whether there is a better way, you can advice org-export function and make a flag like:

(defun org-export@around (fun &rest r)
  (let ((org-export-p t))
    (apply fun r)))
(advice-add 'org-export :around #'org-export@around)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.