# Formatting Equation Output Neatly

I looked around and couldn't find the answer to this anywhere, so I'm sorry if this is a bad question - I'm pretty new to mathematica. I wrote a program to help me compute some annoying series expansions, and the output is pretty ugly, for example:

$\epsilon ^2 \left(\left(a_{5,1} a_{6,1}+a_{1,1} \left(a_{2,1}+a_{6,1}\right)\right) X_{1,2}+\left(a_{5,1} \left(a_{9,1}+a_{10,1}\right)+a_{1,1} \left(a_{3,1}+a_{9,1}+a_{10,1}\right)\right) X_{1,3}+\left(a_{5,1} \left(a_{7,1}+a_{8,1}\right)+a_{1,1} \left(a_{4,1}+a_{7,1}+a_{8,1}\right)\right) X_{1,4}+\left(a_{6,1} \left(a_{9,1}+a_{10,1}\right)+a_{2,1} \left(a_{3,1}+a_{9,1}+a_{10,1}\right)\right) X_{2,3}+\left(a_{6,1} \left(a_{7,1}+a_{8,1}\right)+a_{2,1} \left(a_{4,1}+a_{7,1}+a_{8,1}\right)\right) X_{2,4}+a_{3,1} \left(a_{4,1}+a_{7,1}+a_{8,1}\right) X_{3,4}\right)+\epsilon \left(X_3 \epsilon a_{3,2}+X_4 \epsilon a_{4,2}+X_1 \left(\epsilon a_{1,2}+\epsilon a_{5,2}+a_{1,1}+a_{5,1}\right)+X_2 \left(\epsilon a_{2,2}+\epsilon a_{6,2}+a_{2,1}+a_{6,1}\right)+X_4 \epsilon a_{7,2}+X_4 \epsilon a_{8,2}+X_3 \epsilon a_{9,2}+X_3 \epsilon a_{10,2}+X_3 a_{3,1}+X_4 a_{4,1}+X_4 a_{7,1}+X_4 a_{8,1}+X_3 a_{9,1}+X_3 a_{10,1}\right)$

I'm wondering if there's a way to have it output this in a more readable way, for example, something like:

$X_{1}*(coefficients)\\ X_{2}*(coefficients)\\ ...\\ X_{1,2}*(coefficents)\\ etc...$

Is there a way to do so? Thanks!

-
Please include the Mathematica code that produced your output for the convenience of those who wish to help. –  Mr.Wizard Mar 5 '13 at 22:17

## 1 Answer

One simple way would be something like this:

   Column@Apply[List,
Collect[Sum[Expand[(a - b)^i] X[i, j], {i, 3}, {j, 3}], _X] /.
y_*z_X :> Row[{Style[z, Bold, Red, 22] , "*(", y, ")"}]]


-
So in this case, X[1,1] is my $X_{1}$? And I'm slightly confused how to modify this code to match my case - I'm not sure what would go in for "List", for example, as I have no list. –  laplacian13 Mar 5 '13 at 22:38
So what do you have? Subscript? Please enter a Mathematica expression into the question. Please also read a bit about Mathematica, FullForm, Apply, Plus, List, etc. Or follow one of the online tutorials or go to a training or some such. –  Rolf Mertig Mar 5 '13 at 22:54
Yes, I'm just using subscripts. The subscripts do not correspond to a matrix or anything (I see now where that confusion may have come from), but rather each $X_{i}$ is a vector field, and each $X_{i,j}$ is a Lie bracket of two vector fields. I've done some tutorials and read about Mathematica, I just never found what I was looking for. –  laplacian13 Mar 5 '13 at 22:58
Just post your program to do the series expansions. Tthen people will help you. –  Rolf Mertig Mar 6 '13 at 8:35