On 5/13/11 6:00 AM, Bruno Le Floch wrote:
On 5/13/11, Jason Grout<jason-s...@creativetrax.com>  wrote:
On 5/12/11 11:38 PM, Dan Drake wrote:
If I have a Sage expression, I can do

     latex(foo)

to get LaTeX code. Is there an inverse to that function?

Frequently, I do a calculation in Sage and get something complicated. I
find it easier to look at when typeset by TeX, so I call latex(), paste
the result into a document, then typeset.

Conversely, sometimes I write something in LaTeX and would like to do
some calculations with it. So I'd like to call...something, paste the
result into Sage, and compute.

I'm generally working with reasonably simple symbolic expressions. Is
this possible? I know that a full parser is practically impossible, but
it seems like a relatively simple parser could work pretty well.

I think I'm asking for a complement to Rob Beezer's tex2sws. Thoughts?

If we had this, it would be a lot simpler to do a web-based equation editor.

Jason

I don't think it exists yet, Dan. However, it should be feasible in
simple cases. I have a few ideas on how to do it using TeX (probably
not the fastest, but that's the language I know best). Can you please
post a couple of typical short-but-thorough examples of LaTeX
equations, and the desired output? Don't hesitate to go for "hard"
cases, such as matrices, or slightly "dirty" TeX code: anything you
may realistically wish to use in practice.

I'll try to give the possibility of using a config file to set some
defaults (e.g. maybe \Gamma often represents the Gamma function for
you, maybe \Gamma is a constant for someone else), and try to make it
possible to override them locally. My idea is to write a LaTeX package
which when loaded would convert math expressions to a Sage input,
stored in an external file.

I'm very keen on trying this, as it is related to a recent idea of
mine. Start from a Sage symbolic expression, and convert it using
latex(). Then given a subexpression in the LaTeX code, be able to go
back to the Sage subexpression. The goal would be in the long term to
provide reverse search from the jsmath/mathjax displayed equation back
to the Sage code. Then it may be possible to e.g. select a
subexpression and apply some transformations (i.e. .simplify(), or
..collect(...) to the subexpression rather than the whole expression).
But that's probably a longer term project.

Anyway, give me some examples, and one or two weeks, and I'll try to
produce a prototype.

We might also talk with the jsmath/mathjax developer, Davide Cervone. IIRC, he already converts from latex to MathML, so there is some sort of tex processing that he is doing in javascript. We've talked with him about a way to convert from latex/mathjax back to Sage code before.

For your application, I wonder if it would be easy to somehow encode annotations in the latex output, so that you could delimit subexpressions with the code that originally created them. If we output mathml instead of latex for mathjax, I suppose that encoding such annotations would be easier. Especially if it was Content MathML instead of just Presentation MathML.

Thanks,

Jason

--
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to