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 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 export portions (sub-trees) of an Org document, see Exporting.

The :exports header arguments control the export of code blocks (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
After each evaluation, results are inserted after the end of code block in the Org buffer. Previous results are either replaced (default) or appended to. On export, Org includes only the results and not the code block.
:exports both
Org includes both the code block and the results on export.
:exports none
Org does not include neither the code block nor the results on export.

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. To evaluate just the inline code blocks, set to inline-only. Isolating inline evaluations is not for security but for avoiding any delays due to recalculations during exports, 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).