This question involved quite a bit of squirrely debugging; I made suggestions, and the author did the testing:
Auto index complicated formulas with catcode Question: All suggestions and testing were done via comments. Now that the results are successful, is it worthwhile to reiterate everything in a formal answer, or is the original problem insufficiently general that it will help someone in the future?