19

I would like to manage the tangling my org files with a Makefile. Though I can not find any information of how to tangle files from the command line.

1 Answer 1

20

You can use something like:

emacs --batch --eval "(require 'org)" --eval '(org-babel-tangle-file "file-to-tangle.org")'

(That shell quoting is meant for Bash, adjust if you use a different shell.)

EDIT: Thanks to @SkydiveMike for pointing out I had mistakenly written org-babel-tangle instead of org-babel-tangle-file.

8
  • 1
    I tried it and received a Wrong type argument: stringp, nil error message, any suggestion of what I am possibly doing wrong?
    – lookyhooky
    Sep 17, 2016 at 1:06
  • 1
    I also need the -L flag to add the current directory to the load path, and -l file-to-tangle.org to load the file before attempting to tangle it.
    – lookyhooky
    Sep 17, 2016 at 1:14
  • 8
    emacs --batch -l org foo.org -f org-babel-tangle or emacs --batch -l org --eval '(org-babel-tangle-file "foo.org")' works for me.
    – xuchunyang
    Sep 17, 2016 at 7:28
  • 1
    For a Bash script, this is useful: emacs --batch -l org --eval "(org-babel-tangle-file \"$1\")" Jul 21, 2017 at 20:48
  • 1
    For completeness, the solution by xuchunyang works (as compared to the original) because it has org-babel-tangle-file (which accepts a FILE argument) as compared to org-babel-tangle which works on the current buffer. Dec 26, 2019 at 0:47

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.