Is there a calculator with LaTeX-syntax?

前端 未结 17 2066
北海茫月
北海茫月 2020-12-12 17:00

When I write math in LaTeX I often need to perform simple arithmetic on numbers in my LaTeX source, like 515.1544 + 454 = ???.

I usually copy-paste the

17条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-12 17:45

    As Andy says, the answer is yes there is a calculator that can understand most latex formulas: Emacs.

    Try the following steps (assuming vanilla emacs):

    1. Open emacs
    2. Open your .tex file (or activate latex-mode)
    3. position the point somewhere between the two $$ or e.g. inside the begin/end environment of the formula (or even matrix).
    4. use calc embedded mode for maximum awesomeness

    So with point in the formula you gave above:

    $\frac{154,7}{25} - (289 - \frac{1337}{42})$

    press C-x * d to duplicate the formula in the line below and enter calc-embedded mode which should already have activated a latex variant of calc for you. Your buffer now looks like this:

    $\frac{154,7}{25} - (289 - \frac{1337}{42})$
    
    $\frac{-37651}{150}$`
    

    Note that the fraction as already been transformed as far as possible. Doing the same again (C-x * d) and pressing c f to convert the fractional into a floating point number yields the following buffer:

    $\frac{154,7}{25} - (289 - \frac{1337}{42})$
    
    $\frac{-37651}{150}$
    
    $-251.006666667$
    

    I used C-x * d to duplicate the formula and then enter embedded mode in order to have the intermediate values, however there is also C-x * e which avoids the duplication and simply enters embedded mode for the current formula.

    If you are interested you should really have a look at the info page for Emacs Calc - Embedded Mode. And in general the help for the Gnu Emaca Calculator together with the awesome interactive tutorial.

提交回复
热议问题