all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Charles C. Berry" <ccberry@ucsd.edu>
To: David Dynerman <emperordali@block-party.net>
Cc: emacs-orgmode@gnu.org
Subject: Re: Include sections of org document in tangled files
Date: Wed, 7 Dec 2016 19:12:15 -0800	[thread overview]
Message-ID: <alpine.OSX.2.20.1612071759010.980@charles-berrys-macbook.local> (raw)
In-Reply-To: <m2d1h3qp4s.fsf@block-party.net>

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

      reply	other threads:[~2016-12-08  3:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-02 22:05 Include sections of org document in tangled files David Dynerman
2016-12-03 18:16 ` Charles C. Berry
2016-12-07 23:46   ` David Dynerman
2016-12-08  3:12     ` Charles C. Berry [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.OSX.2.20.1612071759010.980@charles-berrys-macbook.local \
    --to=ccberry@ucsd.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=emperordali@block-party.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.