Drawing formulas with Quartz 2d
Asked Answered
D

2

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.

Distraction answered 25/5, 2010 at 17:42 Comment(0)
P
9

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.

Procession answered 25/5, 2010 at 20:27 Comment(1)
+1. Welcome to the [latex] tag: hope to see you around here more.Commercialism
C
2

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.

Commercialism answered 25/5, 2010 at 19:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.