10
$\begingroup$

I am creating Taylor polynomials and exporting them using TeXForm. When a polynomial p[x] is displayed in Mathematica, it shows, for instance, 1+x+x^2+x^3. However, TeXForm always reverses the polynomial, giving it with largest power first:

TeXForm[p[x]] = x^3+x^2+x+1.

How can I keep the polynomial in the same order? Taylor polynomials are generally thought of as being constructed from low-to-high powers, so reading them in the generated format is a bit confusing to some.

$\endgroup$
1

2 Answers 2

11
$\begingroup$

Use HoldForm:

In[]:= TeXForm[HoldForm[1 + x + x^2 + x^3]]

Out[]//TeXForm= 1+x+x^2+x^3

Or for a function p[x] evaluating to a polynomial:

In[9]:= TeXForm[HoldForm[Evaluate[p[x]]]]

Out[9]//TeXForm=
1+x+x^2+x^3
$\endgroup$
4
  • $\begingroup$ This works if I copy/paste the output into TeXForm[HoldForm[...]]; I'd rather it be done automatically. Using "TeXForm[HoldForm[p[x]]]" just returns "p(x)". $\endgroup$
    – GregH
    Commented Dec 18, 2012 at 16:48
  • 2
    $\begingroup$ How about TeXForm[HoldForm[Evaluate[p[x]]]]? $\endgroup$
    – Joel Klein
    Commented Dec 18, 2012 at 17:19
  • $\begingroup$ Your answer works. If it were a separate answer, I'd accept it; it is more elegant than using an undocumented command. $\endgroup$
    – GregH
    Commented Dec 18, 2012 at 17:45
  • 1
    $\begingroup$ Answer edited to add the form for a function p[x]. $\endgroup$
    – Joel Klein
    Commented Dec 18, 2012 at 17:54
5
$\begingroup$

You can also use the undocumented (and probably deprecated, so beware!) PolynomialForm.

poly = Expand[(1+x)^10]

TeXForm@PolynomialForm[poly, TraditionalOrder -> False]

(* ==> "1+10 x+45 x^2+120 x^3+210 x^4+252 x^5+210 x^6+120 x^7+45 x^8+10 x^9+x^{10}" *)
$\endgroup$
1
  • $\begingroup$ Thanks. This works, but using TeXForm[HoldForm[Evaluate[p[x]]]] is probably better. $\endgroup$
    – GregH
    Commented Dec 18, 2012 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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