emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ken Mankoff <mankoff@gmail.com>
To: Gary Oberbrunner <garyo@oberbrunner.com>
Cc: Orgmode Mailing List <emacs-orgmode@gnu.org>
Subject: Re: Evaluating simple inline expressions in org-mode
Date: Wed, 03 Feb 2016 08:58:25 -0500	[thread overview]
Message-ID: <m2twlpki9q.fsf@gmail.com> (raw)
In-Reply-To: <CAFChFyjRoO6nVyuzn+ST=_q=9EF8PbcVa3facAYkko+vW-8QtA@mail.gmail.com>


On 2016-02-03 at 08:45, Gary Oberbrunner <garyo@oberbrunner.com> wrote:
> I'd like to just have a few inline formulas evaluated in my org-mode
> document (I'm exporting to LaTeX if that matters). Something like this:
>
> =========================
> # a constant:
> # pi = 3.14159
>
> The value of interest is {{{2*$pi}}}.
> =========================
>
> I want that to export as:
>
>   The value of interest is 6.28318.

The following works for me:


#+BEGIN_SRC python :results output :exports none  :session foo
val = 2
#+END_SRC
#+RESULTS:

The value of interest is src_python[:session foo]{np.round(2*val,3)} {{{results(=4=)}}} and src_octave{2*pi} {{{results(=6.283185307179586=)}}}


You don't need the code block + session to set up a value for your example with pi, since Python and Octave know what pi is, but I demonstrate it here because you might want to work with something other than pi.

Python needs a [:session] to work for some reason on my system, but that is also beneficial so you can set up your variables. Note that your :session code block could take in an Org table as a header argument and define them in code from the table, so your actual variables are defined in an Org table, not in code. This is beginning to approach true literate programming...

  -k.

  reply	other threads:[~2016-02-03 13:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-03 13:45 Evaluating simple inline expressions in org-mode Gary Oberbrunner
2016-02-03 13:58 ` Ken Mankoff [this message]
2016-02-03 16:09 ` Eric S Fraga
2016-02-03 16:14   ` Gary Oberbrunner
2016-02-04  7:01   ` H. Dieter Wilhelm
2016-02-04  8:38     ` Eric S Fraga
2016-02-07 15:45       ` H. Dieter Wilhelm
2016-02-08  9:33         ` Eric S Fraga

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=m2twlpki9q.fsf@gmail.com \
    --to=mankoff@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=garyo@oberbrunner.com \
    /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).