# Why the difference in $\LaTeX$ expressions?

I successfully find

exp = CDF[TransformedDistribution[
x1/(x1 + x2 + x3),
{
x1 \[Distributed] UniformDistribution[{0, 1}],
x2 \[Distributed] UniformDistribution[{0, 1}],
x3 \[Distributed] UniformDistribution[{0, 1}]
}
], t]


Then I copy the output as LaTeX and obtain

$$\begin{array}{cc} \{ & \begin{array}{cc} 1 & t>1 \\ -\frac{t}{t-1} & 0<t\leq \frac{1}{3} \\ \frac{5 t^2+2 t-1}{6 t^2} & \frac{1}{2}<t\leq 1 \\ \frac{21 t^3-27 t^2+9 t-1}{6 (t-1) t^2} & \frac{1}{3}<t\leq \frac{1}{2} \\ \end{array} \\ \end{array}$$

The result is not so good. On the other hand,

exp // TeXForm


returns

$$\begin{cases} 1 & t>1 \\ -\frac{t}{t-1} & 0<t\leq \frac{1}{3} \\ \frac{5 t^2+2 t-1}{6 t^2} & \frac{1}{2}<t\leq 1 \\ \frac{21 t^3-27 t^2+9 t-1}{6 (t-1) t^2} & \frac{1}{3}<t\leq \frac{1}{2} \end{cases}$$

which is better. The questions arise: Why is the difference in the outputs observed? Can it be treated as a bug?

• If you look at the Latex, the "Copy As" version starts with \begin{array} while the TeXForm version starts with \begin{cases}. So it looks like what's happening is that the "Copy As" version is building its latex off the form of the expression while the TeXForm is building its Latex from the meaning of the expression. Sep 13, 2018 at 18:10
• @bill s: Thank you. You open an opened door. Sep 13, 2018 at 18:17
• OP: I think @bills is actually on to something. If you look at the boxes that make up the formatted expression, you'll see that it is built as a GridBox—basically the same thing what you get when you use Copy As. The typeset version is just a "table" (a grid) without any meaning. The only reason it can even be converted back to a meaningful expression is the TagBox around it with the "Piecewise" marker. Sep 13, 2018 at 18:58
• Now, is it a bug? I don't know, but I would definitely report this to Wolfram. There might be a good reason why it behaves this way, but it's sure inconvenient. Sep 13, 2018 at 18:59
• Actually ... TeXForm@DisplayForm@First@ToBoxes[exp] still gives the cases version (the correct one), even though we manually removed the TagBox. So my hunch about what is happening may be wrong. Please do report it to Wolfram. Sep 13, 2018 at 19:01

I think this is worth reporting to support. The issue is that the TeX conversion code has a special rule when a GridBox appears at the top level of the corresponding boxes that produces the output you want. Now, the TeXForm code path strips out "identity" boxes, and ends up with a GridBox at the top level that gets converted as desired. The Copy As Latex code path does not end up with a GridBox at the top level, and so the output gets converted differently.
SystemConvertTeXFormDumpStripIdentityBoxes[BoxData @ FormBox[e_, _]] :=
SystemConvertTeXFormDumpStripIdentityBoxes[e]