Just so you know, I've been able to clean the code for the user script to the point where I think I can easily extend it: in particular, the double escaping is gone and there is much less string manipulation. The script now handles double quotes inside equations properly.