Re: [sage-newbie] is there any way to copy jsfonts to word ?

3 views
Skip to first unread message

William Stein

unread,
Dec 13, 2007, 6:26:22 PM12/13/07
to sage-...@googlegroups.com, sage-...@googlegroups.com
On Dec 13, 2007 1:58 PM, carlosap <carlo...@gmail.com> wrote:
>
> If I have the result from something like
>
> show( ... )
>
> how do I copy, paste to word ? So I dont have to rewrite the function
> in that crappy ms ecuation editor?
>

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

boo...@u.washington.edu

unread,
Dec 13, 2007, 6:31:37 PM12/13/07
to sage-...@googlegroups.com
A friend of mine works at Microsoft, and is quite proud that any time I send him an email containing latex, he can copy & paste into Word (I think he's using 2007) -- and their new equation editor groks most of latex.

Jason Grout

unread,
Dec 13, 2007, 6:41:25 PM12/13/07
to sage-...@googlegroups.com

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

Ted Kosan

unread,
Dec 14, 2007, 12:28:26 PM12/14/07
to sage-...@googlegroups.com
Jason wrote:

> 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

William Stein

unread,
Dec 14, 2007, 1:27:21 PM12/14/07
to sage-...@googlegroups.com

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

Jason Grout

unread,
Dec 14, 2007, 1:50:44 PM12/14/07
to sage-...@googlegroups.com

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

William Stein

unread,
Dec 14, 2007, 4:19:41 PM12/14/07
to sage-...@googlegroups.com

Thanks. I've made this a trac enhancement:

http://trac.sagemath.org/sage_trac/ticket/1512

Ted Kosan

unread,
Dec 14, 2007, 4:38:58 PM12/14/07
to sage-...@googlegroups.com
William wrote:

> 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

Ted Kosan

unread,
Dec 14, 2007, 5:31:50 PM12/14/07
to sage-...@googlegroups.com
Ted wrote:

> 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

Reply all
Reply to author
Forward
0 new messages