This is the official manual for the latest Org-mode release.

Table of Contents

Next: , Previous: Editing source code, Up: Working with source code

14.3 Exporting code blocks

Org can flexibly export just the code from the code blocks, just the results of evaluation of the code block, both the code and the results of the code block evaluation, or none. Org defaults to exporting code for most languages. For some languages, such as ditaa, Org defaults to results. To export just the body of code blocks, see Literal examples. To selectively export sub-trees of an Org document, see Exporting.

The :exports header arguments control exporting code blocks only and not inline code:

Header arguments:
:exports code
This is the default for most languages where the body of the code block is exported. See Literal examples for more.
:exports results
On export, Org includes only the results and not the code block. After each evaluation, Org inserts the results after the end of code block in the Org buffer. By default, Org replaces any previous results. Org can also append results.
:exports both
Org exports both the code block and the results.
:exports none
Org does not export the code block nor the results.

To stop Org from evaluating code blocks during export, set org-export-babel-evaluate variable to nil.

Turning off evaluation comes in handy when batch processing. For example, markup languages for wikis, which have a high risk of untrusted code. Stopping code block evaluation also stops evaluation of all header arguments of the code block. This may not be desirable in some circumstances. So during export, to allow evaluation of just the header arguments but not any code evaluation in the source block, set :eval never-export (see eval).

To evaluate just the inline code blocks, set org-export-babel-evaluate to inline-only. Isolating the option to allow inline evaluations separate from ‘src’ code block evaluations during exports is not for security but for avoiding any delays due to recalculations, such as calls to a remote database.

Org never evaluates code blocks in commented sub-trees when exporting (see Comment lines). On the other hand, Org does evaluate code blocks in sub-trees excluded from export (see Export settings).