3

Is there a straightforward way to use a variable for the tangle file? For example, I want to tanlge my file into the directory files. For multiple files I could do

#+begin_src python :tangle files/fileA.py
some code
#+end_src

#+begin_src python :tangle files/fileB.py
some code
#+end_src

But that would mean repeating the file path every time. So ideally I would do something like

#+name: mydir
: files/

#+name: combine
#+begin_src python :var filename=""
return files+filename
#+end_src

#+begin_src python :tangle combine(fileA.py)
some code
#+end_src

#+begin_src python :tangle combine(fileB.py)
some code
#+end_src

But that doesn't work.

I tried using :dir instead but that doesn't work either, as it seems to apply to the execution directory, not the tangle directory.

I have found this post that shows how to use elisp variables but that requires the use of setq and doesn't seem like a good idea.

  • Why don't you use the solution of the post you found. Especially, the :header-args: :dir property should be a good choice for your case. – Tobias Dec 27 '15 at 19:40
  • Thanks for the comment. Maybe I'm misunderstanding something and the solution is plain simple. But :dir doesn't help since it only works on the output of the code block. Maybe I should rephrase my question to a more generic one: How do you evaluate any kind of variables outside of code blocks? So far I haven't been able to do that, neither for tangling, nor for using hyperlinks. – itsok-dontworry Dec 29 '15 at 21:59
  • you can always use setq-local – Łukasz Gruner Mar 13 '16 at 22:15
  • Are you trying to to tangle the 3 blocks into a single file? – Melioratus Sep 7 '16 at 14:55
  • No, I'm trying to tangle every source block into its own file. – itsok-dontworry Sep 7 '16 at 16:36

Your Answer

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

Browse other questions tagged or ask your own question.