From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: getting calc-units working in table formulas Date: Tue, 16 Dec 2014 12:21:50 +0800 Message-ID: <87oar4ql5t.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50209) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y0jYc-0007u4-Ml for emacs-orgmode@gnu.org; Mon, 15 Dec 2014 23:16:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y0jYV-0003bo-5U for emacs-orgmode@gnu.org; Mon, 15 Dec 2014 23:16:22 -0500 Received: from plane.gmane.org ([80.91.229.3]:49698) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y0jYU-0003bg-VE for emacs-orgmode@gnu.org; Mon, 15 Dec 2014 23:16:15 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Y0jYT-0005Rx-Dc for emacs-orgmode@gnu.org; Tue, 16 Dec 2014 05:16:13 +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 05:16:13 +0100 Received: from eric by 114.248.5.200 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 16 Dec 2014 05:16:13 +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 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 But this doesn't: #+BEGIN_SRC emacs-lisp (defmath uconvert (expr target-units) (math-convert-units expr target-units)) #+END_SRC | km | ft | |-------+---------------------| | 2.5km | uconvert(2.5 km ft) | #+TBLFM: $2=uconvert($1 ft) I can't tell if I've written the calcFunc thing wrong, or if it's somehow not getting installed correctly. I've tried several variants, and they mostly all just give me the results above. Does anyone know what I'm doing wrong? Also, once that's figured out, wouldn't it be handy if Org came with a few predefined units-related math functions? It would be a tiny bit of code, for quite a bit more power. At the very least, I'd like to provide a patch to the manual to make the units stuff a little more explicit... Eric