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?

1 Answer 1


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."
   (lambda (par)
     (let ((templates org-macro-templates)
           (val (cdr par)))
       (when (stringp val)
         (setcdr par 
                   (insert val)
                   (org-macro-replace-all templates)

(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 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.