I try to use emacs --batch in Makefile to tangle my .org files.

Here's my test org file (t.org)

* Another Header

  #+BEGIN_SRC emacs-lisp 
    (message "Hello")

* Header 1

  #+BEGIN_SRC emacs-lisp :tangle yes
    (provide 't)

I use this command to try to tangle it to lisp/t.el:

emacs -Q --batch --eval 'require (quote org))' --eval '(org-babel-tangle-file "t.org" "lisp/t.el" "emacs-lisp")'

Instead of get single file (lisp/t.el), I got 2 tangled files:

  1. t.el at current directory:

    (provide 't)

  2. lisp/t.el:

    (message "Hello")

Is that the expect behaviour? How could I tangle all the source blocks to single file (lisp/t.el)?

Emacs: (Built from source) Org-mode: 8.3.4 OS: Ubuntu 16.04

2 Answers 2


From org documentation:

:tangle no The default. The code block is not included in the tangled output.

:tangle yes Include the code block in the tangled output. The output file name is the name of the org file with the extension ‘.org’ replaced by the extension for the block language.

And from org-babel-tangle-file doc string (emphasis mine)

Optional argument TARGET-FILE can be used to specify a default export file for all source blocks.

So your second block having :tangle yes implicitly specify the filename to be used for this block.

Also, my understanding (and this is not exactly obvious) is that the file name provided to org-babel-tangle-file changes the default for the lack of a :tangle argument from :tangle no to :tangle filename with the provided filename.

To tangle all your blocks to the same file, simply remove the :tangle yes argument from the blocks that have it.


Is that the expect behavior?


How could I tangle all the source blocks to single file (lisp/t.el)?

Make all blocks consistent with :tangle yes or do not give the lisp/t.el optional target file in the batch mode. In short don't mix and match different tangle options for blocks in the same file and expect same output.

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.