To use Emacs Org-Mode source blocks with Calc mode for unit conversions, you can leverage Calc's built-in unit conversion capabilities. Here's how to do it:
1. Basic Calc Unit Conversion in Org-Mode
You can use a src block with the emacs-lisp or calc header to perform unit conversions. Calc understands many unit conversions (e.g., inch to cm).
Example:
#+BEGIN_SRC emacs-lisp :results value
(calc-eval "1 inch in cm")
#+END_SRC
This will evaluate to 2.54 (since 1 inch = 2.54 cm).
2. Using Calc Mode Directly
If you want to use Calc mode interactively, you can do so within an Org file by:
- Inserting a
src block with calc as the language.
- Using Calc's unit conversion syntax.
Example:
#+BEGIN_SRC calc
1 inch in cm
#+END_SRC
When you evaluate this (e.g., with C-c C-c), it will return 2.54.
3. More Complex Conversions
You can also perform arithmetic operations with units:
#+BEGIN_SRC calc
(3 * 12 inch) in cm
#+END_SRC
This converts 36 inches to centimeters (result: 91.44).
4. Using org-babel with Calc
Org-Babel supports Calc mode, so you can use it like any other source block.
Example:
#+BEGIN_SRC calc :results value
1 mile in km
#+END_SRC
This will return 1.609344 (1 mile ≈ 1.609344 km).
5. List of Supported Units
Calc supports many units, including:
- Length:
inch, cm, m, km, mile, yard, foot, etc.
- Weight:
kg, lb, g, oz, etc.
- Time:
s, min, h, day, etc.
- Temperature:
C, F, K, etc.
For a full list, see the Calc manual.
6. Alternative: Using M-x calc
If you prefer, you can also open Calc mode (M-x calc), perform the conversion interactively, and then paste the result into Org.
Summary
- Use
#+BEGIN_SRC calc for direct unit conversions.
- Use
calc-eval in emacs-lisp blocks if needed.
- Org-Babel will handle the evaluation and display the result.