Since you want Mathematica to perform some simplifications of your expression, I don't think this is purely formatting question.
Inferring from your desired simplifications of $\rho^i\omega\rho^{-i}$ for different $i$, it is supposed to be some form of multiplication, but different than built-in Times
function.
I would start with defining desired properties of your multiplication. To get results from examples in question this should be enough:
ClearAll[myTimes]
myTimes[l___, 1, r___] := myTimes[l, r]
(* To make it more similar to multiplication, you could add something like: *)
(*myTimes[___,0,___]=0;
myTimes[l___,x_,x_,r___]:=myTimes[l,x^2,r]
myTimes[x_]:=x
myTimes[]=1;
SetAttributes[myTimes,{Flat,OneIdentity}]*)
(* but this is not needed for examples from question. *)
Now let's assign desired formatting to myTimes
function:
ClearAll[toPowerBoxes];
SetAttributes[toPowerBoxes, HoldAllComplete]
toPowerBoxes[{expr___}, form_] :=
List @@ Replace[
HoldComplete[expr],
{
Power[x_, y_] :> SuperscriptBox[MakeBoxes[x, form], MakeBoxes[y, form]],
x_ :> MakeBoxes[x, form]
},
{1}
]
MakeBoxes[HoldPattern@myTimes[expr__], StandardForm] ^:=
RowBox[{"myTimes", "[", RowBox[Riffle[toPowerBoxes[{expr}, StandardForm], ","]], "]"}]
MakeBoxes[HoldPattern@myTimes[expr__], TraditionalForm] ^:=
With[{boxes = RowBox[toPowerBoxes[{expr}, TraditionalForm]]},
InterpretationBox[boxes, myTimes[expr]]
]
Examples from question, with unevaluated s
:
Subscript[W, #][#] == myTimes[ρ^s[#] , Subscript[ω, #], ρ^-s[#]] & /@ Range[4]
% // TableForm // TraditionalForm
$\{W_1[1] == \text{myTimes}[\rho^{s[1]}, \omega_1, \rho^{-s[1]}], ...\}$
(*Out[]//TraditionalForm=*)
$W_1(1)=\rho ^{s(1)}\omega _1\rho ^{-s(1)} \\
...$
and when s
evaluates to something:
Block[{s},
s[1] = 0; s[2] = 23; s[3] = 10; s[4] = -1;
Subscript[W, #][#] == myTimes[ρ^s[#] , Subscript[ω, #], ρ^-s[#]] & /@ Range[4]
]
% // TableForm // TraditionalForm
% // TableForm // TeXForm
$\{
W_1[1] == \text{myTimes}[\omega_1],
W_2[2] == \text{myTimes}[\rho^{23}, \omega_2, \rho^{-23}],
W_3[3] == \text{myTimes}[\rho^{10}, \omega_3, \rho^{-10}],
W_4[4] == \text{myTimes}[\rho^{-1}, \omega_4, \rho]
\}$
(*Out[]//TraditionalForm=*)
$W_1(1)=\omega _1 \\
W_2(2)=\rho ^{23}\omega _2\rho ^{-23} \\
W_3(3)=\rho ^{10}\omega _3\rho ^{-10} \\
W_4(4)=\rho ^{-1}\omega _4\rho$
(*Out[]//TeXForm=
\begin{array}{c}
W_1(1)=\omega _1 \\
W_2(2)=\rho ^{23}\omega _2\rho ^{-23} \\
W_3(3)=\rho ^{10}\omega _3\rho ^{-10} \\
W_4(4)=\rho ^{-1}\omega _4\rho \\
\end{array}*)
You can also select StandardForm
expression containing myTimes
and use Copy As > LaTeX. Result is the same as output of TeXForm
.