Tangling functionality is controlled by the tangle family of tangle header arguments. These arguments can be used to turn tangling on or off (the default), either for the code block or the Org-mode heading level.

The following code blocks demonstrate how to tangle them into a single source code file using org-babel-tangle .

The following two code blocks have no tangle header arguments and so will not, by themselves, create source code files. They are included in the source code file by the third code block, which does have a tangle header argument.

In the Org-mode file:

#+name: hello-world-prefix #+begin_src sh :exports none echo "/-----------------------------------------------------------\\" #+end_src

HTML export of code:

echo "/-----------------------------------------------------------\\"

In the Org-mode file

#+name: hello-world-postfix #+begin_src sh :exports none echo "\-----------------------------------------------------------/" #+end_src

HTML export of code:

echo "\-----------------------------------------------------------/"

The third code block does have a tangle header argument indicating the name of the file to which the tangled source code will be written. It also has Noweb style references to the two previous code blocks. These references will be expanded during tangling to include them in the output file as well.

In the Org-mode file:

#+name: hello-world #+begin_src sh :tangle hello :exports none :noweb yes <<hello-world-prefix>> echo "| hello world |" <<hello-world-postfix>> #+end_src

HTML export of code:

<<hello-world-prefix>> echo "| hello world |" <<hello-world-postfix>>

Calling org-babel-tangle will result in the following shell source code being written to the hello.sh file:

# !/usr/bin/ env sh # [[file:~/org/temp/index.org::*Noweb%20test][hello-world]] echo "/-----------------------------------------------------------\\" echo "| hello world |" echo "\-----------------------------------------------------------/" # hello-world ends here

In addition, the following syntax can be used to insert the results of evaluating a code block, in this case one named example-block .

# <<example-block()>>

Any optional arguments can be passed to example-block() by placing the arguments inside the parentheses following the convention defined when calling source block functions (see the Library of babel). For example,

# <<example-block(a=9)>>