From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: Re: getting calc-units working in table formulas Date: Tue, 16 Dec 2014 14:33:44 +0800 Message-ID: <87a92oqf1z.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]:39286) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y0lcI-0002XO-U6 for emacs-orgmode@gnu.org; Tue, 16 Dec 2014 01:28:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y0lcC-0007QT-JY for emacs-orgmode@gnu.org; Tue, 16 Dec 2014 01:28:18 -0500 Received: from plane.gmane.org ([80.91.229.3]:53553) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y0lcC-0007QL-D7 for emacs-orgmode@gnu.org; Tue, 16 Dec 2014 01:28:12 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Y0lc3-0007f5-LZ for emacs-orgmode@gnu.org; Tue, 16 Dec 2014 07:28:03 +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 ; Tue, 16 Dec 2014 07:28:03 +0100 Received: from eric by 114.248.5.200 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 16 Dec 2014 07:28:03 +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 Eric Abrahamsen writes: > I've been playing with calc-units, and it's pretty amazing. See all the > units with `calc-view-units-table'. > > Some calc-units stuff works out the box (maybe have to require > calc-units?), I think this should be mentioned in the manual: > > | distance | time | speed | > |----------+--------+-------------| > | 3 km | 2.5 hr | 1.2 km / hr | > > #+TBLFM: @2$3=$1/$2 > > Who knew it could do that?! Probably everyone but me... It doesn't need > the constants.el package, and looks nicer in the input, to boot. > > calc-units makes a few of its functions available via defmath: > > | speed | simplified speed | > |--------------+------------------| > | 40km / 2.5hr | 16. km / hr | > | | | > > #+TBLFM: @2$2=usimplify($1) > > But it's got a lot more tricks. I think unit conversion would be very > handy to have, but there's something I'm not getting about using > defmath. For instance, this works: > > | km | ft | > |-------+---------| > | 2.5km | 8202.10 | > > #+TBLFM: $2='(calc-eval (math-convert-units (calc-eval $1 'raw) (calc-eval "ft" 'raw))); %.2f I wonder if the problem is the 'raw in here. To the best of my knowledge, calc-eval needs that 'raw flag to work properly with this. But it doesn't look like `org-table-eval-formula' will ever send that flag. I hope someone who knows this code better than me can comment...