I want to use Emacs Org-Mode source blocks in calc mode to convert units, e.g. 1 inch to…
- User
I want to use Emacs Org-Mode source blocks in calc mode to convert units, e.g. 1 inch to centimetres using calc units. How do I do that?
Assistant
You can use Emacs Org Mode source blocks with
calcto convert units like inches to centimeters. GNU Calc has robust unit conversion support, and you can interface with it viaob-calc, which is part of Org Mode's Babel system for evaluating code blocks.Here’s how to do it step by step:
✅ Step-by-Step Guide
1. Ensure
ob-calc.elis loadedOrg Babel supports
calcthrough theob-calcpackage. Make sure it is loaded.Add this to your Emacs config if not already present:
(org-babel-do-load-languages 'org-babel-load-languages '((calc . t)))Then restart or reload your config (
M-x eval-buffer).
2. Use a Calc Source Block in Org Mode
Now, you can write a source block like this in your
.orgfile:#+BEGIN_SRC calc :results code convert(1_in, cm) #+END_SRCThis tells Calc to convert 1 inch (
1_in) into centimeters (cm).
3. Evaluate the Block
Place the cursor inside the block and press
C-c C-c(or runM-x org-babel-execute-src-block).The result will be inserted below:
#+RESULTS: : 2.54 cm
🧮 More Examples
Convert 10 miles to kilometers:
#+BEGIN_SRC calc :results code convert(10_mi, km) #+END_SRCResult:
#+RESULTS: : 16.09344 kmConvert 60 miles per hour to meters per second:
#+BEGIN_SRC calc :results code convert(60_mi/hr, m/s) #+END_SRCResult:
#+RESULTS: : 26.8224 m / s
📌 Notes
- Use underscores
_to denote units in Calc expressions. - Supported unit abbreviations are similar to those in GNU Calc. See Calc Units for more info.
- You can also perform arithmetic with units directly in the expression, e.g.,
1_m + 100_cm.
Let me know if you'd like to define custom units or automate unit conversions across tables!
- Use underscores
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.