emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: David Dynerman <emperordali@block-party.net>
To: emacs-orgmode@gnu.org
Subject: Include sections of org document in tangled files
Date: Fri, 02 Dec 2016 14:05:44 -0800	[thread overview]
Message-ID: <m2inr2dm13.fsf@block-party.net> (raw)

Dear list,

Is it possible to include sections of an org document while tangling.

I have in mind something like the following:

* Some section
<<doc>>
This is an introduction. We're going to write some code that implements (a finite version of) the formula

\[
f(x) = 1 + x + \frac{x^2}{2} + \frac{x^3}{6} + \ldots + \frac{x^n}{n!} + \ldots
\]

Here's some background about the exponential function.

#+BEGIN_SRC python :tangle myfunction.py
from math import factorial

def f(x,n):
    """<<doc>>"""

    y = 0
    for i in range(n+1):
        y = y + x**i/factorial(i)

    return y
#+END_SRC

The idea would be that when I export this to HTML, I get a nice literate
programming math jax'd section introduction that explains what the
function is doing. Then, when I tangle to generate the python file, the
org section introduction would be included as the python docstring of
the function.

This would be really useful, because currently I find myself repeating
information when I use org for literate programming. First, I explain
what a python function is doing in the org file, but then I also want to
include a docstring in the tangled output that basically contains the
same information as the org file.

Thank you,
David

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

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

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

  List information: https://www.orgmode.org/

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

  git send-email \
    --in-reply-to=m2inr2dm13.fsf@block-party.net \
    --to=emperordali@block-party.net \
    --cc=emacs-orgmode@gnu.org \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).