3

When I run the following code in Mathematica:

  mat = {{x1,x2,x3,x6,x7,x8,x11,x12},{x3,x1,x2,x8,x6,x7,x11,x12},{x3,x2,x1,x8,x7,x6,x12,x11},{x2,x3,x1,x7,x8,x6,x11,x12},{x1,x3,x2,x6,x8,x7,x12,x11},{x2,x1,x3,x7,x6,x8,x12,x11},{x4,x4,x4,x9,x9,x9,x13,x13},{x5,x5,x5,x10,x10,x10,x14,x14}}

res = Det[mat];

Factor[res]

I get the following output.

$$-9 (x11-x12) (x2 x6-x3 x6-x1 x7+x3 x7+x1 x8-x2 x8)^2 (-2 x1 x10 x13-2 x10 x13 x2-2 x10 x13 x3+3 x10 x11 x4+3 x10 x12 x4-2 x14 x4 x6+2 x13 x5 x6-2 x14 x4 x7+2 x13 x5 x7-2 x14 x4 x8+2 x13 x5 x8+2 x1 x14 x9+2 x14 x2 x9+2 x14 x3 x9-3 x11 x5 x9-3 x12 x5 x9)$$

Formatted as $\LaTeX$, the output is:

-9 (\text{x11}-\text{x12}) (-\text{x1} \text{x7}+\text{x1} \text{x8}+\text{x2} \text{x6}-\text{x2} \text{x8}-\text{x3} \text{x6}+\text{x3} \text{x7})^2 ...

Question

Is there any way to get the $\LaTeX$ output to be formatted as subscripted variables instead?

-9 (x_{11}-x_{12}) (-x_1 x_7+x_1 x_8+x_2 x_6-x_2 x_8-x_3 x_6+x_3 x_7)^2...

I could not get TeXForm to work either.

xzczd
  • 65,995
  • 9
  • 163
  • 468
Moo
  • 3,260
  • 1
  • 12
  • 28

1 Answers1

4

This is a possible workaround.

alist = ToExpression["x" <> ToString[#] & /@ Range[15]]
blist = Table[Subscript[x, i], {i, 1, 15}]
rules = Thread[Rule[alist, blist]]

$$\left\{\text{x1}\to x_1,\text{x2}\to x_2,\text{x3}\to x_3,\text{x4}\to x_4,\text{x5}\to x_5,\text{x6}\to x_6,\text{x7}\to x_7,\text{x8}\to x_8,\text{x9}\to x_9,\text{x10}\to x_{10},\text{x11}\to x_{11},\text{x12}\to x_{12},\text{x13}\to x_{13},\text{x14}\to x_{14},\text{x15}\to x_{15}\right\}$$


mat = {{x1, x2, x3, x6, x7, x8, x11, x12}, {x3, x1, x2, x8, x6, x7, 
   x11, x12}, {x3, x2, x1, x8, x7, x6, x12, x11}, {x2, x3, x1, x7, x8,
    x6, x11, x12}, {x1, x3, x2, x6, x8, x7, x12, x11}, {x2, x1, x3, 
   x7, x6, x8, x12, x11}, {x4, x4, x4, x9, x9, x9, x13, x13}, {x5, x5,
    x5, x10, x10, x10, x14, x14}}
res = Det[mat];
expr = Factor[res]
expr /. rules // TeXForm

(*

-9 \left(x_2 x_6-x_3 x_6-x_1 x_7+x_3 x_7+x_1 x_8-x_2 x_8\right){}^2 \left(x_{11}-x_{12}\right) \left(-3 x_5 x_9 x_{11}+3 x_4 x_{10} x_{11}-3 x_5 x_9 x_{12}+3 x_4 x_{10} x_{12}+2 x_5 x_6 x_{13}+2 x_5 x_7 x_{13}+2 x_5 x_8 x_{13}-2 x_1 x_{10} x_{13}-2 x_2 x_{10} x_{13}-2 x_3 x_{10} x_{13}-2 x_4 x_6 x_{14}-2 x_4 x_7 x_{14}-2 x_4 x_8 x_{14}+2 x_1 x_9 x_{14}+2 x_2 x_9 x_{14}+2 x_3 x_9 x_{14}\right)

*)

As LateX:

$$-9 \left(x_2 x_6-x_3 x_6-x_1 x_7+x_3 x_7+x_1 x_8-x_2 x_8\right){}^2 \left(x_{11}-x_{12}\right) \left(-3 x_5 x_9 x_{11}+3 x_4 x_{10} x_{11}-3 x_5 x_9 x_{12}+3 x_4 x_{10} x_{12}+2 x_5 x_6 x_{13}+2 x_5 x_7 x_{13}+2 x_5 x_8 x_{13}-2 x_1 x_{10} x_{13}-2 x_2 x_{10} x_{13}-2 x_3 x_{10} x_{13}-2 x_4 x_6 x_{14}-2 x_4 x_7 x_{14}-2 x_4 x_8 x_{14}+2 x_1 x_9 x_{14}+2 x_2 x_9 x_{14}+2 x_3 x_9 x_{14}\right)$$

Syed
  • 52,495
  • 4
  • 30
  • 85