From mboxrd@z Thu Jan 1 00:00:00 1970 From: Brett Viren Subject: Re: Unit conversions and symbolic mathematics with Babel Date: Wed, 03 Sep 2014 09:18:36 -0400 Message-ID: References: <87vbp5urc4.fsf@vsl28t2g.ww011> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55199) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPASm-0000fx-6D for emacs-orgmode@gnu.org; Wed, 03 Sep 2014 09:19:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XPASh-0002Hv-DJ for emacs-orgmode@gnu.org; Wed, 03 Sep 2014 09:19:04 -0400 Received: from smtpgw.bnl.gov ([2620:10a:0:3::30]:20120 helo=iron4.sec.bnl.local) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPASh-0002G3-8X for emacs-orgmode@gnu.org; Wed, 03 Sep 2014 09:18:59 -0400 In-Reply-To: <87vbp5urc4.fsf@vsl28t2g.ww011> (H. Dieter Wilhelm's message of "Wed, 03 Sep 2014 08:54:19 +0200") 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: Jay Belanger , emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi, dieter@duenenhof-wilhelm.de (H. Dieter Wilhelm) writes: > But what is missing is to assign variables within a source block >=20=20=20 > #+BEGIN_SRC calc :var L1 =3D "5 mm"=20 > L2 :=3D cvun( L1, m) > #+END_SRC=20=20=20=20 >=20=20=20 > Unfortunately this is not working. Do you have an idea how to > implement this? > > - Are you using (better) alternatives? I like Python and in Python I like Pint for units. http://pint.readthedocs.org Below is an example org document that should "run" and shows a couple ways to use snippets of Pint code to do unit conversion. Not shown but Pint Quantity objects support arithmetic so are useful for carrying units through some calculation. For assigning to variables - presumably for use in later blocks - maybe you can investigate using the :session header argument to source blocks. Have fun, =2DBrett. One way to install Pint is: #+BEGIN_SRC sh :results silent pip install --user pint #+END_SRC Here is an example: #+name: uconv #+header: :var val=3D"10m" :var unit=3D"inch"=20 #+BEGIN_SRC python import pint units =3D pint.UnitRegistry() return units.Quantity(val).to(unit) #+END_SRC #+RESULTS: uconv : 393.700787402 inch Now call =3Duconv=3D do to some other conversion: #+call: uconv("2.54cm","inch") #+RESULTS: : 1.0 inch --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlQHFS0ACgkQEixH2Z0dKCwTigCfZ61sR0hDLQYZmmsnbOEAMDNU 9dIAnjU4r50wQ1YiXfWqYGTBxaHG0Vkc =TjgB -----END PGP SIGNATURE----- --=-=-=--