From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: emacs-orgmode@gnu.org
Subject: Re: getting calc-units working in table formulas
Date: Wed, 17 Dec 2014 09:09:20 +0800 [thread overview]
Message-ID: <87egrznl9e.fsf@ericabrahamsen.net> (raw)
In-Reply-To: CALn3zohF_HpHqmaBFWHHmgcOEJBXhundsoDdo5qu9__X6VhkXA@mail.gmail.com
Michael Brand <michael.ch.brand@gmail.com> writes:
> Hi Eric
>
> This answers only one of your questions:
>
> On Tue, Dec 16, 2014 at 5:21 AM, Eric Abrahamsen
> <eric@ericabrahamsen.net> 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
next prev parent reply other threads:[~2014-12-17 1:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-16 4:21 getting calc-units working in table formulas Eric Abrahamsen
2014-12-16 6:33 ` Eric Abrahamsen
2014-12-16 13:06 ` Michael Brand
2014-12-17 1:09 ` Eric Abrahamsen [this message]
2014-12-17 6:39 ` Michael Brand
2014-12-17 7:02 ` Eric Abrahamsen
2014-12-18 10:07 ` [PATCH] " Eric Abrahamsen
2014-12-20 16:33 ` Nicolas Goaziou
2014-12-21 4:22 ` Eric Abrahamsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87egrznl9e.fsf@ericabrahamsen.net \
--to=eric@ericabrahamsen.net \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.