emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] Include sections of org document in tangled files


From: David Dynerman
Subject: [O] Include sections of org document in tangled files
Date: Fri, 02 Dec 2016 14:05:44 -0800

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 via email to

[Prev in Thread] Current Thread [Next in Thread]