Closed AllenDowney closed 12 years ago
not an answer, but maybe a helpful link for the issue later on: http://milde.users.sourceforge.net/LUCR/Math/
Ok, I made some progress on this. In Math.py I've got class MathSymbol with this new invoke method:
def invoke(self, tex):
a = Command.invoke(self, tex)
print 'MathSymbol.invoke'
print self, self.tagName, type(self)
if self.unicode is None:
return a
if self.unicode == -1:
code = self.tagName
else:
code = '&#x%04x;' % ord(self.unicode)
o = self.ownerDocument.createElement('mathsymbol')
child = self.ownerDocument.createTextNode(code)
o.append(child)
self.ownerDocument.context.push(o)
return [o]
Seems to be working, although the ampersand is getting expanded. I might need to escape it.
Or maybe just put in the unicode character and let it get expanded?
Groan. Well, this turns out to be easier than I made it out to be. It turns out that if you hoist any of the MathSymbols out of the math tag (which gets imaged) and into a mathphrase tag (which gets rendered) everything just works.
Greek letters in math mode get parsed into MathSymbols. Each contains the corresponding unicode character in a class variable named unicode. For example (from Math.py):
After parsing, $\alpha$ appears as an alpha tag. Which is not great for me because I want to be able to check whether something is a MathSymbol without enumerating all possible MathSymbols.
Then, I want to write a template to generate the entity.
Something like
But again, MathSymbol doesn't appear at this point, only the specific tag (alpha, beta).
So, do I have to go back and change the way MathSymbols get parsed, or can I recover the information I need during TreeCleaning?