Changes to fix compatability with texmath 0.7
Generalised more in Parsing.hs to enable the use of custom state