unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Using calc's translations programaticaly
@ 2007-10-21 12:43 Nikos Apostolakis
  0 siblings, 0 replies; 3+ messages in thread
From: Nikos Apostolakis @ 2007-10-21 12:43 UTC (permalink / raw)
  To: help-gnu-emacs

Hello group,

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.

My question is how can I access this feature from elisp?  An obvious
hack is to copy the formula to a temp buffer and invoke the above
keystroke sequence, and that's what I am doing at the moment.  I
wonder whether there is a better way though.  I tried to look at
Calc's sources but I got lost -- my elisp is not that good.

TIA,
Nikos

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Using calc's translations programaticaly
  2007-10-22 18:39 ` Using calc's translations programaticaly Jay Belanger
@ 2007-10-22 17:32   ` Nikos Apostolakis
  0 siblings, 0 replies; 3+ messages in thread
From: Nikos Apostolakis @ 2007-10-22 17:32 UTC (permalink / raw)
  To: help-gnu-emacs

Jay Belanger <jay.p.belanger@gmail.com> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Using calc's translations programaticaly
       [not found] <mailman.2400.1192989832.18990.help-gnu-emacs@gnu.org>
@ 2007-10-22 18:39 ` Jay Belanger
  2007-10-22 17:32   ` Nikos Apostolakis
  0 siblings, 1 reply; 3+ messages in thread
From: Jay Belanger @ 2007-10-22 18:39 UTC (permalink / raw)
  To: help-gnu-emacs


> 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.

> 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).  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

Jay

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-10-22 18:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.2400.1192989832.18990.help-gnu-emacs@gnu.org>
2007-10-22 18:39 ` Using calc's translations programaticaly Jay Belanger
2007-10-22 17:32   ` Nikos Apostolakis
2007-10-21 12:43 Nikos Apostolakis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).