I am trying out the literate programming features of org mode and loving it! I will be using the noweb syntax of double angle brackets <<...>> heavily.

I want the named block to be inserted into the place of the double-brackets as intended, when I tangle the file (obviously)

However, when I export to HTML, I don't want the named block to be expanded, and just make <<block-name>> show up instead. This is useful to hide housekeeping code, since that often distracts my reading while reading the documentation.

In brief, how do I prevent expansion of <> while exporting to HTML and allow it while tangling?


The header argument :noweb no-export (or another option, dpending on your need) will help you. See here for more information.

EDIT: As suggested by @Drew a small summary of the :noweb arguments. The table below shows with which argument the code block will be expanded before what action:

| :noweb argument| evaluate | tangle | export  |
| no             |          |        |         |
| yes            | yes      | yes    | yes     |
| tangle         |          | yes    |         |
| no-export      | yes      | yes    |         |
| strip-export   | yes      | yes    | removed |
| eval           | yes      |        |         |

Here a small example that shows how to apply the header argument to the source block:

* Example Use
#+begin_src sh :noweb-ref all
echo "all"

#+begin_src sh :noweb no-export :tangle example.sh
echo "more"

Please note that you have more options to set the header arguments. You can set them for example system wide or on a per file and subtree basis:

* Header arguments
** System wide
Set variable ~org-babel-default-header-args~:
#+BEGIN_SRC emacs-lisp
(setq org-babel-default-header-args '((:exports . "code")))
** Per file
#+property: header-args       :eval no
#+property: header-args:ditaa :eval yes

*** Per Subtree
    :header-args:    :cache yes
  • It would help to show how it helps you, instead of relying solely on the link. A summary.
    – Drew
    Jul 10 '16 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.