2

According to the org-mode manual (emphasis added by me):

The tags that exclude a tree from export (org-export-exclude-tags). The default value is :noexport:. Entries with the :noexport: tag will be unconditionally excluded from the export, even if they have an :export: tag. Code blocks contained in excluded subtrees will still be executed during export even though the subtree is not exported.

However, I have an org mode document featuring python code blocks for which code blocks in :noexport: headings does not execute on export:

* Setup Code             :noexport:
Here's some general text!
#+BEGIN_SRC ipython :session :exports none :tangle ./politics.py
  %matplotlib inline
  import matplotlib.pyplot as plt
  # . . .
  # . . .
#+END_SRC

* Introduction
. . .

When I export, it throws python throws NameError: name 'plt' not defined. Clearly org isn't executing blocks in these :noexport: headings on export. It does work when I remove the :noexport: tag. Am I missing something, or is this an error in the documentation?

I'm using org 8.2.10

2 Answers 2

2

New features around Org 8.2.10 mean that code evaluates on export even if it isn't exported into the document. Evaluating and exporting into the exported document are not the same. You'll need to add :eval no-export to the babel header block.

2
  • I think you misinterpreted the question, yet still gave me the correct answer (I want the code to not export, but to be evaluated). It might be that :noexport: blocks are not to be evaluated in org <= 8.2.10. Upgrading now.
    – Dodgie
    Jan 6, 2017 at 23:07
  • Fixed with upgrade to org-9 via (add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t) (use-package org :mode (("\\.org$" . org-mode)) :ensure org-plus-contrib)
    – Dodgie
    Jan 7, 2017 at 6:12
0

I fixed my issue by upgrading to org version 9 + contrib files. Uninstall org (package-list-packages, find org, press d to mark for deletion, then press x to delete), add the following code to init.el (before any piece of code that loads org), then restart emacs (if you don't have use-package, install it).

(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
(use-package org
  :mode (("\\.org$" . org-mode))
  :ensure org-plus-contrib)

Use org-version to confirm upgrade.

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.