I use org-babel-tangle
to generate lilypond and latex documents from org files.
These org files have the following first line:
#+PROPERTY: header-args :LANG :comments org :tangle PATH/FILE_NAME.EXT
Where
- LANG is either latex or lilypond
- PATH is a specific (each time different) path
- FILE_NAME is a specific (each time different) file name
- EXT is either tex or ly
At first, I was compiling the generated .ly/.tex to pdf from the terminal. But then I started putting a function on each org file to generate and open PDFs. Here is the function for tex documents:
(defun mda/tex-pdf ()
"Produce a Xelatex PDF from an org file containing tex blocks."
(interactive)
(org-babel-tangle)
(cd "PATH")
(shell-command "xelatex -interaction=nonstopmode NAME_FILE.tex")
(shell-command "evince NAME_FILE.pdf"))
I can add easily this function with skeleton, but I have to change PATH once and NAME_FILE twice each time.
I there a way to automatically pick up PATH, and NAME_FILE from the first line? This way I could move the 2 functions to my config file.
EDIT:
It appears that the use case description wasn't precise enough.
So in this use case, every source block in the Org mode file uses the same language and the same :tangle
path spec (which is specified once, in #+PROPERTY: header-args :...
). So that all the tangled blocks end up in the exact same file.
org-babel-get-src-block-info
to get at the header args.org-babel-get-src-block-info
is very useful indeed. However, I can't find how to make it work when called from a function evaluated outside of the tangled buffer (see my edit for more details).