7

Is there a way to highlight and quickly evaluate a simple math expression without using elisp notation? For example, we can already evaluate the elisp expression (+ 1 1) in the following text snippet by putting point behind it and pressing C-x C-e.

Here is a math equation: (+ 1 1)

But can we also do

Here is a math equation: 1 + 1

And get its result?

Tobias
  • 32,569
  • 1
  • 34
  • 75
George
  • 879
  • 5
  • 17

2 Answers2

8

You can use the built-in calc package to do so.

  1. Mark your expression, e.g. 3 * (1 + 1)
  2. Call calc-grab-region
    • Call calc-dispatch (default C-x *), then hit g
Tianxiang Xiong
  • 3,848
  • 16
  • 27
3

You might also use calc's embedded mode if you intent to replace an expression with its result in the current buffer. C-u C-x * e when your formula / expression is on it's own on a separate line.

Otherwise mark it and type C-0 C-x * e

(Update: thanks to Dodgie, forgot to mention that) When you are finished with your mathematical manipulations type C-x * e again to end embedded calc mode.

Dieter.Wilhelm
  • 1,836
  • 14
  • 25