Aside from the bugs in your code, the mactex version of tex-stripdollar
does two things that your code doesn't. First, tex-stripdollar checks
*tex-translations* to see if it should do a translation. Second,
tex-stripdollar does things like x3 --> x_3. Your code doesn't try
to do either. Why?
By the way, tex-stripdollar does have a (I suspect) un-intended feature
(bug report 1162854)
(%i5) x_0;
(%o5) x_0
(%i6) tex(%);
$$
1> (TEX-STRIPDOLLAR |$x_0|)
<1 (TEX-STRIPDOLLAR |x__0|)
x__0$$ <--------bug
(%o6) false
(%i7) tex(x0);
$$
1> (TEX-STRIPDOLLAR |$x0|)
<1 (TEX-STRIPDOLLAR |x_0|)
x_0$$ <--------OK
(%o7) false
(%i8)
Barton