# How to execute a org-babel source block within the working directory?

Say you have the following org-babel source block:

``````#+BEGIN_SRC latex :results raw :file test.pdf
\LaTeX
#+END_SRC
``````

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`)?

• 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 '19 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 '19 at 10:33

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
#+END_SRC

#+BEGIN_SRC latex :results raw :file test.pdf :dir ./workingdir
\input{inputfile}
\LaTeX
#+END_SRC
``````

Thanks to @Hubisan for the pointer!