[Tutor] Splitting strings into blocks
Daniel Watkins
daniel at thewatkins.org.uk
Sun Apr 30 17:34:57 CEST 2006
Hi list,
I'm currently working on a program to parse LaTeX style maths expressions and
provide an answer. For example, I have the expression "2^\frac{1}{2}". I'm
trying to work out a way to split this into it's most basic blocks of LaTeX
(i.e. 2^ and \frac{1}{2}) while maintaining a record of the depth of the
expression (i.e. (2^,0),(\frac{1}{2},1)). I will then process this list from
the highest order downwards, feeding the deeper results progressively into
shallower elements until all have been calculated.
LaTeX allows me to legally express the previously stated expression as
"{2^{\\frac{1}{2}}}". This makes it much easier to figure out where the units
of LaTeX are located. The depth of any item can now be expressed as the
number of unpaired opening or closing braces between the element and the
start or end of the expression.
I'm essentially looking for a way to split the string up along the braces,
while recording the number of braces between the split and either end of the
expression.
Any help would be much appreciated.
Cheers,
Dan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20060430/99b2962a/attachment.pgp
More information about the Tutor
mailing list