Using an org-mode table in emacs to convert units using calc
Question
Is there a way to use an org-mode table to do automatic unit conversion?
I cannot get it to work. What I wanted to do is using a simple table where i can input some weights in ounces and let emacs convert them into gramms.
|---------+---------------|
| 100oz | ??g |
| 50oz | ??g |
|---------+---------------|
#+TBLFM: $2='(calc-eval ?????)
I didn't find out what to put into the calc-eval, in calc mode i would do the conversion by entering f.i. 100g, then pressing u c for "convert unit" and then entering g for "gramm".
Thanks very much.
Solution
u c
runs calc-convert-units
, which obtains the target unit in a peculiar way (i.e. not from the stack). The underlying function is math-convert-units
, and we can use calc-eval
to convert between strings and calc objects.
|---+-------+-----------------|
| # | 100oz | 2834.9523125 g |
| # | 50oz | 1417.47615625 g |
|---+-------+-----------------|
#+TBLFM: $3='(calc-eval (math-convert-units (calc-eval $2 'raw) (calc-eval "g" 'raw)))
OTHER TIPS
This sounds more like a job for Simple Emacs Spreadsheet aka ses.el, see emacs wiki page It is included with Gnu Emacs 23.