Say you have the following org-babel source block:

#+BEGIN_SRC latex :results raw :file test.pdf

When executing it, org-babel will do the actual compilation in a temporary directory and move the resulting PDF back to your working directory afterwards. The problem with this is that I cannot include my local LaTeX commands and configuration with \input{myMacros}, since it won't be found in the temporary directory.

How can I tell org-babel to execute a source block in the folder of the org-mode file (hence in the default-directory)?

  • 2
    Looks like the :dir header argument can probably be used for this, see orgmode.org/manual/dir.html and org-babel.readthedocs.io/en/latest/header-args/#dir Example: #+header: :dir (format "%s" default-directory) (Note: probably not working with just default-directory). If this works I will post as answer.
    – Hubisan
    Oct 15, 2019 at 8:05
  • @Hubisan Unfortunately, your proposal doesn't work here. Even when using :dir, the compilation still takes place in some temporary directory. Maybe this is a bug in org-mode 9.2.6?
    – Timm
    Oct 15, 2019 at 10:33

1 Answer 1


I've checked :dir again and it seems to work now (with org-mode v9.4). Here is a minimal example:

#+BEGIN_SRC latex :tangle ./workingdir/inputfile.tex
Content from input file

#+BEGIN_SRC latex :results raw :file test.pdf :dir ./workingdir

Thanks to @Hubisan for the pointer!

Your Answer

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

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