Multiplication sign in TeXForm?

How do I get Mathematica to produce TeX output that does not omit the multiplication signs ?

For example, this expression:

(z03*z14*z32 + z01*z12*z43 + z14*(z01 + z03 + z12 + z32)*z43)


displays in Mathematica as:

(z14 z43 (z01+z03+z12+z32)+z01 z12 z43+z03 z14 z32)


And the output of TeXForm look like this:

$$\text{z14} \text{z43} (\text{z01}+\text{z03}+\text{z12}+\text{z32})+\text{z01} \text{z12} \text{z43}+\text{z03} \text{z14} \text{z32}$$

which is really hard to read because the spaces get ignored.

How do I get TeXForm to produce this instead ?: $$\text{z14}\times\text{z43}\times(\text{z01}+\text{z03}+\text{z12}+\text{z32})+\text{z01}\times\text{z12}\times\text{z43}+\text{z03}\times\text{z14}\times\text{z32}$$

Even better would be:

$$\text{z14}.\text{z43}.(\text{z01}+\text{z03}+\text{z12}+\text{z32})+\text{z01}.\text{z12}.\text{z43}+\text{z03}.\text{z14}.\text{z32}$$

Worse come to worse, I could even settle for something like this: $$\text{z14}\;\text{z43}\;(\text{z01}+\text{z03}+\text{z12}+\text{z32})+\text{z01}\;\text{z12}\;\text{z43}+\text{z03}\;\text{z14}\;\text{z32}$$

-
Use a string and \[Times] instead of * for multiplication? –  rm -rf Dec 19 '13 at 4:10

3 Answers

Here is a very robust (!!) method

expr = (z14 z43 (z01 + z03 + z12 + z32) + z01 z12 z43 + z03 z14 z32);
StringReplace[ToString[expr, TeXForm], " " :> "\\times"]


Using Ctrl+Shift+C to copy as plain text results in

$$\text{z14}\times\text{z43}\times(\text{z01}+\text{z03}+\text{z12}+\text{z32})+\text{z01}\times\text{z12}\times\text{z43}+\text{z03}\times\text{z14}\times\text{z32}$$

Edit

The above approach might serve you well in the simple setting the OP is representing, in general, this method is very likely to break, because it relies on that a multiplication is converted into a single space in TeXForm.

As questions in our latex tag suggest, there are several problems and subtilities with TeXForm and a general and always working answer can hardly be given at this point without further information.

-
This works, thanks –  blondiepassesby Dec 19 '13 at 21:14
well, now that I am starting to use your trick more, I find that it is not that robust. It works most of the time, but fails when there is a greek letter in the expression: for some reason, Mathematica adds a space after greek letters in the TeXForm output, and that gets caught as a mutltiply by your strignreplace technique. Darn. –  blondiepassesby Jan 5 at 18:25
@blondiepassesby I thought you were aware that the italic very robust in my answer was more a warning sign than a statement?! I was really meant ironically, because I was afraid that it might not work in certain cases. –  halirutan Jan 6 at 0:16
Hmm. Not entirely sure that irony is that helpful or even encouraged on stackexchange answers, especially the kind that may or may not be picked by readers of your answers. I certainly didn't read it as such and accepted your answer at face value. In future, I'd recommend being as explicit as possible. –  blondiepassesby Jan 7 at 8:06
@blondiepassesby First, I'm sorry that you haven't been able to pick up that it meant use it with caution. I thought it was obvious, that a string-replacement in the final texform will not work in all possible circumstances. You are free to unaccept my answer. But before you recommend something, I want you to recall that everyone answering here is very likely doing it in his free time, just for fun. If you want a general solution, free of irony, you just have to pay money and you'll get a totally serious answer/solution. –  halirutan Jan 7 at 11:21

Row appears to work:

expr = (z03*z14*z32 + z01*z12*z43 + z14*(z01 + z03 + z12 + z32)*z43);
expr /. Times :> (Row[{##}, "\[Times]"] &) // TeXForm


Copying as plain text as halirutan did and wrapping in $ symbols:$\text{z14}\times \text{z01}+\text{z03}+\text{z12}+\text{z32}\times \text{z43}+\text{z01}\times \text{z12}\times \text{z43}+\text{z03}\times \text{z14}\times \text{z32}$- Hmm, does this really work for you? Here, I get this output. – halirutan Dec 19 '13 at 23:41 @halirutan In version 7, yes, it does. I already voted for your answer. (Does a space always represent multiplication in TeX?) – Mr.Wizard Dec 20 '13 at 2:21 We want cross? Let's use Cross! expr /. Times -> Cross // TeXForm $ \text{z14}\times (\text{z01}+\text{z03}+\text{z12}+\text{z32})\times \text{z43}+\text{z01}\times \text{z12}\times \text{z43}+\text{z03}\times \text{z14}\times \text{z32} \$

-