1
$\begingroup$

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{}?

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – MassDefect Feb 6 at 16:13
  • $\begingroup$ Yes, this certainly does happen. For example f1 = x + 7 results in \text{f1}=x+7. $\endgroup$ – JimB Feb 6 at 16:44
  • $\begingroup$ @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. $\endgroup$ – MassDefect Feb 6 at 16:51
2
$\begingroup$

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
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.