0

I mean : in a simple way..

(let ((calc-language 'latex))(calc-eval "1/2 + 1/4")) ; =>\frac{1}{12}
(let ((calc-language 'C))(calc-eval "1/2 + 1/4")) ; =>3/4

Of course, no problem if I use parenthesis :

(let ((calc-language 'latex))(calc-eval "(1/2) + (1/4)")) ; =>\frac{3}{4}

But I find that a bit boring.

2 Answers 2

1

I evaluated the following form:

  (put 'latex' math-oper-table (math-standard-ops))

then this one which evaluates the desired value:

  (let ((calc-language 'latex))(calc-eval "1/2 + 1/4")); =>\frac{3}{4}

I don't know if there are any unwanted side effects or not, but it seems like this is exactly what I asked for.

To enable it by default, I put:

(with-eval-after-load 'calc-lang (put 'latex' math-oper-table (math-standard-ops)))

in my init file.

0

Here's a macro I've been using to do something similar (in this package):

(defmacro with-calc-language (lang &rest body)
  "Execute the forms in BODY with `calc-language` set to LANG.
The value of `calc-language` is restored after BODY has been
processed."
  `(let ((old-lang calc-language))
     (unwind-protect
         (progn
           (save-excursion
             (calc-create-buffer))
           (calc-set-language ,lang)
           ,@body)
       (calc-set-language old-lang))))

(with-calc-language 'latex
                    (calc-eval "1/2 + 1/4")) ; => "\\frac{3}{4}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.