Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using an org-mode table in emacs to convert units using calc

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.

like image 493
Moschter Avatar asked Sep 22 '10 13:09

Moschter


2 Answers

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)))
like image 178
Gilles 'SO- stop being evil' Avatar answered Nov 18 '22 13:11

Gilles 'SO- stop being evil'


This sounds more like a job for Simple Emacs Spreadsheet aka ses.el, see emacs wiki page It is included with Gnu Emacs 23.

like image 36
fschmitt Avatar answered Nov 18 '22 12:11

fschmitt