From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric S Fraga Subject: Re: Evaluating simple inline expressions in org-mode Date: Mon, 8 Feb 2016 09:33:03 +0000 Message-ID: <878u2v35tc.fsf@delle7240.chemeng.ucl.ac.uk> References: <87twlpwzbw.fsf@delle7240.chemeng.ucl.ac.uk> <87wpqlyn5f.fsf@duenenhof-wilhelm.de> <87vb64j2f0.fsf@delle7240.chemeng.ucl.ac.uk> <87r3gozfqp.fsf@duenenhof-wilhelm.de> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34435) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSjeZ-00014l-O1 for emacs-orgmode@gnu.org; Mon, 08 Feb 2016 06:06:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aSjeV-0007Av-KS for emacs-orgmode@gnu.org; Mon, 08 Feb 2016 06:06:47 -0500 Received: from mail-db5eur01on0093.outbound.protection.outlook.com ([104.47.2.93]:28576 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSjeV-0007Ad-CM for emacs-orgmode@gnu.org; Mon, 08 Feb 2016 06:06:43 -0500 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: "H. Dieter Wilhelm" Cc: emacs-orgmode@gnu.org On Sunday, 7 Feb 2016 at 16:45, H. Dieter Wilhelm wrote: >>>> works as well. I'm not sure how you define variables in calc however... >>> > >>> You could write something like src_calc[:var x=3.41]{2*x} :-) >> >> Yes but can you save a variable for use in a later expression? > > Well, at the moment I don't know another way as defining the calc > variables on the lisp level: > > #+BEGIN_SRC emacs-lisp > (setq var-foo 9.81 > var-x 3.14 > var-bar ...) > #+END_SRC > > Note: `var-' is a special prefix for the calc variables `foo', `x', Thanks for this. Very useful to know. Using this, I've created a macro which will be quite useful for me in preparing some lecture notes with simple calculations for illustration: #+begin_src org ,#+macro: calculate $2 \leftarrow src_calc[:exports code]{$1} = src_emacs-lisp{(setq var-$2 (string-to-number (calc-eval "evalv($1)")))} An example: {{{calculate(x+y,z)}}} #+end_src -- : Eric S Fraga (0xFFFCF67D), Emacs 25.0.90.1, Org release_8.3.3-535-g7213aa