From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: Re: getting calc-units working in table formulas Date: Wed, 17 Dec 2014 09:09:20 +0800 Message-ID: <87egrznl9e.fsf@ericabrahamsen.net> References: <87oar4ql5t.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46387) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1329-0002Kj-Ff for emacs-orgmode@gnu.org; Tue, 16 Dec 2014 20:04:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y1322-0007MS-Nk for emacs-orgmode@gnu.org; Tue, 16 Dec 2014 20:04:09 -0500 Received: from plane.gmane.org ([80.91.229.3]:59782) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1322-0007Lv-Gp for emacs-orgmode@gnu.org; Tue, 16 Dec 2014 20:04:02 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Y131l-0003lc-G1 for emacs-orgmode@gnu.org; Wed, 17 Dec 2014 02:03:45 +0100 Received: from 114.248.5.200 ([114.248.5.200]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 17 Dec 2014 02:03:45 +0100 Received: from eric by 114.248.5.200 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 17 Dec 2014 02:03:45 +0100 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: emacs-orgmode@gnu.org Michael Brand writes: > Hi Eric > > This answers only one of your questions: > > On Tue, Dec 16, 2014 at 5:21 AM, Eric Abrahamsen > wrote: >> #+BEGIN_SRC emacs-lisp >> (defmath uconvert (expr target-units) >> (math-convert-units expr target-units)) >> #+END_SRC > > I would prefer > > #+BEGIN_SRC emacs-lisp > (defmath uconv (expr target-units &optional pure) > (math-convert-units expr target-units pure)) > #+END_SRC > > >> | km | ft | >> |-------+---------------------| >> | 2.5km | uconvert(2.5 km ft) | >> #+TBLFM: $2=uconvert($1 ft) > > Calc syntax uses comma to separate the function arguments, see > examples in e. g. > http://orgmode.org/manual/Formula-syntax-for-Calc.html I was hoping I'd made a more interesting mistake than that! Thanks for clearing that up. > | km | ft | > |--------+--------------| > | 2.5 km | 8202.0997 ft | > > #+TBLFM: $2 = uconv($1, ft) > > Btw, to have the units only in the column header: > > | km | ft | > |-----+-----------| > | 2.5 | 8202.0997 | > > #+TBLFM: $2 = uconv($1 * @<$1, @<$2, t) > > The same without a user's defmath: > > | km | ft | > |-----+-----------| > | 2.5 | 8202.0997 | > > #+TBLFM: $2 = usimplify($1 * @<$1 / @<$2) Wow, interesting stuff. I had no idea... I'd still like to provide a small patch to the documentation, alerting users to the fact that units work out of the box. Does anyone have any opinions on including a defmath for `math-convert-units'? (The 'pure variant seems like a fine choice.) Lastly, is there a way to both use output formatting, and retain the unit name (if desired)? Right now I get this: | km | units | conversion | |-------+-------+------------| | 2.5km | ft | 8202.10 | #+TBLFM: $3=uconvert($1, $2); %.2f Ie, the "ft" falls off the results when I add the "%.2f". Is it possible to retain that and have formatting? Eric