2

I have the following code blocks:

Block 1 is just one line. This is a MWE. In reality, I have several lines in block 1.

#+name: block1
#+begin_src python :noweb no :exports none
print("Block 1")
#+end_src

Block 2 has also been reduced for the sake of MWE.

#+name: block2
#+begin_src python :noweb no :exports none
<<block1>>
print("Block 2")
#+end_src

This shows a skeleton of myfunc. I want to include this skeleton to give an overview of myfunc.

#+name: block3
#+begin_src python :noweb no :exports code
def myfunc(x):
    <<block2>>
#+end_src

Finally, this shows the full specification of myfunc.

#+begin_src python :noweb yes :exports code
<<block3>>
#+end_src

What I expect it to look like when exported

def myfunc(x):
    print("Block 1")
    print("Block 2")

What it actually looks like

def myfunc(x):
    <<block1>>
    print("Block 2")

How can I get the nested blocks to expand completely when I use :noweb yes?

1

Your example works if I set all headers with :noweb yes and then only the last block has :tangle yes.

A simpler example:

  1. Add this at the top of the file: #+PROPERTY: header-args :noweb yes :tangle no :exports code
  2. Remove all header args from the code blocks.
  3. Add :tangle yes header to the "full specification".
1
  • Thanks. I could make this work with a slight change to get whet I wanted -- I set all the headers to :noweb no-export. That way the blocks are not expanded in my exported pdf, but are expanded in the tangled code. (I realize now that my question did not clarify this well enough). – Vaibhav Karve Sep 6 '20 at 17:07

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.