You might be able to use
latex(...)
to get the latex form of the equation, then use a program such as
this http://www.chikrii.com/products/tex2word/ to convert that
latex expression to word. I have never used the above program - I just
found it by googling for latex2word.
E.g.,
sage: show(taylor(cos(x)/sin(x), x, 1, 2))
<nice equation>
sage: latex(taylor(cos(x)/sin(x), x, 1, 2))
\frac{\cos \left( 1 \right)}{\sin \left( 1 \right)} - \frac{{\left(
{\sin \left( 1 \right)}^{2} + {\cos \left( 1 \right)}^{2} \right)
\cdot \left( x - 1 \right)}}{{\sin \left( 1 \right)}^{2} } +
\frac{{\left( {\cos \left( 1 \right) \cdot {\sin \left( 1 \right)}^{2}
} + {\cos \left( 1 \right)}^{3} \right) \cdot \left( {\left( x - 1
\right)}^{2} \right)}}{{\sin \left( 1 \right)}^{3} }
The big mess above should be auto-convertible to a word equation, in theory.
Does anybody have any better ideas? Another idea would be to try to use
something involving OpenOffice and Latex like this:
http://www.cs.utk.edu/~spires/html/content/code/OO_Latex/index.html
then export from OpenOffice to word.
If you figure anything out that works for you please report back!
-- William
What about writing an openoffice function that converts an expression to
openoffice equation format? For example, the above output is:
{cos(1)} over {sin(1)} - {(sin(1)^2 + cos(1)^2) cdot (x-1)} over
{sin(1)^2} + {(cos(1) cdot sin(1)^2 + cos(1)^3) cdot ((x-1)^2)} over
{sin(1)^3}
(just paste that into the equation editor of openoffice and the equation
pops up in your document).
The syntax is looser than latex, but I think it's probably doable and
probably just a modification of the latex function. While it might be
nice to insist on everyone downloading a latex macro and learning a bit
of latex, having an openoffice export function makes Sage that much more
accessible.
I have no idea if the equations can then be converted to Word. I'd be
interested in knowing, though.
-Jason
> What about writing an openoffice function that converts an expression to
> openoffice equation format? For example, the above output is:
>
> {cos(1)} over {sin(1)} - {(sin(1)^2 + cos(1)^2) cdot (x-1)} over
> {sin(1)^2} + {(cos(1) cdot sin(1)^2 + cos(1)^3) cdot ((x-1)^2)} over
> {sin(1)^3}
>
> (just paste that into the equation editor of openoffice and the equation
> pops up in your document).
>
> The syntax is looser than latex, but I think it's probably doable and
> probably just a modification of the latex function. While it might be
> nice to insist on everyone downloading a latex macro and learning a bit
> of latex, having an openoffice export function makes Sage that much more
> accessible.
I am in the process of writing educational materials which show high
school students how to use SAGE with OpenOffice to create technical
documents and an OpenOffice export function would be very helpful for
this. Does anyone have a feel for how difficult it would be to write
a function like this?
Ted
What needs to be done is to write in Python a latex --> open office format
converter, probably with a bunch of regexp's, etc. How hard is that?
William
To get someone started, here are the rules I used above, with a bit of
extra grouping (the {} brace pairs) to make sure things work out all right.
\frac{a}{b} -> {{a} over {b}}
\sin -> sin
\cos -> cos
\cdot -> cdot
also, I saw that:
\left( -> left (
\right) -> right )
etc.
Whoever does it might click through the openoffice equation toolbar
which gives the openoffice code for the various symbols.
-Jason
> What needs to be done is to write in Python a latex --> open office format
> converter, probably with a bunch of regexp's, etc. How hard is that?
Wouldn't regular expressions be inadequate for deciphering nested
expressions like the following?:
sage: a = cos(cos(cos(x)))
sage: a
cos(cos(cos(x)))
sage: latex(a)
\cos \left( \cos \left( \cos \left( x \right) \right) \right)
For nested expressions, my understanding is that one would need to
first generate something line an Abstract Syntax Tree using a latex
lexical analyzer and parser and then process the tree in order to
generate equivalent openoffice code.
My background is not in Computer Science, though, so I may be wrong about this.
Ted
> Wouldn't regular expressions be inadequate for deciphering nested
> expressions like the following?:
>
> sage: a = cos(cos(cos(x)))
> sage: a
> cos(cos(cos(x)))
> sage: latex(a)
> \cos \left( \cos \left( \cos \left( x \right) \right) \right)
>
> For nested expressions, my understanding is that one would need to
> first generate something line an Abstract Syntax Tree using a latex
> lexical analyzer and parser and then process the tree in order to
> generate equivalent openoffice code.
After studying this further, it looks like it is just a
straightforward translation from latex to OpenOffice math format. I
have been searching the net for code that does this already but I have
not found anything yet. If the process is this simple, I wonder why
there aren't a bunch of people who have done it already?
Ted