views:

278

answers:

3

In my iPhone App I'd like to draw a few formulas. How can I manage that with quartz 2d? Is there a way to build formulas like for example in latex? Or are there any existing frameworks? Thanks.

A: 

There's no real Tex engine implemented for Cocoa touch that I have heard of, but there is a lightweight Javascript formulae-layout engine: jsMath.

Charles Stewart
+1  A: 

As the developer of an iPhone application which does just that, trust me when I say typesetting equations is not a trivial undertaking. In my case, I used Core Animation layers to construct the sub-elements of a parsed equation. The equations are constructed hierarchically, and the operations that compose them are laid out as such. Each operation is contained within its parent operation's layer, and laid out following the rules of that particular operation.

For rendering the visual elements of the operations within an equation, I used Quartz to draw lines, symbols, etc., but most of the drawing was simply text drawn within a CALayer using the NSString text drawing extensions.

I did override the standard CALayer rendering architecture for the generation of PDFs from these equations, because CALayers don't render as vector elements by default. For an example of how this rendering works in my application, see the open source Core Plot project, which does the same thing at its base level.

I do output to LaTeX from the equations, which is pretty simple once you've parsed them into a hierarchical data structure, but parsing them from LaTeX into that structure is proving a little trickier.

For simple text equation input and evaluation, you might find Graham Cox's GCMathParser to be of use.

Brad Larson
+1. Welcome to the [latex] tag: hope to see you around here more.
Charles Stewart
A: 

What about MathML? I googled around too some weeks ago trying to solve the problem you described and I also thought about the approch parsing the formulas like Brad said into Latex and then using MathML display it in kind of a UIWebView or something like that? Any hints on that? Brad, could you describe the way you parsed the equotattion into Latex a little more in depth, please?

Tim Specht