This is similar to my previous question Can one prevent operators like `Factor` or `Apart` from changing full form of some algebraic expressions? but concerns $\TeX$ and I cannot figure out whether I might use the solution found there in this case. I found several questions here about $\LaTeX$ conversion, one of them (Override Equation structure change in mathematica - CopyToLaTeX) addressing this particular issue, but the only relevant answer (using HoldForm
) does not work in my case (see below).
When I export expressions to $\TeX$, some undesirable (for me) form changes occur. A minimal example is e. g. (1+q+q^2)(1-4 q)
which goes to $(1-4q)(q^2+q+1)$. This happens both while right-clicking and choosing "Copy as" -> "LaTeX" or issuing 1-q+q^2//TeXForm
.
Doing TeXForm[StandardForm[(1+q+q^2)(1-4 q)]]
helps only partially, it gives $(1-4q)(1+q+q^2)$, i. e. still interchanges the factors which I don't want to do.
In this particular case, TeXForm[HoldForm[(1+q+q^2)(1-4 q)]]
helps, but I sometimes need to export really huge expressions where HoldForm
does not work the way I want. For example, if I would have Sum[q^n,{n,0,2}](1-4q)
instead (and I frequently have large expressions like that) then TeXForm[HoldForm[Sum[q^n,{n,0,2}](1-4q)]]
gives $\left(\sum _{i=0}^2 q^i\right) (1-4 q)$ (while TeXForm[StandardForm[Sum[q^n,{n,0,2}](1-4q)]]
still interchanges factors giving $(1-4 q) \left(1+q+q^2\right)$).
Clearly it is very annoying to have to change everything back into form I need by hand, especially with large expressions. Is there a way to tell the system to convert just the expression the way it is seen, without changing anything?
TeXForm@DisplayForm@HoldForm[(1 + q + q^2) (1 - 4 q)]
work? $\endgroup$HoldForm
not work exactly? I can't figure it out from your post. Do you mean that you want the summation expanded but the factors not reordered? $\endgroup$HoldForm
. But issuingTeXForm[HoldForm[%]]
just gives\%
. Assigning some new symbol also does not work - if I say firste=%
and thenTeXForm[HoldForm[e]]
this just givese
. $\endgroup$HoldForm
just to prevent additional reordering done byTeXForm
, then you can useEvaluate
:% // Evaluate // HoldForm // TeXForm
. If you want partial evaluation like in your example withSum
, then maybe making some operationsInactive
combined withactiveForm
would work for you:Inactive[Times][Sum[q^n, {n, 0, 2}], (1 - 4 q)] // activeForm // TeXForm
, it can be combined withEvaluate // HoldForm
if needed. $\endgroup$