Search code examples
elisporg-mode

Tangle file when exporting


I want to call org-babel-tangle every time an export is executed.

I've tried (without success) just add the new command to org-latex-pdf-process or using an export filter (org-export-filter-final-output-functions).

first attempt:

(add-to-list 'org-export-filter-final-output-functions 'org-babel-tangle)

second attempt:

(add-to-list 'org-latex-pdf-process 'org-babel-tangle)

It seems that org-babel-tangle cannot be used as it is, maybe it is returning something that is not expected by add-to-list. However, my limited knowledge of elisp does not allow me to identify what is wrong.

Thanks for your attention


Solution

  • You can add it (or actually a small wrapper function around it) to org-export-before-processing-hook. I have not tested this but it should work:

    (add-to-list 'org-export-before-processing-hook (lambda (be) (org-babel-tangle)))
    

    The functions called by this hook are passed a single argument, the backend, but we ignore it in this case.