Hello! I have this code
K[Q_, n_Integer] :=
Module[{z, x},
SymmetricReduction[
SeriesCoefficient[
Product[ComposeSeries[Series[Q[z], {z, 0, n}],
Series[x[i] z, {z, 0, n}]], {i, 1, n}], n],
Table[x[i], {i, 1, n}], Table[Subscript[c, i], {i, 1, n}]][[1]]]
primeFactorForm[n_] :=
If[Length@# == 1, First@#, CenterDot @@ #] &[
Superscript @@@ FactorInteger[n]];
string = StringJoin[
Riffle[Table[poly = K[Sqrt[#]/Tanh[Sqrt[#]] &, i] /. c -> p;
gcd = GCD @@ List @@ poly /. Rational[n_, d_]*c_ :> d;
ToString[
Inactive[Set][Subscript[L, i],
1/primeFactorForm[gcd]*Plus @@ List @@ Distribute[gcd*poly] /.
Times[Rational[n_, d_], e__] :>
RowBox[{primeFactorForm[n]/primeFactorForm[d], e}] /.
x_ :> TraditionalForm@
DisplayForm@
RowBox[{1/Denominator[x], "(", Numerator[x], ")"}]],
TeXForm], {i, 3, 7}], "\\\\"]]
CopyToClipboard[string]
which gives an output like this: $L_3=\frac{1}{3^3\cdot 5^1\cdot 7^1}(2 p_1^3-13 p_2 p_1+62 p_3)\\L_4=\frac{1}{3^3\cdot 5^2\cdot 7^1}(-p_1^4+\frac{-1^1\cdot 19^1}{3^1}p_2^2+\frac{-1^1\cdot 71^1}{3^1}p_1p_3+\frac{2^1\cdot 11^1}{3^1}p_1^2p_2+127 p_4)\\L_5=\frac{1}{3^4\cdot 5^1\cdot 11^1}(\frac{2^1}{3^1\cdot 7^1}p_1^5+\frac{2^1\cdot 73^1}{3^1}p_5+\frac{-1^1\cdot 83^1}{3^1\cdot 5^1\cdot 7^1}p_1^3p_2+\frac{-1^1\cdot 919^1}{3^1\cdot 5^1\cdot 7^1}p_1p_4+\frac{-1^1\cdot 2^4}{5^1}p_2p_3+\frac{79^1}{5^1\cdot 7^1}p_1^2p_3+\frac{127^1}{3^1\cdot 5^1\cdot 7^1}p_1p_2^2)\\L_6=\frac{1}{3^5\cdot 5^2\cdot 7^2\cdot 11^1\cdot 13^1}(\frac{-1^1\cdot 2^1\cdot 691^1}{3^1\cdot 5^1}p_1^6+\frac{-1^1\cdot 167^1\cdot 241^1}{3^1\cdot 5^1}p_3^2+\frac{2^1\cdot 23^1\cdot 89^1\cdot 691^1}{3^1\cdot 5^1}p_6+\frac{2^1\cdot 1453^1}{5^1}p_2^3+\frac{-1^1\cdot 33863^1}{3^1\cdot 5^1}p_1^3p_3+\frac{-1^1\cdot 159287^1}{3^1\cdot 5^1}p_2p_4+\frac{2^1\cdot 6421^1}{3^1\cdot 5^1}p_1^4p_2+\frac{-1^1\cdot 5527^1}{3^1}p_1^2p_2^2+\frac{-1^1\cdot 2^5\cdot 29^1\cdot 181^1}{5^1}p_1p_5+\frac{40841^1}{5^1}p_1^2p_4+\frac{83^1\cdot 349^1}{5^1}p_1p_2p_3)\\L_7=\frac{1}{3^2\cdot 5^1\cdot 7^1\cdot 13^1}(\frac{2^2\cdot 8191^1}{3^4\cdot 5^1\cdot 11^1}p_7+\frac{2^2}{3^4\cdot 5^1\cdot 11^1}p_1^7+\frac{-1^1\cdot 2^1\cdot 23^2}{3^5\cdot 11^1}p_2p_5+\frac{-1^1\cdot 2^1\cdot 113^1}{3^4\cdot 5^1\cdot 7^1}p_1^3p_4+\frac{2^4\cdot 277^1}{3^4\cdot 5^2\cdot 7^1}p_1^2p_5+\frac{-1^1\cdot 2^1\cdot 97^1\cdot 107^1}{3^4\cdot 5^2\cdot 7^1\cdot 11^1}p_3p_4+\frac{2^3\cdot 2087^1}{3^5\cdot 5^2\cdot 7^1\cdot 11^1}p_2^2p_3+\frac{-1^1\cdot 2^1\cdot 2161^1}{3^5\cdot 5^2\cdot 7^1\cdot 11^1}p_1^5p_2+\frac{-1^1\cdot 2^1\cdot 3989^1}{3^5\cdot 5^2\cdot 7^1\cdot 11^1}p_1p_2^3+\frac{-1^1\cdot 2^1\cdot 305633^1}{3^5\cdot 5^2\cdot 7^1\cdot 11^1}p_1p_6+\frac{2^2}{5^2\cdot 7^1}p_1^4p_3+\frac{2^3}{3^2\cdot 5^1\cdot 7^1}p_1^3p_2^2+\frac{22027^1}{3^5\cdot 5^2\cdot 7^1\cdot 11^1}p_1p_3^2+\frac{-1^1\cdot 39341^1}{3^5\cdot 5^2\cdot 7^1\cdot 11^1}p_1^2p_2p_3+\frac{1399^1}{3^3\cdot 5^2\cdot 11^1}p_1p_2p_4)$ $
Is there a way to organize the variables in a more intuitive way? For example in the $L_7$ the term $p_7$ comes before $p_1$ and stuff like this happens more often the more terms I have. In general the order is not consistent. I tried some basic grouping/factorizing commands, but they don't seem to work (or I don't place them in the right place). Can someone help me with this? Thank you!