Question

I'm trying to do something like this:

* Define some functions
#+begin_src python :noweb_ref defs
   def f1(a,b,c):
     return True
   def f2(d,e,f):
     return False
#+end_src

* Use them in a results-exported block later
#+begin_src python :results output :exports both :tangle yes
<<defs>>
print "test results:"
print f1(1,2,3)
#end_src

What I want to happen is for <<defs>> to be expanded tangle-style when the block is evaluated to produce the export output. What actually happens is that <<defs>> gets evaluated literally and causes a syntax error.

When tangling blocks like this to an output file, everything works perfectly, but I can't figure out how to do the same thing when I'm exporting the buffer.

Suggestions?

Was it helpful?

Solution

I'm not sure to really understand your point... but

1) you miss a noweb:yes header argument

2) you can use <<func()>> to insert the results of evaluating func (instead of the code of func) -- that's here that I'm not sure about what you really want.

OTHER TIPS

You can also use :noweb no-export. That shows the noweb-syntax in exported files but expands the code blocks when evaluating or tangling the files.

:noweb strip-export is great if you just want to show an algorithm:

<<prep>>
result = A + B
<<plot>>

The exported file then shows this:

result = A + B
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top