help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using calc's translations programaticaly


From: Nikos Apostolakis
Subject: Re: Using calc's translations programaticaly
Date: Mon, 22 Oct 2007 13:32:51 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/23.0.50 (gnu/linux)

Jay Belanger <address@hidden> writes:

>> Calc has this great feature that automatically (and pretty
>> accurately) translates formulas written in one language to an other
>> language.  For example if I have a LaTeX formula that I want to pass
>> to maxima (say) I can simply do "C-x * e d W C-x * e" and voila: the
>> formula is transformed to a form that maxima understands.
>
> Well, that's supposed to transform it to Maple, but perhaps that's
> close enough.

Pretty close.  I've been thinking of defining a new calc language
for maxima for some time now, but the Maple language works for most
of my needs with little modification that I've never have come
around to do it.

>
>> My question is how can I access this feature from elisp?
>
> Calc really isn't set up to do that, but perhaps something like
>
> (defun calc-change-lang (expr old-lang new-lang)
>   (require 'calc-lang)
>   (let (math-expr-opers 
>         math-expr-function-mapping 
>         math-expr-special-function-mapping 
>         math-expr-variable-mapping
>         calc-language-input-filter
>         calc-language-output-filter
>         calc-vector-brackets
>         calc-complex-format
>         calc-radix-formatter
>         calc-function-open
>         calc-function-close
>         calc-language
>         calc-language-option)
>     (calc-set-language old-lang)
>     (let ((expr (math-read-expr expr)))
>       (calc-set-language new-lang)
>       (math-format-value expr))))
>
> would work (the first `let' is to prevent the current language from
> being disturbed).  

This seems to work great!  Thanks a lot.  

>The interesting (for this) values of old-lang and
> new-lang might be:
>   nil  (normal Calc language)
>   'c
>   'pascal
>   'fortran
>   'tex
>   'latex
>   'eqn
>   'math (Mathematica)
>   'maple

'big is also interesting.  It's helpfull for writing ascii-art
formulas for posts, emails etc.  For example:

           ____________
          |  2
(-b) +/- \| b  - 4 a c
-----------------------
         2 a


Thanks again,
Nikos

>
> Jay





reply via email to

[Prev in Thread] Current Thread [Next in Thread]