# Can TeXForm be forced not to wrap variables in \text{}?

I have a number of long equations in Mathematica that I need to transfer to $$\LaTeX$$. Unfortunately, the equations involve many variables and TeXForm wraps the variables in \text{}. My plan was to go through using find and replace to change the Mathematica variable names to readable formats, like f1 to f_1. But it seems excessive to have all these \text{} and I will have to additionally wrap things in  in order to have math mode inside the \text{}.

Has anybody dealt with this before? Is there a way to make TeXForm not wrap things in \text{}?

• Maybe someone with more experience with TeXForm will know what you mean, but could you include an example? I tried TeXForm[y==Exp[-\[Alpha] l Subscript[x, 3]] and got y=e^{\alpha (-l) x_3} ($y=e^{\alpha (-l) x_3}$) so it seems like it works just fine, but obviously I'm not properly replicating whatever issue you're having. – MassDefect Feb 6 at 16:13
• Yes, this certainly does happen. For example f1 = x + 7 results in \text{f1}=x+7. – JimB Feb 6 at 16:44
• @JimB Ah, I see now. It's a problem when there's a variable and a non-subscripted number. I guess the question does provide that example, I just didn't understand. – MassDefect Feb 6 at 16:51

You want to do somthing like this code:

(f1 == x + 7) /. {f1 -> Subscript[f, 1]} // TeXForm


which returns

f_1=x+7


and use similar substitution rules for all your subscripted variables. A simple example of how this can be done is this code:

rulex = Table[ToExpression["x" <> ToString@n] -> Subscript[x, n], {n, 3}];
(L == a x1 + b x2 + c x3) /. rulex // TeXForm


which returns

L=a x_1+b x_2+c x_3