5

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?

Eric Anderson
  • 1,968
  • 2
  • 15
  • 19

2 Answers2

6

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.

fniessen
  • 4,408
  • 19
  • 18
  • 1
    The `:noweb yes` header was exactly my problem. I'd tried `:noweb tangle` and `:tangle yes`. Now that you point it out, the documentation at http://orgmode.org/manual/noweb.html#noweb is perfectly clear. – Eric Anderson Mar 19 '13 at 02:19
  • Excellent! BTW, on the 2nd point, dunno why this is badly written, but you should read <>, that is your function followed by open and closing parens, all between doubled angular brackets – fniessen Mar 19 '13 at 13:17
  • S.O. tried to turn into HTML, I believe. I edited your answer so it would show up, but the edit is waiting in some sort of review queue, I think, – Eric Anderson Mar 21 '13 at 20:07
2

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
Arne Babenhauserheide
  • 2,423
  • 29
  • 23