f

#### Re: Mathematica and LyX - Graphics and equations

On 1/25/09 at 6:53 AM, latev@shaw.ca (TL) wrote:

>I decided to give it a try and installed the MiKTeX Win version along
>with the LyX fronted for it, since I have absolutely no experience with
>LaTeX.

But LyX really isn't a front end for LaTeX. LyX is a document
processor that can both import and export LaTeX. That is, you
don't create a document in LyX by entering LaTeX code into the
window opens when you select File->New.

>It's almost a week now that I'm struggling to produce anything usable
>with LyX and I have to admit I have mixed feelings about it. It's
>really easy to produce good quality documents with the default
>settings/templates. When something however doesn't look right I feel
>like my hands are tied together - usually there's no user control over
>it. I'm still not giving it up though and I'd like to ask a couple of

LaTeX which I use but not LyX.

>1) What is the best way to export graphics from Mathematica?

I generally use PDF. But I've obtained good results with both
EPS and PDF

>2) How do I export the equations from Mathematica?

I generally use TeXForm and simply copy and paste the result
into the document I am working on. For example doing:

In[3]:= f == Sum[Subscript[x, n], {n, k}] // TeXForm

Out[3]//TeXForm=
f=\sum _n^k x_n

gives a result that can be pasted directly into LaTeX document.

>3) And finally could someone please provide detailed instructions of
>how to setup LyX to interact directly with the Mathematica kernel so
>I can have some semi live  math environment. May be that way the
>equations will come in the right form

Given what LyX is, I doubt this is easily doable if at all.


 0
1/26/2009 2:49:26 AM
comp.soft-sys.math.mathematica 28821 articles. 0 followers.

5 Replies
760 Views

Similar Articles

[PageSpeed] 37

> >3) And finally could someone please provide detailed instructions of
> >how to setup LyX to interact directly with the Mathematica kernel so
> >I can have some semi live  math environment. May be that way the
> >equations will come in the right form
>
> Given what LyX is, I doubt this is easily doable if at all.

The last remark needs fact-checking. It actually works - within
limits. It's a fun feature, but I don't really use it much.

What you have to do to make it work depends on your platform. On Mac
OS X, I first created a little script
/usr/local/bin/math
containing the following two lines:
#!/bin/sh
/Applications/Mathematica.app/Contents/MacOS/MathKernel "$@" The purpose of this is simply to make the command "math" appear in the path visible to LyX, and point to the Mathematica Kernel (so obviously this is Mac specific, and I don't know the PC equivalent). Then whenever you have a calculation that you want to do in LyX, do the following: * Open a math environment. * Type the Mathematica expression you want to evaluate (e.g.: Sin[.2]) * Highlight the expression * While you are still in that math box, go to Edit > Math > Use Computer Algebra System > Mathematica * Magically, an equals sign and the result of the evaluation will appear in the LyX math box. In general, in particular when graphics is involved, I would just work with the Mathematica Notebook and the LyX editor side by side, and copy/paste between the two. In LyX 1.6, you can paste graphics into LyX from the clipboard. Equations in Mathematica's TeXForm can be pasted directly into LyX math environments. In the other direction, you can copy LaTeX from LyX into Mathematica as follows: * enter the desired math expression in LyX (e.g., \sin\alpha) * select all the _contents_ of the math box, but not the math box object itself (i.e., stop highlighting when you reach the end of the math inset). * Copy * Paste literally into a Mathematica Cell, perhaps wrapped by something like ToExpression["\sin\alpha", TeXForm] (where the pasted text goes between the quotation marks) * The result can then be used in Mathematica Labels etc. Although LyX has a non-LaTeX internal file format, everything it does goes through LaTeX, and in particular all its equations can be understood by other LaTeX-aware programs. One may still ask why anyone would you use LyX instead of Mathematica to write equations. I think this has already been addressed, and it may really be a matter of taste - but it's worth pointing out that LyX has unlimited Undo and version control (there's more, but I better stop here). As for the customization of the LyX output, it's true that this isn't trivial if you don't know much LaTeX. The LyX-users mailing list would be a place to start, they are very helpful... Jens   0 noeckel (62) 1/26/2009 10:01:35 AM Hi, if I understand you correctly, the \text{ } is the (correct) response by Mathematica to your entering single-letter variabes without spaces between them. I.e., try TeXForm[ a b ] versus TeXForm[ ab ] So you just have to make sure you write multiplications of variables with spaces in between. If you're referring to something more complicated, an example would help. Jens On Jan 26, 2009, at 8:26 AM, TL wrote: > That's what I was looking for, thanks a lot JUN! > > I have a WinXP environment here and I'm not sure your instructions > will work but at least that's an excellent starting point. > As for pasting content from Mathematica I noticed one really > annoying fact, that's actually mentioned in the Mathematica help as > well - when there are two or more symbol variables in your > equations Mathematica treats them as text and displays them as > such, the result being that part of the equation appears in italic > font part in regular. I think that was the root of my issues in > some of my previous posts and now it's haunting me in other > environments too, cause the LaTeX form of the equations that is > exported by Mathematica contains a whole bunch of text{} tags that > I have to manually get rid of > > Does someone know how to change that behaviour? > > JUN wrote: >>>> 3) And finally could someone please provide detailed >>>> instructions of >>>> how to setup LyX to interact directly with the Mathematica >>>> kernel so >>>> I can have some semi live math environment. May be that way the >>>> equations will come in the right form >>>> >>> Given what LyX is, I doubt this is easily doable if at all. >>> >> >> The last remark needs fact-checking. It actually works - within >> limits. It's a fun feature, but I don't really use it much. >> >> What you have to do to make it work depends on your platform. On Mac >> OS X, I first created a little script >> /usr/local/bin/math >> containing the following two lines: >> #!/bin/sh >> /Applications/Mathematica.app/Contents/MacOS/MathKernel "$@"
>>
>> The purpose of this is simply to make the command "math" appear in
>> the
>> path visible to LyX, and point to the Mathematica Kernel (so
>> obviously
>> this is Mac specific, and I don't know the  PC equivalent). Then
>> whenever you have a calculation that you want to do in LyX, do the
>> following:
>> * Open a math environment.
>> * Type the Mathematica expression you want to evaluate (e.g.: Sin[.
>> 2])
>> * Highlight the expression
>> * While you are still in that math box, go to Edit > Math > Use
>> Computer Algebra System > Mathematica
>> * Magically, an equals sign and the result of the evaluation will
>> appear in the LyX math box.
>>
>> In general, in particular when graphics is involved, I would just
>> work
>> with the Mathematica Notebook and the LyX editor side by side, and
>> copy/paste between the two. In LyX 1.6, you can paste graphics into
>> LyX from the clipboard. Equations in Mathematica's TeXForm can be
>> pasted directly into LyX math environments.
>>
>> In the other direction, you can copy LaTeX from LyX into Mathematica
>> as follows:
>> * enter the desired math expression in LyX (e.g., \sin\alpha)
>> * select all the _contents_ of the math box, but not the math box
>> object itself (i.e., stop highlighting when you reach the end of the
>> math inset).
>> * Copy
>> * Paste literally into a Mathematica Cell, perhaps wrapped by
>> something like ToExpression["\sin\alpha", TeXForm] (where the pasted
>> text goes between the quotation marks)
>> * The result can then be used in Mathematica Labels etc.
>>
>> Although LyX has a non-LaTeX internal file format, everything it does
>> goes through LaTeX, and in particular all its equations can be
>> understood by other LaTeX-aware programs. One may still ask why
>> anyone
>> would you use LyX instead of Mathematica to write equations. I think
>> this has already been addressed, and it may really be a matter of
>> taste - but it's worth pointing out that LyX has unlimited Undo and
>> version control (there's more, but I better stop here).
>>
>> As for the customization of the LyX output, it's true that this isn't
>> trivial if you don't know much LaTeX. The LyX-users mailing list
>> would
>> be a place to start, they are very helpful...
>>
>> Jens
>>
>>
>>
>


 0
noeckel (62)
1/27/2009 12:00:05 PM
That's what I was looking for, thanks a lot JUN!

I have a WinXP environment here and I'm not sure your instructions will
work but at least that's an excellent starting point.
As for pasting content from Mathematica I noticed one really annoying
fact, that's actually mentioned in the Mathematica help as well - when
there are two or more symbol variables in your equations Mathematica
treats them as text and displays them as such, the result being that
part of the equation appears in italic font part in regular. I think
that was the root of my issues in some of my previous posts and now it's
haunting me in other environments too, cause the LaTeX form of the
equations that is exported by Mathematica contains a whole bunch of
text{} tags that I have to manually get rid of

Does someone know how to change that behaviour?

JUN wrote:
>>> 3) And finally could someone please provide detailed instructions of
>>> how to setup LyX to interact directly with the Mathematica kernel so
>>> I can have some semi live  math environment. May be that way the
>>> equations will come in the right form
>>>
>> Given what LyX is, I doubt this is easily doable if at all.
>>
>
> The last remark needs fact-checking. It actually works - within
> limits. It's a fun feature, but I don't really use it much.
>
> What you have to do to make it work depends on your platform. On Mac
> OS X, I first created a little script
> /usr/local/bin/math
> containing the following two lines:
> #!/bin/sh
> /Applications/Mathematica.app/Contents/MacOS/MathKernel "$@" > > The purpose of this is simply to make the command "math" appear in the > path visible to LyX, and point to the Mathematica Kernel (so obviously > this is Mac specific, and I don't know the PC equivalent). Then > whenever you have a calculation that you want to do in LyX, do the > following: > * Open a math environment. > * Type the Mathematica expression you want to evaluate (e.g.: Sin[.2]) > * Highlight the expression > * While you are still in that math box, go to Edit > Math > Use > Computer Algebra System > Mathematica > * Magically, an equals sign and the result of the evaluation will > appear in the LyX math box. > > In general, in particular when graphics is involved, I would just work > with the Mathematica Notebook and the LyX editor side by side, and > copy/paste between the two. In LyX 1.6, you can paste graphics into > LyX from the clipboard. Equations in Mathematica's TeXForm can be > pasted directly into LyX math environments. > > In the other direction, you can copy LaTeX from LyX into Mathematica > as follows: > * enter the desired math expression in LyX (e.g., \sin\alpha) > * select all the _contents_ of the math box, but not the math box > object itself (i.e., stop highlighting when you reach the end of the > math inset). > * Copy > * Paste literally into a Mathematica Cell, perhaps wrapped by > something like ToExpression["\sin\alpha", TeXForm] (where the pasted > text goes between the quotation marks) > * The result can then be used in Mathematica Labels etc. > > Although LyX has a non-LaTeX internal file format, everything it does > goes through LaTeX, and in particular all its equations can be > understood by other LaTeX-aware programs. One may still ask why anyone > would you use LyX instead of Mathematica to write equations. I think > this has already been addressed, and it may really be a matter of > taste - but it's worth pointing out that LyX has unlimited Undo and > version control (there's more, but I better stop here). > > As for the customization of the LyX output, it's true that this isn't > trivial if you don't know much LaTeX. The LyX-users mailing list would > be a place to start, they are very helpful... > > Jens > > >   0 latev (13) 1/27/2009 12:01:11 PM Sorry I didn;t write an example Here's the issue - I have variables such as P_AB - that is P and AB as an index. Mathematica writes \text{} whenever it sees the AB which is unwanted - I want the whole thing to appear in italic form. May be it's a standard convention I'm not really sure, but it just looks ugly and I looked in some math books and saw it all written in italic font there. So is there a way to turn this off? Jens Noeckel wrote: > Hi, > if I understand you correctly, the \text{ } is the (correct) > response by Mathematica to your entering single-letter variabes > without spaces between them. I.e., try > TeXForm[ a b ] > versus > TeXForm[ ab ] > > So you just have to make sure you write multiplications of variables > with spaces in between. If you're referring to something more > complicated, an example would help. > > Jens > > > On Jan 26, 2009, at 8:26 AM, TL wrote: > >> That's what I was looking for, thanks a lot JUN! >> >> I have a WinXP environment here and I'm not sure your instructions >> will work but at least that's an excellent starting point. >> As for pasting content from Mathematica I noticed one really annoying >> fact, that's actually mentioned in the Mathematica help as well - >> when there are two or more symbol variables in your equations >> Mathematica treats them as text and displays them as such, the result >> being that part of the equation appears in italic font part in >> regular. I think that was the root of my issues in some of my >> previous posts and now it's haunting me in other environments too, >> cause the LaTeX form of the equations that is exported by Mathematica >> contains a whole bunch of text{} tags that I have to manually get rid of >> >> Does someone know how to change that behaviour? >> >> JUN wrote: >>>>> 3) And finally could someone please provide detailed instructions of >>>>> how to setup LyX to interact directly with the Mathematica kernel so >>>>> I can have some semi live math environment. May be that way the >>>>> equations will come in the right form >>>>> >>>> Given what LyX is, I doubt this is easily doable if at all. >>>> >>> >>> The last remark needs fact-checking. It actually works - within >>> limits. It's a fun feature, but I don't really use it much. >>> >>> What you have to do to make it work depends on your platform. On Mac >>> OS X, I first created a little script >>> /usr/local/bin/math >>> containing the following two lines: >>> #!/bin/sh >>> /Applications/Mathematica.app/Contents/MacOS/MathKernel "$@"
>>>
>>> The purpose of this is simply to make the command "math" appear in the
>>> path visible to LyX, and point to the Mathematica Kernel (so obviously
>>> this is Mac specific, and I don't know the  PC equivalent). Then
>>> whenever you have a calculation that you want to do in LyX, do the
>>> following:
>>> * Open a math environment.
>>> * Type the Mathematica expression you want to evaluate (e.g.: Sin[.2])
>>> * Highlight the expression
>>> * While you are still in that math box, go to Edit > Math > Use
>>> Computer Algebra System > Mathematica
>>> * Magically, an equals sign and the result of the evaluation will
>>> appear in the LyX math box.
>>>
>>> In general, in particular when graphics is involved, I would just work
>>> with the Mathematica Notebook and the LyX editor side by side, and
>>> copy/paste between the two. In LyX 1.6, you can paste graphics into
>>> LyX from the clipboard. Equations in Mathematica's TeXForm can be
>>> pasted directly into LyX math environments.
>>>
>>> In the other direction, you can copy LaTeX from LyX into Mathematica
>>> as follows:
>>> * enter the desired math expression in LyX (e.g., \sin\alpha)
>>> * select all the _contents_ of the math box, but not the math box
>>> object itself (i.e., stop highlighting when you reach the end of the
>>> math inset).
>>> * Copy
>>> * Paste literally into a Mathematica Cell, perhaps wrapped by
>>> something like ToExpression["\sin\alpha", TeXForm] (where the pasted
>>> text goes between the quotation marks)
>>> * The result can then be used in Mathematica Labels etc.
>>>
>>> Although LyX has a non-LaTeX internal file format, everything it does
>>> goes through LaTeX, and in particular all its equations can be
>>> understood by other LaTeX-aware programs. One may still ask why anyone
>>> would you use LyX instead of Mathematica to write equations. I think
>>> this has already been addressed, and it may really be a matter of
>>> taste - but it's worth pointing out that LyX has unlimited Undo and
>>> version control (there's more, but I better stop here).
>>>
>>> As for the customization of the LyX output, it's true that this isn't
>>> trivial if you don't know much LaTeX. The LyX-users mailing list would
>>> be a place to start, they are very helpful...
>>>
>>> Jens
>>>
>>>
>>>
>>
>
>


 0
latev (13)
1/28/2009 11:33:36 AM
On Jan 28, 3:33 am, TL <la...@shaw.ca> wrote:
> Sorry I didn;t write an example
>
> Here's the issue - I have variables such as P_AB - that is P and AB as
> an index. Mathematica writes \text{} whenever it sees the AB which is
> unwanted - I want the whole thing to appear in italic form. May be it's
> a standard convention I'm not really sure, but it just looks ugly and I
> looked in some math books and saw it all written in italic font there.
> So is there a way to turn this off?

Actually Mathematica is doing the stylistically correct thing here
because AB is a single name according to what you describe. In LaTeX,
authors sometimes get lazy and type names in math environments without
surrounding them by \text or similar things, but then LaTeX not only
sets them in italics but can get fooled into typesetting them the
wrong way because it doesn't know all characters belong to one name.

So you should in fact declare textual names as such. The best approach
depends a lot on what you're actually trying to do with your
expression in Mathematica itself (manipulate it algebraically, use it
as a label, etc.). To "emulate" the lazy italic LaTeX text, you could
mislead Mathematica with the same thing that fools LaTeX: TeXForm
[Subscript[p, A B]].

Of course if you actually meant for A and B to be separate variables,
then you might also want to consider using Subscript[p, A, B] to avoid
any ambiguities.


 0
noeckel (62)
2/1/2009 9:40:49 AM