I have an "internal" notation (since some stuff is equivalent and can be manipulated via patterned expressions in the function F), say


But for output I'd like the easier readable $c_3b_2a_3c_1$. Happily, I enter

G[] := "";
G[X___, Y_, i_] := "G[X]" <> "Subscript[Y,i]";

Epic fail. Even in a function definition I can't match patterns inside a string since G[X] is exactly that - X is no variable on the RHS here.

G[] := Nothing; (* or something like that *)
G[X___, Y_, i_] := G[X]Subscript[Y,i];

would be a clever hack but alas, the implied multiplication is commutative and ruins the (fixed) ordering. Frankly, even if I would replace the implicit * with a ** and the latter could be printed invisible that would be horrible style.

G[] := "";
G[X___, Y_, i_] := ToString[G[X]] <> ToString[Subscript[Y, i]];

Nice try but no.

How would you do it? I don't care if the output is a string or an expression, it suffices if it looks like above. (Also note that my output is a list of F expressions, so I will map a head replace F->G over the list and define G separately.)


G[] := "";
G[X___, Y_] := ToString[G[X]] <> ToString[Y];

avoiding the subscript trouble gets 4 of 5 points, if my task is impossible.


1 Answer 1


Something equivalent to what you tried to do can be done by defining the output format for F:

Format[F[x__], TraditionalForm] := formatF[{}, x] /; EvenQ[Length[{x}]];
formatF[list_List, a_, b_, x___] := formatF[Append[list, Subscript[a, b]], x];
formatF[list_List] := Row[list];

Then, in the traditional form,

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.