On Wed, 7 Dec 2016, David Dynerman wrote:
Dear Chuck,
Your suggestion worked fantastically - I got it working and am very excited.
Now, the next step is figuring out how to handle typesetting math in single way
between org and python docstrings. Math in Python docstrings is usually done by
RestructuredText markdown, e.g.:
:math:`f(x) = x^2`
while the org code should just be, for example,
\[
f(x) = x^2
\]
So the goal would be have noweb not only include a documentation block
in the python code, but also call a translation function that identifies
LaTeX fragments in the org source and converts them to ReST markdown.
This is do-able.
First, look at
(info "(org) Noweb reference syntax")
and note that the noweb reference
<<my-src-block(x="value_for_x")>>
will call `my-src-block' with the `x' var set to "value_for_x" and insert
the output into the current src block.
Second, https://github.com/masayuko/ox-rst has a reStructuredText backend.
So, you can install ox-rst.el, then write an emacs-lisp src block:
#+NAME: export-body
#+BEGIN_SRC emacs-lisp :var src-block-name="my-code" :results raw
(save-excursion
(org-babel-goto-named-src-block
src-block-name)
(org-export-string-as
(org-babel-expand-src-block)
'rst t))
#+END_SRC
and then a src-block like this
#+BEGIN_SRC emacs-lisp :noweb yes :tangle yes
<<export-body("my-code")>>
#+END_SRC
will insert the rst formatted text from the `my-code' src block when the
latter src block is tangled.
p.s. Untested with 'rst.
HTH,
Chuck