Equation style display

Dear all,
I was wondering if there is a way to get the "pretty formatted" version of an equation (from an NSString) to display within a view (similar to the way Graph.app displays it).
The question is open, any means is acceptable (if not too farfetched).
I know I can get a .png version using a call to a php script, but since MAC OS already ships with softwares capable of doing it, maybe there is a more elegant (and simple) way of implementing this feature.
Any idea ?
With my thanks,
Jean 
Would not NSAttributedString be of use?
koko
On Jul 2, 2012, at 9:55 AM, Jean Suisse wrote:
> Dear all,
>
> I was wondering if there is a way to get the "pretty formatted" version of an equation (from an NSString) to display within a view (similar to the way Graph.app displays it).
> The question is open, any means is acceptable (if not too farfetched).
> I know I can get a .png version using a call to a php script, but since MAC OS already ships with softwares capable of doing it, maybe there is a more elegant (and simple) way of implementing this feature.
>
> Any idea ?
>
> With my thanks,
> Jean
>

Le 2 juil. 2012 à 17:55, Jean Suisse a écrit :
> Dear all,
>
> I was wondering if there is a way to get the "pretty formatted" version of an equation (from an NSString) to display within a view (similar to the way Graph.app displays it).
> The question is open, any means is acceptable (if not too farfetched).
> I know I can get a .png version using a call to a php script, but since MAC OS already ships with softwares capable of doing it, maybe there is a more elegant (and simple) way of implementing this feature.
>
> Any idea ?
>
Using MathML and a WebView ?
That said, I don't know what version of the WebKit (and so Mac OS) is required to use MathML.
There is some javascript/css library that let you display them properly if MathML is not supported like http://www.mathjax.org
> With my thanks,
> Jean
>
 JeanDaniel 
Thank you for your reply.
Well, I don't know about the Attributed String. The idea is to get the pretty print of thing like
(9/10) * sin( x/(2*t) )
without having to process the string myself.
On 2 juil. 2012, at 18:15, koko wrote:
> Would not NSAttributedString be of use?
>
> koko
>
> On Jul 2, 2012, at 9:55 AM, Jean Suisse wrote:
>
>> Dear all,
>>
>> I was wondering if there is a way to get the "pretty formatted" version of an equation (from an NSString) to display within a view (similar to the way Graph.app displays it).
>> The question is open, any means is acceptable (if not too farfetched).
>> I know I can get a .png version using a call to a php script, but since MAC OS already ships with softwares capable of doing it, maybe there is a more elegant (and simple) way of implementing this feature.
>>
>> Any idea ?
>>
>> With my thanks,
>> Jean
>>
>

Thank you for your reply. I will investigate this possibility.
Does it take much space for the rendering ? I mean, I would like to display it inside a panel (something like a sheet, or an inspector).
The pretty print is just a feature that would allow the user to quickly spot any mistake in an equation.
On 2 juil. 2012, at 18:23, JeanDaniel Dupas wrote:
>
> Le 2 juil. 2012 à 17:55, Jean Suisse a écrit :
>
>> Dear all,
>>
>> I was wondering if there is a way to get the "pretty formatted" version of an equation (from an NSString) to display within a view (similar to the way Graph.app displays it).
>> The question is open, any means is acceptable (if not too farfetched).
>> I know I can get a .png version using a call to a php script, but since MAC OS already ships with softwares capable of doing it, maybe there is a more elegant (and simple) way of implementing this feature.
>>
>> Any idea ?
>>
>
> Using MathML and a WebView ?
>
> That said, I don't know what version of the WebKit (and so Mac OS) is required to use MathML.
>
> There is some javascript/css library that let you display them properly if MathML is not supported like http://www.mathjax.org
>
>> With my thanks,
>> Jean
>>
>
>  JeanDaniel
>
>
>
>

On Jul 2, 2012, at 8:55 AM, Jean Suisse wrote:
> I was wondering if there is a way to get the "pretty formatted" version of an equation (from an NSString) to display within a view (similar to the way Graph.app displays it).
> The question is open, any means is acceptable (if not too farfetched).
> I know I can get a .png version using a call to a php script, but since MAC OS already ships with softwares capable of doing it, maybe there is a more elegant (and simple) way of implementing this feature.
I'm pretty certain there's nothing already installed to do that, unless maybe WebKit has support for MathML?
—Jens 
Well, it seems that all paths leads towards Webkit and MathML… which unfortunately requires some parsing / rewriting, even for simple equations…
Thank you Jens.
Best regards,
Jean
On 2 juil. 2012, at 18:45, Jens Alfke wrote:
>
> On Jul 2, 2012, at 8:55 AM, Jean Suisse wrote:
>
>
> I'm pretty certain there's nothing already installed to do that, unless maybe WebKit has support for MathML?
>
> —Jens

Hi Jean,
In terms of parsing, I've written a library to help with that: https://github.com/davedelong/DDMathParser/ You'll probably want to do something like this:
NSString *equation = @"(9/10) * sin( $x/(2*$t) )"; // note that variables need a $ in front of them, for simplicity
NSError *error = nil;
DDExpression *expression = [DDExpression expressionFromString:equation error:&error];
Assuming parsing succeeds, it should be relatively straightforward to recurse through the resulting expression object and build up the MathML string you need.
Feel free to contact me offlist if you have specific questions.
Cheers,
Dave
On Jul 2, 2012, at 10:19 AM, Jean Suisse wrote:
> Well, it seems that all paths leads towards Webkit and MathML… which unfortunately requires some parsing / rewriting, even for simple equations…
> Thank you Jens.
>
> Best regards,
> Jean

Mathematical typesetting is actually incredibly complex, and people like Donald Knuth have dedicated significant portions of their careers to it. There's no simple way to go from a textual representation of a formula to a typeset version, not least of which because there's no universally agreedupon textual representation or typeset version.
I'd also recommend using a web view to display an equation, along with one of the JavaScript TeXtoHTML rendering packages. Stack Exchange uses one for their Mathematics Q&A site that seems to work pretty well. However, note that it's not instant.
 Chris
On Jul 2, 2012, at 8:55 AM, Jean Suisse <jean.lists...> wrote:
> Dear all,
>
> I was wondering if there is a way to get the "pretty formatted" version of an equation (from an NSString) to display within a view (similar to the way Graph.app displays it).
> The question is open, any means is acceptable (if not too farfetched).
> I know I can get a .png version using a call to a php script, but since MAC OS already ships with softwares capable of doing it, maybe there is a more elegant (and simple) way of implementing this feature.
>
> Any idea ?
>
> With my thanks,
> Jean

Dave, Chris,
Thank you so much for your reply. I did check the library at https://github.com/davedelong/DDMathParser/. It incredibly nice. I am grateful to Dave for developing & sharing it.
Il will now investigate the parsing + mathML conversion combined with rendering possibility.
Thanks all for helping me to go forward with my project.
Jean
On 2 juil. 2012, at 21:01, Chris Hanson wrote:
> Mathematical typesetting is actually incredibly complex, and people like Donald Knuth have dedicated significant portions of their careers to it. There's no simple way to go from a textual representation of a formula to a typeset version, not least of which because there's no universally agreedupon textual representation or typeset version.
>
> I'd also recommend using a web view to display an equation, along with one of the JavaScript TeXtoHTML rendering packages. Stack Exchange uses one for their Mathematics Q&A site that seems to work pretty well. However, note that it's not instant.
>
>  Chris
>
> On Jul 2, 2012, at 8:55 AM, Jean Suisse <jean.lists...> wrote:
>
>> Dear all,
>>
>> I was wondering if there is a way to get the "pretty formatted" version of an equation (from an NSString) to display within a view (similar to the way Graph.app displays it).
>> The question is open, any means is acceptable (if not too farfetched).
>> I know I can get a .png version using a call to a php script, but since MAC OS already ships with softwares capable of doing it, maybe there is a more elegant (and simple) way of implementing this feature.
>>
>> Any idea ?
>>
>> With my thanks,
>> Jean