1

I use many org files with figures generated by source code blocks.

By example, in an org mode file long/path/document.org I have:

#+BEGIN_SRC dot :file my_fig.png  :exports results
digraph {
  A->B
  B->C
  C->A
}
#+END_SRC

However, to keep a clean directory/files hierarchy I want store the generated figures (or data) in a subdirectory associated to each org mode document, for instance: long/path/document-extra/my_fig.png.

#+BEGIN_SRC dot :file long/path/document-extra/my_fig.png  :exports results
digraph {
  A->B
  B->C
  C->A
}
#+END_SRC

Doing that manually is tedious, how to automate this?

1 Answer 1

3

I define functions at the end of my org mode file (thanks Local variables)

#+BEGIN_SRC dot :file (fig_name "my_fig") :exports results
digraph {
  A->B
  B->C
  C->A
}
#+END_SRC

...

# end of my org mode file

# Local Variables:
# eval: (defun fig_name(name) (concat (file-name-sans-extension (buffer-file-name)) "-extra/" name ".png"))
# End:

The function (fig_name "my_fig") automatically creates the right filename, something like:

: /home/XXX/GitLab/YYY/Bibliography/jiang11_rankin_hodge_theor-notes-extra/my_fig.png

As defined we assumed that the directory long/path/document-extra/ exists, but this can be also checked and eventually created in the fig_name function.

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.