1

Is there a way to specify org-macros that can be used in header arguments of org-babel? One application is to specify the figure path. For instance I want to define:

#+macro: folder figures_here

in the preamble, and then later,

#+begin_src R :results graphics :file {{{folder}}}/figure1.svg

and so on. This does not seem to work - is there another way such a macro can be specified, or specifically for designating the output directory there is a better way?

2

The expansion of org-macros in source block header arguments is not built into org-mode. See that related SO question.

But, you can add it with the following Elisp snippet.

(defun my-org-babel-expand-macros (params)
  "Replace org macros in all header argument values."
  (mapc
   (lambda (par)
     (let ((templates org-macro-templates)
           (val (cdr par)))
       (when (stringp val)
         (setcdr par 
                 (with-temp-buffer
                   (insert val)
                   (org-macro-replace-all templates)
                   (buffer-string))))))
   params))

(advice-add 'org-babel-process-params :filter-return #'my-org-babel-expand-macros)

Your Answer

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

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